]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Allow insertion of components at the ends of straight segments 84/3984/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Tue, 10 Mar 2020 14:29:15 +0000 (16:29 +0200)
committerReino Ruusu <reino.ruusu@semantum.fi>
Tue, 10 Mar 2020 14:29:15 +0000 (16:29 +0200)
gitlab #106

Change-Id: I20b12339d82ca6da52d9b69ec0f34656c5cb3555

org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java
org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java

index 8dcee92610f00f8fea6afc1a1114d949cc787e1f..dae8c629b4335a7bfacb88503086d7d34285311b 100644 (file)
@@ -76,13 +76,13 @@ public class AddComponentAction extends vtkSwtAction {
                                allowed.add(PositionType.NEXT);
                        }  
                } else {
-                       if (component.getNext() == null) {
+                       if (component.getNext() == null || component.getControlPoint().isVariableLength()) {
                                allowed.add(PositionType.NEXT);
                        }
-                       if (component.getPrevious() == null) {
+                       if (component.getPrevious() == null || component.getControlPoint().isVariableLength()) {
                                allowed.add(PositionType.PREVIOUS);
                        }
-                       if (component instanceof InlineComponent && !component.getControlPoint().isFixedLength()){
+                       if (component instanceof InlineComponent && component.getControlPoint().isVariableLength()){
                                allowed.add(PositionType.SPLIT);
                        }
                }
index 6bbabe1e251c9feaf3f10e1767a56ce827ec91f0..438e0bd6a96eae87cf8121640a11bfd350409161 100644 (file)
@@ -499,6 +499,11 @@ public class ComponentUtils {
                
                Vector3d v = new Vector3d(dir);
                if (insertAdjustable) {
+                       // Prevent moving of adjacent components - always insert at end of a connected variable length component
+                       if (position == PositionType.NEXT && component.getNext() != null ||
+                               position == PositionType.PREVIOUS && component.getPrevious() != null)
+                               insertPosition = PositionType.PREVIOUS;
+                       
                        if (insertPosition == PositionType.NEXT)
                                v.scale(newComponent.getControlPoint().getInlineLength());
                        else if (insertPosition == PositionType.SPLIT)
@@ -525,14 +530,20 @@ public class ComponentUtils {
                case NEXT: 
                        if (toPcp.isDualInline())
                                toPcp = toPcp.getDualSub();
-                       newPcp.insert(toPcp, Direction.NEXT);
                        newPcp.setWorldPosition(pos);
+                       if (toPcp.getNext() != null)
+                               PipingRules.splitVariableLengthComponent(newComponent, (InlineComponent)component, false);
+                       else
+                               newPcp.insert(toPcp, Direction.NEXT);
                        break;
                case PREVIOUS:
                        if (toPcp.isDualSub())
                                toPcp = toPcp.parent;
-                       newPcp.insert(toPcp, Direction.PREVIOUS);
                        newPcp.setWorldPosition(pos);
+                       if (toPcp.getPrevious() != null)
+                               PipingRules.splitVariableLengthComponent(newComponent, (InlineComponent)component, false);
+                       else
+                               newPcp.insert(toPcp, Direction.PREVIOUS);
                        break;
                case SPLIT:
                        PipingRules.splitVariableLengthComponent(newComponent, (InlineComponent)component, true);