From: jsimomaa Date: Mon, 18 Feb 2019 11:05:11 +0000 (+0200) Subject: Prevent selection of edge for route start and end points X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F54%2F2654%2F1;p=simantics%2Fdistrict.git Prevent selection of edge for route start and end points gitlab #29 Change-Id: I43cfc51bd587e3784d5ec253add4ce742c253103 --- 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;