]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Dynamic vertex SVG symbol generation 11/2611/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Wed, 23 Jan 2019 10:05:02 +0000 (12:05 +0200)
committerReino Ruusu <reino.ruusu@semantum.fi>
Wed, 23 Jan 2019 10:05:02 +0000 (12:05 +0200)
gitlab #27

Change-Id: I7f01f451e7affd25d2c9e6e504f8242ce39caec2

org.simantics.district.network.ontology/graph/DistrictNetworkProfiles.pgraph
org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java
org.simantics.district.network.ui/META-INF/MANIFEST.MF
org.simantics.district.network.ui/src/org/simantics/district/network/ui/NetworkDrawingParticipant.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElement.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java
org.simantics.district.network/adapters.xml
org.simantics.district.network/src/org/simantics/district/network/profile/VertexSymbolStyle.java [new file with mode: 0644]
org.simantics.district.route.ontology/META-INF/MANIFEST.MF

index ac1cf19fd3ec67b24a986b071656ed89ea0319f7..1a468d12696cca2c3822eebe555ca0f8c2812d01 100644 (file)
@@ -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 <R L0.HasProperty
+    <-- DIA.ProfileEntry
+    --> L0.ExternalValue
+    ==> "Resource -> <ReadGraph> String"
index 9ef2ef02b2b4ab789ac215102cc26b4a3065ede2..97bf9d0a18aacfaf9a88da89407888a5a20b0809 100644 (file)
@@ -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);
index ccb5ab1d844aa285eb898e2eba060ecff44eb20b..6638242ded2f64371fcbcc351ef2bf0370263ff2 100644 (file)
@@ -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,
index 7dd55f5e1743ace66ebb402ec46c498ff155dd84..c020c33d67e65abae9788aa9a3ea761e929c9e53 100644 (file)
@@ -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;
index 2a0cb1229c783f645d416e28a646af6d22311580..7be6a14faa659abb28df213e694b14e9094dd848 100644 (file)
@@ -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);
         }
     }
     
index 0cd5ea884fd29058c2e12907eca01112a3e2dbe0..d063d48c4982d30ee08af9ce18e8b0868179b8ba 100644 (file)
@@ -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;
index 5151e3e3756a923c875a1a8c18def8fad56049ff..8cec44000d1c7b4ecfe1b28724fce4bb51e333e3 100644 (file)
@@ -21,6 +21,9 @@
                <resource uri="http://www.simantics.org/DistrictNetwork-1.0/HideStyle"
                        class="org.simantics.district.network.profile.HideStyle">
                </resource>
+               <resource uri="http://www.simantics.org/DistrictNetwork-1.0/VertexSymbolStyle"
+                       class="org.simantics.district.network.profile.VertexSymbolStyle">
+               </resource>
        </target>
        <target interface="org.simantics.scenegraph.profile.Group">
                <type
diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/VertexSymbolStyle.java b/org.simantics.district.network/src/org/simantics/district/network/profile/VertexSymbolStyle.java
new file mode 100644 (file)
index 0000000..6530450
--- /dev/null
@@ -0,0 +1,47 @@
+package org.simantics.district.network.profile;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.diagram.profile.StyleBase;
+import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.scenegraph.INode;
+import org.simantics.scenegraph.g2d.G2DSceneGraph;
+import org.simantics.scenegraph.g2d.nodes.SingleElementNode;
+import org.simantics.scenegraph.profile.EvaluationContext;
+import org.simantics.scenegraph.profile.common.ProfileVariables;
+import org.simantics.scl.runtime.function.Function;
+
+public class VertexSymbolStyle extends StyleBase<String> {
+
+       @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);
+       }
+
+}
index c9623fa06f76617b26a66ecdfc0b3457d0ced3a7..ee4c1e64ad52d578c67a8d0db8fad0d06b26c35f 100644 (file)
@@ -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