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.ResourceCollectionVariableMap" where
95 createVariableMap :: [Resource] -> VariableMap
97 importJava "org.simantics.db.layer0.variable.ValueAccessor" where
100 importJava "org.simantics.db.layer0.variable.Variable" where
104 rviOf :: Variable -> <ReadGraph> RVI
106 @JavaName getProperties
107 properties_ :: Variable -> <ReadGraph> Collection Variable
109 @JavaName getProperties
110 propertiesClassified_ :: Variable -> Resource -> <ReadGraph> Collection Variable
112 @JavaName getChildren
113 children_ :: Variable -> <ReadGraph> Collection Variable
116 value_ :: Variable -> Binding a -> <ReadGraph> a
118 @JavaName getDatatype
119 datatype :: Variable -> <ReadGraph> Datatype
122 untypedValue :: Variable -> <ReadGraph> a
124 @JavaName getPossibleValue
125 possibleVariableValue_ :: Variable -> Binding a -> <ReadGraph> Maybe a
127 @JavaName getPossibleValue
128 untypedPossibleVariableValue :: Variable -> <ReadGraph> Maybe a
132 child_ :: Variable -> String -> <ReadGraph> Variable
135 @JavaName getPossibleChild
136 possibleChild_ :: Variable -> String -> <ReadGraph> Maybe Variable
138 browse :: Variable -> String -> <ReadGraph> Variable
139 browsePossible :: Variable -> String -> <ReadGraph> Maybe Variable
141 @JavaName getProperty
143 Function **property** return the wanted property as **Variable**
145 **Input 1:** Module which property we want to obtain as **Variable**
147 **Input 2:** Name of the property as **String**
149 **Output:** wanted property as **Variable**
153 import "Simantics/Variables"
154 import "Apros/Module"
155 my_property_variable = property (moduleVariable "PO01") "PO11_PRESSURE"
160 property :: Variable -> String -> <ReadGraph> Variable
162 @JavaName getPossibleProperty
163 possibleProperty :: Variable -> String -> <ReadGraph> Maybe Variable
165 @JavaName getPropertyValue
166 propertyValue_ :: Variable -> String -> Binding a -> <ReadGraph> a
168 @JavaName getPropertyValue
169 untypedPropertyValue :: Variable -> String -> <ReadGraph> a
171 @JavaName getPossiblePropertyValue
172 possiblePropertyValue_ :: Variable -> String -> Binding a -> <ReadGraph> Maybe a
174 @JavaName getPossiblePropertyValue
175 untypedPossiblePropertyValue :: Variable -> String -> <ReadGraph> Maybe a
180 Function **name** return the name of the input variable as string
184 import "Simantics/Variables"
185 import "Apros/Module"
186 name (moduleVariable "PO01")
191 name :: Variable -> <ReadGraph> String
194 Function **uri** return the uri of given variable. The uri is fetched from the active **Experiment**
196 **Input 1:** wanted variable which uri is needed as **Variable**
198 **Output:** uri of the variable as **String**
202 import "Simantics/Variables"
203 import "Apros/Module"
204 uri (moduleVariable "PO01")
206 >"http://Projects/Development%20Project/Model/Experiment/8ee6b693-891b-438e-a597-9e15a2634e8b/NewGenericDiagram/PO01"
209 uri :: Variable -> <ReadGraph> String
213 Function **variableParent** returns the name of the parent variable as **Variable**
217 import "Simantics/Variables"
218 import "Apros/Module"
219 my_variable = moduleVariable "PO01"
220 variableParent my_variable
224 name (variableParent my_variable)
226 > "NewGenericDiagram"
229 variableParent :: Variable -> <ReadGraph> Variable
231 @JavaName getRepresents
234 Function **represents** returns the resource of the given input variable
236 **Input 1:** **Variable** which resource is wanted to be obtainend
238 **Output:** **Resource** of the given input variable.
240 Example: Find out the resource of given variable
242 import "Simantics/Variables"
243 import "Apros/Module"
244 represents (moduleVariable "PO01")
249 represents :: Variable -> <ReadGraph> Resource
251 @JavaName getPossibleRepresents
252 possibleRepresents :: Variable -> <ReadGraph> Maybe Resource
255 setValue :: Variable -> a -> <WriteGraph> ()
257 @JavaName setPropertyValue
258 setPropertyValue_ :: Variable -> String -> a -> Binding a -> <WriteGraph> ()
262 Function **getType** returns the type of the input variable as resource
266 import "Simantics/Variables"
267 import "Apros/Module"
268 getType (moduleVariable "PO01")
272 nameOf(getType (moduleVariable "PO01"))
276 getType :: Variable -> <ReadGraph> Resource
278 @JavaName getPossibleType
279 getPossibleType :: Variable -> <ReadGraph> Maybe Resource
281 getPredicateResource :: Variable -> <ReadGraph> Resource
283 getIndexRoot :: Variable -> <ReadGraph> Resource
285 value :: Serializable a => Typeable a => Variable -> <ReadGraph> a
286 value var = value_ var binding
288 possibleVariableValue :: Serializable a => Typeable a => Variable -> <ReadGraph> Maybe a
289 possibleVariableValue var = possibleVariableValue_ var binding
292 Function **propertyValue** finds the value of given property.
294 Example: Find out the value of point PO01 attribute PO11_PRESSURE
296 import "Simantics/Variables"
297 import "Apros/Module"
298 propertyValue (moduleVariable "PO01") "PO11_PRESSURE" :: Double
304 propertyValue :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> a
305 propertyValue var prop = propertyValue_ var prop binding
307 possiblePropertyValue :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> Maybe a
308 possiblePropertyValue var prop = possiblePropertyValue_ var prop binding
311 Function **setPropertyValue** sets wanted to value to given Variable property.
313 **Input 1:** Wanted module as **Variable**
315 **Input 2:** Wanted property name as **String**
317 **Output:** No output, given value is inserted to property
321 import "Simantics/Variables"
322 import "Apros/Module"
323 setPropertyValue (moduleVariable "PO01") "PO11_PRESSURE" 0.5
326 setPropertyValue :: Serializable a => Variable -> String -> a -> <WriteGraph> ()
327 setPropertyValue subject prediate value = setPropertyValue_ subject prediate value binding
330 Function **modelVariableOfVariable** returns the model, in which the given input Variable is located, as **Variable**
334 import "Simantics/Variables"
335 import "Apros/Module"
336 my_model_variable = modelVariableOfVariable (moduleVariable "PO01")
341 name my_model_variable
346 modelVariableOfVariable :: Variable -> <ReadGraph> Variable
347 modelVariableOfVariable var = variable $ uriOf $ modelOfVariable var
349 uniqueChild :: Model -> Resource -> String -> <ReadGraph> Variable
350 uniqueChild model typet childName = do
351 typeName = DB.nameOf typet
352 query = "Types: " + typeName + " AND Name: " + childName
353 moduleResources = searchByQuery model query
354 variable $ uriOf $ moduleResources ! 0
357 Function **properties** returns a list, which contains of the properties of the input variable as **Variable**
359 Example 1: print out all the properties of certain point as they are shown in Variable Debugger.
361 import "Simantics/Variables"
362 import "Apros/Module"
363 point_properties_list = properties (moduleVariable "PO01")
364 //print out the names of the properties
365 for point_properties_list (\x -> print(name x) )
367 > IncludedInSimulation
375 Example 2: print out only the properties of a point, which name starts as "PO11". Else do nothing.
377 import "Simantics/Variables"
378 import "Apros/Module"
379 point_properties_list = properties (moduleVariable "PO01")
380 for point_properties_list (\x -> do
381 //print out the names of the properties, which name start as "PO11"
382 if (take 4 (name x) == "PO11") then do
393 > PO11_NODE_VELOCITY_CALC
397 properties = collectionToList . properties_
399 instance Show Variable where
400 show _ = "<variable>"
402 instance Browsable Variable where
406 possibleNameOf v = Just (name v)
407 children v = collectionToList (children_ v)
408 parent = variableParent
409 possibleParent v = Just (variableParent v)
410 valueOf v = untypedValue v
411 variantValueOf v = createVariant (datatype v) (untypedValue v :: Dynamic)
413 possibleChild = possibleChild_
415 propertiesClassified :: Variable -> Resource -> <ReadGraph> [Variable]
416 propertiesClassified parent classified = do
417 collectionToList $ propertiesClassified_ parent classified
419 importJava "org.simantics.db.layer0.variable.RVI" where
422 resolvePossible :: RVI -> Variable -> <ReadGraph> Maybe Variable
424 instantiateUnder :: Resource -> Resource -> <WriteGraph> Resource
425 instantiateUnder container typeToInstantiate = do
426 fn = (resourceVariable typeToInstantiate)#methods#instantiateUnder :: Resource -> Resource -> <WriteGraph> Resource
427 fn container typeToInstantiate