ModelScene.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (c) 2006 by Autodesk, Inc.
00003 //
00004 //  By using this code, you are agreeing to the terms and conditions of
00005 //  the License Agreement included in the documentation for this code.
00006 //
00007 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED, AS TO THE CORRECTNESS
00008 //  OF THIS CODE OR ANY DERIVATIVE WORKS WHICH INCORPORATE IT. AUTODESK
00009 //  PROVIDES THE CODE ON AN "AS-IS" BASIS AND EXPLICITLY DISCLAIMS ANY
00010 //  LIABILITY, INCLUDING CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00011 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00012 //
00013 //  Use, duplication, or disclosure by the U.S. Government is subject to
00014 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00015 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00016 //  Data and Computer Software), as applicable.
00017 //
00018 
00019 
00020 #ifndef _DWFTK_MODEL_SCENE_H
00021 #define _DWFTK_MODEL_SCENE_H
00022 
00023 
00028 
00029 #include "dwfcore/STL.h"
00030 #include "dwfcore/Vector.h"
00031 #include "dwfcore/String.h"
00032 using namespace DWFCore;
00033 
00034 #include "dwf/Toolkit.h"
00035 #include "dwf/package/XML.h"
00036 #include "dwf/w3dtk/BOpcodeHandler.h"
00037 #include "dwf/w3dtk/W3DCamera.h"
00038 #include "dwf/publisher/model/AttributeHandlerBuilder.h"
00039 #include "dwf/publisher/model/GeometryHandlerBuilder.h"
00040 #include "dwf/publisher/model/FeatureHandlerBuilder.h"
00041 
00042 //
00043 // fwd decl
00044 //
00045 class TK_Color;
00046 class TK_Color_RGB;
00047 class TK_Cutting_Plane;
00048 class TK_Matrix;
00049 class TK_Visibility;
00050 class W3DCamera;
00051 
00052 namespace DWFToolkit
00053 {
00054 
00055 //
00056 // fwd decl
00057 //
00058 class DWFInstance;
00059 
00067 class DWFModelSceneChangeHandler
00068 #ifndef DWFTK_READ_ONLY
00069                     : public DWFXMLSerializable
00070 #endif
00071 {
00072 public:
00080     class UserAttribute
00081     {
00082     public:
00086         typedef DWFOrderedVector<UserAttribute*>            tList;
00087 
00088     public:
00089         UserAttribute( const DWFString& zName,
00090                         const DWFString& zValue,
00091                         const DWFString& zNamespace )
00092                         : _zName( zName )
00093                         , _zValue( zValue )
00094                         , _zNamespace( zNamespace )
00095         {
00096             ;
00097         }
00098 
00099     public:
00106         const DWFString& name() const
00107             throw()
00108         {
00109             return _zName;
00110         }
00111 
00118         const DWFString& value() const
00119             throw()
00120         {
00121             return _zValue;
00122         }
00123 
00130         const DWFString& nameSpace() const
00131             throw()
00132         {
00133             return _zNamespace;
00134         }
00135 
00136     private:
00137         DWFString   _zName;
00138         DWFString   _zValue;
00139         DWFString   _zNamespace;
00140     };
00141 
00142     UserAttribute::tList  _oUserAttributes;
00143 
00150     typedef enum
00151     {
00155         eSceneLevel,
00156 
00160         eInstanceLevel
00161     } teChangeType;
00162 
00168         _DWFTK_API
00169     virtual ~DWFModelSceneChangeHandler()
00170         throw();
00171     
00178     virtual DWFModelSceneChangeHandler* clone () const
00179         throw() = 0;
00180 
00187     virtual teChangeType changeType () const
00188         throw() = 0;
00189     
00202         _DWFTK_API
00203     virtual void addUserAttribute( const DWFString& zName,
00204                                    const DWFString& zValue,
00205                                    const DWFString& zNamespace )
00206     throw( DWFException );
00207     
00218     virtual UserAttribute::tList::Iterator* getUserAttributes()
00219         throw()
00220     {
00221         return _oUserAttributes.iterator();
00222     }
00223 
00224 #ifndef DWFTK_READ_ONLY
00228         _DWFTK_API
00229     void serializeXML( DWFXMLSerializer& rSerializer, unsigned int nFlags )
00230         throw( DWFException );
00231 #endif
00232 
00233 private:
00234 };
00235 
00236 
00244 class DWFModelScene : public DWFAttributeHandlerBuilder
00245                     , public DWFGeometryHandlerBuilder
00246                     , public DWFFeatureHandlerBuilder
00247                     , public BaseOpcodeHandlerObserver
00248 #ifndef DWFTK_READ_ONLY
00249                     , public DWFXMLSerializable
00250 #endif
00251                     _DWFTK_EXPORT_API_MEMORY_CONTROL_BASE_MEMBER
00252 {
00253 
00254 public:
00255 
00262     typedef enum
00263     {
00267         eCamera                 = 0x0001,
00268 
00272         eColor                  = 0x0002,
00273 
00277         eCuttingPlane           = 0x0004,
00278 
00282         eModellingMatrix        = 0x0008,
00283 
00287         eTextureMatrix          = 0x0010,
00288 
00292         eVisibility             = 0x0020,
00293 
00297         eInstanceVisibility     = 0x0040,
00298 
00302         eInstanceTransparency   = 0x0080,
00303 
00307         eGeometricVariation     = 0x0100,
00308 
00312         eDisplayMode            = 0x0200
00313     } teAttributeType;
00314 
00322     typedef enum
00323     {
00327         eShaded = 0x01,
00330         eEdges =  0x02
00331 
00332     } teDisplayMode;
00333 
00339     _DWFTK_API
00340     DWFModelScene()
00341         throw();
00342 
00348     _DWFTK_API
00349     virtual ~DWFModelScene()
00350         throw();
00351 
00358     _DWFTK_API
00359     virtual void setCurrentInstance( const DWFInstance& rInstance )
00360         throw( DWFException );
00361 
00368     _DWFTK_API
00369     virtual void setCurrentInstanceID( const DWFString& zID )
00370         throw( DWFException );
00371 
00380     _DWFTK_API
00381     virtual void setCamera( const W3DCamera& rCamera, bool bSmoothTransition )
00382         throw( DWFException );
00383 
00387     _DWFTK_API
00388     virtual TK_Color& getColorHandler()
00389         throw( DWFException );
00390 
00394     _DWFTK_API
00395     virtual TK_Cutting_Plane& getCuttingPlaneHandler()
00396         throw( DWFException );
00397 
00401     _DWFTK_API
00402     virtual TK_Matrix& getModellingMatrixHandler()
00403         throw( DWFException );
00404 
00408     _DWFTK_API
00409     virtual TK_Matrix& getTextureMatrixHandler()
00410         throw( DWFException );
00411 
00415     _DWFTK_API
00416     virtual TK_Visibility& getVisibilityHandler()
00417         throw( DWFException );
00418 
00425     _DWFTK_API
00426     virtual void setGeometricVariationIndex( unsigned int nIndex )
00427         throw( DWFException );
00428 
00436     _DWFTK_API
00437     virtual void setVisibility( bool bVisibility )
00438         throw( DWFException );
00439 
00447     _DWFTK_API
00448     virtual void setTransparency( bool bTransparency )
00449         throw( DWFException );
00450 
00458     _DWFTK_API
00459     virtual void lockAttribute( teAttributeType eType )
00460         throw( DWFException );
00461 
00468     _DWFTK_API
00469     virtual void unlockAttribute( teAttributeType eType )
00470         throw( DWFException );
00471 
00479     _DWFTK_API
00480     virtual void setDisplayMode( unsigned int nDisplayMode )
00481         throw( DWFException );
00482 
00489     _DWFTK_API
00490     virtual void open()
00491         throw( DWFException )
00492     {
00493         ;
00494     }
00495 
00502     _DWFTK_API
00503     virtual void close()
00504         throw( DWFException );
00505 
00506 #ifndef DWFTK_READ_ONLY
00510     _DWFTK_API
00511     virtual void serializeXML( DWFXMLSerializer& rSerializer, unsigned int nFlags )
00512         throw( DWFException );
00513 #endif
00514 
00515 
00516 protected:
00517 
00518     class _W3DXMLPseudoHandler : public BBaseOpcodeHandler
00519                                , public DWFModelSceneChangeHandler
00520     {
00521     public:
00522         _W3DXMLPseudoHandler() : BBaseOpcodeHandler( (unsigned char)(-1) ) {;}
00523         _W3DXMLPseudoHandler( const _W3DXMLPseudoHandler& ) : BBaseOpcodeHandler( (unsigned char)(-1) ) {;}
00524         virtual ~_W3DXMLPseudoHandler()
00525             throw()
00526         {;}
00527 
00528         virtual TK_Status Read (BStreamFileToolkit&) { _DWFCORE_THROW( DWFUnexpectedException, /*NOXLATE*/L"This handler cannot be materialized into the scene graph" ); }
00529         virtual TK_Status Write (BStreamFileToolkit&) { _DWFCORE_THROW( DWFUnexpectedException, /*NOXLATE*/L"This handler cannot be serialized from the scene graph" ); }
00530     private:
00531         _W3DXMLPseudoHandler& operator=( const _W3DXMLPseudoHandler& rHandler );
00532     };
00533 
00534     class _W3DInstance : public _W3DXMLPseudoHandler
00535     {
00536     public:
00537         _W3DInstance() {;}
00538         _W3DInstance( const DWFString& zID )
00539             : _zID( zID )
00540         {;}
00541         _W3DInstance( const _W3DInstance& rInstance )
00542             : _W3DXMLPseudoHandler( rInstance )
00543             , _zID( rInstance._zID )
00544         {;}
00545         virtual ~_W3DInstance()
00546             throw()
00547         {;}
00548         virtual DWFModelSceneChangeHandler* clone () const 
00549             throw()
00550         {
00551             return DWFCORE_ALLOC_OBJECT( _W3DInstance(*this) );
00552         }
00553 
00554         virtual teChangeType changeType () const
00555             throw()
00556         {
00557             return eSceneLevel;
00558         }
00559 
00560         const DWFString& id() const { return _zID; }
00561 
00562                 _DWFTK_API
00563         void serializeXML( DWFXMLSerializer& rSerializer, unsigned int nFlags )
00564             throw( DWFException );
00565     private:
00566         DWFString       _zID;
00567     private:
00568         _W3DInstance& operator=( const _W3DInstance& );
00569     };
00570 
00571     class _W3DInstanceOptions : public _W3DXMLPseudoHandler
00572     {
00573     public:
00574         _W3DInstanceOptions() 
00575             : _nVisible( -1 )
00576             , _nTransparent( -1 )
00577             , _nVariation( -1 )
00578         {;}
00579         _W3DInstanceOptions( const _W3DInstanceOptions& rOptions )
00580             : _nVisible( rOptions._nVisible )
00581             , _nTransparent( rOptions._nTransparent )
00582             , _nVariation( rOptions._nVariation )
00583         {;}
00584         virtual ~_W3DInstanceOptions()
00585             throw()
00586         {;}
00587         virtual DWFModelSceneChangeHandler* clone () const
00588             throw()
00589         {
00590             return DWFCORE_ALLOC_OBJECT( _W3DInstanceOptions(*this) );
00591         }
00592         virtual teChangeType changeType () const
00593             throw()
00594         {
00595             return eInstanceLevel;
00596         }
00597 
00598         void show()         { _nVisible = 1; }
00599         void hide()         { _nVisible = 0; }
00600         void ghost()        { _nTransparent = 1; }
00601         void unghost()      { _nTransparent = 0; }
00602         void vary( int i )  { _nVariation = i; }
00603 
00604         int visible() const { return _nVisible; }
00605         int transparent() const { return _nTransparent; }
00606         int variation() const { return _nVariation; }
00607 
00608                 _DWFTK_API
00609         void serializeXML( DWFXMLSerializer& rSerializer, unsigned int nFlags )
00610             throw( DWFException );
00611     private:
00612         _W3DInstanceOptions& operator=( const _W3DInstanceOptions& );
00613 
00614     private:
00615         short   _nVisible;
00616         short   _nTransparent;
00617         int     _nVariation;
00618     };
00619 
00620     class _W3DAttributeLock : public _W3DXMLPseudoHandler
00621     {
00622     public:
00623         _W3DAttributeLock( DWFModelScene::teAttributeType eAttribute ) 
00624             : _bLock( true )
00625             , _eAttribute( eAttribute )
00626         {;}
00627         _W3DAttributeLock( const _W3DAttributeLock& rLock )
00628             : _bLock( rLock._bLock )
00629             , _eAttribute( rLock._eAttribute )
00630         {;}
00631         virtual ~_W3DAttributeLock()
00632             throw()
00633         {;}
00634         virtual DWFModelSceneChangeHandler* clone () const
00635             throw()
00636         {
00637             return DWFCORE_ALLOC_OBJECT( _W3DAttributeLock(*this) );
00638         }
00639         virtual teChangeType changeType () const
00640             throw()
00641         {
00642             return eInstanceLevel;
00643         }
00644 
00645         void lock() { _bLock = true; }
00646         void unlock() { _bLock = false; }
00647 
00648         bool locked() const { return (_bLock == true); }
00649         DWFModelScene::teAttributeType attribute() const { return _eAttribute; }
00650 
00651                 _DWFTK_API
00652         void serializeXML( DWFXMLSerializer& rSerializer, unsigned int nFlags )
00653             throw( DWFException );
00654     private:
00655         _W3DAttributeLock& operator=( const _W3DAttributeLock& );
00656 
00657     private:
00658         bool                            _bLock;
00659         DWFModelScene::teAttributeType  _eAttribute;
00660     };
00661 
00662     class _W3DCamera : public W3DCamera
00663                      , public _W3DXMLPseudoHandler
00664     {
00665     public:
00666         _W3DCamera()
00667             : W3DCamera()
00668             , _bSmoothTransition( false )
00669         {;}
00670         _W3DCamera( const W3DCamera& rCamera, bool bSmoothTransition )
00671             : W3DCamera( rCamera )
00672             , _bSmoothTransition( bSmoothTransition )
00673         {;}
00674         _W3DCamera( const _W3DCamera& rCamera ) 
00675             : W3DCamera( rCamera )
00676             , _bSmoothTransition( rCamera._bSmoothTransition) 
00677         {;}
00678         _W3DCamera& operator=( const _W3DCamera& rCamera ) { W3DCamera::operator=(rCamera); return *this; }
00679         virtual ~_W3DCamera()
00680             throw()
00681         {;}
00682         virtual DWFModelSceneChangeHandler* clone () const
00683             throw()
00684         {
00685             return DWFCORE_ALLOC_OBJECT( _W3DCamera(*this) );
00686         }
00687         virtual teChangeType changeType () const
00688             throw()
00689         {
00690             return eSceneLevel;
00691         }
00692     
00693                 _DWFTK_API
00694         void serializeXML( DWFXMLSerializer& rSerializer, unsigned int nFlags )
00695             throw( DWFException );
00696 
00697         bool smoothTransition() const { return _bSmoothTransition; }
00698     private:
00699         bool        _bSmoothTransition;
00700     };
00701 
00702     class _W3DColor : public TK_Color
00703                     , public DWFModelSceneChangeHandler
00704     {
00705     public:
00706         _W3DColor() : TK_Color() {;}
00707         _W3DColor(const _W3DColor& rColor) : TK_Color(rColor) {;}
00708         virtual ~_W3DColor()
00709             throw()
00710         {;}
00711             virtual DWFModelSceneChangeHandler* clone () const
00712             throw()
00713         {
00714             return DWFCORE_ALLOC_OBJECT( _W3DColor(*this) );
00715         }
00716 
00717         virtual teChangeType changeType () const
00718             throw()
00719         {
00720             return eInstanceLevel;
00721         }
00722 
00723                 _DWFTK_API
00724         void serializeXML( DWFXMLSerializer& rSerializer, unsigned int nFlags )
00725             throw( DWFException );
00726 
00727         inline void _serializeChannels( DWFXMLSerializer& rSerializer, const float* anChannels );
00728     };
00729 
00730     class _W3DCuttingPlanes : public TK_Cutting_Plane
00731                             , public DWFModelSceneChangeHandler
00732     {
00733     public:
00734         _W3DCuttingPlanes() : TK_Cutting_Plane() {;}
00735         _W3DCuttingPlanes(const _W3DCuttingPlanes& rPlanes) : TK_Cutting_Plane(rPlanes) {;}
00736         virtual ~_W3DCuttingPlanes()
00737             throw()
00738         {;}
00739         virtual DWFModelSceneChangeHandler* clone () const
00740             throw()
00741         {
00742             return DWFCORE_ALLOC_OBJECT( _W3DCuttingPlanes(*this) );
00743         }
00744 
00745         virtual teChangeType changeType () const
00746             throw()
00747         {
00748             return eSceneLevel;
00749         }
00750 
00751                 _DWFTK_API
00752         void serializeXML( DWFXMLSerializer& rSerializer, unsigned int nFlags )
00753             throw( DWFException );
00754     };
00755 
00756     class _W3DTransform : public TK_Matrix
00757                         , public DWFModelSceneChangeHandler
00758     {
00759     public:
00760         _W3DTransform( unsigned char eWhich ) : TK_Matrix( eWhich ) {;}
00761         _W3DTransform( const _W3DTransform& rTransform ) : TK_Matrix( rTransform ) {;}
00762         virtual ~_W3DTransform()
00763             throw()
00764         {;}
00765         virtual DWFModelSceneChangeHandler* clone () const
00766             throw()
00767         {
00768             return DWFCORE_ALLOC_OBJECT( _W3DTransform(*this) );
00769         }
00770     
00771         virtual teChangeType changeType () const
00772             throw()
00773         {
00774             return eInstanceLevel;
00775         }
00776 
00777                 _DWFTK_API
00778         void serializeXML( DWFXMLSerializer& rSerializer, unsigned int nFlags )
00779             throw( DWFException );
00780     };
00781 
00782     class _W3DVisibility : public TK_Visibility
00783                          , public DWFModelSceneChangeHandler
00784     {
00785     public:
00786         _W3DVisibility() : TK_Visibility() {;}
00787         _W3DVisibility( const _W3DVisibility& rVis ) : TK_Visibility( rVis ) {;}
00788         virtual ~_W3DVisibility()
00789             throw()
00790         {;}
00791         virtual DWFModelSceneChangeHandler* clone () const
00792             throw()
00793         {
00794             return DWFCORE_ALLOC_OBJECT( _W3DVisibility(*this) );
00795         }
00796     
00797         virtual teChangeType changeType () const
00798             throw()
00799         {
00800             return eInstanceLevel;
00801         }
00802 
00803                 _DWFTK_API
00804         void serializeXML( DWFXMLSerializer& rSerializer, unsigned int nFlags )
00805             throw( DWFException );
00806     };
00807 
00808     class _W3DDisplayMode : public _W3DXMLPseudoHandler
00809     {
00810     public:
00811         _W3DDisplayMode( unsigned int nDisplayMode ) 
00812             : _nDisplayMode( nDisplayMode )
00813         {;}
00814         _W3DDisplayMode( const _W3DDisplayMode& rDisplayMode )
00815             : _nDisplayMode( rDisplayMode._nDisplayMode ) 
00816         {;}
00817         virtual ~_W3DDisplayMode()
00818             throw()
00819         {;}
00820         virtual DWFModelSceneChangeHandler* clone () const
00821             throw()
00822         {
00823             return DWFCORE_ALLOC_OBJECT( _W3DDisplayMode(*this) );
00824         }
00825 
00826         virtual teChangeType changeType () const
00827             throw()
00828         {
00829             return eSceneLevel;
00830         }
00831 
00832         void setMode( unsigned int nDisplayMode) { _nDisplayMode = nDisplayMode; }
00833         unsigned int mode() const { return _nDisplayMode; }
00834 
00835                 _DWFTK_API
00836         void serializeXML( DWFXMLSerializer& rSerializer, unsigned int nFlags )
00837             throw( DWFException );
00838     private:
00839         _W3DDisplayMode& operator=( const _W3DDisplayMode& );
00840 
00841     private:
00842         unsigned int                    _nDisplayMode;
00843     };
00844 
00845 protected:
00846 
00847     std::deque<DWFModelSceneChangeHandler*>  _oSerializableSceneAPI;
00848     bool                        _bOpenInstance;
00849     DWFString                   _zOpenInstanceID;
00850     bool                        _bInstancePreviouslyOpen;
00851     DWFString                   _zPreviousInstanceID;
00852 
00853 private:
00854 
00855     void _checkForOpenInstance()
00856     throw( DWFException );
00857 
00858     DWFModelScene( const DWFModelScene& );
00859     DWFModelScene& operator=( const DWFModelScene& );
00860 
00861 };
00862 
00863 }
00864 
00865 #endif

Generated on Tue Jan 6 22:40:04 2009 for Autodesk DWF Toolkit by  doxygen 1.4.5