1 include "Simantics/Model"
\r
2 include "Simantics/DB"
\r
3 import "Simantics/DB" as DB
\r
5 importJava "java.lang.Object" where
\r
8 Function **variableEquals** compares the given input variables and returns True if they are the same.
\r
12 import "Simantics/Variables"
\r
13 import "Apros/Module"
\r
14 my_variable_1 = moduleVariable "PO01"
\r
15 my_variable_2 = moduleVariable "PO02"
\r
16 variableEquals my_variable_1 my_variable_2
\r
21 variableEquals :: Variable -> Variable -> Boolean
\r
23 variableHash :: Variable -> Integer
\r
25 instance Eq Variable where
\r
26 (==) = variableEquals
\r
28 instance Hashable Variable where
\r
29 hashP = hashP . variableHash
\r
31 importJava "org.simantics.db.layer0.variable.Variables" where
\r
32 @JavaName getVariable
\r
34 Function **variable** converts a variable URI to a variable.
\r
38 import "Simantics/Variables"
\r
39 import "Apros/Module"
\r
40 model_id = model "Model"
\r
41 my_component = getComponent model_id "PO01"
\r
42 my_uri = uriOf my_component
\r
43 my_variable = variable my_uri
\r
48 variable :: String -> <ReadGraph> Variable
\r
50 @JavaName getVariable
\r
52 Function **resourceVariable** converts a resource to a corresponding variable.
\r
56 import "Simantics/Variables"
\r
57 import "Apros/Module"
\r
58 model_id = model "Model"
\r
59 my_resource = getComponent model_id "PO01"
\r
60 my_variable = resourceVariable my_resource
\r
65 resourceVariable :: Resource -> <ReadGraph> Variable
\r
69 Function **modelOfVariable** returns the model, in which the given input variable is located, as **Resource**
\r
73 import "Simantics/Variables"
\r
74 import "Apros/Module"
\r
75 my_variable = moduleVariable "PO01"
\r
76 my_model = modelOfVariable my_variable
\r
81 // use function nameOf, which works for resources, to print out the name of the model
\r
87 modelOfVariable :: Variable -> <ReadGraph> Model
\r
90 modelResourceOfVariable :: Variable -> <ReadGraph> Resource
\r
92 @JavaName possibleActiveVariable
\r
93 possibleActiveVariable :: Variable -> <ReadGraph> Maybe Variable
\r
95 @JavaName switchPossibleContext
\r
96 switchPossibleContext :: Variable -> Resource -> <ReadGraph> Maybe Variable
\r
98 @JavaName getIndexRoot
\r
99 instanceIndexRoot :: Variable -> <ReadGraph> Resource
\r
101 createValueAccessor :: (Variable -> <ReadGraph> a) -> (Variable -> Binding b -> <ReadGraph> b) -> (Variable -> c -> <WriteGraph> ()) -> (Variable -> d -> Binding d -> <WriteGraph> ()) -> (Variable -> <ReadGraph> Datatype) -> ValueAccessor
\r
103 importJava "org.simantics.db.layer0.function.All" where
\r
105 standardGetValue1 :: Variable -> <ReadGraph> a
\r
106 standardGetValue2 :: Variable -> Binding a -> <ReadGraph> a
\r
107 standardSetValue2 :: Variable -> a -> <WriteGraph> ()
\r
108 standardSetValue3 :: Variable -> a -> Binding a -> <WriteGraph> ()
\r
109 standardGetDatatype :: Variable -> <ReadGraph> Datatype
\r
111 importJava "org.simantics.db.layer0.variable.VariableMap" where
\r
114 importJava "org.simantics.db.layer0.variable.ValueAccessor" where
\r
117 importJava "org.simantics.db.layer0.variable.Variable" where
\r
120 @JavaName getProperties
\r
121 properties_ :: Variable -> <ReadGraph> Collection Variable
\r
123 @JavaName getProperties
\r
124 propertiesClassified_ :: Variable -> Resource -> <ReadGraph> Collection Variable
\r
126 @JavaName getChildren
\r
127 children_ :: Variable -> <ReadGraph> Collection Variable
\r
130 value_ :: Variable -> Binding a -> <ReadGraph> a
\r
132 @JavaName getDatatype
\r
133 datatype :: Variable -> <ReadGraph> Datatype
\r
136 untypedValue :: Variable -> <ReadGraph> a
\r
138 @JavaName getPossibleValue
\r
139 possibleVariableValue_ :: Variable -> Binding a -> <ReadGraph> Maybe a
\r
141 @JavaName getPossibleValue
\r
142 untypedPossibleVariableValue :: Variable -> <ReadGraph> Maybe a
\r
146 child_ :: Variable -> String -> <ReadGraph> Variable
\r
149 @JavaName getPossibleChild
\r
150 possibleChild_ :: Variable -> String -> <ReadGraph> Maybe Variable
\r
152 browse :: Variable -> String -> <ReadGraph> Variable
\r
153 browsePossible :: Variable -> String -> <ReadGraph> Maybe Variable
\r
155 @JavaName getProperty
\r
157 Function **property** return the wanted property as **Variable**
\r
159 **Input 1:** Module which property we want to obtain as **Variable**
\r
161 **Input 2:** Name of the property as **String**
\r
163 **Output:** wanted property as **Variable**
\r
167 import "Simantics/Variables"
\r
168 import "Apros/Module"
\r
169 my_property_variable = property (moduleVariable "PO01") "PO11_PRESSURE"
\r
170 my_property_variable
\r
174 property :: Variable -> String -> <ReadGraph> Variable
\r
176 @JavaName getPossibleProperty
\r
177 possibleProperty :: Variable -> String -> <ReadGraph> Maybe Variable
\r
179 @JavaName getPropertyValue
\r
180 propertyValue_ :: Variable -> String -> Binding a -> <ReadGraph> a
\r
182 @JavaName getPropertyValue
\r
183 untypedPropertyValue :: Variable -> String -> <ReadGraph> a
\r
185 @JavaName getPossiblePropertyValue
\r
186 possiblePropertyValue_ :: Variable -> String -> Binding a -> <ReadGraph> Maybe a
\r
188 @JavaName getPossiblePropertyValue
\r
189 untypedPossiblePropertyValue :: Variable -> String -> <ReadGraph> Maybe a
\r
194 Function **name** return the name of the input variable as string
\r
198 import "Simantics/Variables"
\r
199 import "Apros/Module"
\r
200 name (moduleVariable "PO01")
\r
205 name :: Variable -> <ReadGraph> String
\r
208 Function **uri** return the uri of given variable. The uri is fetched from the active **Experiment**
\r
210 **Input 1:** wanted variable which uri is needed as **Variable**
\r
212 **Output:** uri of the variable as **String**
\r
216 import "Simantics/Variables"
\r
217 import "Apros/Module"
\r
218 uri (moduleVariable "PO01")
\r
220 >"http://Projects/Development%20Project/Model/Experiment/8ee6b693-891b-438e-a597-9e15a2634e8b/NewGenericDiagram/PO01"
\r
223 uri :: Variable -> <ReadGraph> String
\r
225 @JavaName getParent
\r
227 Function **variableParent** returns the name of the parent variable as **Variable**
\r
231 import "Simantics/Variables"
\r
232 import "Apros/Module"
\r
233 my_variable = moduleVariable "PO01"
\r
234 variableParent my_variable
\r
238 name (variableParent my_variable)
\r
240 > "NewGenericDiagram"
\r
243 variableParent :: Variable -> <ReadGraph> Variable
\r
245 @JavaName getRepresents
\r
248 Function **represents** returns the resource of the given input variable
\r
250 **Input 1:** **Variable** which resource is wanted to be obtainend
\r
252 **Output:** **Resource** of the given input variable.
\r
254 Example: Find out the resource of given variable
\r
256 import "Simantics/Variables"
\r
257 import "Apros/Module"
\r
258 represents (moduleVariable "PO01")
\r
263 represents :: Variable -> <ReadGraph> Resource
\r
265 @JavaName getPossibleRepresents
\r
266 possibleRepresents :: Variable -> <ReadGraph> Maybe Resource
\r
269 setValue :: Variable -> a -> <WriteGraph> ()
\r
271 @JavaName setPropertyValue
\r
272 setPropertyValue_ :: Variable -> String -> a -> Binding a -> <WriteGraph> ()
\r
276 Function **getType** returns the type of the input variable as resource
\r
280 import "Simantics/Variables"
\r
281 import "Apros/Module"
\r
282 getType (moduleVariable "PO01")
\r
286 nameOf(getType (moduleVariable "PO01"))
\r
290 getType :: Variable -> <ReadGraph> Resource
\r
292 @JavaName getPossibleType
\r
293 getPossibleType :: Variable -> <ReadGraph> Maybe Resource
\r
295 getPredicateResource :: Variable -> <ReadGraph> Resource
\r
297 getIndexRoot :: Variable -> <ReadGraph> Resource
\r
299 value :: Serializable a => Typeable a => Variable -> <ReadGraph> a
\r
300 value var = value_ var binding
\r
302 possibleVariableValue :: Serializable a => Typeable a => Variable -> <ReadGraph> Maybe a
\r
303 possibleVariableValue var = possibleVariableValue_ var binding
\r
306 Function **propertyValue** finds the value of given property.
\r
308 Example: Find out the value of point PO01 attribute PO11_PRESSURE
\r
310 import "Simantics/Variables"
\r
311 import "Apros/Module"
\r
312 propertyValue (moduleVariable "PO01") "PO11_PRESSURE" :: Double
\r
318 propertyValue :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> a
\r
319 propertyValue var prop = propertyValue_ var prop binding
\r
321 possiblePropertyValue :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> Maybe a
\r
322 possiblePropertyValue var prop = possiblePropertyValue_ var prop binding
\r
325 Function **setPropertyValue** sets wanted to value to given Variable property.
\r
327 **Input 1:** Wanted module as **Variable**
\r
329 **Input 2:** Wanted property name as **String**
\r
331 **Output:** No output, given value is inserted to property
\r
335 import "Simantics/Variables"
\r
336 import "Apros/Module"
\r
337 setPropertyValue (moduleVariable "PO01") "PO11_PRESSURE" 0.5
\r
340 setPropertyValue :: Serializable a => Variable -> String -> a -> <WriteGraph> ()
\r
341 setPropertyValue subject prediate value = setPropertyValue_ subject prediate value binding
\r
344 Function **modelVariableOfVariable** returns the model, in which the given input Variable is located, as **Variable**
\r
348 import "Simantics/Variables"
\r
349 import "Apros/Module"
\r
350 my_model_variable = modelVariableOfVariable (moduleVariable "PO01")
\r
355 name my_model_variable
\r
360 modelVariableOfVariable :: Variable -> <ReadGraph> Variable
\r
361 modelVariableOfVariable var = variable $ uriOf $ toResource $ modelOfVariable var
\r
363 uniqueChild :: Model -> Resource -> String -> <ReadGraph> Variable
\r
364 uniqueChild model typet childName = do
\r
365 typeName = DB.nameOf typet
\r
366 query = "Types: " + typeName + " AND Name: " + childName
\r
367 moduleResources = searchByQuery (toResource model) query
\r
368 variable $ uriOf $ moduleResources ! 0
\r
371 Function **properties** returns a list, which contains of the properties of the input variable as **Variable**
\r
373 Example 1: print out all the properties of certain point as they are shown in Variable Debugger.
\r
375 import "Simantics/Variables"
\r
376 import "Apros/Module"
\r
377 point_properties_list = properties (moduleVariable "PO01")
\r
378 //print out the names of the properties
\r
379 for point_properties_list (\x -> print(name x) )
\r
381 > IncludedInSimulation
\r
384 > PO11_PROPERTY_CALC
\r
386 > PO11_ELEV_FROM_BOT
\r
389 Example 2: print out only the properties of a point, which name starts as "PO11". Else do nothing.
\r
391 import "Simantics/Variables"
\r
392 import "Apros/Module"
\r
393 point_properties_list = properties (moduleVariable "PO01")
\r
394 for point_properties_list (\x -> do
\r
395 //print out the names of the properties, which name start as "PO11"
\r
396 if (take 4 (name x) == "PO11") then do
\r
404 > PO11_PROPERTY_CALC
\r
406 > PO11_ELEV_FROM_BOT
\r
407 > PO11_NODE_VELOCITY_CALC
\r
411 properties = collectionToList . properties_
\r
413 instance Show Variable where
\r
414 show _ = "<variable>"
\r
416 instance Browsable Variable where
\r
420 possibleNameOf v = Just (name v)
\r
421 children v = collectionToList (children_ v)
\r
422 parent = variableParent
\r
423 possibleParent v = Just (variableParent v)
\r
424 valueOf v = untypedValue v
\r
425 variantValueOf v = createVariant (datatype v) (untypedValue v :: Dynamic)
\r
427 possibleChild = possibleChild_
\r
429 propertiesClassified :: Variable -> Resource -> <ReadGraph> [Variable]
\r
430 propertiesClassified parent classified = do
\r
431 collectionToList $ propertiesClassified_ parent classified