X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d.vtk%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fvtk%2Fcommon%2FAbstractVTKNodeMap.java;h=953ef198b2d43cbbd18c7f7285596fffaf88935c;hb=9070983be64f9f107e0a6388549aad475fcd9d76;hp=674a71f2987953f0cf1ace01014b1deb9a68103e;hpb=53d55c24c779745f188bdb18d32f71d20acb61b2;p=simantics%2F3d.git 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 674a71f2..953ef198 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 @@ -11,9 +11,11 @@ *******************************************************************************/ 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; @@ -46,12 +48,12 @@ import org.simantics.utils.ui.ExceptionUtils; import vtk.vtkProp; -public abstract class AbstractVTKNodeMap implements VTKNodeMap, IMappingListener, RenderListener, NodeListener, UndoRedoSupport.ChangeListener{ +public abstract class AbstractVTKNodeMap implements VTKNodeMap, IMappingListener, RenderListener, NodeListener, UndoRedoSupport.ChangeListener{ private static final boolean DEBUG = false; protected Session session; - protected IMapping mapping; + protected IMapping mapping; protected VtkView view; protected MapList nodeToActor = new MapList(); @@ -64,7 +66,7 @@ public abstract class AbstractVTKNodeMap implements VTKNodeMap< protected int redoOpCount = 0; protected boolean runUndo = false; protected boolean runRedo = false; - public AbstractVTKNodeMap(Session session, IMapping mapping, VtkView view, ParentNode rootNode) { + public AbstractVTKNodeMap(Session session, IMapping mapping, VtkView view, ParentNode rootNode) { this.session = session; this.mapping = mapping; this.view = view; @@ -141,6 +143,10 @@ public abstract class AbstractVTKNodeMap implements VTKNodeMap< private boolean rangeModified = false; + public boolean isRangeModified() { + return rangeModified; + } + @Override public void onChanged() { try { @@ -315,10 +321,11 @@ public abstract class AbstractVTKNodeMap implements VTKNodeMap< protected void reset(ReadGraph graph) throws MappingException { if (DEBUG) System.out.println("Reset"); + synchronized (syncMutex) { graphUpdates = true; mapping.getRangeModified().clear(); - for (Object o : mapping.getDomain()) + for (DBObject o : mapping.getDomain()) mapping.domainModified(o); mapping.updateRange(graph); graphModified.clear(); @@ -335,7 +342,7 @@ public abstract class AbstractVTKNodeMap implements VTKNodeMap< } else { synchronized (syncMutex) { graphUpdates = true; - for (Object domainObject : mapping.getDomainModified()) { + for (DBObject domainObject : mapping.getDomainModified()) { E rangeObject = mapping.get(domainObject); if (rangeObject != null) graphModified.add(rangeObject); @@ -426,6 +433,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(); @@ -435,6 +452,28 @@ public abstract class AbstractVTKNodeMap implements VTKNodeMap< synchronized (syncMutex) { + // 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(); + boolean conflict = filterChange(removed, n); + if (conflict) { + System.out.println("Prevent removing " + n); + //filterChange(added, n) + if (filterChange(added, n)) + System.out.println("Prevent adding " + n); + } + if (n instanceof ParentNode) { + ParentNode pn = (ParentNode)n; + for (INode cn : pn.getNodes()) { + stack.push((E)cn); + } + } + } + rem.addAll(removed); add.addAll(added); for (E e : updated.getKeys()) { @@ -448,6 +487,8 @@ public abstract class AbstractVTKNodeMap implements VTKNodeMap< updated.clear(); } + + for (Pair n : rem) { stopListening(n.first); removeActor(n.first); @@ -624,7 +665,7 @@ public abstract class AbstractVTKNodeMap implements VTKNodeMap< } - public IMapping getMapping() { + public IMapping getMapping() { return mapping; }