2 #include "AL/maya/Common.h"
4 #include "maya/MStatus.h"
5 #include "maya/MString.h"
6 #include "maya/MGlobal.h"
53 #ifndef AL_GENERATING_DOCS
65 inline bool operator < (
const Menu& menu)
const
66 {
return m_name < menu.m_name; }
68 inline bool operator == (
const Menu& menu)
const
69 {
return m_name == menu.m_name; }
71 inline void print_indent(std::ostream& os,
int indent)
const
72 {
for(
int i = 0; i <= indent; ++i) os <<
" "; }
74 void generate(std::ostringstream& os, std::ostringstream& kill,
const char* prefix,
int indent = 0)
const;
76 const std::string& name()
const {
return m_name; }
77 const std::set<Menu>& childMenus()
const {
return m_childMenus; }
78 const std::vector<MenuItem>& menuItems()
const {
return m_menuItems; }
82 mutable std::set<Menu> m_childMenus;
83 mutable std::vector<MenuItem> m_menuItems;
87 static const std::set<Menu>& rootMenus()
91 static void clearRootMenus()
101 static MenuItem*
addEntry(
const char* menuItemPath,
const char* command,
bool hasCheckbox =
false,
bool defaultCheckBoxValue =
false);
108 static bool addEntry(
const char* menuItemPath,
const char* command,
const char* optionBoxCommand);
118 template<
typename FnPlugin>
119 static MStatus
generatePluginUI(FnPlugin& fnPlugin,
const MString& prefix,
const MString& extraOnInit =
"",
const MString& extraOnExit =
"")
123 MString ui_init = prefix +
"_initGUI";
124 MString ui_exit = prefix +
"_exitGUI";
127 std::ostringstream initGUI;
128 initGUI <<
"global proc " << ui_init.asChar() <<
"()\n{\n global string $gMainWindow;\n";
130 if(extraOnInit.length())
131 initGUI <<
" " << extraOnInit.asChar() << std::endl;
134 std::ostringstream exitGUI;
135 exitGUI <<
"global proc " << ui_exit.asChar() <<
"()\n{\n";
136 if(extraOnExit.length())
137 exitGUI <<
" " << extraOnExit.asChar() << std::endl;
138 exitGUI <<
" deleteUI ";
141 for(
auto it = m_menus.begin(); it != m_menus.end(); ++it)
143 it->generate(initGUI, exitGUI, prefix.asChar());
150 exitGUI <<
";\n}\n\n";
152 MGlobal::executeCommand(initGUI.str().c_str());
153 MGlobal::executeCommand(exitGUI.str().c_str());
155 #if AL_USD_PRINT_UI_CODE
156 std::cout << initGUI.str() << std::endl;
157 std::cout << exitGUI.str() << std::endl;
160 return fnPlugin.registerUI(ui_init, ui_exit);
164 static std::set<Menu> m_menus;