G2D.HasSVGDocument """<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" overflow="visible" version="1.1"><g style="fill:#000000;fill-opacity:1;stroke:none"><path d="m 4.2699962,-2.1489344 -0.4716797,0 C 3.7572928,-2.3129896 3.6832369,-2.5078137 3.5761485,-2.733407 3.4690444,-2.9589851 3.3494156,-3.1720383 3.2172618,-3.3725672 3.0805357,-3.5821941 2.9312845,-3.7656249 2.7695079,-3.9228601 2.6077171,-4.0800777 2.4516301,-4.1700841 2.3012462,-4.1928797 2.1599637,-4.2110997 1.9822295,-4.2247716 1.768043,-4.2338953 1.5538445,-4.2430007 1.3556025,-4.247558 1.1733165,-4.2475672 l -0.3964844,0 0,7.7587891 c -5.05e-6,0.1503919 0.031896,0.2882498 0.0957031,0.4135742 0.0637969,0.1253264 0.17545037,0.2221687 0.33496097,0.2905273 0.082026,0.031902 0.2540632,0.075196 0.5161132,0.1298829 0.2620381,0.054688 0.4659766,0.08431 0.6118165,0.088867 l 0,0.4853516 -4.5800782,0 0,-0.4853516 c 0.127602,-0.00911 0.3224261,-0.027343 0.5844727,-0.054687 0.2620414,-0.027343 0.4431935,-0.061523 0.543457,-0.102539 0.15038733,-0.059244 0.26090154,-0.1446932 0.33154298,-0.2563477 0.0706345,-0.1116526 0.10595343,-0.2609038 0.10595704,-0.4477539 l 0,-7.8203125 -0.39648442,0 c -0.1412791,9.2e-6 -0.3167346,0.00343 -0.5263671,0.010254 -0.2096379,0.00685 -0.4101586,0.021656 -0.6015625,0.044434 -0.1503926,0.018238 -0.3064797,0.1082447 -0.4682618,0.2700196 -0.1617853,0.1617925 -0.3110364,0.3452233 -0.4477539,0.5502929 -0.1367197,0.2050862 -0.2574879,0.4226967 -0.3623047,0.6528321 -0.1048184,0.2301506 -0.177735,0.4204173 -0.21875,0.5708007 l -0.4785156,0 0,-2.6318359 8.4492188,0 z" /></g></svg>""" : L0.String\r
\r
SYSDYN.Loop <T SYSDYN.Component <T DIA.FontProvider <T DIA.ColorProvider //<T DIA.TextElement\r
- >-- SYSDYN.Loop.Clockwise --> L0.Boolean <R L0.ConsistsOf : L0.FunctionalRelation\r
>-- SYSDYN.Loop.Comment --> L0.String <R L0.ConsistsOf : L0.FunctionalRelation\r
>-- SYSDYN.Loop.Items --> L0.List <R L0.DependsOn : L0.FunctionalRelation\r
- @L0.assert SYSDYN.Loop.Clockwise L0.True\r
@L0.assert SYSDYN.Loop.Comment "$$AUTO$$"\r
@L0.assert G2D.HasFont SYSDYN.DefaultFont \r
@L0.assert G2D.HasColor \r
\r
SYSDYN.LoopSymbol <T SYSDYN.SysdynSymbol\r
@MOD.defSymbol "Loop" SYSDYN.Loop\r
+ >-- SYSDYN.LoopSymbol.Clockwise --> L0.Boolean <R L0.ConsistsOf : L0.FunctionalRelation\r
+ @L0.assert SYSDYN.LoopSymbol.Clockwise L0.True\r
L0.HasDescription "(Shift+L)"\r
L0.IsDependencyOf GENERAL\r
G2D.HasSVGDocument \r
public final Resource LookupExpression_lookup_Inverse;\r
public final Resource Loop;\r
public final Resource LoopSymbol;\r
- public final Resource Loop_Clockwise;\r
- public final Resource Loop_Clockwise_Inverse;\r
+ public final Resource LoopSymbol_Clockwise;\r
+ public final Resource LoopSymbol_Clockwise_Inverse;\r
public final Resource Loop_Comment;\r
public final Resource Loop_Comment_Inverse;\r
public final Resource Loop_Items;\r
public static final String LookupExpression_lookup_Inverse = "http://www.simantics.org/Sysdyn-1.1/LookupExpression/lookup/Inverse";\r
public static final String Loop = "http://www.simantics.org/Sysdyn-1.1/Loop";\r
public static final String LoopSymbol = "http://www.simantics.org/Sysdyn-1.1/LoopSymbol";\r
- public static final String Loop_Clockwise = "http://www.simantics.org/Sysdyn-1.1/Loop/Clockwise";\r
- public static final String Loop_Clockwise_Inverse = "http://www.simantics.org/Sysdyn-1.1/Loop/Clockwise/Inverse";\r
+ public static final String LoopSymbol_Clockwise = "http://www.simantics.org/Sysdyn-1.1/LoopSymbol/Clockwise";\r
+ public static final String LoopSymbol_Clockwise_Inverse = "http://www.simantics.org/Sysdyn-1.1/LoopSymbol/Clockwise/Inverse";\r
public static final String Loop_Comment = "http://www.simantics.org/Sysdyn-1.1/Loop/Comment";\r
public static final String Loop_Comment_Inverse = "http://www.simantics.org/Sysdyn-1.1/Loop/Comment/Inverse";\r
public static final String Loop_Items = "http://www.simantics.org/Sysdyn-1.1/Loop/Items";\r
LookupExpression_lookup_Inverse = getResourceOrNull(graph, URIs.LookupExpression_lookup_Inverse);\r
Loop = getResourceOrNull(graph, URIs.Loop);\r
LoopSymbol = getResourceOrNull(graph, URIs.LoopSymbol);\r
- Loop_Clockwise = getResourceOrNull(graph, URIs.Loop_Clockwise);\r
- Loop_Clockwise_Inverse = getResourceOrNull(graph, URIs.Loop_Clockwise_Inverse);\r
+ LoopSymbol_Clockwise = getResourceOrNull(graph, URIs.LoopSymbol_Clockwise);\r
+ LoopSymbol_Clockwise_Inverse = getResourceOrNull(graph, URIs.LoopSymbol_Clockwise_Inverse);\r
Loop_Comment = getResourceOrNull(graph, URIs.Loop_Comment);\r
Loop_Comment_Inverse = getResourceOrNull(graph, URIs.Loop_Comment_Inverse);\r
Loop_Items = getResourceOrNull(graph, URIs.Loop_Items);\r
\r
import org.simantics.db.Resource;\r
import org.simantics.g2d.element.ElementClass;\r
+import org.simantics.g2d.element.IElement;\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
/**\r
* @author Tuukka Lehtonen\r
new StaticObjectAdapter(elementType),\r
new StaticSymbolImpl(AUX_STATIC_IMAGE),\r
StaticSymbolImageInitializer.INSTANCE,\r
- new HoverTextElementHandler(0, 0, Alignment.LEADING, 0, 1.5, 1.5, true),\r
+ new AuxiliarySceneGraph(0, 0, Alignment.LEADING, 0, 1.5, 1.5, true),\r
BoundsOutline.INSTANCE,\r
new WholeElementTerminals(terminals)\r
).setId(AuxiliaryFactory.class.getSimpleName());\r
}\r
+ \r
+ public static class AuxiliarySceneGraph extends HoverTextElementHandler {\r
\r
+ private static final long serialVersionUID = -7077873654863790864L;\r
+ \r
+ public AuxiliarySceneGraph(double i, double j, Alignment leading, double k, double d,\r
+ double e, boolean b) {\r
+ super(i, j, leading, k, d, e, b);\r
+ }\r
+\r
+ @Override\r
+ public void init(IElement e, G2DParentNode parent) {\r
+ super.init(e, parent);\r
+ unflipText(e);\r
+ }\r
+\r
+ }\r
+ \r
}\r
node.setTransform(at);\r
}\r
\r
+ public static void unflipText(IElement e) {\r
+ Object o = e.getHint(SG_NODE);\r
+ if (o instanceof TextNode) {\r
+ TextNode text = (TextNode)o;\r
+ AffineTransform at = text.getTransform();\r
+ double x = at.getTranslateX();\r
+ double y = at.getTranslateY();\r
+ at.setToRotation(0);\r
+ at.setToTranslation(x, y);\r
+ at.setTransform(at);\r
+ }\r
+ }\r
+ \r
protected void activateEdit(final HoverTextNode node, final IElement e) {\r
final ICanvasContext ctx = DiagramNodeUtil.getCanvasContext(node);\r
// FIXME: needed only because eventdelegator registrations are done before adding node to scene graph.\r
at2.translate(0, font.getSize2D() * scale);\r
node.setTransform(at2);\r
}\r
+ \r
+ unflipText(e);\r
}\r
\r
@Override\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.elements;\r
+\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.handler.ElementHandler;\r
+\r
+public class LoopClockwise implements ElementHandler {\r
+\r
+ private static final long serialVersionUID = -5104770127548577905L;\r
+ \r
+ public static final LoopClockwise INSTANCE = new LoopClockwise();\r
+ \r
+ public String getTextLocation(IElement e) {\r
+ return e.getHint(SysdynElementHints.KEY_LOOP_CLOCKWISE);\r
+ }\r
+\r
+ \r
+ public void setTextLocation(IElement e, Boolean clockwise) {\r
+ if (clockwise != null)\r
+ e.setHint(SysdynElementHints.KEY_LOOP_CLOCKWISE, clockwise);\r
+ else\r
+ e.removeHint(SysdynElementHints.KEY_LOOP_CLOCKWISE);\r
+ }\r
+\r
+}\r
import java.awt.geom.AffineTransform;\r
import java.awt.geom.Arc2D;\r
import java.awt.geom.Path2D;\r
-import java.awt.geom.Rectangle2D;\r
+import java.awt.geom.Point2D;\r
import java.awt.geom.RectangularShape;\r
import java.util.Collection;\r
\r
+import org.simantics.databoard.Bindings;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
new StaticObjectAdapter(elementType),\r
new StaticSymbolImpl(image),\r
StaticSymbolImageInitializer.INSTANCE,\r
+ LoopSceneGraph.INSTANCE,\r
new LoopImageSceneGraph(image),\r
HoverImpl.INSTANCE,\r
- LoopSceneGraph.INSTANCE,\r
- BoundsOutline.INSTANCE\r
- ).setId(LoopFactory.class.getSimpleName());\r
+ BoundsOutline.INSTANCE,\r
+ LoopClockwise.INSTANCE\r
+ ).setId(LoopFactory.class.getSimpleName());\r
}\r
\r
static Shape getLoopShape() {\r
Collection<ObjectTerminal> terminals) {\r
return null;\r
}\r
+ \r
+ @Override\r
+ public void load(ReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, final Resource element, final IElement e) throws DatabaseException {\r
+ super.load(graph, canvas, diagram, element, e);\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Boolean clockwise = graph.getPossibleRelatedValue(element, sr.LoopSymbol_Clockwise, Bindings.BOOLEAN);\r
+ if(clockwise == null) {\r
+ clockwise = Boolean.TRUE;\r
+ }\r
+ SysdynElementUtils.setLoopClockwise(e, clockwise);\r
+ }\r
+ \r
+ \r
\r
/**\r
* Handling for the loop image on diagram.\r
// Create new hover shape node for the loop image\r
final HoverShapeNode node = ElementUtils.getOrCreateNode(e, parent, NODE, "loopHover", HoverShapeNode.class);\r
\r
- // Set the shape of the shape node to match the shape of the image\r
+ // Mirror the image if clockwise is selected.\r
+ Boolean clockwise = e.getHint(SysdynElementHints.KEY_LOOP_CLOCKWISE);\r
SVGNode image = e.getHint(getNodeKey());\r
+ if (clockwise != null && clockwise) {\r
+ Point2D imageParent = (Point2D) image.localToParent(new Point2D.Double(0.0,0.0)).clone();\r
+ AffineTransform at = new AffineTransform(-1.0, 0.0, 0.0, 1.0, imageParent.getX(), imageParent.getY());\r
+ image.setTransform(at);\r
+ }\r
+ \r
+ // Set the shape of the shape node to match the shape of the image\r
RectangularShape bounds = (RectangularShape)image.getBounds().clone();\r
node.setShape(bounds);\r
-\r
+ \r
// Set the shape node transparent\r
Paint paint = new Color(0,0,0,0);\r
node.setColor(paint);\r
AffineTransform at = ElementUtils.getTransform(e);\r
final HoverShapeNode node = ElementUtils.getOrCreateNode(e, parent, NODE, "loopComment", HoverShapeNode.class);\r
\r
+ // Unflip the text and image\r
+ unflipText(e);\r
+\r
if(at != null) {\r
node.setTransform(at);\r
\r
name.setHorizontalAlignment((byte) alignment.ordinal());\r
}\r
}\r
-\r
}\r
\r
private static double getXCoordShift(IElement e) {\r
//String location = e.getHint(SysdynElementHints.KEY_LOCATION);\r
- return 0.4;\r
+ return 0;\r
}\r
\r
private static double getYCoordShift(IElement e) {\r
super(originX, originY, horizontalAlignment, borderWidth, paddingX, paddingY, editable);\r
}\r
\r
+ @Override\r
+ public void init(IElement e, G2DParentNode parent) {\r
+ super.init(e, parent);\r
+ unflipText(e);\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
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 StockFactory extends SysdynElementFactory {\r
\r
new StaticObjectAdapter(elementType),\r
new StaticSymbolImpl(STOCK_IMAGE),\r
StaticSymbolImageInitializer.INSTANCE,\r
- new HoverTextElementHandler(0, 0, Alignment.LEADING, 1f, 1.0, 1.0, true),\r
+ new StockSceneGraph(0, 0, Alignment.LEADING, 1f, 1.0, 1.0, true),\r
BoundsOutline.INSTANCE,\r
new BorderColorImpl(Color.BLACK),\r
new WholeElementTerminals(terminals)\r
super.load(graph, canvas, diagram, element, e);\r
e.setHint(ElementHints.KEY_BORDER_COLOR, e.getHint(ElementHints.KEY_TEXT_COLOR));\r
}\r
- \r
+ \r
+ public static class StockSceneGraph extends HoverTextElementHandler {\r
+\r
+ private static final long serialVersionUID = 6635538659448488606L;\r
+\r
+ public StockSceneGraph(double i, double j, Alignment leading, double k, double d,\r
+ double e, boolean b) {\r
+ super(i, j, leading, k, d, e, b);\r
+ }\r
+\r
+ @Override\r
+ public void init(IElement e, G2DParentNode parent) {\r
+ super.init(e, parent);\r
+ unflipText(e);\r
+ }\r
+\r
+ }\r
+ \r
+ \r
}\r
public static final Key KEY_INPUT_REFERENCE = new KeyOf(String.class, "INPUT_REFERENCE");\r
public static final Key KEY_ORIENTATION = new KeyOf(String.class, "ORIENTATION"); \r
public static final Key KEY_LOCATION = new KeyOf(String.class, "LOCATION"); \r
+ public static final Key KEY_LOOP_CLOCKWISE = new KeyOf(Boolean.class, "LOOP_CLOCKWISE"); \r
\r
public static final Key SYSDYN_KEY_TOOL = new KeyOf(ToolMode.class, "SysdynKeyTool");\r
public static final IToolMode DEPENDENCY_TOOL = new ToolMode("DependencyTool");\r
return null;\r
}\r
\r
+ public static void setLoopClockwise(IElement e, Boolean clockwise) {\r
+ LoopClockwise l = e.getElementClass().getSingleItem(LoopClockwise.class);\r
+ if(l != null)\r
+ l.setTextLocation(e, clockwise);\r
+ }\r
+\r
+ public static String getLoopClockwise(IElement e)\r
+ {\r
+ LoopClockwise l = e.getElementClass().getSingleItem(LoopClockwise.class);\r
+ if(l != null)\r
+ return l.getTextLocation(e);\r
+ else\r
+ return null;\r
+ }\r
+\r
+\r
}\r
}\r
};\r
e.addHintListener(hoverHintListener);\r
+ \r
+ unflipText(e);\r
}\r
\r
@Override\r
import org.simantics.db.WriteGraph;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.management.ISessionContext;\r
+import org.simantics.modeling.ModelingResources;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.utils.datastructures.Pair;\r
import org.simantics.utils.datastructures.Triple;\r
}\r
\r
@Override\r
- public void apply(WriteGraph graph, Resource connectionElement) throws DatabaseException {\r
+ public void apply(WriteGraph graph, Resource component) throws DatabaseException {\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
- graph.deny(connectionElement, sr.Loop_Clockwise);\r
- graph.claimLiteral(connectionElement, sr.Loop_Clockwise, clockwise);\r
+ ModelingResources mr = ModelingResources.getInstance(graph);\r
+ Resource symbol = graph.getPossibleObject(component, mr.ComponentToElement);\r
+ if(symbol != null) {\r
+ graph.deny(symbol, sr.LoopSymbol_Clockwise);\r
+ graph.claimLiteral(symbol, sr.LoopSymbol_Clockwise, clockwise);\r
+ }\r
}\r
\r
}\r
}\r
\r
@Override\r
- public Boolean perform(ReadGraph graph, Resource dependencyConnection) throws DatabaseException {\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- Boolean clockwise = graph.getPossibleRelatedValue(dependencyConnection, sr.Loop_Clockwise, Bindings.BOOLEAN); \r
- return ObjectUtils.objectEquals(this.clockwise, clockwise);\r
+ public Boolean perform(ReadGraph graph, Resource component) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph); \r
+ ModelingResources mr = ModelingResources.getInstance(graph);\r
+ Resource symbol = graph.getPossibleObject(component, mr.ComponentToElement);\r
+ if(symbol != null) {\r
+ Boolean clockwise = graph.getPossibleRelatedValue(symbol, sr.LoopSymbol_Clockwise, Bindings.BOOLEAN); \r
+ return ObjectUtils.objectEquals(this.clockwise, clockwise);\r
+ }\r
+ return Boolean.TRUE;\r
}\r
}\r
\r
@RelatedElement(Layer0.URIs.PartOf)\r
protected Object parent;\r
\r
- @RelatedValue(SysdynResource.URIs.Loop_Clockwise)\r
+ @RelatedValue(SysdynResource.URIs.LoopSymbol_Clockwise)\r
protected Boolean clockwise;\r
\r
@RelatedValue(SysdynResource.URIs.Loop_Comment)\r