]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/scl/Simantics/UserComponent.scl
Make Write-interfaces as @FunctionalInterface for lambdas
[simantics/platform.git] / bundles / org.simantics.modeling / scl / Simantics / UserComponent.scl
1 include "Simantics/Model"
2 import "Simantics/Diagram"
3 import "Simantics/Flag"
4 include "Simantics/Ontologies"
5
6 type UserComponent = Resource
7 type ComponentTypeConfiguration = Resource
8 type ComponentTypeProperty = Resource
9     
10 importJava "org.simantics.modeling.NewComponentType" where
11     @JavaName createComponentType
12     createUserComponent :: Model -> <WriteGraph> UserComponent
13     
14 configurationOfComponentType :: UserComponent -> <ReadGraph> Resource
15 configurationOfComponentType component = do
16       config = singleObject (toResource component) STR.IsDefinedBy 
17       config
18       
19 importJava "org.simantics.modeling.flags.LiftFlag" where
20     liftFlag :: Resource -> <WriteGraph> Maybe String
21     
22 flagToTerminal :: Flag -> <WriteGraph> Resource
23 flagToTerminal flag = do
24     result = liftFlag (toResource flag)
25     if result == Nothing
26     then singleObject (toResource flag) DIA.IsLiftedAs
27     else do
28         show result
29         (toResource flag)
30     
31 configToDiagram :: Resource -> Diagram
32 configToDiagram config = do
33     fromResource config
34
35 populateTerminalToSymbol :: Resource  -> (Double, Double) -> <WriteGraph> Element
36 populateTerminalToSymbol terminal (x, y) = do
37     uc = singleObject terminal L0.PartOf
38     symbol = singleObject uc MOD.ComponentTypeToSymbol
39     diagram = singleObject symbol STR.IsDefinedBy
40     element = newResource ()
41     addToOrderedSet diagram element
42     claim diagram
43         L0.ConsistsOf
44         element
45     elementClass = singleObject terminal MOD.ConnectionRelationToTerminal
46     claim element
47         L0.InstanceOf
48         elementClass
49     s = ((match possibleRelatedValue diagram DIA.HasModCount with Nothing -> 1 ; Just v -> v) :: Long)
50     claimRelatedValue element
51         L0.HasName
52         (show s)
53     claimRelatedValue diagram 
54         DIA.HasModCount
55         ((match possibleRelatedValue diagram DIA.HasModCount with Nothing -> 1 ; Just v -> v+1) :: Long)
56     claimRelatedValueWithType element
57         DIA.HasTransform
58         G2D.Transform
59         (toDoubleArray [1,0,0,1,x,y])
60     addToGraph diagram terminal element
61     addCommentMetadata ("Populated terminal " + (show element) + " to user component " + (show uc))
62     (fromResource element)
63
64 importJava "org.simantics.modeling.symbolEditor.PopulateTerminal" where
65     addToGraph :: Resource -> Resource -> Resource -> <WriteGraph> ()
66
67 importJava "org.simantics.modeling.NewSymbolGroupRequest" where
68     createNewSymbolGroup :: Model -> String -> <WriteGraph> Resource
69
70 importJava "org.simantics.modeling.AssignSymbolGroupRequest" where
71     assignSymbolGroup :: [Resource] -> [Resource] -> [UserComponent] -> <WriteGraph> ()
72
73 importJava "org.simantics.modeling.GetSymbolGroups" where
74     getSymbolGroups :: Resource -> <ReadGraph> [Resource]
75
76 importJava "org.simantics.modeling.userComponent.ComponentTypeCommands" where
77     @JavaName createPropertyWithDefaults
78     createUserComponentProperty :: UserComponent -> <WriteGraph> Resource
79      
80     @JavaName rename
81     renameUserComponentProperty :: Resource -> String -> <WriteGraph> ()
82     
83     @JavaName setDescription
84     setUserComponentPropertyDescription :: Resource -> String -> <WriteGraph> ()
85     
86     @JavaName createMonitorPropertyWithDefaults
87     createUserComponentMonitorProperty :: UserComponent -> <WriteGraph> Resource
88     
89     setMonitorExpression :: Resource -> Resource -> String -> <WriteGraph> ()
90     
91     @JavaName setDefaultValue 
92     setUserComponentPropertyDefaultValue :: Resource -> Resource -> String -> <WriteGraph> ()
93     
94     @JavaName setUnit
95     setUserComponentPropertyUnit :: Resource -> Resource -> String -> <WriteGraph> ()
96     
97     @JavaName setRange
98     setUserComponentPropertyRange :: Resource -> Resource -> String -> <WriteGraph> ()
99     
100     @JavaName setLabel
101     setUserComponentPropertyLabel :: Resource -> String -> <WriteGraph> ()
102
103     @private
104     editType :: Resource -> Resource -> Boolean -> String -> <WriteGraph> ()
105     
106 setUserComponentPropertyRequiredType :: Resource -> Resource -> String -> <WriteGraph> ()
107 setUserComponentPropertyRequiredType componentType property newValue = do
108     editType componentType property True newValue
109  
110 importJava "org.simantics.modeling.UserComponentMigration" where
111     migrateUserComponents :: UserComponent -> UserComponent -> [Component] -> <WriteGraph> ()
112
113
114 /*
115     @JavaName newAnnotationProperty
116     createProperty :: UserComponent -> <WriteGraph> ComponentTypeProperty
117     
118     @JavaName advancedAnnotationProperty
119     createAdvancedProperty :: UserComponent -> String -> String -> String -> String -> String -> String -> <WriteGraph> ComponentTypeProperty
120
121     @JavaName removeAnnotationProperty
122     removeProperty :: UserComponent -> ComponentTypeProperty -> <WriteGraph> ()
123 */
124
125 """
126 `addUserComponentScript userComponent scriptType scriptCode` adds the script to the user component.
127 """
128 addUserComponentScript :: Resource -> String -> String -> String -> <WriteGraph> ()
129 addUserComponentScript userComponent scriptName scriptType scriptCode = do
130     script = newResource ()
131     claim script L0.InstanceOf STR.ComponentTypeScript
132     claim userComponent STR.ComponentType.hasScript script
133     claimRelatedValue script L0.HasName scriptName
134     claimRelatedValue script STR.ComponentTypeScript.type scriptType 
135     claimRelatedValue script STR.ComponentTypeScript.code scriptCode