Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
3.5 KiB

  1. //======= Copyright � 1996-2006, Valve Corporation, All rights reserved. ======
  2. //
  3. // Utility classes for creating maya commands
  4. //
  5. //=============================================================================
  6. #ifndef VSMAYACOMMAND_H
  7. #define VSMAYACOMMAND_H
  8. #if defined( _WIN32 )
  9. #pragma once
  10. #endif
  11. #include "tier0/dbg.h"
  12. #include "xsi_status.h"
  13. #include "idccmain.h"
  14. #include "xsi_context.h"
  15. //-----------------------------------------------------------------------------
  16. // Forward declarations
  17. //-----------------------------------------------------------------------------
  18. namespace XSI
  19. {
  20. class Context;
  21. class CRef;
  22. class PluginRegistrar;
  23. }
  24. //-----------------------------------------------------------------------------
  25. // Base class for maya commands
  26. //-----------------------------------------------------------------------------
  27. class CVsMayaCommand
  28. {
  29. public:
  30. CVsMayaCommand();
  31. virtual void OnRegister( XSI::PluginRegistrar& in_reg ) {}
  32. virtual XSI::CStatus doIt( XSI::Context &ctx ) = 0;
  33. // Derived classes must specify this to override syntax
  34. virtual void SpecifySyntax( const XSI::Context &ctx ) {}
  35. };
  36. //-----------------------------------------------------------------------------
  37. // Base class for maya command factories
  38. //-----------------------------------------------------------------------------
  39. class CVsMayaCommandFactoryBase
  40. {
  41. public:
  42. // Returns the commandname associated with the factory
  43. const char *GetCommandName();
  44. // Called when we register
  45. virtual void OnRegister( XSI::PluginRegistrar& in_reg ) {}
  46. // Registers/deregisters all commands
  47. static bool RegisterAllCommands( XSI::PluginRegistrar& in_reg );
  48. static void DeregisterAllCommands( const XSI::PluginRegistrar& in_reg );
  49. protected:
  50. // Constructor
  51. CVsMayaCommandFactoryBase( const char *pCommandName );
  52. private:
  53. CVsMayaCommandFactoryBase* m_pNextFactory;
  54. const char* m_CommandName;
  55. static CVsMayaCommandFactoryBase *s_pFirstCommandFactory;
  56. };
  57. template < class T >
  58. class CVsDCCCommandFactory : public CVsMayaCommandFactoryBase
  59. {
  60. typedef CVsMayaCommandFactoryBase BaseClass;
  61. public:
  62. // Constructor
  63. CVsDCCCommandFactory( const char *pCommandName ) : BaseClass( pCommandName ) {}
  64. // Called when we register
  65. virtual void OnRegister( XSI::PluginRegistrar& in_reg )
  66. {
  67. m_Singleton.OnRegister( in_reg );
  68. }
  69. T m_Singleton;
  70. };
  71. //-----------------------------------------------------------------------------
  72. // Helper macro to instantiate a command
  73. //-----------------------------------------------------------------------------
  74. #define INSTALL_MAYA_COMMAND( _commandClassName, _stringName ) \
  75. static CVsDCCCommandFactory< _commandClassName > s_##_commandClassName##_Factory( #_stringName ); \
  76. XSIPLUGINCALLBACK XSI::CStatus _stringName##_Init( const XSI::CRef& in_context ) \
  77. { \
  78. if ( !g_pDCCMain->IsInitialized() ) \
  79. return XSI::CStatus::Fail; \
  80. XSI::Context ctx(in_context); \
  81. s_##_commandClassName##_Factory.m_Singleton.SpecifySyntax( ctx ); \
  82. return XSI::CStatus::OK; \
  83. } \
  84. XSIPLUGINCALLBACK XSI::CStatus _stringName##_Execute( XSI::CRef& in_context ) \
  85. { \
  86. if ( !g_pDCCMain->IsInitialized() ) \
  87. return XSI::CStatus::Fail; \
  88. XSI::Context ctxt( in_context ); \
  89. s_##_commandClassName##_Factory.m_Singleton.doIt( ctxt ); \
  90. } \
  91. #endif // VSMAYACOMMAND_H