formCallbacks.c
1 #include
2 #include "global.h"
3 #include "trees.h"
4 #include "forms.h"
5 #include "ecoform.h"
6 #include "graphicsData.h"
7
8 eco_color bgColor;
9 treeData currentTree;
10 treeData tree1, tree2;
11 int whichTree;
12 bool file1Selected, file2Selected;
13 bool file1First, file2First;
14
15 string brchFile1, lvsFile1, rtsFile1, brchFile2, lvsFile2, rtsFile2;
16
17 extern void GenerateTree (int,treeData);
18 extern void setLeafAttributeRange (lfStructPtr,eco_leafType,float*,float*);
19 extern void setRootAttributeRange (rtSegPtr,eco_rootType,float*,float*);
20 extern void copyTree (treeData*,treeData);
21 extern void setForm (treeData);
22 extern void loadTreeFiles (treeData*,string,string,string,bool*,bool*,FL_OBJECT*);
23
24 /********************************************************************
25 * assignDefaults:
26 * Initializes the callback data
27 ********************************************************************/
28 assignDefaults ()
29 {
30 currentTree.displayBranches = TRUE;
31 currentTree.displayRoots = FALSE;
32 currentTree.displaySun = FALSE;
33 currentTree.branchChanged = TRUE;
34 currentTree.rootsChanged = TRUE;
35 currentTree.leavesChanged = TRUE;
36 currentTree.leafType = NORMAL;
37 currentTree.rootType = NORMAL;
38 currentTree.minLfValue = 0.0;
39 currentTree.maxLfValue = 0.0;
40 currentTree.minRtValue = 0.0;
41 currentTree.maxRtValue = 0.0;
42 currentTree.minLfValueOrig = 0.0;
43 currentTree.maxLfValueOrig = 0.0;
44 currentTree.minRtValueOrig = 0.0;
45 currentTree.maxRtValueOrig = 0.0;
46 currentTree.rootColorIndex = 1;
47 currentTree.leafColorIndex = 4;
48 currentTree.B = NULL;
49 currentTree.R = NULL;
50 currentTree.L = NULL;
51
52 file1Selected = FALSE;
53 file2Selected = FALSE;
54 file1First = FALSE;
55 file2First = FALSE;
56 whichTree = TREE1;
57
58 /**** default leaf color is GREEN ****/
59 currentTree.leafColor.red = 0.0;
60 currentTree.leafColor.green = 1.0;
61 currentTree.leafColor.blue = 0.0;
62
63 /*** default color for leaf attribute display is RED ***/
64 currentTree.leafAttribColor.red = 1.0;
65 currentTree.leafAttribColor.green = 0.0;
66 currentTree.leafAttribColor.blue = 0.0;
67
68 /**** default root color is BLACK ****/
69 currentTree.rootColor.red = 0.0;
70 currentTree.rootColor.green = 0.0;
71 currentTree.rootColor.blue = 0.0;
72
73 /*** default color for root attribute display is RED ***/
74 currentTree.rootAttribColor.red = 1.0;
75 currentTree.rootAttribColor.green = 0.0;
76 currentTree.rootAttribColor.blue = 0.0;
77
78 /**** default bg color is LT. BLUE ****/
79 bgColor.red = 0.53;
80 bgColor.green = 0.84;
81 bgColor.blue = 0.98;
82
83 currentTree.brchColor.red = BRANCHCOLOR_RED;
84 currentTree.brchColor.green = BRANCHCOLOR_GREEN;
85 currentTree.brchColor.blue = BRANCHCOLOR_BLUE;
86
87 copyTree (&tree1, currentTree);
88 copyTree (&tree2, currentTree);
89 setForm (currentTree);
90 }
91
92 /********************************************************************
93 * updateButton_cb:
94 * associated with: the update button
95 * task: checks if a file's been selected and does error checking.
96 * If no errors, it calls the function to define the tree.
97 ********************************************************************/
98
99 void updateButton_cb (FL_OBJECT *obj, long arg)
100 {
101 bool fileSelected = (whichTree == TREE1) ? file1Selected : file2Selected;
102 if (fileSelected) {
103 if ((currentTree.maxLfValue < currentTree.minLfValue) &&
104 (currentTree.leafType != NORMAL)) {
105 fl_show_message ("The max. leaf attribute value is not","greater than the min. leaf attribute value","");
106 } else if ((currentTree.maxRtValue < currentTree.minRtValue) &&
107 (currentTree.rootType != NORMAL)) {
108 fl_show_message ("The max. root attribute value is not","greater than the min. leaf attribute value","");
109 } else {
110 GenerateTree (whichTree,currentTree);
111 currentTree.rootsChanged = FALSE;
112 currentTree.leavesChanged = FALSE;
113 currentTree.branchChanged = FALSE;
114 }
115 } else {
116 fl_show_message ("No file has been selected for this tree!","","");
117 }
118 }
119
120 /********************************************************************
121 * treeButton_cb:
122 * associated with: the "Tree 1" and "Tree 2" buttons
123 * task: determines which tree has been chosen, saves the data
124 * from the current tree, and copies the data from the chosen
125 * tree into the current tree.
126 ********************************************************************/
127
128 void treeButton_cb (FL_OBJECT *obj, long arg)
129 {
130 if (fl_get_button (tree1Button)) {
131 copyTree (&tree2, currentTree);
132 copyTree (¤tTree, tree1);
133 whichTree = TREE1;
134 fl_activate_object (fileButton1);
135 fl_deactivate_object (fileButton2);
136 } else {
137 copyTree (&tree1, currentTree);
138 copyTree (¤tTree, tree2);
139 whichTree = TREE2;
140 fl_activate_object (fileButton2);
141 fl_deactivate_object (fileButton1);
142 }
143 setForm (currentTree);
144 }
145
146 /********************************************************************
147 * loadFile_cb:
148 * associated with: the "Load" buttons for each tree
149 * task: determines which tree to load the file for and makes
150 * calls to procedures that handle the loading of the files.
151 ********************************************************************/
152
153 void loadFile_cb (FL_OBJECT *obj, long arg)
154 {
155 if (obj == fileButton1) {
156 loadTreeFiles (¤tTree,brchFile1,lvsFile1,rtsFile1,
157 &file1Selected,&file1First,fileBrow1);
158 } else {
159 loadTreeFiles (¤tTree,brchFile2,lvsFile2,rtsFile2,
160 &file2Selected,&file2First,fileBrow2);
161 }
162 }
163
164 /********************************************************************
165 * leafType_cb
166 * associated with: the leaf type choice object
167 * task: determines what type of leaf was chosen from the choice
168 * object and sets the neccessary variables and form settings
169 * to the corresponding values.
170 ********************************************************************/
171
172 void leafType_cb (FL_OBJECT *obj, long arg)
173 {
174 int num;
175 string temp;
176 bool fileSelected;
177 float min, max;
178 currentTree.leafType = fl_get_choice (obj);
179 if (currentTree.leafType == NORMAL) {
180 /*** the user wants to display the leaves normally ***/
181
182 /** normal leaf color is green **/
183 currentTree.leafColor.red = 0.0;
184 currentTree.leafColor.blue = 0.0;
185 currentTree.leafColor.green = 1.0;
186
187 /** deactivate the leaf color choice object, the min & max leaf
188 * attribute value fields, and the reset button since the values
189 * of these are not needed for displaying leaves normally
190 ***/
191 fl_deactivate_object (leafAttribGrp);
192 fl_set_input (lfmin, "0.0");
193 fl_set_input (lfmax, "0.0");
194 currentTree.leavesChanged = TRUE;
195
196 } else {
197 /*** the user wants the leaves colored according to attribute values ***/
198
199 fileSelected = (whichTree == TREE1) ? file1Selected : file2Selected;
200 if (fileSelected) {
201 setLeafAttributeRange (currentTree.L,currentTree.leafType,&min,&max);
202 currentTree.minLfValue = min;
203 currentTree.maxLfValue = max;
204 currentTree.minLfValueOrig = min;
205 currentTree.maxLfValueOrig = max;
206
207 /*** set the min and max attribute values inputs on the form ***/
208 sprintf (temp,"%f",currentTree.minLfValue);
209 fl_set_input (lfmin, temp);
210 sprintf (temp,"%f",currentTree.maxLfValue);
211 fl_set_input (lfmax, temp);
212
213 currentTree.leafColor.red = currentTree.leafAttribColor.red;
214 currentTree.leafColor.green = currentTree.leafAttribColor.green;
215 currentTree.leafColor.blue = currentTree.leafAttribColor.blue;
216 fl_activate_object (leafAttribGrp);
217 currentTree.leavesChanged = TRUE;
218
219 } else {
220 /*** no file has been selected ***/
221 fl_set_choice (obj, NORMAL);
222 fl_show_message ("A tree files must be selected","to change that leaf option!","");
223 }
224 }
225 }
226
227 /********************************************************************
228 * leafColorChoice_cb:
229 * associated with: the leaf color choice object
230 * task: determines which color was selected by the user and
231 * sets the tree leaf and leaf attribute colors to the
232 * corresponding values.
233 ********************************************************************/
234
235 void leafColorChoice_cb (FL_OBJECT *obj, long arg)
236 {
237 currentTree.leafColorIndex = fl_get_choice (obj);
238 currentTree.leafAttribColor.red = 0.0;
239 currentTree.leafAttribColor.green = 0.0;
240 currentTree.leafAttribColor.blue = 0.0;
241 currentTree.leafColor.red = 0.0;
242 currentTree.leafColor.green = 0.0;
243 currentTree.leafColor.blue = 0.0;
244 switch (currentTree.leafColorIndex) {
245 case 1:
246 currentTree.leafAttribColor.blue = 1.0;
247 currentTree.leafColor.blue = 1.0;
248 break;
249 case 2:
250 currentTree.leafAttribColor.green = 1.0;
251 currentTree.leafColor.green = 1.0;
252 break;
253 case 3:
254 currentTree.leafAttribColor.green = 1.0;
255 currentTree.leafAttribColor.blue = 1.0;
256 currentTree.leafColor.green = 1.0;
257 currentTree.leafColor.blue = 1.0;
258 break;
259 case 4:
260 currentTree.leafAttribColor.red = 1.0;
261 currentTree.leafColor.red = 1.0;
262 break;
263 case 5:
264 currentTree.leafAttribColor.red = 1.0;
265 currentTree.leafAttribColor.blue = 1.0;
266 currentTree.leafColor.red = 1.0;
267 currentTree.leafColor.blue = 1.0;
268 break;
269 case 6:
270 currentTree.leafAttribColor.red = 1.0;
271 currentTree.leafAttribColor.green = 1.0;
272 currentTree.leafColor.red = 1.0;
273 currentTree.leafColor.green = 1.0;
274 break;
275 }
276 currentTree.leavesChanged = TRUE;
277 }
278
279 /********************************************************************
280 * leafMinValue_cb:
281 * associated with: the minimum leaf attribute input field
282 * task: takes the floating point value entered by user and
283 * sets the current tree's min leaf attribute value to it.
284 ********************************************************************/
285
286 void leafminValue_cb (FL_OBJECT *obj, long arg)
287 {
288 float temp;
289 strpointer valueStr;
290 valueStr = fl_get_input (obj);
291 temp = (float) atof (valueStr);
292 if (temp >= currentTree.minLfValueOrig) {
293 currentTree.minLfValue = temp;
294 } else {
295 sprintf (valueStr, "%f", currentTree.minLfValueOrig);
296 fl_set_input (lfmin, valueStr);
297 currentTree.minLfValue = currentTree.minLfValueOrig;
298 }
299 currentTree.leavesChanged = TRUE;
300 }
301
302 /********************************************************************
303 * leafMaxValue_cb:
304 * associated with: the maximum leaf attribute input field
305 * task: takes the floating point value entered by user and
306 * sets the current tree's max leaf attribute value to it.
307 ********************************************************************/
308
309 void leafmaxValue_cb (FL_OBJECT *obj, long arg)
310 {
311 float temp;
312 strpointer valueStr;
313 valueStr = fl_get_input (obj);
314 temp = (float) atof (valueStr);
315 if (temp <= currentTree.maxLfValueOrig) {
316 currentTree.maxLfValue = temp;
317 } else {
318 sprintf (valueStr, "%f", currentTree.maxLfValueOrig);
319 fl_set_input (lfmax, valueStr);
320 currentTree.maxLfValue = currentTree.maxLfValueOrig;
321 }
322 currentTree.leavesChanged = TRUE;
323 }
324
325 /********************************************************************
326 * resetLeaves_cb:
327 * associated with: the "Reset" button for the min and max leaf
328 * attribute value input fields
329 * task: sets the min and max leaf attribute values for the
330 * current tree to the original ones read from the file
331 ********************************************************************/
332
333 void resetLeaves_cb (FL_OBJECT *obj, long arg)
334 {
335 string temp;
336 currentTree.minLfValue = currentTree.minLfValueOrig;
337 currentTree.maxLfValue = currentTree.maxLfValueOrig;
338 sprintf (temp, "%f", currentTree.minLfValue);
339 fl_set_input (lfmin, temp);
340 sprintf (temp, "%f", currentTree.maxLfValue);
341 fl_set_input (lfmax, temp);
342 currentTree.leavesChanged = TRUE;
343 }
344
345 /********************************************************************
346 * rootType_cb:
347 * associated with: the root type choice object
348 * task: determines what type of root was chosen from the choice
349 * object and sets the neccessary variables and form settings
350 * to the corresponding values.
351 ********************************************************************/
352
353 void rootType_cb (FL_OBJECT *obj, long arg)
354 {
355 int color;
356 string temp;
357 bool fileSelected;
358 float min, max;
359 currentTree.rootType = (fl_get_choice (obj));
360
361 if ((currentTree.rootType == NORMAL)
362 || (currentTree.rootType == DOUBLE)) {
363 /*** color the roots using the color selected in the leaf color
364 choice object ***/
365
366 fl_clear_choice (rootColorChoice);
367 fl_addto_choice (rootColorChoice, "blue");
368 fl_addto_choice (rootColorChoice, "green");
369 fl_addto_choice (rootColorChoice, "sea green");
370 fl_addto_choice (rootColorChoice, "red");
371 fl_addto_choice (rootColorChoice, "magenta");
372 fl_addto_choice (rootColorChoice, "yellow");
373 fl_addto_choice (rootColorChoice, "white");
374 fl_addto_choice (rootColorChoice, "black");
375 fl_set_choice (rootColorChoice, 8);
376 currentTree.rootColor.red = 0.0;
377 currentTree.rootColor.green = 0.0;
378 currentTree.rootColor.blue = 0.0;
379 fl_set_input (rtmin, "0.0");
380 fl_set_input (rtmax, "0.0");
381 fl_deactivate_object (rootMinMaxGrp);
382 fl_activate_object (rootTypeColGrp);
383 currentTree.rootsChanged = TRUE;
384 } else {
385
386 /*** color the roots based on the values of root attrib. ***/
387
388 fileSelected = (whichTree == TREE1) ? file1Selected : file2Selected;
389 if (fileSelected) {
390 if (((color = fl_get_choice (rootColorChoice)) == 7)
391 || (color == 8)) {
392 fl_set_choice (rootColorChoice, 4);
393 currentTree.rootColor.blue = currentTree.rootColor.green = 0.0;
394 currentTree.rootColor.red = 1.0;
395 }
396 fl_delete_choice (rootColorChoice, 8);
397 fl_delete_choice (rootColorChoice, 7);
398 fl_activate_object (rootColorChoice);
399 setRootAttributeRange (currentTree.R,currentTree.rootType,&min,&max);
400 currentTree.minRtValue = min;
401 currentTree.maxRtValue = max;
402 currentTree.minRtValueOrig = min;
403 currentTree.maxRtValueOrig = max;
404 sprintf (temp,"%f",currentTree.minRtValue);
405 fl_set_input (rtmin, temp);
406 sprintf (temp,"%f",currentTree.maxRtValue);
407 fl_set_input (rtmax, temp);
408 currentTree.rootColor.red = currentTree.rootAttribColor.red;
409 currentTree.rootColor.green = currentTree.rootAttribColor.green;
410 currentTree.rootColor.blue = currentTree.rootAttribColor.blue;
411 fl_activate_object (rootMinMaxGrp);
412 fl_activate_object (rootTypeColGrp);
413 currentTree.rootsChanged = TRUE;
414 } else {
415 fl_set_choice (obj, NORMAL);
416 fl_show_message ("A tree files must be selected","to change that root option!","");
417 }
418 }
419 }
420
421 /********************************************************************
422 * rootColorChoice_cb:
423 * associated with: the root color choice object
424 * task: determines which color was selected by the user and
425 * sets the root leaf and leaf attribute colors to the
426 * corresponding values.
427 ********************************************************************/
428
429 void rootColorChoice_cb (FL_OBJECT *obj, long arg)
430 {
431 currentTree.rootColorIndex = fl_get_choice (obj);
432 currentTree.rootAttribColor.red = 0.0;
433 currentTree.rootAttribColor.green = 0.0;
434 currentTree.rootAttribColor.blue = 0.0;
435 currentTree.rootColor.red = 0.0;
436 currentTree.rootColor.green = 0.0;
437 currentTree.rootColor.blue = 0.0;
438 switch (currentTree.rootColorIndex) {
439 case 1: /* color is blue */
440 currentTree.rootAttribColor.blue = 1.0;
441 currentTree.rootColor.blue = 1.0;
442 break;
443 case 2: /* color is green */
444 currentTree.rootAttribColor.green = 1.0;
445 currentTree.rootColor.green = 1.0;
446 break;
447 case 3: /* color is sea green */
448 currentTree.rootAttribColor.green = 1.0;
449 currentTree.rootAttribColor.blue = 1.0;
450 currentTree.rootColor.green = 1.0;
451 currentTree.rootColor.blue = 1.0;
452 break;
453 case 4: /* color is red */
454 currentTree.rootAttribColor.red = 1.0;
455 currentTree.rootColor.red = 1.0;
456 break;
457 case 5: /* color is magenta */
458 currentTree.rootAttribColor.red = 1.0;
459 currentTree.rootAttribColor.blue = 1.0;
460 currentTree.rootColor.red = 1.0;
461 currentTree.rootColor.blue = 1.0;
462 break;
463 case 6: /* color is yellow */
464 currentTree.rootAttribColor.red = 1.0;
465 currentTree.rootAttribColor.green = 1.0;
466 currentTree.rootColor.red = 1.0;
467 currentTree.rootColor.green = 1.0;
468 break;
469 case 7: /* color is white */
470 currentTree.rootAttribColor.red = 1.0;
471 currentTree.rootAttribColor.green = 1.0;
472 currentTree.rootAttribColor.blue = 1.0;
473 currentTree.rootColor.red = 1.0;
474 currentTree.rootColor.green = 1.0;
475 currentTree.rootColor.blue = 1.0;
476 break;
477 case 8: /* color is black */
478 currentTree.rootAttribColor.red = 0.0;
479 currentTree.rootAttribColor.green = 0.0;
480 currentTree.rootAttribColor.blue = 0.0;
481 currentTree.rootColor.red = 0.0;
482 currentTree.rootColor.green = 0.0;
483 currentTree.rootColor.blue = 0.0;
484 break;
485 }
486 currentTree.rootsChanged = TRUE;
487 }
488
489 /********************************************************************
490 * rootminValue_cb:
491 * associated with: the minimum root attribute input field
492 * task: takes the floating point value entered by user and
493 * sets the current tree's minimum root attribute value to it.
494 ********************************************************************/
495
496 void rootminValue_cb (FL_OBJECT *obj, long arg)
497 {
498 float temp;
499 strpointer valueStr;
500 valueStr = fl_get_input (obj);
501 temp = (float) atof (valueStr);
502 if (temp >= currentTree.minRtValueOrig) {
503 currentTree.minRtValue = temp;
504 } else {
505 sprintf (valueStr, "%f", currentTree.minRtValueOrig);
506 fl_set_input (rtmin, valueStr);
507 currentTree.minLfValue = currentTree.minRtValueOrig;
508 }
509 currentTree.rootsChanged = TRUE;
510 }
511
512 /********************************************************************
513 * rootmaxValue_cb:
514 * associated with: the maximum root attribute input field
515 * task: takes the floating point value entered by user and
516 * sets the current tree's maximum root attribute value to it.
517 *******************************************************************/
518
519 void rootmaxValue_cb (FL_OBJECT *obj, long arg)
520 {
521 float temp;
522 strpointer valueStr;
523 valueStr = fl_get_input (obj);
524 temp = (float) atof (valueStr);
525 if (temp <= currentTree.maxRtValueOrig) {
526 currentTree.maxRtValue = temp;
527 } else {
528 sprintf (valueStr, "%f", currentTree.maxRtValueOrig);
529 fl_set_input (rtmax, valueStr);
530 currentTree.maxRtValue = currentTree.maxRtValueOrig;
531 }
532 currentTree.rootsChanged = TRUE;
533 }
534
535 /********************************************************************
536 * resetRoots_cb:
537 * associated with: the "Reset" button for the min and max root
538 * attribute values
539 * task: sets the min and max root attribute values for the
540 * current tree to the original ones read from the file
541 ********************************************************************/
542
543 void resetRoots_cb (FL_OBJECT *obj, long arg)
544 {
545 string temp;
546 currentTree.minRtValue = currentTree.minRtValueOrig;
547 currentTree.maxRtValue = currentTree.maxRtValueOrig;
548 sprintf (temp, "%f", currentTree.minRtValue);
549 fl_set_input (rtmin, temp);
550 sprintf (temp, "%f", currentTree.maxRtValue);
551 fl_set_input (rtmax, temp);
552 currentTree.rootsChanged = TRUE;
553 }
554
555 /********************************************************************
556 * branchChoice_cb:
557 * associated with: the display branches choice object
558 * task: determines if the user selected to display or not to
559 * display the branches of the current and indicates that the
560 * branches should be redrawn during the next update.
561 ********************************************************************/
562
563 void branchChoice_cb (FL_OBJECT *obj, long arg)
564 {
565 if (fl_get_choice (brchChoice) == 1)
566 currentTree.displayBranches = FALSE;
567 else
568 currentTree.displayBranches = TRUE;
569 currentTree.branchChanged = TRUE;
570 }
571
572 /********************************************************************
573 * rootChoice_cb:
574 * associated with: the display roots choice object
575 * task: determines if the user selected to display or not to
576 * display the roots of the current tree and indicates that
577 * the roots should be redrawn during the next update.
578 ********************************************************************/
579
580 void rootChoice_cb (FL_OBJECT *obj, long arg)
581 {
582 int temp;
583 if (fl_get_choice (obj) == 1) {
584 currentTree.displayRoots = FALSE;
585 fl_deactivate_object (rootMinMaxGrp);
586 fl_deactivate_object (rootTypeColGrp);
587 } else {
588 currentTree.displayRoots = TRUE;
589 if (((temp = fl_get_choice (rootTypeChoice)) == NORMAL) ||
590 (temp == DOUBLE)) {
591 fl_deactivate_object (rootMinMaxGrp);
592 fl_activate_object (rootColorChoice);
593 } else {
594 fl_activate_object (rootMinMaxGrp);
595 fl_activate_object (rootColorChoice);
596 }
597 fl_activate_object (rootTypeChoice);
598 }
599 currentTree.rootsChanged = TRUE;
600 }
601
602 /********************************************************************
603 * sunChoice_cb:
604 * associated with: the display sunlight choice object
605 * task: determines if the user selected to display or not to
606 * display the sunlight vector on the next update of the tree.
607 ********************************************************************/
608
609 void sunChoice_cb (FL_OBJECT *obj, long arg)
610 {
611 if (fl_get_choice (obj) == 1)
612 currentTree.displaySun = FALSE;
613 else
614 currentTree.displaySun = TRUE;
615 }
616
617 /********************* end of formCallbacks.c *********************/
618