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.StructuredProperty" where
100 data StructuredProperty
102 importJava "org.simantics.db.layer0.variable.ResourceCollectionVariableMap" where
104 createVariableMap :: [Resource] -> VariableMap
106 importJava "org.simantics.db.layer0.variable.ValueAccessor" where
109 importJava "org.simantics.db.layer0.variable.Variable" where
113 rviOf :: Variable -> <ReadGraph> RVI
115 @JavaName getProperties
116 properties_ :: Variable -> <ReadGraph> Collection Variable
118 @JavaName getProperties
119 propertiesClassified_ :: Variable -> Resource -> <ReadGraph> Collection Variable
121 @JavaName getChildren
122 children_ :: Variable -> <ReadGraph> Collection Variable
125 value_ :: Variable -> Binding a -> <ReadGraph> a
127 @JavaName getDatatype
128 datatype :: Variable -> <ReadGraph> Datatype
131 untypedValue :: Variable -> <ReadGraph> a
133 @JavaName getPossibleValue
134 possibleVariableValue_ :: Variable -> Binding a -> <ReadGraph> Maybe a
136 @JavaName getPossibleValue
137 untypedPossibleVariableValue :: Variable -> <ReadGraph> Maybe a
141 child_ :: Variable -> String -> <ReadGraph> Variable
144 @JavaName getPossibleChild
145 possibleChild_ :: Variable -> String -> <ReadGraph> Maybe Variable
147 browse :: Variable -> String -> <ReadGraph> Variable
148 browsePossible :: Variable -> String -> <ReadGraph> Maybe Variable
150 @JavaName getProperty
152 Function **property** return the wanted property as **Variable**
154 **Input 1:** Module which property we want to obtain as **Variable**
156 **Input 2:** Name of the property as **String**
158 **Output:** wanted property as **Variable**
162 import "Simantics/Variables"
163 import "Apros/Module"
164 my_property_variable = property (moduleVariable "PO01") "PO11_PRESSURE"
169 property :: Variable -> String -> <ReadGraph> Variable
171 @JavaName getPossibleProperty
172 possibleProperty :: Variable -> String -> <ReadGraph> Maybe Variable
174 @JavaName getPropertyValue
175 propertyValue_ :: Variable -> String -> Binding a -> <ReadGraph> a
177 @JavaName getPropertyValue
178 untypedPropertyValue :: Variable -> String -> <ReadGraph> a
180 @JavaName getPossiblePropertyValue
181 possiblePropertyValue_ :: Variable -> String -> Binding a -> <ReadGraph> Maybe a
183 @JavaName getPossiblePropertyValue
184 untypedPossiblePropertyValue :: Variable -> String -> <ReadGraph> Maybe a
189 Function **name** return the name of the input variable as string
193 import "Simantics/Variables"
194 import "Apros/Module"
195 name (moduleVariable "PO01")
200 name :: Variable -> <ReadGraph> String
203 Function **uri** return the uri of given variable. The uri is fetched from the active **Experiment**
205 **Input 1:** wanted variable which uri is needed as **Variable**
207 **Output:** uri of the variable as **String**
211 import "Simantics/Variables"
212 import "Apros/Module"
213 uri (moduleVariable "PO01")
215 >"http://Projects/Development%20Project/Model/Experiment/8ee6b693-891b-438e-a597-9e15a2634e8b/NewGenericDiagram/PO01"
218 uri :: Variable -> <ReadGraph> String
222 Function **variableParent** returns the name of the parent variable as **Variable**
226 import "Simantics/Variables"
227 import "Apros/Module"
228 my_variable = moduleVariable "PO01"
229 variableParent my_variable
233 name (variableParent my_variable)
235 > "NewGenericDiagram"
238 variableParent :: Variable -> <ReadGraph> Variable
240 @JavaName getRepresents
243 Function **represents** returns the resource of the given input variable
245 **Input 1:** **Variable** which resource is wanted to be obtainend
247 **Output:** **Resource** of the given input variable.
249 Example: Find out the resource of given variable
251 import "Simantics/Variables"
252 import "Apros/Module"
253 represents (moduleVariable "PO01")
258 represents :: Variable -> <ReadGraph> Resource
260 @JavaName getPossibleRepresents
261 possibleRepresents :: Variable -> <ReadGraph> Maybe Resource
264 setValue :: Variable -> a -> <WriteGraph> ()
266 @JavaName setPropertyValue
267 setPropertyValue_ :: Variable -> String -> a -> Binding a -> <WriteGraph> ()
271 Function **getType** returns the type of the input variable as resource
275 import "Simantics/Variables"
276 import "Apros/Module"
277 getType (moduleVariable "PO01")
281 nameOf(getType (moduleVariable "PO01"))
285 getType :: Variable -> <ReadGraph> Resource
287 @JavaName getPossibleType
288 getPossibleType :: Variable -> <ReadGraph> Maybe Resource
290 getPredicateResource :: Variable -> <ReadGraph> Resource
292 getIndexRoot :: Variable -> <ReadGraph> Resource
294 value :: Serializable a => Typeable a => Variable -> <ReadGraph> a
295 value var = value_ var binding
297 possibleVariableValue :: Serializable a => Typeable a => Variable -> <ReadGraph> Maybe a
298 possibleVariableValue var = possibleVariableValue_ var binding
301 Function **propertyValue** finds the value of given property.
303 Example: Find out the value of point PO01 attribute PO11_PRESSURE
305 import "Simantics/Variables"
306 import "Apros/Module"
307 propertyValue (moduleVariable "PO01") "PO11_PRESSURE" :: Double
313 propertyValue :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> a
314 propertyValue var prop = propertyValue_ var prop binding
316 possiblePropertyValue :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> Maybe a
317 possiblePropertyValue var prop = possiblePropertyValue_ var prop binding
320 Function **setPropertyValue** sets wanted to value to given Variable property.
322 **Input 1:** Wanted module as **Variable**
324 **Input 2:** Wanted property name as **String**
326 **Output:** No output, given value is inserted to property
330 import "Simantics/Variables"
331 import "Apros/Module"
332 setPropertyValue (moduleVariable "PO01") "PO11_PRESSURE" 0.5
335 setPropertyValue :: Serializable a => Variable -> String -> a -> <WriteGraph> ()
336 setPropertyValue subject prediate value = setPropertyValue_ subject prediate value binding
339 Function **modelVariableOfVariable** returns the model, in which the given input Variable is located, as **Variable**
343 import "Simantics/Variables"
344 import "Apros/Module"
345 my_model_variable = modelVariableOfVariable (moduleVariable "PO01")
350 name my_model_variable
355 modelVariableOfVariable :: Variable -> <ReadGraph> Variable
356 modelVariableOfVariable var = variable $ uriOf $ modelOfVariable var
358 uniqueChild :: Model -> Resource -> String -> <ReadGraph> Variable
359 uniqueChild model typet childName = do
360 typeName = DB.nameOf typet
361 query = "Types: " + typeName + " AND Name: " + childName
362 moduleResources = searchByQuery model query
363 variable $ uriOf $ moduleResources ! 0
366 Function **properties** returns a list, which contains of the properties of the input variable as **Variable**
368 Example 1: print out all the properties of certain point as they are shown in Variable Debugger.
370 import "Simantics/Variables"
371 import "Apros/Module"
372 point_properties_list = properties (moduleVariable "PO01")
373 //print out the names of the properties
374 for point_properties_list (\x -> print(name x) )
376 > IncludedInSimulation
384 Example 2: print out only the properties of a point, which name starts as "PO11". Else do nothing.
386 import "Simantics/Variables"
387 import "Apros/Module"
388 point_properties_list = properties (moduleVariable "PO01")
389 for point_properties_list (\x -> do
390 //print out the names of the properties, which name start as "PO11"
391 if (take 4 (name x) == "PO11") then do
402 > PO11_NODE_VELOCITY_CALC
406 properties = collectionToList . properties_
408 instance Show Variable where
409 show _ = "<variable>"
411 instance Browsable Variable where
414 possibleUriOf v = Just (uri v)
416 possibleNameOf v = Just (name v)
417 children v = collectionToList (children_ v)
418 parent = variableParent
419 possibleParent v = Just (variableParent v)
420 valueOf v = untypedValue v
421 variantValueOf v = createVariant (datatype v) (untypedValue v :: Dynamic)
423 possibleChild = possibleChild_
425 genericRelatedValue v rel = untypedPropertyValue v (nameOf rel)
426 genericPossibleRelatedValue v rel = untypedPossiblePropertyValue v (nameOf rel)
428 propertiesClassified :: Variable -> Resource -> <ReadGraph> [Variable]
429 propertiesClassified parent classified = do
430 collectionToList $ propertiesClassified_ parent classified
432 importJava "org.simantics.db.layer0.variable.RVI" where
435 resolvePossible :: RVI -> Variable -> <ReadGraph> Maybe Variable
437 instantiateUnder :: Resource -> Resource -> <WriteGraph> Resource
438 instantiateUnder container typeToInstantiate = do
439 fn = (resourceVariable typeToInstantiate)#methods#instantiateUnder :: Resource -> Resource -> <WriteGraph> Resource
440 fn container typeToInstantiate