node.h

Go to the documentation of this file.
00001 //**************************************************************************/
00002 // Copyright (c) 2008 Autodesk, Inc.
00003 // All rights reserved.
00004 //
00005 // Use of this software is subject to the terms of the Autodesk license
00006 // agreement provided at the time of installation or download, or which
00007 // otherwise accompanies this software in either electronic or hard copy form.
00008 //
00009 //**************************************************************************/
00010 // DESCRIPTION:
00011 // CREATED: October 2008
00012 //**************************************************************************/
00013 
00014 namespace mudbox {
00015 
00016 class Template;
00017 class Node;
00018 
00020 class MBDLL_DECL ClassDesc
00021 {
00022     const ClassDesc *m_pParent[2], *m_pNext;
00023     QString m_sName;
00024     QString m_sDisplayName;
00025     typedef class Node *creator( unsigned int );
00026     creator *m_pCreator;
00027     static ClassDesc *s_pFirst;
00028     Template *m_pTemplate;
00029     int m_iVersion;
00030 public:
00031     int m_iStreamVersion;
00032     
00034     ClassDesc( const ClassDesc *pParent0, const ClassDesc *pParent1, const QString &sName, const QString &sDisplayName, creator *pCreator, int iVersion = 0, int iStreamVersion = 0 );
00036     const ClassDesc *Parent( unsigned int iIndex = 0 ) const;
00038     const QString &Name( void ) const;
00040     const QString &DisplayName( void ) const;
00042     bool IsDerivedFrom( const ClassDesc *pClass ) const;
00044     class Node *CreateInstances( int iCount = 1 ) const;
00045 
00049         static const ClassDesc *First( void );
00051         const ClassDesc *Next( void ) const;
00053 
00055     static const ClassDesc *ByName( const QString &sName );
00057     int Version( void ) const;
00058 
00059     friend class Node;
00060     friend class Stream;
00061 };
00062 
00082 #define DECLARE_CLASS \
00083 private: \
00084     static mudbox::ClassDesc s_cMyClass; \
00085 public: \
00086     virtual const mudbox::ClassDesc *RuntimeClass( void ) const { return &s_cMyClass; }; \
00087     static const mudbox::ClassDesc *StaticClass( void ); \
00088     static mudbox::Node *CreateInstances( unsigned int iCount = 1 );
00089 
00090 #define IMPLEMENT_SDK_VCLASS2( name, parent0, parent1, displayname, instanceclass, version, streamversion ) \
00091     mudbox::ClassDesc name::s_cMyClass( parent0::StaticClass(), parent1::StaticClass(), #name, displayname, name::CreateInstances, version, streamversion ); \
00092     const mudbox::ClassDesc *name::StaticClass( void ) { return &s_cMyClass; }; \
00093     mudbox::Node *name::CreateInstances( unsigned int iCount ) \
00094         { Node *p; \
00095             if ( iCount > 1 ) { p = new instanceclass[iCount]; for ( unsigned int i = 0; i < iCount; i++ ) p[i].Initialize(); } \
00096             else { p = new instanceclass; p->Initialize(); }; \
00097             return p; };
00098 
00099 #define IMPLEMENT_SDK_CLASS( name, parent, displayname, instanceclass ) IMPLEMENT_SDK_VCLASS2( name, parent, parent, displayname, instanceclass, 0, 0 )
00100 #define IMPLEMENT_VCLASS2( name, parent0, parent1, displayname, version ) IMPLEMENT_SDK_VCLASS2( name, parent0, parent1, displayname, name, version, 0 )
00101 #define IMPLEMENT_VCLASS( name, parent, displayname, version ) IMPLEMENT_SDK_VCLASS2( name, parent, parent, displayname, name, version, 0 )
00102 #define IMPLEMENT_CLASS2( name, parent0, parent1, displayname ) IMPLEMENT_SDK_VCLASS2( name, parent0, parent1, displayname, name, 0, 0 )
00103 #define IMPLEMENT_CLASS( name, parent, displayname ) IMPLEMENT_SDK_VCLASS2( name, parent, parent, displayname, name, 0, 0 )
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126 
00127 
00128 
00129 
00130 
00131 
00132 #define IMPLEMENT_SCLASS( name, parent, displayname, streamversion ) IMPLEMENT_SDK_VCLASS2( name, parent, parent, displayname, name, 0, streamversion )
00133 
00135 enum NodeEventType
00136 {
00138     etValueChanged,
00140     etSourceChanged,
00142     etTargetChanged,
00144     etPointerContentChanged,
00146     etPointerTargetDestroyed,
00148     etStatusChanged,
00150     etPointerTargetUIChanged,
00152     etDeferred,
00155     etRefreshDialogUI,
00157     etEventTriggered = etValueChanged
00158 };
00159 
00166 struct MBDLL_DECL Attribute
00167 {   
00169     enum AttributeType
00170     {
00172         typeUnknown,
00174         typeInt,
00176         typeFloat,
00178         typeBool,
00180         typeString,
00182         typePointer,
00184         typeColor,
00186         typeVector,
00188         typeEnum,
00190         typeWatch
00191     };
00192 
00193     enum AsStringOptions
00194     {
00196         asStringInternal  = 0x0001,
00197 
00200         asStringLocalized = 0x0002,
00201 
00203         asStringDefault = 0x0000,
00204 
00206         asStringDefaultSet = asStringInternal
00207     };
00208 
00210     unsigned int TargetCount( void ) const;
00212     Attribute *Target( unsigned int iIndex ) const;
00214     Attribute *Source( void );
00216     bool operator ==( const Attribute &cAttribute ) const;
00218     bool operator !=( const Attribute &cAttribute ) const;
00220     virtual AttributeType Type( void ) const;
00221 
00223     QString ID( void ) const;
00225     QString Name( void ) const;
00227     void SetName( const QString &sName );
00229     QString Category( void ) const;
00231     void SetCategory( const QString &sCategory, bool bSeparator = false );
00233     bool Separator( void ) const;
00235     void SetSeparator( bool bSeparator );
00237     bool Const( void ) const;
00239     void SetConst( bool bConst );
00241     bool Visible( void ) const;
00243     void SetVisible( bool bVisible );
00245     QString ToolTip( void ) const;
00247     void SetToolTip( const QString &sToolTip );
00249     unsigned int Size( void ) const;
00253     float LabelWidth( void ) const;
00255     void SetLabelWidth( float fLabelWidth );
00257     int Index( void ) const;
00259     void SetIndex( int iIndex );
00260 
00262     Node *Owner( void ) const;
00264     virtual void Serialize( Stream &s );
00265 
00267     virtual QString AsString( unsigned int options = asStringDefault ) const;
00269     virtual void SetFromString( const QString &sValue, unsigned int options = asStringDefaultSet );
00270 
00276         void ClearTargets( void );
00278         void ClearSource( void );
00280         virtual void AddTarget( Attribute &cTarget );
00282         void Connect( Attribute &cSource );
00284         virtual void UpdateTargets( void );
00286 
00291         virtual const ClassDesc* TargetType( void ) const;
00293         virtual void SetPointerValue( Node *pValue, bool bLink = true );
00295         virtual Node *PointerValue( void ) const;
00297         virtual bool ValidatePointerValue( const Node *pValue );
00299 
00300     virtual ~Attribute( void );
00301     virtual void StartEvent( NodeEventType cType ) const;
00302     
00308     void SetOwner( Node *pOwner );
00309 
00315     virtual AttributeWidget *CreateEditorWidget( QWidget *pParent, 
00316         int iWidth 
00317         );
00318     
00323     virtual unsigned int ParameterCount( void ) const;
00325     virtual QString ParameterName( unsigned int iIndex ) const;
00327     virtual QString ParameterValue( unsigned int iIndex ) const;
00329     virtual void SetParameterValue( const QString &sName, const QString &sValue );
00331 
00333     void LogTargets( void );
00335     void LogSource( void );
00336     
00337 protected:
00338 
00339     Attribute( Node *pOwner, const QString &sID);
00340     Attribute( Node *pOwner, bool bInstall);
00341 
00342     int m_iSize;
00343     Attribute *m_pSource, *m_pNext;
00344     Store<Attribute *> m_aTargets;
00345     Node *m_pNode;
00346     QString m_sName;
00347     bool m_bSeparator;
00348     QString m_sCategory;
00349     QString m_sToolTip;
00350     float m_fLabelWidth;
00351     bool m_bConst;
00352     bool m_bVisible;
00353     int m_iIndex;
00354     QString m_sID;
00355 
00356     void Uninstall( void );
00357 
00358     friend class Node;
00359 };
00360 
00365 class MBDLL_DECL AttributeVoid : public Attribute
00366 {
00367 public:
00368     AttributeVoid(Node *pOwner, const QString &sName ) : Attribute(pOwner, sName) {}
00369     ~AttributeVoid() {}
00370 };
00371 
00372 typedef AttributeVoid avoid;
00373 
00379 template < typename type >
00380 struct MBDLL_TEMPLATE_DECL AttributeInstance : public Attribute
00381 {
00383     AttributeInstance( Node *pOwner, const QString &sID) : Attribute( pOwner, sID ) { m_iSize = sizeof(type); };
00385     AttributeInstance( Node *pOwner, const QString &sID, const type &cValue ) : Attribute( pOwner, sID ) { m_cValue = cValue; m_iSize = sizeof(type); };
00386 
00387     // Value management
00389     const type &Value( void ) const { return m_cValue; };
00392     virtual void SetValue( type cValue, unsigned int options = 0 )
00393     {
00394         m_cValue = cValue;
00395         UpdateTargets();
00396         if ( !(options & Attribute::asStringInternal) )
00397             StartEvent( etValueChanged );
00398     };
00399     void UpdateTargets( void )
00400     {
00401         for ( unsigned int i = 0; i < TargetCount(); i++ )
00402         {
00403             if ( Target(i)->Size() == Size() )
00404                 ((AttributeInstance<type> *)Target(i))->SetValue( m_cValue );
00405             else
00406                 Target(i)->StartEvent( etValueChanged );
00407         };
00408     };
00409     void Serialize( Stream &s );
00410 
00411     // Connection management
00412     void AddTarget( Attribute &cTarget )
00413     {
00414         Attribute::AddTarget( cTarget );
00415         if ( cTarget.Size() )
00416         {
00417             AttributeInstance<type> *pT = (AttributeInstance<type> *)&cTarget;
00418             if ( pT->Value() != Value() )
00419                 pT->SetValue( Value() );
00420         };
00421 
00422         StartEvent( etTargetChanged );
00423         cTarget.StartEvent( etSourceChanged );
00424     };
00425 
00426     // Default string operations
00427     QString AsString( unsigned int /*options*/ = asStringDefault ) const
00428     {
00429         QString sValue;
00430         const unsigned char *tData = (const unsigned char *)(void *)(&m_cValue);
00431         for ( unsigned int i = 0; i < sizeof(m_cValue); i++ )
00432         {
00433             if ( i ) 
00434                 sValue += " ";
00435             sValue += QString("%1").arg(int(tData[i]));
00436         };
00437         return sValue;
00438     };
00439     void SetFromString( const QString &sValue, unsigned int options = asStringDefaultSet )
00440     {
00441         type cValue;
00442         unsigned char *tData = (unsigned char *)(void *)(&cValue);
00443         for ( int i = 0; i < (int)sizeof(cValue); i++ )
00444             tData[i] = sValue.section(' ', i, i).toInt();
00445         SetValue( cValue, options );
00446     };
00447     AttributeWidget *CreateEditorWidget( QWidget *pParent, int iWidth ) { return Attribute::CreateEditorWidget( pParent, iWidth ); };
00448     Attribute::AttributeType Type( void ) const { return Attribute::AttributeType(); };
00449 
00450     // Operators
00451     // Used for the QString class which does not have a predefined ! operator
00452     // if the line below is used, than pointers wont be linked into the target node THIS pointer.
00453     //inline type operator =( type cValue ) { AttributeInstance<type>::SetValue( cValue, true ); return cValue; }; 
00454 #define OPERATORS_NOEXCMARK( type ) \
00455  \
00456     inline operator const type( void ) const { return AttributeInstance<type>::Value(); }; \
00457  \
00458     inline type const &operator ~( void ) const { return AttributeInstance<type>::Value(); }; \
00459  \
00460     inline type operator =( type cValue ) { SetValue( cValue, Attribute::asStringInternal ); return cValue; }; \
00461  \
00462     inline type operator =( const AttributeInstance<type> &cValue ) { /*AttributeInstance<type>::*/SetValue( cValue.AttributeInstance<type>::Value(), Attribute::asStringInternal ); return cValue; }; \
00463  \
00464     inline bool operator ==( type cValue ) const { return AttributeInstance<type>::Value() == cValue; }; \
00465  \
00466     inline bool operator !=( type cValue ) const { return AttributeInstance<type>::Value() != cValue; }; \
00467  \
00472     inline const QString &operator <<=( const QString &sCategory ) { AttributeInstance<type>::SetCategory( sCategory ); return sCategory; };
00473 #define OPERATORS( type ) \
00474     OPERATORS_NOEXCMARK( type ) \
00475  \
00476     inline bool operator !( void ) { return !AttributeInstance<type>::Value(); };
00477 
00478     OPERATORS( type );
00479  
00480 protected:
00482     AttributeInstance( Node *pOwner, const QString &sName, bool bInstall ) : Attribute( pOwner, bInstall ) { m_sName = sName; m_iSize = sizeof(type); };
00483     
00484 private:
00485 // HACK:
00486 public:
00487     type m_cValue;
00488 };
00489 
00491 typedef AttributeInstance<int> aint;
00493 typedef AttributeInstance<float> afloat;
00495 typedef AttributeInstance<bool> abool;
00497 typedef AttributeInstance<QString> astring; 
00498 
00499 template <> inline
00500 bool astring::operator !(void) { return !(m_cValue.isEmpty()); }
00501 
00502 template <> MBDLL_DECL
00503 QString aint::AsString( unsigned int /*options*/ ) const;
00504 template <> MBDLL_DECL
00505 QString afloat::AsString( unsigned int /*options*/ ) const;
00506 template <> MBDLL_DECL
00507 QString abool::AsString( unsigned int /*options*/ ) const;
00508 template <> inline
00509 QString astring::AsString( unsigned int /*options*/ ) const { return m_cValue; };
00510 
00511 template <> MBDLL_DECL
00512 void aint::SetFromString( const QString &sValue, unsigned int options );
00513 template <> MBDLL_DECL
00514 void afloat::SetFromString( const QString &sValue, unsigned int options );
00515 template <> MBDLL_DECL
00516 void abool::SetFromString( const QString &sValue, unsigned int options );
00517 template <> inline
00518 void astring::SetFromString( const QString &sValue, unsigned int options ) { SetValue( sValue, options ); };
00519 
00520 template <> inline
00521 Attribute::AttributeType aint::Type( void ) const { return typeInt; };
00522 template <> inline
00523 Attribute::AttributeType abool::Type( void ) const { return typeBool; }; 
00524 template <> inline
00525 Attribute::AttributeType afloat::Type( void ) const { return typeFloat; };
00526 template <> inline
00527 Attribute::AttributeType astring::Type( void ) const { return typeString; };
00528 
00529 MBDLL_DECL AttributeWidget *CreateNewPtrWidget( QWidget *pParent, int iWidth, Attribute *pAttribute, const ClassDesc *pType );
00530 MBDLL_DECL AttributeWidget *CreateNewBoolWidget( QWidget *pParent, int iWidth, abool *pAttribute );
00531 MBDLL_DECL AttributeWidget *CreateNewIntWidget( QWidget *pParent, int iWidth, aint *pAttribute );
00532 
00533 template <> inline
00534 AttributeWidget *abool::CreateEditorWidget( QWidget *pParent, int iWidth ) { return CreateNewBoolWidget( pParent, iWidth, this ); };
00535 template <> inline
00536 AttributeWidget *aint::CreateEditorWidget( QWidget *pParent, int iWidth ) { return CreateNewIntWidget( pParent, iWidth, this ); };
00537 
00539 template < typename type > inline
00540 bool operator ==( const Attribute &cA, const AttributeInstance<type> &cB )
00541 {
00542     return &cA == &cB;
00543 };
00544     
00545 template < typename type > inline
00546 Stream &operator ==( Stream &s, AttributeInstance<type> &c )
00547 {
00548     c.Serialize( s );
00549     return s;
00550 };
00551 
00552 class EventGate;
00553 
00561 template < typename type >
00562 class AttributePointer : public AttributeInstance<type *>
00563 {
00564     const ClassDesc *TargetType( void ) const { return type::StaticClass(); };
00565     Node *PointerValue( void ) const { return AttributeInstance<type *>::Value(); };
00566     void UpdateTargets( void )
00567     {
00568         for ( unsigned int i = 0; i < AttributeInstance<type *>::TargetCount(); i++ )
00569             AttributeInstance<type *>::Target(i)->SetPointerValue( PointerValue(), false );
00570     };
00571     AttributeWidget *CreateEditorWidget( QWidget *pParent, int iWidth ) { return CreateNewPtrWidget( pParent, iWidth, this, type::StaticClass() ); };
00572     typedef bool validator( const type *pTarget );
00573     validator *m_pValidator;
00574     bool ValidatePointerValue( const Node *pValue )
00575     {
00576         if ( m_pValidator == 0 || m_pValidator( dynamic_cast< const type *>( pValue ) ) )
00577             return true;
00578 
00579         return false;
00580     };
00581 
00582 public:
00583     AttributePointer( Node *pOwner=NULL, const QString &sID = "") : AttributeInstance<type *>( pOwner, sID ) { SetValue( 0, Attribute::asStringInternal ); m_pValidator = 0; m_sNullString = "NULL"; m_bAllowNull = true; };
00584     AttributePointer( Node *pOwner, const QString &sID,  bool bInstall ) : AttributeInstance<type *>( pOwner, sID, bInstall ) { SetValue( 0, Attribute::asStringInternal ); m_pValidator = 0; m_sNullString = "NULL"; m_bAllowNull = true; };
00585     QString AsString( unsigned int /*options*/ ) const { if ( PointerValue() ) return PointerValue()->Name(); else return m_sNullString; };
00586     void SetFromString( const QString & /*sValue*/, unsigned int /*options*/ = Attribute::asStringInternal ) { SetPointerValue( 0 ); };
00588     inline void SetValidator( validator *pValidator ) { m_pValidator = pValidator; };
00589     void SetPointerValue( Node *pNode, bool bLink = true ) 
00590     {
00591         // always accept 0 pointer, the target may be destroyed
00592         if ( pNode && m_pValidator && !m_pValidator( dynamic_cast<type *>( pNode ) ) )
00593             return;
00594         if ( bLink )
00595             SetValue( dynamic_cast<type *>( pNode ) );
00596         else
00597             AttributeInstance<type *>::SetValue( dynamic_cast<type *>( pNode ) );
00598     };
00599     virtual void SetValue( type *cValue, unsigned int options = 0 )
00600     {
00601         if ( cValue == AttributePointer<type>::Value() )
00602             return;
00603         AttributeInstance<type *>::SetValue( cValue, options );
00604         if ( cValue )
00605             cValue->m_pThis.AddTarget( *this );
00606         else
00607             Attribute::ClearSource();
00608     };
00609     void AddTarget( Attribute &cTarget )
00610     {
00611         Attribute::AddTarget( cTarget );
00612         if ( cTarget.Size() )
00613         {
00614             if ( cTarget.PointerValue() != PointerValue() )
00615                 cTarget.SetPointerValue( PointerValue() );
00616         };
00617     };
00619     void DeleteTarget( void )
00620     {
00621         delete AttributePointer<type>::Value();
00622     };
00638     void Serialize( Stream &s );
00639     void StartEvent( NodeEventType cType ) const
00640     {
00641         AttributeInstance<type *>::StartEvent( cType );
00642         if ( cType == etPointerContentChanged || cType == etPointerTargetDestroyed || cType == etPointerTargetUIChanged || cType == etRefreshDialogUI )
00643             for ( unsigned int i = 0; i < AttributeInstance<type *>::TargetCount(); i++ )
00644                 AttributeInstance<type *>::Target( i )->StartEvent( cType );
00645     };
00646     Attribute::AttributeType Type( void ) const { return AttributeInstance<type *>::typePointer; };
00647 #define PTROPERATORS( type ) \
00648     OPERATORS( type* ); \
00649  \
00650     inline type *operator =( int iValue ) { MB_ASSERT( iValue == 0 ); return operator =( (type *)(uint64)iValue ); }; \
00651  \
00652     inline bool operator ==( int iValue ) { MB_ASSERT( iValue == 0 ); return operator ==( (type *)(uint64)iValue ); }; \
00653  \
00654     inline bool operator !=( int iValue ) { MB_ASSERT( iValue == 0 ); return operator !=( (type *)(uint64)iValue ); }; \
00655  \
00656     inline type *operator ->( void ) { return AttributeInstance<type *>::Value(); }; \
00657  \
00658     inline const type *operator ->( void ) const { return AttributeInstance<type *>::Value(); }; \
00659  \
00660     inline operator bool( void ) const { return AttributeInstance<type *>::Value() != 0; };
00661     PTROPERATORS( type );
00662 
00663     QString m_sNullString;
00664     bool m_bAllowNull;
00665 
00666     friend class Node;
00667     friend class AttributeThisPointer;
00668     friend struct Attribute;
00669 };
00670 
00671 //template < typename type>
00672 //typedef AttributePointer<type> aptr<type>;
00673 #define aptr AttributePointer
00674 template < typename type >
00675 inline Stream &operator ==( Stream &cStream, AttributePointer<type> &cPointer ) { cPointer.AttributePointer<type>::Serialize( cStream ); return cStream; };
00676 
00678 class MBDLL_DECL AttributeThisPointer : public aptr<Node>
00679 {
00680     AttributeThisPointer( Node *pOwner );
00681     const ClassDesc *TargetType( void ) const;
00682     PTROPERATORS( Node );
00683 
00684     friend class Node;
00685 };
00686 
00688 class MBDLL_DECL Node
00689 {
00690     Attribute *m_pAttributes;
00691 
00692     static Node *s_pFirstNode;
00693     int m_iID;
00694     Node *m_pNext, *m_pPrev;
00695 
00696     static int s_iNextID;
00697     friend struct Attribute;
00698     friend class Stream;
00699 
00700 public:
00701 
00703     enum DiagnosticLevel
00704     {
00706         dgnLevel1,
00707 
00709         dgnLevel2,
00710 
00712         dgnLevel3
00713     };
00714 
00717     Node( const QString &sStringID = "", const QString &sDisplayName = "" );
00718     virtual ~Node( void );
00719     virtual void Initialize( void );
00720 
00725 
00745         virtual void OnNodeEvent( const Attribute &cAttribute, NodeEventType cType );
00747         virtual void OnEvent( const EventGate &cEvent );
00749         void RequestDeferredEvent( Attribute &cAttribute );
00751 
00753     void LoadTemplate( const QString &sFileName = "", bool bStartEvent = false );
00755     void SaveTemplate( const QString &sFileName = "", bool bSaveOnlyVisible = false);
00757     unsigned int Version( void ) const;
00759     void SetVersion( unsigned int iVersion );
00760     
00765         static Node *First( void );
00767         Node *Next( void ) const;
00769         int ID( void ) const;
00771         static Node *ByID( int iID );
00773         static Node *ByName( const QString &sClass, const QString &sName );
00775 
00776     // TODO I18N: remove this deprecated interface.
00779     virtual QString Name( const ClassDesc *pClass = 0 ) const;
00780     // TODO I18N: remove this deprecated interface.
00783     virtual void SetName( const QString &sName );
00786     virtual QString StringID( const ClassDesc *pClass = 0 ) const;
00788     virtual void SetStringID( const QString &sStringID );
00791     virtual QString DisplayName( void ) const;
00793     virtual void SetDisplayName( const QString & sDisplayName );
00795     virtual QString HelpID( void ) const;
00797     virtual void SetHelpID( const QString &sHelpID );
00798 
00800     void Annex( Node *pSource, const QString &sCategory = "" );
00801 
00806         unsigned int AttributeCount( void ) const;
00808         Attribute *AttributeByIndex( int iIndex ) const;
00810         Attribute *AttributeByName( const QString &sName ) const;
00812         Attribute *AttributeByID( const QString &sID ) const;
00814         void SetAttributeValue( const QString &sAttributeID, const QString &sNewValue );
00816         QString AttributeValue( const QString &sAttributeID ) const;
00818         void LogAttributes( void ) const;
00820         virtual QWidget *CreatePropertiesWindow( QWidget *pParent );
00824         Attribute *AddAttribute(Attribute::AttributeType type, const QString &id);
00825         // Allows SDK users to add attributes at runtime.  The Attribute passed into the function
00826         // *MUST* be allocated on the heap (dynamically allocated).  Returns true on success & false on failure.  On successfull adding
00827         // then this node manages the attribute (deletes on node destructor).  Returns true if attribute
00828         // already exists.  This function sets the owner of this attribute to the node.  The new owner is
00829         // responsible for deleting the attribute.  Attribute visibility is set to false.
00830         // Note that the attribute will be serialized when the node is serialized.
00831         //
00832         // Disabled until we support serialization of user-defined attribute types.
00833         //bool AddAttribute(Attribute *pAttribute);
00834 
00835         // Runtime attribute count
00837 
00841     virtual void Serialize( Stream &s );
00842 
00843     AttributeThisPointer m_pThis;
00844 
00845     friend class EventGate;
00846 
00848     bool IsKindOf( const ClassDesc *pClass ) const;
00849     
00853     void ContentChanged( void ) const;
00854     
00859     virtual void CheckValidity( DiagnosticLevel iLevel = dgnLevel2 ) const;
00860 
00861     DECLARE_CLASS;
00862 
00863 private:
00864     QString m_sStringID;
00865     QString m_sDisplayName;
00866     QString m_sHelpID;
00867     mutable unsigned int m_iVersion;
00868 
00869     QList<Attribute *> m_aRuntimeAttributes;
00870 };
00871 
00873 AttributeWidget *CreateNewEventWidget( QWidget *pParent, int iWidth, EventGate *pAttribute );
00874 
00900 class MBDLL_DECL EventGate : public AttributeInstance<int>
00901 {
00902     void StartEvent( NodeEventType cType ) const;
00903     AttributeWidget *CreateEditorWidget( QWidget *pParent, int iWidth );
00904 
00905 public:
00907     EventGate( Node *pOwner, const QString &sID = "" );
00909     void Trigger( void );
00911     void Connect( EventGate &cEvent );
00913     bool operator ==( const EventGate &cEvent ) const;
00914 };
00915 typedef EventGate aevent;
00916 
00917 // special attributes
00919 class MBDLL_DECL AttributeFloatRange : public afloat
00920 {
00921     Q_DECLARE_TR_FUNCTIONS(mudbox::AttributeFloatRange);
00922 private:
00923     mutable float m_fMin, m_fMax;
00924     mutable float m_fEditMin, m_fEditMax;
00925     float m_fFactor;
00926     int m_iPrecision;
00927 
00928     QString AsString( unsigned int /*options*/ ) const;
00929     void SetFromString( const QString &sValue, unsigned int options = asStringInternal );
00930 
00931     unsigned int ParameterCount( void ) const;
00932     QString ParameterName( unsigned int iIndex ) const;
00933     QString ParameterValue( unsigned int iIndex ) const;
00934     void SetParameterValue( const QString &sName, const QString &sValue );
00935 public:
00937     AttributeFloatRange( Node *pOwner, const QString &sID, float fMinimum = 0, float fMaximum = 1, float fFactor = 1, int iPrecision = 2 );
00938     OPERATORS( float );
00939     void StartEvent( NodeEventType cType ) const;
00940     AttributeWidget *CreateEditorWidget( QWidget *pParent, int iWidth );
00941     float Min( void ) const;
00942     float Max( void ) const;
00943     void SetMin( float fValue );
00944     void SetMax( float fValue );
00945     // Set the min max limit to the edit box
00946     void SetEditMin( float fEditMin );
00947     void SetEditMax( float fEditMax );
00948     float EditMin( void ) const;
00949     float EditMax( void ) const;
00950 };
00951 
00952 typedef AttributeFloatRange afloatr;
00953 MBDLL_DECL Stream &operator ==( Stream &s, afloatr &a );
00954 
00956 class MBDLL_DECL AttributeNumber : public AttributeInstance<int>
00957 {
00958     int m_iDigitCount;
00959     int m_iControlWidth;
00960     AttributeWidget *CreateEditorWidget( QWidget *pParent, int iWidth );
00961 public:
00962     AttributeNumber( Node *pOwner, const QString &sID, int m_iControlwidth = 40, int m_iDigitCount = 0 );
00963     OPERATORS( int );
00964 };
00965 
00966 typedef AttributeNumber anumber;
00967 
00969 class MBDLL_DECL AttributeEnumeration : public aint
00970 {
00971     Q_DECLARE_TR_FUNCTIONS(mudbox::AttributeEnumeration);
00972 private:
00973     Store<QString> m_aValues;
00974     bool m_bDisplayAsIcons;
00975 
00976     unsigned int ParameterCount( void ) const;
00977     QString ParameterName( unsigned int iIndex ) const;
00978     QString ParameterValue( unsigned int iIndex ) const;
00979     void SetParameterValue( const QString &sName, const QString &sValue );
00980 public:
00981     AttributeEnumeration( Node *pOwner, const QString &sID );
00982     OPERATORS( int );
00983     AttributeWidget *CreateEditorWidget( QWidget *pParent, int iWidth );
00985     unsigned int AddItem( const QString &sValue );
00986     void SetItem( unsigned int iIndex, const QString &sValue );
00988     void SetIconMode( 
00989         bool bDisplayAsIcons 
00990 
00991 
00992         ) { m_bDisplayAsIcons = bDisplayAsIcons; };
00994     bool IconMode( void ) const { return m_bDisplayAsIcons; };
01009     AttributeEnumeration &operator <<( const char *sValue );
01010     AttributeEnumeration &operator =( const AttributeEnumeration &aeValue );
01011 
01013     unsigned int ItemCount( void ) const;
01014     void Clear( void );
01015     QString Item( unsigned int iIndex ) const;
01016 };
01017 typedef AttributeEnumeration aenum;
01018 MBDLL_DECL Stream &operator ==( Stream &s, aenum &a );
01019 
01021 class MBDLL_DECL AttributeFilename : public astring
01022 {
01023 public:
01024     AttributeFilename( Node *pOwner, const QString &sID, bool bMustExists = true );
01025     OPERATORS_NOEXCMARK( QString );
01026     AttributeWidget *CreateEditorWidget( QWidget *pParent, int iWidth );
01027 
01028     unsigned int ParameterCount( void ) const;
01029     QString ParameterName( unsigned int iIndex ) const;
01030     QString ParameterValue( unsigned int iIndex ) const;
01031     void SetParameterValue( const QString &sName, const QString &sValue );
01032 
01033     bool m_bMustExists;
01034     QString m_sFilter;
01035     QString m_sPath;
01036 };
01037 typedef AttributeFilename afilename;
01038 
01040 class MBDLL_DECL AttributeTextureFilename : public AttributeFilename
01041 {
01042 public:
01043     AttributeTextureFilename( Node *pOwner, const QString &sID,  bool bMustExists = true );
01044     OPERATORS_NOEXCMARK( QString );
01045     AttributeWidget *CreateEditorWidget( QWidget *pParent, int iWidth );
01046 };
01047 typedef AttributeTextureFilename atexturefilename;
01048 MBDLL_DECL Stream &operator ==( Stream &s, afilename &a );
01049 
01053 class MBDLL_DECL AttributeWatch : public Attribute
01054 {
01055     Attribute::AttributeType Type( void ) const;
01056 public:
01057     AttributeWatch( Node *pOwner, const QString &sID = "");
01058 };
01059 
01061 class MBDLL_DECL AttributeBoolCollection : public AttributeInstance<int>
01062 {
01063     Q_DECLARE_TR_FUNCTIONS(mudbox::AttributeBoolCollection);
01064 
01065 private:
01066     AttributeWidget *CreateEditorWidget( QWidget *pParent, int iWidth );
01067     QString m_aNames[32];
01068     unsigned int m_iBoolCount;
01069 
01070     unsigned int ParameterCount( void ) const;
01071     QString ParameterName( unsigned int iIndex ) const;
01072     QString ParameterValue( unsigned int iIndex ) const;
01073     void SetParameterValue( const QString &sName, const QString &sValue );
01074 public:
01075     AttributeBoolCollection( Node *pOwner, const QString &sID );
01076     void Clear( void );
01077     void SetValue( unsigned int iIndex, bool bValue, unsigned int options = Attribute::asStringInternal );
01078     bool Value( unsigned int iIndex ) const;
01079     int AddBool( const QString &sName, bool bValue = false );
01080     unsigned int BoolCount( void ) const;
01081     void SetBoolName( unsigned int iIndex, const QString &sName );
01082     QString BoolName( unsigned int iIndex ) const;
01083 };
01084 typedef AttributeBoolCollection aboolc;
01085 
01086 }; // end of namespace mudbox
01087 
01088