X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2FDNEdgeBuilder.java;h=ebdb9e87adde5dd422eeedcac5dea37c5fea5d97;hb=16ee01dc5a40981c58fd5b478b89552e5814e8bb;hp=687ca337b85689f6dd749fcba1fbfde04a9bec7b;hpb=9dace20146d19dd0541480a80fd289de45b6cfc8;p=simantics%2Fdistrict.git 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 687ca337..ebdb9e87 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 @@ -34,7 +34,7 @@ public class DNEdgeBuilder { glm = context.get(GraphSynchronizationHints.GRAPH_LAYER_MANAGER); } - public void create(WriteGraph graph, double[] start, double[] end) throws DatabaseException { + public void create(WriteGraph graph, double[] start, double[] end, double padding) throws DatabaseException { DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); @@ -46,8 +46,8 @@ public class DNEdgeBuilder { // 2. Add vertices Collection vertices = graph.syncRequest(new ObjectsWithType(diagramResource, Layer0.getInstance(graph).ConsistsOf, DistrictNetworkResource.getInstance(graph).Vertex)); - Resource startVertex = getOrCreateVertex(graph, vertices, start); - Resource endVertex = getOrCreateVertex(graph, vertices, end); + Resource startVertex = getOrCreateVertex(graph, vertices, start, padding); + Resource endVertex = getOrCreateVertex(graph, vertices, end, padding); graph.claim(edge, DN.HasStartVertex, startVertex); graph.claim(edge, DN.HasEndVertex, endVertex); @@ -68,12 +68,13 @@ public class DNEdgeBuilder { glm.putElementOnVisibleLayers(diagram, graph, res); } - private Resource getOrCreateVertex(WriteGraph graph, Collection vertices, double[] coords) throws DatabaseException { + private Resource getOrCreateVertex(WriteGraph graph, Collection vertices, double[] coords, double padding) throws DatabaseException { Resource vertex = null; + double halfPadding = padding / 2; for (Resource vertx : vertices) { double[] existingCoords = graph.getRelatedValue2(vertx, DiagramResource.getInstance(graph).HasLocation, Bindings.DOUBLE_ARRAY); - Rectangle2D existing = new Rectangle2D.Double(existingCoords[0], existingCoords[1], 1, 1); - Rectangle2D tobecreated = new Rectangle2D.Double(coords[0], coords[1], 1, 1); + Rectangle2D existing = new Rectangle2D.Double(existingCoords[0] - halfPadding, existingCoords[1] - halfPadding, padding, padding); + Rectangle2D tobecreated = new Rectangle2D.Double(coords[0] - halfPadding, coords[1] - halfPadding, padding, padding); if (existing.intersects(tobecreated)) { vertex = vertx; break;