]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Include component type SCL scripts in textual ontology dump
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 26 Jun 2020 20:51:11 +0000 (23:51 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 26 Jun 2020 20:51:11 +0000 (23:51 +0300)
Also procedural component type substructure code is now dumped into the
same __contents__ file.

refs #561

bundles/org.simantics.modeling.ontology/graph/Modeling.pgraph
bundles/org.simantics.modeling/scl/Simantics/Testing.scl
bundles/org.simantics.modeling/src/org/simantics/modeling/ContentDumps.java

index 865f03e989527c9571d51d8c3be511586c1fd49e..b13462813e1fbf9f8a477c64313fea55a0db036c 100644 (file)
@@ -568,6 +568,11 @@ STR.Component
     MOD.StructuralComponentContentDumpFunction
       @L0.sclValue "structuralComponentContentDump" "Resource -> <ReadGraph> Vector Byte"
 
+STR.ComponentType
+  MOD.contentDumpFunction
+    MOD.StructuralComponentTypeContentDumpFunction
+      @L0.sclValue "structuralComponentTypeContentDump" "Resource -> <ReadGraph> Vector Byte"
+
 SEL.GenericParameterType
   MOD.contentDumpFunction
     MOD.GenericParameterTypeContentDumpFunction
index f1ebaf50c3d5117e99f2737ec85cfa0fcb95cbb2..08f9f2868b4deec344ddcefb3a7744233ca3a774 100644 (file)
@@ -11,5 +11,6 @@ importJava "org.simantics.modeling.ContentDumps" where
   pgraphContentDump :: Resource -> <ReadGraph> Vector Byte
   graphFileContentDump :: Resource -> <ReadGraph> Vector Byte
   structuralComponentContentDump :: Resource -> <ReadGraph> Vector Byte
+  structuralComponentTypeContentDump :: Resource -> <ReadGraph> Vector Byte
   genericParameterTypeContentDump :: Resource -> <ReadGraph> Vector Byte
 
index 687544e78a52d99306436408d0211f23fa157157..39ed968dd5385034f76ccdbb520d050e9995c63c 100644 (file)
@@ -2,6 +2,8 @@ package org.simantics.modeling;
 
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.Map;
 import java.util.TreeMap;
 import java.util.TreeSet;
 
@@ -9,6 +11,7 @@ import org.simantics.databoard.Bindings;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.common.utils.CommonDBUtils;
+import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
@@ -47,12 +50,10 @@ public class ContentDumps {
         return graph.getRelatedValue(resource, GF.HasFiledata, Bindings.BYTE_ARRAY); 
     }
 
-    public static byte[] structuralComponentContentDump(ReadGraph graph, Resource resource) throws DatabaseException {
-
-        StringBuilder dump = new StringBuilder();
+    private static StringBuilder structuralComponentContentDump(ReadGraph graph, Resource resource, StringBuilder dump) throws DatabaseException {
 
         Variable v = Variables.getVariable(graph, resource);
-        
+
         TreeSet<String> types = new TreeSet<>();
         for(Resource t : graph.getPrincipalTypes(resource)) {
             types.add(graph.getURI(t));
@@ -87,6 +88,47 @@ public class ContentDumps {
                 dump.append("\n");
             }
         }
+
+        return dump;
+    }
+
+    public static byte[] structuralComponentContentDump(ReadGraph graph, Resource resource) throws DatabaseException {
+        return structuralComponentContentDump(graph, resource, new StringBuilder()).toString().getBytes(UTF8);
+    }
+
+    public static byte[] structuralComponentTypeContentDump(ReadGraph graph, Resource resource) throws DatabaseException {
+        StringBuilder dump = structuralComponentContentDump(graph, resource, new StringBuilder());
+
+        StructuralResource2 STR = StructuralResource2.getInstance(graph);
+
+        // Dump procedural component type code if present
+        String proceduralCode = graph.getPossibleRelatedValue(resource, STR.ProceduralComponentType_code, Bindings.STRING);
+        if (proceduralCode != null) {
+            dump
+            .append("\n---- ProceduralComponentType.code begins ----\n")
+            .append(proceduralCode)
+            .append("---- ProceduralComponentType.code ends ----\n");
+        }
+
+        // Dump component type SCL scripts
+        Collection<Resource> scripts = graph.getObjects(resource, STR.ComponentType_hasScript);
+        if (!scripts.isEmpty()) {
+            dump.append("\nComponentType.hasScript (").append(scripts.size()).append(")\n");
+            TreeMap<String,Resource> sortedScripts = new TreeMap<>();
+            for (Resource script : scripts)
+                sortedScripts.put(NameUtils.getSafeName(graph, script), script);
+            for (Map.Entry<String, Resource> entry : sortedScripts.entrySet()) {
+                String name = entry.getKey();
+                Resource script = entry.getValue();
+                String type = graph.getPossibleRelatedValue(script, STR.ComponentTypeScript_type, Bindings.STRING);
+                String code = graph.getPossibleRelatedValue(script, STR.ComponentTypeScript_code, Bindings.STRING);
+                dump
+                .append("---- script `").append(name).append("` of type `").append(type).append("` begins ----\n")
+                .append(code)
+                .append("\n---- script `").append(name).append("` of type `").append(type).append("` ends ----\n");
+            }
+        }
+
         return dump.toString().getBytes(UTF8);
     }