]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.db/scl/Simantics/Variables.scl
possibleVariable into Simantics/Variables
[simantics/platform.git] / bundles / org.simantics.scl.db / scl / Simantics / Variables.scl
1 include "Simantics/Model"
2 include "Simantics/DB"
3 import "Simantics/DB" as DB
4
5 importJava "org.simantics.db.layer0.variable.Variables" where
6     @JavaName getVariable
7     """
8 Function **variable** converts a variable URI to a variable.
9
10 Example:
11
12     import "Simantics/Variables"
13     import "Apros/Module"
14     model_id = model "Model"
15     my_component = getComponent model_id "PO01"
16     my_uri = uriOf my_component
17     my_variable = variable my_uri
18     my_variable
19     
20     > <variable>
21     """
22     variable :: String -> <ReadGraph> Variable
23     
24     @JavaName getPossibleVariable
25     possibleVariable :: String -> <ReadGraph> Maybe Variable
26
27     @JavaName getVariable
28     """
29 Function **resourceVariable** converts a resource to a corresponding variable.
30
31 Example:
32     
33     import "Simantics/Variables"
34     import "Apros/Module"
35     model_id = model "Model"
36     my_resource = getComponent model_id "PO01"
37     my_variable = resourceVariable my_resource
38     my_variable
39     
40     > <variable>
41     """
42     resourceVariable :: Resource -> <ReadGraph> Variable
43     
44     @JavaName getModel
45     """
46 Function **modelOfVariable** returns the model, in which the given input variable is located, as **Resource**
47
48 Example:
49
50     import "Simantics/Variables"
51     import "Apros/Module"
52     my_variable = moduleVariable "PO01"
53     my_model = modelOfVariable my_variable
54     my_model
55     
56     > #376833
57     
58     // use function nameOf, which works for resources, to print out the name of the model
59     nameOf(my_model)
60     
61     > "Model"
62
63     """
64     modelOfVariable :: Variable -> <ReadGraph> Model
65
66     @JavaName getModel
67     modelResourceOfVariable :: Variable -> <ReadGraph> Resource
68     
69     @JavaName possibleActiveVariable
70     possibleActiveVariable :: Variable -> <ReadGraph> Maybe Variable
71
72     @JavaName switchPossibleContext
73     switchPossibleContext :: Variable -> Resource -> <ReadGraph> Maybe Variable
74     
75     @JavaName getIndexRoot
76     instanceIndexRoot :: Variable -> <ReadGraph> Resource
77     
78     createValueAccessor :: (Variable -> <ReadGraph> a) -> (Variable -> Binding b -> <ReadGraph> b) -> (Variable -> c -> <WriteGraph> ()) -> (Variable -> d -> Binding d -> <WriteGraph> ()) -> (Variable -> <ReadGraph> Datatype) -> ValueAccessor
79
80     @JavaName getConfigurationContext
81     possibleConfigurationContext :: Resource -> <ReadGraph> Variable
82
83     setRVIProperty :: Variable -> RVI -> <WriteGraph> ()
84     
85 importJava "org.simantics.db.layer0.function.All" where
86
87     standardGetValue1 :: Variable -> <ReadGraph> a
88     standardGetValue2 :: Variable -> Binding a -> <ReadGraph> a
89     standardSetValue2 :: Variable -> a -> <WriteGraph> ()
90     standardSetValue3 :: Variable -> a -> Binding a -> <WriteGraph> ()
91     standardGetDatatype :: Variable -> <ReadGraph> Datatype
92
93 importJava "org.simantics.db.layer0.variable.VariableMap" where
94     data VariableMap
95
96 importJava "org.simantics.db.layer0.variable.ResourceCollectionVariableMap" where
97     @JavaName "<init>"
98     createVariableMap :: [Resource] -> VariableMap
99
100 importJava "org.simantics.db.layer0.variable.ValueAccessor" where
101     data ValueAccessor
102
103 importJava "org.simantics.db.layer0.variable.Variable" where
104     data Variable
105
106     @JavaName getRVI
107     rviOf :: Variable -> <ReadGraph> RVI
108     
109     @JavaName getProperties
110     properties_ :: Variable -> <ReadGraph> Collection Variable
111     
112     @JavaName getProperties
113     propertiesClassified_ :: Variable -> Resource -> <ReadGraph> Collection Variable
114     
115     @JavaName getChildren
116     children_ :: Variable -> <ReadGraph> Collection Variable
117     
118     @JavaName getValue
119     value_ :: Variable -> Binding a -> <ReadGraph> a
120     
121     @JavaName getDatatype
122     datatype :: Variable -> <ReadGraph> Datatype
123     
124     @JavaName getValue
125     untypedValue :: Variable -> <ReadGraph> a
126     
127     @JavaName getPossibleValue
128     possibleVariableValue_ :: Variable -> Binding a -> <ReadGraph> Maybe a
129     
130     @JavaName getPossibleValue
131     untypedPossibleVariableValue :: Variable -> <ReadGraph> Maybe a
132     
133     @private
134     @JavaName getChild
135     child_ :: Variable -> String -> <ReadGraph> Variable
136     
137     @private
138     @JavaName getPossibleChild
139     possibleChild_ :: Variable -> String -> <ReadGraph> Maybe Variable
140
141     browse :: Variable -> String -> <ReadGraph> Variable
142     browsePossible :: Variable -> String -> <ReadGraph> Maybe Variable
143     
144     @JavaName getProperty
145     """
146 Function **property** return the wanted property as **Variable**
147
148 **Input 1:** Module which property we want to obtain as **Variable**
149
150 **Input 2:** Name of the property as **String**
151
152 **Output:** wanted property as **Variable**
153
154 Example
155
156     import "Simantics/Variables"
157     import "Apros/Module"
158     my_property_variable = property (moduleVariable "PO01") "PO11_PRESSURE"
159     my_property_variable
160     
161     > <variable>
162     """
163     property :: Variable -> String -> <ReadGraph> Variable
164     
165     @JavaName getPossibleProperty
166     possibleProperty :: Variable -> String -> <ReadGraph> Maybe Variable
167     
168     @JavaName getPropertyValue
169     propertyValue_ :: Variable -> String -> Binding a -> <ReadGraph> a
170
171     @JavaName getPropertyValue
172     untypedPropertyValue :: Variable -> String -> <ReadGraph> a
173
174     @JavaName getPossiblePropertyValue
175     possiblePropertyValue_ :: Variable -> String -> Binding a -> <ReadGraph> Maybe a
176     
177     @JavaName getPossiblePropertyValue
178     untypedPossiblePropertyValue :: Variable -> String -> <ReadGraph> Maybe a
179     
180     @JavaName getName
181
182     """
183 Function **name** return the name of the input variable as string
184
185 Example:
186     
187     import "Simantics/Variables"
188     import "Apros/Module"
189     name (moduleVariable "PO01")
190     
191     > "PO01"
192     """
193     
194     name :: Variable -> <ReadGraph> String
195     @JavaName getURI
196     """
197 Function **uri** return the uri of given variable. The uri is fetched from the active **Experiment**
198
199 **Input 1:** wanted variable which uri is needed as **Variable**
200
201 **Output:** uri of the variable as **String**
202
203 Example:
204
205     import "Simantics/Variables"
206     import "Apros/Module"
207     uri (moduleVariable "PO01")
208
209     >"http://Projects/Development%20Project/Model/Experiment/8ee6b693-891b-438e-a597-9e15a2634e8b/NewGenericDiagram/PO01"
210
211     """
212     uri :: Variable -> <ReadGraph> String
213     
214     @JavaName getParent
215     """
216 Function **variableParent** returns the name of the parent variable as **Variable**
217
218 Example:
219
220     import "Simantics/Variables"
221     import "Apros/Module"
222     my_variable = moduleVariable "PO01"
223     variableParent my_variable
224     
225     > <variable>
226     
227     name (variableParent my_variable)
228
229     > "NewGenericDiagram"
230     
231     """
232     variableParent :: Variable -> <ReadGraph> Variable
233
234     @JavaName getRepresents
235     
236     """
237 Function **represents** returns the resource of the given input variable
238
239 **Input 1:** **Variable** which resource is wanted to be obtainend
240
241 **Output:** **Resource** of the given input variable.
242
243 Example: Find out the resource of given variable
244
245     import "Simantics/Variables"
246     import "Apros/Module"
247     represents (moduleVariable "PO01")
248
249         > #426013
250
251     """
252     represents :: Variable -> <ReadGraph> Resource
253     
254     @JavaName getPossibleRepresents
255     possibleRepresents :: Variable -> <ReadGraph> Maybe Resource
256     
257     @JavaName setValue
258     setValue :: Variable -> a -> <WriteGraph> ()
259     
260     @JavaName setPropertyValue
261     setPropertyValue_ :: Variable -> String -> a -> Binding a -> <WriteGraph> ()
262     
263     @JavaName getType
264     """
265 Function **getType** returns the type of the input variable as resource
266
267 Example:
268
269     import "Simantics/Variables"
270     import "Apros/Module"
271     getType (moduleVariable "PO01")
272     
273     > #275837
274     
275     nameOf(getType (moduleVariable "PO01"))
276     
277     > "POINT_QF"
278     """
279     getType :: Variable -> <ReadGraph> Resource
280     
281     @JavaName getPossibleType
282     getPossibleType :: Variable -> <ReadGraph> Maybe Resource
283         
284     getPredicateResource :: Variable -> <ReadGraph> Resource
285     
286     getIndexRoot :: Variable -> <ReadGraph> Resource
287
288 value :: Serializable a => Typeable a => Variable -> <ReadGraph> a
289 value var = value_ var binding 
290
291 possibleVariableValue :: Serializable a => Typeable a => Variable -> <ReadGraph> Maybe a
292 possibleVariableValue var = possibleVariableValue_ var binding  
293
294 """
295 Function **propertyValue** finds the value of given property.
296
297 Example: Find out the value of point PO01 attribute PO11_PRESSURE
298
299     import "Simantics/Variables"
300     import "Apros/Module"
301     propertyValue (moduleVariable "PO01") "PO11_PRESSURE" :: Double
302
303         > 0.75
304
305 """
306
307 propertyValue :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> a
308 propertyValue var prop = propertyValue_ var prop binding
309
310 possiblePropertyValue :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> Maybe a
311 possiblePropertyValue var prop = possiblePropertyValue_ var prop binding
312
313 """
314 Function **setPropertyValue** sets wanted to value to given Variable property.
315
316 **Input 1:** Wanted module as **Variable**
317
318 **Input 2:** Wanted property name as **String**
319
320 **Output:** No output, given value is inserted to property 
321
322 Example:
323
324     import "Simantics/Variables"
325     import "Apros/Module"
326     setPropertyValue (moduleVariable "PO01") "PO11_PRESSURE" 0.5
327 """
328
329 setPropertyValue :: Serializable a => Variable -> String -> a -> <WriteGraph> ()
330 setPropertyValue subject prediate value = setPropertyValue_ subject prediate value binding
331
332 """
333 Function **modelVariableOfVariable** returns the model, in which the given input Variable is located, as **Variable**
334
335 Example:
336
337     import "Simantics/Variables"
338     import "Apros/Module"
339     my_model_variable = modelVariableOfVariable (moduleVariable "PO01")
340     my_model_variable
341
342     > <variable>
343     
344     name my_model_variable
345     
346     > "Model"
347 """
348
349 modelVariableOfVariable :: Variable -> <ReadGraph> Variable     
350 modelVariableOfVariable var = variable $ uriOf $ modelOfVariable var
351
352 uniqueChild :: Model -> Resource -> String -> <ReadGraph> Variable
353 uniqueChild model typet childName = do
354     typeName = DB.nameOf typet
355     query = "Types: " + typeName + " AND Name: " + childName
356     moduleResources = searchByQuery model query
357     variable $ uriOf $ moduleResources ! 0
358
359 """
360 Function **properties** returns a list, which contains of the properties of the input variable as **Variable**
361
362 Example 1: print out all the properties of certain point as they are shown in Variable Debugger.
363     
364     import "Simantics/Variables"
365     import "Apros/Module"
366     point_properties_list = properties (moduleVariable "PO01")
367     //print out the names of the properties
368     for point_properties_list (\x -> print(name x) )
369     
370     > IncludedInSimulation
371     > PO11_PRESSURE
372     > IsDesynchronized
373     > PO11_PROPERTY_CALC
374     > PO11_EPM_ROU
375     > PO11_ELEV_FROM_BOT
376     ...
377
378 Example 2: print out only the properties of a point, which name starts as "PO11". Else do nothing.
379
380     import "Simantics/Variables"
381     import "Apros/Module"
382     point_properties_list = properties (moduleVariable "PO01")
383     for point_properties_list (\x -> do
384         //print out the names of the properties, which name start as "PO11"
385         if (take 4 (name x) == "PO11") then do
386             print(name x)
387             ()
388         else do
389             ()
390     )
391     
392     > PO11_PRESSURE
393     > PO11_PROPERTY_CALC
394     > PO11_EPM_ROU
395     > PO11_ELEV_FROM_BOT
396     > PO11_NODE_VELOCITY_CALC
397     ...
398
399 """
400 properties = collectionToList . properties_
401
402 instance Show Variable where
403     show _ = "<variable>"
404     
405 instance Browsable Variable where
406     fromUri = variable
407     uriOf = uri
408     nameOf = name
409     possibleNameOf v = Just (name v)
410     children v = collectionToList (children_ v)
411     parent = variableParent
412     possibleParent v = Just (variableParent v)
413     valueOf v = untypedValue v
414     variantValueOf v = createVariant (datatype v) (untypedValue v :: Dynamic)
415     child = child_
416     possibleChild = possibleChild_
417
418 propertiesClassified :: Variable -> Resource -> <ReadGraph> [Variable]
419 propertiesClassified parent classified = do
420     collectionToList $ propertiesClassified_ parent classified
421
422 importJava "org.simantics.db.layer0.variable.RVI" where
423     data RVI
424     
425     resolvePossible :: RVI -> Variable -> <ReadGraph> Maybe Variable
426
427 instantiateUnder :: Resource -> Resource -> <WriteGraph> Resource
428 instantiateUnder container typeToInstantiate = do
429     fn = (resourceVariable typeToInstantiate)#methods#instantiateUnder :: Resource -> Resource -> <WriteGraph> Resource  
430     fn container typeToInstantiate