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