1 /*******************************************************************************
2 * Copyright (c) 2019 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 include "Simantics/Model"
13 include "Simantics/DB"
14 import "Simantics/DB" as DB
16 importJava "org.simantics.db.layer0.variable.Variables" where
19 Function **variable** converts a variable URI to a variable.
23 import "Simantics/Variables"
25 model_id = model "Model"
26 my_component = getComponent model_id "PO01"
27 my_uri = uriOf my_component
28 my_variable = variable my_uri
33 variable :: String -> <ReadGraph> Variable
35 @JavaName getPossibleVariable
36 possibleResourceVariable :: Resource -> <ReadGraph> Maybe Variable
38 @JavaName getPossibleVariable
39 possibleVariable :: String -> <ReadGraph> Maybe Variable
43 Function **resourceVariable** converts a resource to a corresponding variable.
47 import "Simantics/Variables"
49 model_id = model "Model"
50 my_resource = getComponent model_id "PO01"
51 my_variable = resourceVariable my_resource
56 resourceVariable :: Resource -> <ReadGraph> Variable
60 Function **modelOfVariable** returns the model, in which the given input variable is located, as **Resource**
64 import "Simantics/Variables"
66 my_variable = moduleVariable "PO01"
67 my_model = modelOfVariable my_variable
72 // use function nameOf, which works for resources, to print out the name of the model
78 modelOfVariable :: Variable -> <ReadGraph> Model
81 modelResourceOfVariable :: Variable -> <ReadGraph> Resource
83 @JavaName possibleActiveVariable
84 possibleActiveVariable :: Variable -> <ReadGraph> Maybe Variable
86 @JavaName switchPossibleContext
87 switchPossibleContext :: Variable -> Resource -> <ReadGraph> Maybe Variable
89 @JavaName getIndexRoot
90 instanceIndexRoot :: Variable -> <ReadGraph> Resource
92 createValueAccessor :: (Variable -> <ReadGraph> a) -> (Variable -> Binding b -> <ReadGraph> b) -> (Variable -> c -> <WriteGraph> ()) -> (Variable -> d -> Binding d -> <WriteGraph> ()) -> (Variable -> <ReadGraph> Datatype) -> ValueAccessor
94 @JavaName getConfigurationContext
95 possibleConfigurationContext :: Resource -> <ReadGraph> Variable
97 setRVIProperty :: Variable -> RVI -> <WriteGraph> ()
99 importJava "org.simantics.db.layer0.function.All" where
101 standardGetValue1 :: Variable -> <ReadGraph> a
102 standardGetValue2 :: Variable -> Binding a -> <ReadGraph> a
103 standardSetValue2 :: Variable -> a -> <WriteGraph> ()
104 standardSetValue3 :: Variable -> a -> Binding a -> <WriteGraph> ()
105 standardGetDatatype :: Variable -> <ReadGraph> Datatype
107 importJava "org.simantics.db.layer0.variable.VariableMap" where
110 importJava "org.simantics.db.layer0.variable.StructuredProperty" where
111 data StructuredProperty
113 importJava "org.simantics.db.layer0.variable.ResourceCollectionVariableMap" where
115 createVariableMap :: [Resource] -> VariableMap
117 importJava "org.simantics.db.layer0.variable.ValueAccessor" where
120 importJava "org.simantics.db.layer0.variable.Variable" where
124 rviOf :: Variable -> <ReadGraph> RVI
126 @JavaName getProperties
127 properties_ :: Variable -> <ReadGraph> Collection Variable
129 @JavaName getProperties
130 propertiesClassified_ :: Variable -> Resource -> <ReadGraph> Collection Variable
132 @JavaName getChildren
133 children_ :: Variable -> <ReadGraph> Collection Variable
136 value_ :: Variable -> Binding a -> <ReadGraph> a
138 @JavaName getDatatype
139 datatype :: Variable -> <ReadGraph> Datatype
142 untypedValue :: Variable -> <ReadGraph> a
144 @JavaName getPossibleValue
145 possibleVariableValue_ :: Variable -> Binding a -> <ReadGraph> Maybe a
147 @JavaName getPossibleValue
148 untypedPossibleVariableValue :: Variable -> <ReadGraph> Maybe a
152 child_ :: Variable -> String -> <ReadGraph> Variable
155 @JavaName getPossibleChild
156 possibleChild_ :: Variable -> String -> <ReadGraph> Maybe Variable
158 browse :: Variable -> String -> <ReadGraph> Variable
159 browsePossible :: Variable -> String -> <ReadGraph> Maybe Variable
161 @JavaName getProperty
163 Function **property** return the wanted property as **Variable**
165 **Input 1:** Module which property we want to obtain as **Variable**
167 **Input 2:** Name of the property as **String**
169 **Output:** wanted property as **Variable**
173 import "Simantics/Variables"
174 import "Apros/Module"
175 my_property_variable = property (moduleVariable "PO01") "PO11_PRESSURE"
180 property :: Variable -> String -> <ReadGraph> Variable
182 @JavaName getPossibleProperty
183 possibleProperty :: Variable -> String -> <ReadGraph> Maybe Variable
185 @JavaName getPropertyValue
186 propertyValue_ :: Variable -> String -> Binding a -> <ReadGraph> a
188 @JavaName getPropertyValue
189 untypedPropertyValue :: Variable -> String -> <ReadGraph> a
191 @JavaName getPossiblePropertyValue
192 possiblePropertyValue_ :: Variable -> String -> Binding a -> <ReadGraph> Maybe a
194 @JavaName getPossiblePropertyValue
195 untypedPossiblePropertyValue :: Variable -> String -> <ReadGraph> Maybe a
200 Function **name** return the name of the input variable as string
204 import "Simantics/Variables"
205 import "Apros/Module"
206 name (moduleVariable "PO01")
211 name :: Variable -> <ReadGraph> String
214 Function **uri** return the uri of given variable. The uri is fetched from the active **Experiment**
216 **Input 1:** wanted variable which uri is needed as **Variable**
218 **Output:** uri of the variable as **String**
222 import "Simantics/Variables"
223 import "Apros/Module"
224 uri (moduleVariable "PO01")
226 >"http://Projects/Development%20Project/Model/Experiment/8ee6b693-891b-438e-a597-9e15a2634e8b/NewGenericDiagram/PO01"
229 uri :: Variable -> <ReadGraph> String
233 Function **variableParent** returns the name of the parent variable as **Variable**
237 import "Simantics/Variables"
238 import "Apros/Module"
239 my_variable = moduleVariable "PO01"
240 variableParent my_variable
244 name (variableParent my_variable)
246 > "NewGenericDiagram"
249 variableParent :: Variable -> <ReadGraph> Variable
251 @JavaName getRepresents
254 Function **represents** returns the resource of the given input variable
256 **Input 1:** **Variable** which resource is wanted to be obtainend
258 **Output:** **Resource** of the given input variable.
260 Example: Find out the resource of given variable
262 import "Simantics/Variables"
263 import "Apros/Module"
264 represents (moduleVariable "PO01")
269 represents :: Variable -> <ReadGraph> Resource
271 @JavaName getPossibleRepresents
272 possibleRepresents :: Variable -> <ReadGraph> Maybe Resource
275 setValue :: Variable -> a -> <WriteGraph> ()
277 @JavaName setPropertyValue
278 setPropertyValue_ :: Variable -> String -> a -> Binding a -> <WriteGraph> ()
282 Function **getType** returns the type of the input variable as resource
286 import "Simantics/Variables"
287 import "Apros/Module"
288 getType (moduleVariable "PO01")
292 nameOf(getType (moduleVariable "PO01"))
296 getType :: Variable -> <ReadGraph> Resource
298 @JavaName getPossibleType
299 getPossibleType :: Variable -> <ReadGraph> Maybe Resource
301 getPredicateResource :: Variable -> <ReadGraph> Resource
303 getIndexRoot :: Variable -> <ReadGraph> Resource
305 value :: Serializable a => Typeable a => Variable -> <ReadGraph> a
306 value var = value_ var binding
308 possibleVariableValue :: Serializable a => Typeable a => Variable -> <ReadGraph> Maybe a
309 possibleVariableValue var = possibleVariableValue_ var binding
312 Function **propertyValue** finds the value of given property.
314 Example: Find out the value of point PO01 attribute PO11_PRESSURE
316 import "Simantics/Variables"
317 import "Apros/Module"
318 propertyValue (moduleVariable "PO01") "PO11_PRESSURE" :: Double
324 propertyValue :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> a
325 propertyValue var prop = propertyValue_ var prop binding
327 possiblePropertyValue :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> Maybe a
328 possiblePropertyValue var prop = possiblePropertyValue_ var prop binding
331 Function **setPropertyValue** sets wanted to value to given Variable property.
333 **Input 1:** Wanted module as **Variable**
335 **Input 2:** Wanted property name as **String**
337 **Output:** No output, given value is inserted to property
341 import "Simantics/Variables"
342 import "Apros/Module"
343 setPropertyValue (moduleVariable "PO01") "PO11_PRESSURE" 0.5
346 setPropertyValue :: Serializable a => Variable -> String -> a -> <WriteGraph> ()
347 setPropertyValue subject prediate value = setPropertyValue_ subject prediate value binding
350 Function **modelVariableOfVariable** returns the model, in which the given input Variable is located, as **Variable**
354 import "Simantics/Variables"
355 import "Apros/Module"
356 my_model_variable = modelVariableOfVariable (moduleVariable "PO01")
361 name my_model_variable
366 modelVariableOfVariable :: Variable -> <ReadGraph> Variable
367 modelVariableOfVariable var = variable $ uriOf $ modelOfVariable var
369 uniqueChild :: Model -> Resource -> String -> <ReadGraph> Variable
370 uniqueChild model typet childName = do
371 typeName = DB.nameOf typet
372 query = "Types: " + typeName + " AND Name: " + childName
373 moduleResources = searchByQuery model query
374 variable $ uriOf $ moduleResources ! 0
377 Function **properties** returns a list, which contains of the properties of the input variable as **Variable**
379 Example 1: print out all the properties of certain point as they are shown in Variable Debugger.
381 import "Simantics/Variables"
382 import "Apros/Module"
383 point_properties_list = properties (moduleVariable "PO01")
384 //print out the names of the properties
385 for point_properties_list (\x -> print(name x) )
387 > IncludedInSimulation
395 Example 2: print out only the properties of a point, which name starts as "PO11". Else do nothing.
397 import "Simantics/Variables"
398 import "Apros/Module"
399 point_properties_list = properties (moduleVariable "PO01")
400 for point_properties_list (\x -> do
401 //print out the names of the properties, which name start as "PO11"
402 if (take 4 (name x) == "PO11") then do
413 > PO11_NODE_VELOCITY_CALC
417 properties = collectionToList . properties_
419 instance Show Variable where
420 show _ = "<variable>"
422 instance Browsable Variable where
425 possibleUriOf v = Just (uri v)
427 possibleNameOf v = Just (name v)
428 children v = collectionToList (children_ v)
429 parent = variableParent
430 possibleParent v = Just (variableParent v)
431 valueOf v = untypedValue v
432 variantValueOf v = createVariant (datatype v) (untypedValue v :: Dynamic)
434 possibleChild = possibleChild_
436 genericRelatedValue v rel = untypedPropertyValue v (nameOf rel)
437 genericPossibleRelatedValue v rel = untypedPossiblePropertyValue v (nameOf rel)
439 propertiesClassified :: Variable -> Resource -> <ReadGraph> [Variable]
440 propertiesClassified parent classified = do
441 collectionToList $ propertiesClassified_ parent classified
443 importJava "org.simantics.db.layer0.variable.RVI" where
446 resolvePossible :: RVI -> Variable -> <ReadGraph> Maybe Variable
448 instantiateUnder :: Resource -> Resource -> <WriteGraph> Resource
449 instantiateUnder container typeToInstantiate = do
450 fn = (resourceVariable typeToInstantiate)#methods#instantiateUnder :: Resource -> Resource -> <WriteGraph> Resource
451 fn container typeToInstantiate
453 @JavaType "org.simantics.db.layer0.variable.VariableOrResource"
454 data VariableOrResource =
455 @JavaType "org.simantics.db.layer0.variable.ResourceX"
458 | @JavaType "org.simantics.db.layer0.variable.VariableX"