]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Handle PipeRun removals with detaching Components. 44/3644/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Fri, 29 Nov 2019 10:44:52 +0000 (12:44 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Fri, 29 Nov 2019 11:03:20 +0000 (11:03 +0000)
Some operations can move Components between PipeRuns. If we create a
PipeRun within such operation, and the undo the modification, removal of
the created PipeRun may remove Components before they are attached to
their original PipeRuns.

1. Now PipeRun removal detaches Components, so that Component structure
remains intact.
2. PipeCOntrolPoint removal work without PipeRun.
3. AbstractVTKNodeMap calls INode.remove() all removed nodes.

gitlab #35

Change-Id: I37ec56302581ab176fe630c91b3cddb301ad1210
(cherry picked from commit f346390a5a8cd4262a9aa68951e55d504d412549)

org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/PipeRun.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/PipelineComponent.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java

index a03e89cbc8e1fc6273708686fa5fcc4174b95dde..f4458fc34bd47731a2073279cc344d864e8faab3 100644 (file)
@@ -121,8 +121,16 @@ public abstract class AbstractVTKNodeMap<DBObject,E extends INode> implements VT
        
        protected void removeMap(E node) {
            Collection<vtkProp> coll = nodeToActor.getValuesUnsafe(node);
-           for (vtkProp p : coll) {
-               actorToNode.remove(p);
+           if (coll.size() > 0) {
+               view.lock();
+           for (vtkProp p : coll) {
+               actorToNode.remove(p);
+               if (p.GetVTKId() != 0) {
+                    view.getRenderer().RemoveActor(p);
+                    p.Delete();
+                }
+           }
+           view.unlock();
            }
            nodeToActor.remove(node);
        }
@@ -352,7 +360,7 @@ public abstract class AbstractVTKNodeMap<DBObject,E extends INode> implements VT
                if (runUndo && useFullSyncWithUndo) {
                        reset(graph);
                } else {
-                       synchronized (syncMutex) {
+                   synchronized (syncMutex) {
                                graphUpdates = true;
                                for (DBObject domainObject : mapping.getDomainModified()) {
                                        @SuppressWarnings("unchecked")
@@ -365,7 +373,7 @@ public abstract class AbstractVTKNodeMap<DBObject,E extends INode> implements VT
                                syncDeletes();
                                clearDeletes();
                                graphUpdates = false;
-                       }
+               }
                }
                
                if (mapping.isRangeModified() && !runUndo && !runRedo)
@@ -477,10 +485,10 @@ public abstract class AbstractVTKNodeMap<DBObject,E extends INode> implements VT
                    E n = stack.pop();
                    boolean conflict = filterChange(removed, n);
                    if (conflict) {
-                       System.out.println("Prevent removing " + n);
+                       if (DEBUG) System.out.println("Prevent removing " + n);
                        //filterChange(added, n)
                        if (filterChange(added, n))
-                           System.out.println("Prevent adding " + n);
+                          if (DEBUG) System.out.println("Prevent adding " + n);
                    }
                    if (n instanceof ParentNode) {
                        ParentNode<INode> pn = (ParentNode<INode>)n;
@@ -504,16 +512,16 @@ public abstract class AbstractVTKNodeMap<DBObject,E extends INode> implements VT
                }
                
                
-               
                for (Pair<E, String> n : rem) {
                        stopListening(n.first);
                        removeActor(n.first);
+                       n.first.remove();
                }
                
-               for (Pair<E, String> n : add) {
-                       addActor(n.first);
-                       listen(n.first);
-               }
+           for (Pair<E, String> n : add) {
+               addActor(n.first);
+               listen(n.first);
+           }
                
                for (E e : mod.getKeys()) {
                        Set<String> ids = mod.getValues(e);
@@ -547,26 +555,11 @@ public abstract class AbstractVTKNodeMap<DBObject,E extends INode> implements VT
                        }
                }
                
-//      synchronized (syncMutex) {
-//          rem.addAll(removed);
-//          add.addAll(added);
-//          //mod.addAll(updated);
-//          for (E e : updated.getKeys()) {
-//              for (String s : updated.getValues(e))
-//                  mod.add(e, s);
-//          }
-//          
-//          removed.clear();
-//          added.clear();
-//          updated.clear();
-//      }
-               
                for (E e : mod.getKeys()) {
                        Set<String> ids = mod.getValues(e);
                        updateActor(e,ids);
                }
-               
-               
+
                for (Pair<E, String> n : rem) {
                        for (NodeListener l : nodeListeners)
                                l.nodeRemoved(null, n.first, n.second);
@@ -638,7 +631,7 @@ public abstract class AbstractVTKNodeMap<DBObject,E extends INode> implements VT
                
                //FIXME : 1. sometimes removed structural models cause ObjMap to add their children again.
                //           removing the listener here prevents corruption of visual model, but better fix is needed.
-               //        2. detach causes nodeRemoved event, which then causes other critical events to be missed. Took out th 
+               //        2. detach causes nodeRemoved event, which then causes other critical events to be missed. Took out call: 
                //stopListening(child);
        }
        
index 2c334c1f2810f085f0deaad34028ea9d2a28994c..1d199f53f2ec604737d798a3ec074e7978bda485 100644 (file)
@@ -112,8 +112,22 @@ public class PipeRun extends P3DParentNode<IP3DNode> {
        }
        
        @RelatedElementsRem(Plant3D.URIs.children)
+       public void _remChild(PipelineComponent node) {
+               //since we do not now, if DB remove is actually remove or detach, we have to use detach. NodeMap will handle Component removals.
+           deattachNode(Plant3D.URIs.children, node);
+       }
+       
        public void remChild(PipelineComponent node) {
-               removeNode(Plant3D.URIs.children, node);
+           removeNode(Plant3D.URIs.children, node);
+       }
+       
+       @Override
+       public void remove() {
+           // since we do not now, if DB remove is actually remove or detach, we have to use detach. NodeMap will handle Component removals.
+           Collection<PipelineComponent> comps = getChild();
+           for (PipelineComponent c : comps)
+               c.deattach();
+           super.remove();
        }
 
        
index 61e48585336fb7749ba30c021fd42f549f40a027..ad1c2b7a7d210e7c9fd83ae15aab4fa7f4555fb0 100644 (file)
@@ -455,6 +455,7 @@ public abstract class PipelineComponent extends GeometryNode {
                if (pcp != null && pcp.getPipelineComponent() != null) {
                        pcp.remove();
                }
+               setPipeRun(null);
                super.remove();
        }
        
@@ -464,6 +465,7 @@ public abstract class PipelineComponent extends GeometryNode {
         if (pcp != null && pcp.getPipelineComponent() != null) {
             pcp.removeAndSplit();
         }
+        setPipeRun(null);
         super.remove();
        }
 
index aa5eacf9338550c88ef2e6692677c349dd0f82c3..8b1455ca2980a8f4927b291299efff2102d5606f 100644 (file)
@@ -43,6 +43,8 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
        private boolean isSizeChange = false;  // changes size of the pipe. The next control point / component is on different PipeRun
        private boolean isSub = false;         // child point for offset / size change
 
+       private boolean disposed = false;
+       
        public PipeControlPoint(PipelineComponent component) {
                this.component = component;
                if (component.getPipeRun() != null)
@@ -1065,17 +1067,19 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
        
 
        public void _remove(boolean renconnect) {
-               if (component == null && next == null && previous == null)
-                       return;
-               if (DEBUG) System.out.println(this + " Remove " + renconnect);
+           if (disposed)
+               return;
+               
+           if (DEBUG) System.out.println(this + " Remove " + renconnect);
 
                if (getParentPoint() != null) {
                    getParentPoint()._remove(renconnect);
                    return;
                }
                PipeRun pipeRun = getPipeRun();
-               if (pipeRun == null)
-                       return;
+//             PipeRUn removal has been changed, so pipeRun may be null.
+//             if (pipeRun == null)
+//                     return;
 
                PipeControlPoint additionalRemove = null;
                if (!PipingRules.isEnabled()) {
@@ -1088,8 +1092,10 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                        PipeControlPoint currentNext = next;
                        if (currentNext == null && currentPrev == null) {
                                removeComponent();
-                               pipeRun.remChild(this);
-                               checkRemove(pipeRun);
+                               if (pipeRun != null) {
+                                   pipeRun.remChild(this);
+                                   checkRemove(pipeRun);
+                               }
                                return;
                        }
                        if (currentNext != null && currentPrev != null) {
@@ -1255,12 +1261,15 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                }
 
                removeComponent();
-               pipeRun.remChild(this);
-               checkRemove(pipeRun);
-               if (PipingRules.isEnabled() && pipeRun.getParent() != null && pipeRun.getControlPoints().size() > 0)
-                       PipingRules.validate(pipeRun);
+               if (pipeRun != null) {
+               pipeRun.remChild(this);
+               checkRemove(pipeRun);
+               if (PipingRules.isEnabled() && pipeRun.getParent() != null && pipeRun.getControlPoints().size() > 0)
+                       PipingRules.validate(pipeRun);
+               }
                if (additionalRemove != null)
                        additionalRemove.remove();
+               disposed = true;
        }
 
        /**
@@ -1353,6 +1362,8 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
     }
 
        private boolean checkRemove(PipeRun pipeRun) {
+           if (pipeRun == null)
+               return false;
                Collection<PipeControlPoint> points = pipeRun.getControlPoints();
                if (points.size() == 0) {
                        pipeRun.remove();