FreeWRL/FreeX3D  3.0.0
Component_EventUtils.c
1 /*
2 
3 
4 X3D Event Utilities Component
5 
6 */
7 
8 
9 /****************************************************************************
10  This file is part of the FreeWRL/FreeX3D Distribution.
11 
12  Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
13 
14  FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
15  it under the terms of the GNU Lesser Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  FreeWRL/FreeX3D is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  GNU General Public License for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
26 ****************************************************************************/
27 
28 
29 
30 #include <config.h>
31 #include <system.h>
32 #include <display.h>
33 #include <internal.h>
34 
35 #include <libFreeWRL.h>
36 
37 #include "../vrml_parser/Structs.h"
38 #include "../vrml_parser/CRoutes.h"
39 #include "../main/headers.h"
40 
41 
42 /******************************************************************************/
43 /* see the spec for a description. fields inputTrue and inputFalse are set in
44  VRMLNodes.pm and are never changed, ONLY MARK_EVENT is called when
45  appropriate. So, inputFalse will ALWAYS be false, BUT, the event will
46  be called when set_boolean is set to false. */
47 
48 void do_BooleanFilter (void *node){
49  struct X3D_BooleanFilter *px;
50 
51  if (!node) return;
52  px = (struct X3D_BooleanFilter *) node;
53 
54  if (px->set_boolean == TRUE) {
55  px->inputNegate = FALSE;
56  MARK_EVENT (node, offsetof (struct X3D_BooleanFilter, inputTrue));
57  MARK_EVENT (node, offsetof (struct X3D_BooleanFilter, inputNegate));
58  } else {
59  px->inputNegate = TRUE;
60  MARK_EVENT (node, offsetof (struct X3D_BooleanFilter, inputFalse));
61  MARK_EVENT (node, offsetof (struct X3D_BooleanFilter, inputNegate));
62  }
63 }
64 
65 /******************************************************************************/
66 /* see the spec for a description */
67 
68 /* WHAT ARE NEXT AND PREVIOUS FIELDS FOR???? NOT MENTIONED IN SPEC (AT LEAST
69 REVISION FOUND WHEN IMPLEMENTING */
70 
71 void do_BooleanSequencer (void *node){
72  struct X3D_BooleanSequencer *px;
73  int kin, kvin;
74  int *kVs;
75  int counter;
76  int oldValue;
77 
78  if (!node) return;
79  px = (struct X3D_BooleanSequencer *) node;
80  kin = px->key.n;
81  kvin = px->keyValue.n;
82  kVs = px->keyValue.p;
83 
84  oldValue = px->value_changed;
85 
86 
87  /* make sure we have the keys and keyValues */
88  if ((kvin == 0) || (kin == 0)) {
89  px->value_changed = 0; //(float) 0.0;
90  return;
91  }
92  if (kin>kvin) kin=kvin; /* means we don't use whole of keyValue, but... */
93 
94  #ifdef SEVERBOSE
95  printf ("BooleanSequencer, kin %d kvin %d, vc %f\n",kin,kvin,px->value_changed);
96  printf (" and set_fraction is %f\n",px->set_fraction);
97  #endif
98 
99  /* set_fraction less than or greater than keys */
100  if (px->set_fraction <= px->key.p[0]) {
101  px->value_changed = kVs[0];
102  } else if (px->set_fraction >= px->key.p[kin-1]) {
103  px->value_changed = kVs[kvin-1];
104  } else {
105  /* have to go through and find the key before */
106  counter=find_key(kin,(float)(px->set_fraction),px->key.p);
107  /* printf ("counter %d\n",counter); */
108  //px->value_changed = px->key.p[counter]; //yikes - key is a MF float
109  //should it be keyvalue? like integer_sequencer?:
110  /* bounds check */
111  if (counter >= px->keyValue.n) counter = px->keyValue.n-1;
112  px->value_changed = px->keyValue.p[counter];
113 
114  }
115 
116  if (oldValue != px->value_changed) {
117  MARK_EVENT (node, offsetof (struct X3D_BooleanSequencer, value_changed));
118  }
119 }
120 
121 
122 /******************************************************************************/
123 /* see the spec for a description */
124 void do_BooleanToggle (void *node){
125  struct X3D_BooleanToggle *px;
126  int oldBoolean;
127 
128  if (!node) return;
129  px = (struct X3D_BooleanToggle *) node;
130 
131  oldBoolean = px->toggle;
132 
133  if (px->set_boolean == TRUE) px->toggle = FALSE;
134  else px->toggle = TRUE;
135  if (oldBoolean != px->toggle) MARK_EVENT (node, offsetof (struct X3D_BooleanToggle, toggle));
136 }
137 
138 /******************************************************************************/
139 /* see the spec for a description */
140 void do_BooleanTrigger (void *node){
141  struct X3D_BooleanTrigger *px;
142 
143  if (!node) return;
144  px = (struct X3D_BooleanTrigger *) node;
145 
146  px->triggerTrue = TRUE; /* spec says that this is ALWAYS true */
147  MARK_EVENT (node, offsetof (struct X3D_BooleanTrigger, triggerTrue));
148 }
149 
150 /******************************************************************************/
151 /* see the spec for a description */
152 
153 /* WHAT ARE NEXT AND PREVIOUS FIELDS FOR???? NOT MENTIONED IN SPEC (AT LEAST
154 REVISION FOUND WHEN IMPLEMENTING */
155 
156 void do_IntegerSequencer (void *node){
157  struct X3D_IntegerSequencer *px;
158  int kin, kvin;
159  int *kVs;
160  int counter;
161 
162  if (!node) return;
163  px = (struct X3D_IntegerSequencer *) node;
164  kin = px->key.n;
165  kvin = px->keyValue.n;
166  kVs = px->keyValue.p;
167 
168  MARK_EVENT (node, offsetof (struct X3D_IntegerSequencer, value_changed));
169 
170  #ifdef SEVERBOSE
171  printf ("IntegerSequencer, kin %d kvin %d, sf %f vc %d\n",kin,kvin,px->set_fraction, px->value_changed);
172  #endif
173 
174  /* make sure we have the keys and keyValues */
175  if ((kvin == 0) || (kin == 0)) {
176  px->value_changed = 0;
177  return;
178  }
179  if (kin>kvin) kin=kvin; /* means we don't use whole of keyValue, but... */
180 
181  /* set_fraction less than or greater than keys */
182  if (px->set_fraction <= px->key.p[0]) {
183  px->value_changed = kVs[0];
184  } else if (px->set_fraction >= px->key.p[kin-1]) {
185  px->value_changed = kVs[kvin-1];
186  } else {
187  /* have to go through and find the key before */
188 
189  counter=find_key(kin+1,(float)(px->set_fraction),px->key.p)-1;
190 
191  /* bounds check */
192  if (counter >= px->keyValue.n) counter = px->keyValue.n-1;
193 
194  px->value_changed =
195  px->keyValue.p[counter];
196  }
197 }
198 
199 /******************************************************************************/
200 /* see the spec for a description */
201 void do_IntegerTrigger (void *node){
202  struct X3D_IntegerTrigger *px;
203 
204  if (!node) return;
205 
206  px = (struct X3D_IntegerTrigger *) node;
207 
208  //specs: "The value of set_boolean shall be ignored."
209  //if (px->set_boolean == TRUE) {
210  px->triggerValue = px->integerKey;
211  MARK_EVENT (node, offsetof (struct X3D_IntegerTrigger,triggerValue));
212  //} else {
214  //}
215 
216 
217 
218 }
219 
220 /******************************************************************************/
221 /* see the spec for a description */
222 void do_TimeTrigger (void *node){
223  struct X3D_TimeTrigger *px;
224 
225  if (!node) return;
226  px = (struct X3D_TimeTrigger *) node;
227 
228  px->triggerTime = TickTime();
229  MARK_EVENT (node, offsetof (struct X3D_TimeTrigger,triggerTime));
230 }
231