]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Added a route validation command to model browser
authorReino Ruusu <reino.ruusu@semantum.fi>
Wed, 7 Aug 2019 10:30:05 +0000 (13:30 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Sat, 31 Aug 2019 20:10:12 +0000 (23:10 +0300)
gitlab #58

Change-Id: I4af93100f4003b66f5229394674cb61312e65e64

org.simantics.district.route.ontology/graph/DistrictNetworkRoutesViewpoint.pgraph
org.simantics.district.route.ontology/src/org/simantics/district/route/ontology/RouteResource.java
org.simantics.district.route.ui/adapters.xml
org.simantics.district.route.ui/src/org/simantics/district/route/ui/actions/ValidateRouteAction.java [new file with mode: 0644]

index f01d26b6fdca2024946283b1d3a730a83ef3a29f..1b5c1ecd8b38538412d7a981af0433875c5ebb69 100644 (file)
@@ -7,7 +7,9 @@ SILK = <http://www.simantics.org/Silk-1.1>
 
 RAC = DNR.RouteActionContext : VP.BrowseContext
     @VP.actionContribution "Select Route" DNR.Route SILK.wand VP.EditActionCategory DNR.Actions.SelectRoute
+    @VP.actionContribution "Validate Route" DNR.Route SILK.accept VP.EditActionCategory DNR.Actions.ValidateRoute
 
 DNR.Actions : L0.Library
 
 DNR.Actions.SelectRoute : ACT.Action
+DNR.Actions.ValidateRoute : ACT.Action
\ No newline at end of file
index c77dbf0f86034748bfac3d17a3d1f3a999131ac7..b9641270aaa8a86761f85df745ee6a5d172a6f07 100644 (file)
@@ -12,6 +12,7 @@ public class RouteResource {
     
     public final Resource Actions;
     public final Resource Actions_SelectRoute;
+    public final Resource Actions_ValidateRoute;
     public final Resource Route;
     public final Resource RouteActionContext;
     public final Resource RouteFolder;
@@ -19,6 +20,7 @@ public class RouteResource {
     public static class URIs {
         public static final String Actions = "http://www.simantics.org/DistrictNetworkRoutes-1.0/Actions";
         public static final String Actions_SelectRoute = "http://www.simantics.org/DistrictNetworkRoutes-1.0/Actions/SelectRoute";
+        public static final String Actions_ValidateRoute = "http://www.simantics.org/DistrictNetworkRoutes-1.0/Actions/ValidateRoute";
         public static final String Route = "http://www.simantics.org/DistrictNetworkRoutes-1.0/Route";
         public static final String RouteActionContext = "http://www.simantics.org/DistrictNetworkRoutes-1.0/RouteActionContext";
         public static final String RouteFolder = "http://www.simantics.org/DistrictNetworkRoutes-1.0/RouteFolder";
@@ -36,6 +38,7 @@ public class RouteResource {
     public RouteResource(ReadGraph graph) {
         Actions = getResourceOrNull(graph, URIs.Actions);
         Actions_SelectRoute = getResourceOrNull(graph, URIs.Actions_SelectRoute);
+        Actions_ValidateRoute = getResourceOrNull(graph, URIs.Actions_ValidateRoute);
         Route = getResourceOrNull(graph, URIs.Route);
         RouteActionContext = getResourceOrNull(graph, URIs.RouteActionContext);
         RouteFolder = getResourceOrNull(graph, URIs.RouteFolder);
index 66c37e3b166c3fadee3d47f16f42239dfe5f8db6..94d23ae77005dd4d48894a05a26e02e41cc6c19c 100644 (file)
@@ -4,4 +4,8 @@
                <resource uri="http://www.simantics.org/DistrictNetworkRoutes-1.0/Actions/SelectRoute"
                        class="org.simantics.district.route.ui.actions.SelectRouteAction" />
        </target>
+       <target interface="org.simantics.db.layer0.adapter.ActionFactory">
+               <resource uri="http://www.simantics.org/DistrictNetworkRoutes-1.0/Actions/ValidateRoute"
+                       class="org.simantics.district.route.ui.actions.ValidateRouteAction" />
+       </target>
 </adapters>
diff --git a/org.simantics.district.route.ui/src/org/simantics/district/route/ui/actions/ValidateRouteAction.java b/org.simantics.district.route.ui/src/org/simantics/district/route/ui/actions/ValidateRouteAction.java
new file mode 100644 (file)
index 0000000..5b0e7d0
--- /dev/null
@@ -0,0 +1,58 @@
+package org.simantics.district.route.ui.actions;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+
+import org.simantics.Simantics;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.ActionFactory;
+import org.simantics.district.route.Route;
+import org.simantics.district.route.RouteJob;
+import org.simantics.district.route.RouterConfiguration;
+import org.simantics.district.route.internal.RoutePersistence;
+import org.simantics.utils.ui.dialogs.ShowMessage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ValidateRouteAction implements ActionFactory {
+
+    protected static final Logger LOGGER = LoggerFactory.getLogger(ValidateRouteAction.class);
+
+    @Override
+    public Runnable create(Object target) {
+        if (!(target instanceof Resource))
+            return null;
+
+        return new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    Route route = Simantics.getSession().syncRequest(new RoutePersistence.RouteRequest((Resource)target));
+                    if (route == null) {
+                        ShowMessage.showInformation("Route Validation", "Reading the route object failed");
+                        LOGGER.error("Reading a route object failed"); //$NON-NLS-1$
+                        return;
+                    }
+                    
+                    CompletableFuture<List<Resource>> result = new CompletableFuture<>();
+                    result.exceptionally(e -> null).thenAccept(dnElements -> {
+                        if (dnElements != null) {
+                            if (!dnElements.isEmpty())
+                                ShowMessage.showInformation("Route Validation", "The route is valid");
+                            else
+                                ShowMessage.showInformation("Route Validation", "The route produced an empty list of vertices");
+                        }
+                    });
+                    
+                    RouterConfiguration config = new RouterConfiguration();
+                    new RouteJob(config, route, result).schedule();
+                }
+                catch (DatabaseException e) {
+                    LOGGER.error("Error in selecting route " + target, e); //$NON-NLS-1$
+                }
+            }
+        };
+    }
+}