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=bb5493f6b7a76ee806d712d402691f5b862cdc8d;hb=refs%2Fchanges%2F51%2F3451%2F1;hp=d9b754b45e115bb0f7be78fc6c3f56c327abae37;hpb=46c28cc32944d0f73c5ab4062bd6b0b232143be7;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 d9b754b4..bb5493f6 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 @@ -48,16 +48,16 @@ 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(); - protected Map actorToNode = new HashMap(); + private MapList nodeToActor = new MapList(); + private Map actorToNode = new HashMap(); protected ParentNode rootNode; @@ -66,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; @@ -85,9 +85,7 @@ public abstract class AbstractVTKNodeMap implements VTKNodeMap< e.printStackTrace(); } } - - - + protected abstract void addActor(E node); protected abstract void removeActor(E node); protected abstract void updateActor(E node,Set ids); @@ -114,6 +112,21 @@ public abstract class AbstractVTKNodeMap implements VTKNodeMap< return nodeToActor.getValues((E)node); } + protected void map(E node, Collection props) { + for (vtkProp p : props) { + nodeToActor.add(node, p); + actorToNode.put(p, node); + } + } + + protected void removeMap(E node) { + Collection coll = nodeToActor.getValuesUnsafe(node); + for (vtkProp p : coll) { + actorToNode.remove(p); + } + nodeToActor.remove(node); + } + @SuppressWarnings("unchecked") @Override public ParentNode getRootNode() { @@ -143,6 +156,10 @@ public abstract class AbstractVTKNodeMap implements VTKNodeMap< private boolean rangeModified = false; + public boolean isRangeModified() { + return rangeModified; + } + @Override public void onChanged() { try { @@ -210,11 +227,12 @@ public abstract class AbstractVTKNodeMap implements VTKNodeMap< } if (changeTracking) { mapping.rangeModified((E)node.getParent()); + mapping.rangeModified((E)node); } added.add(new Pair(node, id)); rangeModified = true; } - view.refresh(); + repaint(); } @SuppressWarnings("unchecked") @@ -225,8 +243,10 @@ public abstract class AbstractVTKNodeMap implements VTKNodeMap< if (n.first.equals(node)) return; } - if (changeTracking && !db) + if (changeTracking && !db) { + mapping.rangeModified((E)node); mapping.rangeModified((E)node.getParent()); + } removed.add(new Pair(node, id)); rangeModified = true; } @@ -317,10 +337,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(); @@ -337,7 +358,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); @@ -389,7 +410,7 @@ public abstract class AbstractVTKNodeMap implements VTKNodeMap< /** * When objects are removed (either from Java or Graph), after remove processing the Java objects remain in mapping cache. - * This causes problems with Undo and Redo, whcih the end up re-using the removed objects from mapping cache. + * This causes problems with Undo and Redo, which cause re-using the removed objects from mapping cache. * * This code here synchronizes removed and added objects to collect deletable objects. (a deletable object is one which is removed but not added). * @@ -420,6 +441,7 @@ public abstract class AbstractVTKNodeMap implements VTKNodeMap< for (E n : delete) { if (DEBUG) System.out.println(debugString(n)); mapping.getRange().remove(n); + stopListening(n); } delete.clear(); } @@ -428,6 +450,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 +469,19 @@ 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) { + 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; @@ -594,7 +627,6 @@ public abstract class AbstractVTKNodeMap implements VTKNodeMap< if (DEBUG) System.out.println("Node added " + child + " parent " + node); //receiveAdd((E)child, rel ,graphUpdates); receiveAdd((E)child, rel ,graphModified.contains(node)); - } @SuppressWarnings("unchecked") @@ -605,9 +637,10 @@ public abstract class AbstractVTKNodeMap implements VTKNodeMap< //receiveRemove((E)child, rel, graphUpdates); receiveRemove((E)child, rel, graphModified.contains(node)); - //FIXME : 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. - stopListening(child); + //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 + //stopListening(child); } @Override @@ -649,7 +682,7 @@ public abstract class AbstractVTKNodeMap implements VTKNodeMap< } - public IMapping getMapping() { + public IMapping getMapping() { return mapping; }