]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/scl/Simantics/Query.scl
Fixed Simantics/Diagram/setElements to resolve attachment relations
[simantics/platform.git] / bundles / org.simantics.modeling / scl / Simantics / Query.scl
1 include "Simantics/DB"
2 include "Simantics/Ontologies"
3 include "Simantics/Variables"
4 include "Spreadsheet/All"
5
6 createSCLQueryAction :: Resource -> <Proc> ()
7 createSCLQueryAction res = do
8   syncWrite (\() -> createSCLQueryDefault res) 
9   ()
10
11 createSCLQueryTypeAction :: Resource -> <Proc> ()
12 createSCLQueryTypeAction res = do
13   syncWrite (\() -> createSCLQueryTypeDefault res) 
14   ()
15
16 createSCLQueryDefault :: Resource -> Resource -> <WriteGraph> Resource
17 createSCLQueryDefault library queryType = createSCLQuery library queryType $ findFreshEscapedName "Query" library 
18
19 createSCLQuery :: Resource -> Resource -> String -> <WriteGraph> Resource
20 createSCLQuery library queryType name = do
21     markUndoPoint ()
22     module = newResource ()
23     claim module L0.InstanceOf queryType
24     claimRelatedValue module L0.HasName name
25     claim module L0.PartOf library
26     sheet = createSheet module "Sheet"
27     range = createRange sheet SHEET.ExpressionRange "Range1" "queryCells $ sheetQueryValue self input"
28     addCommentMetadata ("Created SCL Query " + name)
29     module
30
31 createSCLQueryTypeDefault :: Resource -> <WriteGraph> Resource
32 createSCLQueryTypeDefault library = createSCLQueryType library $ findFreshEscapedName "QueryType" library 
33
34 createSCLQueryType :: Resource -> String -> <WriteGraph> Resource
35 createSCLQueryType library name = do
36     markUndoPoint ()
37     queryType = newResource ()
38     claim queryType L0.Inherits MOD.SCLQuery
39     claimRelatedValue queryType L0.HasName name
40     claimAssertion queryType MOD.SCLQuery.values $ createSCLValueIndependent MOD.SCLQuery.Value "[]"
41     claim queryType L0.PartOf library
42     addCommentMetadata ("Created SCL Query Type " + name)
43     queryType
44
45 queryValue :: Variable -> Variable -> <ReadGraph> a
46 queryValue variable input = do
47     untypedValue $ browse (makeProxyVariable variable input) "#values" 
48
49 sheetQueryVariable :: Variable -> Variable -> <ReadGraph> Variable
50 sheetQueryVariable self input = do
51     query = variableParent $ proxyVariableBase self
52     makeProxyVariable query input
53
54 sheetQueryValue :: Variable -> Variable -> <ReadGraph> a
55 sheetQueryValue self input = do
56     var = sheetQueryVariable self input
57     untypedValue $ browse var "#values"
58
59 importJava "org.simantics.db.layer0.variable.ProxyVariables" where
60     inputVariable :: Variable -> <ReadGraph> Variable
61     sessionVariable :: Variable -> <ReadGraph> Variable
62     proxyVariableBase :: Variable -> <ReadGraph> Variable
63     makeProxyVariable :: Variable -> Variable -> <ReadGraph> Variable
64