From: miettinen Date: Fri, 22 Nov 2013 09:48:49 +0000 (+0000) Subject: Hover to follow Loop image. Flip image with the clockwise option. (refs #3012) X-Git-Tag: 1.8.1~186 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=4b560c2d54d01dfe4ddff24fad585dfa8ae07266;p=simantics%2Fsysdyn.git Hover to follow Loop image. Flip image with the clockwise option. (refs #3012) Simantics flips to not mirror text elements. git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28356 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ontology/graph.tg b/org.simantics.sysdyn.ontology/graph.tg index ec145e4c..7bdd693e 100644 Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ diff --git a/org.simantics.sysdyn.ontology/graph/CommentSymbols.pgraph b/org.simantics.sysdyn.ontology/graph/CommentSymbols.pgraph index 82666f45..adfd0b9a 100644 --- a/org.simantics.sysdyn.ontology/graph/CommentSymbols.pgraph +++ b/org.simantics.sysdyn.ontology/graph/CommentSymbols.pgraph @@ -16,10 +16,8 @@ SYSDYN.AdditionalSymbols.MultilineText """ : L0.String SYSDYN.Loop -- SYSDYN.Loop.Clockwise --> L0.Boolean -- SYSDYN.Loop.Comment --> L0.String -- SYSDYN.Loop.Items --> L0.List -- SYSDYN.LoopSymbol.Clockwise --> L0.Boolean terminals) { return null; } + + @Override + public void load(ReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, final Resource element, final IElement e) throws DatabaseException { + super.load(graph, canvas, diagram, element, e); + SysdynResource sr = SysdynResource.getInstance(graph); + Boolean clockwise = graph.getPossibleRelatedValue(element, sr.LoopSymbol_Clockwise, Bindings.BOOLEAN); + if(clockwise == null) { + clockwise = Boolean.TRUE; + } + SysdynElementUtils.setLoopClockwise(e, clockwise); + } + + /** * Handling for the loop image on diagram. @@ -168,11 +183,19 @@ public class LoopFactory extends SysdynElementFactory { // Create new hover shape node for the loop image final HoverShapeNode node = ElementUtils.getOrCreateNode(e, parent, NODE, "loopHover", HoverShapeNode.class); - // Set the shape of the shape node to match the shape of the image + // Mirror the image if clockwise is selected. + Boolean clockwise = e.getHint(SysdynElementHints.KEY_LOOP_CLOCKWISE); SVGNode image = e.getHint(getNodeKey()); + if (clockwise != null && clockwise) { + Point2D imageParent = (Point2D) image.localToParent(new Point2D.Double(0.0,0.0)).clone(); + AffineTransform at = new AffineTransform(-1.0, 0.0, 0.0, 1.0, imageParent.getX(), imageParent.getY()); + image.setTransform(at); + } + + // Set the shape of the shape node to match the shape of the image RectangularShape bounds = (RectangularShape)image.getBounds().clone(); node.setShape(bounds); - + // Set the shape node transparent Paint paint = new Color(0,0,0,0); node.setColor(paint); @@ -232,6 +255,9 @@ public class LoopFactory extends SysdynElementFactory { AffineTransform at = ElementUtils.getTransform(e); final HoverShapeNode node = ElementUtils.getOrCreateNode(e, parent, NODE, "loopComment", HoverShapeNode.class); + // Unflip the text and image + unflipText(e); + if(at != null) { node.setTransform(at); @@ -247,12 +273,11 @@ public class LoopFactory extends SysdynElementFactory { name.setHorizontalAlignment((byte) alignment.ordinal()); } } - } private static double getXCoordShift(IElement e) { //String location = e.getHint(SysdynElementHints.KEY_LOCATION); - return 0.4; + return 0; } private static double getYCoordShift(IElement e) { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ModuleFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ModuleFactory.java index e67b7967..a7f9b15f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ModuleFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ModuleFactory.java @@ -73,6 +73,12 @@ public class ModuleFactory extends SysdynElementFactory { super(originX, originY, horizontalAlignment, borderWidth, paddingX, paddingY, editable); } + @Override + public void init(IElement e, G2DParentNode parent) { + super.init(e, parent); + unflipText(e); + } + protected HoverTextNode getTextNode(IElement e, G2DParentNode parent) { return ElementUtils.getOrCreateNode(e, parent, SG_NODE, "text", ModuleNode.class, getCallback(e, parent, ModuleNode.class)); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/StockFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/StockFactory.java index 1777033c..13a6ee48 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/StockFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/StockFactory.java @@ -39,6 +39,7 @@ import org.simantics.g2d.element.handler.impl.TextImpl; import org.simantics.g2d.image.Image; import org.simantics.g2d.image.impl.ShapeImage; import org.simantics.g2d.utils.Alignment; +import org.simantics.scenegraph.g2d.G2DParentNode; public class StockFactory extends SysdynElementFactory { @@ -57,7 +58,7 @@ public class StockFactory extends SysdynElementFactory { new StaticObjectAdapter(elementType), new StaticSymbolImpl(STOCK_IMAGE), StaticSymbolImageInitializer.INSTANCE, - new HoverTextElementHandler(0, 0, Alignment.LEADING, 1f, 1.0, 1.0, true), + new StockSceneGraph(0, 0, Alignment.LEADING, 1f, 1.0, 1.0, true), BoundsOutline.INSTANCE, new BorderColorImpl(Color.BLACK), new WholeElementTerminals(terminals) @@ -69,5 +70,23 @@ public class StockFactory extends SysdynElementFactory { super.load(graph, canvas, diagram, element, e); e.setHint(ElementHints.KEY_BORDER_COLOR, e.getHint(ElementHints.KEY_TEXT_COLOR)); } - + + public static class StockSceneGraph extends HoverTextElementHandler { + + private static final long serialVersionUID = 6635538659448488606L; + + public StockSceneGraph(double i, double j, Alignment leading, double k, double d, + double e, boolean b) { + super(i, j, leading, k, d, e, b); + } + + @Override + public void init(IElement e, G2DParentNode parent) { + super.init(e, parent); + unflipText(e); + } + + } + + } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynElementHints.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynElementHints.java index 14a59e83..fdd74d41 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynElementHints.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynElementHints.java @@ -21,6 +21,7 @@ public class SysdynElementHints { public static final Key KEY_INPUT_REFERENCE = new KeyOf(String.class, "INPUT_REFERENCE"); public static final Key KEY_ORIENTATION = new KeyOf(String.class, "ORIENTATION"); public static final Key KEY_LOCATION = new KeyOf(String.class, "LOCATION"); + public static final Key KEY_LOOP_CLOCKWISE = new KeyOf(Boolean.class, "LOOP_CLOCKWISE"); public static final Key SYSDYN_KEY_TOOL = new KeyOf(ToolMode.class, "SysdynKeyTool"); public static final IToolMode DEPENDENCY_TOOL = new ToolMode("DependencyTool"); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynElementUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynElementUtils.java index 6802a9d9..f912495f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynElementUtils.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynElementUtils.java @@ -64,4 +64,20 @@ public class SysdynElementUtils { return null; } + public static void setLoopClockwise(IElement e, Boolean clockwise) { + LoopClockwise l = e.getElementClass().getSingleItem(LoopClockwise.class); + if(l != null) + l.setTextLocation(e, clockwise); + } + + public static String getLoopClockwise(IElement e) + { + LoopClockwise l = e.getElementClass().getSingleItem(LoopClockwise.class); + if(l != null) + return l.getTextLocation(e); + else + return null; + } + + } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveFactory.java index 4f861591..94d16aea 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveFactory.java @@ -220,6 +220,8 @@ public class ValveFactory extends SysdynElementFactory { } }; e.addHintListener(hoverHintListener); + + unflipText(e); } @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LoopTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LoopTab.java index 27cc9a56..60720d62 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LoopTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LoopTab.java @@ -30,6 +30,7 @@ import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.exception.DatabaseException; import org.simantics.db.management.ISessionContext; +import org.simantics.modeling.ModelingResources; import org.simantics.sysdyn.SysdynResource; import org.simantics.utils.datastructures.Pair; import org.simantics.utils.datastructures.Triple; @@ -127,10 +128,14 @@ public class LoopTab extends LabelPropertyTabContributor { } @Override - public void apply(WriteGraph graph, Resource connectionElement) throws DatabaseException { + public void apply(WriteGraph graph, Resource component) throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(graph); - graph.deny(connectionElement, sr.Loop_Clockwise); - graph.claimLiteral(connectionElement, sr.Loop_Clockwise, clockwise); + ModelingResources mr = ModelingResources.getInstance(graph); + Resource symbol = graph.getPossibleObject(component, mr.ComponentToElement); + if(symbol != null) { + graph.deny(symbol, sr.LoopSymbol_Clockwise); + graph.claimLiteral(symbol, sr.LoopSymbol_Clockwise, clockwise); + } } } @@ -148,10 +153,15 @@ public class LoopTab extends LabelPropertyTabContributor { } @Override - public Boolean perform(ReadGraph graph, Resource dependencyConnection) throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - Boolean clockwise = graph.getPossibleRelatedValue(dependencyConnection, sr.Loop_Clockwise, Bindings.BOOLEAN); - return ObjectUtils.objectEquals(this.clockwise, clockwise); + public Boolean perform(ReadGraph graph, Resource component) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + Resource symbol = graph.getPossibleObject(component, mr.ComponentToElement); + if(symbol != null) { + Boolean clockwise = graph.getPossibleRelatedValue(symbol, sr.LoopSymbol_Clockwise, Bindings.BOOLEAN); + return ObjectUtils.objectEquals(this.clockwise, clockwise); + } + return Boolean.TRUE; } } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Loop.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Loop.java index 1345faa0..f81e5355 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Loop.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Loop.java @@ -31,7 +31,7 @@ public class Loop implements IElement { @RelatedElement(Layer0.URIs.PartOf) protected Object parent; - @RelatedValue(SysdynResource.URIs.Loop_Clockwise) + @RelatedValue(SysdynResource.URIs.LoopSymbol_Clockwise) protected Boolean clockwise; @RelatedValue(SysdynResource.URIs.Loop_Comment)