Simantics/SCL

This module contains functions closely related to SCL and storing SCL related constructs in the Simantics database.

SCL Command Session

data CommandResponse

The outcome of one command executed in an SCL command session. message is the text the command produced and error tells whether the command failed. Showing a response gives its message.

CommandResponse :: String -> Boolean -> CommandResponse
createTextAndErrors :: String -> [CompilationError] -> TextAndErrors

createTextAndErrors text errors pairs the source text with the compiler errors reported for it.

execute :: String -> <SCL,Proc> ()

execute commands parses and executes the given SCL command text in the command session of the current SCL context. The commands are compiled against the modules the session imports, which always include Builtin, StandardLibrary and the modules imported with the import command.

Everything the commands print, and any syntax error, compilation error or thrown exception, is passed to the reporting handler of the session. Failures are therefore not raised in the caller: a command that does not compile or that throws only produces output and cancels the rest of the command text.

isSuccessful :: CommandResponse -> Boolean

Returns True when the given command response does not report an error.

SCL Realm

getOrCreateSCLRealm :: String -> <Proc> SCLRealm

Returns the SCL realm with the given identifier, creating a new empty realm if one does not exist yet.

readSCLRealm :: Resource -> <ReadGraph,Proc> SCLRealm

Returns the SCL realm whose identifier is the name (L0.HasName) of the given resource, creating a new realm with that identifier if one does not exist yet.

refreshVariables :: SCLRealm -> <Proc> ()

Discards the cached values of the realm's variables and notifies the listeners that follow them. Returns only after the listeners have been notified.

sclRealmById :: String -> <Proc> Maybe SCLRealm

Returns Just the SCL realm with the given identifier, or Nothing if no realm with that identifier has been created. Unlike getOrCreateSCLRealm this does not create a realm.

syncExec :: SCLRealm -> <SCL,Proc> a -> <Proc> a

syncExec realm f runs f with the command session of realm as the current SCL context and returns its result. The execution thread of the realm is held for the duration, so nothing else scheduled in the realm runs at the same time.

Command Session Variable Access

setVariable :: String -> Type -> a -> <SCL> ()

setVariable name type value sets the session variable name of the command session of the current SCL context to value of the given type. Commands executed afterwards can refer to the variable by name, and it is type checked against type.

variableValue :: String -> <SCL> a

variableValue name returns the value of the session variable name in the command session of the current SCL context. The value is returned without a type check, so the caller must know the type the variable was set with, and a variable that has never been set gives a null value.

SCL Values

createSCLValue :: Resource -> Resource -> Resource -> String -> <WriteGraph> Resource

createSCLValue container predicate valueType expression creates a new SCL value resource of the given valueType whose expression is expression, attaches it to container with the statement predicate, and returns it.

createSCLValueIndependent :: Resource -> String -> <WriteGraph> Resource

createSCLValueIndependent valueType expression creates a new SCL value resource of the given valueType whose expression is expression, and returns it. The created value is not attached to anything; use createSCLValue to attach it at the same time.

setExpression :: Variable -> String -> <WriteGraph> ()

setExpression self expression replaces the SCL expression of the value resource that the variable self represents with expression. Fails if the variable does not represent a resource.

SCL Modules

createSCLModuleAction :: Resource -> <Proc> ()

Creates a new empty SCL module with a generated name under the given container in a write transaction of its own. Intended to be used as a user interface action.

createSCLModuleDefault :: Resource -> <WriteGraph> ()

As createSCLModuleR but names the new module with a fresh name derived from SCLModule and discards the created resource.

createSCLModule :: Resource -> String -> <WriteGraph> ()

Use createSCLModuleR instead.

createSCLModuleR :: Resource -> String -> <WriteGraph> Resource

createSCLModuleR container name creates a new empty SCL module under the specified container with the specified name and returns the created module's Resource.

createSCLModuleWithDefinition :: Resource -> String -> String -> <WriteGraph> 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.

setSCLModuleDefinition :: Resource -> String -> <WriteGraph> Resource

setSCLModuleDefinition module definition sets the textual definition of the specified SCL module.

SCL Scripts

createSCLScriptAction :: Resource -> <Proc> ()

Creates a new empty SCL script with a generated name under the given container in a write transaction of its own. Intended to be used as a user interface action.

createSCLScriptDefault :: Resource -> <WriteGraph> ()

As createSCLScriptR but names the new script with a fresh name derived from SCLScript and discards the created resource.

createSCLScript :: Resource -> String -> <WriteGraph> ()

Use createSCLScriptR instead.

createSCLScriptR :: Resource -> String -> <WriteGraph> 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.

createSCLScriptWithDefinition :: Resource -> String -> String -> <WriteGraph> Resource

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.

executeSCLScript :: Resource -> <Proc,Exception> ()

Shorthand for ignore $ getFutureResult (executeSCLScriptF script) to execute an SCL script and wait until the execution completes or fails without returning anything.

Before Simantics 1.52.0 this function only used to schedule the script execution like executeSCLScriptF but was changed to wait until the script execution finishes because the original behavior made no sense in under any real circumstances. The old behavior can be mimicked using ignore $ executeSCLScriptF script.

executeSCLScript will immediately raise an exception if invoked from within a database transaction. This is done avoid to avoid some potential deadlock circumstances.

executeSCLScriptF :: Resource -> <Proc> Future String

executeSCLScriptF scriptResource starts the execution of the SCL script stored in the configuration database as scriptResource.

The function only schedules the script execution and returns immediately with a Future String that can be waited upon to block until the execution finishes or fails. The String return value from the future contains information

The output of the script will be delegated primarily to the reporting handler attached to the current SCL execution context.

Secondarily, if the platform UI workbench is running, output will be pushed to SCL Script Output view.

Otherwise output will be pushed to the default logging reporter.

executeSCLScriptF will immediately raise an exception if invoked from within a database transaction. This is done avoid to avoid some potential deadlock circumstances.

setSCLScriptDefinition :: Resource -> String -> <WriteGraph> Resource

setSCLScriptDefinition script definition sets the textual definition of the specified SCL script.

Ontology definitions (PGraphs)

PGraph (partial graph) is a textual format for specifying ontologies for Simantics. For more information on the format, see this documentation.

createPGraphAction :: Resource -> <Proc> ()

Creates a new empty ontology definition file (PGraph) with a generated name under the given container in a write transaction of its own. Intended to be used as a user interface action.

createPGraphDefault :: Resource -> <WriteGraph> ()

As createPGraphR but names the new ontology definition file with a fresh name derived from Ontology Definition File and discards the created resource.

createPGraph :: Resource -> String -> <WriteGraph> ()

Use createPGraphR instead.

createPGraphR :: Resource -> String -> <WriteGraph> 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.

setPGraphDefinition :: Resource -> String -> <WriteGraph> Resource

setPGraphDefinition pgraph definition sets the textual definition of the specified ontology definition file pgraph.