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=a03e89cbc8e1fc6273708686fa5fcc4174b95dde;hb=refs%2Fchanges%2F00%2F3500%2F1;hp=2c37521b8367b751451d3a73c5b02cbca60977cd;hpb=b93886889422a3111b05a6944b3bcb2cdd8c416a;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 2c37521b..a03e89cb 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 @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.Stack; +import java.util.function.Consumer; import org.simantics.db.ReadGraph; import org.simantics.db.Session; @@ -40,7 +41,6 @@ import org.simantics.g3d.scenegraph.base.ParentNode; import org.simantics.objmap.exceptions.MappingException; import org.simantics.objmap.graph.IMapping; import org.simantics.objmap.graph.IMappingListener; -import org.simantics.utils.datastructures.Callback; import org.simantics.utils.datastructures.MapList; import org.simantics.utils.datastructures.MapSet; import org.simantics.utils.datastructures.Pair; @@ -53,7 +53,7 @@ public abstract class AbstractVTKNodeMap implements VT private static final boolean DEBUG = false; protected Session session; - protected IMapping mapping; + protected IMapping mapping; protected VtkView view; private MapList nodeToActor = new MapList(); @@ -66,7 +66,7 @@ public abstract class AbstractVTKNodeMap implements VT 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; @@ -109,7 +109,7 @@ public abstract class AbstractVTKNodeMap implements VT @SuppressWarnings("unchecked") @Override public Collection getRenderObjects(INode node) { - return nodeToActor.getValues((E)node); + return nodeToActor.getValues((E) node); } protected void map(E node, Collection props) { @@ -127,7 +127,6 @@ public abstract class AbstractVTKNodeMap implements VT nodeToActor.remove(node); } - @SuppressWarnings("unchecked") @Override public ParentNode getRootNode() { return (ParentNode)rootNode; @@ -188,12 +187,11 @@ public abstract class AbstractVTKNodeMap implements VT } - @SuppressWarnings("unchecked") @Override public void updateRenderObjectsFor(E node) { List toDelete = new ArrayList(); view.lock(); - for (vtkProp prop : nodeToActor.getValues((E)node)) { + for (vtkProp prop : nodeToActor.getValues(node)) { if (prop.GetVTKId() != 0) { view.getRenderer().RemoveActor(prop); //prop.Delete(); @@ -202,12 +200,12 @@ public abstract class AbstractVTKNodeMap implements VT actorToNode.remove(prop); } view.unlock(); - nodeToActor.remove((E)node); - Collection coll = getActors((E)node); + nodeToActor.remove(node); + Collection coll = getActors(node); if (coll != null) { for (vtkProp prop : coll) { - nodeToActor.add((E)node,prop); - actorToNode.put(prop, (E)node); + nodeToActor.add(node,prop); + actorToNode.put(prop, node); toDelete.remove(prop); } } @@ -227,6 +225,7 @@ public abstract class AbstractVTKNodeMap implements VT } if (changeTracking) { mapping.rangeModified((E)node.getParent()); + mapping.rangeModified((E)node); } added.add(new Pair(node, id)); rangeModified = true; @@ -242,15 +241,16 @@ public abstract class AbstractVTKNodeMap implements VT 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; } repaint(); } - @SuppressWarnings("unchecked") private void receiveUpdate(E node, String id, boolean db) { if (DEBUG) System.out.println("receiveUpdate " + debugString(node) + " " + id + " " + db); synchronized (syncMutex) { @@ -293,10 +293,10 @@ public abstract class AbstractVTKNodeMap implements VT commit(graph); } - }, new Callback() { + }, new Consumer() { @Override - public void run(DatabaseException parameter) { + public void accept(DatabaseException parameter) { if (parameter != null) ExceptionUtils.logAndShowError("Cannot commit editor changes", parameter); } @@ -323,7 +323,6 @@ public abstract class AbstractVTKNodeMap implements VT if (DEBUG)System.out.println("domainModified"); session.asyncRequest(new ReadRequest() { - @SuppressWarnings("unchecked") @Override public void run(ReadGraph graph) throws DatabaseException { update(graph); @@ -356,7 +355,8 @@ public abstract class AbstractVTKNodeMap implements VT synchronized (syncMutex) { graphUpdates = true; for (DBObject domainObject : mapping.getDomainModified()) { - E rangeObject = mapping.get(domainObject); + @SuppressWarnings("unchecked") + E rangeObject = (E) mapping.get(domainObject); if (rangeObject != null) graphModified.add(rangeObject); } @@ -412,6 +412,7 @@ public abstract class AbstractVTKNodeMap implements VT * This code here synchronizes removed and added objects to collect deletable objects. (a deletable object is one which is removed but not added). * */ + @SuppressWarnings("unused") protected void syncDeletes() { deleteUC.clear(); for (Pair n : removed) { @@ -433,11 +434,13 @@ public abstract class AbstractVTKNodeMap implements VT /** * Clears deletable objects from mapping cache. */ + @SuppressWarnings("unused") protected void clearDeletes() { if (DEBUG && delete.size() > 0) System.out.println("Delete"); for (E n : delete) { if (DEBUG) System.out.println(debugString(n)); mapping.getRange().remove(n); + stopListening(n); } delete.clear(); } @@ -623,7 +626,6 @@ public abstract class AbstractVTKNodeMap implements VT if (DEBUG) System.out.println("Node added " + child + " parent " + node); //receiveAdd((E)child, rel ,graphUpdates); receiveAdd((E)child, rel ,graphModified.contains(node)); - } @SuppressWarnings("unchecked") @@ -634,9 +636,10 @@ public abstract class AbstractVTKNodeMap implements VT //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 @@ -678,7 +681,7 @@ public abstract class AbstractVTKNodeMap implements VT } - public IMapping getMapping() { + public IMapping getMapping() { return mapping; }