*******************************************************************************/
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;
synchronized (syncMutex) {
+ // Check for overlapping additions and deletions, prevent deleting objects that are also added.
+ Deque<E> stack = new ArrayDeque<E>();
+ for (Pair<E, String> 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;
+ }
+ }
+ 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);
package org.simantics.g3d.scl;
+import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.Deque;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
synchronized (syncMutex) {
+ // Check for overlapping additions and deletions, prevent deleting objects that are also added.
+ Deque<E> stack = new ArrayDeque<E>();
+ for (Pair<E, String> 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;
+ }
+ }
+ 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()) {
--- /dev/null
+package org.simantics.plant3d.actions;
+
+import org.simantics.g3d.scenegraph.IG3DNode;
+import org.simantics.g3d.vtk.action.RemoveAction;
+import org.simantics.g3d.vtk.common.VTKNodeMap;
+import org.simantics.plant3d.scenegraph.PipelineComponent;
+
+public class RemoveAndSplitAction extends RemoveAction {
+
+ public RemoveAndSplitAction(VTKNodeMap nodeMap) {
+ super(nodeMap);
+ setText("Remove/Split");
+ }
+
+ @Override
+ public boolean isRemovable(IG3DNode node) {
+ if (!super.isRemovable(node))
+ return false;
+ if (!(node instanceof PipelineComponent))
+ return false;
+ PipelineComponent pc = (PipelineComponent)node;
+ if (pc.getNext() != null && pc.getPrevious() != null)
+ return true;
+ else return false;
+ }
+
+
+ @Override
+ protected void doRemove(IG3DNode node) {
+ PipelineComponent pc = (PipelineComponent)node;
+ pc.removeAndSplit();
+ }
+
+}
import org.simantics.plant3d.actions.AddComponentAction;
import org.simantics.plant3d.actions.AddEquipmentAction;
import org.simantics.plant3d.actions.AddNozzleAction;
+import org.simantics.plant3d.actions.RemoveAndSplitAction;
import org.simantics.plant3d.actions.RoutePipeAction;
import org.simantics.plant3d.actions.TranslateInlineAction;
import org.simantics.plant3d.scenegraph.EndComponent;
import org.simantics.plant3d.scenegraph.InlineComponent;
import org.simantics.plant3d.scenegraph.Nozzle;
import org.simantics.plant3d.scenegraph.P3DRootNode;
-import org.simantics.plant3d.scenegraph.PipeRun;
import org.simantics.plant3d.scenegraph.PipelineComponent;
import org.simantics.plant3d.scenegraph.SchemaBuilder;
import org.simantics.plant3d.scenegraph.TurnComponent;
import org.simantics.plant3d.scenegraph.controlpoint.ControlPointFactory;
-import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint;
import org.simantics.plant3d.scenegraph.controlpoint.PipingRules;
import org.simantics.plant3d.utils.ComponentUtils;
import org.simantics.plant3d.utils.Item;
private TranslateInlineAction translateInlineAction;
private RotateAction rotateAction;
private RemoveAction removeAction;
+ private RemoveAndSplitAction removeSplitAction;
private RoutePipeAction routePipeAction;
private AddComponentAction addComponentAction;
removeAction = new RemoveAction(nodeMap) {
public void setNode(IG3DNode node) {
super.setNode(node);
-
-
}
};
+
+ removeSplitAction = new RemoveAndSplitAction(nodeMap);
routePipeAction = new RoutePipeAction(panel,rootNode);
addComponentAction = new AddComponentAction(panel, rootNode);
}
add.setEquipment((Equipment)node);
m.add(add);
}
+ m.add(removeAction);
} else if (node instanceof Nozzle) {
Nozzle nozzle = (Nozzle)node;
if (!nozzle.isFixed()) {
routePipeAction.setEnabled(nozzle.getNext() == null && nozzle.getPrevious() == null);
m.add(addComponentAction);
addComponentAction.setComponent(nozzle);
+ m.add(removeAction);
} else if (node instanceof TurnComponent) {
m.add(translateAction);
TurnComponent component = (TurnComponent)node;
routePipeAction.setEnabled(component.getNext() == null || component.getPrevious() == null);
m.add(addComponentAction);
addComponentAction.setComponent(component);
+ m.add(removeAction);
+ m.add(removeSplitAction);
+ removeSplitAction.setNode(node);
} else if (node instanceof EndComponent) {
m.add(translateAction);
m.add(addComponentAction);
addComponentAction.setComponent((PipelineComponent)node);
+ m.add(removeAction);
} else if (node instanceof InlineComponent) {
//m.add(translateInlineAction);
InlineComponent component = (InlineComponent)node;
routePipeAction.setComponent(component);
m.add(addComponentAction);
addComponentAction.setComponent(component);
+ m.add(removeAction);
+ m.add(removeSplitAction);
+ removeSplitAction.setNode(node);
+ } else {
+ m.add(removeAction);
}
- m.add(removeAction);
+
translateAction.setNode(node);
translateInlineAction.setNode(node);
rotateAction.setNode(node);
}
super.remove();
}
+
+ public void removeAndSplit() {
+ PipeControlPoint pcp = getControlPoint();
+ // Second check is needed, when remove process is initiated from control point.
+ if (pcp != null && pcp.getPipelineComponent() != null) {
+ pcp.removeAndSplit();
+ }
+ super.remove();
+ }
@Override
protected double[] getColor() {
import org.simantics.g3d.property.annotations.GetPropertyValue;
import org.simantics.g3d.scenegraph.G3DNode;
import org.simantics.plant3d.scenegraph.IP3DNode;
+import org.simantics.plant3d.scenegraph.Nozzle;
+import org.simantics.plant3d.scenegraph.P3DRootNode;
import org.simantics.plant3d.scenegraph.PipeRun;
import org.simantics.plant3d.scenegraph.PipelineComponent;
}
}
}
-
+
public void _remove() {
+ _remove(true);
+ }
+
+ public void _remove(boolean renconnect) {
if (component == null && next == null && previous == null)
return;
if (isDualInline() || isDualSub()) {
return;
}
if (currentNext != null && currentPrev != null) {
- boolean link = true;
+ boolean link = renconnect;
if (currentNext.isBranchEnd()) {
link = false;
// currentNext.setPrevious(null);
e.printStackTrace();
}
}
+
+ public void removeAndSplit() {
+ PipeControlPoint currentPrev = previous;
+ PipeControlPoint currentNext = next;
+
+ if (next != null && previous != null) {
+ P3DRootNode root = (P3DRootNode)getPipelineComponent().getRootNode();
+ PipeRun nextPipeRun = new PipeRun();
+ nextPipeRun.setName(root.getUniqueName("PipeRun"));
+ root.addChild(nextPipeRun);
+
+ PipeRun previousRun = previous.getPipeRun();
+ nextPipeRun.setPipeDiameter(previousRun.getPipeDiameter());
+ nextPipeRun.setTurnRadius(previousRun.getTurnRadius());
+
+ PipelineComponent n = next.getPipelineComponent();
+ while (n != null) {
+ if (! (n instanceof Nozzle)) {
+ n.deattach();
+ nextPipeRun.addChild(n);
+ } else
+ n.setPipeRun(nextPipeRun);
+ n = n.getNext();
+ }
+ }
+ _remove(false);
+ try {
+ if (currentNext != null)
+ PipingRules.requestUpdate(currentNext);
+ if (currentPrev != null)
+ PipingRules.requestUpdate(currentPrev);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
private void checkRemove(PipeRun pipeRun) {
Collection<PipeControlPoint> points = pipeRun.getControlPoints();