1 include "Simantics/Model"
3 import "Simantics/DB" as DB
5 importJava "org.simantics.db.layer0.variable.Variables" where
8 Function **variable** converts a variable URI to a variable.
12 import "Simantics/Variables"
14 model_id = model "Model"
15 my_component = getComponent model_id "PO01"
16 my_uri = uriOf my_component
17 my_variable = variable my_uri
22 variable :: String -> <ReadGraph> Variable
24 @JavaName getPossibleVariable
25 possibleVariable :: String -> <ReadGraph> Maybe Variable
29 Function **resourceVariable** converts a resource to a corresponding variable.
33 import "Simantics/Variables"
35 model_id = model "Model"
36 my_resource = getComponent model_id "PO01"
37 my_variable = resourceVariable my_resource
42 resourceVariable :: Resource -> <ReadGraph> Variable
46 Function **modelOfVariable** returns the model, in which the given input variable is located, as **Resource**
50 import "Simantics/Variables"
52 my_variable = moduleVariable "PO01"
53 my_model = modelOfVariable my_variable
58 // use function nameOf, which works for resources, to print out the name of the model
64 modelOfVariable :: Variable -> <ReadGraph> Model
67 modelResourceOfVariable :: Variable -> <ReadGraph> Resource
69 @JavaName possibleActiveVariable
70 possibleActiveVariable :: Variable -> <ReadGraph> Maybe Variable
72 @JavaName switchPossibleContext
73 switchPossibleContext :: Variable -> Resource -> <ReadGraph> Maybe Variable
75 @JavaName getIndexRoot
76 instanceIndexRoot :: Variable -> <ReadGraph> Resource
78 createValueAccessor :: (Variable -> <ReadGraph> a) -> (Variable -> Binding b -> <ReadGraph> b) -> (Variable -> c -> <WriteGraph> ()) -> (Variable -> d -> Binding d -> <WriteGraph> ()) -> (Variable -> <ReadGraph> Datatype) -> ValueAccessor
80 @JavaName getConfigurationContext
81 possibleConfigurationContext :: Resource -> <ReadGraph> Variable
83 setRVIProperty :: Variable -> RVI -> <WriteGraph> ()
85 importJava "org.simantics.db.layer0.function.All" where
87 standardGetValue1 :: Variable -> <ReadGraph> a
88 standardGetValue2 :: Variable -> Binding a -> <ReadGraph> a
89 standardSetValue2 :: Variable -> a -> <WriteGraph> ()
90 standardSetValue3 :: Variable -> a -> Binding a -> <WriteGraph> ()
91 standardGetDatatype :: Variable -> <ReadGraph> Datatype
93 importJava "org.simantics.db.layer0.variable.VariableMap" where
96 importJava "org.simantics.db.layer0.variable.ResourceCollectionVariableMap" where
98 createVariableMap :: [Resource] -> VariableMap
100 importJava "org.simantics.db.layer0.variable.ValueAccessor" where
103 importJava "org.simantics.db.layer0.variable.Variable" where
107 rviOf :: Variable -> <ReadGraph> RVI
109 @JavaName getProperties
110 properties_ :: Variable -> <ReadGraph> Collection Variable
112 @JavaName getProperties
113 propertiesClassified_ :: Variable -> Resource -> <ReadGraph> Collection Variable
115 @JavaName getChildren
116 children_ :: Variable -> <ReadGraph> Collection Variable
119 value_ :: Variable -> Binding a -> <ReadGraph> a
121 @JavaName getDatatype
122 datatype :: Variable -> <ReadGraph> Datatype
125 untypedValue :: Variable -> <ReadGraph> a
127 @JavaName getPossibleValue
128 possibleVariableValue_ :: Variable -> Binding a -> <ReadGraph> Maybe a
130 @JavaName getPossibleValue
131 untypedPossibleVariableValue :: Variable -> <ReadGraph> Maybe a
135 child_ :: Variable -> String -> <ReadGraph> Variable
138 @JavaName getPossibleChild
139 possibleChild_ :: Variable -> String -> <ReadGraph> Maybe Variable
141 browse :: Variable -> String -> <ReadGraph> Variable
142 browsePossible :: Variable -> String -> <ReadGraph> Maybe Variable
144 @JavaName getProperty
146 Function **property** return the wanted property as **Variable**
148 **Input 1:** Module which property we want to obtain as **Variable**
150 **Input 2:** Name of the property as **String**
152 **Output:** wanted property as **Variable**
156 import "Simantics/Variables"
157 import "Apros/Module"
158 my_property_variable = property (moduleVariable "PO01") "PO11_PRESSURE"
163 property :: Variable -> String -> <ReadGraph> Variable
165 @JavaName getPossibleProperty
166 possibleProperty :: Variable -> String -> <ReadGraph> Maybe Variable
168 @JavaName getPropertyValue
169 propertyValue_ :: Variable -> String -> Binding a -> <ReadGraph> a
171 @JavaName getPropertyValue
172 untypedPropertyValue :: Variable -> String -> <ReadGraph> a
174 @JavaName getPossiblePropertyValue
175 possiblePropertyValue_ :: Variable -> String -> Binding a -> <ReadGraph> Maybe a
177 @JavaName getPossiblePropertyValue
178 untypedPossiblePropertyValue :: Variable -> String -> <ReadGraph> Maybe a
183 Function **name** return the name of the input variable as string
187 import "Simantics/Variables"
188 import "Apros/Module"
189 name (moduleVariable "PO01")
194 name :: Variable -> <ReadGraph> String
197 Function **uri** return the uri of given variable. The uri is fetched from the active **Experiment**
199 **Input 1:** wanted variable which uri is needed as **Variable**
201 **Output:** uri of the variable as **String**
205 import "Simantics/Variables"
206 import "Apros/Module"
207 uri (moduleVariable "PO01")
209 >"http://Projects/Development%20Project/Model/Experiment/8ee6b693-891b-438e-a597-9e15a2634e8b/NewGenericDiagram/PO01"
212 uri :: Variable -> <ReadGraph> String
216 Function **variableParent** returns the name of the parent variable as **Variable**
220 import "Simantics/Variables"
221 import "Apros/Module"
222 my_variable = moduleVariable "PO01"
223 variableParent my_variable
227 name (variableParent my_variable)
229 > "NewGenericDiagram"
232 variableParent :: Variable -> <ReadGraph> Variable
234 @JavaName getRepresents
237 Function **represents** returns the resource of the given input variable
239 **Input 1:** **Variable** which resource is wanted to be obtainend
241 **Output:** **Resource** of the given input variable.
243 Example: Find out the resource of given variable
245 import "Simantics/Variables"
246 import "Apros/Module"
247 represents (moduleVariable "PO01")
252 represents :: Variable -> <ReadGraph> Resource
254 @JavaName getPossibleRepresents
255 possibleRepresents :: Variable -> <ReadGraph> Maybe Resource
258 setValue :: Variable -> a -> <WriteGraph> ()
260 @JavaName setPropertyValue
261 setPropertyValue_ :: Variable -> String -> a -> Binding a -> <WriteGraph> ()
265 Function **getType** returns the type of the input variable as resource
269 import "Simantics/Variables"
270 import "Apros/Module"
271 getType (moduleVariable "PO01")
275 nameOf(getType (moduleVariable "PO01"))
279 getType :: Variable -> <ReadGraph> Resource
281 @JavaName getPossibleType
282 getPossibleType :: Variable -> <ReadGraph> Maybe Resource
284 getPredicateResource :: Variable -> <ReadGraph> Resource
286 getIndexRoot :: Variable -> <ReadGraph> Resource
288 value :: Serializable a => Typeable a => Variable -> <ReadGraph> a
289 value var = value_ var binding
291 possibleVariableValue :: Serializable a => Typeable a => Variable -> <ReadGraph> Maybe a
292 possibleVariableValue var = possibleVariableValue_ var binding
295 Function **propertyValue** finds the value of given property.
297 Example: Find out the value of point PO01 attribute PO11_PRESSURE
299 import "Simantics/Variables"
300 import "Apros/Module"
301 propertyValue (moduleVariable "PO01") "PO11_PRESSURE" :: Double
307 propertyValue :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> a
308 propertyValue var prop = propertyValue_ var prop binding
310 possiblePropertyValue :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> Maybe a
311 possiblePropertyValue var prop = possiblePropertyValue_ var prop binding
314 Function **setPropertyValue** sets wanted to value to given Variable property.
316 **Input 1:** Wanted module as **Variable**
318 **Input 2:** Wanted property name as **String**
320 **Output:** No output, given value is inserted to property
324 import "Simantics/Variables"
325 import "Apros/Module"
326 setPropertyValue (moduleVariable "PO01") "PO11_PRESSURE" 0.5
329 setPropertyValue :: Serializable a => Variable -> String -> a -> <WriteGraph> ()
330 setPropertyValue subject prediate value = setPropertyValue_ subject prediate value binding
333 Function **modelVariableOfVariable** returns the model, in which the given input Variable is located, as **Variable**
337 import "Simantics/Variables"
338 import "Apros/Module"
339 my_model_variable = modelVariableOfVariable (moduleVariable "PO01")
344 name my_model_variable
349 modelVariableOfVariable :: Variable -> <ReadGraph> Variable
350 modelVariableOfVariable var = variable $ uriOf $ modelOfVariable var
352 uniqueChild :: Model -> Resource -> String -> <ReadGraph> Variable
353 uniqueChild model typet childName = do
354 typeName = DB.nameOf typet
355 query = "Types: " + typeName + " AND Name: " + childName
356 moduleResources = searchByQuery model query
357 variable $ uriOf $ moduleResources ! 0
360 Function **properties** returns a list, which contains of the properties of the input variable as **Variable**
362 Example 1: print out all the properties of certain point as they are shown in Variable Debugger.
364 import "Simantics/Variables"
365 import "Apros/Module"
366 point_properties_list = properties (moduleVariable "PO01")
367 //print out the names of the properties
368 for point_properties_list (\x -> print(name x) )
370 > IncludedInSimulation
378 Example 2: print out only the properties of a point, which name starts as "PO11". Else do nothing.
380 import "Simantics/Variables"
381 import "Apros/Module"
382 point_properties_list = properties (moduleVariable "PO01")
383 for point_properties_list (\x -> do
384 //print out the names of the properties, which name start as "PO11"
385 if (take 4 (name x) == "PO11") then do
396 > PO11_NODE_VELOCITY_CALC
400 properties = collectionToList . properties_
402 instance Show Variable where
403 show _ = "<variable>"
405 instance Browsable Variable where
409 possibleNameOf v = Just (name v)
410 children v = collectionToList (children_ v)
411 parent = variableParent
412 possibleParent v = Just (variableParent v)
413 valueOf v = untypedValue v
414 variantValueOf v = createVariant (datatype v) (untypedValue v :: Dynamic)
416 possibleChild = possibleChild_
418 propertiesClassified :: Variable -> Resource -> <ReadGraph> [Variable]
419 propertiesClassified parent classified = do
420 collectionToList $ propertiesClassified_ parent classified
422 importJava "org.simantics.db.layer0.variable.RVI" where
425 resolvePossible :: RVI -> Variable -> <ReadGraph> Maybe Variable
427 instantiateUnder :: Resource -> Resource -> <WriteGraph> Resource
428 instantiateUnder container typeToInstantiate = do
429 fn = (resourceVariable typeToInstantiate)#methods#instantiateUnder :: Resource -> Resource -> <WriteGraph> Resource
430 fn container typeToInstantiate