]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/scl/Simantics/SCL.scl
Improved Simantics/SCL module SCL module/script functionality
[simantics/platform.git] / bundles / org.simantics.modeling / scl / Simantics / SCL.scl
1 include "Simantics/DB"
2 include "Simantics/Variables"
3 include "Simantics/Ontologies"
4
5 include "http://www.simantics.org/Modeling-1.2/SCLQuery" as SCLQuery
6
7 importJava "org.simantics.scl.compiler.errors.CompilationError" where
8     data CompilationError
9
10 importJava "org.simantics.scl.ui.editor.TextAndErrors" where
11     data TextAndErrors
12     createTextAndErrors :: String -> [CompilationError] -> TextAndErrors
13
14 createSCLModuleAction :: Resource -> <Proc> ()
15 createSCLModuleAction res = ignore $ syncWrite (\() -> createSCLModuleDefault res)
16
17 createSCLScriptAction :: Resource -> <Proc> ()
18 createSCLScriptAction res = ignore $ syncWrite (\() -> createSCLScriptDefault res)
19
20 createPGraphAction :: Resource -> <Proc> ()
21 createPGraphAction res = ignore $ syncWrite (\() -> createPGraphDefault res)
22
23 createSCLValueIndependent :: Resource -> String -> <WriteGraph> Resource
24 createSCLValueIndependent valueType expression = do
25     value = newResource ()
26     claim value L0.InstanceOf valueType
27     claimRelatedValue value L0.SCLValue.expression expression
28     value
29
30 createSCLValue :: Resource -> Resource -> Resource -> String -> <WriteGraph> Resource
31 createSCLValue container predicate valueType expression = do
32     value = createSCLValueIndependent valueType expression
33     claim container predicate value
34     value
35
36 setExpression :: Variable -> String -> <WriteGraph> ()
37 setExpression self expression = do
38     res = represents self
39     claimRelatedValue res L0.SCLValue.expression expression
40
41 importJava "org.simantics.modeling.ModelingUtils" where
42     createSCLModuleDefault :: Resource -> <WriteGraph> ()
43     createSCLScriptDefault :: Resource -> <WriteGraph> ()
44     createPGraphDefault :: Resource -> <WriteGraph> ()
45     "Use [createSCLModuleR](#createSCLModuleR) instead."
46     @deprecated
47     createSCLModule :: Resource -> String -> <WriteGraph> ()
48     "Use [createSCLScriptR](#createSCLScriptR) instead."
49     @deprecated
50     createSCLScript :: Resource -> String -> <WriteGraph> ()
51     "Use [createPGraphR](#createPGraphR) instead."
52     @deprecated
53     createPGraph :: Resource -> String -> <WriteGraph> ()
54     """
55     `createSCLModuleR container name` creates a new empty SCL module under
56     the specified `container` with the specified `name` and returns the created
57     module's Resource.
58     """
59     @JavaName createSCLModule
60     createSCLModuleR :: Resource -> String -> <WriteGraph> Resource
61     """
62     `createSCLScriptR container name` creates a new empty SCL script under
63     the specified `container` with the specified `name` and returns the created
64     script's Resource.
65     """
66     @JavaName createSCLScript
67     createSCLScriptR :: Resource -> String -> <WriteGraph> Resource
68     """
69     `createPGraphR container name` creates a new empty partial graph
70     ontology definition (PGraph) under the specified `container` with
71     the specified `name` and returns the created ontology definition's
72     Resource.
73     """
74     @JavaName createPGraph
75     createPGraphR :: Resource -> String -> <WriteGraph> Resource
76     "`setSCLModuleDefinition module definition` sets the textual `definition` of the specified SCL `module`."
77     setSCLModuleDefinition :: Resource -> String -> <WriteGraph> Resource
78     "`setSCLScriptDefinition module definition` sets the textual `definition` of the specified SCL `module`."
79     setSCLScriptDefinition :: Resource -> String -> <WriteGraph> Resource
80     setPGraphDefinition :: Resource -> String -> <WriteGraph> Resource
81
82 """
83 `createSCLModuleWithDefinition container name definition` creates a new SCL module under
84 the specified `container` with the specified `name` and `definition` and returns
85 the created module's Resource.
86 """
87 createSCLModuleWithDefinition :: Resource -> String -> String -> <WriteGraph> Resource
88 createSCLModuleWithDefinition container name definition = setSCLModuleDefinition (createSCLModuleR container name) definition
89
90 """
91 `createSCLScriptWithDefinition container name definition` creates a new SCL script under
92 the specified `container` with the specified `name` and `definition` and returns
93 the created script's Resource.
94 """
95 createSCLScriptWithDefinition :: Resource -> String -> String -> <WriteGraph> Resource
96 createSCLScriptWithDefinition container name definition = setSCLScriptDefinition (createSCLScriptR container name) definition
97
98 effect SCL 
99     "scl" 
100     "org.simantics.scl.compiler.commands.CommandSession"
101
102 importJava "org.simantics.modeling.scl.SCLRealm" where
103     data SCLRealm
104     syncExec :: SCLRealm -> (<SCL, Proc> a) -> <Proc> a
105     @JavaName refreshVariablesSync
106     refreshVariables :: SCLRealm -> <Proc> ()
107     
108 readSCLRealm :: Resource -> <ReadGraph,Proc> SCLRealm
109 readSCLRealm r = let
110     id = relatedValue r L0.HasName
111   in match sclRealmById id with
112     Just realm -> realm
113     Nothing -> getOrCreateSCLRealm id
114
115 importJava "org.simantics.modeling.scl.SCLSessionManager" where
116     getOrCreateSCLRealm :: String -> <Proc> SCLRealm
117     sclRealmById :: String -> <Proc> Maybe SCLRealm
118     
119 importJava "org.simantics.scl.compiler.top.CommandResponse" where
120     data CommandResponse = 
121         @FieldNames [message, error]
122         CommandResponse String Boolean
123
124 isSuccessful :: CommandResponse -> Boolean
125 isSuccessful (CommandResponse _ error) = not error
126
127 instance Show CommandResponse where
128     show (CommandResponse message _) = message
129
130 importJava "org.simantics.scl.compiler.commands.CommandSession" where
131     execute :: String -> <SCL, Proc> ()
132     
133     @JavaName getVariableValue
134     variableValue :: String -> <SCL> a
135     setVariable :: String -> Type -> a -> <SCL> ()