diff --git a/src/main/java/edu/mit/blocks/codeblocks/BlockGenus.java b/src/main/java/edu/mit/blocks/codeblocks/BlockGenus.java index ad77269b5a5c23e90b6a2abf236424a5befee54b..04b4d79eae777616e56b11c59a02def94ffc603a 100644 --- a/src/main/java/edu/mit/blocks/codeblocks/BlockGenus.java +++ b/src/main/java/edu/mit/blocks/codeblocks/BlockGenus.java @@ -891,6 +891,13 @@ public class BlockGenus { && newGenus.sockets.get(1).getPositionType() == BlockConnector.PositionType.BOTTOM) { newGenus.isInfix = true; } + //TODO: test -> 3 bottom connectors test - added by letsgoING + else if (newGenus.sockets != null && newGenus.sockets.size() == 3 + && newGenus.sockets.get(0).getPositionType() == BlockConnector.PositionType.BOTTOM + && newGenus.sockets.get(1).getPositionType() == BlockConnector.PositionType.BOTTOM + && newGenus.sockets.get(2).getPositionType() == BlockConnector.PositionType.BOTTOM) { + newGenus.isInfix = true; + } } else if (genusChild.getNodeName().equals("Images")) { /// LOAD BLOCK IMAGES /// loadBlockImages(genusChild.getChildNodes(), newGenus); diff --git a/src/main/java/edu/mit/blocks/codeblocks/InfixBlockShape.java b/src/main/java/edu/mit/blocks/codeblocks/InfixBlockShape.java index 77c09da0b18977319eb41387d4378aa9bee7f6d2..adc4d3cb229ecaa0eea9ab5aff6f652c4f282444 100644 --- a/src/main/java/edu/mit/blocks/codeblocks/InfixBlockShape.java +++ b/src/main/java/edu/mit/blocks/codeblocks/InfixBlockShape.java @@ -64,14 +64,10 @@ public class InfixBlockShape extends BlockShape { gpBottom.lineTo( (float) gpBottom.getCurrentPoint().getX() + BOTTOM_SOCKET_MIDDLE_SPACER, (float) gpBottom.getCurrentPoint().getY()); - } else if(block.isCommandBlock()) { //TODO: check //added by letsgoING for new setVariableBlock test + }else { gpBottom.lineTo( (float) gpBottom.getCurrentPoint().getX() + BOTTOM_SOCKET_SIDE_SPACER, (float) gpBottom.getCurrentPoint().getY()); - } else { - gpBottom.lineTo( - (float) gpBottom.getCurrentPoint().getX() + BOTTOM_SOCKET_SIDE_SPACER , - (float) gpBottom.getCurrentPoint().getY()); } @@ -97,12 +93,13 @@ public class InfixBlockShape extends BlockShape { (float) gpBottom.getCurrentPoint().getX() + BOTTOM_SOCKET_SIDE_SPACER, (float) gpBottom.getCurrentPoint().getY()); - //draw first socket - down right side BCS.addDataSocket(gpBottom, curSocket.getKind(), false); //rb.updateSocketPoint(curSocket, rightSocket); } else { //there is a connected block Block connectedBlock = rb.getWorkspace().getEnv().getBlock(curSocket.getBlockID()); + + //TODO: check why RBlock on second connector is always NULL??? RenderableBlock connectedRBlock = rb.getWorkspace().getEnv().getRenderableBlock(curSocket.getBlockID()); //calculate and update the new socket point @@ -246,43 +243,34 @@ public class InfixBlockShape extends BlockShape { int bottomSocketWidth = 0; - //added by letsgoING for new setVariableBlock test - if (block.isCommandBlock()) { - for (BlockConnector socket : block.getSockets()) { - if (socket.getPositionType() == BlockConnector.PositionType.BOTTOM) { - if (socket.getBlockID() == Block.NULL) { - //3 socket spacers = left of socket, between connectors, right of socket - bottomSocketWidth += BOTTOM_SOCKET_SIDE_SPACER + BOTTOM_SOCKET_MIDDLE_SPACER; - } else { //a block is connected to socket - //TODO get their assigned width from rb - if (rb.getSocketSpaceDimension(socket) != null) { - bottomSocketWidth += rb.getSocketSpaceDimension(socket).width; - } + + for (BlockConnector socket : block.getSockets()) { + if (socket.getPositionType() == BlockConnector.PositionType.BOTTOM) { + if (socket.getBlockID() == Block.NULL) { + //3 socket spacers = left of socket, between connectors, right of socket + bottomSocketWidth += BOTTOM_SOCKET_SIDE_SPACER; + if(block.isCommandBlock()) {//added by letsgoING for new setVariableBlock test + //TODO get correct size of socket + bottomSocketWidth += rb.accomodateLabelsWidth(); + } + } else { //a block is connected to socket + //TODO get their assigned width from rb + if (rb.getSocketSpaceDimension(socket) != null) { + bottomSocketWidth += rb.getSocketSpaceDimension(socket).width; + if(block.isCommandBlock()) {//added by letsgoING for new setVariableBlock test + //TODO get correct size of socket + bottomSocketWidth += rb.accomodateLabelsWidth(); + } + } + bottomSocketWidth -= BlockConnectorShape.NORMAL_DATA_PLUG_WIDTH; + // if it's a mirror plug, subtract for the other side, too. + if (rb.getWorkspace().getEnv().getBlock(socket.getBlockID()).getPlug().getPositionType() == BlockConnector.PositionType.MIRROR) { + bottomSocketWidth -= BlockConnectorShape.NORMAL_DATA_PLUG_WIDTH; } } } } - //if the sum of bottom sockets is greater than the calculated width, then use it - else { - for (BlockConnector socket : block.getSockets()) { - if (socket.getPositionType() == BlockConnector.PositionType.BOTTOM) { - if (socket.getBlockID() == Block.NULL) { - //3 socket spacers = left of socket, between connectors, right of socket - bottomSocketWidth += BOTTOM_SOCKET_SIDE_SPACER; - } else { //a block is connected to socket - //TODO get their assigned width from rb - if (rb.getSocketSpaceDimension(socket) != null) { - bottomSocketWidth += rb.getSocketSpaceDimension(socket).width; - } - bottomSocketWidth -= BlockConnectorShape.NORMAL_DATA_PLUG_WIDTH; - // if it's a mirror plug, subtract for the other side, too. - if (rb.getWorkspace().getEnv().getBlock(socket.getBlockID()).getPlug().getPositionType() == BlockConnector.PositionType.MIRROR) { - bottomSocketWidth -= BlockConnectorShape.NORMAL_DATA_PLUG_WIDTH; - } - } - } - } - } + bottomSocketWidth += 2 * BOTTOM_SOCKET_MIDDLE_SPACER; //TODO need to decide for a size of the middle spacer and how to place them diff --git a/src/main/java/edu/mit/blocks/renderable/SocketLabel.java b/src/main/java/edu/mit/blocks/renderable/SocketLabel.java index 7cc953554868ee0d103750292f14b7e9327bd0ac..b01741678792466af67c970182f5cc9e0e91c2fd 100644 --- a/src/main/java/edu/mit/blocks/renderable/SocketLabel.java +++ b/src/main/java/edu/mit/blocks/renderable/SocketLabel.java @@ -24,7 +24,10 @@ class SocketLabel extends BlockLabel { * @return true if the specified socket should have a corresponding Blocklabel instance added to this. */ static boolean ignoreSocket(BlockConnector socket) { - return (socket.getPositionType() == BlockConnector.PositionType.BOTTOM) || socket.getLabel().equals(""); + //removed bottom-connector from ignore-list for new setVariable-Block by letsgoING + //TODO: TEST for all Blocks -> letsgoING + //return (socket.getPositionType() == BlockConnector.PositionType.BOTTOM) || socket.getLabel().equals(""); + return socket.getLabel().equals(""); } void update(Point2D socketPoint) {