From: Tuukka Lehtonen Date: Tue, 14 Nov 2017 09:06:55 +0000 (+0200) Subject: Improved Simantics/SCL module SCL module/script functionality X-Git-Tag: v1.31.0~40 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=3edbf85ff8a7f1bd596857a24b1bdebd66943d6b Improved Simantics/SCL module SCL module/script functionality * Added new functions create{SCLModule,SCLScript,PGraph}R that return the created resource instead of returning (). * Added new functions createSCL{Module,Script}WithDefinition for directly creating modules/scripts with a specific definition * Added new functions set{SCLModule,SCLScript,PGraph}Definition for setting the definition specific to each entity. * Added preliminary documentation for the module * Deprecated create{SCLModule,SCLScript,PGraph} functions in favor of create...R refs #7616 Change-Id: Ia2d97682eb184f5b0edd849f564ca05561938cb4 --- diff --git a/bundles/org.simantics.modeling/scl/Simantics/SCL.md b/bundles/org.simantics.modeling/scl/Simantics/SCL.md new file mode 100644 index 000000000..d985176f7 --- /dev/null +++ b/bundles/org.simantics.modeling/scl/Simantics/SCL.md @@ -0,0 +1,59 @@ +# Simantics/SCL + +This module contains functions closely related to SCL and storing +SCL related constructs in the Simantics database. + +## SCL Command Session + +::data[CommandResponse] +::value[createTextAndErrors] +::value[execute] +::value[isSuccessful] + +### SCL Realm + +::value[getOrCreateSCLRealm] +::value[readSCLRealm] +::value[refreshVariables] +::value[sclRealmById] +::value[syncExec] + +### Command Session Variable Access + +::value[setVariable] +::value[variableValue] + +## SCL Values + +::value[createSCLValue] +::value[createSCLValueIndependent] +::value[setExpression] + +## SCL Modules + +::value[createSCLModuleAction] +::value[createSCLModuleDefault] +::value[createSCLModule] +::value[createSCLModuleR] +::value[createSCLModuleWithDefinition] +::value[setSCLModuleDefinition] + +## SCL Scripts + +::value[createSCLScriptAction] +::value[createSCLScriptDefault] +::value[createSCLScript] +::value[createSCLScriptR] +::value[createSCLScriptWithDefinition] +::value[setSCLScriptDefinition] + +## Ontology definitions (PGraphs) + +PGraph (partial graph) is a textual format for specifying ontologies for Simantics. +For more information on the format, see [this documentation](http://dev.simantics.org/index.php/Graph_File_Format). + +::value[createPGraphAction] +::value[createPGraphDefault] +::value[createPGraph] +::value[createPGraphR] +::value[setPGraphDefinition] diff --git a/bundles/org.simantics.modeling/scl/Simantics/SCL.scl b/bundles/org.simantics.modeling/scl/Simantics/SCL.scl index 05fbc0ee2..d636ca8ef 100644 --- a/bundles/org.simantics.modeling/scl/Simantics/SCL.scl +++ b/bundles/org.simantics.modeling/scl/Simantics/SCL.scl @@ -42,9 +42,58 @@ importJava "org.simantics.modeling.ModelingUtils" where createSCLModuleDefault :: Resource -> () createSCLScriptDefault :: Resource -> () createPGraphDefault :: Resource -> () + "Use [createSCLModuleR](#createSCLModuleR) instead." + @deprecated createSCLModule :: Resource -> String -> () + "Use [createSCLScriptR](#createSCLScriptR) instead." + @deprecated createSCLScript :: Resource -> String -> () + "Use [createPGraphR](#createPGraphR) instead." + @deprecated createPGraph :: Resource -> String -> () + """ + `createSCLModuleR container name` creates a new empty SCL module under + the specified `container` with the specified `name` and returns the created + module's Resource. + """ + @JavaName createSCLModule + createSCLModuleR :: Resource -> String -> Resource + """ + `createSCLScriptR container name` creates a new empty SCL script under + the specified `container` with the specified `name` and returns the created + script's Resource. + """ + @JavaName createSCLScript + createSCLScriptR :: Resource -> String -> Resource + """ + `createPGraphR container name` creates a new empty partial graph + ontology definition (PGraph) under the specified `container` with + the specified `name` and returns the created ontology definition's + Resource. + """ + @JavaName createPGraph + createPGraphR :: Resource -> String -> Resource + "`setSCLModuleDefinition module definition` sets the textual `definition` of the specified SCL `module`." + setSCLModuleDefinition :: Resource -> String -> Resource + "`setSCLScriptDefinition module definition` sets the textual `definition` of the specified SCL `module`." + setSCLScriptDefinition :: Resource -> String -> Resource + setPGraphDefinition :: Resource -> String -> Resource + +""" +`createSCLModuleWithDefinition container name definition` creates a new SCL module under +the specified `container` with the specified `name` and `definition` and returns +the created module's Resource. +""" +createSCLModuleWithDefinition :: Resource -> String -> String -> Resource +createSCLModuleWithDefinition container name definition = setSCLModuleDefinition (createSCLModuleR container name) definition + +""" +`createSCLScriptWithDefinition container name definition` creates a new SCL script under +the specified `container` with the specified `name` and `definition` and returns +the created script's Resource. +""" +createSCLScriptWithDefinition :: Resource -> String -> String -> Resource +createSCLScriptWithDefinition container name definition = setSCLScriptDefinition (createSCLScriptR container name) definition effect SCL "scl" diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java index e0551eb3e..a43220f06 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java @@ -1760,28 +1760,36 @@ public class ModelingUtils { } - - public static void createSCLModuleDefault(WriteGraph graph, Resource target) throws DatabaseException { - String name = NameUtils.findFreshEscapedName(graph, "SCLModule", target); - createSCLModule(graph, target, name); + public static Resource createSCLModuleDefault(WriteGraph graph, Resource target) throws DatabaseException { + String name = NameUtils.findFreshEscapedName(graph, "SCLModule", target); + return createSCLModule(graph, target, name); } - public static void createSCLModule(WriteGraph graph, Resource target, String name) throws DatabaseException { + public static Resource createSCLModule(WriteGraph graph, Resource target, String name) throws DatabaseException { graph.markUndoPoint(); - Layer0 L0 = Layer0.getInstance(graph); + Layer0 L0 = Layer0.getInstance(graph); Resource sclModule = GraphUtils.create2(graph, L0.SCLModule, L0.HasName, name, L0.PartOf, target, L0.SCLModule_definition, ""); - Layer0Utils.addCommentMetadata(graph, "Created SCL Module " + name + " " + sclModule.toString()); + Layer0Utils.addCommentMetadata(graph, "Created SCL Module " + name + " " + sclModule.toString()); + return sclModule; + } + + public static Resource setSCLModuleDefinition(WriteGraph graph, Resource module, String definition) throws DatabaseException { + graph.markUndoPoint(); + Layer0 L0 = Layer0.getInstance(graph); + graph.claimLiteral(module, L0.SCLModule_definition, definition, Bindings.STRING); + Layer0Utils.addCommentMetadata(graph, "Set SCL module " + module + " definition."); + return module; } - public static void createSCLScriptDefault(WriteGraph graph, Resource target) throws DatabaseException { + public static Resource createSCLScriptDefault(WriteGraph graph, Resource target) throws DatabaseException { String name = NameUtils.findFreshEscapedName(graph, "SCLScript", target); - createSCLScript(graph, target, name); + return createSCLScript(graph, target, name); } - public static void createSCLScript(WriteGraph graph, Resource target, String name) throws DatabaseException { + public static Resource createSCLScript(WriteGraph graph, Resource target, String name) throws DatabaseException { graph.markUndoPoint(); Layer0 L0 = Layer0.getInstance(graph); Resource sclModule = GraphUtils.create2(graph, L0.SCLScript, @@ -1789,23 +1797,41 @@ public class ModelingUtils { L0.PartOf, target, L0.SCLScript_definition, ""); Layer0Utils.addCommentMetadata(graph, "Created SCL Script " + name + " " + sclModule.toString()); + return sclModule; } - public static void createPGraphDefault(WriteGraph graph, Resource target) throws DatabaseException { - String name = NameUtils.findFreshEscapedName(graph, "Ontology Definition File", target); - createPGraph(graph, target, name); + public static Resource setSCLScriptDefinition(WriteGraph graph, Resource script, String definition) throws DatabaseException { + graph.markUndoPoint(); + Layer0 L0 = Layer0.getInstance(graph); + graph.claimLiteral(script, L0.SCLScript_definition, definition, Bindings.STRING); + Layer0Utils.addCommentMetadata(graph, "Set SCL script " + script + " definition."); + return script; } - public static void createPGraph(WriteGraph graph, Resource target, String name) throws DatabaseException { + public static Resource createPGraphDefault(WriteGraph graph, Resource target) throws DatabaseException { + String name = NameUtils.findFreshEscapedName(graph, "Ontology Definition File", target); + return createPGraph(graph, target, name); + } + + public static Resource createPGraph(WriteGraph graph, Resource target, String name) throws DatabaseException { graph.markUndoPoint(); - Layer0 L0 = Layer0.getInstance(graph); + Layer0 L0 = Layer0.getInstance(graph); Resource file = GraphUtils.create2(graph, L0.PGraph, L0.HasName, name, L0.PartOf, target, L0.PGraph_definition, ""); - Layer0Utils.addCommentMetadata(graph, "Created Ontology Definition File " + name + " " + file.toString()); + Layer0Utils.addCommentMetadata(graph, "Created Ontology Definition File " + name + " " + file.toString()); + return file; } - + + public static Resource setPGraphDefinition(WriteGraph graph, Resource pgraph, String definition) throws DatabaseException { + graph.markUndoPoint(); + Layer0 L0 = Layer0.getInstance(graph); + graph.claimLiteral(pgraph, L0.PGraph_definition, definition, Bindings.STRING); + Layer0Utils.addCommentMetadata(graph, "Set PGraph " + pgraph + " definition."); + return pgraph; + } + public static void publish(WriteGraph graph, Resource target) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); graph.claimLiteral(target, L0.Entity_published, true, Bindings.BOOLEAN);