]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Prevent selection of edge for route start and end points 54/2654/1
authorjsimomaa <jani.simomaa@gmail.com>
Mon, 18 Feb 2019 11:05:11 +0000 (13:05 +0200)
committerjsimomaa <jani.simomaa@gmail.com>
Mon, 18 Feb 2019 11:05:11 +0000 (13:05 +0200)
gitlab #29

Change-Id: I43cfc51bd587e3784d5ec253add4ce742c253103

org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/RoutingMode.java

index daacb31296ac0fa7c64d82b1366cc13a7cf1fb2d..54224f4f85e7ea0813516e73350d6a2aee90e2cc 100644 (file)
@@ -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;