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     void SetDisplayName( const QString &sName );
00043 
00045     bool IsDerivedFrom( const ClassDesc *pClass ) const;
00047     class Node *CreateInstances( int iCount = 1 ) const;
00048 
00052         static const ClassDesc *First( void );
00054         const ClassDesc *Next( void ) const;
00056 
00058     static const ClassDesc *ByName( const QString &sName );
00060     int Version( void ) const;
00061 
00062     friend class Node;
00063     friend class Stream;
00064 };
00065 
00085 #define DECLARE_CLASS \
00086 private: \
00087     static mudbox::ClassDesc s_cMyClass; \
00088 public: \
00089     virtual const mudbox::ClassDesc *RuntimeClass( void ) const { return &s_cMyClass; }; \
00090     static const mudbox::ClassDesc *StaticClass( void ); \
00091     static mudbox::Node *CreateInstances( unsigned int iCount = 1 );
00092 
00093 #define IMPLEMENT_SDK_VCLASS2( name, parent0, parent1, displayname, instanceclass, version, streamversion ) \
00094     mudbox::ClassDesc name::s_cMyClass( parent0::StaticClass(), parent1::StaticClass(), #name, displayname, name::CreateInstances, version, streamversion ); \
00095     const mudbox::ClassDesc *name::StaticClass( void ) { return &s_cMyClass; }; \
00096     mudbox::Node *name::CreateInstances( unsigned int iCount ) \
00097         { Node *p; \
00098             if ( iCount > 1 ) { p = new instanceclass[iCount]; for ( unsigned int i = 0; i < iCount; i++ ) p[i].Initialize(); } \
00099             else { p = new instanceclass; p->Initialize(); }; \
00100             return p; };
00101 
00102 #define IMPLEMENT_SDK_VCLASS( name, parent, displayname, instanceclass, streamversion ) IMPLEMENT_SDK_VCLASS2( name, parent, parent, displayname, instanceclass, 0, streamversion )
00103 #define IMPLEMENT_SDK_CLASS( name, parent, displayname, instanceclass ) IMPLEMENT_SDK_VCLASS2( name, parent, parent, displayname, instanceclass, 0, 0 )
00104 #define IMPLEMENT_VCLASS2( name, parent0, parent1, displayname, version ) IMPLEMENT_SDK_VCLASS2( name, parent0, parent1, displayname, name, version, 0 )
00105 #define IMPLEMENT_VCLASS( name, parent, displayname, version ) IMPLEMENT_SDK_VCLASS2( name, parent, parent, displayname, name, version, 0 )
00106 #define IMPLEMENT_CLASS2( name, parent0, parent1, displayname ) IMPLEMENT_SDK_VCLASS2( name, parent0, parent1, displayname, name, 0, 0 )
00107 #define IMPLEMENT_CLASS( name, parent, displayname ) IMPLEMENT_SDK_VCLASS2( name, parent, parent, displayname, name, 0, 0 )
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 
00133 
00134 
00135 
00136 #define IMPLEMENT_SCLASS( name, parent, displayname, streamversion ) IMPLEMENT_SDK_VCLASS2( name, parent, parent, displayname, name, 0, streamversion )
00137 #define IMPLEMENT_SCLASS2( name, parent0, parent1, displayname, streamversion ) IMPLEMENT_SDK_VCLASS2( name, parent0, parent1, displayname, name, 0, streamversion )
00138 
00140 enum NodeEventType
00141 {
00143     etValueChanged,
00145     etSourceChanged,
00147     etTargetChanged,
00149     etPointerContentChanged,
00151     etPointerTargetDestroyed,
00153     etStatusChanged,
00155     etPointerTargetUIChanged,
00157     etDeferred,
00160     etRefreshDialogUI,
00162     etEditingFinished,
00164     etEventTriggered = etValueChanged
00165 };
00166 
00173 struct MBDLL_DECL Attribute
00174 {   
00176     enum AttributeType
00177     {
00179         typeUnknown,
00181         typeInt,
00183         typeFloat,
00185         typeBool,
00187         typeString,
00189         typePointer,
00191         typeColor,
00193         typeVector,
00195         typeEnum,
00197         typeWatch
00198     };
00199 
00201     unsigned int TargetCount( void ) const;
00203     Attribute *Target( unsigned int iIndex ) const;
00205     Attribute *Source( void );
00207     bool operator ==( const Attribute &cAttribute ) const;
00209     bool operator !=( const Attribute &cAttribute ) const;
00211     virtual AttributeType Type( void ) const;
00212 
00214     QString ID( void ) const;
00216     QString Name( void ) const;
00218     void SetName( const QString &sName );
00220     QString Category( void ) const;
00222     void SetCategory( const QString &sCategory, bool bSeparator = false );
00224     bool Separator( void ) const;
00226     void SetSeparator( bool bSeparator );
00228     bool Const( void ) const;
00230     void SetConst( bool bConst );
00232     bool InstantEdit( void ) const;
00234     void SetInstantEdit( bool bOn );
00236     bool Visible( void ) const;
00238     void SetVisible( bool bVisible );
00240     QString ToolTip( void ) const;
00242     void SetToolTip( const QString &sToolTip );
00244     unsigned int Size( void ) const;
00248     float LabelWidth( void ) const;
00250     void SetLabelWidth( float fLabelWidth );
00252     int Index( void ) const;
00254     void SetIndex( int iIndex );
00255 
00257     Node *Owner( void ) const;
00259     virtual void Serialize( Stream &s );
00260 
00263     virtual QString AsString( bool bLocalized = false ) const;
00267     virtual void SetFromString( const QString &sValue, bool bInternal = true, bool bLocalized = false );
00268 
00274         void ClearTargets( void );
00276         void ClearSource( void );
00278         virtual void AddTarget( Attribute &cTarget );
00280         void Connect( Attribute &cSource );
00282         virtual void UpdateTargets( void );
00284 
00289         virtual const ClassDesc* TargetType( void ) const;
00291         virtual void SetPointerValue( Node *pValue, bool bLink = true );
00293         virtual Node *PointerValue( void ) const;
00295         virtual bool ValidatePointerValue( const Node *pValue );
00297 
00298     virtual ~Attribute( void );
00299     virtual void StartEvent( NodeEventType cType ) const;
00300     
00306     void SetOwner( Node *pOwner );
00307 
00313     virtual AttributeWidget *CreateEditorWidget( QWidget *pParent, 
00314         int iWidth 
00315         );
00316     
00321     virtual unsigned int ParameterCount( void ) const;
00323     virtual QString ParameterName( unsigned int iIndex ) const;
00325     virtual QString ParameterValue( unsigned int iIndex ) const;
00327     virtual void SetParameterValue( const QString &sName, const QString &sValue );
00329 
00331     void LogTargets( void );
00333     void LogSource( void );
00335     void CheckValidity( 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     bool m_bInstantEdit;
00355     QString m_sID;
00356 
00357     void Uninstall( void );
00358 
00359     friend class Node;
00360 };
00361 
00366 class MBDLL_DECL AttributeVoid : public Attribute
00367 {
00368 public:
00369     AttributeVoid(Node *pOwner, const QString &sName ) : Attribute(pOwner, sName) {}
00370     ~AttributeVoid() {}
00371 };
00372 
00373 typedef AttributeVoid avoid;
00374 
00380 template < typename type >
00381 struct MBDLL_TEMPLATE_DECL AttributeInstance : public Attribute
00382 {
00384     AttributeInstance( Node *pOwner, const QString &sID ) : Attribute( pOwner, sID ) { m_iSize = sizeof(type); };
00386     AttributeInstance( Node *pOwner, const QString &sID, const type &cValue ) : Attribute( pOwner, sID ) { m_cValue = cValue; m_iSize = sizeof(type); };
00387     AttributeInstance( const AttributeInstance<type> &o ) : Attribute( 0, "" ) { SetValue( o.Value(), true ); m_iSize = sizeof(type); };
00388 
00389     // Value management
00391     const type &Value( void ) const { return m_cValue; };
00394     virtual void SetValue( type cValue, bool bInternal = false )
00395     {
00396         m_cValue = cValue;
00397         UpdateTargets();
00398         if ( !bInternal )
00399             StartEvent( etValueChanged );
00400     };
00401     void UpdateTargets( void )
00402     {
00403         for ( unsigned int i = 0; i < TargetCount(); i++ )
00404         {
00405             if ( Target(i)->Size() == Size() )
00406                 ((AttributeInstance<type> *)Target(i))->SetValue( m_cValue );
00407             else
00408                 Target(i)->StartEvent( etValueChanged );
00409         };
00410     };
00411     void Serialize( Stream &s );
00412 
00413     // Connection management
00414     void AddTarget( Attribute &cTarget )
00415     {
00416         Attribute::AddTarget( cTarget );
00417         if ( cTarget.Size() )
00418         {
00419             AttributeInstance<type> *pT = (AttributeInstance<type> *)&cTarget;
00420             if ( pT->Value() != Value() )
00421                 pT->SetValue( Value() );
00422         };
00423 
00424         StartEvent( etTargetChanged );
00425         cTarget.StartEvent( etSourceChanged );
00426     };
00427 
00428     // Default string operations
00429     QString AsString( bool bLocalized = false ) const
00430     {
00431         bLocalized;
00432         QString sValue;
00433         const unsigned char *tData = (const unsigned char *)(void *)(&m_cValue);
00434         for ( unsigned int i = 0; i < sizeof(m_cValue); i++ )
00435         {
00436             if ( i ) 
00437                 sValue += " ";
00438             sValue += QString("%1").arg(int(tData[i]));
00439         };
00440         return sValue;
00441     };
00442     void SetFromString( const QString &sValue, bool bInternal = true, bool /*bLocalized*/ = false )
00443     {
00444         type cValue;
00445         unsigned char *tData = (unsigned char *)(void *)(&cValue);
00446         for ( int i = 0; i < (int)sizeof(cValue); i++ )
00447             tData[i] = sValue.section(' ', i, i).toInt();
00448         SetValue( cValue, bInternal );
00449     };
00450     AttributeWidget *CreateEditorWidget( QWidget *pParent, int iWidth ) { return Attribute::CreateEditorWidget( pParent, iWidth ); };
00451     Attribute::AttributeType Type( void ) const { return Attribute::AttributeType(); };
00452 
00453     // Operators
00454     // Used for the QString class which does not have a predefined ! operator
00455     // if the line below is used, than pointers wont be linked into the target node THIS pointer.
00456     //inline type operator =( type cValue ) { AttributeInstance<type>::SetValue( cValue, true ); return cValue; }; 
00457 #define OPERATORS_NOEXCMARK( type ) \
00458  \
00459     inline operator type( void ) const { return AttributeInstance<type>::Value(); }; \
00460  \
00461     inline type const &operator ~( void ) const { return AttributeInstance<type>::Value(); }; \
00462  \
00463     inline type operator =( type cValue ) { SetValue( cValue, true ); return cValue; }; \
00464  \
00465     inline type operator =( const AttributeInstance<type> &cValue ) { /*AttributeInstance<type>::*/SetValue( cValue.AttributeInstance<type>::Value(), true ); return cValue; }; \
00466  \
00467     inline bool operator ==( type cValue ) const { return AttributeInstance<type>::Value() == cValue; }; \
00468  \
00469     inline bool operator !=( type cValue ) const { return AttributeInstance<type>::Value() != cValue; }; \
00470  \
00475     inline const QString &operator <<=( const QString &sCategory ) { AttributeInstance<type>::SetCategory( sCategory ); return sCategory; };
00476 #define OPERATORS( type ) \
00477     OPERATORS_NOEXCMARK( type ) \
00478  \
00479     inline bool operator !( void ) { return !AttributeInstance<type>::Value(); };
00480 
00481     OPERATORS( type );
00482  
00483 protected:
00485     AttributeInstance( Node *pOwner, const QString &sName, bool bInstall ) : Attribute( pOwner, bInstall ) { m_sName = sName; m_iSize = sizeof(type); };
00486     
00487 private:
00488 // HACK:
00489 public:
00490     type m_cValue;
00491 };
00492 
00494 typedef AttributeInstance<int> aint;
00496 typedef AttributeInstance<float> afloat;
00498 typedef AttributeInstance<bool> abool;
00500 typedef AttributeInstance<QString> astring; 
00501 
00502 template <> inline
00503 bool astring::operator !(void) { return !(m_cValue.isEmpty()); }
00504 
00505 template <> MBDLL_DECL
00506 QString aint::AsString( bool bLocalized ) const;
00507 template <> MBDLL_DECL
00508 QString afloat::AsString( bool bLocalized ) const;
00509 template <> MBDLL_DECL
00510 QString abool::AsString( bool bLocalized ) const;
00511 template <> inline
00512 QString astring::AsString( bool bLocalized ) const { return m_cValue; };
00513 
00514 template <> MBDLL_DECL
00515 void aint::SetFromString( const QString &sValue, bool bInternal, bool bLocalized );
00516 template <> MBDLL_DECL
00517 void afloat::SetFromString( const QString &sValue, bool bInternal, bool bLocalized );
00518 template <> MBDLL_DECL
00519 void abool::SetFromString( const QString &sValue, bool bInternal, bool bLocalized );
00520 template <> inline
00521 void astring::SetFromString( const QString &sValue, bool bInternal, bool bLocalized ) { SetValue( sValue, bInternal ); };
00522 
00523 template <> inline
00524 Attribute::AttributeType aint::Type( void ) const { return typeInt; };
00525 template <> inline
00526 Attribute::AttributeType abool::Type( void ) const { return typeBool; }; 
00527 template <> inline
00528 Attribute::AttributeType afloat::Type( void ) const { return typeFloat; };
00529 template <> inline
00530 Attribute::AttributeType astring::Type( void ) const { return typeString; };
00531 
00532 MBDLL_DECL AttributeWidget *CreateNewPtrWidget( QWidget *pParent, int iWidth, Attribute *pAttribute, const ClassDesc *pType );
00533 MBDLL_DECL AttributeWidget *CreateNewBoolWidget( QWidget *pParent, int iWidth, abool *pAttribute );
00534 MBDLL_DECL AttributeWidget *CreateNewIntWidget( QWidget *pParent, int iWidth, aint *pAttribute );
00535 
00536 template <> inline
00537 AttributeWidget *abool::CreateEditorWidget( QWidget *pParent, int iWidth ) { return CreateNewBoolWidget( pParent, iWidth, this ); };
00538 template <> inline
00539 AttributeWidget *aint::CreateEditorWidget( QWidget *pParent, int iWidth ) { return CreateNewIntWidget( pParent, iWidth, this ); };
00540 
00542 template < typename type > inline
00543 bool operator ==( const Attribute &cA, const AttributeInstance<type> &cB )
00544 {
00545     return &cA == &cB;
00546 };
00547     
00548 template < typename type > inline
00549 Stream &operator ==( Stream &s, AttributeInstance<type> &c )
00550 {
00551     c.Serialize( s );
00552     return s;
00553 };
00554 
00555 class EventGate;
00556 
00564 template < typename type >
00565 class AttributePointer : public AttributeInstance<type *>
00566 {
00567     const ClassDesc *TargetType( void ) const { return type::StaticClass(); };
00568     Node *PointerValue( void ) const { return AttributeInstance<type *>::Value(); };
00569     void UpdateTargets( void )
00570     {
00571         for ( unsigned int i = 0; i < AttributeInstance<type *>::TargetCount(); i++ )
00572             AttributeInstance<type *>::Target(i)->SetPointerValue( PointerValue(), false );
00573     };
00574     AttributeWidget *CreateEditorWidget( QWidget *pParent, int iWidth ) { return CreateNewPtrWidget( pParent, iWidth, this, type::StaticClass() ); };
00575     typedef bool validator( const type *pTarget );
00576     validator *m_pValidator;
00577     bool ValidatePointerValue( const Node *pValue )
00578     {
00579         if ( m_pValidator == 0 || m_pValidator( dynamic_cast< const type *>( pValue ) ) )
00580             return true;
00581 
00582         return false;
00583     };
00584 
00585 public:
00586     AttributePointer( Node *pOwner=NULL, const QString &sID = "") : AttributeInstance<type *>( pOwner, sID ) { SetValue( 0, true ); m_pValidator = 0; m_sNullString = "NULL"; m_bAllowNull = true; };
00587     AttributePointer( Node *pOwner, const QString &sID,  bool bInstall ) : AttributeInstance<type *>( pOwner, sID, bInstall ) { SetValue( 0, true ); m_pValidator = 0; m_sNullString = "NULL"; m_bAllowNull = true; };
00588     AttributePointer( const AttributePointer<type> &cOther ) : AttributeInstance<type *>( 0, "" ) { SetValue( cOther.Value(), true ); m_pValidator = 0; m_sNullString = "NULL"; m_bAllowNull = true; };
00589     QString AsString( bool /*bLocalized*/ ) const { if ( PointerValue() ) return PointerValue()->Name(); else return m_sNullString; };
00590     void SetFromString( const QString & /*sValue*/, bool /*bInternal*/ = true, bool /*bLocalized*/ = false ) { SetPointerValue( 0 ); };
00592     inline void SetValidator( validator *pValidator ) { m_pValidator = pValidator; };
00593     void SetPointerValue( Node *pNode, bool bLink = true ) 
00594     {
00595         // always accept 0 pointer, the target may be destroyed
00596         if ( pNode && m_pValidator && !m_pValidator( dynamic_cast<type *>( pNode ) ) )
00597             return;
00598         if ( bLink )
00599             SetValue( dynamic_cast<type *>( pNode ) );
00600         else
00601             AttributeInstance<type *>::SetValue( dynamic_cast<type *>( pNode ) );
00602     };
00603     virtual void SetValue( type *cValue, bool bInternal = false )
00604     {
00605         if ( cValue == AttributePointer<type>::Value() )
00606             return;
00607         AttributeInstance<type *>::SetValue( cValue, bInternal );
00608         if ( cValue )
00609             cValue->m_pThis.AddTarget( *this );
00610         else
00611             Attribute::ClearSource();
00612     };
00613     void AddTarget( Attribute &cTarget )
00614     {
00615         Attribute::AddTarget( cTarget );
00616         if ( cTarget.Size() )
00617         {
00618             if ( cTarget.PointerValue() != PointerValue() )
00619                 cTarget.SetPointerValue( PointerValue() );
00620         };
00621     };
00623     void DeleteTarget( void )
00624     {
00625         delete AttributePointer<type>::Value();
00626     };
00642     void Serialize( Stream &s );
00643     void StartEvent( NodeEventType cType ) const
00644     {
00645         AttributeInstance<type *>::StartEvent( cType );
00646         if ( cType == etPointerContentChanged || cType == etPointerTargetDestroyed || cType == etPointerTargetUIChanged || cType == etRefreshDialogUI )
00647             for ( unsigned int i = 0; i < AttributeInstance<type *>::TargetCount(); i++ )
00648                 AttributeInstance<type *>::Target( i )->StartEvent( cType );
00649     };
00650     Attribute::AttributeType Type( void ) const { return AttributeInstance<type *>::typePointer; };
00651 #define PTROPERATORS( type ) \
00652     OPERATORS( type* ); \
00653  \
00654     inline type *operator =( int iValue ) { MB_ASSERT( iValue == 0 ); return operator =( (type *)(uint64)iValue ); }; \
00655  \
00656     inline bool operator ==( int iValue ) { MB_ASSERT( iValue == 0 ); return operator ==( (type *)(uint64)iValue ); }; \
00657  \
00658     inline bool operator !=( int iValue ) { MB_ASSERT( iValue == 0 ); return operator !=( (type *)(uint64)iValue ); }; \
00659  \
00660     inline type *operator ->( void ) { return AttributeInstance<type *>::Value(); }; \
00661  \
00662     inline const type *operator ->( void ) const { return AttributeInstance<type *>::Value(); }; \
00663  \
00664     inline operator bool( void ) const { return AttributeInstance<type *>::Value() != 0; };
00665     PTROPERATORS( type );
00666 
00667     QString m_sNullString;
00668     bool m_bAllowNull;
00669 
00670     friend class Node;
00671     friend class AttributeThisPointer;
00672     friend struct Attribute;
00673 };
00674 
00675 //template < typename type>
00676 //typedef AttributePointer<type> aptr<type>;
00677 #define aptr AttributePointer
00678 template < typename type >
00679 inline Stream &operator ==( Stream &cStream, AttributePointer<type> &cPointer ) { cPointer.AttributePointer<type>::Serialize( cStream ); return cStream; };
00680 
00682 class MBDLL_DECL AttributeThisPointer : public aptr<Node>
00683 {
00684     AttributeThisPointer( Node *pOwner );
00685     const ClassDesc *TargetType( void ) const;
00686     PTROPERATORS( Node );
00687 
00688     friend class Node;
00689 };
00690 
00692 class MBDLL_DECL Node
00693 {
00694     Attribute *m_pAttributes;
00695 
00696     static Node *s_pFirstNode;
00697     int m_iID;
00698     Node *m_pNext, *m_pPrev;
00699 
00700     static int s_iNextID;
00701     friend struct Attribute;
00702     friend class Stream;
00703 
00704 public:
00705 
00707     enum DiagnosticLevel
00708     {
00710         dgnLevel1,
00711 
00713         dgnLevel2,
00714 
00716         dgnLevel3
00717     };
00718 
00721     Node( const QString &sStringID = "", const QString &sDisplayName = "" );
00722     virtual ~Node( void );
00723     virtual void Initialize( void );
00724 
00729 
00749         virtual void OnNodeEvent( const Attribute &cAttribute, NodeEventType cType );
00751         virtual void OnEvent( const EventGate &cEvent );
00753         void RequestDeferredEvent( Attribute &cAttribute );
00755 
00757     void LoadTemplate( const QString &sFileName = "", bool bStartEvent = false );
00759     void SaveTemplate( const QString &sFileName = "", bool bSaveOnlyVisible = false);
00761     unsigned int Version( void ) const;
00763     void SetVersion( unsigned int iVersion );
00765     unsigned int ReferenceCount( void ) const;
00767     Attribute *ReferencePointer( unsigned int iIndex ) const;
00769     Node *ReferenceNode( unsigned int iIndex ) const;
00770     
00775         static Node *First( void );
00777         Node *Next( void ) const;
00779         int ID( void ) const;
00781         bool SetID( int iID );
00783         static Node *ByID( int iID );
00785         static Node *ByName( const QString &sClass, const QString &sName );
00787 
00788     // TODO I18N: remove this deprecated interface.
00791     virtual QString Name( const ClassDesc *pClass = 0 ) const;
00792     // TODO I18N: remove this deprecated interface.
00795     virtual void SetName( const QString &sName );
00798     virtual QString StringID( const ClassDesc *pClass = 0 ) const;
00800     virtual void SetStringID( const QString &sStringID );
00803     virtual QString DisplayName( void ) const;
00805     virtual void SetDisplayName( const QString & sDisplayName );
00807     virtual QString HelpID( void ) const;
00809     virtual void SetHelpID( const QString &sHelpID );
00810 
00812     void Annex( Node *pSource, const QString &sCategory = "" );
00813 
00818         unsigned int AttributeCount( void ) const;
00820         Attribute *AttributeByIndex( int iIndex ) const;
00822         Attribute *AttributeByName( const QString &sName ) const;
00824         Attribute *AttributeByID( const QString &sID ) const;
00826         void SetAttributeValue( const QString &sAttributeID, const QString &sNewValue );
00828         QString AttributeValue( const QString &sAttributeID ) const;
00830         void LogAttributes( void ) const;
00832         virtual QWidget *CreatePropertiesWindow( QWidget *pParent );
00836         Attribute *AddAttribute(Attribute::AttributeType type, const QString &id);
00837         // Allows SDK users to add attributes at runtime.  The Attribute passed into the function
00838         // *MUST* be allocated on the heap (dynamically allocated).  Returns true on success & false on failure.  On successfull adding
00839         // then this node manages the attribute (deletes on node destructor).  Returns true if attribute
00840         // already exists.  This function sets the owner of this attribute to the node.  The new owner is
00841         // responsible for deleting the attribute.  Attribute visibility is set to false.
00842         // Note that the attribute will be serialized when the node is serialized.
00843         //
00844         // Disabled until we support serialization of user-defined attribute types.
00845         //bool AddAttribute(Attribute *pAttribute);
00846 
00847         // Runtime attribute count
00849 
00853     virtual void Serialize( Stream &s );
00854 
00855     AttributeThisPointer m_pThis;
00856 
00857     friend class EventGate;
00858 
00860     bool IsKindOf( const ClassDesc *pClass ) const;
00861     
00865     void ContentChanged( void ) const;
00866     
00871     virtual void CheckValidity( DiagnosticLevel iLevel = dgnLevel2 ) const;
00872 
00873     virtual void CopyTo( Node *pNode) const;
00874 
00875     virtual Node *Duplicate( void ) const;
00876 
00877     DECLARE_CLASS;
00878 
00879 private:
00880     QString m_sStringID;
00881     QString m_sDisplayName;
00882     QString m_sHelpID;
00883     mutable unsigned int m_iVersion;
00884 
00885     QList<Attribute *> m_aRuntimeAttributes;
00886 };
00887 
00889 AttributeWidget *CreateNewEventWidget( QWidget *pParent, int iWidth, EventGate *pAttribute );
00890 
00916 class MBDLL_DECL EventGate : public AttributeInstance<int>
00917 {
00918     void StartEvent( NodeEventType cType ) const;
00919     AttributeWidget *CreateEditorWidget( QWidget *pParent, int iWidth );
00920 
00921 public:
00923     EventGate( Node *pOwner, const QString &sID = "" );
00925     void Trigger( void );
00927     void Connect( EventGate &cEvent );
00929     bool operator ==( const EventGate &cEvent ) const;
00930 };
00931 typedef EventGate aevent;
00932 
00933 // special attributes
00935 class MBDLL_DECL AttributeFloatRange : public afloat
00936 {
00937     Q_DECLARE_TR_FUNCTIONS(mudbox::AttributeFloatRange);
00938 private:
00939     mutable float m_fMin, m_fMax;
00940     mutable float m_fEditMin, m_fEditMax;
00941     float m_fFactor;
00942     int m_iPrecision;
00943 
00944     QString AsString( bool /*bLocalized*/ ) const;
00945     void SetFromString( const QString &sValue, bool bInternal = true, bool bLocalized = false );
00946 
00947     unsigned int ParameterCount( void ) const;
00948     QString ParameterName( unsigned int iIndex ) const;
00949     QString ParameterValue( unsigned int iIndex ) const;
00950     void SetParameterValue( const QString &sName, const QString &sValue );
00951 public:
00953     AttributeFloatRange( Node *pOwner, const QString &sID, float fMinimum = 0, float fMaximum = 1, float fFactor = 1, int iPrecision = 2 );
00954     OPERATORS( float );
00955     void StartEvent( NodeEventType cType ) const;
00956     AttributeWidget *CreateEditorWidget( QWidget *pParent, int iWidth );
00957     float Min( void ) const;
00958     float Max( void ) const;
00959     void SetMin( float fValue );
00960     void SetMax( float fValue );
00961     // Set the min max limit to the edit box
00962     void SetEditMin( float fEditMin );
00963     void SetEditMax( float fEditMax );
00964     float EditMin( void ) const;
00965     float EditMax( void ) const;
00966 };
00967 
00968 typedef AttributeFloatRange afloatr;
00969 MBDLL_DECL Stream &operator ==( Stream &s, afloatr &a );
00970 
00972 class MBDLL_DECL AttributeNumber : public AttributeInstance<int>
00973 {
00974     int m_iDigitCount;
00975     int m_iControlWidth;
00976     AttributeWidget *CreateEditorWidget( QWidget *pParent, int iWidth );
00977 public:
00978     AttributeNumber( Node *pOwner, const QString &sID, int m_iControlwidth = 40, int m_iDigitCount = 0 );
00979     OPERATORS( int );
00980 };
00981 
00982 typedef AttributeNumber anumber;
00983 
00985 class MBDLL_DECL AttributeEnumeration : public aint
00986 {
00987     Q_DECLARE_TR_FUNCTIONS(mudbox::AttributeEnumeration);
00988 private:
00989     Store<QString> m_aValues;
00990     bool m_bDisplayAsIcons;
00991 
00992     unsigned int ParameterCount( void ) const;
00993     QString ParameterName( unsigned int iIndex ) const;
00994     QString ParameterValue( unsigned int iIndex ) const;
00995     void SetParameterValue( const QString &sName, const QString &sValue );
00996 public:
00997     AttributeEnumeration( Node *pOwner, const QString &sID );
00998     OPERATORS( int );
00999     AttributeWidget *CreateEditorWidget( QWidget *pParent, int iWidth );
01001     unsigned int AddItem( const QString &sValue );
01002     void SetItem( unsigned int iIndex, const QString &sValue );
01004     void SetIconMode( 
01005         bool bDisplayAsIcons 
01006 
01007 
01008         ) { m_bDisplayAsIcons = bDisplayAsIcons; };
01010     bool IconMode( void ) const { return m_bDisplayAsIcons; };
01025     AttributeEnumeration &operator <<( const char *sValue );
01026     AttributeEnumeration &operator =( const AttributeEnumeration &aeValue );
01027 
01029     unsigned int ItemCount( void ) const;
01030     void Clear( void );
01031     QString Item( unsigned int iIndex ) const;
01032 };
01033 typedef AttributeEnumeration aenum;
01034 MBDLL_DECL Stream &operator ==( Stream &s, aenum &a );
01035 
01037 class MBDLL_DECL AttributeFilename : public astring
01038 {
01039 public:
01040     AttributeFilename( Node *pOwner, const QString &sID, bool bMustExists = true );
01041     OPERATORS_NOEXCMARK( QString );
01042     AttributeWidget *CreateEditorWidget( QWidget *pParent, int iWidth );
01043 
01044     unsigned int ParameterCount( void ) const;
01045     QString ParameterName( unsigned int iIndex ) const;
01046     QString ParameterValue( unsigned int iIndex ) const;
01047     void SetParameterValue( const QString &sName, const QString &sValue );
01048 
01049     bool m_bMustExists;
01050     QString m_sFilter;
01051     QString m_sPath;
01052     QString m_sSelectedFilter;
01053 };
01054 typedef AttributeFilename afilename;
01055 
01057 class MBDLL_DECL AttributeTextureFilename : public AttributeFilename
01058 {
01059 public:
01060     AttributeTextureFilename( Node *pOwner, const QString &sID,  bool bMustExists = true );
01061     OPERATORS_NOEXCMARK( QString );
01062     AttributeWidget *CreateEditorWidget( QWidget *pParent, int iWidth );
01063 };
01064 typedef AttributeTextureFilename atexturefilename;
01065 MBDLL_DECL Stream &operator ==( Stream &s, afilename &a );
01066 
01070 class MBDLL_DECL AttributeWatch : public Attribute
01071 {
01072     Attribute::AttributeType Type( void ) const;
01073 public:
01074     AttributeWatch( Node *pOwner, const QString &sID = "");
01075 };
01076 
01078 class MBDLL_DECL AttributeBoolCollection : public AttributeInstance<int>
01079 {
01080     Q_DECLARE_TR_FUNCTIONS(mudbox::AttributeBoolCollection);
01081 
01082 private:
01083     AttributeWidget *CreateEditorWidget( QWidget *pParent, int iWidth );
01084     QString m_aNames[32];
01085     unsigned int m_iBoolCount;
01086 
01087     unsigned int ParameterCount( void ) const;
01088     QString ParameterName( unsigned int iIndex ) const;
01089     QString ParameterValue( unsigned int iIndex ) const;
01090     void SetParameterValue( const QString &sName, const QString &sValue );
01091 public:
01092     AttributeBoolCollection( Node *pOwner, const QString &sID );
01093     void Clear( void );
01094     void SetValue( unsigned int iIndex, bool bValue, bool bInternal = false );
01095     bool Value( unsigned int iIndex ) const;
01096     int AddBool( const QString &sName, bool bValue = false );
01097     unsigned int BoolCount( void ) const;
01098     void SetBoolName( unsigned int iIndex, const QString &sName );
01099     QString BoolName( unsigned int iIndex ) const;
01100 };
01101 typedef AttributeBoolCollection aboolc;
01102 
01103 }; // end of namespace mudbox
01104 
01105