]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Filter conflicting changes (deleted + added at the same time) 95/3395/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Wed, 23 Oct 2019 14:28:09 +0000 (17:28 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Wed, 23 Oct 2019 14:28:09 +0000 (17:28 +0300)
gitlab #35

Change-Id: I90278469f0052b367b326a2ff495ae00c20aa12b

org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java
org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/ParentNode.java
org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java

index d9b754b45e115bb0f7be78fc6c3f56c327abae37..b762200786217a0434515a068a8d0f89cbe222e6 100644 (file)
@@ -50,7 +50,7 @@ import vtk.vtkProp;
 
 public abstract class AbstractVTKNodeMap<E extends INode> implements VTKNodeMap<E>, IMappingListener, RenderListener, NodeListener, UndoRedoSupport.ChangeListener{
 
-       private static final boolean DEBUG = false;
+       private static final boolean DEBUG = true;
        
        protected Session session;
        protected IMapping<Object,E> mapping;
@@ -428,6 +428,16 @@ public abstract class AbstractVTKNodeMap<E extends INode> implements VTKNodeMap<
                return n + "@" + Integer.toHexString(n.hashCode());
        }
        
+       protected boolean filterChange(List<Pair<E,String>> list,E n) {
+           for (int i = list.size()-1; i >= 0; i--) {
+            if (list.get(i).first == n) {
+                list.remove(i);
+                return true;
+            }
+        }
+           return false;
+       }
+       
        @SuppressWarnings("unchecked")
        protected void updateCycle() {
                rem.clear();
@@ -437,18 +447,16 @@ public abstract class AbstractVTKNodeMap<E extends INode> implements VTKNodeMap<
                
                
                synchronized (syncMutex) {
-                   // Check for overlapping additions and deletions, prevent deleting objects that are also added.
+                   // Check for overlapping additions and deletions, prevent deleting objects that are also added and vice versa.
                    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;
-                       }
+                   boolean conflict = filterChange(removed, n);
+                   if (conflict) {
+                       filterChange(added, n);   
                    }
                    if (n instanceof ParentNode) {
                        ParentNode<INode> pn = (ParentNode<INode>)n;
index 7da387d7fa5866ae6a5e6117000ee6b48837c044..5c834fba1dd8b89233f1dbc4e33c5f9a30fb42a4 100644 (file)
@@ -12,7 +12,6 @@
 package org.simantics.g3d.scenegraph.base;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.List;
 
 import org.simantics.utils.datastructures.MapList;
@@ -22,8 +21,13 @@ public abstract class ParentNode<T extends INode> extends Node {
        private MapList<String, T> children = new MapList<String, T>();
 
        public synchronized void addNode(String relName, T child) {
-               if (child.getParent() != null)
+           if (child == null)
+               throw new NullPointerException("Cannot add null child");
+               if (child.getParent() != null) {
+                   if (child.getParent() == this)
+                       throw new IllegalArgumentException("Given node is already a child");
                        child.getParent().deattachNode(child.getParentRel(), child);
+               }
 
                child.setParent(this, relName);
                children.add(relName, (T) child);
index 574206dae05211ffe29f000f0357cb6470f90b53..4bee16b61bd94660beae05d0fe96f0295b260b07 100644 (file)
@@ -203,7 +203,6 @@ public class ComponentUtils {
                Equipment equipment = createEquipment(root, equipmentType.getUri());
                String n = root.getUniqueName(equipmentType.getName());
                equipment.setName(n);
-               root.addChild(equipment);
                return equipment;
        }