From a42f11d276ab590703c54fe5e117c46608ad66cd Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Mon, 18 Feb 2019 13:05:11 +0200 Subject: [PATCH] Prevent selection of edge for route start and end points gitlab #29 Change-Id: I43cfc51bd587e3784d5ec253add4ce742c253103 --- .../network/ui/participants/RoutingMode.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/RoutingMode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/RoutingMode.java index daacb312..54224f4f 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/RoutingMode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/RoutingMode.java @@ -14,6 +14,7 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; import org.simantics.db.Resource; import org.simantics.diagram.ui.DiagramModelHints; +import org.simantics.district.network.ui.adapters.DistrictNetworkVertexElement; import org.simantics.district.network.ui.internal.Activator; import org.simantics.district.route.Route; import org.simantics.district.route.RouteEvent; @@ -30,6 +31,7 @@ import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit; import org.simantics.g2d.diagram.handler.PickContext; import org.simantics.g2d.diagram.participant.Selection; import org.simantics.g2d.diagram.participant.pointertool.AbstractMode; +import org.simantics.g2d.element.ElementClass; import org.simantics.g2d.element.ElementUtils; import org.simantics.g2d.element.IElement; import org.simantics.g2d.participant.TransformUtil; @@ -145,12 +147,22 @@ public class RoutingMode extends AbstractMode { return; Object o = ElementUtils.getObject(element); - if (o instanceof Resource) { + if (o instanceof Resource && filterAcceptableElement(element, o)) { Waypoint wp = route.createWaypoint(o); route.addWaypoint(wp); } } + /** + * For now, routing can only start from vertices + * + * @return true if element is a vertex + */ + private boolean filterAcceptableElement(IElement element, Object o) { + ElementClass elementClass = element.getElementClass(); + return elementClass.getId().equals(DistrictNetworkVertexElement.CLASS.getId()); + } + @SGInit public void initSG(G2DParentNode parent) { this.parent = parent; -- 2.47.1