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
26 Function **resourceVariable** converts a resource to a corresponding variable.
30 import "Simantics/Variables"
32 model_id = model "Model"
33 my_resource = getComponent model_id "PO01"
34 my_variable = resourceVariable my_resource
39 resourceVariable :: Resource -> <ReadGraph> Variable
43 Function **modelOfVariable** returns the model, in which the given input variable is located, as **Resource**
47 import "Simantics/Variables"
49 my_variable = moduleVariable "PO01"
50 my_model = modelOfVariable my_variable
55 // use function nameOf, which works for resources, to print out the name of the model
61 modelOfVariable :: Variable -> <ReadGraph> Model
64 modelResourceOfVariable :: Variable -> <ReadGraph> Resource
66 @JavaName possibleActiveVariable
67 possibleActiveVariable :: Variable -> <ReadGraph> Maybe Variable
69 @JavaName switchPossibleContext
70 switchPossibleContext :: Variable -> Resource -> <ReadGraph> Maybe Variable
72 @JavaName getIndexRoot
73 instanceIndexRoot :: Variable -> <ReadGraph> Resource
75 createValueAccessor :: (Variable -> <ReadGraph> a) -> (Variable -> Binding b -> <ReadGraph> b) -> (Variable -> c -> <WriteGraph> ()) -> (Variable -> d -> Binding d -> <WriteGraph> ()) -> (Variable -> <ReadGraph> Datatype) -> ValueAccessor
77 @JavaName getConfigurationContext
78 possibleConfigurationContext :: Resource -> <ReadGraph> Variable
80 setRVIProperty :: Variable -> RVI -> <WriteGraph> ()
82 importJava "org.simantics.db.layer0.function.All" where
84 standardGetValue1 :: Variable -> <ReadGraph> a
85 standardGetValue2 :: Variable -> Binding a -> <ReadGraph> a
86 standardSetValue2 :: Variable -> a -> <WriteGraph> ()
87 standardSetValue3 :: Variable -> a -> Binding a -> <WriteGraph> ()
88 standardGetDatatype :: Variable -> <ReadGraph> Datatype
90 importJava "org.simantics.db.layer0.variable.VariableMap" where
93 importJava "org.simantics.db.layer0.variable.ValueAccessor" where
96 importJava "org.simantics.db.layer0.variable.Variable" where
100 rviOf :: Variable -> <ReadGraph> RVI
102 @JavaName getProperties
103 properties_ :: Variable -> <ReadGraph> Collection Variable
105 @JavaName getProperties
106 propertiesClassified_ :: Variable -> Resource -> <ReadGraph> Collection Variable
108 @JavaName getChildren
109 children_ :: Variable -> <ReadGraph> Collection Variable
112 value_ :: Variable -> Binding a -> <ReadGraph> a
114 @JavaName getDatatype
115 datatype :: Variable -> <ReadGraph> Datatype
118 untypedValue :: Variable -> <ReadGraph> a
120 @JavaName getPossibleValue
121 possibleVariableValue_ :: Variable -> Binding a -> <ReadGraph> Maybe a
123 @JavaName getPossibleValue
124 untypedPossibleVariableValue :: Variable -> <ReadGraph> Maybe a
128 child_ :: Variable -> String -> <ReadGraph> Variable
131 @JavaName getPossibleChild
132 possibleChild_ :: Variable -> String -> <ReadGraph> Maybe Variable
134 browse :: Variable -> String -> <ReadGraph> Variable
135 browsePossible :: Variable -> String -> <ReadGraph> Maybe Variable
137 @JavaName getProperty
139 Function **property** return the wanted property as **Variable**
141 **Input 1:** Module which property we want to obtain as **Variable**
143 **Input 2:** Name of the property as **String**
145 **Output:** wanted property as **Variable**
149 import "Simantics/Variables"
150 import "Apros/Module"
151 my_property_variable = property (moduleVariable "PO01") "PO11_PRESSURE"
156 property :: Variable -> String -> <ReadGraph> Variable
158 @JavaName getPossibleProperty
159 possibleProperty :: Variable -> String -> <ReadGraph> Maybe Variable
161 @JavaName getPropertyValue
162 propertyValue_ :: Variable -> String -> Binding a -> <ReadGraph> a
164 @JavaName getPropertyValue
165 untypedPropertyValue :: Variable -> String -> <ReadGraph> a
167 @JavaName getPossiblePropertyValue
168 possiblePropertyValue_ :: Variable -> String -> Binding a -> <ReadGraph> Maybe a
170 @JavaName getPossiblePropertyValue
171 untypedPossiblePropertyValue :: Variable -> String -> <ReadGraph> Maybe a
176 Function **name** return the name of the input variable as string
180 import "Simantics/Variables"
181 import "Apros/Module"
182 name (moduleVariable "PO01")
187 name :: Variable -> <ReadGraph> String
190 Function **uri** return the uri of given variable. The uri is fetched from the active **Experiment**
192 **Input 1:** wanted variable which uri is needed as **Variable**
194 **Output:** uri of the variable as **String**
198 import "Simantics/Variables"
199 import "Apros/Module"
200 uri (moduleVariable "PO01")
202 >"http://Projects/Development%20Project/Model/Experiment/8ee6b693-891b-438e-a597-9e15a2634e8b/NewGenericDiagram/PO01"
205 uri :: Variable -> <ReadGraph> String
209 Function **variableParent** returns the name of the parent variable as **Variable**
213 import "Simantics/Variables"
214 import "Apros/Module"
215 my_variable = moduleVariable "PO01"
216 variableParent my_variable
220 name (variableParent my_variable)
222 > "NewGenericDiagram"
225 variableParent :: Variable -> <ReadGraph> Variable
227 @JavaName getRepresents
230 Function **represents** returns the resource of the given input variable
232 **Input 1:** **Variable** which resource is wanted to be obtainend
234 **Output:** **Resource** of the given input variable.
236 Example: Find out the resource of given variable
238 import "Simantics/Variables"
239 import "Apros/Module"
240 represents (moduleVariable "PO01")
245 represents :: Variable -> <ReadGraph> Resource
247 @JavaName getPossibleRepresents
248 possibleRepresents :: Variable -> <ReadGraph> Maybe Resource
251 setValue :: Variable -> a -> <WriteGraph> ()
253 @JavaName setPropertyValue
254 setPropertyValue_ :: Variable -> String -> a -> Binding a -> <WriteGraph> ()
258 Function **getType** returns the type of the input variable as resource
262 import "Simantics/Variables"
263 import "Apros/Module"
264 getType (moduleVariable "PO01")
268 nameOf(getType (moduleVariable "PO01"))
272 getType :: Variable -> <ReadGraph> Resource
274 @JavaName getPossibleType
275 getPossibleType :: Variable -> <ReadGraph> Maybe Resource
277 getPredicateResource :: Variable -> <ReadGraph> Resource
279 getIndexRoot :: Variable -> <ReadGraph> Resource
281 value :: Serializable a => Typeable a => Variable -> <ReadGraph> a
282 value var = value_ var binding
284 possibleVariableValue :: Serializable a => Typeable a => Variable -> <ReadGraph> Maybe a
285 possibleVariableValue var = possibleVariableValue_ var binding
288 Function **propertyValue** finds the value of given property.
290 Example: Find out the value of point PO01 attribute PO11_PRESSURE
292 import "Simantics/Variables"
293 import "Apros/Module"
294 propertyValue (moduleVariable "PO01") "PO11_PRESSURE" :: Double
300 propertyValue :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> a
301 propertyValue var prop = propertyValue_ var prop binding
303 possiblePropertyValue :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> Maybe a
304 possiblePropertyValue var prop = possiblePropertyValue_ var prop binding
307 Function **setPropertyValue** sets wanted to value to given Variable property.
309 **Input 1:** Wanted module as **Variable**
311 **Input 2:** Wanted property name as **String**
313 **Output:** No output, given value is inserted to property
317 import "Simantics/Variables"
318 import "Apros/Module"
319 setPropertyValue (moduleVariable "PO01") "PO11_PRESSURE" 0.5
322 setPropertyValue :: Serializable a => Variable -> String -> a -> <WriteGraph> ()
323 setPropertyValue subject prediate value = setPropertyValue_ subject prediate value binding
326 Function **modelVariableOfVariable** returns the model, in which the given input Variable is located, as **Variable**
330 import "Simantics/Variables"
331 import "Apros/Module"
332 my_model_variable = modelVariableOfVariable (moduleVariable "PO01")
337 name my_model_variable
342 modelVariableOfVariable :: Variable -> <ReadGraph> Variable
343 modelVariableOfVariable var = variable $ uriOf $ modelOfVariable var
345 uniqueChild :: Model -> Resource -> String -> <ReadGraph> Variable
346 uniqueChild model typet childName = do
347 typeName = DB.nameOf typet
348 query = "Types: " + typeName + " AND Name: " + childName
349 moduleResources = searchByQuery model query
350 variable $ uriOf $ moduleResources ! 0
353 Function **properties** returns a list, which contains of the properties of the input variable as **Variable**
355 Example 1: print out all the properties of certain point as they are shown in Variable Debugger.
357 import "Simantics/Variables"
358 import "Apros/Module"
359 point_properties_list = properties (moduleVariable "PO01")
360 //print out the names of the properties
361 for point_properties_list (\x -> print(name x) )
363 > IncludedInSimulation
371 Example 2: print out only the properties of a point, which name starts as "PO11". Else do nothing.
373 import "Simantics/Variables"
374 import "Apros/Module"
375 point_properties_list = properties (moduleVariable "PO01")
376 for point_properties_list (\x -> do
377 //print out the names of the properties, which name start as "PO11"
378 if (take 4 (name x) == "PO11") then do
389 > PO11_NODE_VELOCITY_CALC
393 properties = collectionToList . properties_
395 instance Show Variable where
396 show _ = "<variable>"
398 instance Browsable Variable where
402 possibleNameOf v = Just (name v)
403 children v = collectionToList (children_ v)
404 parent = variableParent
405 possibleParent v = Just (variableParent v)
406 valueOf v = untypedValue v
407 variantValueOf v = createVariant (datatype v) (untypedValue v :: Dynamic)
409 possibleChild = possibleChild_
411 propertiesClassified :: Variable -> Resource -> <ReadGraph> [Variable]
412 propertiesClassified parent classified = do
413 collectionToList $ propertiesClassified_ parent classified
415 importJava "org.simantics.db.layer0.variable.RVI" where
418 resolvePossible :: RVI -> Variable -> <ReadGraph> Maybe Variable
420 instantiateUnder :: Resource -> Resource -> <WriteGraph> Resource
421 instantiateUnder container typeToInstantiate = do
422 fn = (resourceVariable typeToInstantiate)#methods#instantiateUnder :: Resource -> Resource -> <WriteGraph> Resource
423 fn container typeToInstantiate