AL_USDMaya  0.16.6
USD to Maya Bridge
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
CommandGuiHelper.h
1 #pragma once
2 #include "AL/maya/Common.h"
3 
4 #include "maya/MString.h"
5 #include "maya/MPxCommand.h"
6 
7 #include <sstream>
8 #include <string>
9 #include <vector>
10 
11 namespace AL {
12 namespace maya {
13 
15 typedef MStringArray (*GenerateListFn)(const MString& context);
16 
17 //----------------------------------------------------------------------------------------------------------------------
20 //----------------------------------------------------------------------------------------------------------------------
22  : public MPxCommand
23 {
24 public:
25  AL_MAYA_DECLARE_COMMAND();
26 
33  static int32_t registerListFunc(GenerateListFn generateListFunc, const MString& menuName);
34 
35 private:
36  bool isUndoable() const override { return false; }
37  MStatus doIt(const MArgList& args) override;
38  static std::vector<std::pair<MString, GenerateListFn>> m_funcs;
39 };
40 
41 //----------------------------------------------------------------------------------------------------------------------
77 //----------------------------------------------------------------------------------------------------------------------
79 {
80 public:
81 
83  enum FileMode
84  {
85  kSave = 0,
86  kLoad = 1,
88  kDirectory = 3,
90  };
91 
95  {
98  };
99 
107  CommandGuiHelper(const char* commandName, const char* windowTitle, const char* doitLabel, const char* menuItemPath, bool hasOptionBox = true);
108 
114  CommandGuiHelper(const char* commandName, const char* menuItemPath, bool checkBoxValue = false);
115 
118 
124  void addFlagOption(const char* commandFlag, const char* label, bool defaultVal, bool persist = true);
125 
131  void addBoolOption(const char* commandFlag, const char* label, bool defaultVal, bool persist = true);
132 
138  void addIntOption(const char* commandFlag, const char* label, int32_t defaultVal, bool persist = true);
139 
147  void addIntSliderOption(const char* commandFlag, const char* label, int32_t minVal, int32_t maxVal, int32_t defaultVal, bool persist = true);
148 
154  void addInt2Option(const char* commandFlag, const char* label, const int32_t defaultVal[2], bool persist = true);
155 
162  void addInt2Option(const char* commandFlag, const char* label, const int32_t a, const int32_t b, bool persist = true)
163  {
164  const int32_t temp[] = {a, b};
165  addInt2Option(commandFlag, label, temp, persist);
166  }
167 
173  void addInt3Option(const char* commandFlag, const char* label, const int32_t defaultVal[3], bool persist = true);
174 
182  void addInt3Option(const char* commandFlag, const char* label, const int32_t a, const int32_t b, const int32_t c, bool persist = true)
183  {
184  const int32_t temp[] = {a, b, c};
185  addInt3Option(commandFlag, label, temp, persist);
186  }
187 
193  void addInt4Option(const char* commandFlag, const char* label, const int32_t defaultVal[4], bool persist = true);
194 
203  void addInt4Option(const char* commandFlag, const char* label, const int32_t a, const int32_t b, const int32_t c, const int32_t d, bool persist = true)
204  {
205  const int32_t temp[] = {a, b, c, d};
206  addInt4Option(commandFlag, label, temp, persist);
207  }
208 
218  void addListOption(const char* commandFlag, const char* label, GenerateListFn generateList);
219 
239  void addEnumOption(
240  const char* commandFlag,
241  const char* label,
242  int defaultIndex,
243  const char* const enumNames[],
244  const int32_t enumValues[],
245  bool persist = true,
246  bool passAsString = false);
247 
269  const char* commandFlag,
270  const char* label,
271  int defaultIndex,
272  const char* const enumNames[],
273  const int32_t enumValues[],
274  bool persist = true,
275  bool passAsString = false);
276 
282  void addDoubleOption(const char* commandFlag, const char* label, double defaultVal, bool persist = true);
283 
291  void addDoubleSliderOption(const char* commandFlag, const char* label, double minVal, double maxVal, double defaultVal, bool persist = true);
292 
298  void addVec2Option(const char* commandFlag, const char* label, const double defaultVal[2], bool persist = true);
299 
306  void addVec2Option(const char* commandFlag, const char* label, const double a, const double b, bool persist = true)
307  {
308  const double temp[] = {a, b};
309  addVec2Option(commandFlag, label, temp, persist);
310  }
311 
317  void addVec3Option(const char* commandFlag, const char* label, const double defaultVal[3], bool persist = true);
318 
326  void addVec3Option(const char* commandFlag, const char* label, const double a, const double b, const double c, bool persist = true)
327  {
328  const double temp[] = {a, b, c};
329  addVec3Option(commandFlag, label, temp, persist);
330  }
331 
337  void addVec4Option(const char* commandFlag, const char* label, const double defaultVal[4], bool persist = true);
338 
347  void addVec4Option(const char* commandFlag, const char* label, const double a, const double b, const double c, const double d, bool persist = true)
348  {
349  const double temp[] = {a, b, c, d};
350  addVec4Option(commandFlag, label, temp, persist);
351  }
352 
358  void addColourOption(const char* commandFlag, const char* label, const double defaultVal[3], bool persist = true);
359 
367  void addColourOption(const char* commandFlag, const char* label, const double a, const double b, const double c, bool persist = true)
368  {
369  const double temp[] = {a, b, c};
370  addColourOption(commandFlag, label, temp, persist);
371  }
372 
379  void addStringOption(const char* commandFlag, const char* label, MString defaultVal, bool persist = true, StringPolicy policy = kStringOptional);
380 
387  void addFilePathOption(const char* commandFlag, const char* label, FileMode fileMode, const char* filter = "All files (*) (*)", StringPolicy policy = kStringOptional);
388 
389 private:
390  std::ostringstream m_global;
391  std::ostringstream m_init;
392  std::ostringstream m_save;
393  std::ostringstream m_load;
394  std::ostringstream m_reset;
395  std::ostringstream m_execute;
396  std::ostringstream m_labels;
397  std::ostringstream m_controls;
398  std::string m_commandName;
399  bool m_hasFilePath;
400  bool m_checkBoxCommand;
401 };
402 
403 //----------------------------------------------------------------------------------------------------------------------
404 } // usdmaya
405 } // al
406 //----------------------------------------------------------------------------------------------------------------------
void addInt2Option(const char *commandFlag, const char *label, const int32_t a, const int32_t b, bool persist=true)
add a 2D integer option value to the GUI
Definition: CommandGuiHelper.h:162
void addInt2Option(const char *commandFlag, const char *label, const int32_t defaultVal[2], bool persist=true)
add a 2D integer option value to the GUI
void addListOption(const char *commandFlag, const char *label, GenerateListFn generateList)
adds a dynamic drop down list of items that will be displayed within an optionMenu control...
A method used by the generated command GUI code to retrieve a list of items from C++.
Definition: CommandGuiHelper.h:21
void addVec2Option(const char *commandFlag, const char *label, const double a, const double b, bool persist=true)
add a 2D vector option value to the GUI
Definition: CommandGuiHelper.h:306
a directory dialog, but displays files.
Definition: CommandGuiHelper.h:87
void addColourOption(const char *commandFlag, const char *label, const double defaultVal[3], bool persist=true)
add a colour option value to the GUI
void addColourOption(const char *commandFlag, const char *label, const double a, const double b, const double c, bool persist=true)
add a colour option value to the GUI
Definition: CommandGuiHelper.h:367
a directory dialog
Definition: CommandGuiHelper.h:88
void addVec2Option(const char *commandFlag, const char *label, const double defaultVal[2], bool persist=true)
add a 2D vector option value to the GUI
void addVec3Option(const char *commandFlag, const char *label, const double defaultVal[3], bool persist=true)
add a 3D vector option value to the GUI
void addInt4Option(const char *commandFlag, const char *label, const int32_t a, const int32_t b, const int32_t c, const int32_t d, bool persist=true)
add a 4D integer option value to the GUI
Definition: CommandGuiHelper.h:203
void addRadioButtonGroupOption(const char *commandFlag, const char *label, int defaultIndex, const char *const enumNames[], const int32_t enumValues[], bool persist=true, bool passAsString=false)
Similar to the enum option, but this time with radio buttons. THE MAXIMUM NUMBER OF OPTIONS IS 4...
void addBoolOption(const char *commandFlag, const char *label, bool defaultVal, bool persist=true)
add a boolean option value to the GUI
This class isn't really a wrapper around command options as such, it's mainly just a helper to auto g...
Definition: CommandGuiHelper.h:78
void addIntOption(const char *commandFlag, const char *label, int32_t defaultVal, bool persist=true)
add an integer option value to the GUI
a save file dialog
Definition: CommandGuiHelper.h:85
static int32_t registerListFunc(GenerateListFn generateListFunc, const MString &menuName)
Internal method. Registers a custom list function with this command so that MEL can request a custom ...
void addDoubleOption(const char *commandFlag, const char *label, double defaultVal, bool persist=true)
add a double precision option value to the GUI
void addVec3Option(const char *commandFlag, const char *label, const double a, const double b, const double c, bool persist=true)
add a 3D vector option value to the GUI
Definition: CommandGuiHelper.h:326
StringPolicy
determines if a text string argument is optional (e.g. a name of the object if specified, but falls back to a default if not), or whether it must exist (e.g. for a file to open)
Definition: CommandGuiHelper.h:94
void addInt4Option(const char *commandFlag, const char *label, const int32_t defaultVal[4], bool persist=true)
add a 4D integer option value to the GUI
if the string is empty, it is an error.
Definition: CommandGuiHelper.h:97
void addFlagOption(const char *commandFlag, const char *label, bool defaultVal, bool persist=true)
add a boolean option value to the GUI
~CommandGuiHelper()
dtor - auto generates, and executes the GUI code.
a load file dialog
Definition: CommandGuiHelper.h:86
void addVec4Option(const char *commandFlag, const char *label, const double defaultVal[4], bool persist=true)
add a 4D vector option value to the GUI
void addIntSliderOption(const char *commandFlag, const char *label, int32_t minVal, int32_t maxVal, int32_t defaultVal, bool persist=true)
add an integer option value to the GUI (with min/max, displayed as a slider)
FileMode
Used to describe the type of file dialog that should be used for a file path attribute.
Definition: CommandGuiHelper.h:83
void addStringOption(const char *commandFlag, const char *label, MString defaultVal, bool persist=true, StringPolicy policy=kStringOptional)
add a string option value to the GUI
multiple input files
Definition: CommandGuiHelper.h:89
void addVec4Option(const char *commandFlag, const char *label, const double a, const double b, const double c, const double d, bool persist=true)
add a 4D vector option value to the GUI
Definition: CommandGuiHelper.h:347
void addDoubleSliderOption(const char *commandFlag, const char *label, double minVal, double maxVal, double defaultVal, bool persist=true)
add a double precision option value to the GUI (with min/max, displayed as a slider) ...
CommandGuiHelper(const char *commandName, const char *windowTitle, const char *doitLabel, const char *menuItemPath, bool hasOptionBox=true)
ctor
void addEnumOption(const char *commandFlag, const char *label, int defaultIndex, const char *const enumNames[], const int32_t enumValues[], bool persist=true, bool passAsString=false)
add an enum option value to the GUI
void addInt3Option(const char *commandFlag, const char *label, const int32_t defaultVal[3], bool persist=true)
add a 3D integer option value to the GUI
if the string value is empty, the flag will be omitted.
Definition: CommandGuiHelper.h:96
void addInt3Option(const char *commandFlag, const char *label, const int32_t a, const int32_t b, const int32_t c, bool persist=true)
add a 3D integer option value to the GUI
Definition: CommandGuiHelper.h:182
void addFilePathOption(const char *commandFlag, const char *label, FileMode fileMode, const char *filter="All files (*) (*)", StringPolicy policy=kStringOptional)
add a file path option value to the GUI