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;
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;
private static final boolean DEBUG = false;
protected Session session;
- protected IMapping<DBObject,E> mapping;
+ protected IMapping<DBObject, INode> mapping;
protected VtkView view;
private MapList<E, vtkProp> nodeToActor = new MapList<E, vtkProp>();
protected int redoOpCount = 0;
protected boolean runUndo = false;
protected boolean runRedo = false;
- public AbstractVTKNodeMap(Session session, IMapping<DBObject,E> mapping, VtkView view, ParentNode<E> rootNode) {
+ public AbstractVTKNodeMap(Session session, IMapping<DBObject,INode> mapping, VtkView view, ParentNode<E> rootNode) {
this.session = session;
this.mapping = mapping;
this.view = view;
@SuppressWarnings("unchecked")
@Override
public Collection<vtkProp> getRenderObjects(INode node) {
- return nodeToActor.getValues((E)node);
+ return nodeToActor.getValues((E) node);
}
protected <T extends vtkProp> void map(E node, Collection<T> props) {
protected void removeMap(E node) {
Collection<vtkProp> coll = nodeToActor.getValuesUnsafe(node);
- for (vtkProp p : coll) {
- actorToNode.remove(p);
+ if (coll.size() > 0) {
+ view.lock();
+ for (vtkProp p : coll) {
+ actorToNode.remove(p);
+ if (p.GetVTKId() != 0) {
+ view.getRenderer().RemoveActor(p);
+ p.Delete();
+ }
+ }
+ view.unlock();
}
nodeToActor.remove(node);
}
- @SuppressWarnings("unchecked")
@Override
public ParentNode<E> getRootNode() {
return (ParentNode<E>)rootNode;
}
- @SuppressWarnings("unchecked")
@Override
public void updateRenderObjectsFor(E node) {
List<vtkProp> toDelete = new ArrayList<vtkProp>();
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();
actorToNode.remove(prop);
}
view.unlock();
- nodeToActor.remove((E)node);
- Collection<vtkProp> coll = getActors((E)node);
+ nodeToActor.remove(node);
+ Collection<vtkProp> 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);
}
}
}
if (changeTracking) {
mapping.rangeModified((E)node.getParent());
+ mapping.rangeModified((E)node);
}
added.add(new Pair<E, String>(node, id));
rangeModified = true;
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<E, String>(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) {
commit(graph);
}
- }, new Callback<DatabaseException>() {
+ }, new Consumer<DatabaseException>() {
@Override
- public void run(DatabaseException parameter) {
+ public void accept(DatabaseException parameter) {
if (parameter != null)
ExceptionUtils.logAndShowError("Cannot commit editor changes", parameter);
}
if (DEBUG)System.out.println("domainModified");
session.asyncRequest(new ReadRequest() {
- @SuppressWarnings("unchecked")
@Override
public void run(ReadGraph graph) throws DatabaseException {
update(graph);
if (runUndo && useFullSyncWithUndo) {
reset(graph);
} else {
- synchronized (syncMutex) {
+ 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);
}
syncDeletes();
clearDeletes();
graphUpdates = false;
- }
+ }
}
if (mapping.isRangeModified() && !runUndo && !runRedo)
* 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<E, String> n : removed) {
/**
* 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();
}
E n = stack.pop();
boolean conflict = filterChange(removed, n);
if (conflict) {
- System.out.println("Prevent removing " + n);
+ if (DEBUG) System.out.println("Prevent removing " + n);
//filterChange(added, n)
if (filterChange(added, n))
- System.out.println("Prevent adding " + n);
+ if (DEBUG) System.out.println("Prevent adding " + n);
}
if (n instanceof ParentNode) {
ParentNode<INode> pn = (ParentNode<INode>)n;
}
-
for (Pair<E, String> n : rem) {
stopListening(n.first);
removeActor(n.first);
+ n.first.remove();
}
- for (Pair<E, String> n : add) {
- addActor(n.first);
- listen(n.first);
- }
+ for (Pair<E, String> n : add) {
+ addActor(n.first);
+ listen(n.first);
+ }
for (E e : mod.getKeys()) {
Set<String> ids = mod.getValues(e);
}
}
-// synchronized (syncMutex) {
-// rem.addAll(removed);
-// add.addAll(added);
-// //mod.addAll(updated);
-// for (E e : updated.getKeys()) {
-// for (String s : updated.getValues(e))
-// mod.add(e, s);
-// }
-//
-// removed.clear();
-// added.clear();
-// updated.clear();
-// }
-
for (E e : mod.getKeys()) {
Set<String> ids = mod.getValues(e);
updateActor(e,ids);
}
-
-
+
for (Pair<E, String> n : rem) {
for (NodeListener l : nodeListeners)
l.nodeRemoved(null, n.first, n.second);
if (DEBUG) System.out.println("Node added " + child + " parent " + node);
//receiveAdd((E)child, rel ,graphUpdates);
receiveAdd((E)child, rel ,graphModified.contains(node));
-
}
@SuppressWarnings("unchecked")
//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 call:
+ //stopListening(child);
}
@Override
}
- public IMapping<DBObject,E> getMapping() {
+ public IMapping<DBObject,INode> getMapping() {
return mapping;
}