]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Enable static info labels for vertex elements
authorReino Ruusu <reino.ruusu@semantum.fi>
Thu, 6 Jun 2019 09:53:33 +0000 (12:53 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Sat, 31 Aug 2019 20:08:43 +0000 (23:08 +0300)
gitlab #47
APROS-15309

Change-Id: If37d3256d6bed52a444573e957c47b9997abcb6a

org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkStaticInfoStyle.java
org.simantics.district.network/scl/Simantics/District/Algorithm.scl

index 49d524a4b2f9525b9fcde4e4f95c96f466a5e59b..20e8ecbc4fa30727f0f4fa14a1029150350be62c 100644 (file)
@@ -55,13 +55,17 @@ public class DistrictNetworkStaticInfoStyle extends StyleBase<DistrictNetworkSta
                        throws DatabaseException {
                DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
                
-               if (!graph.isInstanceOf(mapElement, DN.Edge))
+               boolean isEdge = graph.isInstanceOf(mapElement, DN.Edge);
+               boolean isVertex = graph.isInstanceOf(mapElement, DN.Vertex);
+               if (!isEdge && !isVertex)
                        return null;
                
-               Resource diagram = graph.getSingleObject(mapElement, Layer0.getInstance(graph).PartOf);
-               Set<Resource> edgesToUse = graph.syncRequest(new MidBranchEdgeSetRequest(diagram), TransientCacheListener.instance());
-               if (!edgesToUse.contains(mapElement))
-                       return null;
+               if (isEdge) {
+                       Resource diagram = graph.getSingleObject(mapElement, Layer0.getInstance(graph).PartOf);
+                       Set<Resource> edgesToUse = graph.syncRequest(new MidBranchEdgeSetRequest(diagram), TransientCacheListener.instance());
+                       if (!edgesToUse.contains(mapElement))
+                               return null;
+               }
                
                DiagramResource DIA = DiagramResource.getInstance(graph);
                StructuralResource2 STR = StructuralResource2.getInstance(graph);
@@ -90,14 +94,23 @@ public class DistrictNetworkStaticInfoStyle extends StyleBase<DistrictNetworkSta
                        result = null;
                }
                
-               Resource v1 = graph.getSingleObject(mapElement, DN.HasStartVertex);
-               double[] coords1 = graph.getRelatedValue(v1, DIA.HasLocation);
-               Resource v2 = graph.getSingleObject(mapElement, DN.HasEndVertex);
-               double[] coords2 = graph.getRelatedValue(v2, DIA.HasLocation);
-               Point2D p1 = DistrictNetworkNodeUtils.calculatePoint2D(new Point2D.Double(coords1[0], coords1[1]), null);
-               Point2D p2 = DistrictNetworkNodeUtils.calculatePoint2D(new Point2D.Double(coords2[0], coords2[1]), null);
+               if (isVertex) {
+                       double[] coords = graph.getRelatedValue(mapElement, DIA.HasLocation);
+                       Point2D p = DistrictNetworkNodeUtils.calculatePoint2D(new Point2D.Double(coords[0], coords[1]), null);
+                       return new StyleResult(p, p, result);
+               }
+               else if (isEdge) {
+                       Resource v1 = graph.getSingleObject(mapElement, DN.HasStartVertex);
+                       double[] coords1 = graph.getRelatedValue(v1, DIA.HasLocation);
+                       Resource v2 = graph.getSingleObject(mapElement, DN.HasEndVertex);
+                       double[] coords2 = graph.getRelatedValue(v2, DIA.HasLocation);
+                       Point2D p1 = DistrictNetworkNodeUtils.calculatePoint2D(new Point2D.Double(coords1[0], coords1[1]), null);
+                       Point2D p2 = DistrictNetworkNodeUtils.calculatePoint2D(new Point2D.Double(coords2[0], coords2[1]), null);
+                       
+                       return new StyleResult(p1, p2, result);
+               }
                
-               return new StyleResult(p1, p2, result);
+               return null;
        }
        
        @Override
@@ -114,11 +127,17 @@ public class DistrictNetworkStaticInfoStyle extends StyleBase<DistrictNetworkSta
                Point2D p1 = result.p1;
                Point2D p2 = result.p2;
                
-               double sign = Math.signum(p1.getX() - p2.getX());
-               Point2D.Double origin = new Point2D.Double(0.5 * (p1.getX() + p2.getX()), 0.5 * (p1.getY() + p2.getY()));
-               Point2D direction = new Point2D.Double(0.5 * sign * (p1.getX() - p2.getX()), 0.5 * sign * (p1.getY() - p2.getY()));
+               if (p1.equals(p2)) {
+                       node.setLocation(p1, new Point2D.Double(1.0, 0.0));
+               }
+               else {
+                       double sign = Math.signum(p1.getX() - p2.getX());
+                       Point2D.Double origin = new Point2D.Double(0.5 * (p1.getX() + p2.getX()), 0.5 * (p1.getY() + p2.getY()));
+                       Point2D direction = new Point2D.Double(0.5 * sign * (p1.getX() - p2.getX()), 0.5 * sign * (p1.getY() - p2.getY()));
+                       
+                       node.setLocation(origin, direction);
+               }
                
-               node.setLocation(origin, direction);
                node.setInfo(result.info);
        }
        
@@ -155,6 +174,6 @@ public class DistrictNetworkStaticInfoStyle extends StyleBase<DistrictNetworkSta
        
        @Override
        protected void cleanupStyleForNode(EvaluationContext evaluationContext, INode node) {
-               ProfileVariables.denyChild(node, DistrictNetworkStaticInfoNode.NODE_KEY);
+               ProfileVariables.denyChild(node, "*", DistrictNetworkStaticInfoNode.NODE_KEY);
        }
 }
index 259ad087620bed708791cb3887a4ba12f6977aef..c03ea7964ebc379a32ebc96a2547f3921a8391cd 100644 (file)
@@ -118,6 +118,20 @@ reportDisconnectedSubnetworks vertexThreshold (diagram, subgraphs) = do
         print ""
         forI (sortStrings (map showEdge es)) (\i s -> print "* e\(i): \(s)")
 
+"""
+Get a set of vertices that acts as break points between network branches.
+"""
+branchPoints :: Resource -> <ReadGraph> [Resource]
+branchPoints networkDiagram = runProc let
+  in  
+    filter isBranchPoint vertices
+  where 
+    all       = if isInstanceOf networkDiagram DIA.Diagram
+                then networkDiagram # L0.ConsistsOf
+                else singleObject networkDiagram MOD.CompositeToDiagram # L0.ConsistsOf
+    vertices = filter (flip isInstanceOf DN.Vertex) all
+    isBranchPoint v = length (v # DN.HasEndVertex_Inverse) != 1 || length (v # DN.HasStartVertex_Inverse) != 1
+
 """
 Get a set of the edges that are at the middle points of each span between branch points.
 """