source: GTP/trunk/Lib/Vis/Preprocessing/src/X3dParserXerces.h @ 490

Revision 490, 7.0 KB checked in by mattausch, 19 years ago (diff)

added loading and storing rays capability

Line 
1#ifndef _X3D_PARSER_XERCES__H
2#define _X3D_PARSER_XERCES__H
3
4// ---------------------------------------------------------------------------
5//  Includes
6// ---------------------------------------------------------------------------
7#include <xercesc/sax/HandlerBase.hpp>
8#include "Mesh.h"
9
10XERCES_CPP_NAMESPACE_USE
11XERCES_CPP_NAMESPACE_BEGIN
12class AttributeList;
13XERCES_CPP_NAMESPACE_END
14
15class SceneGraphNode;
16class Mesh;
17class Material;
18class ViewCellsManager;
19
20class X3dParseHandlers : public HandlerBase
21{
22public:
23  // -----------------------------------------------------------------------
24  //  Constructors and Destructor
25  // -----------------------------------------------------------------------
26  X3dParseHandlers(SceneGraphNode *root);
27  ~X3dParseHandlers();
28 
29 
30  // -----------------------------------------------------------------------
31  //  Getter methods
32  // -----------------------------------------------------------------------
33  unsigned int GetElementCount()
34  {
35    return mElementCount;
36  }
37 
38  unsigned int GetAttrCount()
39  {
40    return mAttrCount;
41  }
42 
43  unsigned int GetCharacterCount()
44  {
45    return mCharacterCount;
46  }
47 
48  unsigned int GetSpaceCount()
49  {
50    return mSpaceCount;
51  }
52
53
54  // -----------------------------------------------------------------------
55  //  Handlers for the SAX DocumentHandler interface
56  // -----------------------------------------------------------------------
57  void endElement(const XMLCh* const name);
58  void startElement(const XMLCh* const name, AttributeList& attributes);
59  void characters(const XMLCh* const chars, const unsigned int length);
60  void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
61  void resetDocument();
62
63  SceneGraphNode *mCurrentNode;
64  Mesh *mCurrentMesh;
65  Material *mCurrentMaterial;
66  //int mCurrentObjectId;
67
68  // Handlers for X3D
69  void
70  StartIndexedFaceSet(
71                      AttributeList&  attributes);
72 
73  void
74  EndShape();
75
76  void
77  StartCoordinate(
78                  AttributeList&  attributes);
79
80  void
81  StartMaterial(
82                AttributeList&  attributes);
83 
84 
85  // -----------------------------------------------------------------------
86  //  Handlers for the SAX ErrorHandler interface
87  // -----------------------------------------------------------------------
88  void warning(const SAXParseException& exc);
89  void error(const SAXParseException& exc);
90  void fatalError(const SAXParseException& exc);
91 
92 
93private:
94  // -----------------------------------------------------------------------
95  //  Private data members
96  //
97  //  fAttrCount
98  //  fCharacterCount
99  //  fElementCount
100  //  fSpaceCount
101  //      These are just counters that are run upwards based on the input
102  //      from the document handlers.
103  // -----------------------------------------------------------------------
104  unsigned int    mAttrCount;
105  unsigned int    mCharacterCount;
106  unsigned int    mElementCount;
107  unsigned int    mSpaceCount;
108};
109
110/** Parser handlers for view cell x3d files.
111*/
112class X3dViewCellsParseHandlers : public HandlerBase
113{
114public:
115  // -----------------------------------------------------------------------
116  //  Constructors and Destructor
117  // -----------------------------------------------------------------------
118  X3dViewCellsParseHandlers(ViewCellsManager *viewCellsManager,
119                                                        float viewCellHeight);
120  ~X3dViewCellsParseHandlers();
121 
122 
123  // -----------------------------------------------------------------------
124  //  Getter methods
125  // -----------------------------------------------------------------------
126  unsigned int GetElementCount()
127  {
128    return mElementCount;
129  }
130 
131  unsigned int GetAttrCount()
132  {
133    return mAttrCount;
134  }
135 
136  unsigned int GetCharacterCount()
137  {
138    return mCharacterCount;
139  }
140 
141  unsigned int GetSpaceCount()
142  {
143    return mSpaceCount;
144  }
145
146
147  // -----------------------------------------------------------------------
148  //  Handlers for the SAX DocumentHandler interface
149  // -----------------------------------------------------------------------
150  void endElement(const XMLCh* const name);
151  void startElement(const XMLCh* const name, AttributeList& attributes);
152  void characters(const XMLCh* const chars, const unsigned int length);
153  void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
154  void resetDocument();
155
156  ViewCellsManager *mViewCellsManager;
157  float mViewCellHeight;
158
159  VertexIndexContainer mCurrentVertexIndices;
160
161  // Handlers for X3D
162  void
163  StartIndexedFaceSet(
164                      AttributeList&  attributes);
165 
166  void
167  EndShape();
168
169  void
170  StartCoordinate(
171                  AttributeList&  attributes);
172
173  void
174  StartMaterial(
175                AttributeList&  attributes);
176 
177 
178  // -----------------------------------------------------------------------
179  //  Handlers for the SAX ErrorHandler interface
180  // -----------------------------------------------------------------------
181  void warning(const SAXParseException& exc);
182  void error(const SAXParseException& exc);
183  void fatalError(const SAXParseException& exc);
184 
185 
186private:
187  // -----------------------------------------------------------------------
188  //  Private data members
189  //
190  //  fAttrCount
191  //  fCharacterCount
192  //  fElementCount
193  //  fSpaceCount
194  //      These are just counters that are run upwards based on the input
195  //      from the document handlers.
196  // -----------------------------------------------------------------------
197  unsigned int    mAttrCount;
198  unsigned int    mCharacterCount;
199  unsigned int    mElementCount;
200  unsigned int    mSpaceCount;
201};
202
203
204// ---------------------------------------------------------------------------
205//  This is a simple class that lets us do easy (though not terribly efficient)
206//  trancoding of XMLCh data to local code page for display.
207// ---------------------------------------------------------------------------
208class StrX
209{
210public :
211  // -----------------------------------------------------------------------
212  //  Constructors and Destructor
213  // -----------------------------------------------------------------------
214  StrX(const XMLCh* const toTranscode)
215  {
216    // Call the private transcoding method
217    mLocalForm = XMLString::transcode(toTranscode);
218  }
219 
220  ~StrX()
221  {
222    XMLString::release(&mLocalForm);
223  }
224 
225  // -----------------------------------------------------------------------
226  //  Getter methods
227  // -----------------------------------------------------------------------
228  const char* LocalForm() const
229  {
230    return mLocalForm;
231  }
232 
233private :
234  // -----------------------------------------------------------------------
235  //  Private data members
236  //
237  //  fLocalForm
238  //      This is the local code page form of the string.
239  // -----------------------------------------------------------------------
240  char*   mLocalForm;
241};
242
243inline XERCES_STD_QUALIFIER ostream&
244operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
245{
246  target << toDump.LocalForm();
247  return target;
248}
249
250#endif
Note: See TracBrowser for help on using the repository browser.