From: Reino Ruusu Date: Wed, 23 Jan 2019 10:05:02 +0000 (+0200) Subject: Dynamic vertex SVG symbol generation X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=beab0411489f5730942d98d47dc3faf3107c6c02;p=simantics%2Fdistrict.git Dynamic vertex SVG symbol generation gitlab #27 Change-Id: I7f01f451e7affd25d2c9e6e504f8242ce39caec2 --- diff --git a/org.simantics.district.network.ontology/graph/DistrictNetworkProfiles.pgraph b/org.simantics.district.network.ontology/graph/DistrictNetworkProfiles.pgraph index ac1cf19f..1a468d12 100644 --- a/org.simantics.district.network.ontology/graph/DistrictNetworkProfiles.pgraph +++ b/org.simantics.district.network.ontology/graph/DistrictNetworkProfiles.pgraph @@ -23,3 +23,12 @@ DN.ElementColoringStyle : DIA.Style DN.VertexSizeStyle : DIA.Style DN.EdgeThicknessStyle : DIA.Style DN.HideStyle : DIA.Style +DN.VertexSymbolStyle : DIA.Style + +// Function for dynamic selection of symbols for a vertex +// The input of the function is a DN.Vertex +// The output of the function should be SVG +DN.HasSymbolFunction L0.ExternalValue + ==> "Resource -> String" diff --git a/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java b/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java index 9ef2ef02..97bf9d0a 100644 --- a/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java +++ b/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java @@ -123,6 +123,8 @@ public class DistrictNetworkResource { public final Resource HasSpatialRefSystem_Inverse; public final Resource HasStartVertex; public final Resource HasStartVertex_Inverse; + public final Resource HasSymbolFunction; + public final Resource HasSymbolFunction_Inverse; public final Resource HideStyle; public final Resource Images; public final Resource Images_MapImage; @@ -229,6 +231,7 @@ public class DistrictNetworkResource { public final Resource VertexMappingParameterType; public final Resource VertexScalePropertyParameterType; public final Resource VertexSizeStyle; + public final Resource VertexSymbolStyle; public final Resource Vertex_HasAddress; public final Resource Vertex_HasAddress_Inverse; public final Resource Vertex_HasDeltaPressure; @@ -394,6 +397,8 @@ public class DistrictNetworkResource { public static final String HasSpatialRefSystem_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasSpatialRefSystem/Inverse"; public static final String HasStartVertex = "http://www.simantics.org/DistrictNetwork-1.0/HasStartVertex"; public static final String HasStartVertex_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasStartVertex_Inverse"; + public static final String HasSymbolFunction = "http://www.simantics.org/DistrictNetwork-1.0/HasSymbolFunction"; + public static final String HasSymbolFunction_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasSymbolFunction/Inverse"; public static final String HideStyle = "http://www.simantics.org/DistrictNetwork-1.0/HideStyle"; public static final String Images = "http://www.simantics.org/DistrictNetwork-1.0/Images"; public static final String Images_MapImage = "http://www.simantics.org/DistrictNetwork-1.0/Images/MapImage"; @@ -500,6 +505,7 @@ public class DistrictNetworkResource { public static final String VertexMappingParameterType = "http://www.simantics.org/DistrictNetwork-1.0/VertexMappingParameterType"; public static final String VertexScalePropertyParameterType = "http://www.simantics.org/DistrictNetwork-1.0/VertexScalePropertyParameterType"; public static final String VertexSizeStyle = "http://www.simantics.org/DistrictNetwork-1.0/VertexSizeStyle"; + public static final String VertexSymbolStyle = "http://www.simantics.org/DistrictNetwork-1.0/VertexSymbolStyle"; public static final String Vertex_HasAddress = "http://www.simantics.org/DistrictNetwork-1.0/Vertex/HasAddress"; public static final String Vertex_HasAddress_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Vertex/HasAddress/Inverse"; public static final String Vertex_HasDeltaPressure = "http://www.simantics.org/DistrictNetwork-1.0/Vertex/HasDeltaPressure"; @@ -675,6 +681,8 @@ public class DistrictNetworkResource { HasSpatialRefSystem_Inverse = getResourceOrNull(graph, URIs.HasSpatialRefSystem_Inverse); HasStartVertex = getResourceOrNull(graph, URIs.HasStartVertex); HasStartVertex_Inverse = getResourceOrNull(graph, URIs.HasStartVertex_Inverse); + HasSymbolFunction = getResourceOrNull(graph, URIs.HasSymbolFunction); + HasSymbolFunction_Inverse = getResourceOrNull(graph, URIs.HasSymbolFunction_Inverse); HideStyle = getResourceOrNull(graph, URIs.HideStyle); Images = getResourceOrNull(graph, URIs.Images); Images_MapImage = getResourceOrNull(graph, URIs.Images_MapImage); @@ -781,6 +789,7 @@ public class DistrictNetworkResource { VertexMappingParameterType = getResourceOrNull(graph, URIs.VertexMappingParameterType); VertexScalePropertyParameterType = getResourceOrNull(graph, URIs.VertexScalePropertyParameterType); VertexSizeStyle = getResourceOrNull(graph, URIs.VertexSizeStyle); + VertexSymbolStyle = getResourceOrNull(graph, URIs.VertexSymbolStyle); Vertex_HasAddress = getResourceOrNull(graph, URIs.Vertex_HasAddress); Vertex_HasAddress_Inverse = getResourceOrNull(graph, URIs.Vertex_HasAddress_Inverse); Vertex_HasDeltaPressure = getResourceOrNull(graph, URIs.Vertex_HasDeltaPressure); diff --git a/org.simantics.district.network.ui/META-INF/MANIFEST.MF b/org.simantics.district.network.ui/META-INF/MANIFEST.MF index ccb5ab1d..6638242d 100644 --- a/org.simantics.district.network.ui/META-INF/MANIFEST.MF +++ b/org.simantics.district.network.ui/META-INF/MANIFEST.MF @@ -7,7 +7,8 @@ Bundle-Activator: org.simantics.district.network.ui.internal.Activator Export-Package: org.simantics.district.network.ui, org.simantics.district.network.ui.adapters, org.simantics.district.network.ui.breakdown, - org.simantics.district.network.ui.function + org.simantics.district.network.ui.function, + org.simantics.district.network.ui.nodes Require-Bundle: org.eclipse.e4.ui.model.workbench;bundle-version="1.1.100.v20150407-1430", org.eclipse.swt, org.simantics.g2d, diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/NetworkDrawingParticipant.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/NetworkDrawingParticipant.java index 7dd55f5e..c020c33d 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/NetworkDrawingParticipant.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/NetworkDrawingParticipant.java @@ -16,7 +16,7 @@ import org.simantics.g2d.diagram.handler.PickContext; import org.simantics.g2d.diagram.handler.PickRequest; import org.simantics.g2d.diagram.participant.AbstractDiagramParticipant; import org.simantics.g2d.element.IElement; -import org.simantics.scenegraph.g2d.G2DNode; +import org.simantics.scenegraph.Node; import org.simantics.scenegraph.g2d.G2DParentNode; import org.simantics.utils.datastructures.hints.IHintContext.Key; import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; @@ -69,7 +69,7 @@ public class NetworkDrawingParticipant extends AbstractDiagramParticipant { boolean changed = false; for (IElement sn : snap) { - G2DNode node = sn.getHint(DistrictNetworkVertexElement.KEY_DN_VERTEX_NODE); + Node node = sn.getHint(DistrictNetworkVertexElement.KEY_DN_VERTEX_NODE); if (node instanceof DistrictNetworkVertexNode) { if (((DistrictNetworkVertexNode) node).hover(false) && !changed) { changed = true; @@ -78,7 +78,7 @@ public class NetworkDrawingParticipant extends AbstractDiagramParticipant { } for (IElement elem : pickables) { - G2DNode node = elem.getHint(DistrictNetworkVertexElement.KEY_DN_VERTEX_NODE); + Node node = elem.getHint(DistrictNetworkVertexElement.KEY_DN_VERTEX_NODE); if (node instanceof DistrictNetworkVertexNode) { if (((DistrictNetworkVertexNode) node).hover(true) && !changed) { changed = true; diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElement.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElement.java index 2a0cb122..7be6a14f 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElement.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElement.java @@ -13,7 +13,9 @@ import org.simantics.g2d.element.handler.InternalSize; import org.simantics.g2d.element.handler.SceneGraph; import org.simantics.g2d.element.handler.impl.DefaultTransform; import org.simantics.g2d.element.handler.impl.SimpleElementLayers; +import org.simantics.scenegraph.INode; import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.g2d.nodes.SVGNode; import org.simantics.utils.datastructures.hints.IHintContext.Key; import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; @@ -21,6 +23,7 @@ public class DistrictNetworkVertexElement { public static final Key KEY_DN_VERTEX = new KeyOf(DistrictNetworkVertex.class, "DN_VERTEX"); public static final Key KEY_DN_VERTEX_NODE = new SceneGraphNodeKey(DistrictNetworkVertexNode.class, "DN_VERTEX_NODE"); + public static final Key KEY_DN_VERTEX_SYMBOL_NODE = new SceneGraphNodeKey(SVGNode.class, "DN_VERTEX_SYMBOL_NODE"); public static final ElementClass CLASS = ElementClass.compile( @@ -47,7 +50,11 @@ public class DistrictNetworkVertexElement { if (node == null) { node = parent.addNode(ElementUtils.generateNodeId(vertexElement), DistrictNetworkVertexNode.class); vertexElement.setHint(KEY_DN_VERTEX_NODE, node); + + SVGNode symbol = node.addNode(ElementUtils.generateNodeId(vertexElement), SVGNode.class); + vertexElement.setHint(KEY_DN_VERTEX_SYMBOL_NODE, symbol); } + node.setVertex(vertex); node.setColor(ElementUtils.getAdditionalColor(vertexElement, Color.BLUE)); @@ -60,8 +67,13 @@ public class DistrictNetworkVertexElement { @Override public void cleanup(IElement edge) { - ElementUtils.removePossibleNode(edge, KEY_DN_VERTEX_NODE); + ElementUtils.removePossibleNode(edge, KEY_DN_VERTEX_SYMBOL_NODE); + INode node = ElementUtils.removePossibleNode(edge, KEY_DN_VERTEX_NODE); + if (node != null) + node.getParent().remove(); + edge.removeHint(KEY_DN_VERTEX_NODE); + edge.removeHint(KEY_DN_VERTEX_SYMBOL_NODE); } } diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java index 0cd5ea88..d063d48c 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java @@ -10,12 +10,15 @@ import java.awt.geom.Rectangle2D; import org.simantics.district.network.ModelledCRS; import org.simantics.district.network.ui.adapters.DistrictNetworkVertex; +import org.simantics.scenegraph.INode; import org.simantics.scenegraph.ISelectionPainterNode; import org.simantics.scenegraph.g2d.G2DNode; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.g2d.nodes.SVGNode; import org.simantics.scenegraph.utils.GeometryUtils; import org.simantics.scenegraph.utils.NodeUtil; -public class DistrictNetworkVertexNode extends G2DNode implements ISelectionPainterNode { +public class DistrictNetworkVertexNode extends G2DParentNode implements ISelectionPainterNode { //private static final Logger LOGGER = LoggerFactory.getLogger(DistrictNetworkVertexNode.class); @@ -98,12 +101,19 @@ public class DistrictNetworkVertexNode extends G2DNode implements ISelectionPain if (changeColor) g2d.setColor(newColor); g2d.fill(toDraw); - + // Reset settings if (changeColor) g2d.setColor(oldColor); if (oaaHint != null) - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aaHint); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aaHint); + + // Render SVG symbol + for (INode nn : getNodes()) { + ((G2DNode)nn).setTransform(new AffineTransform(toDraw.getWidth(), 0.0, 0.0, toDraw.getHeight(), toDraw.getCenterX(), toDraw.getCenterY())); + ((G2DNode)nn).render(g2d); + } + if (ot != null) g2d.setTransform(ot); } @@ -187,6 +197,14 @@ public class DistrictNetworkVertexNode extends G2DNode implements ISelectionPain return color; } + @PropertySetter(value = "SVG") + public void setSVG(String value) { + for (INode nn : this.getNodes()) + if (nn instanceof SVGNode) + ((SVGNode)nn).setData(value); + } + + @PropertySetter(value = "size") public void setSize(Double size) { boolean changed = false; diff --git a/org.simantics.district.network/adapters.xml b/org.simantics.district.network/adapters.xml index 5151e3e3..8cec4400 100644 --- a/org.simantics.district.network/adapters.xml +++ b/org.simantics.district.network/adapters.xml @@ -21,6 +21,9 @@ + + { + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public String calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException { + DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); + Resource symbolFunctionResource = graph.getPossibleObject(entry, DN.HasSymbolFunction); + if (symbolFunctionResource == null) + return null; + + Function symbolFunction = (Function) graph.getPossibleValue2(symbolFunctionResource, null); + if (symbolFunction == null) + return null; + + return (String) symbolFunction.apply(graph, entry); + } + + @Override + public void applyStyleForNode(EvaluationContext observer, INode node, String value) { + SingleElementNode n = (SingleElementNode) node; + for (INode nn : n.getNodes()) + ProfileVariables.claimNodeProperty(nn, "SVG", value, observer); + } + + @Override + protected void cleanupStyleForNode(EvaluationContext evaluationContext, INode node) { + ((G2DSceneGraph)node.getRootNode()).clearPending(node); + SingleElementNode n = (SingleElementNode) node; + for (INode nn : n.getNodes()) + ProfileVariables.claimNodeProperty(nn, "SVG", null, evaluationContext); + } + +} diff --git a/org.simantics.district.route.ontology/META-INF/MANIFEST.MF b/org.simantics.district.route.ontology/META-INF/MANIFEST.MF index c9623fa0..ee4c1e64 100644 --- a/org.simantics.district.route.ontology/META-INF/MANIFEST.MF +++ b/org.simantics.district.route.ontology/META-INF/MANIFEST.MF @@ -5,7 +5,8 @@ Bundle-SymbolicName: org.simantics.district.route.ontology Bundle-Version: 1.0.0.qualifier Bundle-Vendor: Semantum Oy Require-Bundle: org.simantics.layer0, - org.simantics.district.network.ontology;bundle-version="1.0.0" + org.simantics.district.network.ontology;bundle-version="1.0.0", + org.simantics.diagram.ontology;bundle-version="2.2.0" Automatic-Module-Name: fi.vtt.apros.district.route.ontology Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: org.simantics.district.route.ontology