-/*******************************************************************************\r
- * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.g3d.csg.actions;\r
-\r
-import java.util.Collection;\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.Map;\r
-\r
-import javax.vecmath.Quat4d;\r
-import javax.vecmath.Vector3d;\r
-\r
-import org.eclipse.jface.action.Action;\r
-import org.simantics.g3d.csg.scenegraph2.CSGparentNode;\r
-import org.simantics.g3d.csg.scenegraph2.CSGrootNode;\r
-import org.simantics.g3d.csg.scenegraph2.ICSGnode;\r
-import org.simantics.utils.ui.ExceptionUtils;\r
-\r
-public class AddBooleanOpAction2 extends Action {\r
- CSGrootNode root;\r
- Class<? extends CSGparentNode> booleanClass;\r
- Collection<ICSGnode> nodes;\r
- \r
- public AddBooleanOpAction2(CSGrootNode root, Class<? extends CSGparentNode> booleanClass, Collection<ICSGnode> nodes) {\r
- super();\r
- String name = booleanClass.getSimpleName();\r
- if (name.endsWith("Node"))\r
- name = name.substring(0,name.length()-4);\r
- setText(name);\r
- this.booleanClass = booleanClass;\r
- this.nodes = nodes;\r
- this.root = root;\r
- if (nodes.size() != 2)\r
- setEnabled(false);\r
- for (ICSGnode node : nodes) {\r
- if (!node.getParent().equals(root))\r
- setEnabled(false);\r
- }\r
- }\r
- \r
- @Override\r
- public void run() {\r
- try {\r
- CSGparentNode booleanNode = booleanClass.newInstance();\r
- Map<ICSGnode,Vector3d> positions = new HashMap<ICSGnode, Vector3d>();\r
- Map<ICSGnode,Quat4d> orientations = new HashMap<ICSGnode, Quat4d>();\r
- for (ICSGnode node : nodes) {\r
- positions.put(node, node.getWorldPosition());\r
- orientations.put(node, node.getWorldOrientation());\r
- //root.remChild(node);\r
- node.deattach();\r
- }\r
- Iterator<ICSGnode> iter = nodes.iterator();\r
- booleanNode.addPrimaryChild(iter.next());\r
- booleanNode.addSecondaryChild(iter.next());\r
- \r
- String name = root.getUniqueName(booleanNode.getClass().getSimpleName());\r
- booleanNode.setName(name);\r
- \r
- root.addChild(booleanNode);\r
- for (ICSGnode node : nodes) {\r
- node.setWorldPosition(positions.get(node));\r
- node.setWorldOrientation(orientations.get(node));\r
- }\r
- root.getNodeMap().commit();\r
- } catch (Exception e) {\r
- ExceptionUtils.logAndShowError("Cannot create boolean operation.", e);\r
- }\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.g3d.csg.actions;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.vecmath.Quat4d;
+import javax.vecmath.Vector3d;
+
+import org.eclipse.jface.action.Action;
+import org.simantics.g3d.csg.scenegraph2.CSGparentNode;
+import org.simantics.g3d.csg.scenegraph2.CSGrootNode;
+import org.simantics.g3d.csg.scenegraph2.ICSGnode;
+import org.simantics.utils.ui.ExceptionUtils;
+
+public class AddBooleanOpAction2 extends Action {
+ CSGrootNode root;
+ Class<? extends CSGparentNode> booleanClass;
+ Collection<ICSGnode> nodes;
+
+ public AddBooleanOpAction2(CSGrootNode root, Class<? extends CSGparentNode> booleanClass, Collection<ICSGnode> nodes) {
+ super();
+ String name = booleanClass.getSimpleName();
+ if (name.endsWith("Node"))
+ name = name.substring(0,name.length()-4);
+ setText(name);
+ this.booleanClass = booleanClass;
+ this.nodes = nodes;
+ this.root = root;
+ if (nodes.size() != 2)
+ setEnabled(false);
+ for (ICSGnode node : nodes) {
+ if (!node.getParent().equals(root))
+ setEnabled(false);
+ }
+ }
+
+ @Override
+ public void run() {
+ try {
+ CSGparentNode booleanNode = booleanClass.newInstance();
+ Map<ICSGnode,Vector3d> positions = new HashMap<ICSGnode, Vector3d>();
+ Map<ICSGnode,Quat4d> orientations = new HashMap<ICSGnode, Quat4d>();
+ for (ICSGnode node : nodes) {
+ positions.put(node, node.getWorldPosition());
+ orientations.put(node, node.getWorldOrientation());
+ //root.remChild(node);
+ node.deattach();
+ }
+ Iterator<ICSGnode> iter = nodes.iterator();
+ booleanNode.addPrimaryChild(iter.next());
+ booleanNode.addSecondaryChild(iter.next());
+
+ String name = root.getUniqueName(booleanNode.getClass().getSimpleName());
+ booleanNode.setName(name);
+
+ root.addChild(booleanNode);
+ for (ICSGnode node : nodes) {
+ node.setWorldPosition(positions.get(node));
+ node.setWorldOrientation(orientations.get(node));
+ }
+ root.getNodeMap().commit("Add Boolean Op");
+ } catch (Exception e) {
+ ExceptionUtils.logAndShowError("Cannot create boolean operation.", e);
+ }
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.g3d.csg.actions;\r
-\r
-import org.eclipse.jface.action.Action;\r
-import org.simantics.g3d.csg.scenegraph2.CSGnode;\r
-import org.simantics.g3d.csg.scenegraph2.CSGrootNode;\r
-import org.simantics.utils.ui.ExceptionUtils;\r
-\r
-public class AddPrimitiveAction2 extends Action {\r
- \r
- CSGrootNode root;\r
- Class<? extends CSGnode> primitiveClass;\r
- public AddPrimitiveAction2(CSGrootNode root, Class<? extends CSGnode> primitiveClass) {\r
- super();\r
- String name = primitiveClass.getSimpleName();\r
- if (name.endsWith("Node"))\r
- name = name.substring(0,name.length()-4);\r
- setText(name);\r
- this.primitiveClass = primitiveClass;\r
- this.root = root;\r
- }\r
- \r
- @Override\r
- public void run() {\r
- try {\r
- CSGnode node = primitiveClass.newInstance();\r
- String name = root.getUniqueName(node.getClass().getSimpleName());\r
- node.setName(name);\r
- root.addChild(node);\r
- root.getNodeMap().commit();\r
- } catch (Exception e) {\r
- ExceptionUtils.logAndShowError("Cannot create primitive.", e);\r
- }\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.g3d.csg.actions;
+
+import org.eclipse.jface.action.Action;
+import org.simantics.g3d.csg.scenegraph2.CSGnode;
+import org.simantics.g3d.csg.scenegraph2.CSGrootNode;
+import org.simantics.utils.ui.ExceptionUtils;
+
+public class AddPrimitiveAction2 extends Action {
+
+ CSGrootNode root;
+ Class<? extends CSGnode> primitiveClass;
+ public AddPrimitiveAction2(CSGrootNode root, Class<? extends CSGnode> primitiveClass) {
+ super();
+ String name = primitiveClass.getSimpleName();
+ if (name.endsWith("Node"))
+ name = name.substring(0,name.length()-4);
+ setText(name);
+ this.primitiveClass = primitiveClass;
+ this.root = root;
+ }
+
+ @Override
+ public void run() {
+ try {
+ CSGnode node = primitiveClass.newInstance();
+ String name = root.getUniqueName(node.getClass().getSimpleName());
+ node.setName(name);
+ root.addChild(node);
+ root.getNodeMap().commit("Add primitive");
+ } catch (Exception e) {
+ ExceptionUtils.logAndShowError("Cannot create primitive.", e);
+ }
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.g3d.csg.actions;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-import javax.vecmath.Quat4d;\r
-import javax.vecmath.Vector3d;\r
-\r
-import org.eclipse.jface.action.Action;\r
-import org.simantics.g3d.csg.scenegraph2.CSGparentNode;\r
-import org.simantics.g3d.csg.scenegraph2.CSGrootNode;\r
-import org.simantics.g3d.csg.scenegraph2.ICSGnode;\r
-\r
-public class SplitBooleanOpAction2 extends Action {\r
- private CSGrootNode root;\r
- private CSGparentNode booleanOp;\r
- \r
- public SplitBooleanOpAction2(CSGrootNode root, CSGparentNode booleanOp) {\r
- super();\r
- setText("Split");\r
- this.booleanOp = booleanOp;\r
- this.root = root;\r
- }\r
- \r
- @Override\r
- public void run() {\r
- Collection<ICSGnode> nodes = new ArrayList<ICSGnode>();\r
- nodes.addAll(booleanOp.getPrimaryChild());\r
- nodes.addAll(booleanOp.getSecondaryChild());\r
- Map<ICSGnode,Vector3d> positions = new HashMap<ICSGnode, Vector3d>();\r
- Map<ICSGnode,Quat4d> orientations = new HashMap<ICSGnode, Quat4d>();\r
- for (ICSGnode node : nodes) {\r
- positions.put(node, node.getWorldPosition());\r
- orientations.put(node, node.getWorldOrientation());\r
- node.deattach();\r
- }\r
- for (ICSGnode node : nodes) {\r
- root.addChild(node);\r
- node.setWorldPosition(positions.get(node));\r
- node.setWorldOrientation(orientations.get(node));\r
- }\r
- root.remChild(booleanOp);\r
- root.getNodeMap().commit();\r
-\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.g3d.csg.actions;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.vecmath.Quat4d;
+import javax.vecmath.Vector3d;
+
+import org.eclipse.jface.action.Action;
+import org.simantics.g3d.csg.scenegraph2.CSGparentNode;
+import org.simantics.g3d.csg.scenegraph2.CSGrootNode;
+import org.simantics.g3d.csg.scenegraph2.ICSGnode;
+
+public class SplitBooleanOpAction2 extends Action {
+ private CSGrootNode root;
+ private CSGparentNode booleanOp;
+
+ public SplitBooleanOpAction2(CSGrootNode root, CSGparentNode booleanOp) {
+ super();
+ setText("Split");
+ this.booleanOp = booleanOp;
+ this.root = root;
+ }
+
+ @Override
+ public void run() {
+ Collection<ICSGnode> nodes = new ArrayList<ICSGnode>();
+ nodes.addAll(booleanOp.getPrimaryChild());
+ nodes.addAll(booleanOp.getSecondaryChild());
+ Map<ICSGnode,Vector3d> positions = new HashMap<ICSGnode, Vector3d>();
+ Map<ICSGnode,Quat4d> orientations = new HashMap<ICSGnode, Quat4d>();
+ for (ICSGnode node : nodes) {
+ positions.put(node, node.getWorldPosition());
+ orientations.put(node, node.getWorldOrientation());
+ node.deattach();
+ }
+ for (ICSGnode node : nodes) {
+ root.addChild(node);
+ node.setWorldPosition(positions.get(node));
+ node.setWorldOrientation(orientations.get(node));
+ }
+ root.remChild(booleanOp);
+ root.getNodeMap().commit("Split");
+
+ }
+
+}
-/*******************************************************************************\r
- * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.g3d.vtk.action;\r
-\r
-import org.eclipse.jface.action.Action;\r
-import org.simantics.g3d.scenegraph.IG3DNode;\r
-import org.simantics.g3d.scenegraph.structural.IStructuralNode;\r
-import org.simantics.g3d.vtk.Activator;\r
-import org.simantics.g3d.vtk.common.VTKNodeMap;\r
-\r
-public class RemoveAction extends Action {\r
-\r
- private VTKNodeMap nodeMap;\r
- protected IG3DNode node;\r
- \r
- public RemoveAction(VTKNodeMap nodeMap) {\r
- setText("Remove");\r
- setImageDescriptor(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/delete.png"));\r
- this.nodeMap = nodeMap;\r
- }\r
- \r
- public void setNode(IG3DNode node) {\r
- this.node = node;\r
- setEnabled(isRemovable(node));\r
- }\r
- \r
- public boolean isRemovable(IG3DNode node) {\r
- if ((node instanceof IStructuralNode) && ((IStructuralNode)node).isPartOfInstantiatedModel() && !((IStructuralNode)node).isInstantiatedModelRoot())\r
- return false;\r
- return true;\r
- }\r
- \r
- @Override\r
- public void run() {\r
- \r
- doRemove(node);\r
- nodeMap.commit();\r
- node = null;\r
- }\r
- \r
- protected void doRemove(IG3DNode node) {\r
- node.remove();\r
- }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.g3d.vtk.action;
+
+import org.eclipse.jface.action.Action;
+import org.simantics.g3d.scenegraph.IG3DNode;
+import org.simantics.g3d.scenegraph.structural.IStructuralNode;
+import org.simantics.g3d.vtk.Activator;
+import org.simantics.g3d.vtk.common.VTKNodeMap;
+
+public class RemoveAction extends Action {
+
+ private VTKNodeMap nodeMap;
+ protected IG3DNode node;
+
+ public RemoveAction(VTKNodeMap nodeMap) {
+ setText("Remove");
+ setImageDescriptor(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/delete.png"));
+ this.nodeMap = nodeMap;
+ }
+
+ public void setNode(IG3DNode node) {
+ this.node = node;
+ setEnabled(isRemovable(node));
+ }
+
+ public boolean isRemovable(IG3DNode node) {
+ if ((node instanceof IStructuralNode) && ((IStructuralNode)node).isPartOfInstantiatedModel() && !((IStructuralNode)node).isInstantiatedModelRoot())
+ return false;
+ return true;
+ }
+
+ @Override
+ public void run() {
+
+ doRemove(node);
+ nodeMap.commit("Remove");
+ node = null;
+ }
+
+ protected void doRemove(IG3DNode node) {
+ node.remove();
+ }
+}
public void deattach() {
node = null;
- nodeMap.commit();
+ nodeMap.commit("Rotate");
deattachUI();
super.deattach();
panel.repaint();
public void deattach() {
node = null;
- nodeMap.commit();
+ nodeMap.commit("Translate");
deattachUI();
super.deattach();
panel.repaint();
import org.simantics.db.common.request.ReadRequest;
import org.simantics.db.common.request.WriteRequest;
import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.util.Layer0Utils;
import org.simantics.g3d.ontology.G3D;
import org.simantics.g3d.scenegraph.RenderListener;
import org.simantics.g3d.scenegraph.base.INode;
private Set<E> graphModified = new HashSet<E>();
private boolean requestCommit = false;
+ private String commitMessage = null;
@Override
- public void commit() {
+ public void commit(String message) {
requestCommit = true;
+ commitMessage = message;
}
protected void doCommit() {
@Override
public void perform(WriteGraph graph) throws DatabaseException {
commit(graph);
+ if (commitMessage != null) {
+ Layer0Utils.addCommentMetadata(graph, commitMessage);
+ commitMessage = null;
+ }
+ graph.markUndoPoint();
}
}, new Callback<DatabaseException>() {
}
if (mapping.isRangeModified())
- commit();
+ commit("Graph sync");
}
@Override
public void deattach() {
node = null;
- nodeMap.commit();
+ nodeMap.commit("Rotate");
deattachUI();
super.deattach();
panel.refresh();
public void deattach() {
node = null;
- nodeMap.commit();
+ nodeMap.commit("Translate");
deattachUI();
super.deattach();
panel.refresh();
if (DEBUG)System.err.println("CELL SET VALUE: " + element + " " + value);
manipulator.setValue((String)value,index);
viewer.refresh(item);
- nodeMap.commit();
+ nodeMap.commit("Set " + item.id + " value to " + value);
}
/**
* Commit changes to the database.
*/
- public void commit();
+ public void commit(String message);
/**
public void deattach() {
// deactivate();
component = null;
- nodeMap.commit();
+ nodeMap.commit("Add component");
deattachUI();
super.deattach();
panel.refresh();
String n = root.getUniqueName(item.getName());
equipment.setName(n);
root.addChild(equipment);
- root.getNodeMap().commit();
+ root.getNodeMap().commit("Add equipment " + n);
} catch (Exception e) {
ExceptionUtils.logAndShowError("Cannot create equipment",e);
}
equipment.addChild(nozzle);
//root.addChild(nozzle);
root.addChild(pipeRun);
- root.getNodeMap().commit();
+ root.getNodeMap().commit("Add nozzle " + n);
} catch (Exception e) {
ExceptionUtils.logAndShowError("Cannot create equipment",e);
}
public void deattach() {
deactivate();
startComponent = null;
- nodeMap.commit();
+ nodeMap.commit("Route pipe");
deattachUI();
super.deattach();
panel.refresh();
setEnabled(false);
return;
}
- if (prev.getControlPoint().isInline() && !prev.getControlPoint().isFixed())
+ if (prev.getControlPoint().isInline() && !prev.getControlPoint().isFixed() && prev.getPrevious() != null)
prev = prev.getPrevious();
- if (next.getControlPoint().isInline() && !next.getControlPoint().isFixed()) {
+ if (next.getControlPoint().isInline() && !next.getControlPoint().isFixed() && next.getNext() != null) {
next = next.getNext();
}
Point3d ns = new Point3d();
dir.normalize();
// We may have offsets in the path leg, hence we have to project the coordinates.
Vector3d wp = node.getWorldPosition();
- s = MathTools.closestPointOnStraight(pe, wp, dir);
- e = MathTools.closestPointOnStraight(ns, wp, dir);
+ if (prev.getControlPoint().isVariableLength())
+ s = MathTools.closestPointOnStraight(ps, wp, dir);
+ else
+ s = MathTools.closestPointOnStraight(pe, wp, dir);
+ if (next.getControlPoint().isVariableLength())
+ e = MathTools.closestPointOnStraight(ne, wp, dir);
+ else
+ e = MathTools.closestPointOnStraight(ns, wp, dir);
// Remove component's own space from end points to get actual movement range
double l = comp.getControlPoint().getInlineLength();
Vector3d ld = new Vector3d(dir);
}
@Override
- public void commit() {
+ public void commit(String commitMessage) {
validate();
// System.out.println("Graph commit");
- super.commit();
+ super.commit(commitMessage);
}
@Override