From 2161d658d9d7f6a5bd68bd2d629dbfaa14fc3be0 Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Fri, 26 Jun 2020 23:51:11 +0300 Subject: [PATCH] Include component type SCL scripts in textual ontology dump Also procedural component type substructure code is now dumped into the same __contents__ file. refs #561 (cherry picked from commit 1987d5091a213380354e22b863c6a48119faa5ad) --- .../graph/Modeling.pgraph | 5 ++ .../scl/Simantics/Testing.scl | 1 + .../org/simantics/modeling/ContentDumps.java | 50 +++++++++++++++++-- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/bundles/org.simantics.modeling.ontology/graph/Modeling.pgraph b/bundles/org.simantics.modeling.ontology/graph/Modeling.pgraph index 865f03e98..b13462813 100644 --- a/bundles/org.simantics.modeling.ontology/graph/Modeling.pgraph +++ b/bundles/org.simantics.modeling.ontology/graph/Modeling.pgraph @@ -568,6 +568,11 @@ STR.Component MOD.StructuralComponentContentDumpFunction @L0.sclValue "structuralComponentContentDump" "Resource -> Vector Byte" +STR.ComponentType + MOD.contentDumpFunction + MOD.StructuralComponentTypeContentDumpFunction + @L0.sclValue "structuralComponentTypeContentDump" "Resource -> Vector Byte" + SEL.GenericParameterType MOD.contentDumpFunction MOD.GenericParameterTypeContentDumpFunction diff --git a/bundles/org.simantics.modeling/scl/Simantics/Testing.scl b/bundles/org.simantics.modeling/scl/Simantics/Testing.scl index f1ebaf50c..08f9f2868 100644 --- a/bundles/org.simantics.modeling/scl/Simantics/Testing.scl +++ b/bundles/org.simantics.modeling/scl/Simantics/Testing.scl @@ -11,5 +11,6 @@ importJava "org.simantics.modeling.ContentDumps" where pgraphContentDump :: Resource -> Vector Byte graphFileContentDump :: Resource -> Vector Byte structuralComponentContentDump :: Resource -> Vector Byte + structuralComponentTypeContentDump :: Resource -> Vector Byte genericParameterTypeContentDump :: Resource -> Vector Byte diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/ContentDumps.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/ContentDumps.java index 687544e78..39ed968dd 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/ContentDumps.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/ContentDumps.java @@ -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 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 scripts = graph.getObjects(resource, STR.ComponentType_hasScript); + if (!scripts.isEmpty()) { + dump.append("\nComponentType.hasScript (").append(scripts.size()).append(")\n"); + TreeMap sortedScripts = new TreeMap<>(); + for (Resource script : scripts) + sortedScripts.put(NameUtils.getSafeName(graph, script), script); + for (Map.Entry 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); } -- 2.47.1