]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/scl/Simantics/UserComponent.scl
Fixed Simantics/Diagram/setElements to resolve attachment relations
[simantics/platform.git] / bundles / org.simantics.modeling / scl / Simantics / UserComponent.scl
1 include "Simantics/Model"
2 import "Simantics/Diagram"
3 import "Simantics/Flag"
4 import "Simantics/Workbench"
5 include "Simantics/Ontologies"
6
7 type UserComponent = Resource
8 type ComponentTypeConfiguration = Resource
9 type ComponentTypeProperty = Resource
10     
11 importJava "org.simantics.modeling.NewComponentType" where
12     @JavaName createComponentType
13     createUserComponent :: Model -> <WriteGraph> UserComponent
14     
15 configurationOfComponentType :: UserComponent -> <ReadGraph> Resource
16 configurationOfComponentType component = do
17       config = singleObject component STR.IsDefinedBy 
18       config
19       
20 importJava "org.simantics.modeling.flags.LiftFlag" where
21     liftFlag :: Resource -> <WriteGraph> Maybe String
22     
23 flagToTerminal :: Flag -> <WriteGraph> Resource
24 flagToTerminal flag = do
25     result = liftFlag flag
26     if result == Nothing
27     then singleObject flag DIA.IsLiftedAs
28     else flag
29
30 @deprecated "Calling this function is unnecessary."  
31 configToDiagram :: Resource -> Diagram
32 configToDiagram config = config
33
34 populateTerminalToSymbol :: Resource  -> (Double, Double) -> <WriteGraph> Element
35 populateTerminalToSymbol terminal (x, y) = element
36   where
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     
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 
136
137 @private
138 possibleSubstructure :: Resource -> <ReadGraph> Maybe Resource
139 possibleSubstructure element = do
140      match possibleObject element MOD.ElementToComponent with
141        Nothing -> Nothing
142        Just component -> match possibleTypeOf component STR.Component with
143          Nothing -> Nothing
144          Just componentType -> match possibleObject componentType STR.IsDefinedBy with
145            Nothing -> Nothing
146            Just configuration -> Just configuration
147
148 @private
149 possibleSubstructureEditor :: Resource -> <ReadGraph,Proc> Maybe (Resource,EditorAdapter)
150 possibleSubstructureEditor element = match possibleSubstructure element with
151   Nothing -> Nothing
152   Just configuration -> do
153     adapters = editorAdapters configuration
154     if(length adapters > 0) then Just (configuration, adapters!0) else Nothing
155
156 navigateToSubstructureAction :: Resource -> <Proc> ()
157 navigateToSubstructureAction element = do
158  match (syncRead (\x -> possibleSubstructureEditor element)) with
159    Nothing -> ()
160    Just (configuration,editor) -> openEditor editor configuration
161
162 importJava "org.simantics.modeling.MigrateModel" where
163     "changeAllComponentTypes model oldComponentType newComponentType"
164     changeAllComponentTypes :: Resource -> Resource -> Resource -> <WriteGraph> ()