From: jsimomaa Date: Mon, 30 Jul 2018 07:19:22 +0000 (+0300) Subject: Stash for edge styling & import progress monitoring X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=ac6ad8ff2b20a10e85e7b12c1af670500daebdd4;hp=82fc4004ddaf355147e97fd951a18d3a3815e049;p=simantics%2Fdistrict.git Stash for edge styling & import progress monitoring gitlab #2 Change-Id: I6f2b2349936641c9b4405335dc81bf7dbbce401c --- diff --git a/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizard.java b/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizard.java index 80bf1447..76c30d98 100644 --- a/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizard.java +++ b/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizard.java @@ -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 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 vertices = graph.syncRequest(new ObjectsWithType(model.getParentDiagram(), Layer0.getInstance(graph).ConsistsOf, DistrictNetworkResource.getInstance(graph).Vertex)); + List 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); } } }); diff --git a/org.simantics.district.network.ontology/graph.tg b/org.simantics.district.network.ontology/graph.tg index be35590c..2bda23f8 100644 Binary files a/org.simantics.district.network.ontology/graph.tg and b/org.simantics.district.network.ontology/graph.tg differ diff --git a/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph b/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph index 75716c69..64dbb60f 100644 --- a/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph +++ b/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph @@ -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 -> (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 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 32aabfa2..d1e9ebd1 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 @@ -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); diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNEdgeBuilder.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNEdgeBuilder.java index c2238d8e..0270fea0 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNEdgeBuilder.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNEdgeBuilder.java @@ -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 vertices = graph.syncRequest(new ObjectsWithType(diagramResource, Layer0.getInstance(graph).ConsistsOf, DistrictNetworkResource.getInstance(graph).Vertex)); + List 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 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 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 vertices, double[] coords, double padding) throws DatabaseException { + private static Resource getOrCreateVertex(WriteGraph graph, Resource diagramResource, Collection 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; + } + } } diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java index 8187002b..9d07f037 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java @@ -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 index 00000000..1a4f83d8 --- /dev/null +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictPanZoomRotateHandler.java @@ -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 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; + } + + } +} diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElementFactory.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElementFactory.java index 36d57308..1003a9b2 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElementFactory.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElementFactory.java @@ -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); diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElementFactory.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElementFactory.java index 431beb52..1fc38bf6 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElementFactory.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElementFactory.java @@ -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); diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java index 745f2a80..03080275 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java @@ -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; + } + } 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 c566981e..99eb3cc1 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 @@ -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; + } } diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java index 1ccde2c7..aaf26a10 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java @@ -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 }; diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNTranslateMode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNTranslateMode.java index fda0fc71..fdc333b2 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNTranslateMode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNTranslateMode.java @@ -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.")); } } }); diff --git a/org.simantics.district.network/META-INF/MANIFEST.MF b/org.simantics.district.network/META-INF/MANIFEST.MF index 47d74d8e..2d1fe771 100644 --- a/org.simantics.district.network/META-INF/MANIFEST.MF +++ b/org.simantics.district.network/META-INF/MANIFEST.MF @@ -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 diff --git a/org.simantics.district.network/adapters.xml b/org.simantics.district.network/adapters.xml index 590741aa..adb325ce 100644 --- a/org.simantics.district.network/adapters.xml +++ b/org.simantics.district.network/adapters.xml @@ -8,4 +8,15 @@ + + + + + + + + + \ No newline at end of file diff --git a/org.simantics.district.network/scl/Simantics/District.scl b/org.simantics.district.network/scl/Simantics/District.scl index c92cc4cc..6318d755 100644 --- a/org.simantics.district.network/scl/Simantics/District.scl +++ b/org.simantics.district.network/scl/Simantics/District.scl @@ -78,3 +78,8 @@ translateElement elem = do () else () () + +importJava "org.simantics.district.network.DistrictNetworkUtil" where + createVertex :: Resource -> Vector Double -> Resource -> Resource + createEdge :: Resource -> Resource -> Resource + diff --git a/org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java b/org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java index 165e6e96..40e8fc1d 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java +++ b/org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java @@ -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);