X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2Fadapters%2FDistrictNetworkEdgeElementFactory.java;h=3b18dc6f0f3481068853253ae5658ed076e59b78;hb=e6b35994e05232dd536af4da224a342c1bd090af;hp=c3058a0edf5518341c6389ca61ad188019a0b85c;hpb=02ecca5e61d2eb17de40cc058be678b414aaad00;p=simantics%2Fdistrict.git 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 c3058a0e..3b18dc6f 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 @@ -1,8 +1,8 @@ package org.simantics.district.network.ui.adapters; -import java.awt.geom.Path2D; import java.awt.geom.Point2D; +import org.simantics.databoard.Bindings; import org.simantics.db.AsyncReadGraph; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; @@ -14,7 +14,6 @@ import org.simantics.diagram.synchronization.IModifiableSynchronizationContext; import org.simantics.diagram.synchronization.SynchronizationHints; import org.simantics.diagram.synchronization.graph.GraphSynchronizationHints; import org.simantics.diagram.synchronization.graph.layer.GraphLayerManager; -import org.simantics.district.network.ModelledCRS; import org.simantics.district.network.ontology.DistrictNetworkResource; import org.simantics.district.network.ui.DistrictNetworkEdge; import org.simantics.g2d.canvas.ICanvasContext; @@ -30,7 +29,8 @@ import org.simantics.maps.MapScalingTransform; public class DistrictNetworkEdgeElementFactory extends SyncElementFactory { public static final ElementClass CLASS = DistrictNetworkEdgeElement.CLASS; - + public static final double[] EMPTY = new double[0]; + private DistrictNetworkResource DN; private DiagramResource DIA; @@ -48,37 +48,39 @@ public class DistrictNetworkEdgeElementFactory extends SyncElementFactory { protected Resource getElementClassBaseType(AsyncReadGraph graph) { return DN.Edge; } - + @Override public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource edgeResource, IElement element) throws DatabaseException { - - Resource startVertex = graph.getSingleObject(edgeResource, DN.HasStartVertex); - Resource endVertex = graph.getSingleObject(edgeResource, DN.HasEndVertex); + if (!graph.hasStatement(edgeResource)) + return; // already deleted - // TODO: fix scale.. - double scale = 100000; - - double[] startCoords = graph.getRelatedValue2(startVertex, DIA.HasLocation); - - double startLon = ModelledCRS.longitudeToX(startCoords[0]) * scale; - double startLat = ModelledCRS.latitudeToY(startCoords[1]) * scale; + if (!graph.hasStatement(edgeResource, DN.HasStartVertex)) + return; // already deleted + Resource startVertex = graph.getSingleObject(edgeResource, DN.HasStartVertex); - double[] endCoords = graph.getRelatedValue2(endVertex, DIA.HasLocation); + if (!graph.hasStatement(edgeResource, DN.HasEndVertex)) + return; // already deleted + Resource endVertex = graph.getSingleObject(edgeResource, DN.HasEndVertex); - double endLon = ModelledCRS.longitudeToX(endCoords[0]) * scale; - double endLat = ModelledCRS.latitudeToY(endCoords[1]) * scale; - - Path2D path = new Path2D.Double(); - path.moveTo(startLon, startLat); - path.lineTo(endLon, endLat); + double[] startCoords = graph.getRelatedValue2(startVertex, DIA.HasLocation, Bindings.DOUBLE_ARRAY); + double[] endCoords = graph.getRelatedValue2(endVertex, DIA.HasLocation, Bindings.DOUBLE_ARRAY); - DistrictNetworkEdge edge = new DistrictNetworkEdge(path); + double[] geometry = EMPTY; + try { + geometry = graph.getPossibleRelatedValue2(edgeResource, DN.Edge_HasGeometry, Bindings.DOUBLE_ARRAY); + } catch (Exception e) { + // most likely no geometry available + } + DistrictNetworkEdge edge = new DistrictNetworkEdge(new Point2D.Double(startCoords[0], startCoords[1]), new Point2D.Double(endCoords[0], endCoords[1]), geometry); Resource mapping = graph.getSingleObject(edgeResource, DistrictNetworkResource.getInstance(graph).HasMapping); element.setHint(DistrictNetworkAdditionalColor.KEY_DN_MAPPING_RESOURCE, mapping); element.setHint(DistrictNetworkEdgeElement.KEY_DN_EDGE, edge); + // set scaling transform + ElementUtils.setTransform(element, MapScalingTransform.INSTANCE); + IModifiableSynchronizationContext context = diagram.getHint(SynchronizationHints.CONTEXT); GraphLayerManager layerManager = context.get(GraphSynchronizationHints.GRAPH_LAYER_MANAGER);