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=f502933963c63185379cb5a6097e05c9263f2d1a;hp=36d573081b8489bec41274311008eed35f33c624;hpb=00e4eca98cef6d77d5023f4b424f9e8da0487463;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 36d57308..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,17 +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);