]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Stash for edge styling & import progress monitoring 71/1971/3
authorjsimomaa <jani.simomaa@gmail.com>
Mon, 30 Jul 2018 07:19:22 +0000 (10:19 +0300)
committerjsimomaa <jani.simomaa@gmail.com>
Mon, 30 Jul 2018 09:11:47 +0000 (12:11 +0300)
gitlab #2

Change-Id: I6f2b2349936641c9b4405335dc81bf7dbbce401c

17 files changed:
org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizard.java
org.simantics.district.network.ontology/graph.tg
org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph
org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNEdgeBuilder.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictPanZoomRotateHandler.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElementFactory.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElementFactory.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.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNTranslateMode.java
org.simantics.district.network/META-INF/MANIFEST.MF
org.simantics.district.network/adapters.xml
org.simantics.district.network/scl/Simantics/District.scl
org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java

index 80bf1447ae1bc9d602102e7ba7faa133d2661439..76c30d98113adb381a39b1c38c47b80b479ab54b 100644 (file)
@@ -2,6 +2,8 @@ package org.simantics.district.imports.ui;
 
 import java.lang.reflect.InvocationTargetException;
 import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 import org.apache.commons.csv.CSVRecord;
@@ -23,13 +25,16 @@ import org.simantics.Simantics;
 import org.simantics.databoard.Bindings;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.ObjectsWithType;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.request.Write;
+import org.simantics.diagram.stubs.DiagramResource;
 import org.simantics.district.imports.DistrictImportUtils;
 import org.simantics.district.network.DistrictNetworkUtil;
 import org.simantics.district.network.ontology.DistrictNetworkResource;
 import org.simantics.district.network.ui.DNEdgeBuilder;
