]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Merge remote-tracking branch 'origin/master' into release/1.35.2
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 6 Sep 2019 08:56:11 +0000 (11:56 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 10 Sep 2019 12:40:26 +0000 (15:40 +0300)
Conflicts resolved:
org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportModel.java
org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizard.java
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/adapters.xml
org.simantics.district.network.ui/fragment.e4xmi
org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictTransformUtil.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/NetworkElementActionMenuContribution.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java
org.simantics.district.network/scl/Simantics/District/Algorithm.scl
org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java
org.simantics.district.network/src/org/simantics/district/network/profile/ArrowLengthStyle.java

gitlab #60

org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/NetworkElementActionMenuContribution.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/ConnectionLineStyle.java [new file with mode: 0644]
org.simantics.district.network/src/org/simantics/district/network/profile/DistrictNodeGroup.java
pom.xml

index cca371728d8dcb13a95feb81ca26589f0f5bd009..e29d11a22e2f0ec919d9c5e397b6b78c606344c8 100644 (file)
@@ -62,6 +62,9 @@ public class NetworkElementActionMenuContribution {
             return;
         }
         
+        if (actions == null || actions.isEmpty())
+            return;
+        
         items.add(MMenuFactory.INSTANCE.createMenuSeparator());
         MMenu subMenu = MMenuFactory.INSTANCE.createMenu();
         List<MMenuElement> children = subMenu.getChildren();
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/ConnectionLineStyle.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/ConnectionLineStyle.java
new file mode 100644 (file)
index 0000000..5b3d2b4
--- /dev/null
@@ -0,0 +1,198 @@
+package org.simantics.district.network.ui.nodes;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.geom.Line2D;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.simantics.Simantics;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.procedure.adapter.TransientCacheListener;
+import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.util.Layer0Utils;
+import org.simantics.diagram.profile.StyleBase;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.district.network.DistrictNetworkUtil;
+import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.layer0.Layer0;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.scenegraph.INode;
+import org.simantics.scenegraph.g2d.G2DNode;
+import org.simantics.scenegraph.profile.EvaluationContext;
+import org.simantics.scenegraph.profile.common.ProfileVariables;
+import org.simantics.scenegraph.utils.GeometryUtils;
+import org.simantics.scl.compiler.top.ValueNotFound;
+import org.simantics.scl.osgi.SCLOsgi;
+import org.simantics.scl.runtime.SCLContext;
+import org.simantics.scl.runtime.function.Function1;
+import org.simantics.structural.stubs.StructuralResource2;
+
+public class ConnectionLineStyle extends StyleBase<List<Point2D>> {
+       
+       public static class ConnectionLineNode extends G2DNode {
+               private static final BasicStroke STROKE = new BasicStroke(1.f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.f, new float[] {4.f, 2.f}, 0.f);
+               private static final Color[] colors = { Color.RED, Color.GREEN, Color.BLUE, Color.ORANGE, Color.CYAN, Color.PINK };
+               
+               private float strokeWidth;
+               private Line2D[] lines;
+
+               public ConnectionLineNode() {
+                       super();
+               }
+               
+               private static final long serialVersionUID = 1L;
+
+               @Override
+               public Rectangle2D getBoundsInLocal() {
+                       return null;
+               }
+
+               @Override
+               public Rectangle2D getBoundsInLocal(boolean b) {
+                       return null;
+               }
+
+               @Override
+               public Rectangle2D getBounds() {
+                       return null;
+               }
+               
+               public void setStrokeWidth(float w) {
+                       strokeWidth = w;
+               }
+               
+               public void setPoints(List<Point2D> result) {
+                       Point2D p0 = DistrictNetworkNodeUtils.calculatePoint2D(result.get(0), null);
+                       lines = new Line2D[result.size() - 1];
+                       for (int i = 1; i < result.size(); i++) 
+                       {
+                               Point2D p = result.get(i);
+                               lines[i-1] = p != null ? new Line2D.Double(p0, DistrictNetworkNodeUtils.calculatePoint2D(p, null)) : null;
+                       }
+               }
+               
+               @Override
+               public void render(Graphics2D g2d) {
+                       if (lines == null || lines.length == 0)
+                               return;
+                       
+                       // Keep fixed line width on screen
+                       float scaleRecip = (float) GeometryUtils.getScale(g2d.getTransform());
+                       g2d.setStroke(GeometryUtils.scaleStroke(STROKE, strokeWidth / scaleRecip));
+                       
+                       for (int i = 0; i < lines.length; i++) {
+                               if (lines[i] != null) {
+                                       g2d.setColor(colors[i % colors.length]);
+                                       g2d.draw(lines[i]);
+                               }
+                       }
+               }
+       }
+       
+       @Override
+       public List<Point2D> calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem)
+                       throws DatabaseException {
+               DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+               ModelingResources MOD = ModelingResources.getInstance(graph);
+               StructuralResource2 STR = StructuralResource2.getInstance(graph);
+               
+               Resource vertex = groupItem;
+               if (!graph.isInstanceOf(vertex, DN.Vertex))
+                       return Collections.emptyList();
+               
+               double[] coords = graph.getRelatedValue(vertex, DiagramResource.getInstance(graph).HasLocation);
+               
+               Resource component = DistrictNetworkUtil.getMappedComponentCached(graph, vertex);
+               if (component == null)
+                       return Collections.emptyList();
+               
+               Resource componentType = graph.getPossibleType(component, STR.Component);
+               if (componentType == null)
+                       return Collections.emptyList();
+               
+               Function1<Resource, List<Resource>> fun = getConnectedComponentsFunctionCached(graph, componentType);
+               if (fun == null)
+                       return Collections.emptyList();
+
+               List<Resource> components = Simantics.applySCLRead(graph, fun, component);
+               
+               if (components == null || components.isEmpty())
+                       return Collections.emptyList();
+               
+               List<Point2D> result = new ArrayList<>(components.size() + 1);
+               result.add(new Point2D.Double(coords[0], coords[1]));
+               for (Resource comp : components) {
+                       Resource e = comp != null ? graph.getPossibleObject(comp, MOD.ComponentToElement) : null;
+                       Resource mappingElement = e != null ? graph.getPossibleObject(e, DN.MappedFromElement) : null;
+                       if (mappingElement != null) {
+                               double[] coords2 = graph.getRelatedValue(mappingElement, DiagramResource.getInstance(graph).HasLocation);
+                               result.add(new Point2D.Double(coords2[0], coords2[1]));
+                       }
+                       else {
+                               result.add(null);
+                       }
+               }
+               
+               return result;
+       }
+       
+       @Override
+       public void applyStyleForNode(EvaluationContext observer, INode parent, List<Point2D> result) {
+               if (result == null || result.size() < 2) {
+                       ProfileVariables.denyChild(parent, "*", "districtNetworkConnection");
+                       return;
+               }
+               
+               ConnectionLineNode node = ProfileVariables.claimChild(parent, "*", "districtNetworkConnection", ConnectionLineNode.class, observer);
+               if (node == null)
+                       return;
+               
+               node.setPoints(result);
+               node.setZIndex(0);
+               node.setStrokeWidth(2.f);
+       }
+
+       @Override
+       protected void cleanupStyleForNode(EvaluationContext evaluationContext, INode parent) {
+               ProfileVariables.denyChild(parent, "*", "districtNetworkConnection");
+       }
+       
+       private static Function1<Resource, List<Resource>> getConnectedComponentsFunctionCached(ReadGraph graph, Resource componentType)
+                       throws DatabaseException {
+               return graph.syncRequest(new ConnectedComponentsFunctionRequest(componentType), TransientCacheListener.instance());
+       }
+       
+       private static final class ConnectedComponentsFunctionRequest
+                       extends ResourceRead<Function1<Resource, List<Resource>>> {
+               public ConnectedComponentsFunctionRequest(Resource resource) {
+                       super(resource);
+               }
+
+               @SuppressWarnings("unchecked")
+               @Override
+               public Function1<Resource, List<Resource>> perform(ReadGraph graph) throws DatabaseException {
+                       Resource actionsModule = Layer0Utils.getPossibleChild(graph, resource, "Actions");
+                       if (actionsModule == null || !graph.isInstanceOf(actionsModule, Layer0.getInstance(graph).SCLModule))
+                               return null;
+                       
+                       String uri = graph.getURI(actionsModule);
+                       SCLContext sclContext = SCLContext.getCurrent();
+                       Object oldGraph = sclContext.get("graph");
+                       try {
+                               sclContext.put("graph", graph);
+                               return (Function1<Resource, List<Resource>>) SCLOsgi.MODULE_REPOSITORY.getValue(uri, "getConnectedComponents");
+                       } catch (ValueNotFound e1) {
+                               return null;
+                       } finally {
+                               sclContext.put("graph", oldGraph);
+                       }
+               }
+       }
+}
index 8d229b78c325ea49fb0d0f8500c25726b1c8cf81..fff235ac638133c53a43c072fc285a77b048d0f7 100644 (file)
@@ -67,12 +67,12 @@ public class DistrictNodeGroup implements Group {
     }
 
     @Override
-    public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener<Resource> listener) throws DatabaseException {
+    public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener<Resource> listener) {
         if (types.isEmpty()) {
             System.out.println("DistrictNodeGroup has no types!");
             return;
         }
-        processor.syncRequest(new TernaryRead<Resource, Collection<Resource>, Set<String>, Collection<Resource>>(runtimeDiagram, types, mappedComponentTypeNames) {
+        processor.asyncRequest(new TernaryRead<Resource, Collection<Resource>, Set<String>, Collection<Resource>>(runtimeDiagram, types, mappedComponentTypeNames) {
             @Override
             public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {
                 return graph.syncRequest(new ElementsMappedToComponentTypes(parameter, parameter2, parameter3));
diff --git a/pom.xml b/pom.xml
index 8bec8afda089560df799ba0c8d7c6aec8bb32109..5489a9087306724350c083bf849047ec9a21eeec 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -8,7 +8,7 @@
 
        <!-- common settings for all modules -->
        <properties>
-               <branch-spec>master</branch-spec>
+               <branch-spec>release/1.35.1</branch-spec>
                <simantics-download-site>http://www.simantics.org/download</simantics-download-site>
                <tycho-version>1.0.0</tycho-version>
        </properties>