From: Marko Luukkainen Date: Wed, 23 Oct 2019 14:28:09 +0000 (+0300) Subject: Filter conflicting changes (deleted + added at the same time) X-Git-Tag: v1.43.0~176 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=b32696a059ab6f9e01e16df26f1cdf0d8fbf1e91;p=simantics%2F3d.git Filter conflicting changes (deleted + added at the same time) gitlab #35 Change-Id: I90278469f0052b367b326a2ff495ae00c20aa12b --- diff --git a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java index d9b754b4..b7622007 100644 --- a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java +++ b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java @@ -50,7 +50,7 @@ import vtk.vtkProp; public abstract class AbstractVTKNodeMap implements VTKNodeMap, IMappingListener, RenderListener, NodeListener, UndoRedoSupport.ChangeListener{ - private static final boolean DEBUG = false; + private static final boolean DEBUG = true; protected Session session; protected IMapping mapping; @@ -428,6 +428,16 @@ public abstract class AbstractVTKNodeMap implements VTKNodeMap< return n + "@" + Integer.toHexString(n.hashCode()); } + protected boolean filterChange(List> 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 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 stack = new ArrayDeque(); for (Pair 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 pn = (ParentNode)n; diff --git a/org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/ParentNode.java b/org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/ParentNode.java index 7da387d7..5c834fba 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/ParentNode.java +++ b/org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/ParentNode.java @@ -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 extends Node { private MapList children = new MapList(); 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); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java b/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java index 574206da..4bee16b6 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java @@ -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; }