FreeWRL/FreeX3D  3.0.0
X3DNode.h
1 
2 /****************************************************************************
3  This file is part of the FreeWRL/FreeX3D Distribution.
4 
5  Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
6 
7  FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
8  it under the terms of the GNU Lesser Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  FreeWRL/FreeX3D is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
19 ****************************************************************************/
20 
21 #ifndef _X3DNODE_H
22 #define _X3DNODE_H
23 
24 #ifdef WIN32
25  #ifndef WIN32_LEAN_AND_MEAN
26  #define WIN32_LEAN_AND_MEAN
27  #endif
28 
29  #define strdup _strdup
30  #include <winsock2.h>
31  #include <ws2tcpip.h> /* for TCPIP - are we using tcp? */
32  #include <windows.h>
33 #else
34  #include <sys/socket.h>
35  #include <netinet/in.h>
36  #include <netdb.h>
37 #endif
38 
39 #include <sys/types.h>
40 #include <stdint.h>
41 #ifdef HAVE_UNISTD_H
42  #include <unistd.h>
43 #else
44  #include <stdio.h>
45 #endif
46 
47 #ifdef HAVE_STRINGS_H
48  #include <strings.h>
49 #endif
50 
51 #include <string.h>
52 #include <stdlib.h>
53 #include <pthread.h>
54 
55 #define STRLEN 256
56 
57 typedef struct { int type; int value; } _intX3D_SFBool;
58 typedef struct { int type; float value; } _intX3D_SFFloat;
59 typedef struct { int type; double value; } _intX3D_SFTime;
60 typedef struct { int type; int value; } _intX3D_SFInt32;
61 typedef struct { int type; int adr; } _intX3D_SFNode;
62 typedef struct { int type; float r[4]; } _intX3D_SFRotation;
63 typedef struct { int type; float c[2]; } _intX3D_SFVec2f;
64 typedef struct { int type; double c[2]; } _intX3D_SFVec2d;
65 typedef struct { int type; float c[3]; } _intX3D_SFColor;
66 typedef struct { int type; float c[3]; } _intX3D_SFVec3f;
67 typedef struct { int type; double c[3]; } _intX3D_SFVec3d;
68 typedef struct { int type; float r[4]; } _intX3D_SFColorRGBA;
69 typedef struct { int type; int len; char *strptr;} _intX3D_SFString;
70 typedef struct { int type; int len; char *strptr;} _intX3D_SFImage;
71 
72 typedef struct { int type; int n; _intX3D_SFColor *p; } _intX3D_MFColor;
73 typedef struct { int type; int n; _intX3D_SFColorRGBA *p; } _intX3D_MFColorRGBA;
74 typedef struct { int type; int n; _intX3D_SFFloat *p; } _intX3D_MFFloat;
75 typedef struct { int type; int n; _intX3D_SFTime *p; } _intX3D_MFTime;
76 typedef struct { int type; int n; _intX3D_SFRotation *p; } _intX3D_MFRotation;
77 typedef struct { int type; int n; _intX3D_SFVec3d *p; } _intX3D_MFVec3d;
78 typedef struct { int type; int n; _intX3D_SFVec2d *p; } _intX3D_MFVec2d;
79 typedef struct { int type; int n; _intX3D_SFVec3f *p; } _intX3D_MFVec3f;
80 typedef struct { int type; int n; _intX3D_SFVec2f *p; } _intX3D_MFVec2f;
81 typedef struct { int type; int n; _intX3D_SFBool *p; } _intX3D_MFBool;
82 typedef struct { int type; int n; _intX3D_SFInt32 *p; } _intX3D_MFInt32;
83 typedef struct { int type; int n; _intX3D_SFNode *p; } _intX3D_MFNode;
84 typedef struct { int type; int n; _intX3D_SFString *p; } _intX3D_MFString;
85 typedef struct { int type; int n; _intX3D_SFImage *p; } _intX3D_MFImage;
86 
87 typedef union _X3DNode {
88  int type;
89  _intX3D_MFBool X3D_MFBool;
90  _intX3D_SFBool X3D_SFBool;
91  _intX3D_SFFloat X3D_SFFloat;
92  _intX3D_SFTime X3D_SFTime;
93  _intX3D_SFInt32 X3D_SFInt32;
94  _intX3D_MFColor X3D_MFColor;
95  _intX3D_MFColorRGBA X3D_MFColorRGBA;
96  _intX3D_SFString X3D_SFString;
97  _intX3D_SFNode X3D_SFNode;
98  _intX3D_SFRotation X3D_SFRotation;
99  _intX3D_SFVec2f X3D_SFVec2f;
100  _intX3D_SFVec2d X3D_SFVec2d;
101  _intX3D_SFColor X3D_SFColor;
102  _intX3D_SFColor X3D_SFVec3f;
103  _intX3D_SFVec3d X3D_SFVec3d;
104  _intX3D_SFColorRGBA X3D_SFColorRGBA;
105  _intX3D_MFFloat X3D_MFFloat;
106  _intX3D_MFTime X3D_MFTime;
107  _intX3D_MFInt32 X3D_MFInt32;
108  _intX3D_MFString X3D_MFString;
109  _intX3D_MFNode X3D_MFNode;
110  _intX3D_MFRotation X3D_MFRotation;
111  _intX3D_MFVec2f X3D_MFVec2f;
112  _intX3D_MFVec3f X3D_MFVec3f;
113  _intX3D_MFImage X3D_MFImage;
114  _intX3D_MFVec3d X3D_MFVec3d;
115 
116 } X3DNode;
117 
118 #ifndef TRUE
119 #define TRUE 1==1
120 #endif
121 #ifndef FALSE
122 #define FALSE 1!=1
123 #endif
124 
125 #define REMOVE_EOT {char *lp; lp=strstr(ptr,"RE_EOT"); if (lp!=NULL) {lp--; *lp='\0';}};
126 #define SKIP_IF_GT_SPACE while (*ptr > ' ') ptr++;
127 #define SKIP_CONTROLCHARS while ((*ptr != '\0') && (*ptr <= ' ')) ptr++;
128 
129 
130 /* structures */
131 
132 
134  int nodeptr;
135  int offset;
136  int datatype;
137  int datasize;
138  int scripttype;
139  char *field;
140 };
141 
142 #define X3DEventIn struct _intX3DEventIn
143 #define X3DEventOut struct _intX3DEventIn
144 #define X3DFieldDef struct _intX3DEventIn
145 /* single value structures */
146 
147 
148 X3DNode *X3D_getNode (char *name);
149 X3DNode *X3D_getExecutionContext();
150 void X3D_rootNodeHandling(X3DNode* scene, X3DNode* node, int action); //1=add,2=remove
151 X3DEventIn *X3D_getEventIn(X3DNode *node, char *name);
152 X3DEventOut *X3D_getEventOut(X3DNode *node, char *name);
153 void X3D_setValue (X3DEventIn *dest, X3DNode *node);
154 void X3D_addRoute (X3DEventOut *from, X3DEventIn *to);
155 void X3D_deleteRoute (X3DEventOut *from, X3DEventIn *to);
156 char* X3D_getFieldDefs(int nodeAdr);
157 X3DFieldDef* X3D_getFieldDef(X3DNode *node, char *name);
158 
159 //writes all the parents of a given node into an allocated array and passes the address of it to the outParentArray argument. Caller should free the array.
160 //returns the number of parents, "0" if none found, "-1" if an error occurred
161 int X3D_getParentNodes(X3DNode* child, X3DNode** outParentArray);
162 //same as above, but also get the child node using the DEF name passed and copy the address of it into the outChildNode argument.
163 int X3D_getParentNodesbyName(char *childName, X3DNode** outChildNode, X3DNode** outParentArray);
164 
165 
166 /* initialize, shutdown public methods */
167 void X3D_initialize(char *);
168 void X3D_shutdown();
169 #ifdef WIN32
170 #ifdef SWIG
171 void* freewrlSwigThread(void *);
172 #endif //SWIG
173 int findFieldInFIELDTYPES(char *fieldtype);
174 void X3D_freeNode(X3DNode* node);
175 X3DNode* X3D_getValue (X3DEventOut *src);
176 #else
177 void freewrlSwigThread(void);
178 #endif
179 void *freewrlReadThread(void*);
180 void *freewrlEVcallbackThread(void*);
181 
182 /* float public methods */
183 float X3D_getCurrentSpeed();
184 float X3D_getCurrentFrameRate();
185 
186 /* null public methods */
187 void X3D_firstViewpoint();
188 void X3D_lastViewpoint();
189 void X3D_nextViewpoint();
190 void X3D_previousViewpoint();
191 void X3D_setDescription(char *newDescription);
192 
193 /* string return val public methods */
194 char *X3D_getDescription();
195 char *X3D_getName();
196 char *X3D_getVersion();
197 char *X3D_getWorldURL();
198 
199 /* MFNode public methods */
200 X3DNode *X3D_createVrmlFromString(char *str);
201 X3DNode *X3D_createX3DFromString(char *str);
202 X3DNode *X3D_newSFVec3f (float a, float b, float c);
203 X3DNode *X3D_newSFColor (float a, float b, float c);
204 X3DNode *X3D_newSFVec2f (float a, float b);
205 X3DNode *X3D_newSFRotation (float a, float b,float c, float d);
206 X3DNode *X3D_newSFColorRGBA (float a, float b,float c, float d);
207 X3DNode *X3D_newSFVec3d (double a, double b,double c);
208 X3DNode *X3D_newSFVec2d (double a, double b);
209 X3DNode *X3D_newSFBool (int a);
210 X3DNode *X3D_newSFFloat (float a);
211 X3DNode *X3D_newSFTime (double a);
212 X3DNode *X3D_newSFInt32 (int a);
213 //X3DNode *X3D_newSFString();
214 //X3DNode *X3D_newSFNode();
215 //X3DNode *X3D_newSFImage();
216 //X3DNode *X3D_newMFColor();
217 //X3DNode *X3D_newMFFloat();
218 //X3DNode *X3D_newMFTime();
219 //X3DNode *X3D_newMFInt32();
220 //X3DNode *X3D_newMFString();
221 //X3DNode *X3D_newMFNode();
222 //X3DNode *X3D_newMFRotation();
223 //X3DNode *X3D_newMFVec2f();
224 //X3DNode *X3D_newMFVec3f();
225 //X3DNode *X3D_newMFColorRGBA();
226 //X3DNode *X3D_newMFBool();
227 //X3DNode *X3D_newMFVec3d();
228 //X3DNode *X3D_newMFVec2d();
229 
230 extern int _X3D_queryno;
231 extern int _X3D_FreeWRL_FD;
232 extern int _X3D_FreeWRL_Swig_FD;
233 extern int isSwig;
234 int _X3D_countWords(char *ptr);
235 char *_X3D_make1StringCommand (char command, char *name);
236 char *_X3D_make2StringCommand (char command, char *str1, char *str2);
237 char *_X3D_Browser_SendEventType(int adr,char *name, char *evtype);
238 char *_X3D_makeShortCommand (char command);
239 void _X3D_sendEvent (char command, char *string, int li);
240 void _handleFreeWRLcallback(char *command);
241 
242 void X3D_error(char *msg);
243 char *fieldTypeName(char type);
244 
245 char * _RegisterListener (X3DEventOut *node, int adin);
246 int X3DAdvise (X3DEventOut *node, void *fn);
247 int X3DAdviseArg (X3DEventOut *node, void *fn, void* arg);
248 void _handleReWireCallback(char *buf);
249 char mapFieldTypeToEAItype (int st);
250 int mapEAItypeToFieldType (char st);
251 X3DNode* X3D_getValue(X3DEventOut *src);
252 void X3D_freeEventIn(X3DEventIn* ev);
253 void X3D_freeEventOut(X3DEventOut* ev);
254 void X3D_freeNode(X3DNode* node);
255 X3DNode* X3D_newSFVec3f(float a, float b, float c);
256 void X3D_getSFVec3f(X3DNode* node, float* value);
257 X3DNode* X3D_newColor(float a, float b, float c);
258 void X3D_getSFColor(X3DNode* node, float* value);
259 X3DNode* X3D_newSFVec2f(float a, float b);
260 void X3D_getSFVec2f(X3DNode* node, float* value);
261 X3DNode* X3D_newSFRotation(float a, float b, float c, float d);
262 void X3D_getSFRotation(X3DNode* node, float* value);
263 X3DNode* X3D_newSFColorRGBA(float a, float b, float c, float d);
264 void X3D_getSF(X3DNode* node, float* value);
265 X3DNode* X3D_newSFBool(int a);
266 void X3D_getSFBool(X3DNode* node, int* value);
267 X3DNode* X3D_newSFFloat(float a);
268 void X3D_getSFFloat(X3DNode* node, float* value);
269 void X3D_getSFTime(X3DNode* node, double* value);
270 X3DNode* X3D_newSFTime(double a);
271 X3DNode* X3D_newSFInt32(int a);
272 void X3D_getSFInt32(X3DNode* node, int* value);
273 X3DNode* X3D_newSFString(char* a);
274 char* X3D_getSFString(X3DNode* node);
275 X3DNode* X3D_newMFInt32(int num, int* array);
276 void X3D_getMFInt32(X3DNode*, int** array, int* num);
277 X3DNode* X3D_newMFFloat(int num, float* array);
278 void X3D_getMFFloat(X3DNode*, float** array, int* num);
279 X3DNode* X3D_newMFVec3f(int num, float(* array)[3]);
280 void X3D_getMFVec3f(X3DNode*, float*** array, int* num);
281 X3DNode* X3D_newMFColor(int num, float(* array)[3]);
282 void X3D_getMFColor(X3DNode*, float*** array, int* num);
283 X3DNode* X3D_newMFVec2f(int num, float(* array)[2]);
284 void X3D_getMFVec2f(X3DNode*, float*** array, int* num);
285 X3DNode* X3D_newMFRotation(int num, float(* array)[4]);
286 void X3D_getMFRotation(X3DNode*, float*** array, int* num);
287 X3DNode* X3D_newMFColorRGBA(int num, float(* array)[4]);
288 void X3D_getMFColorRGBA(X3DNode*, float*** array, int* num);
289 X3DNode* X3D_newMFBool(int num, int* array);
290 void X3D_getMFBool(X3DNode*, int** array, int* num);
291 X3DNode* X3D_newMFVec3d(int num, double(* array)[3]);
292 void X3D_getMFVec3d(X3DNode*, double*** array, int* num);
293 X3DNode* X3D_newMFString(int num, char array[][STRLEN]);
294 void X3D_getMFString(X3DNode* node, char*** array, int* num);
295 X3DNode* X3D_newSFNode();
296 X3DNode* X3D_newSFImage();
297 X3DNode* X3D_newMFNode();
298 
299 #endif //_X3DNODE_H