1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGVRMLWRITEACTION_H_
40 #define _OSGVRMLWRITEACTION_H_
45 //---------------------------------------------------------------------------
47 //---------------------------------------------------------------------------
52 #include "OSGFileIODef.h"
53 #include "OSGBaseTypes.h"
54 #include "OSGAction.h"
55 #include "OSGGeometry.h"
60 //---------------------------------------------------------------------------
62 //---------------------------------------------------------------------------
68 //---------------------------------------------------------------------------
70 //---------------------------------------------------------------------------
72 //---------------------------------------------------------------------------
74 //---------------------------------------------------------------------------
76 /*! \brief DrawAction class
77 \ingroup GrpFileIOWRLObj
78 \ingroup GrpLibOSGFileIO
81 class OSG_FILEIO_DLLMAPPING VRMLWriteAction
: public Action
85 //-----------------------------------------------------------------------
87 //-----------------------------------------------------------------------
91 OSGCollectFC
= 0x0001,
97 OSGNoOptions
= 0x0000,
99 OSGNoNormals
= 0x0002,
100 OSGPixelTextures
= 0x0004
103 //-----------------------------------------------------------------------
105 //-----------------------------------------------------------------------
107 //-----------------------------------------------------------------------
109 //-----------------------------------------------------------------------
111 static const char *getClassname(void) { return "VRMLWriteAction"; };
113 // create a new DrawAction by cloning the prototype
114 static VRMLWriteAction
* create( void );
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
);
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;
169 //-----------------------------------------------------------------------
171 //-----------------------------------------------------------------------
173 //-----------------------------------------------------------------------
175 //-----------------------------------------------------------------------
177 //-----------------------------------------------------------------------
179 //-----------------------------------------------------------------------
181 //-----------------------------------------------------------------------
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
);
205 //-----------------------------------------------------------------------
207 //-----------------------------------------------------------------------
209 //-----------------------------------------------------------------------
211 //-----------------------------------------------------------------------
213 typedef Action Inherited
;
217 struct ActionInitializer
219 ActionInitializer(void);
220 ~ActionInitializer(void);
237 FCInfo(const FCInfo
&source
);
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
);
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
259 void operator =(const FCInfo
&rhs
);
262 //-----------------------------------------------------------------------
264 //-----------------------------------------------------------------------
266 friend struct ActionInitializer
;
268 //-----------------------------------------------------------------------
270 //-----------------------------------------------------------------------
272 //-----------------------------------------------------------------------
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 //-----------------------------------------------------------------------
287 //-----------------------------------------------------------------------
290 static Action::ResultE
writeGroupEnter(NodeCore
* const pGroup
,
292 static Action::ResultE
writeGroupLeave(NodeCore
* const pGroup
,
295 static Action::ResultE
writeMatGroupEnter(NodeCore
* const pGroup
,
297 static Action::ResultE
writeMatGroupLeave(NodeCore
* const pGroup
,
300 static Action::ResultE
writeComponentTransformEnter(NodeCore
* const pGroup
,
302 static Action::ResultE
writeComponentTransformLeave(NodeCore
* const pGroup
,
305 static Action::ResultE
writeTransformEnter(NodeCore
* const pGroup
,
307 static Action::ResultE
writeTransformLeave(NodeCore
* const pGroup
,
310 static void writePoints ( Geometry
*pGeo
,
312 VRMLWriteAction
*pWriter
);
313 static void writePointSetPoints( Geometry
*pGeo
,
315 VRMLWriteAction
*pWriter
);
316 static void writeNormals ( Geometry
*pGeo
,
318 VRMLWriteAction
*pWriter
);
319 static void writeColors ( Geometry
*pGeo
,
321 VRMLWriteAction
*pWriter
);
322 static void writePointSetColors( Geometry
*pGeo
,
324 VRMLWriteAction
*pWriter
);
325 static void writeTexCoords ( Geometry
*pGeo
,
327 VRMLWriteAction
*pWriter
);
329 static void writeIndex ( Geometry
*pGeo
,
331 VRMLWriteAction
*pWriter
);
333 static void writeLineIndex ( Geometry
*pGeo
,
335 VRMLWriteAction
*pWriter
);
337 static void writeMaterial ( Geometry
*pGeo
,
339 VRMLWriteAction
*pWriter
);
341 static bool writeGeoCommon ( Node
*pNode
,
344 VRMLWriteAction
*pWriter
,
345 const Char8
*setTypename
);
347 static void writePointSet ( Node
*pNode
,
350 VRMLWriteAction
*pWriter
);
352 static void writeLineSet ( Node
*pNode
,
355 VRMLWriteAction
*pWriter
,
356 bool bSinglePrimitiveGeo
);
358 static void writeFaceSet ( Node
*pNode
,
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 //-----------------------------------------------------------------------
379 TraversalMode _eTraversalMode
;
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
;
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
);
427 #include "OSGVRMLWriteAction.inl"
429 #endif /* _OSGVRMLWRITEACTION_H_ */