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
24 @JavaName getPossibleVariable
25 possibleResourceVariable :: Resource -> <ReadGraph> Maybe Variable
27 @JavaName getPossibleVariable
28 possibleVariable :: String -> <ReadGraph> Maybe Variable
32 Function **resourceVariable** converts a resource to a corresponding variable.
36 import "Simantics/Variables"
38 model_id = model "Model"
39 my_resource = getComponent model_id "PO01"
40 my_variable = resourceVariable my_resource
45 resourceVariable :: Resource -> <ReadGraph> Variable
49 Function **modelOfVariable** returns the model, in which the given input variable is located, as **Resource**
53 import "Simantics/Variables"
55 my_variable = moduleVariable "PO01"
56 my_model = modelOfVariable my_variable
61 // use function nameOf, which works for resources, to print out the name of the model
67 modelOfVariable :: Variable -> <ReadGraph> Model
70 modelResourceOfVariable :: Variable -> <ReadGraph> Resource
72 @JavaName possibleActiveVariable
73 possibleActiveVariable :: Variable -> <ReadGraph> Maybe Variable
75 @JavaName switchPossibleContext
76 switchPossibleContext :: Variable -> Resource -> <ReadGraph> Maybe Variable
78 @JavaName getIndexRoot
79 instanceIndexRoot :: Variable -> <ReadGraph> Resource
81 createValueAccessor :: (Variable -> <ReadGraph> a) -> (Variable -> Binding b -> <ReadGraph> b) -> (Variable -> c -> <WriteGraph> ()) -> (Variable -> d -> Binding d -> <WriteGraph> ()) -> (Variable -> <ReadGraph> Datatype) -> ValueAccessor
83 @JavaName getConfigurationContext
84 possibleConfigurationContext :: Resource -> <ReadGraph> Variable
86 setRVIProperty :: Variable -> RVI -> <WriteGraph> ()
88 importJava "org.simantics.db.layer0.function.All" where
90 standardGetValue1 :: Variable -> <ReadGraph> a
91 standardGetValue2 :: Variable -> Binding a -> <ReadGraph> a
92 standardSetValue2 :: Variable -> a -> <WriteGraph> ()
93 standardSetValue3 :: Variable -> a -> Binding a -> <WriteGraph> ()
94 standardGetDatatype :: Variable -> <ReadGraph> Datatype
96 importJava "org.simantics.db.layer0.variable.VariableMap" where
99 importJava "org.simantics.db.layer0.variable.ResourceCollectionVariableMap" where
101 createVariableMap :: [Resource] -> VariableMap
103 importJava "org.simantics.db.layer0.variable.ValueAccessor" where
106 importJava "org.simantics.db.layer0.variable.Variable" where
110 rviOf :: Variable -> <ReadGraph> RVI
112 @JavaName getProperties
113 properties_ :: Variable -> <ReadGraph> Collection Variable
115 @JavaName getProperties
116 propertiesClassified_ :: Variable -> Resource -> <ReadGraph> Collection Variable
118 @JavaName getChildren
119 children_ :: Variable -> <ReadGraph> Collection Variable
122 value_ :: Variable -> Binding a -> <ReadGraph> a
124 @JavaName getDatatype
125 datatype :: Variable -> <ReadGraph> Datatype
128 untypedValue :: Variable -> <ReadGraph> a
130 @JavaName getPossibleValue
131 possibleVariableValue_ :: Variable -> Binding a -> <ReadGraph> Maybe a
133 @JavaName getPossibleValue
134 untypedPossibleVariableValue :: Variable -> <ReadGraph> Maybe a
138 child_ :: Variable -> String -> <ReadGraph> Variable
141 @JavaName getPossibleChild
142 possibleChild_ :: Variable -> String -> <ReadGraph> Maybe Variable
144 browse :: Variable -> String -> <ReadGraph> Variable
145 browsePossible :: Variable -> String -> <ReadGraph> Maybe Variable
147 @JavaName getProperty
149 Function **property** return the wanted property as **Variable**
151 **Input 1:** Module which property we want to obtain as **Variable**
153 **Input 2:** Name of the property as **String**
155 **Output:** wanted property as **Variable**
159 import "Simantics/Variables"
160 import "Apros/Module"
161 my_property_variable = property (moduleVariable "PO01") "PO11_PRESSURE"
166 property :: Variable -> String -> <ReadGraph> Variable
168 @JavaName getPossibleProperty
169 possibleProperty :: Variable -> String -> <ReadGraph> Maybe Variable
171 @JavaName getPropertyValue
172 propertyValue_ :: Variable -> String -> Binding a -> <ReadGraph> a
174 @JavaName getPropertyValue
175 untypedPropertyValue :: Variable -> String -> <ReadGraph> a
177 @JavaName getPossiblePropertyValue
178 possiblePropertyValue_ :: Variable -> String -> Binding a -> <ReadGraph> Maybe a
180 @JavaName getPossiblePropertyValue
181 untypedPossiblePropertyValue :: Variable -> String -> <ReadGraph> Maybe a
186 Function **name** return the name of the input variable as string
190 import "Simantics/Variables"
191 import "Apros/Module"
192 name (moduleVariable "PO01")
197 name :: Variable -> <ReadGraph> String
200 Function **uri** return the uri of given variable. The uri is fetched from the active **Experiment**
202 **Input 1:** wanted variable which uri is needed as **Variable**
204 **Output:** uri of the variable as **String**
208 import "Simantics/Variables"
209 import "Apros/Module"
210 uri (moduleVariable "PO01")
212 >"http://Projects/Development%20Project/Model/Experiment/8ee6b693-891b-438e-a597-9e15a2634e8b/NewGenericDiagram/PO01"
215 uri :: Variable -> <ReadGraph> String
219 Function **variableParent** returns the name of the parent variable as **Variable**
223 import "Simantics/Variables"
224 import "Apros/Module"
225 my_variable = moduleVariable "PO01"
226 variableParent my_variable
230 name (variableParent my_variable)
232 > "NewGenericDiagram"
235 variableParent :: Variable -> <ReadGraph> Variable
237 @JavaName getRepresents
240 Function **represents** returns the resource of the given input variable
242 **Input 1:** **Variable** which resource is wanted to be obtainend
244 **Output:** **Resource** of the given input variable.
246 Example: Find out the resource of given variable
248 import "Simantics/Variables"
249 import "Apros/Module"
250 represents (moduleVariable "PO01")
255 represents :: Variable -> <ReadGraph> Resource
257 @JavaName getPossibleRepresents
258 possibleRepresents :: Variable -> <ReadGraph> Maybe Resource
261 setValue :: Variable -> a -> <WriteGraph> ()
263 @JavaName setPropertyValue
264 setPropertyValue_ :: Variable -> String -> a -> Binding a -> <WriteGraph> ()
268 Function **getType** returns the type of the input variable as resource
272 import "Simantics/Variables"
273 import "Apros/Module"
274 getType (moduleVariable "PO01")
278 nameOf(getType (moduleVariable "PO01"))
282 getType :: Variable -> <ReadGraph> Resource
284 @JavaName getPossibleType
285 getPossibleType :: Variable -> <ReadGraph> Maybe Resource
287 getPredicateResource :: Variable -> <ReadGraph> Resource
289 getIndexRoot :: Variable -> <ReadGraph> Resource
291 value :: Serializable a => Typeable a => Variable -> <ReadGraph> a
292 value var = value_ var binding
294 possibleVariableValue :: Serializable a => Typeable a => Variable -> <ReadGraph> Maybe a
295 possibleVariableValue var = possibleVariableValue_ var binding
298 Function **propertyValue** finds the value of given property.
300 Example: Find out the value of point PO01 attribute PO11_PRESSURE
302 import "Simantics/Variables"
303 import "Apros/Module"
304 propertyValue (moduleVariable "PO01") "PO11_PRESSURE" :: Double
310 propertyValue :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> a
311 propertyValue var prop = propertyValue_ var prop binding
313 possiblePropertyValue :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> Maybe a
314 possiblePropertyValue var prop = possiblePropertyValue_ var prop binding
317 Function **setPropertyValue** sets wanted to value to given Variable property.
319 **Input 1:** Wanted module as **Variable**
321 **Input 2:** Wanted property name as **String**
323 **Output:** No output, given value is inserted to property
327 import "Simantics/Variables"
328 import "Apros/Module"
329 setPropertyValue (moduleVariable "PO01") "PO11_PRESSURE" 0.5
332 setPropertyValue :: Serializable a => Variable -> String -> a -> <WriteGraph> ()
333 setPropertyValue subject prediate value = setPropertyValue_ subject prediate value binding
336 Function **modelVariableOfVariable** returns the model, in which the given input Variable is located, as **Variable**
340 import "Simantics/Variables"
341 import "Apros/Module"
342 my_model_variable = modelVariableOfVariable (moduleVariable "PO01")
347 name my_model_variable
352 modelVariableOfVariable :: Variable -> <ReadGraph> Variable
353 modelVariableOfVariable var = variable $ uriOf $ modelOfVariable var
355 uniqueChild :: Model -> Resource -> String -> <ReadGraph> Variable
356 uniqueChild model typet childName = do
357 typeName = DB.nameOf typet
358 query = "Types: " + typeName + " AND Name: " + childName
359 moduleResources = searchByQuery model query
360 variable $ uriOf $ moduleResources ! 0
363 Function **properties** returns a list, which contains of the properties of the input variable as **Variable**
365 Example 1: print out all the properties of certain point as they are shown in Variable Debugger.
367 import "Simantics/Variables"
368 import "Apros/Module"
369 point_properties_list = properties (moduleVariable "PO01")
370 //print out the names of the properties
371 for point_properties_list (\x -> print(name x) )
373 > IncludedInSimulation
381 Example 2: print out only the properties of a point, which name starts as "PO11". Else do nothing.
383 import "Simantics/Variables"
384 import "Apros/Module"
385 point_properties_list = properties (moduleVariable "PO01")
386 for point_properties_list (\x -> do
387 //print out the names of the properties, which name start as "PO11"
388 if (take 4 (name x) == "PO11") then do
399 > PO11_NODE_VELOCITY_CALC
403 properties = collectionToList . properties_
405 instance Show Variable where
406 show _ = "<variable>"
408 instance Browsable Variable where
411 possibleUriOf v = Just (uri v)
413 possibleNameOf v = Just (name v)
414 children v = collectionToList (children_ v)
415 parent = variableParent
416 possibleParent v = Just (variableParent v)
417 valueOf v = untypedValue v
418 variantValueOf v = createVariant (datatype v) (untypedValue v :: Dynamic)
420 possibleChild = possibleChild_
422 propertiesClassified :: Variable -> Resource -> <ReadGraph> [Variable]
423 propertiesClassified parent classified = do
424 collectionToList $ propertiesClassified_ parent classified
426 importJava "org.simantics.db.layer0.variable.RVI" where
429 resolvePossible :: RVI -> Variable -> <ReadGraph> Maybe Variable
431 instantiateUnder :: Resource -> Resource -> <WriteGraph> Resource
432 instantiateUnder container typeToInstantiate = do
433 fn = (resourceVariable typeToInstantiate)#methods#instantiateUnder :: Resource -> Resource -> <WriteGraph> Resource
434 fn container typeToInstantiate