From e9e4d5aa42316eda7f4f21577801f94fce90c0a7 Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Sat, 23 Nov 2019 01:48:48 +0200 Subject: [PATCH] Fixed edge arrows to always be rendered above the edge Optimized MidBranchEdgeSetRequest memory use by using CollectionSupport to create a ResourceSet instead of using HashSet. gitlab #47 Change-Id: Ic763cb1ea8976ca3ff5c933e8de5f18aa29f6579 --- .../ui/nodes/DistrictNetworkEdgeNode.java | 17 +++++++++++++---- .../ui/nodes/DistrictNetworkStaticInfoNode.java | 2 +- .../profile/MidBranchEdgeSetRequest.java | 5 +++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java index 1c677316..e724a68d 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java @@ -135,10 +135,19 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection double centerX = centerPoint.getX(), centerY = centerPoint.getY(); double deltaX = direction.getX(), deltaY = direction.getY(); - double x0 = centerX - l/2 * deltaX + offset * deltaY; - double y0 = centerY - l/2 * deltaY - offset * deltaX; - double x1 = centerX + (l/2 - w) * deltaX + offset * deltaY; - double y1 = centerY + (l/2 - w) * deltaY - offset * deltaX; + // Ensure the line is always rendered on top of the edge + // to prevent overlap with static info rendered below it. + double odx = offset * deltaY; + double ody = offset * deltaX; + if (odx < 0) { + odx = -odx; + ody = -ody; + } + + double x0 = centerX - l/2 * deltaX + ody; + double y0 = centerY - l/2 * deltaY - odx; + double x1 = centerX + (l/2 - w) * deltaX + ody; + double y1 = centerY + (l/2 - w) * deltaY - odx; g2d.draw(new Line2D.Double(x0, y0, x1, y1)); diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkStaticInfoNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkStaticInfoNode.java index 4ce35a27..c8eae515 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkStaticInfoNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkStaticInfoNode.java @@ -86,7 +86,7 @@ public class DistrictNetworkStaticInfoNode extends G2DNode implements DeferredNo int ascent = fm.getMaxAscent(); g.transform(AffineTransform.getRotateInstance(direction.getX(), direction.getY())); - g.translate(0, ascent); + g.translate(0, ascent+2); // int height = fm.getHeight(); // g.setColor(Color.WHITE); diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/MidBranchEdgeSetRequest.java b/org.simantics.district.network/src/org/simantics/district/network/profile/MidBranchEdgeSetRequest.java index c1a9394f..ac66b88f 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/profile/MidBranchEdgeSetRequest.java +++ b/org.simantics.district.network/src/org/simantics/district/network/profile/MidBranchEdgeSetRequest.java @@ -1,6 +1,5 @@ package org.simantics.district.network.profile; -import java.util.HashSet; import java.util.List; import java.util.Set; @@ -9,6 +8,7 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.request.ResourceRead; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.CollectionSupport; public class MidBranchEdgeSetRequest extends ResourceRead> { public MidBranchEdgeSetRequest(Resource resource) { @@ -18,6 +18,7 @@ public class MidBranchEdgeSetRequest extends ResourceRead> { @Override public Set perform(ReadGraph graph) throws DatabaseException { List edges = Simantics.applySCL("Simantics/District/Algorithm", "midBranchEdges", graph, resource); - return new HashSet<>(edges); + CollectionSupport cs = graph.getService(CollectionSupport.class); + return cs.getResourceSet(graph, edges); } } -- 2.47.1