kernel.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 
00018 class MBDLL_DECL FileEventNotifier : public Node
00019 {
00020     DECLARE_CLASS;
00021 
00022     enum Type
00023     {
00026         typeBrowseForRead,
00029         typeBrowseForWrite,
00032         typePreRead,
00034         typePostRead,
00037         typePreWrite,
00039         typePostWrite
00040     } m_eType;
00043     QString m_sFileName;
00044 };
00045 
00046 class MBDLL_DECL KeyboardEventNotifier : public Node
00047 {
00048     DECLARE_CLASS;
00049 
00051     enum Type
00052     {
00053         ePressed,
00054         eReleased
00055     } m_eType;
00057     int m_iKey;
00061     int m_iModifiers;
00062 };
00063 
00064 //-----------------------------------------------------------------------------
00071 class MBDLL_DECL TextureUnprojector : public Node
00072 {
00073     DECLARE_CLASS;
00074 
00075 public:
00079     virtual Texture*  DoUnproject(int xSize, int ySize, bool want16BitFP = false);
00080 };
00081 
00082 //-----------------------------------------------------------------------------
00083 
00084 class Operation;
00085 class XRef;
00086 
00090 class MBDLL_DECL Kernel : public Node
00091 {
00092     Q_DECLARE_TR_FUNCTIONS(mudbox::Kernel);
00093     DECLARE_CLASS;
00094     class XRef* m_pXRef;
00095 public:
00096     enum MessageBoxType
00097     {
00098         msgInformation,
00099         msgWarning,
00100         msgQuestion,
00101         msgError
00102     };
00103     enum MessageBoxButton
00104     {
00105         buttonNone      = 0x00000000,
00106         buttonOk        = 0x00000400,
00107         buttonCancel    = 0x00400000,
00108         buttonClose     = 0x00200000,
00109         buttonYes       = 0x00004000,
00110         buttonYesToAll  = 0x00008000,
00111         buttonNo        = 0x00010000,
00112         buttonNoToAll   = 0x00020000,
00113         buttonAbort     = 0x00040000,
00114         buttonRetry     = 0x00080000,
00115         buttonIgnore    = 0x00100000,
00116         buttonHelp      = 0x01000000
00117     };
00118     enum HUDMessageType
00119     {
00120         HUDmsgPin,      
00121         HUDmsgFade      
00122     };
00123 
00124     enum StatusType
00125     {
00126         stNormal,       
00127         stWarning,      
00128         stError         
00129     };
00130 
00131     static QString menuFile;
00132     static QString menuEdit;
00133     static QString menuCreate;
00134     static QString menuCurves;
00135     static QString menuDisplay;
00136     static QString menuHelp;
00137     static QString menuPlugins;
00138     static QString menuMesh;
00139     static QString menuRender;
00140     static QString menuScripts;
00141     static QString menuMaps;
00142     static QString menuWindows;
00143 
00145     Kernel( void ); 
00146 
00153     void Log(const QString &sMessage);
00154     
00156     void LogMemoryStatus(
00157         bool bCompact = true    
00158         );
00159     
00164     void LogMemoryBlocks(
00165         float fSizeLimit = 0.01  
00166         );
00167     
00169     int MessageBox(
00170         MessageBoxType iType,   
00171         const QString &sTitle,  
00172         const QString &sText,   
00173         int iButtons = buttonNone,  
00174         int iDefaultButton = buttonNone 
00175         );
00176 
00180     int OneTimeMessageBox (
00181         MessageBoxType iType,   
00182         const QString &sTitle,  
00183         const QString &sText,   
00184         int buttons = 0  
00185         );
00186 
00193     void HUDMessageShow(
00194         const QString &sMessage, 
00195         HUDMessageType iType    
00196         );
00197         
00202     void HUDMessageHide();
00203     
00205     void SetStatus(
00206         StatusType iType,   
00207         const QString& sMsg 
00208         );
00209 
00225     void AddClassMenuItem(
00226         const QString &sMenu,           
00227         const QString &sSubmenu,        
00228         const ClassDesc *pClass,        
00229         const QString &sCreatorText,    
00230         const int &index = -1,          
00231         const int &subindex = -1,       
00232         const bool addSeparator = false 
00233         );
00234 
00241     void AddCallbackMenuItem(
00242         const QString &sMenu,       
00243         const QString &sSubmenu,        
00244         const QString &sItemName,   
00245         void (*pCallback)(),        
00246         const QString &sID = "",    
00247         const int &index = -1,      
00248         const int &subindex = -1,   
00249         const bool addSeparator = false 
00250         );
00251 
00252     void AddLayerCallbackMenuItem(
00253         Interface::LayerUIType ltType,
00254         const QString &sItemName,
00255         void (*pCallback)()
00256         );
00257 
00261     Mesh *CreateMesh(
00262         Topology::FaceType eType    
00263         );
00264 
00266     void ProgressStart(
00267         const QString &sDescription,        
00268         unsigned int iMaxValue          
00269         );
00270     
00272     void ProgressSet(
00273         unsigned int iValue     
00274         );
00275     
00277     void ProgressAdd( void );
00278     
00280     void ProgressEnd( void );
00281     
00287     bool ProgressIsCancelRequested( void );
00288 
00292     QString LoadFileDialog(
00293         const QString &sTitle,  
00294         const QString &sPath,   
00295         const QString &sFilter  
00296         ) const;
00297     
00301     QString SaveFileDialog(
00302         const QString &sTitle,          
00303         const QString &sPath,           
00304         const QString &sFilter,         
00305         bool bAskForOverwrite = true,   
00306         QString* sSelectedFilter = 0        
00307         ) const;
00308 
00312     QString GetDirectoryDialog(
00313         const QString &sTitle,  
00314         const QString &sPath    
00315         ) const;
00316 
00320     QStringList LoadFilesDialog(
00321         const QString &sTitle,  
00322         const QString &sPath,   
00323         const QString &sFilter  
00324         ) const;
00325 
00327     void WaitCursorStart( void );
00328     
00330     void WaitCursorEnd( void );
00331 
00332     // Automation
00333 
00364     void RecordCommand( const QString &sCommand );
00365 
00367     astring NextCommand;
00368 
00370     class Scene *CreateDefaultScene( void );
00371 
00372     // plugin management
00382     const ClassDesc *PreferredDescendant(
00383         const ClassDesc *pClass     //< [in] The ClassDesc of a base class (obtained via the StaticClass() function:  myClass::StaticClass() )
00384         ) const;
00385     
00390     Node *CreateClassInstance( const ClassDesc *pClass ) const;
00391 
00397     Image *LoadImage(
00398         const QString &sFileName        
00399         ) const;
00400 
00402     void GLCheckError(
00403         const char *sSourceFileName,    
00404         const char *sFunctionName,      
00405         unsigned int iLine              
00406         ) const;
00407     
00409     void GLCheckStates(
00410         const char *sSourceFileName,    
00411         const char *sFunctionName,      
00412         unsigned int iLine              
00413         ) const;
00414 
00415 
00419     void Redraw( void );
00420 
00422     class Scene *Scene( void ) const;
00423     
00425     mudbox::Preferences *Preferences( void ) const;
00426     
00428     class mudbox::Interface *Interface( void ) const;
00429 
00431     class Statistics *Statistics( void ) const;
00432     
00434     class ViewPort *ViewPort( void ) const;
00435     
00437     QWidget *MainWindow( void ) const;
00438 
00440     QString MudboxVersionName( void ) const;
00441 
00443     void AddView(QString className, QString windowTitle, const bool select = false) const;
00444 
00446     void RegisterWindowPlugin(WindowPlugin* plugin) const;
00447 
00449     mudbox::TrayAccessor *TrayAccessor( void ) const;
00450 
00452     bool ExtractArchiveFile(QString sArchiveFilePath, QString sDestPath);
00453     bool CreateArchiveFile(QString sArchiveFilePath, QStringList files);
00454 
00456     void AddToCreateMeshMenu(QFileInfo fileInfo);
00457     
00459     QString DataDirectory( void ) const;
00460 
00462     QString ApplicationDirectory( void ) const;
00463     
00465     QString ProjectFilesDirectory( void ) const;
00466     
00468     QString SafeWritableDirectory( void ) const;
00469     
00471     QString PluginDirectory( const QString& pluginName ) const;
00472     
00475     bool IsTestModeOn( void ) const;
00476     
00478     bool IsBetaVersion( void ) const;
00479 
00481     void RefreshUI( void ) const;
00482     
00484     enum SceneRenderMode {
00485         srmNormal = 0,          
00486         srmFlatTexturesOnBlack, 
00487         srmFlatTexturesOnWhite, 
00488         srmFlatNoTextures,      
00489         srmNoTextures           
00490     };
00491 
00506     Image *RenderScene(
00507         const QString &sChannel, 
00508         int  iWidth,        
00509         int  iHeight,       
00510         SceneRenderMode renderMode, 
00511         enum Image::Format fmt = Image::e8integer, 
00512         bool bTiledImg = true 
00513         );
00514 
00529     Image *RenderScene(
00530         int  iWidth,        
00531         int  iHeight,       
00532         SceneRenderMode renderMode, 
00533         enum Image::Format fmt = Image::e8integer, 
00534         bool bTiledImg = true 
00535         );
00536 
00548     Image *RenderScene(
00549         int  iWidth,          
00550         int  iHeight,         
00551         enum Image::Format fmt = Image::e8integer, 
00552         bool bTiledImg = true 
00553         ) const;
00554 
00555 
00562 
00563     Image *ExtractUnprojectedTextures(const QString &sChannel, 
00564                                       int  iWidth,   
00565                                       int  iHeight,  
00566                                       enum Image::Format fmt = Image::e8integer, 
00567                                       bool bTiledImg = false 
00568         );
00569 
00570     Image *ExtractUnprojectedTextures(int  iWidth,   
00571                                       int  iHeight,  
00572                                       enum Image::Format fmt = Image::e8integer, 
00573                                       bool bTiledImg = false 
00574         );
00575 
00584      
00585     Image *ExtractShadingMap(int iWidth,            
00586                              int iHeight,           
00587                              enum Image::Format fmt = Image::e8integer,  
00588                              bool bTiledImg = false 
00589         );
00590 
00591 
00593     int ViewportWidth() const;
00594     
00596     int ViewportHeight() const;
00597 
00599     class XRef* XRef() const; 
00600 
00608     void ReportVideoMemoryUsage(
00609         qint64 iSize        
00610         );
00611     
00613     qint64 VideoMemoryUsage( void ) const;
00614 
00616     qint64 TotalVideoMemory( void ) const;
00617     
00622     bool DoOperation(
00623         Operation *pOp, 
00624         bool bMerge = false 
00625         );
00626 
00630     void FlushUndoQueue();
00631 
00633     aevent PreRenderEvent;
00634     
00636     aevent FrameEvent;
00637     
00639     aevent StrokeBeginEvent;
00640 
00642     aevent StrokeEndEvent;
00643 
00645     aevent EndRenderEvent;
00646     
00648     aevent TangentMirrorUpdateEvent;
00649     
00651     aevent GeometryAddedEvent;
00652     
00654     aevent GeometryRemovedEvent;
00655 
00657     aevent GeometryAboutToRemovedEvent;
00658 
00660     aevent GeometryTransformedEvent;
00661     
00666     aevent LowMemoryEvent;
00667     
00670     aevent RestoreMemoryEvent;
00671     
00674     aevent PostRenderEvent;
00675 
00689     QString TriggerFileEvent(
00690         FileEventNotifier::Type eType,      
00691         const QString &sFileName        
00692         ) const;
00693 
00702     mutable aptr<FileEventNotifier> FileEvent;
00703  
00710     mutable aptr<KeyboardEventNotifier> KeyboardEvent;
00711 
00714     aptr<Node> SelectedNode;
00715 
00718     aptr<BrushOperation> SelectedBrush;
00719 
00725     aptr<Geometry> m_pGeometryToAdd;
00726 
00730     aevent PostUIInitializationEvent;
00731 
00733     aevent PaintSelectionEvent;
00734 
00736     aevent PaintLayerAddedEvent;
00737 
00739     aevent PaintLayerRemovedEvent;
00740 
00742     aevent ScenePreDeletedEvent;
00743 };
00744 
00746 MBDLL_DECL Kernel *Kernel( void );
00747 
00749 class MBDLL_DECL Timer
00750 {
00751     int m_iIndex;
00752 
00753 public:
00755     Timer( const char *sName, int &iIndex );
00756     ~Timer( void );
00758     static unsigned int Current( void );
00761     static void ResetAll( void );
00763     static void LogAll( void );
00764 };
00765 
00766 
00768 class MBDLL_DECL Statistics
00769 {
00770 public:
00771     void AddRenderedPolygonCount( unsigned int iPolygonCount );
00772     int FrameCount( void ) const;
00773 };
00774 
00780 template < typename c >
00781 c* CreateInstance( void ) { return dynamic_cast<c *>( Kernel()->CreateClassInstance( c::StaticClass() ) ); };
00782 
00820 template < typename c >
00821 class MBDLL_TEMPLATE_DECL Instance
00822 {
00823     c *m_pObject;
00824 
00825 public:
00826     inline Instance( c* pObject ) : m_pObject( pObject ) {};
00827     inline Instance( void ) { m_pObject = CreateInstance<c>(); };
00828     inline ~Instance( void ) { if( m_pObject ) delete m_pObject; };
00829     inline c *operator ->( void ) { return m_pObject; };
00830     inline const c *operator ->( void ) const { return m_pObject; };
00831     inline operator c*( void ) const { return m_pObject; };
00832 
00835     inline c * Release() { c* pTemp = m_pObject; m_pObject = 0; return pTemp; }
00836 };
00837 
00838 }; // end of namespace mudbox