2 import "Simantics/Variables"
3 import "Simantics/Entity"
4 import "Simantics/Model"
5 import "http://www.simantics.org/Modeling-1.2" as MOD
7 type Subscription = Resource
8 type SubscriptionFolder = Resource
10 importJava "org.simantics.modeling.subscription.SCLSubscription" where
11 @JavaName addSubscriptionItems
13 Creates new Subscription with the given Variable under the given SubscriptionFolder.
15 **Input 1:** Subscription folder in which subscription is wanbted to be created as **Resource**
17 **Input 2:** Wanted module attribute from which subscription is to be created as **Variable**
19 **Output:** The newly created subscription as **Resource**
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.
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
39 print(labelOf(my_subscription_folder_list!0))
41 > Pressure subscriptions of the model
43 print(labelOf(my_subscription_folder_list!1))
47 addSubscriptionInFolder (my_subscription_folder_list!0) my_variable
52 addSubscriptionInFolder :: SubscriptionFolder -> Variable -> <WriteGraph> Subscription
54 @JavaName newSubscriptionItem
56 Creates new Subscription with advanced options for user to define non-default parameters.
58 **Input 1:** Wanted subscription folder as **Resource**
60 **Input 2:** Wanted variable from which the subscription is done as **Variable**
62 **Input 3:** Sampling interval as **Double**
64 **Input 4:** Deadband as **Double**
66 **Input 5:** Gain as **Double**
68 **Input 6:** Bias as **Double**
70 **Input 7:** Unit as **String**
72 **Input 8:** Label as **String**
74 **Output:** The newly created subscription as **Resource**
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**
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"
96 newSubscription :: SubscriptionFolder -> Variable -> Double -> Double -> Double -> Double -> String -> String -> <WriteGraph> Subscription
98 @JavaName addSubscriptionFolder
100 Creates new SubscriptionFolder under the given Model. Parameter String defines the name of the folder.
102 **Input 1:** Model in which new subscription folder is wanted to be created as **Model**
104 **Input 2:** Wanted name for the new subscription folder as **String**
106 **Output:** The newly created subscription folder as **Resource**
111 import "Simantics/Subscription"
112 my_model = model "Model"
113 addSubscriptionFolder my_model "Pressure subscriptions of the model"
117 addSubscriptionFolder :: Model -> String -> <WriteGraph> SubscriptionFolder
119 @JavaName defaultSubscriptionFolder
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
123 **Input 1:** Model which default subscription folder is wanted to be obtained as **Model**
125 **Output:** The default subscription folder as **Resource**
130 import "Simantics/Subscription"
131 my_model = model "Model"
132 defaultSubscriptionFolder my_model
137 defaultSubscriptionFolder :: Model -> <ReadGraph> SubscriptionFolder
140 getSubscriptionLabel :: Subscription -> <ReadGraph> String
143 Creates new Subscription with the given Variable to the Variables models default SubscriptionFolder.
145 **Input 1:** Wanted module attribute from which subscription is to be created as **Variable**
147 **Output:** The newly created subscription as **Resource**
149 Example: create a subscription of module PO01 attribute PO11_PRESSURE to the default subscription folder with default options.
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
166 addSubscription :: Variable -> <WriteGraph,ReadGraph> Subscription
167 addSubscription variable = do
168 model = modelOfVariable variable
169 default = defaultSubscriptionFolder model
170 addSubscriptionInFolder default variable
173 Browses the given Model for its SubscriptionFolders and then returns them in a list.
175 **Input 1:** Model which subscription folders are wanted as **Model**
177 **Output:** List which elements are subscription folder **Resources**
179 Example: Model contains two subscription folders called **Default** and **Pressure subscriptions of the model**. Let's fetch them and print out their names.
182 import "Simantics/Subscription"
183 my_model = model "Model"
184 my_subscription_folder_list = subscriptionFoldersOf my_model
185 my_subscription_folder_list
189 print(labelOf(my_subscription_folder_list!0))
193 print(labelOf(my_subscription_folder_list!1))
195 Pressure subscriptions of the model
198 subscriptionFoldersOf :: Model -> <ReadGraph> [SubscriptionFolder]
199 subscriptionFoldersOf model = recurse model
201 recurse r = filter isSubscriptionFolder (children r)
202 isSubscriptionFolder r = isInstanceOf r MOD.Subscription