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