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=386525ce8e466427df0624a304ebb64df249d1bb;hp=1003a9b22b0a8cd55646c79f9dd4ad38520ed8bb;hpb=ac6ad8ff2b20a10e85e7b12c1af670500daebdd4;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 1003a9b2..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 @@ -2,6 +2,7 @@ package org.simantics.district.network.ui.adapters; 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; @@ -28,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; @@ -46,19 +48,30 @@ 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 { if (!graph.hasStatement(edgeResource)) return; // already deleted + if (!graph.hasStatement(edgeResource, DN.HasStartVertex)) + return; // already deleted Resource startVertex = graph.getSingleObject(edgeResource, DN.HasStartVertex); + + if (!graph.hasStatement(edgeResource, DN.HasEndVertex)) + return; // already deleted Resource endVertex = graph.getSingleObject(edgeResource, DN.HasEndVertex); - // TODO: Find maybe a better way to apply the scaling - double[] startCoords = graph.getRelatedValue2(startVertex, DIA.HasLocation); - double[] endCoords = graph.getRelatedValue2(endVertex, DIA.HasLocation); - DistrictNetworkEdge edge = new DistrictNetworkEdge(new Point2D.Double(startCoords[0], startCoords[1]), new Point2D.Double(endCoords[0], endCoords[1])); + double[] startCoords = graph.getRelatedValue2(startVertex, DIA.HasLocation, Bindings.DOUBLE_ARRAY); + double[] endCoords = graph.getRelatedValue2(endVertex, DIA.HasLocation, Bindings.DOUBLE_ARRAY); + + 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);