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
122 @JavaName getChildren
\r
123 children_ :: Variable -> <ReadGraph> Collection Variable
\r
126 value_ :: Variable -> Binding a -> <ReadGraph> a
\r
128 @JavaName getDatatype
\r
129 datatype :: Variable -> <ReadGraph> Datatype
\r
132 untypedValue :: Variable -> <ReadGraph> a
\r
134 @JavaName getPossibleValue
\r
135 possibleVariableValue_ :: Variable -> Binding a -> <ReadGraph> Maybe a
\r
137 @JavaName getPossibleValue
\r
138 untypedPossibleVariableValue :: Variable -> <ReadGraph> Maybe a
\r
142 child_ :: Variable -> String -> <ReadGraph> Variable
\r
145 @JavaName getPossibleChild
\r
146 possibleChild_ :: Variable -> String -> <ReadGraph> Maybe Variable
\r
148 browse :: Variable -> String -> <ReadGraph> Variable
\r
149 browsePossible :: Variable -> String -> <ReadGraph> Maybe Variable
\r
151 @JavaName getProperty
\r
153 Function **property** return the wanted property as **Variable**
\r
155 **Input 1:** Module which property we want to obtain as **Variable**
\r
157 **Input 2:** Name of the property as **String**
\r
159 **Output:** wanted property as **Variable**
\r
163 import "Simantics/Variables"
\r
164 import "Apros/Module"
\r
165 my_property_variable = property (moduleVariable "PO01") "PO11_PRESSURE"
\r
166 my_property_variable
\r
170 property :: Variable -> String -> <ReadGraph> Variable
\r
172 @JavaName getPossibleProperty
\r
173 possibleProperty :: Variable -> String -> <ReadGraph> Maybe Variable
\r
175 @JavaName getPropertyValue
\r
176 propertyValue_ :: Variable -> String -> Binding a -> <ReadGraph> a
\r
178 @JavaName getPropertyValue
\r
179 untypedPropertyValue :: Variable -> String -> <ReadGraph> a
\r
181 @JavaName getPossiblePropertyValue
\r
182 possiblePropertyValue_ :: Variable -> String -> Binding a -> <ReadGraph> Maybe a
\r
184 @JavaName getPossiblePropertyValue
\r
185 untypedPossiblePropertyValue :: Variable -> String -> <ReadGraph> Maybe a
\r
190 Function **name** return the name of the input variable as string
\r
194 import "Simantics/Variables"
\r
195 import "Apros/Module"
\r
196 name (moduleVariable "PO01")
\r
201 name :: Variable -> <ReadGraph> String
\r
204 Function **uri** return the uri of given variable. The uri is fetched from the active **Experiment**
\r
206 **Input 1:** wanted variable which uri is needed as **Variable**
\r
208 **Output:** uri of the variable as **String**
\r
212 import "Simantics/Variables"
\r
213 import "Apros/Module"
\r
214 uri (moduleVariable "PO01")
\r
216 >"http://Projects/Development%20Project/Model/Experiment/8ee6b693-891b-438e-a597-9e15a2634e8b/NewGenericDiagram/PO01"
\r
219 uri :: Variable -> <ReadGraph> String
\r
221 @JavaName getParent
\r
223 Function **variableParent** returns the name of the parent variable as **Variable**
\r
227 import "Simantics/Variables"
\r
228 import "Apros/Module"
\r
229 my_variable = moduleVariable "PO01"
\r
230 variableParent my_variable
\r
234 name (variableParent my_variable)
\r
236 > "NewGenericDiagram"
\r
239 variableParent :: Variable -> <ReadGraph> Variable
\r
241 @JavaName getRepresents
\r
244 Function **represents** returns the resource of the given input variable
\r
246 **Input 1:** **Variable** which resource is wanted to be obtainend
\r
248 **Output:** **Resource** of the given input variable.
\r
250 Example: Find out the resource of given variable
\r
252 import "Simantics/Variables"
\r
253 import "Apros/Module"
\r
254 represents (moduleVariable "PO01")
\r
259 represents :: Variable -> <ReadGraph> Resource
\r
261 @JavaName getPossibleRepresents
\r
262 possibleRepresents :: Variable -> <ReadGraph> Maybe Resource
\r
265 setValue :: Variable -> a -> <WriteGraph> ()
\r
267 @JavaName setPropertyValue
\r
268 setPropertyValue_ :: Variable -> String -> a -> Binding a -> <WriteGraph> ()
\r
272 Function **getType** returns the type of the input variable as resource
\r
276 import "Simantics/Variables"
\r
277 import "Apros/Module"
\r
278 getType (moduleVariable "PO01")
\r
282 nameOf(getType (moduleVariable "PO01"))
\r
286 getType :: Variable -> <ReadGraph> Resource
\r
288 @JavaName getPossibleType
\r
289 getPossibleType :: Variable -> <ReadGraph> Maybe Resource
\r
291 getPredicateResource :: Variable -> <ReadGraph> Resource
\r
293 getIndexRoot :: Variable -> <ReadGraph> Resource
\r
295 value :: Serializable a => Typeable a => Variable -> <ReadGraph> a
\r
296 value var = value_ var binding
\r
298 possibleVariableValue :: Serializable a => Typeable a => Variable -> <ReadGraph> Maybe a
\r
299 possibleVariableValue var = possibleVariableValue_ var binding
\r
302 Function **propertyValue** finds the value of given property.
\r
304 Example: Find out the value of point PO01 attribute PO11_PRESSURE
\r
306 import "Simantics/Variables"
\r
307 import "Apros/Module"
\r
308 propertyValue (moduleVariable "PO01") "PO11_PRESSURE" :: Double
\r
314 propertyValue :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> a
\r
315 propertyValue var prop = propertyValue_ var prop binding
\r
317 possiblePropertyValue :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> Maybe a
\r
318 possiblePropertyValue var prop = possiblePropertyValue_ var prop binding
\r
321 Function **setPropertyValue** sets wanted to value to given Variable property.
\r
323 **Input 1:** Wanted module as **Variable**
\r
325 **Input 2:** Wanted property name as **String**
\r
327 **Output:** No output, given value is inserted to property
\r
331 import "Simantics/Variables"
\r
332 import "Apros/Module"
\r
333 setPropertyValue (moduleVariable "PO01") "PO11_PRESSURE" 0.5
\r
336 setPropertyValue :: Serializable a => Variable -> String -> a -> <WriteGraph> ()
\r
337 setPropertyValue subject prediate value = setPropertyValue_ subject prediate value binding
\r
340 Function **modelVariableOfVariable** returns the model, in which the given input Variable is located, as **Variable**
\r
344 import "Simantics/Variables"
\r
345 import "Apros/Module"
\r
346 my_model_variable = modelVariableOfVariable (moduleVariable "PO01")
\r
351 name my_model_variable
\r
356 modelVariableOfVariable :: Variable -> <ReadGraph> Variable
\r
357 modelVariableOfVariable var = variable $ uriOf $ toResource $ modelOfVariable var
\r
359 uniqueChild :: Model -> Resource -> String -> <ReadGraph> Variable
\r
360 uniqueChild model typet childName = do
\r
361 typeName = DB.nameOf typet
\r
362 query = "Types: " + typeName + " AND Name: " + childName
\r
363 moduleResources = searchByQuery (toResource model) query
\r
364 variable $ uriOf $ moduleResources ! 0
\r
367 Function **properties** returns a list, which contains of the properties of the input variable as **Variable**
\r
369 Example 1: print out all the properties of certain point as they are shown in Variable Debugger.
\r
371 import "Simantics/Variables"
\r
372 import "Apros/Module"
\r
373 point_properties_list = properties (moduleVariable "PO01")
\r
374 //print out the names of the properties
\r
375 for point_properties_list (\x -> print(name x) )
\r
377 > IncludedInSimulation
\r
380 > PO11_PROPERTY_CALC
\r
382 > PO11_ELEV_FROM_BOT
\r
385 Example 2: print out only the properties of a point, which name starts as "PO11". Else do nothing.
\r
387 import "Simantics/Variables"
\r
388 import "Apros/Module"
\r
389 point_properties_list = properties (moduleVariable "PO01")
\r
390 for point_properties_list (\x -> do
\r
391 //print out the names of the properties, which name start as "PO11"
\r
392 if (take 4 (name x) == "PO11") then do
\r
400 > PO11_PROPERTY_CALC
\r
402 > PO11_ELEV_FROM_BOT
\r
403 > PO11_NODE_VELOCITY_CALC
\r
407 properties = collectionToList . properties_
\r
409 instance Show Variable where
\r
410 show _ = "<variable>"
\r
412 instance Browsable Variable where
\r
416 possibleNameOf v = Just (name v)
\r
417 children v = collectionToList (children_ v)
\r
418 parent = variableParent
\r
419 possibleParent v = Just (variableParent v)
\r
420 valueOf v = untypedValue v
\r
421 variantValueOf v = createVariant (datatype v) (untypedValue v :: Dynamic)
\r
423 possibleChild = possibleChild_