]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network.ui/src/org/simantics/district/network/ui/function/Functions.java
Added Edge.ThicknessProperty for generic edge-thickness styling
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / function / Functions.java
index 4fc40dbb109253fb5a2a2bf01a9eea0624dc6013..9748f87c8fc4980f77a767e84dde9d157b6885d4 100644 (file)
@@ -1,9 +1,12 @@
 package org.simantics.district.network.ui.function;
 
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 import org.eclipse.jface.dialogs.Dialog;
@@ -48,8 +51,8 @@ import org.simantics.modeling.ModelingResources;
 import org.simantics.modeling.ModelingUtils;
 import org.simantics.modeling.adapters.NewCompositeActionFactory;
 import org.simantics.modeling.typicals.TypicalUtil;
+import org.simantics.operation.Layer0X;
 import org.simantics.scl.reflection.annotations.SCLValue;
-import org.simantics.structural.stubs.StructuralResource2;
 import org.simantics.ui.workbench.action.DefaultActions;
 import org.simantics.utils.ui.SWTUtils;
 import org.slf4j.Logger;
@@ -119,7 +122,10 @@ public class Functions {
         mappings.forEach(mapping -> {
             try {
                 String name = graph.getRelatedValue2(mapping, L0.HasName);
-                result.put(name, mapping);
+                Resource existing = result.put(name, mapping);
+                if (existing != null) {
+                    LOGGER.warn("Duplicate mapping name! {} {} and existing is {}", name, mapping, existing);
+                }
             } catch (DatabaseException e) {
                 e.printStackTrace();
             }
@@ -432,6 +438,10 @@ public class Functions {
                                 graph.claim(diagram, DN.EdgeDefaultMapping, dialog.getDefaultEdgeMapping());
                                 graph.claim(diagram, DN.VertexDefaultMapping, dialog.getDefaultVertexMapping());
                                 graph.claim(diagram, DN.HasSpatialRefSystem, dialog.getCRS());
+                                
+                                // Generated name prefix from composite name
+                                String compositeName = graph.getRelatedValue2(composite, Layer0.getInstance(graph).HasName, Bindings.STRING);
+                                graph.claimLiteral(diagram, Layer0X.getInstance(graph).HasGeneratedNamePrefix, "N" + compositeName.substring(compositeName.length() - 1, compositeName.length()));
                             }
                         });
                         DefaultActions.asyncPerformDefaultAction(Simantics.getSession(), composite, false, false, true);
@@ -446,7 +456,28 @@ public class Functions {
                 });
     }
 
-    public static void getDistrictDiagrams(ReadGraph graph) {
-        
+    public static Collection<Resource> getDistrictDiagrams(ReadGraph graph) throws DatabaseException {
+        Layer0 L0 = Layer0.getInstance(graph);
+        Collection<Resource> indexRoots = graph.sync(new ObjectsWithType(Simantics.getProjectResource(), L0.ConsistsOf, L0.IndexRoot));
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        Set<Resource> results = new HashSet<>();
+        for (Resource indexRoot : indexRoots) {
+            Collection<Resource> diagrams = ModelingUtils.searchByType(graph, indexRoot, DN.Diagram);
+            results.addAll(diagrams);
+        }
+        return results;
     }
+
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")
+    public static Object edgeThicknessPropertyEnumerationValues(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {
+        return Collections.emptyList();
+    }
+
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")
+    public static Object edgeThicknessPropertyModifier(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {
+        Resource diagram = resolveElement(graph, context);
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        return baseMappingModifier(graph, diagram, DN.Diagram_edgeThicknessProperty, DN.Edge_ThicknessProperty, context);
+    }
+
 }