</with>\r
</activeWhen>\r
</handler>\r
+ <handler\r
+ class="org.simantics.modeling.ui.modelBrowser.handlers.StandardCopyHandler"\r
+ commandId="org.eclipse.ui.edit.copy">\r
+ <enabledWhen>\r
+ <not>\r
+ <count\r
+ value="0">\r
+ </count>\r
+ </not>\r
+ </enabledWhen>\r
+ <activeWhen>\r
+ <with\r
+ variable="selection">\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.EnumerationNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ </with>\r
+ </activeWhen>\r
+ </handler>\r
+ <handler\r
+ class="org.simantics.modeling.ui.modelBrowser.handlers.StandardPasteHandler"\r
+ commandId="org.eclipse.ui.edit.paste">\r
+ <enabledWhen>\r
+ <not>\r
+ <count\r
+ value="0">\r
+ </count>\r
+ </not>\r
+ </enabledWhen>\r
+ <activeWhen>\r
+ <with\r
+ variable="selection">\r
+ <and>\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ <not>\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.ModuleNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ </not>\r
+ </and>\r
+ </with>\r
+ </activeWhen>\r
+ </handler>\r
</extension>\r
<extension\r
point="org.simantics.browsing.ui.common.viewpointContributionBinding">\r
/*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2007, 2011 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
import org.simantics.sysdyn.ui.utils.VariableNameUtils;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.utils.datastructures.Callback;\r
+import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
import org.simantics.utils.datastructures.hints.IHintListener;\r
import org.simantics.utils.datastructures.hints.IHintObservable;\r
-import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
\r
/**\r
* ElementHandler for text elements\r
super(originX, originY, horizontalAlignment, borderWidth, paddingX, paddingY, editable);\r
}\r
\r
- @Override\r
- public void init(final IElement e, G2DParentNode parent) {\r
- HoverTextNode node = ElementUtils.getOrCreateNode(e, parent, SG_NODE, "text", HoverTextNode.class, new Callback<HoverTextNode>() {\r
+ protected HoverTextNode getTextNode(IElement e, G2DParentNode parent) {\r
+ return ElementUtils.getOrCreateNode(e, parent, SG_NODE, "text", HoverTextNode.class, getCallback(e, parent, HoverTextNode.class));\r
+ }\r
+ \r
+ protected <T extends HoverTextNode> Callback<T> getCallback(final IElement e, G2DParentNode parent, Class<T> nodeClass) {\r
+ return new Callback<T>() {\r
@Override\r
- public void run(HoverTextNode node) {\r
+ public void run(T node) {\r
node.setTextListener(new ITextListener() {\r
\r
String textBeforeEdit;\r
}\r
});\r
}\r
- });\r
+ };\r
+ }\r
+\r
+ @Override\r
+ public void init(final IElement e, G2DParentNode parent) {\r
+ HoverTextNode node = getTextNode(e, parent);\r
\r
//Font font = new Font("Tahoma", 0, 12);\r
Font font = ElementUtils.getTextFont(e);\r
/*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2007, 2011 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
import java.awt.geom.Rectangle2D;\r
\r
import org.simantics.diagram.elements.TextNode;\r
-import org.simantics.g2d.utils.Alignment;\r
import org.simantics.scenegraph.ISelectionPainterNode;\r
import org.simantics.scenegraph.utils.NodeUtil;\r
\r
\r
private static final long serialVersionUID = 3539499125943249895L;\r
- private static transient ThreadLocal<Rectangle2D> tempBounds = new ThreadLocal<Rectangle2D>() {\r
+ protected static transient ThreadLocal<Rectangle2D> tempBounds = new ThreadLocal<Rectangle2D>() {\r
@Override\r
protected Rectangle2D initialValue() {\r
return new Rectangle2D.Double();\r
/*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2007, 2011 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
\r
import org.simantics.db.Resource;\r
import org.simantics.g2d.element.ElementClass;\r
+import org.simantics.g2d.element.ElementUtils;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.handler.InternalSize;\r
import org.simantics.g2d.element.handler.impl.BoundsOutline;\r
import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
import org.simantics.g2d.element.handler.impl.ObjectTerminal;\r
import org.simantics.g2d.image.Image;\r
import org.simantics.g2d.image.impl.ShapeImage;\r
import org.simantics.g2d.utils.Alignment;\r
+import org.simantics.scenegraph.g2d.G2DParentNode;\r
\r
public class ModuleFactory extends SysdynElementFactory {\r
\r
- private static final BasicStroke STROKE = new BasicStroke(1f);\r
+ private static final BasicStroke STROKE = new BasicStroke(2.0f);\r
private static final Image DEFAULT_IMAGE = new ShapeImage(new Rectangle2D.Double(-5, -2.5, 10, 5), null, STROKE, true);\r
\r
@Override\r
new StaticObjectAdapter(elementType),\r
new StaticSymbolImpl(DEFAULT_IMAGE),\r
StaticSymbolImageInitializer.INSTANCE,\r
- new HoverTextElementHandler(0, 0, Alignment.LEADING, 1f , 7, 7, true),\r
+ new ModuleSceneGraph(0, 0, Alignment.LEADING, 1f , 4, 4, true),\r
BoundsOutline.INSTANCE,\r
new WholeElementTerminals(terminals)\r
).setId(ModuleFactory.class.getSimpleName());\r
}\r
+ \r
+ \r
+ public static class ModuleSceneGraph extends HoverTextElementHandler implements InternalSize {\r
\r
+ private static final long serialVersionUID = 2367230056477661273L;\r
+ \r
+ public ModuleSceneGraph(double originX, double originY, Alignment horizontalAlignment, double borderWidth,\r
+ double paddingX, double paddingY, boolean editable) {\r
+ super(originX, originY, horizontalAlignment, borderWidth, paddingX, paddingY, editable);\r
+ }\r
+ \r
+ protected HoverTextNode getTextNode(IElement e, G2DParentNode parent) {\r
+ return ElementUtils.getOrCreateNode(e, parent, SG_NODE, "text", ModuleNode.class, getCallback(e, parent, ModuleNode.class));\r
+ }\r
+\r
+ }\r
}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 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.sysdyn.ui.elements2;\r
+\r
+import java.awt.AlphaComposite;\r
+import java.awt.BasicStroke;\r
+import java.awt.Color;\r
+import java.awt.Composite;\r
+import java.awt.Graphics2D;\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.geom.Path2D;\r
+import java.awt.geom.Rectangle2D;\r
+\r
+import org.simantics.scenegraph.utils.GeometryUtils;\r
+import org.simantics.scenegraph.utils.NodeUtil;\r
+\r
+public class ModuleNode extends HoverTextNode {\r
+\r
+ private static final long serialVersionUID = 8535695797227320496L;\r
+ private static double CORNER_LENGTH = 2.0; \r
+ private static double CORNER_PADDING = 0.8; \r
+ \r
+ \r
+ @Override\r
+ public void render(Graphics2D g) {\r
+ super.render(g);\r
+ \r
+ AffineTransform ot = g.getTransform();\r
+ BasicStroke oldStroke = (BasicStroke)g.getStroke();\r
+ Color oldColor = g.getColor();\r
+\r
+ \r
+ g.transform(transform);\r
+ \r
+ Rectangle2D bounds = expandBounds( alignBounds( getTightUnalignedBoundsInLocal( tempBounds.get() ) ) );\r
+\r
+ Path2D path = new Path2D.Double();\r
+ // LEFT TOP\r
+ path.moveTo(bounds.getMinX() + CORNER_LENGTH, bounds.getMinY() - CORNER_PADDING);\r
+ path.lineTo(bounds.getMinX() - CORNER_PADDING, bounds.getMinY() - CORNER_PADDING);\r
+ path.lineTo(bounds.getMinX() - CORNER_PADDING, bounds.getMinY() + CORNER_LENGTH);\r
+ \r
+ // LEFT BOTTOM\r
+ path.moveTo(bounds.getMinX() + CORNER_LENGTH, bounds.getMaxY() + CORNER_PADDING);\r
+ path.lineTo(bounds.getMinX() - CORNER_PADDING, bounds.getMaxY() + CORNER_PADDING);\r
+ path.lineTo(bounds.getMinX() - CORNER_PADDING, bounds.getMaxY() - CORNER_LENGTH);\r
+ \r
+ // RIGHT TOP\r
+ path.moveTo(bounds.getMaxX() - CORNER_LENGTH, bounds.getMinY() - CORNER_PADDING);\r
+ path.lineTo(bounds.getMaxX() + CORNER_PADDING, bounds.getMinY() - CORNER_PADDING);\r
+ path.lineTo(bounds.getMaxX() + CORNER_PADDING, bounds.getMinY() + CORNER_LENGTH);\r
+ \r
+ // RIGHT BOTTOM\r
+ path.moveTo(bounds.getMaxX() - CORNER_LENGTH, bounds.getMaxY() + CORNER_PADDING);\r
+ path.lineTo(bounds.getMaxX() + CORNER_PADDING, bounds.getMaxY() + CORNER_PADDING);\r
+ path.lineTo(bounds.getMaxX() + CORNER_PADDING, bounds.getMaxY() - CORNER_LENGTH);\r
+ \r
+ g.translate(x, y);\r
+ g.setStroke(new BasicStroke((float) (scale*borderWidth))); \r
+ g.setColor(Color.GRAY);\r
+ g.draw(path); \r
+ \r
+ \r
+ boolean selected = NodeUtil.isSelected(this, 1);\r
+ if (selected && showSelection()) {\r
+ Composite oc = g.getComposite();\r
+ g.setComposite(AlphaComposite.SrcAtop.derive(0.5f));\r
+\r
+ g.setColor(Color.RED);\r
+ float bw = borderWidth;\r
+ double s = GeometryUtils.getScale(g.getTransform());\r
+ if (bw <= 0f) {\r
+ bw = (float) (1f / s);\r
+ } else {\r
+ bw *= 3f * scale;\r
+ }\r
+ g.setStroke(new BasicStroke(bw));\r
+ g.draw(path);\r
+ //g.draw(GeometryUtils.expandRectangle(r, 1.0));\r
+\r
+ g.setComposite(oc);\r
+ }\r
+ \r
+ g.setColor(oldColor);\r
+ g.setStroke(oldStroke);\r
+ g.translate(-x, -y);\r
+ \r
+ g.setTransform(ot);\r
+ }\r
+\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 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.sysdyn.ui.handlers;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+\r
+public class EnumerationPasteHandler extends AbstractHandler {\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+ ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+ System.out.println("PASTE " + sel);\r
+ return null;\r
+ }\r
+\r
+}\r
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 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.sysdyn.ui.properties;\r
\r
+import java.util.HashSet;\r
import java.util.List;\r
\r
import org.eclipse.jface.layout.GridDataFactory;\r
import org.simantics.db.WriteGraph;\r
import org.simantics.db.common.request.ReadRequest;\r
import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.common.utils.OrderedSetUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.variable.Variable;\r
public void perform(WriteGraph graph) throws DatabaseException {\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
Layer0 l0 = Layer0.getInstance(graph);\r
-\r
-\r
+ \r
+ HashSet<String> names = new HashSet<String>();\r
+ for(Resource r : OrderedSetUtils.toList(graph, enumerationIndexes)) {\r
+ names.add(NameUtils.getSafeName(graph, r));\r
+ }\r
+ \r
Resource ei = GraphUtils.create2(graph, \r
sr.EnumerationIndex,\r
- l0.HasName, "index");\r
+ l0.HasName, NameUtils.findFreshName(graph, "index", names, ""));\r
OrderedSetUtils.add(graph, enumerationIndexes, ei);\r
}\r
});\r
/*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2007, 2011 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
}\r
\r
// VARIABLE NAMES\r
+ \r
+ if(variables.contains("time"))\r
+ variables.remove("time");\r
\r
for(String v : variables) {\r
if(!modelVariables.keySet().contains(v)) {\r