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 importJava "org.simantics.db.layer0.function.All" where
79 standardGetValue1 :: Variable -> <ReadGraph> a
80 standardGetValue2 :: Variable -> Binding a -> <ReadGraph> a
81 standardSetValue2 :: Variable -> a -> <WriteGraph> ()
82 standardSetValue3 :: Variable -> a -> Binding a -> <WriteGraph> ()
83 standardGetDatatype :: Variable -> <ReadGraph> Datatype
85 importJava "org.simantics.db.layer0.variable.VariableMap" where
88 importJava "org.simantics.db.layer0.variable.ValueAccessor" where
91 importJava "org.simantics.db.layer0.variable.Variable" where
94 @JavaName getProperties
95 properties_ :: Variable -> <ReadGraph> Collection Variable
97 @JavaName getProperties
98 propertiesClassified_ :: Variable -> Resource -> <ReadGraph> Collection Variable
100 @JavaName getChildren
101 children_ :: Variable -> <ReadGraph> Collection Variable
104 value_ :: Variable -> Binding a -> <ReadGraph> a
106 @JavaName getDatatype
107 datatype :: Variable -> <ReadGraph> Datatype
110 untypedValue :: Variable -> <ReadGraph> a
112 @JavaName getPossibleValue
113 possibleVariableValue_ :: Variable -> Binding a -> <ReadGraph> Maybe a
115 @JavaName getPossibleValue
116 untypedPossibleVariableValue :: Variable -> <ReadGraph> Maybe a
120 child_ :: Variable -> String -> <ReadGraph> Variable
123 @JavaName getPossibleChild
124 possibleChild_ :: Variable -> String -> <ReadGraph> Maybe Variable
126 browse :: Variable -> String -> <ReadGraph> Variable
127 browsePossible :: Variable -> String -> <ReadGraph> Maybe Variable
129 @JavaName getProperty
131 Function **property** return the wanted property as **Variable**
133 **Input 1:** Module which property we want to obtain as **Variable**
135 **Input 2:** Name of the property as **String**
137 **Output:** wanted property as **Variable**
141 import "Simantics/Variables"
142 import "Apros/Module"
143 my_property_variable = property (moduleVariable "PO01") "PO11_PRESSURE"
148 property :: Variable -> String -> <ReadGraph> Variable
150 @JavaName getPossibleProperty
151 possibleProperty :: Variable -> String -> <ReadGraph> Maybe Variable
153 @JavaName getPropertyValue
154 propertyValue_ :: Variable -> String -> Binding a -> <ReadGraph> a
156 @JavaName getPropertyValue
157 untypedPropertyValue :: Variable -> String -> <ReadGraph> a
159 @JavaName getPossiblePropertyValue
160 possiblePropertyValue_ :: Variable -> String -> Binding a -> <ReadGraph> Maybe a
162 @JavaName getPossiblePropertyValue
163 untypedPossiblePropertyValue :: Variable -> String -> <ReadGraph> Maybe a
168 Function **name** return the name of the input variable as string
172 import "Simantics/Variables"
173 import "Apros/Module"
174 name (moduleVariable "PO01")
179 name :: Variable -> <ReadGraph> String
182 Function **uri** return the uri of given variable. The uri is fetched from the active **Experiment**
184 **Input 1:** wanted variable which uri is needed as **Variable**
186 **Output:** uri of the variable as **String**
190 import "Simantics/Variables"
191 import "Apros/Module"
192 uri (moduleVariable "PO01")
194 >"http://Projects/Development%20Project/Model/Experiment/8ee6b693-891b-438e-a597-9e15a2634e8b/NewGenericDiagram/PO01"
197 uri :: Variable -> <ReadGraph> String
201 Function **variableParent** returns the name of the parent variable as **Variable**
205 import "Simantics/Variables"
206 import "Apros/Module"
207 my_variable = moduleVariable "PO01"
208 variableParent my_variable
212 name (variableParent my_variable)
214 > "NewGenericDiagram"
217 variableParent :: Variable -> <ReadGraph> Variable
219 @JavaName getRepresents
222 Function **represents** returns the resource of the given input variable
224 **Input 1:** **Variable** which resource is wanted to be obtainend
226 **Output:** **Resource** of the given input variable.
228 Example: Find out the resource of given variable
230 import "Simantics/Variables"
231 import "Apros/Module"
232 represents (moduleVariable "PO01")
237 represents :: Variable -> <ReadGraph> Resource
239 @JavaName getPossibleRepresents
240 possibleRepresents :: Variable -> <ReadGraph> Maybe Resource
243 setValue :: Variable -> a -> <WriteGraph> ()
245 @JavaName setPropertyValue
246 setPropertyValue_ :: Variable -> String -> a -> Binding a -> <WriteGraph> ()
250 Function **getType** returns the type of the input variable as resource
254 import "Simantics/Variables"
255 import "Apros/Module"
256 getType (moduleVariable "PO01")
260 nameOf(getType (moduleVariable "PO01"))
264 getType :: Variable -> <ReadGraph> Resource
266 @JavaName getPossibleType
267 getPossibleType :: Variable -> <ReadGraph> Maybe Resource
269 getPredicateResource :: Variable -> <ReadGraph> Resource
271 getIndexRoot :: Variable -> <ReadGraph> Resource
273 value :: Serializable a => Typeable a => Variable -> <ReadGraph> a
274 value var = value_ var binding
276 possibleVariableValue :: Serializable a => Typeable a => Variable -> <ReadGraph> Maybe a
277 possibleVariableValue var = possibleVariableValue_ var binding
280 Function **propertyValue** finds the value of given property.
282 Example: Find out the value of point PO01 attribute PO11_PRESSURE
284 import "Simantics/Variables"
285 import "Apros/Module"
286 propertyValue (moduleVariable "PO01") "PO11_PRESSURE" :: Double
292 propertyValue :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> a
293 propertyValue var prop = propertyValue_ var prop binding
295 possiblePropertyValue :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> Maybe a
296 possiblePropertyValue var prop = possiblePropertyValue_ var prop binding
299 Function **setPropertyValue** sets wanted to value to given Variable property.
301 **Input 1:** Wanted module as **Variable**
303 **Input 2:** Wanted property name as **String**
305 **Output:** No output, given value is inserted to property
309 import "Simantics/Variables"
310 import "Apros/Module"
311 setPropertyValue (moduleVariable "PO01") "PO11_PRESSURE" 0.5
314 setPropertyValue :: Serializable a => Variable -> String -> a -> <WriteGraph> ()
315 setPropertyValue subject prediate value = setPropertyValue_ subject prediate value binding
318 Function **modelVariableOfVariable** returns the model, in which the given input Variable is located, as **Variable**
322 import "Simantics/Variables"
323 import "Apros/Module"
324 my_model_variable = modelVariableOfVariable (moduleVariable "PO01")
329 name my_model_variable
334 modelVariableOfVariable :: Variable -> <ReadGraph> Variable
335 modelVariableOfVariable var = variable $ uriOf $ modelOfVariable var
337 uniqueChild :: Model -> Resource -> String -> <ReadGraph> Variable
338 uniqueChild model typet childName = do
339 typeName = DB.nameOf typet
340 query = "Types: " + typeName + " AND Name: " + childName
341 moduleResources = searchByQuery model query
342 variable $ uriOf $ moduleResources ! 0
345 Function **properties** returns a list, which contains of the properties of the input variable as **Variable**
347 Example 1: print out all the properties of certain point as they are shown in Variable Debugger.
349 import "Simantics/Variables"
350 import "Apros/Module"
351 point_properties_list = properties (moduleVariable "PO01")
352 //print out the names of the properties
353 for point_properties_list (\x -> print(name x) )
355 > IncludedInSimulation
363 Example 2: print out only the properties of a point, which name starts as "PO11". Else do nothing.
365 import "Simantics/Variables"
366 import "Apros/Module"
367 point_properties_list = properties (moduleVariable "PO01")
368 for point_properties_list (\x -> do
369 //print out the names of the properties, which name start as "PO11"
370 if (take 4 (name x) == "PO11") then do
381 > PO11_NODE_VELOCITY_CALC
385 properties = collectionToList . properties_
387 instance Show Variable where
388 show _ = "<variable>"
390 instance Browsable Variable where
394 possibleNameOf v = Just (name v)
395 children v = collectionToList (children_ v)
396 parent = variableParent
397 possibleParent v = Just (variableParent v)
398 valueOf v = untypedValue v
399 variantValueOf v = createVariant (datatype v) (untypedValue v :: Dynamic)
401 possibleChild = possibleChild_
403 propertiesClassified :: Variable -> Resource -> <ReadGraph> [Variable]
404 propertiesClassified parent classified = do
405 collectionToList $ propertiesClassified_ parent classified