fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / WRL / OSGVRMLWriteAction.h
blobc59176b2b1c4d6f8939c973fe93efb5f0026c233
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGVRMLWRITEACTION_H_
40 #define _OSGVRMLWRITEACTION_H_
41 #ifdef __sgi
42 #pragma once
43 #endif
45 //---------------------------------------------------------------------------
46 // Includes
47 //---------------------------------------------------------------------------
49 #include <vector>
50 #include <map>
52 #include "OSGFileIODef.h"
53 #include "OSGBaseTypes.h"
54 #include "OSGAction.h"
55 #include "OSGGeometry.h"
56 #include "OSGGroup.h"
58 OSG_BEGIN_NAMESPACE
60 //---------------------------------------------------------------------------
61 // Forward References
62 //---------------------------------------------------------------------------
64 class Node;
65 class Action;
66 class Material;
68 //---------------------------------------------------------------------------
69 // Types
70 //---------------------------------------------------------------------------
72 //---------------------------------------------------------------------------
73 // Class
74 //---------------------------------------------------------------------------
76 /*! \brief DrawAction class
77 \ingroup GrpFileIOWRLObj
78 \ingroup GrpLibOSGFileIO
81 class OSG_FILEIO_DLLMAPPING VRMLWriteAction : public Action
83 public:
85 //-----------------------------------------------------------------------
86 // enums
87 //-----------------------------------------------------------------------
89 enum TraversalMode
91 OSGCollectFC = 0x0001,
92 OSGWrite = 0x0002
95 enum WriterOption
97 OSGNoOptions = 0x0000,
98 OSGNoIndent = 0x0001,
99 OSGNoNormals = 0x0002,
100 OSGPixelTextures = 0x0004
103 //-----------------------------------------------------------------------
104 // types
105 //-----------------------------------------------------------------------
107 //-----------------------------------------------------------------------
108 // class functions
109 //-----------------------------------------------------------------------
111 static const char *getClassname(void) { return "VRMLWriteAction"; };
113 // create a new DrawAction by cloning the prototype
114 static VRMLWriteAction * create( void );
116 // prototype access
117 // after setting the prototype all new DrawActions are clones of it
118 static void setPrototype(VRMLWriteAction * proto);
119 static VRMLWriteAction *getPrototype(void);
121 //-----------------------------------------------------------------------
122 // instance functions
123 //-----------------------------------------------------------------------
125 virtual ~VRMLWriteAction(void);
127 /*------------------------- your_category -------------------------------*/
129 // default registration. static, so it can be called during static init
131 static void registerEnterDefault( const FieldContainerType &type,
132 const Functor &func);
134 static void registerLeaveDefault( const FieldContainerType &type,
135 const Functor &func);
138 // rendering state handling
140 Material *getMaterial(void) const;
141 void setMaterial(Material *material);
143 FILE *getFilePtr(void) const;
144 TraversalMode getMode (void) const;
146 /*------------------------- your_operators ------------------------------*/
148 bool open (const Char8 *szFilename);
149 void close(void);
151 /*------------------------- assignment ----------------------------------*/
153 void addOptions(UInt32 uiOptions);
154 void subOptions(UInt32 uiOptions);
156 UInt32 getOptions(void );
158 virtual Action::ResultE write(Node *node);
160 /*------------------------- comparison ----------------------------------*/
162 bool operator < (const VRMLWriteAction &other) const;
164 bool operator == (const VRMLWriteAction &other) const;
165 bool operator != (const VRMLWriteAction &other) const;
167 protected:
169 //-----------------------------------------------------------------------
170 // enums
171 //-----------------------------------------------------------------------
173 //-----------------------------------------------------------------------
174 // types
175 //-----------------------------------------------------------------------
177 //-----------------------------------------------------------------------
178 // class variables
179 //-----------------------------------------------------------------------
181 //-----------------------------------------------------------------------
182 // class functions
183 //-----------------------------------------------------------------------
185 //-----------------------------------------------------------------------
186 // instance variables
187 //-----------------------------------------------------------------------
189 //-----------------------------------------------------------------------
190 // instance functions
191 //-----------------------------------------------------------------------
193 // access default functors
195 virtual std::vector<Functor> *getDefaultEnterFunctors( void );
196 virtual std::vector<Functor> *getDefaultLeaveFunctors( void );
198 virtual Action::ResultE apply(std::vector<Node *>::iterator begin,
199 std::vector<Node *>::iterator end);
201 virtual Action::ResultE apply(Node * const node);
203 private:
205 //-----------------------------------------------------------------------
206 // enums
207 //-----------------------------------------------------------------------
209 //-----------------------------------------------------------------------
210 // types
211 //-----------------------------------------------------------------------
213 typedef Action Inherited;
215 /*! \nohierarchy
217 struct ActionInitializer
219 ActionInitializer(void);
220 ~ActionInitializer(void);
223 /*! \nohierarchy
225 struct FCInfo
227 private:
229 Int32 _iTimesUsed;
230 bool _bOwnName;
231 Char8 *_szName;
232 bool _bWritten;
234 public:
236 FCInfo(void);
237 FCInfo(const FCInfo &source);
238 ~FCInfo(void);
240 Char8 mapChar ( Char8 c);
241 void convertName( Char8 *&szName);
243 void setName (const Char8 *szName);
244 void buildName (const Char8 *szTypename,
245 UInt32 uiContainerId);
246 void incUse (void);
248 UInt32 getUse (void) const;
249 const Char8 *getName(void) const;
251 bool getWritten(void) const;
252 void setWritten (void);
254 // returnvalue required by MS
255 Int32 clear (void);
257 private:
259 void operator =(const FCInfo &rhs);
262 //-----------------------------------------------------------------------
263 // friend classes
264 //-----------------------------------------------------------------------
266 friend struct ActionInitializer;
268 //-----------------------------------------------------------------------
269 // friend functions
270 //-----------------------------------------------------------------------
272 //-----------------------------------------------------------------------
273 // class variables
274 //-----------------------------------------------------------------------
276 // the prototype which is copied to create new actions
277 static VRMLWriteAction * _prototype;
279 // default functors for instantiation
280 static std::vector<Functor> *_defaultEnterFunctors;
281 static std::vector<Functor> *_defaultLeaveFunctors;
283 static ActionInitializer _actionInitializer;
285 //-----------------------------------------------------------------------
286 // class functions
287 //-----------------------------------------------------------------------
290 static Action::ResultE writeGroupEnter(NodeCore * const pGroup,
291 Action *pAction);
292 static Action::ResultE writeGroupLeave(NodeCore * const pGroup,
293 Action *pAction);
295 static Action::ResultE writeMatGroupEnter(NodeCore * const pGroup,
296 Action *pAction);
297 static Action::ResultE writeMatGroupLeave(NodeCore * const pGroup,
298 Action *pAction);
300 static Action::ResultE writeComponentTransformEnter(NodeCore * const pGroup,
301 Action *pAction);
302 static Action::ResultE writeComponentTransformLeave(NodeCore * const pGroup,
303 Action *pAction);
305 static Action::ResultE writeTransformEnter(NodeCore * const pGroup,
306 Action *pAction);
307 static Action::ResultE writeTransformLeave(NodeCore * const pGroup,
308 Action *pAction);
310 static void writePoints ( Geometry *pGeo,
311 FILE *pFile,
312 VRMLWriteAction *pWriter);
313 static void writePointSetPoints( Geometry *pGeo,
314 FILE *pFile,
315 VRMLWriteAction *pWriter);
316 static void writeNormals ( Geometry *pGeo,
317 FILE *pFile,
318 VRMLWriteAction *pWriter);
319 static void writeColors ( Geometry *pGeo,
320 FILE *pFile,
321 VRMLWriteAction *pWriter);
322 static void writePointSetColors( Geometry *pGeo,
323 FILE *pFile,
324 VRMLWriteAction *pWriter);
325 static void writeTexCoords ( Geometry *pGeo,
326 FILE *pFile,
327 VRMLWriteAction *pWriter);
329 static void writeIndex ( Geometry *pGeo,
330 FILE *pFile,
331 VRMLWriteAction *pWriter);
333 static void writeLineIndex ( Geometry *pGeo,
334 FILE *pFile,
335 VRMLWriteAction *pWriter);
337 static void writeMaterial ( Geometry *pGeo,
338 FILE *pFile,
339 VRMLWriteAction *pWriter);
341 static bool writeGeoCommon ( Node *pNode,
342 Geometry *pGeo,
343 FILE *pFile,
344 VRMLWriteAction *pWriter,
345 const Char8 *setTypename);
347 static void writePointSet ( Node *pNode,
348 Geometry *pGeo,
349 FILE *pFile,
350 VRMLWriteAction *pWriter);
352 static void writeLineSet ( Node *pNode,
353 Geometry *pGeo,
354 FILE *pFile,
355 VRMLWriteAction *pWriter,
356 bool bSinglePrimitiveGeo);
358 static void writeFaceSet ( Node *pNode,
359 Geometry *pGeo,
360 FILE *pFile,
361 VRMLWriteAction *pWriter,
362 bool bSinglePrimitiveGeo);
364 static Action::ResultE writeGeoEnter(NodeCore * const pGroup, Action *pAction);
365 static Action::ResultE writeGeoLeave(NodeCore * const pGroup, Action *pAction);
367 static bool initializeAction(void);
368 static bool terminateAction (void);
370 //-----------------------------------------------------------------------
371 // instance variables
372 //-----------------------------------------------------------------------
374 Material *_material;
376 UInt32 _uiIndent;
377 FILE *_pFile;
379 TraversalMode _eTraversalMode;
380 bool _currentUse;
381 UInt32 _uiOptions;
383 //std::vector<FCInfo> _vFCInfos;
384 typedef std::map<UInt32, FCInfo *> FCInfosMap;
385 FCInfosMap _vFCInfos;
387 // this is a quick hack to get material sharing to work.
388 // I don't understand the reasoning and design of the FCInfo stuff and
389 // don't have time to do it right. :( DR 040106
390 std::vector<FieldContainer *> _writtenFCs;
392 UInt32 _nodeCount;
393 UInt32 _currentNodeCount;
395 //-----------------------------------------------------------------------
396 // instance functions
397 //-----------------------------------------------------------------------
399 // prohibit default functions (move to 'public' if you need one)
401 VRMLWriteAction(void);
402 VRMLWriteAction(const VRMLWriteAction &source);
403 VRMLWriteAction& operator =(const VRMLWriteAction &source);
405 void incIndent (UInt32 uiDelta);
406 void decIndent (UInt32 uiDelta);
407 void printIndent(void);
409 void setCurrentUse (bool bVal );
410 bool isCurrentUse (void );
412 void addNodeUse (Node *pNode );
413 void addContainerUse(FieldContainer *pContainer);
415 void clearInfos (void);
416 FCInfo *getInfo (FieldContainer *pContainer);
418 void updateProgress (void );
420 inline bool isWritten (FieldContainer *fc);
421 inline UInt32 getIndex (FieldContainer *fc);
422 inline UInt32 setWritten(FieldContainer *fc);
425 OSG_END_NAMESPACE
427 #include "OSGVRMLWriteAction.inl"
429 #endif /* _OSGVRMLWRITEACTION_H_ */