]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNEdgeBuilder.java
Some more added functionality to simantics district editor etc
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / DNEdgeBuilder.java
index 687ca337b85689f6dd749fcba1fbfde04a9bec7b..ebdb9e87adde5dd422eeedcac5dea37c5fea5d97 100644 (file)
@@ -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<Resource> 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<Resource> vertices, double[] coords) throws DatabaseException {
+    private Resource getOrCreateVertex(WriteGraph graph, Collection<Resource> 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;