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