-import org.simantics.maps.MapScalingTransform;
+import org.simantics.district.network.ui.DNEdgeBuilder.ResourceVertex;
+import org.simantics.layer0.Layer0;
 import org.simantics.utils.ui.ExceptionUtils;
 
 public class CSVImportWizard extends Wizard implements IImportWizard {
@@ -38,6 +43,7 @@ public class CSVImportWizard extends Wizard implements IImportWizard {
     
     public CSVImportWizard() {
         setWindowTitle("Import CSV data");
+        setNeedsProgressMonitor(true);
     }
     
     
@@ -56,12 +62,12 @@ public class CSVImportWizard extends Wizard implements IImportWizard {
 
                 @Override
                 public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
-                    monitor.beginTask("Importing CSV", 1000);
                     try {
                         Path csvFile = model.getSource();
                         char delim = model.getDelimiter();
                         
                         List<CSVRecord> rows = DistrictImportUtils.readRows(csvFile, delim, -1);
+                        monitor.beginTask("Importing CSV", rows.size());
                         
     //                    Path wktFile = model.getWKTFile();
                         
@@ -127,6 +133,13 @@ public class CSVImportWizard extends Wizard implements IImportWizard {
                                 
                                 DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
                                 
+                                Collection<Resource> vertices = graph.syncRequest(new ObjectsWithType(model.getParentDiagram(), Layer0.getInstance(graph).ConsistsOf, DistrictNetworkResource.getInstance(graph).Vertex));
+                                List<ResourceVertex> vv = new ArrayList<>(vertices.size());
+                                for (Resource vertex : vertices) {
+                                    double[] existingCoords = graph.getRelatedValue2(vertex, DiagramResource.getInstance(graph).HasLocation, Bindings.DOUBLE_ARRAY);
+                                    vv.add(new ResourceVertex(vertex, existingCoords));
+                                }
+                                
                                 for (int k = 1; k < rows.size(); k++) {
                                     CSVRecord row = rows.get(k);
                                     
@@ -136,7 +149,7 @@ public class CSVImportWizard extends Wizard implements IImportWizard {
                                         if (model.isVertexImport()) {
                                             String xCoords = row.get(xCoordColumnIndex);
                                             String yCoords = row.get(yCoordColumnIndex);
-                                            double xCoord = - Double.parseDouble(xCoords); // make negative for now
+                                            double xCoord = Double.parseDouble(xCoords);
                                             double yCoord = Double.parseDouble(yCoords);
                                             
                                             double z = 0;
@@ -159,9 +172,9 @@ public class CSVImportWizard extends Wizard implements IImportWizard {
                                                 DirectPosition res = actualTransform.transform(sourcePos, targetPos);
                                                 coords = res.getCoordinate();
                                             } else {
-                                                coords = new double[] { xCoord / MapScalingTransform.getScaleX(), yCoord / MapScalingTransform.getScaleY() };
+                                                coords = new double[] { xCoord, yCoord };
                                             }
-                                            Resource vertex = DistrictNetworkUtil.createVertex(graph, model.getParentDiagram(), new double[] { coords[1], -coords[0]}, model.getComponentMappings().get(mappingValue));
+                                            Resource vertex = DistrictNetworkUtil.createVertex(graph, model.getParentDiagram(), coords, model.getComponentMappings().get(mappingValue));
                                             
                                             writeStringValue(graph, row, idColumn, vertex, DN.HasId);
                                             
@@ -192,10 +205,10 @@ public class CSVImportWizard extends Wizard implements IImportWizard {
                                             String endXCoords = row.get(endXCoordColumnIndex);
                                             String endYCoords = row.get(endYCoordColumnIndex);
                                             
-                                            double startXCoord = Double.parseDouble(startXCoords); // make negative
+                                            double startXCoord = Double.parseDouble(startXCoords); // make negative
                                             double startYCoord = Double.parseDouble(startYCoords);
                                             
-                                            double endXCoord = Double.parseDouble(endXCoords); // make negative
+                                            double endXCoord = Double.parseDouble(endXCoords); // make negative
                                             double endYCoord = Double.parseDouble(endYCoords);
                                             
                                             double[] startCoords;
@@ -211,11 +224,11 @@ public class CSVImportWizard extends Wizard implements IImportWizard {
                                                 DirectPosition endRes = actualTransform.transform(endSourcePos, endTargetPos);
                                                 endCoords = endRes.getCoordinate();
                                             } else {
-                                                startCoords = new double[] { startXCoord / MapScalingTransform.getScaleX(), startYCoord / MapScalingTransform.getScaleY() };
-                                                endCoords = new double[] { endXCoord / MapScalingTransform.getScaleX(), endYCoord / MapScalingTransform.getScaleY() };
+                                                startCoords = new double[] { startXCoord , startYCoord };
+                                                endCoords = new double[] { endXCoord , endYCoord };
                                             }
-                                             
-                                            Resource edge = DNEdgeBuilder.create(graph, model.getParentDiagram(), model.getComponentMappings().get(mappingValue), new double[] { startCoords[1], -startCoords[0]}, new double[] { endCoords[1], -endCoords[0]}, padding);
+
+                                            Resource edge = DNEdgeBuilder.create(graph, vv, model.getParentDiagram(), model.getComponentMappings().get(mappingValue), startCoords, endCoords, padding);
                                             writeStringValue(graph, row, idColumn, edge, DN.HasId);
                                             
                                             writeValue(graph, row, diameterColumnIndex, edge, DN.Edge_HasDiameter);
@@ -229,6 +242,7 @@ public class CSVImportWizard extends Wizard implements IImportWizard {
                                     } catch (MismatchedDimensionException | TransformException | DatabaseException e) {
                                         throw new DatabaseException(e);
                                     }
+                                    monitor.worked(1);
                                 }
                             }
                         });
index be35590cce833b30baf3448c0490abb4740de784..2bda23f8d57b1aa466c0c304240c0d739b4338d0 100644 (file)
Binary files a/org.simantics.district.network.ontology/graph.tg and b/org.simantics.district.network.ontology/graph.tg differ
index 75716c692b302cf108addf830ac258b7c8a747fd..64dbb60f89f6be5c06e581af81842d59145eed79 100644 (file)
@@ -354,6 +354,9 @@ DN.DistrictProfile : DIA.Profile
           DN.DistrictProfile.entry1
             L0.HasLabel "Id"
             @DIA.groupStyleProfileEntry DN.ComponentIdStyle DN.Groups.ElementGroup
+          DN.DistrictProfile.entry2
+            L0.HasLabel "Edge Node Styling"
+            @DIA.groupStyleProfileEntry DN.EdgeNodeStyle DN.Groups.ElementGroup
 
 DN.Groups : L0.Library
 
@@ -375,3 +378,22 @@ DN.ComponentIdStyle : DIA.ResourceSCLTextGridStyle
         """
         "String -> Variable -> <ReadGraph> (String, String, String)"
     @G2D.fontProperty DIA.TextElement.font "Arial" 30 G2D.FontStyle.normal_font_style
+
+//DN.EdgeNodeGroup : DIA.Group
+
+//DN.Profiles : L0.Library
+
+DN.EdgeNodeStyle : DIA.Style
+
+// Templates
+
+//groupStyleEntry : L0.Template
+//    @template %subject %style %group
+//        %subject : DIA.GroupStyleProfileEntry
+//            DIA.ProfileEntry.HasStyle %style
+//            DIA.ProfileEntry.HasGroup %group
+
+
+//DN.Profiles.EdgeNodeStyle
+//    L0.HasLabel "Edge Node Style"
+//    @groupStyleEntry DN.EdgeNodeStyle DN.EdgeNodeGroup
index 32aabfa25f8cf1f8f5ff1821c4429a03cbeaf431..d1e9ebd1ee38fbb4f3b2e4a6c2fa3652f05eb2a3 100644 (file)
@@ -25,11 +25,13 @@ public class DistrictNetworkResource {
     public final Resource DistrictProfile;
     public final Resource DistrictProfile_entry;
     public final Resource DistrictProfile_entry1;
+    public final Resource DistrictProfile_entry2;
     public final Resource EPSG_4326;
     public final Resource Edge;
     public final Resource EdgeDefaultMapping;
     public final Resource EdgeDefaultMapping_Inverse;
     public final Resource EdgeMappingParameterType;
+    public final Resource EdgeNodeStyle;
     public final Resource Edge_HasDiameter;
     public final Resource Edge_HasDiameter_Inverse;
     public final Resource Edge_HasFlowArea;
@@ -214,11 +216,13 @@ public class DistrictNetworkResource {
         public static final String DistrictProfile = "http://www.simantics.org/DistrictNetwork-1.0/DistrictProfile";
         public static final String DistrictProfile_entry = "http://www.simantics.org/DistrictNetwork-1.0/DistrictProfile/entry";
         public static final String DistrictProfile_entry1 = "http://www.simantics.org/DistrictNetwork-1.0/DistrictProfile/entry1";
+        public static final String DistrictProfile_entry2 = "http://www.simantics.org/DistrictNetwork-1.0/DistrictProfile/entry2";
         public static final String EPSG_4326 = "http://www.simantics.org/DistrictNetwork-1.0/EPSG_4326";
         public static final String Edge = "http://www.simantics.org/DistrictNetwork-1.0/Edge";
         public static final String EdgeDefaultMapping = "http://www.simantics.org/DistrictNetwork-1.0/EdgeDefaultMapping";
         public static final String EdgeDefaultMapping_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/EdgeDefaultMapping/Inverse";
         public static final String EdgeMappingParameterType = "http://www.simantics.org/DistrictNetwork-1.0/EdgeMappingParameterType";
+        public static final String EdgeNodeStyle = "http://www.simantics.org/DistrictNetwork-1.0/EdgeNodeStyle";
         public static final String Edge_HasDiameter = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasDiameter";
         public static final String Edge_HasDiameter_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasDiameter/Inverse";
         public static final String Edge_HasFlowArea = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasFlowArea";
@@ -413,11 +417,13 @@ public class DistrictNetworkResource {
         DistrictProfile = getResourceOrNull(graph, URIs.DistrictProfile);
         DistrictProfile_entry = getResourceOrNull(graph, URIs.DistrictProfile_entry);
         DistrictProfile_entry1 = getResourceOrNull(graph, URIs.DistrictProfile_entry1);
+        DistrictProfile_entry2 = getResourceOrNull(graph, URIs.DistrictProfile_entry2);
         EPSG_4326 = getResourceOrNull(graph, URIs.EPSG_4326);
         Edge = getResourceOrNull(graph, URIs.Edge);
         EdgeDefaultMapping = getResourceOrNull(graph, URIs.EdgeDefaultMapping);
         EdgeDefaultMapping_Inverse = getResourceOrNull(graph, URIs.EdgeDefaultMapping_Inverse);
         EdgeMappingParameterType = getResourceOrNull(graph, URIs.EdgeMappingParameterType);
+        EdgeNodeStyle = getResourceOrNull(graph, URIs.EdgeNodeStyle);
         Edge_HasDiameter = getResourceOrNull(graph, URIs.Edge_HasDiameter);
         Edge_HasDiameter_Inverse = getResourceOrNull(graph, URIs.Edge_HasDiameter_Inverse);
         Edge_HasFlowArea = getResourceOrNull(graph, URIs.Edge_HasFlowArea);
index c2238d8e56eb0e082ce7ce4482cb402a7faba869..0270fea0277eaa0c799fb8556a4367bc50e6c578 100644 (file)
@@ -1,7 +1,9 @@
 package org.simantics.district.network.ui;
 
 import java.awt.geom.Rectangle2D;
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
 
 import org.simantics.databoard.Bindings;
 import org.simantics.db.Resource;
@@ -37,10 +39,16 @@ public class DNEdgeBuilder {
     }
 
     public static Resource create(WriteGraph graph, Resource diagramResource, double[] start, double[] end, double padding) throws DatabaseException {
-        return create(graph, diagramResource, null, start, end, padding);
+        Collection<Resource> vertices = graph.syncRequest(new ObjectsWithType(diagramResource, Layer0.getInstance(graph).ConsistsOf, DistrictNetworkResource.getInstance(graph).Vertex));
+        List<ResourceVertex> vv = new ArrayList<>(vertices.size());
+        for (Resource vertex : vertices) {
+            double[] existingCoords = graph.getRelatedValue2(vertex, DiagramResource.getInstance(graph).HasLocation, Bindings.DOUBLE_ARRAY);
+            vv.add(new ResourceVertex(vertex, existingCoords));
+        }
+        return create(graph, vv, diagramResource, null, start, end, padding);
     }
     
-    public static Resource create(WriteGraph graph, Resource diagramResource, Resource mapping, double[] start, double[] end, double padding) throws DatabaseException {
+    public static Resource create(WriteGraph graph, Collection<ResourceVertex> vertices, Resource diagramResource, Resource mapping, double[] start, double[] end, double padding) throws DatabaseException {
         
         DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
         
@@ -48,24 +56,23 @@ public class DNEdgeBuilder {
         Resource edge = getOrCreateEdge(graph, diagramResource, mapping);
         
         // 2. Add vertices
-        Collection<Resource> vertices = graph.syncRequest(new ObjectsWithType(diagramResource, Layer0.getInstance(graph).ConsistsOf, DistrictNetworkResource.getInstance(graph).Vertex));
-        Resource startVertex = getOrCreateVertex(graph, diagramResource, vertices, start, padding);
-        Resource endVertex = getOrCreateVertex(graph, diagramResource, vertices, end, padding);
+        Resource startVertex = getOrCreateVertex(graph, diagramResource, vertices, start, padding, null);
+        Resource endVertex = getOrCreateVertex(graph, diagramResource, vertices, end, padding, startVertex);
         
         graph.claim(edge, DN.HasStartVertex, startVertex);
         graph.claim(edge, DN.HasEndVertex, endVertex);
         
         // We need to put GraphLayer to newLayers so...
-        for (Resource layer : graph.getObjects(diagramResource, DiagramResource.getInstance(graph).HasLayer)) {
-            IGraphLayerUtil layerUtil = graph.adapt(graph.getSingleObject(layer, Layer0.getInstance(graph).InstanceOf), IGraphLayerUtil.class);
-            
-            GraphLayer gl = layerUtil.loadLayer(graph, layer);
-            gl.forEachTag(tag -> {
-                DiagramGraphUtil.tag(graph, startVertex, tag, true);
-                DiagramGraphUtil.tag(graph, endVertex, tag, true);
-            });
-        }
-        
+//        for (Resource layer : graph.getObjects(diagramResource, DiagramResource.getInstance(graph).HasLayer)) {
+//            IGraphLayerUtil layerUtil = graph.adapt(graph.getSingleObject(layer, Layer0.getInstance(graph).InstanceOf), IGraphLayerUtil.class);
+//            
+//            GraphLayer gl = layerUtil.loadLayer(graph, layer);
+//            gl.forEachTag(tag -> {
+//                DiagramGraphUtil.tag(graph, startVertex, tag, true);
+//                DiagramGraphUtil.tag(graph, endVertex, tag, true);
+//            });
+//        }
+//        
         return edge;
     }
     public void create(WriteGraph graph,  double[] start, double[] end, double padding) throws DatabaseException {
@@ -85,23 +92,24 @@ public class DNEdgeBuilder {
         glm.putElementOnVisibleLayers(diagram, graph, res);
     }
 
-    private static Resource getOrCreateVertex(WriteGraph graph, Resource diagramResource, Collection<Resource> vertices, double[] coords, double padding) throws DatabaseException {
+    private static Resource getOrCreateVertex(WriteGraph graph, Resource diagramResource, Collection<ResourceVertex> vertices, double[] coords, double padding, Resource startVertex) throws DatabaseException {
         Resource vertex = null;
         double halfPadding = padding / 2;
         double maxDistance = Double.MAX_VALUE;
-        for (Resource vertx : vertices) {
-            double[] existingCoords = graph.getRelatedValue2(vertx, DiagramResource.getInstance(graph).HasLocation, Bindings.DOUBLE_ARRAY);
-            Rectangle2D existing = new Rectangle2D.Double(existingCoords[0] - halfPadding, existingCoords[1] - halfPadding, padding, padding);
+        for (ResourceVertex vertx : vertices) {
+            Rectangle2D existing = new Rectangle2D.Double(vertx.coords[0] - halfPadding, vertx.coords[1] - halfPadding, padding, padding);
             Rectangle2D tobecreated = new Rectangle2D.Double(coords[0] - halfPadding, coords[1] - halfPadding, padding, padding);
             if (existing.intersects(tobecreated)) {
-                double dist = Math.sqrt((Math.pow(coords[0] - existingCoords[0], 2) + (Math.pow(coords[1] - existingCoords[1], 2))));
-                if (dist <= maxDistance) {
-                    vertex = vertx;
+                double dist = Math.sqrt((Math.pow(coords[0] - vertx.coords[0], 2) + (Math.pow(coords[1] - vertx.coords[1], 2))));
+                if (dist <= maxDistance && !vertx.vertex.equals(startVertex)) {
+                    vertex = vertx.vertex;
+                    maxDistance = dist;
                 }
             }
         }
         if (vertex == null) {
             vertex = DistrictNetworkUtil.createVertex(graph, diagramResource, coords); 
+            vertices.add(new ResourceVertex(vertex, coords));
         }
         return vertex;
     }
@@ -110,4 +118,14 @@ public class DNEdgeBuilder {
         return DistrictNetworkUtil.createEdge(graph, diagramResource, mapping);
     }
 
+    public static class ResourceVertex {
+        
+        final Resource vertex;
+        final double[] coords;
+        
+        public ResourceVertex(Resource vertex, double[] coords) {
+            this.vertex = vertex;
+            this.coords = coords;
+        }
+    }
 }
index 8187002b9f3ea6703cf1b6d04b067e95f55a45d1..9d07f0378a18e69fd9252200b06a4000b3ff2233 100644 (file)
@@ -15,6 +15,7 @@ import org.simantics.g2d.participant.BackgroundPainter;
 import org.simantics.g2d.participant.GridPainter;
 import org.simantics.g2d.participant.PanZoomRotateHandler;
 import org.simantics.g2d.participant.RenderingQualityInteractor;
+import org.simantics.g2d.participant.ZoomToAreaHandler;
 import org.simantics.maps.MapScalingTransform;
 import org.simantics.maps.eclipse.MapPainter;
 import org.simantics.modeling.ui.diagramEditor.DiagramViewer;
@@ -58,4 +59,13 @@ public class DistrictDiagramViewer extends DiagramViewer {
         ctx.add(new MapRulerPainter());
         ctx.add(new BackgroundPainter());
     }
+    
+    protected void addViewManipulationParticipants(CanvasContext ctx) {
+        ctx.add(new DistrictPanZoomRotateHandler());
+        //ctx.add(new MousePanZoomInteractor());
+        //ctx.add(new MultitouchPanZoomRotateInteractor());
+        // ctx.add( new OrientationRestorer() );
+        ctx.add(new ZoomToAreaHandler());
+    }
+
 }
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictPanZoomRotateHandler.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictPanZoomRotateHandler.java
new file mode 100644 (file)
index 0000000..1a4f83d
--- /dev/null
@@ -0,0 +1,53 @@
+package org.simantics.district.network.ui;
+
+import org.simantics.g2d.participant.PanZoomRotateHandler;
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseWheelMovedEvent;
+import org.simantics.scenegraph.g2d.nodes.NavigationNode;
+
+public class DistrictPanZoomRotateHandler extends PanZoomRotateHandler {
+
+    public DistrictPanZoomRotateHandler() {
+    }
+
+    @Override
+    protected Class<? extends NavigationNode> getNavigationNodeClass() {
+        return DistrictNavigationNode.class;
+    }
+
+    public static class DistrictNavigationNode extends NavigationNode {
+
+        private static final long serialVersionUID = 5452897272925816875L;
+
+        @Override
+        public Double getZoomInLimit() {
+            return super.getZoomInLimit();
+        }
+
+        @Override
+        public Double getZoomOutLimit() {
+            return super.getZoomOutLimit();
+        }
+
+        @Override
+        public boolean mouseWheelMoved(MouseWheelMovedEvent me) {
+            if (navigationEnabled && zoomEnabled) {
+                double scroll = Math.min(0.9, -me.wheelRotation / 20.0);
+                double z = 1 - scroll;
+                double dx = (me.controlPosition.getX() - transform.getTranslateX()) / transform.getScaleX();
+                double dy = (me.controlPosition.getY() - transform.getTranslateY()) / transform.getScaleY();
+                dx = dx * (1 - z);
+                dy = dy * (1 - z);
+                double limitedScale = limitScaleFactor(z);
+                if (limitedScale != 1.0) {
+                    translate(dx, dy);
+                    scale(z, z);
+                    transformChanged();
+                    dropQuality();
+                    repaint();
+                }
+            }
+            return false;
+        }
+
+    }
+}
index 36d573081b8489bec41274311008eed35f33c624..1003a9b22b0a8cd55646c79f9dd4ad38520ed8bb 100644 (file)
@@ -49,7 +49,9 @@ public class DistrictNetworkEdgeElementFactory extends SyncElementFactory {
     
     @Override
     public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource edgeResource, IElement element) throws DatabaseException {
-        
+        if (!graph.hasStatement(edgeResource))
+            return; // already deleted
+
         Resource startVertex = graph.getSingleObject(edgeResource, DN.HasStartVertex);
         Resource endVertex = graph.getSingleObject(edgeResource, DN.HasEndVertex);
 
index 431beb52d60280de30d44d5bf31c11c5a129a18e..1fc38bf6e03f8cf56566a9445e929fb621d510ea 100644 (file)
@@ -45,7 +45,9 @@ public class DistrictNetworkVertexElementFactory extends SyncElementFactory {
 
     @Override
     public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource vertexResource, IElement element) throws DatabaseException {
-        
+        if (!graph.hasStatement(vertexResource))
+            return; // already deleted
+
         double[] coords = graph.getRelatedValue(vertexResource, DIA.HasLocation);
         DistrictNetworkVertex vertex = new DistrictNetworkVertex(coords);
         
index 745f2a80fccb04dbf0e83bbc2bfeff5b252489b0..030802755080b61135ddae9951c3293c663bcde4 100644 (file)
@@ -31,6 +31,8 @@ public class DistrictNetworkEdgeNode extends G2DNode {
 
     private Color color;
 
+    private Double stroke;
+
     @Override
     public void init() {
     }
@@ -61,7 +63,12 @@ public class DistrictNetworkEdgeNode extends G2DNode {
         g2d.setColor(color);
         if (STROKE != null) {
             if (scaleStroke && STROKE instanceof BasicStroke) {
-                BasicStroke bs = GeometryUtils.scaleStroke(STROKE, (float) (1.0 / GeometryUtils.getScale(g2d.getTransform())));
+                double str;
+                if (stroke != null)
+                    str = stroke;
+                else
+                    str = 1.0;
+                BasicStroke bs = GeometryUtils.scaleStroke(STROKE, (float) (str / GeometryUtils.getScale(g2d.getTransform())));
                 g2d.setStroke(bs);
             } else {
                 g2d.setStroke(STROKE);
@@ -82,9 +89,9 @@ public class DistrictNetworkEdgeNode extends G2DNode {
     public static Path2D calculatePath(DistrictNetworkEdge edge) {
         // Convert to screen coordinates
         double startX = ModelledCRS.longitudeToX(edge.getStartPoint().getX());
-        double startY = ModelledCRS.latitudeToY(edge.getStartPoint().getY());
+        double startY = ModelledCRS.latitudeToY(-edge.getStartPoint().getY()); // Invert for Simantics
         double endX = ModelledCRS.longitudeToX(edge.getEndPoint().getX());
-        double endY = ModelledCRS.latitudeToY(edge.getEndPoint().getY());
+        double endY = ModelledCRS.latitudeToY(-edge.getEndPoint().getY());// Invert for Simantics
         
         // render
         Path2D path = new Path2D.Double();
@@ -126,4 +133,9 @@ public class DistrictNetworkEdgeNode extends G2DNode {
         return color;
     }
 
+    @PropertySetter(value = "stroke")
+    public void setStroke(Double stroke) {
+        this.stroke = stroke / 100;
+    }
+
 }
index c566981e05261b5f735ae18c77538a18a97a2dc2..99eb3cc117b7fb91cbb8352016a62da7e9836249 100644 (file)
@@ -24,10 +24,10 @@ public class DistrictNetworkVertexNode extends G2DNode {
     private static final long serialVersionUID = -2641639101400236719L;
     private DistrictNetworkVertex vertex;
 
-    private static final double left = -0.5;
-    private static final double top = -0.5;
-    private static final double width = 1;
-    private static final double height = 1;
+    private static final double left = -0.25;
+    private static final double top = -0.25;
+    private static final double width = 0.5;
+    private static final double height = 0.5;
     
     private static final Rectangle2D NORMAL = new Rectangle2D.Double(left, top, width, height);
     private static final Rectangle2D HOVERED = new Rectangle2D.Double(left * 3, top * 3, width * 3, height * 3);
@@ -40,6 +40,8 @@ public class DistrictNetworkVertexNode extends G2DNode {
 
     private Rectangle2D bounds;
 
+    private Double strokee;
+
     @Override
     public void init() {
         setZIndex(2);
@@ -65,7 +67,11 @@ public class DistrictNetworkVertexNode extends G2DNode {
         double scaleRecip = 1;
         if (scaleStroke) {
             double scale = GeometryUtils.getScale(g2d.getTransform());
-            
+            double str;
+            if (strokee != null)
+                str = strokee;
+            else
+                str = 1.0;
             //System.out.println("scale: " + scale);
             scaleRecip = 1.0 / scale;
         }
@@ -131,7 +137,7 @@ public class DistrictNetworkVertexNode extends G2DNode {
     private static Point2D calculatePoint2D(DistrictNetworkVertex vertex) {
         Point2D point= vertex.getPoint();
         double x = ModelledCRS.longitudeToX(point.getX());
-        double y = ModelledCRS.latitudeToY(point.getY());
+        double y = ModelledCRS.latitudeToY(-point.getY()); // Inverse because Simantics Diagram is inverted
 
         // Apply the scaling
         Point2D res = new Point2D.Double(x, y);
@@ -162,4 +168,8 @@ public class DistrictNetworkVertexNode extends G2DNode {
         return color;
     }
 
+    @PropertySetter(value = "stroke")
+    public void setStroke(Double stroke) {
+        this.strokee = stroke / 10;
+    }
 }
index 1ccde2c7b18db0c459648af546428b57c3205428..aaf26a10855545bd97f3eb585a573981d775bba2 100644 (file)
@@ -166,10 +166,10 @@ public class NetworkDrawingNode extends G2DNode {
         double scaleY = getTransform().getScaleY();
         double scaleX = getTransform().getScaleX();
         
-        double startLat = ModelledCRS.yToLatitude(start.getY() / scaleY);
+        double startLat = ModelledCRS.yToLatitude(-start.getY() / scaleY);
         double startLon = ModelledCRS.xToLongitude(start.getX() / scaleX);
         
-        double endLat = ModelledCRS.yToLatitude(end.getY() / scaleY);
+        double endLat = ModelledCRS.yToLatitude(-end.getY() / scaleY);
         double endLon = ModelledCRS.xToLongitude(end.getX() / scaleX);
         
         double[] startCoords = new double[] { startLon, startLat };
index fda0fc717d3dce0d1511c3dceb414294a2f293ad..fdc333b2fb82f88d64da9894f8111d0be0f27812 100644 (file)
@@ -5,8 +5,6 @@ import java.awt.geom.Point2D;
 import java.util.ArrayList;
 import java.util.Collection;
 
-import javax.xml.bind.DataBindingException;
-
 import org.simantics.Simantics;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
@@ -55,7 +53,7 @@ public class DNTranslateMode extends TranslateMode {
                             AffineTransform at = ElementUtils.getLocalTransform(e, new AffineTransform());
                             if (graph.isInstanceOf(res, DN.Vertex)) {
                                 
-                                double lat = ModelledCRS.yToLatitude(y + (dy / at.getScaleY()));
+                                double lat = ModelledCRS.yToLatitude(y + (-dy / at.getScaleY()));
                                 double lon = ModelledCRS.xToLongitude(x + (dx / at.getScaleX()));
                                 
                                 // write to db
@@ -75,7 +73,7 @@ public class DNTranslateMode extends TranslateMode {
                         CommentMetadata cm = graph.getMetadata(CommentMetadata.class);
                         graph.addMetadata(cm.add("Translated " + transformed.size() + " "
                                 + (transformed.size() == 1 ? "element" : "elements")
-                                + " by (" + dx + "," + dy + ") mm."));
+                                + " by (" + dx + "," + -dy + ") mm."));
                     }
                 }
             });
index 47d74d8e09bd90c66c98ceb92c9c0681ea2cc53b..2d1fe771ff1e313c11f68fa1d3e0744639be2598 100644 (file)
@@ -12,5 +12,6 @@ Require-Bundle: org.simantics.db,
  org.simantics.db.layer0,
  org.simantics.district.maps,
  org.simantics.district.geotools;bundle-version="1.0.0",
- org.simantics.diagram
+ org.simantics.diagram,
+ org.simantics.scenegraph.profile;bundle-version="1.0.0"
 Export-Package: org.simantics.district.network
index 590741aa62768a7f275ec1ede5079a444463ddb6..adb325ce1824191055ea263ac1d54a3424a4dd91 100644 (file)
@@ -8,4 +8,15 @@
                        <this />
                </type>
        </target>
+       <target interface="org.simantics.scenegraph.profile.Group">
+               <resource uri="http://www.simantics.org/DistrictNetwork-1.0/EdgeNodeGroup"
+                       class="org.simantics.district.network.profile.EdgeNodeGroup">
+            <graph/>
+               </resource>
+    </target>
+       <target interface="org.simantics.scenegraph.profile.Style">
+               <resource uri="http://www.simantics.org/DistrictNetwork-1.0/EdgeNodeStyle"
+                       class="org.simantics.district.network.profile.EdgeNodeStyle">
+               </resource>
+    </target>
 </adapters>
\ No newline at end of file
index c92cc4cc6e97b88cbbe9dee9b971f52f43d06c85..6318d7550b5a7bfcf7a15c0a245bdce85c83aef9 100644 (file)
@@ -78,3 +78,8 @@ translateElement elem = do
         ()
     else ()
     ()
+
+importJava "org.simantics.district.network.DistrictNetworkUtil" where
+    createVertex :: Resource -> Vector Double -> Resource -> <WriteGraph, Proc> Resource
+    createEdge :: Resource -> Resource -> <WriteGraph, Proc> Resource
+
index 165e6e96327dd1e655e09bb0997fa024fb2a4b9a..40e8fc1d7825e3f47c877030b64ac3dcd632c9fe 100644 (file)
@@ -22,7 +22,7 @@ public class DistrictNetworkUtil {
     public static Resource createEdge(WriteGraph graph, Resource composite) throws DatabaseException {
         return createEdge(graph, composite, graph.getPossibleObject(composite, DistrictNetworkResource.getInstance(graph).EdgeDefaultMapping));
     }
-    
+
     public static Resource createEdge(WriteGraph graph, Resource composite, Resource mapping) throws DatabaseException {
         Layer0 L0 = Layer0.getInstance(graph);
         DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
@@ -39,14 +39,25 @@ public class DistrictNetworkUtil {
         graph.claim(composite, L0.ConsistsOf, L0.PartOf, edge);
         
         claimFreshElementName(graph, composite, edge);
+        
+        // We need to put GraphLayer to newLayers so...
+        for (Resource layer : graph.getObjects(composite, DiagramResource.getInstance(graph).HasLayer)) {
+            IGraphLayerUtil layerUtil = graph.adapt(graph.getSingleObject(layer, Layer0.getInstance(graph).InstanceOf), IGraphLayerUtil.class);
+            
+            GraphLayer gl = layerUtil.loadLayer(graph, layer);
+            gl.forEachTag(tag -> {
+                DiagramGraphUtil.tag(graph, edge, tag, true);
+            });
+        }
+        
         return edge;
     }
-    
+
     public static Resource createVertex(WriteGraph graph, Resource composite, double[] coords) throws DatabaseException {
         Resource defaultVertexMapping = graph.getPossibleObject(composite, DistrictNetworkResource.getInstance(graph).VertexDefaultMapping);
         return createVertex(graph, composite, coords, defaultVertexMapping);
     }
-    
+
     public static Resource createVertex(WriteGraph graph, Resource composite, double[] coords, Resource mapping) throws DatabaseException {
         Layer0 L0 = Layer0.getInstance(graph);
         DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);