Rev 1221 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
900 | werner | 1 | |
2 | /** |
||
3 | The global variable `fmengine` (of type `FMEngine`) variable lets you access the ABE core engine. |
||
4 | |||
5 | Use `fmengine` to register agents and stand treatment programmes. `fmengine` also provides some additional functionalities, such as logging (`log`) |
||
6 | or executing functions/activities in the ABE context. |
||
7 | |||
8 | @class FMEngine |
||
9 | */ |
||
1061 | werner | 10 | var fmengine= { |
900 | werner | 11 | /** |
12 | `log` writes a log message. Each message is prefixed with a code for identifying the current stand and the current year of the simulation. |
||
13 | The format of the prefix is: 'S_standid_Y_year_:'. |
||
14 | |||
1188 | werner | 15 | fmengine.log('log message for stand ' + stand.id); |
16 | // produces (in year 0 and for stand 7) |
||
17 | abe: "S7Y0:" log message for stand 7 |
||
900 | werner | 18 | |
19 | @method log |
||
20 | @param {string} message The message to be printed. |
||
21 | */ |
||
1061 | werner | 22 | log: function(x){}, |
900 | werner | 23 | |
24 | /** |
||
901 | werner | 25 | Calling `abort` stops the execution of ABE and prints the error message `message` to the console (and shows the error). Note that `abort` does not |
26 | interrupt execution of JavaScript code immediately. However, the ABE core engine cancels all further activities, when the `abort` method has been called. |
||
27 | |||
28 | |||
29 | if (some_error_condition) { |
||
30 | fmengine.abort('This is really not expected!!'); |
||
31 | return; // required; otherwise do_some_stuff() would be executed. |
||
32 | } |
||
33 | do_some_stuff(); |
||
34 | |||
35 | |||
36 | @method abort |
||
37 | @param {string} message The error message. |
||
38 | */ |
||
1061 | werner | 39 | abort: function(x), |
901 | werner | 40 | |
41 | /** |
||
900 | werner | 42 | `runActivity` executes an {{#crossLink "Activity"}}{{/crossLink}} for stand given by `standId`. This bypasses the normal scheduling (useful for debugging/testing). |
1061 | werner | 43 | This function calls the main execution function of the activity. |
900 | werner | 44 | |
45 | @method runActivity |
||
46 | @param {int} standId the (integer) id of the stand in which context the activity should be executed. |
||
47 | @param {string} activity the name of the activity that should be executed. |
||
48 | @return {boolean} returns false if the stand or activity were not found. |
||
49 | |||
50 | */ |
||
1061 | werner | 51 | runActivity: function(id, activity), |
900 | werner | 52 | |
53 | /** |
||
1061 | werner | 54 | `runActivityEvaluate` executes an {{#crossLink "Activity"}}{{/crossLink}} for stand given by `standId`. This bypasses the normal scheduling (useful for debugging/testing). |
55 | 'runActivityEvaluate' invokes the evaluation code of scheduled activites (e.g., ActThinning, ActScheduled). |
||
56 | |||
57 | @method runActivity |
||
58 | @param {int} standId the (integer) id of the stand in which context the activity should be executed. |
||
59 | @param {string} activity the name of the activity that should be executed. |
||
60 | @return {boolean} returns false if the stand or activity were not found. |
||
61 | |||
62 | */ |
||
63 | runActivityEvaluate: function(id, activity), |
||
64 | |||
65 | /** |
||
900 | werner | 66 | adds a management program (STP) whose definition is provided by the Javascript object `program`. The `name` of the program is used internally. |
67 | |||
68 | See also: {{#crossLink "Activity"}}{{/crossLink}} |
||
69 | |||
70 | @method addManagement |
||
71 | @param {object} program The javascript object that defines the STP. |
||
72 | @param {string} name The name that ABE should be use for this STP. |
||
73 | @return {boolean} true on success. |
||
74 | */ |
||
1061 | werner | 75 | addManatgement: function(obj, name), |
900 | werner | 76 | |
77 | /** |
||
78 | add an agent definition (Javascript) and gives the agent the name `name`. |
||
79 | |||
80 | @method addAgent |
||
81 | @param {object} program The javascript object that defines the {{#crossLink "Agent"}}{{/crossLink}}. |
||
82 | @param {string} name The name that ABE should be use for this {{#crossLink "Agent"}}{{/crossLink}}. |
||
83 | @return {boolean} true on success. |
||
84 | */ |
||
1061 | werner | 85 | addAgent: function(obj, name), |
900 | werner | 86 | |
951 | werner | 87 | /** |
88 | checks if a given `stand_id` is valid (i.e., part of the currently simulated area). |
||
934 | werner | 89 | |
951 | werner | 90 | @method isValidStand |
91 | @param {int} stand_id The id of the stand to check. |
||
92 | @return {boolean} true, if 'stand_id' is a valid stand in the current setup. |
||
93 | */ |
||
1061 | werner | 94 | isValidStand: function(id), |
951 | werner | 95 | |
900 | werner | 96 | /** |
1059 | werner | 97 | returns a list of valid stand-ids within the model. |
98 | See also: {{#crossLink "standId:property"}}{{/crossLink}} |
||
99 | |||
100 | |||
101 | @method standIds |
||
102 | @return {array} Array of valid stand-ids. |
||
103 | */ |
||
1061 | werner | 104 | standIds: function(), |
1059 | werner | 105 | |
106 | /** |
||
934 | werner | 107 | Runs a planting activity (without the context of stand treatment programmes). This is especially useful for |
108 | setting up initial stand conditions. The `planting` defines the activity according to the syntax of the planting activity. |
||
109 | |||
110 | |||
1189 | werner | 111 | // global 'onInit' function is called during startup |
112 | function onInit() { |
||
113 | // run a planting activity for the stand 235 (30cm spruce trees on 90% of the pixels) |
||
114 | fmengine.runPlanting( 235, { species: "piab", fraction: 0.9, height: 0.3 }); |
||
115 | } |
||
116 | |||
934 | werner | 117 | @method runPlanting |
118 | @param {int} standId (integer) of the stand for which a planting activity should be executed. |
||
119 | @param {object} planting A javascript object with the definition of the planting activity (see ABE documentation). |
||
120 | */ |
||
1061 | werner | 121 | runPlanting: function(standid, obj), |
934 | werner | 122 | |
123 | /** |
||
900 | werner | 124 | ABE generates much more detailed log messages, if `verbose` is true. This is generally useful for debugging and |
125 | should be turned off for productive use. Note, that `verbose` mode can switched on for specfic code sections: |
||
126 | |||
127 | .... |
||
128 | fmengine.verbose = true; |
||
129 | ... // do some complicated stuff |
||
130 | fmengine.verbose = false; // switch off verbose mode |
||
131 | |||
132 | See also: {{#crossLink "Stand/trace:property"}}{{/crossLink}} |
||
133 | |||
134 | @property verbose |
||
135 | @type boolean |
||
136 | @default false |
||
137 | */ |
||
1061 | werner | 138 | verbose: false, |
900 | werner | 139 | |
140 | /** |
||
141 | `standId` is the numeric Id of the stand that is set as the current execution context, i.e. the `stand`, `site`, etc. variables |
||
142 | that are available in the current context refer to the stand with this Id. The property is set automatically by ABE during the |
||
143 | execution of forest management. It can, however, be changed by Javascript for debugging/testing purposes. Note that changing |
||
144 | the `standId` might lead to unexpected behavior. |
||
145 | |||
146 | |||
147 | See also: {{#crossLink "Stand/id:property"}}{{/crossLink}} |
||
148 | |||
149 | @property standId |
||
150 | @type int |
||
151 | @default -1 |
||
152 | */ |
||
1061 | werner | 153 | standId: -1, |
154 | /** |
||
155 | This function adds quicklinks that trigger Javascript functions to the user interface of iLand. Each name-value pair |
||
156 | defines one function call (name) and its description (value). |
||
900 | werner | 157 | |
158 | |||
1061 | werner | 159 | // call this anywhere (e.g. in the body of the main javascript) |
160 | Globals.setUIShortcuts( { 'Globals.reloadABE()': 'full reload of ABE', 'test()': 'my dearest test function' } ); |
||
900 | werner | 161 | |
934 | werner | 162 | |
1061 | werner | 163 | @method setUIShortcuts |
164 | @param {object} A object containt name/value pairs that are used in the iLand UI to create quicklinks for calling javascript functions. |
||
165 | */ |
||
166 | setUIShortcuts: function(obj) |
||
167 | |||
168 | } |
||
169 | |||
170 | |||
900 | werner | 171 | |
172 | |||
173 | |||
174 | |||
175 | /** |
||
176 | * Access to properties of the current activity. |
||
177 | * The `activity` variable is available in the execution context of forest management and provides access to properties and functions |
||
178 | * of the current activity (linked to a `stand`) that is currently processed. In addition, other activities of the (currently active) programme |
||
179 | * can be accessed with {{#crossLink "Stand/activity:method"}}{{/crossLink}}. |
||
180 | * |
||
181 | * Note that the variable `activity` is provided through the C++ framework and does not need to be created separately. |
||
182 | * |
||
183 | * See also: Variables `stand` ({{#crossLink "Stand"}}{{/crossLink}}) |
||
184 | |||
185 | * |
||
186 | @class Activity |
||
187 | */ |
||
1061 | werner | 188 | var activity: { |
900 | werner | 189 | |
190 | /** |
||
191 | The `active` property indicates whether an activity __can__ still be executed during this rotation. After an activity is executed, |
||
192 | the `active` flag is set to false, and the next active (and `enabled`) activity is selected. At the end of a rotation, the `active` |
||
193 | flag of all activities of the programme are set back to true. By changing the value of `active`, activities can be either removed |
||
194 | from the current rotation, or re-enabled. |
||
195 | |||
196 | //re-enable the 'todo' activity. |
||
197 | stand.activity("todo").active = true; |
||
198 | |||
199 | |||
200 | See also: {{#crossLink "Activity/enabled:property"}}{{/crossLink}} |
||
201 | |||
202 | @property active |
||
203 | @type boolean |
||
204 | @default false |
||
205 | */ |
||
1061 | werner | 206 | active: false, |
900 | werner | 207 | |
208 | /** |
||
209 | An activity can only be executed, if the `enabled` property is true. Activities can be switched on/ off using this flag. |
||
210 | |||
211 | Note that an activity needs also to be `{{#crossLink "Activity/active:property"}}{{/crossLink}}` in order to get executed. |
||
212 | |||
213 | // switch off a repeating activity, when a height threshold is surpassed. |
||
214 | if (stand.hmean>12) |
||
215 | stand.activity('repeater').enabled = false; |
||
216 | |||
217 | |||
218 | See also: {{#crossLink "Activity/active:property"}}{{/crossLink}} |
||
219 | |||
220 | @property enabled |
||
221 | @type boolean |
||
222 | @default false |
||
223 | */ |
||
1061 | werner | 224 | enabled: false, |
900 | werner | 225 | |
226 | /** |
||
227 | This flag indicates whether the {{#crossLink "Scheduler"}}{{/crossLink}} is used when this activity is run, i.e. if the |
||
228 | exact date of execution is selected by the scheduling algorithm of ABE. The default value depends on the type of the activity, |
||
229 | e.g., default is false for activities of type __general__, but true for __scheduled__ activities. |
||
230 | |||
231 | @property scheduled |
||
232 | @type boolean |
||
233 | @default depends on activity type. |
||
234 | */ |
||
1061 | werner | 235 | scheduled: false, |
900 | werner | 236 | |
237 | /** |
||
238 | An activity with `finalHarvest`=true ends a rotation when (successfully) executed. This resets the `{{#crossLink "Stand/age:property"}}{{/crossLink}}` |
||
239 | counter and sets all activites `{{#crossLink "Activity/active:property"}}{{/crossLink}}`. |
||
240 | |||
241 | @property finalHarvest |
||
242 | @type boolean |
||
243 | @default depends on activity type. |
||
244 | */ |
||
1061 | werner | 245 | finalHarvest: false, |
900 | werner | 246 | |
247 | |||
248 | /** |
||
249 | The name of the activity as provided in the definition of the activity. |
||
250 | |||
251 | See also: {{#crossLink "FMEngine/addManagement:method"}}fmengine.addManagement{{/crossLink}} |
||
252 | |||
253 | @property name |
||
254 | @type string |
||
255 | @readonly |
||
256 | */ |
||
1061 | werner | 257 | name: '' |
258 | } |
||
259 | |||
260 | |||
261 | |||
262 | |||
263 | /** |
||
264 | * Access to properties of the current stand treatment program. |
||
265 | * The `stp` variable is available in the execution context of forest management and provides access to properties STP |
||
266 | * activity (linked to a `stand`). |
||
267 | * |
||
268 | * Note that the variable `stp` is provided through the C++ framework and does not need to be created separately. |
||
269 | * |
||
270 | * See also: Variables `stand` ({{#crossLink "Stand"}}{{/crossLink}}) |
||
271 | |||
272 | * |
||
273 | @class STP |
||
274 | */ |
||
275 | var stp: { |
||
276 | /** |
||
277 | The name of the stand treatment program as provided when called the respecitve 'fmengine' functions. |
||
278 | |||
279 | See also: {{#crossLink "FMEngine/addManagement:method"}}fmengine.addManagement{{/crossLink}} |
||
280 | |||
281 | @property name |
||
282 | @type string |
||
283 | @readonly |
||
284 | */ |
||
285 | name: '' |
||
286 | }, |
||
287 | /** |
||
288 | * The 'options' property provides a link to the 'options' property of the STP *definition*, i.e., this is a mechanism |
||
289 | * that can be used to pass purely javascript options/values to other javascript code (e.g., when an activity within the |
||
290 | * stand context is executed). Note that the C++ part of ABE does not interfere with these options. |
||
291 | |||
292 | // definition of the STP |
||
293 | var stp: { U: [110, 130, 150], // define the rotation period |
||
294 | clearcut: a_clearcut, // some activities |
||
295 | options: { dbh: 5, someOtherParameter: 50} |
||
296 | } |
||
297 | |||
298 | // definition of activities… here the ‘dbh’ options is used |
||
299 | // in the Javascript code to select trees to harvest. |
||
300 | var a_clearcut: { |
||
301 | type: "scheduled", … , |
||
302 | onEvaluate: function() { |
||
303 | trees.loadAll(); |
||
304 | trees.harvest("dbh>" + stp.options.dbh );} |
||
305 | } |
||
306 | }; |
||
307 | |||
308 | |||
309 | |||
310 | @property options |
||
311 | @type object |
||
312 | */ |
||
313 | options: {} |
||
314 | |||
315 | |||
316 | } |