From 6d0ac4dd272cfa9f82ad012e703dd0454463f5f7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Anian=20B=C3=BChler?=
 <anian.buehler@reutlingen-university.de>
Date: Mon, 17 May 2021 18:08:04 +0200
Subject: [PATCH] added 3-port infix-block

---
 .../edu/mit/blocks/codeblocks/BlockGenus.java |  7 ++
 .../blocks/codeblocks/InfixBlockShape.java    | 66 ++++++++-----------
 .../mit/blocks/renderable/SocketLabel.java    |  5 +-
 3 files changed, 38 insertions(+), 40 deletions(-)

diff --git a/src/main/java/edu/mit/blocks/codeblocks/BlockGenus.java b/src/main/java/edu/mit/blocks/codeblocks/BlockGenus.java
index ad77269..04b4d79 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 77c09da..adc4d3c 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 7cc9535..b017416 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) {
-- 
GitLab