1 include "Simantics/Model"
2 import "Simantics/Diagram"
3 import "Simantics/Flag"
4 import "Simantics/Workbench"
5 include "Simantics/Ontologies"
7 type UserComponent = Resource
8 type ComponentTypeConfiguration = Resource
9 type ComponentTypeProperty = Resource
11 importJava "org.simantics.modeling.NewComponentType" where
12 @JavaName createComponentType
13 createUserComponent :: Model -> <WriteGraph> UserComponent
15 configurationOfComponentType :: UserComponent -> <ReadGraph> Resource
16 configurationOfComponentType component = do
17 config = singleObject component STR.IsDefinedBy
20 importJava "org.simantics.modeling.flags.LiftFlag" where
21 liftFlag :: Resource -> <WriteGraph> Maybe String
23 flagToTerminal :: Flag -> <WriteGraph> Resource
24 flagToTerminal flag = do
25 result = liftFlag flag
27 then singleObject flag DIA.IsLiftedAs
30 @deprecated "Calling this function is unnecessary."
31 configToDiagram :: Resource -> Diagram
32 configToDiagram config = config
34 populateTerminalToSymbol :: Resource -> (Double, Double) -> <WriteGraph> Element
35 populateTerminalToSymbol terminal (x, y) = element
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
45 elementClass = singleObject terminal MOD.ConnectionRelationToTerminal
49 s = ((match possibleRelatedValue diagram DIA.HasModCount with Nothing -> 1 ; Just v -> v) :: Long)
50 claimRelatedValue element
53 claimRelatedValue diagram
55 ((match possibleRelatedValue diagram DIA.HasModCount with Nothing -> 1 ; Just v -> v+1) :: Long)
56 claimRelatedValueWithType element
59 (toDoubleArray [1,0,0,1,x,y])
60 addToGraph diagram terminal element
61 addCommentMetadata ("Populated terminal " + (show element) + " to user component " + (show uc))
64 importJava "org.simantics.modeling.symbolEditor.PopulateTerminal" where
65 addToGraph :: Resource -> Resource -> Resource -> <WriteGraph> ()
67 importJava "org.simantics.modeling.NewSymbolGroupRequest" where
68 createNewSymbolGroup :: Model -> String -> <WriteGraph> Resource
70 importJava "org.simantics.modeling.AssignSymbolGroupRequest" where
71 assignSymbolGroup :: [Resource] -> [Resource] -> [UserComponent] -> <WriteGraph> ()
73 importJava "org.simantics.modeling.GetSymbolGroups" where
74 getSymbolGroups :: Resource -> <ReadGraph> [Resource]
76 importJava "org.simantics.modeling.userComponent.ComponentTypeCommands" where
77 @JavaName createPropertyWithDefaults
78 createUserComponentProperty :: UserComponent -> <WriteGraph> Resource
81 renameUserComponentProperty :: Resource -> String -> <WriteGraph> ()
83 @JavaName setDescription
84 setUserComponentPropertyDescription :: Resource -> String -> <WriteGraph> ()
86 @JavaName createMonitorPropertyWithDefaults
87 createUserComponentMonitorProperty :: UserComponent -> <WriteGraph> Resource
89 setMonitorExpression :: Resource -> Resource -> String -> <WriteGraph> ()
91 @JavaName setDefaultValue
92 setUserComponentPropertyDefaultValue :: Resource -> Resource -> String -> <WriteGraph> ()
95 setUserComponentPropertyUnit :: Resource -> Resource -> String -> <WriteGraph> ()
98 setUserComponentPropertyRange :: Resource -> Resource -> String -> <WriteGraph> ()
101 setUserComponentPropertyLabel :: Resource -> String -> <WriteGraph> ()
104 editType :: Resource -> Resource -> Boolean -> String -> <WriteGraph> ()
106 setUserComponentPropertyRequiredType :: Resource -> Resource -> String -> <WriteGraph> ()
107 setUserComponentPropertyRequiredType componentType property newValue = do
108 editType componentType property True newValue
110 importJava "org.simantics.modeling.UserComponentMigration" where
111 migrateUserComponents :: UserComponent -> UserComponent -> [Component] -> <WriteGraph> ()
115 @JavaName newAnnotationProperty
116 createProperty :: UserComponent -> <WriteGraph> ComponentTypeProperty
118 @JavaName advancedAnnotationProperty
119 createAdvancedProperty :: UserComponent -> String -> String -> String -> String -> String -> String -> <WriteGraph> ComponentTypeProperty
121 @JavaName removeAnnotationProperty
122 removeProperty :: UserComponent -> ComponentTypeProperty -> <WriteGraph> ()
126 `addUserComponentScript userComponent scriptType scriptCode` adds the script to the user component.
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
138 possibleSubstructure :: Resource -> <ReadGraph> Maybe Resource
139 possibleSubstructure element = do
140 match possibleObject element MOD.ElementToComponent with
142 Just component -> match possibleTypeOf component STR.Component with
144 Just componentType -> match possibleObject componentType STR.IsDefinedBy with
146 Just configuration -> Just configuration
149 possibleSubstructureEditor :: Resource -> <ReadGraph,Proc> Maybe (Resource,EditorAdapter)
150 possibleSubstructureEditor element = match possibleSubstructure element with
152 Just configuration -> do
153 adapters = editorAdapters configuration
154 if(length adapters > 0) then Just (configuration, adapters!0) else Nothing
156 navigateToSubstructureAction :: Resource -> <Proc> ()
157 navigateToSubstructureAction element = do
158 match (syncRead (\x -> possibleSubstructureEditor element)) with
160 Just (configuration,editor) -> openEditor editor configuration
162 importJava "org.simantics.modeling.MigrateModel" where
163 "changeAllComponentTypes model oldComponentType newComponentType"
164 changeAllComponentTypes :: Resource -> Resource -> Resource -> <WriteGraph> ()