*******************************************************************************/
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;
public abstract class AbstractVTKNodeMap<E extends INode> implements VTKNodeMap<E>, IMappingListener, RenderListener, NodeListener, UndoRedoSupport.ChangeListener{
- private static final boolean DEBUG = false;
+ private static final boolean DEBUG = true;
protected Session session;
protected IMapping<Object,E> mapping;
return n + "@" + Integer.toHexString(n.hashCode());
}
+ protected boolean filterChange(List<Pair<E,String>> 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();
synchronized (syncMutex) {
+ // Check for overlapping additions and deletions, prevent deleting objects that are also added and vice versa.
+ Deque<E> stack = new ArrayDeque<E>();
+ for (Pair<E, String> n : added) {
+ stack.add(n.first);
+ }
+ while (!stack.isEmpty()) {
+ E n = stack.pop();
+ boolean conflict = filterChange(removed, n);
+ if (conflict) {
+ filterChange(added, n);
+ }
+ if (n instanceof ParentNode) {
+ ParentNode<INode> pn = (ParentNode<INode>)n;
+ for (INode cn : pn.getNodes()) {
+ stack.push((E)cn);
+ }
+ }
+ }
+
rem.addAll(removed);
add.addAll(added);
for (E e : updated.getKeys()) {
updated.clear();
}
+
+
for (Pair<E, String> n : rem) {
stopListening(n.first);
removeActor(n.first);