FreeWRL / FreeX3D 4.3.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
57typedef struct { int type; int value; } _intX3D_SFBool;
58typedef struct { int type; float value; } _intX3D_SFFloat;
59typedef struct { int type; double value; } _intX3D_SFTime;
60typedef struct { int type; int value; } _intX3D_SFInt32;
61typedef struct { int type; int adr; } _intX3D_SFNode;
62typedef struct { int type; float r[4]; } _intX3D_SFRotation;
63typedef struct { int type; float c[2]; } _intX3D_SFVec2f;
64typedef struct { int type; double c[2]; } _intX3D_SFVec2d;
65typedef struct { int type; float c[3]; } _intX3D_SFColor;
66typedef struct { int type; float c[3]; } _intX3D_SFVec3f;
67typedef struct { int type; double c[3]; } _intX3D_SFVec3d;
68typedef struct { int type; float r[4]; } _intX3D_SFColorRGBA;
69typedef struct { int type; int len; char *strptr;} _intX3D_SFString;
70typedef struct { int type; int len; char *strptr;} _intX3D_SFImage;
71
72typedef struct { int type; int n; _intX3D_SFColor *p; } _intX3D_MFColor;
73typedef struct { int type; int n; _intX3D_SFColorRGBA *p; } _intX3D_MFColorRGBA;
74typedef struct { int type; int n; _intX3D_SFFloat *p; } _intX3D_MFFloat;
75typedef struct { int type; int n; _intX3D_SFTime *p; } _intX3D_MFTime;
76typedef struct { int type; int n; _intX3D_SFRotation *p; } _intX3D_MFRotation;
77typedef struct { int type; int n; _intX3D_SFVec3d *p; } _intX3D_MFVec3d;
78typedef struct { int type; int n; _intX3D_SFVec2d *p; } _intX3D_MFVec2d;
79typedef struct { int type; int n; _intX3D_SFVec3f *p; } _intX3D_MFVec3f;
80typedef struct { int type; int n; _intX3D_SFVec2f *p; } _intX3D_MFVec2f;
81typedef struct { int type; int n; _intX3D_SFBool *p; } _intX3D_MFBool;
82typedef struct { int type; int n; _intX3D_SFInt32 *p; } _intX3D_MFInt32;
83typedef struct { int type; int n; _intX3D_SFNode *p; } _intX3D_MFNode;
84typedef struct { int type; int n; _intX3D_SFString *p; } _intX3D_MFString;
85typedef struct { int type; int n; _intX3D_SFImage *p; } _intX3D_MFImage;
86
87typedef 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
148X3DNode *X3D_getNode (char *name);
149X3DNode *X3D_getExecutionContext();
150void X3D_rootNodeHandling(X3DNode* scene, X3DNode* node, int action); //1=add,2=remove
151X3DEventIn *X3D_getEventIn(X3DNode *node, char *name);
152X3DEventOut *X3D_getEventOut(X3DNode *node, char *name);
153void X3D_setValue (X3DEventIn *dest, X3DNode *node);
154void X3D_addRoute (X3DEventOut *from, X3DEventIn *to);
155void X3D_deleteRoute (X3DEventOut *from, X3DEventIn *to);
156char* X3D_getFieldDefs(int nodeAdr);
157X3DFieldDef* 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
161int 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.
163int X3D_getParentNodesbyName(char *childName, X3DNode** outChildNode, X3DNode** outParentArray);
164
165
166/* initialize, shutdown public methods */
167void X3D_initialize(char *);
168void X3D_shutdown();
169#ifdef WIN32
170#ifdef SWIG
171void* freewrlSwigThread(void *);
172#endif //SWIG
173int findFieldInFIELDTYPES(char *fieldtype);
174void X3D_freeNode(X3DNode* node);
175X3DNode* X3D_getValue (X3DEventOut *src);
176#else
177void freewrlSwigThread(void);
178#endif
179void *freewrlReadThread(void*);
180void *freewrlEVcallbackThread(void*);
181
182/* float public methods */
183float X3D_getCurrentSpeed();
184float X3D_getCurrentFrameRate();
185
186/* null public methods */
187void X3D_firstViewpoint();
188void X3D_lastViewpoint();
189void X3D_nextViewpoint();
190void X3D_previousViewpoint();
191void X3D_setDescription(char *newDescription);
192
193/* string return val public methods */
194char *X3D_getDescription();
195char *X3D_getName();
196char *X3D_getVersion();
197char *X3D_getWorldURL();
198
199/* MFNode public methods */
200X3DNode *X3D_createVrmlFromString(char *str);
201X3DNode *X3D_createX3DFromString(char *str);
202X3DNode *X3D_newSFVec3f (float a, float b, float c);
203X3DNode *X3D_newSFColor (float a, float b, float c);
204X3DNode *X3D_newSFVec2f (float a, float b);
205X3DNode *X3D_newSFRotation (float a, float b,float c, float d);
206X3DNode *X3D_newSFColorRGBA (float a, float b,float c, float d);
207X3DNode *X3D_newSFVec3d (double a, double b,double c);
208X3DNode *X3D_newSFVec2d (double a, double b);
209X3DNode *X3D_newSFBool (int a);
210X3DNode *X3D_newSFFloat (float a);
211X3DNode *X3D_newSFTime (double a);
212X3DNode *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
230extern int _X3D_queryno;
231extern int _X3D_FreeWRL_FD;
232extern int _X3D_FreeWRL_Swig_FD;
233extern int isSwig;
234int _X3D_countWords(char *ptr);
235char *_X3D_make1StringCommand (char command, char *name);
236char *_X3D_make2StringCommand (char command, char *str1, char *str2);
237char *_X3D_Browser_SendEventType(int adr,char *name, char *evtype);
238char *_X3D_makeShortCommand (char command);
239void _X3D_sendEvent (char command, char *string, int li);
240void _handleFreeWRLcallback(char *command);
241
242void X3D_error(char *msg);
243char *fieldTypeName(char type);
244
245char * _RegisterListener (X3DEventOut *node, int adin);
246int X3DAdvise (X3DEventOut *node, void *fn);
247int X3DAdviseArg (X3DEventOut *node, void *fn, void* arg);
248void _handleReWireCallback(char *buf);
249char mapFieldTypeToEAItype (int st);
250int mapEAItypeToFieldType (char st);
251X3DNode* X3D_getValue(X3DEventOut *src);
252void X3D_freeEventIn(X3DEventIn* ev);
253void X3D_freeEventOut(X3DEventOut* ev);
254void X3D_freeNode(X3DNode* node);
255X3DNode* X3D_newSFVec3f(float a, float b, float c);
256void X3D_getSFVec3f(X3DNode* node, float* value);
257X3DNode* X3D_newColor(float a, float b, float c);
258void X3D_getSFColor(X3DNode* node, float* value);
259X3DNode* X3D_newSFVec2f(float a, float b);
260void X3D_getSFVec2f(X3DNode* node, float* value);
261X3DNode* X3D_newSFRotation(float a, float b, float c, float d);
262void X3D_getSFRotation(X3DNode* node, float* value);
263X3DNode* X3D_newSFColorRGBA(float a, float b, float c, float d);
264void X3D_getSF(X3DNode* node, float* value);
265X3DNode* X3D_newSFBool(int a);
266void X3D_getSFBool(X3DNode* node, int* value);
267X3DNode* X3D_newSFFloat(float a);
268void X3D_getSFFloat(X3DNode* node, float* value);
269void X3D_getSFTime(X3DNode* node, double* value);
270X3DNode* X3D_newSFTime(double a);
271X3DNode* X3D_newSFInt32(int a);
272void X3D_getSFInt32(X3DNode* node, int* value);
273X3DNode* X3D_newSFString(char* a);
274char* X3D_getSFString(X3DNode* node);
275X3DNode* X3D_newMFInt32(int num, int* array);
276void X3D_getMFInt32(X3DNode*, int** array, int* num);
277X3DNode* X3D_newMFFloat(int num, float* array);
278void X3D_getMFFloat(X3DNode*, float** array, int* num);
279X3DNode* X3D_newMFVec3f(int num, float(* array)[3]);
280void X3D_getMFVec3f(X3DNode*, float*** array, int* num);
281X3DNode* X3D_newMFColor(int num, float(* array)[3]);
282void X3D_getMFColor(X3DNode*, float*** array, int* num);
283X3DNode* X3D_newMFVec2f(int num, float(* array)[2]);
284void X3D_getMFVec2f(X3DNode*, float*** array, int* num);
285X3DNode* X3D_newMFRotation(int num, float(* array)[4]);
286void X3D_getMFRotation(X3DNode*, float*** array, int* num);
287X3DNode* X3D_newMFColorRGBA(int num, float(* array)[4]);
288void X3D_getMFColorRGBA(X3DNode*, float*** array, int* num);
289X3DNode* X3D_newMFBool(int num, int* array);
290void X3D_getMFBool(X3DNode*, int** array, int* num);
291X3DNode* X3D_newMFVec3d(int num, double(* array)[3]);
292void X3D_getMFVec3d(X3DNode*, double*** array, int* num);
293X3DNode* X3D_newMFString(int num, char array[][STRLEN]);
294void X3D_getMFString(X3DNode* node, char*** array, int* num);
295X3DNode* X3D_newSFNode();
296X3DNode* X3D_newSFImage();
297X3DNode* X3D_newMFNode();
298
299#endif //_X3DNODE_H