]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Remove/Split action removes pipeline components without reconnecting 58/3358/2
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 17 Oct 2019 11:25:45 +0000 (14:25 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 17 Oct 2019 11:49:40 +0000 (14:49 +0300)
gitlab #33

Change-Id: I9bd2df03b9d4f4b8abea03c15e22dcce39fb70bb

org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java
org.simantics.g3d/src/org/simantics/g3d/scl/ScriptNodeMap.java
org.simantics.plant3d/src/org/simantics/plant3d/actions/RemoveAndSplitAction.java [new file with mode: 0644]
org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/PipelineComponent.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java

index 674a71f2987953f0cf1ace01014b1deb9a68103e..d9b754b45e115bb0f7be78fc6c3f56c327abae37 100644 (file)
  *******************************************************************************/
 package org.simantics.g3d.vtk.common;
 
+import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Deque;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -435,6 +437,27 @@ public abstract class AbstractVTKNodeMap<E extends INode> implements VTKNodeMap<
                
                
                synchronized (syncMutex) {
+                   // Check for overlapping additions and deletions, prevent deleting objects that are also added.
+                   Deque<E> stack = new ArrayDeque<E>();
+               for (Pair<E, String> n : added) {
+                   stack.add(n.first);
+               }
+               while (!stack.isEmpty()) {
+                   E n = stack.pop();
+                   for (int i = removed.size()-1; i >= 0; i--) {
+                       if (removed.get(i).first == n) {
+                           removed.remove(i);
+                           break;
+                       }
+                   }
+                   if (n instanceof ParentNode) {
+                       ParentNode<INode> pn = (ParentNode<INode>)n;
+                       for (INode cn : pn.getNodes()) {
+                           stack.push((E)cn);
+                       }
+                   }
+               }
+               
                        rem.addAll(removed);
                        add.addAll(added);
                        for (E e : updated.getKeys()) {
@@ -448,6 +471,8 @@ public abstract class AbstractVTKNodeMap<E extends INode> implements VTKNodeMap<
                        updated.clear();
                }
                
+               
+               
                for (Pair<E, String> n : rem) {
                        stopListening(n.first);
                        removeActor(n.first);
index 37b124e3f49757fdf2461ac3a8b9ceb012221041..cd2447b3ae17e38855a8036e22077ba941a0b1d9 100644 (file)
@@ -1,8 +1,10 @@
 package org.simantics.g3d.scl;
 
+import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Deque;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -360,6 +362,27 @@ public abstract class ScriptNodeMap<E extends INode> implements NodeMap<Object,E
                
                
                synchronized (syncMutex) {
+                   // Check for overlapping additions and deletions, prevent deleting objects that are also added.
+            Deque<E> stack = new ArrayDeque<E>();
+            for (Pair<E, String> n : added) {
+                stack.add(n.first);
+            }
+            while (!stack.isEmpty()) {
+                E n = stack.pop();
+                for (int i = removed.size()-1; i >= 0; i--) {
+                    if (removed.get(i).first == n) {
+                        removed.remove(i);
+                        break;
+                    }
+                }
+                if (n instanceof ParentNode) {
+                    ParentNode<INode> pn = (ParentNode<INode>)n;
+                    for (INode cn : pn.getNodes()) {
+                        stack.push((E)cn);
+                    }
+                }
+            }
+            
                        rem.addAll(removed);
                        add.addAll(added);
                        for (E e : updated.getKeys()) {
diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/actions/RemoveAndSplitAction.java b/org.simantics.plant3d/src/org/simantics/plant3d/actions/RemoveAndSplitAction.java
new file mode 100644 (file)
index 0000000..d20a59c
--- /dev/null
@@ -0,0 +1,34 @@
+package org.simantics.plant3d.actions;
+
+import org.simantics.g3d.scenegraph.IG3DNode;
+import org.simantics.g3d.vtk.action.RemoveAction;
+import org.simantics.g3d.vtk.common.VTKNodeMap;
+import org.simantics.plant3d.scenegraph.PipelineComponent;
+
+public class RemoveAndSplitAction extends RemoveAction {
+
+    public RemoveAndSplitAction(VTKNodeMap nodeMap) {
+        super(nodeMap);
+        setText("Remove/Split");
+    }
+    
+    @Override
+    public boolean isRemovable(IG3DNode node) {
+        if (!super.isRemovable(node))
+            return false;
+        if (!(node instanceof PipelineComponent))
+            return false;
+        PipelineComponent pc = (PipelineComponent)node;
+        if (pc.getNext() != null && pc.getPrevious() != null)
+            return true;
+        else return false;
+    }
+    
+    
+    @Override
+    protected void doRemove(IG3DNode node) {
+        PipelineComponent pc = (PipelineComponent)node;
+        pc.removeAndSplit();
+    }
+
+}
index ba56f2f9201d0d1ca3d0c09dada69d7ee2284888..8387650bb68d5cf7410a53862a2963580d5885bc 100644 (file)
@@ -42,6 +42,7 @@ import org.simantics.objmap.graph.schema.IMappingSchema;
 import org.simantics.plant3d.actions.AddComponentAction;
 import org.simantics.plant3d.actions.AddEquipmentAction;
 import org.simantics.plant3d.actions.AddNozzleAction;
+import org.simantics.plant3d.actions.RemoveAndSplitAction;
 import org.simantics.plant3d.actions.RoutePipeAction;
 import org.simantics.plant3d.actions.TranslateInlineAction;
 import org.simantics.plant3d.scenegraph.EndComponent;
@@ -50,12 +51,10 @@ import org.simantics.plant3d.scenegraph.IP3DNode;
 import org.simantics.plant3d.scenegraph.InlineComponent;
 import org.simantics.plant3d.scenegraph.Nozzle;
 import org.simantics.plant3d.scenegraph.P3DRootNode;
-import org.simantics.plant3d.scenegraph.PipeRun;
 import org.simantics.plant3d.scenegraph.PipelineComponent;
 import org.simantics.plant3d.scenegraph.SchemaBuilder;
 import org.simantics.plant3d.scenegraph.TurnComponent;
 import org.simantics.plant3d.scenegraph.controlpoint.ControlPointFactory;
-import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint;
 import org.simantics.plant3d.scenegraph.controlpoint.PipingRules;
 import org.simantics.plant3d.utils.ComponentUtils;
 import org.simantics.plant3d.utils.Item;
@@ -94,6 +93,7 @@ public class Plant3DEditor extends ResourceEditorPart {
        private TranslateInlineAction translateInlineAction;
        private RotateAction rotateAction;
        private RemoveAction removeAction;
+       private RemoveAndSplitAction removeSplitAction;
        private RoutePipeAction routePipeAction;
        private AddComponentAction addComponentAction;
        
@@ -215,10 +215,10 @@ public class Plant3DEditor extends ResourceEditorPart {
                removeAction = new RemoveAction(nodeMap) {
                        public void setNode(IG3DNode node) {
                                super.setNode(node);
-                               
-                               
                        }
                };
+               
+               removeSplitAction = new RemoveAndSplitAction(nodeMap);
                routePipeAction = new RoutePipeAction(panel,rootNode);
                addComponentAction = new AddComponentAction(panel, rootNode);
        }
@@ -325,6 +325,7 @@ public class Plant3DEditor extends ResourceEditorPart {
                                                add.setEquipment((Equipment)node);
                                                m.add(add);
                                        }
+                                       m.add(removeAction);
                                } else if (node instanceof Nozzle) {
                                        Nozzle nozzle = (Nozzle)node;
                                        if (!nozzle.isFixed()) {
@@ -336,6 +337,7 @@ public class Plant3DEditor extends ResourceEditorPart {
                                        routePipeAction.setEnabled(nozzle.getNext() == null && nozzle.getPrevious() == null);
                                        m.add(addComponentAction);
                                        addComponentAction.setComponent(nozzle);
+                                       m.add(removeAction);
                                } else if (node instanceof TurnComponent) {
                                        m.add(translateAction);
                                        TurnComponent component = (TurnComponent)node;
@@ -344,10 +346,14 @@ public class Plant3DEditor extends ResourceEditorPart {
                                        routePipeAction.setEnabled(component.getNext() == null || component.getPrevious() == null);
                                        m.add(addComponentAction);
                                        addComponentAction.setComponent(component);
+                                       m.add(removeAction);
+                                       m.add(removeSplitAction);
+                                       removeSplitAction.setNode(node);
                                } else if (node instanceof EndComponent) {
                                        m.add(translateAction);
                                        m.add(addComponentAction);
                                        addComponentAction.setComponent((PipelineComponent)node);
+                                       m.add(removeAction);
                                } else if (node instanceof InlineComponent) {
                                        //m.add(translateInlineAction);
                                        InlineComponent component = (InlineComponent)node;
@@ -356,9 +362,14 @@ public class Plant3DEditor extends ResourceEditorPart {
                                        routePipeAction.setComponent(component);
                                        m.add(addComponentAction);
                                        addComponentAction.setComponent(component);
+                                       m.add(removeAction);
+                                       m.add(removeSplitAction);
+                                       removeSplitAction.setNode(node);
+                               } else {
+                                   m.add(removeAction);
                                }
                                
-                               m.add(removeAction);
+                               
                                translateAction.setNode(node);
                                translateInlineAction.setNode(node);
                                rotateAction.setNode(node);
index d66869ea2069219be8c6dae03e2ec378d235f40d..3f393364e3ccf456cc9ab63b53b8c01927ee6278 100644 (file)
@@ -388,6 +388,15 @@ public abstract class PipelineComponent extends GeometryNode {
                }
                super.remove();
        }
+       
+       public void removeAndSplit() {
+           PipeControlPoint pcp = getControlPoint();
+        // Second check is needed, when remove process is initiated from control point.
+        if (pcp != null && pcp.getPipelineComponent() != null) {
+            pcp.removeAndSplit();
+        }
+        super.remove();
+       }
 
        @Override
        protected double[] getColor() {
index 93186779e60d580aa31d23a95585ce4886ff9f7b..daab2d111b234d2da42a16f78671a543a9f23607 100644 (file)
@@ -16,6 +16,8 @@ import org.simantics.g3d.math.MathTools;
 import org.simantics.g3d.property.annotations.GetPropertyValue;
 import org.simantics.g3d.scenegraph.G3DNode;
 import org.simantics.plant3d.scenegraph.IP3DNode;
+import org.simantics.plant3d.scenegraph.Nozzle;
+import org.simantics.plant3d.scenegraph.P3DRootNode;
 import org.simantics.plant3d.scenegraph.PipeRun;
 import org.simantics.plant3d.scenegraph.PipelineComponent;
 
@@ -938,8 +940,12 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                        }
                }
        }
-
+       
        public void _remove() {
+           _remove(true);
+       }
+
+       public void _remove(boolean renconnect) {
                if (component == null && next == null && previous == null)
                        return;
                if (isDualInline() || isDualSub()) {
@@ -964,7 +970,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                                return;
                        }
                        if (currentNext != null && currentPrev != null) {
-                               boolean link = true;
+                               boolean link = renconnect;
                                if (currentNext.isBranchEnd()) {
                                        link = false;
                                        //                                      currentNext.setPrevious(null);
@@ -1125,6 +1131,41 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                        e.printStackTrace();
                }
        }
+       
+       public void removeAndSplit() {
+        PipeControlPoint currentPrev = previous;
+        PipeControlPoint currentNext = next;
+        
+        if (next != null && previous != null) {
+            P3DRootNode root = (P3DRootNode)getPipelineComponent().getRootNode();
+            PipeRun nextPipeRun = new PipeRun();
+            nextPipeRun.setName(root.getUniqueName("PipeRun"));
+            root.addChild(nextPipeRun);
+            
+            PipeRun previousRun = previous.getPipeRun();
+            nextPipeRun.setPipeDiameter(previousRun.getPipeDiameter());
+            nextPipeRun.setTurnRadius(previousRun.getTurnRadius());
+            
+            PipelineComponent n = next.getPipelineComponent();
+            while (n != null) {
+                if (! (n instanceof Nozzle)) {
+                    n.deattach();
+                    nextPipeRun.addChild(n);
+                } else
+                    n.setPipeRun(nextPipeRun);
+                n = n.getNext();
+            }
+        }
+        _remove(false);
+        try {
+            if (currentNext != null)
+                PipingRules.requestUpdate(currentNext);
+            if (currentPrev != null)
+                PipingRules.requestUpdate(currentPrev);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
 
        private void checkRemove(PipeRun pipeRun) {
                Collection<PipeControlPoint> points = pipeRun.getControlPoints();