]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/scl/Simantics/Subscription.scl
Remove useless ReadGraph effect from addSubscription
[simantics/platform.git] / bundles / org.simantics.modeling / scl / Simantics / Subscription.scl
1 import "Simantics/DB"
2 import "Simantics/Variables"
3 import "Simantics/Entity"
4 import "Simantics/Model"
5 import "http://www.simantics.org/Modeling-1.2" as MOD
6
7 type Subscription = Resource
8 type SubscriptionFolder = Resource
9
10 importJava "org.simantics.modeling.subscription.SCLSubscription" where 
11     @JavaName addSubscriptionItems
12     """
13 Creates new Subscription with the given Variable under the given SubscriptionFolder.
14
15 **Input 1:** Subscription folder in which subscription is wanbted to be created as **Resource**
16
17 **Input 2:** Wanted module attribute from which subscription is to be created as **Variable**
18
19 **Output:** The newly created subscription as **Resource**
20
21 Example: Model contains two subscription folders called **Default** and **Pressure subscriptions of the model**. Let's fetch them and add one new subscription
22 of module PO01 attribute PO11_PRESSURE to the latter folder.
23
24     import "Apros/Model"
25     import "Apros/Module"
26     import "Simantics/Diagram"
27     import "Apros/Variables"
28     import "Simantics/Subscription"
29     my_model = model "Model"
30     my_diagram = diagram my_model ["NewGenericDiagram"]
31     my_component = getComponent my_model "PO01"
32     my_variable_uri = stateVariableUri my_model my_diagram my_component "PO11_PRESSURE"
33     my_variable = getStateVariable my_variable_uri
34     my_subscription_folder_list = subscriptionFoldersOf my_model
35     my_subscription_folder_list
36     
37     > [#430091, #386608]
38     
39     print(labelOf(my_subscription_folder_list!0))
40
41     > Pressure subscriptions of the model
42
43     print(labelOf(my_subscription_folder_list!1))
44
45     > Default
46     
47     addSubscriptionInFolder (my_subscription_folder_list!0) my_variable
48
49     > #430094    
50     
51     """
52     addSubscriptionInFolder :: SubscriptionFolder -> Variable -> <WriteGraph> Subscription
53
54     @JavaName newSubscriptionItem
55     """
56 Creates new Subscription with advanced options for user to define non-default parameters.
57
58 **Input 1:** Wanted subscription folder as **Resource**
59
60 **Input 2:** Wanted variable from which the subscription is done as **Variable**
61
62 **Input 3:** Sampling interval as **Double**
63
64 **Input 4:** Deadband as **Double**
65
66 **Input 5:** Gain as **Double**
67
68 **Input 6:** Bias as **Double**
69
70 **Input 7:** Unit as **String**
71
72 **Input 8:** Label as **String**
73
74 **Output:** The newly created subscription as **Resource**
75     
76 Example: Let's add a subscription of module **PO01** attribute **PO11_PRESSURE** to the default subscription folder. This point is 
77 located on diagram **NewGenericDiagram** in a model called **Model**. We want to have unit to be shown as bars, so lets define gain as **10**.
78 Also lets define sampling interval to be **5 seconds** and label as **Pressure at point PO01**
79     
80     import "Apros/Model"
81     import "Apros/Module"
82     import "Simantics/Diagram"
83     import "Apros/Variables"
84     import "Simantics/Subscription"
85     my_model = model "Model"
86     my_diagram = diagram my_model ["NewGenericDiagram"]
87     my_component = getComponent my_model "PO01"
88     my_variable_uri = stateVariableUri my_model my_diagram my_component "PO11_PRESSURE"
89     my_variable = getStateVariable my_variable_uri
90     my_subscription_folder = defaultSubscriptionFolder my_model
91     newSubscription my_subscription_folder my_variable 5 0 10 0 "Bar" "Pressure at point PO01"
92
93     #430173
94     
95     """
96     newSubscription :: SubscriptionFolder -> Variable -> Double -> Double -> Double -> Double -> String -> String -> <WriteGraph> Subscription
97     
98     @JavaName addSubscriptionFolder
99     """
100 Creates new SubscriptionFolder under the given Model. Parameter String defines the name of the folder.
101
102 **Input 1:** Model in which new subscription folder is wanted to be created as **Model**
103
104 **Input 2:** Wanted name for the new subscription folder as **String**
105
106 **Output:** The newly created subscription folder as **Resource**
107
108 Example:
109
110     import "Apros/Model"
111     import "Simantics/Subscription"
112     my_model = model "Model"
113     addSubscriptionFolder my_model "Pressure subscriptions of the model"
114
115     #430186
116     """
117     addSubscriptionFolder :: Model -> String -> <WriteGraph> SubscriptionFolder
118     
119     @JavaName defaultSubscriptionFolder
120     """
121 Browses the given Model for its default SubscriptionFolder with name "Default" and then returns it. If folder is not found, returns a random SubscriptionFolder
122
123 **Input 1:** Model which default subscription folder is wanted to be obtained as **Model**
124
125 **Output:** The default subscription folder as **Resource**
126
127 Example:
128
129     import "Apros/Model"
130     import "Simantics/Subscription"
131     my_model = model "Model"
132     defaultSubscriptionFolder my_model
133
134     #386608
135
136     """
137     defaultSubscriptionFolder :: Model -> <ReadGraph> SubscriptionFolder
138     
139     @JavaName getLabel
140     getSubscriptionLabel :: Subscription -> <ReadGraph> String
141
142 """
143 Creates new Subscription with the given Variable to the Variables models default SubscriptionFolder.
144
145 **Input 1:** Wanted module attribute from which subscription is to be created as **Variable**
146
147 **Output:** The newly created subscription as **Resource**
148
149 Example: create a subscription of module PO01 attribute PO11_PRESSURE to the default subscription folder with default options.
150
151     import "Apros/Model"
152     import "Apros/Module"
153     import "Simantics/Diagram"
154     import "Apros/Variables"
155     import "Simantics/Subscription"
156     my_model = model "Model"
157     my_diagram = diagram my_model ["NewGenericDiagram"]
158     my_component = getComponent my_model "PO01"
159     my_variable_uri = stateVariableUri my_model my_diagram my_component "PO11_PRESSURE"
160     my_variable = getStateVariable my_variable_uri
161     addSubscription my_variable
162     
163     #430121
164
165 """
166 addSubscription :: Variable -> <WriteGraph> Subscription
167 addSubscription variable = do
168     model = modelOfVariable variable
169     default = defaultSubscriptionFolder model
170     addSubscriptionInFolder default variable
171
172 """
173 Browses the given Model for its SubscriptionFolders and then returns them in a list.
174
175 **Input 1:** Model which subscription folders are wanted as **Model**
176
177 **Output:** List which elements are subscription folder **Resources**
178
179 Example: Model contains two subscription folders called **Default** and **Pressure subscriptions of the model**. Let's fetch them and print out their names.
180
181     import "Apros/Model"
182     import "Simantics/Subscription"
183     my_model = model "Model"
184     my_subscription_folder_list = subscriptionFoldersOf my_model
185     my_subscription_folder_list
186
187     [#386608, #430189]
188
189     print(labelOf(my_subscription_folder_list!0))
190
191     Default
192
193     print(labelOf(my_subscription_folder_list!1))
194
195     Pressure subscriptions of the model
196
197 """
198 subscriptionFoldersOf :: Model -> <ReadGraph> [SubscriptionFolder]
199 subscriptionFoldersOf model = recurse model
200   where
201     recurse r = filter isSubscriptionFolder (children r)
202     isSubscriptionFolder r = isInstanceOf r MOD.Subscription