]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/scl/Simantics/SCL.scl
Added function createSCLScript to Simantics/SCL API
[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     createSCLModule :: Resource -> String -> <WriteGraph> ()
46     createSCLScript :: Resource -> String -> <WriteGraph> ()
47     createPGraph :: Resource -> String -> <WriteGraph> ()
48
49 effect SCL 
50     "scl" 
51     "org.simantics.scl.compiler.commands.CommandSession"
52
53 importJava "org.simantics.modeling.scl.SCLRealm" where
54     data SCLRealm
55     syncExec :: SCLRealm -> (<SCL, Proc> a) -> <Proc> a
56     @JavaName refreshVariablesSync
57     refreshVariables :: SCLRealm -> <Proc> ()
58     
59 readSCLRealm :: Resource -> <ReadGraph,Proc> SCLRealm
60 readSCLRealm r = let
61     id = relatedValue r L0.HasName
62   in match sclRealmById id with
63     Just realm -> realm
64     Nothing -> getOrCreateSCLRealm id
65
66 importJava "org.simantics.modeling.scl.SCLSessionManager" where
67     getOrCreateSCLRealm :: String -> <Proc> SCLRealm
68     sclRealmById :: String -> <Proc> Maybe SCLRealm
69     
70 importJava "org.simantics.scl.compiler.top.CommandResponse" where
71     data CommandResponse = 
72         @FieldNames [message, error]
73         CommandResponse String Boolean
74
75 isSuccessful :: CommandResponse -> Boolean
76 isSuccessful (CommandResponse _ error) = not error
77
78 instance Show CommandResponse where
79     show (CommandResponse message _) = message
80
81 importJava "org.simantics.scl.compiler.commands.CommandSession" where
82     execute :: String -> <SCL, Proc> ()
83     
84     @JavaName getVariableValue
85     variableValue :: String -> <SCL> a
86     setVariable :: String -> Type -> a -> <SCL> ()