AL_USDMaya  0.16.6
USD to Maya Bridge
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
FileTranslatorOptions.h
1 #pragma once
2 #include "AL/maya/Common.h"
3 
4 #include "maya/MString.h"
5 
6 #include <map>
7 #include <vector>
8 #include <string>
9 
10 namespace AL {
11 namespace maya {
12 
13 //----------------------------------------------------------------------------------------------------------------------
16 //----------------------------------------------------------------------------------------------------------------------
18 {
19  friend class FileTranslatorOptions;
20 public:
21 
23  OptionsParser();
24 
27 
32  MStatus parse(const MString& optionString);
33 
37  bool getBool(const char* const str) const
38  {
39  auto it = m_niceNameToValue.find(str);
40  if(it != m_niceNameToValue.end())
41  {
42  return it->second->m_bool;
43  }
44  return false;
45  }
46 
50  int getInt(const char* const str) const
51  {
52  auto it = m_niceNameToValue.find(str);
53  if(it != m_niceNameToValue.end())
54  {
55  return it->second->m_int;
56  }
57  return 0;
58  }
59 
63  float getFloat(const char* const str) const
64  {
65  auto it = m_niceNameToValue.find(str);
66  if(it != m_niceNameToValue.end())
67  {
68  return it->second->m_float;
69  }
70  return 0.0f;
71  }
72 
76  MString getString(const char* const str) const
77  {
78  auto it = m_niceNameToValue.find(str);
79  if(it != m_niceNameToValue.end())
80  {
81  return it->second->m_string.c_str();
82  }
83  return kNullString;
84  }
85 
86 private:
87 #ifndef AL_GENERATING_DOCS
88  enum OptionType
89  {
90  kBool,
91  kInt,
92  kFloat,
93  kString
94  };
95 
96  static const MString kNullString;
97  struct OptionValue
98  {
99  void init()
100  {
101  switch(m_type)
102  {
103  case kBool: m_bool = m_defaultBool; break;
104  case kInt: m_int = m_defaultInt; break;
105  case kFloat: m_float = m_defaultFloat; break;
106  case kString: m_string = m_defaultString; break;
107  default: break;
108  }
109  }
110 
111  void parse(MString& str)
112  {
113  switch(m_type)
114  {
115  case kBool: m_bool = str.asInt() ? true : false; break;
116  case kInt: m_int = str.asInt(); break;
117  case kFloat: m_float = str.asFloat(); break;
118  case kString: m_string = str.asChar(); break;
119  default: break;
120  }
121  }
122 
123  OptionType m_type;
124  union
125  {
126  bool m_defaultBool;
127  int m_defaultInt;
128  float m_defaultFloat;
129  };
130  std::string m_defaultString;
131  union
132  {
133  bool m_bool;
134  int m_int;
135  float m_float;
136  };
137  std::string m_string;
138  };
139  std::map<std::string, OptionValue*> m_optionNameToValue;
140  std::map<std::string, OptionValue*> m_niceNameToValue;
141 #endif
142 };
143 
144 
145 //----------------------------------------------------------------------------------------------------------------------
147 //----------------------------------------------------------------------------------------------------------------------
149 {
150 public:
151 
154  FileTranslatorOptions(const char* fileTranslatorName);
155 
159 
163  bool addFrame(const char* frameName);
164 
168 
173  bool addBool(const char* optionName, bool defaultValue = false);
174 
179  bool addInt(const char* optionName, int defaultValue = 0);
180 
185  bool addFloat(const char* optionName, float defaultValue = 0.0f);
186 
191  bool addString(const char* optionName, const char* const defaultValue = "");
192 
202  bool boolControlsVisibility(const char* controller, const char* controlled, bool invertBehaviour = false);
203 
207 
215  MStatus generateScript(OptionsParser& optionParser, MString& defaultOptionString);
216 
217 protected:
218 #ifndef AL_GENERATING_DOCS
219  bool hasOption(const char* const optionName) const;
220  bool hasOption(const MString& optionName) const { return hasOption(optionName.asChar()); }
221  void generateBoolGlobals(const MString& niceName, const MString& optionName, bool defaultValue);
222  void generateIntGlobals(const MString& niceName, const MString& optionName, int defaultValue);
223  void generateFloatGlobals(const MString& niceName, const MString& optionName, float defaultValue);
224  void generateStringGlobals(const MString& niceName, const MString& optionName, MString defaultValue);
225 #endif
226 private:
227 #ifndef AL_GENERATING_DOCS
228  enum OptionType
229  {
230  kBool,
231  kInt,
232  kFloat,
233  kString
234  };
235  struct FrameLayout
236  {
237  FrameLayout(const char* frameName)
238  : m_frameName(frameName), m_options()
239  {}
240  MString m_frameName;
241  struct Option
242  {
243  MString optionName;
244  MString niceName;
245  OptionType type;
246  union
247  {
248  bool defaultBool;
249  int defaultInt;
250  float defaultFloat;
251  const char* defaultString;
252  };
253  };
254  std::vector<Option> m_options;
255  };
256  FrameLayout& lastFrame()
257  {
258  return *(m_frames.end() - 1);
259  }
260  std::vector<FrameLayout> m_frames;
261  std::vector<std::pair<MString, MString> > m_visibility;
262  MString m_translatorName;
263  MString m_code;
264 #endif
265 };
266 
267 //----------------------------------------------------------------------------------------------------------------------
268 } // usdmaya
269 } // AL
270 //----------------------------------------------------------------------------------------------------------------------
Definition: FileTranslatorOptions.h:241
int getInt(const char *const str) const
Given the text name of an option, returns the integer value for that option.
Definition: FileTranslatorOptions.h:50
bool getBool(const char *const str) const
Given the text name of an option, returns the boolean value for that option.
Definition: FileTranslatorOptions.h:37
MString getString(const char *const str) const
Given the text name of an option, returns the string value for that option.
Definition: FileTranslatorOptions.h:76
Utility class that constructs the file translator export GUI from the export options you want to supp...
Definition: FileTranslatorOptions.h:148
bool addBool(const char *optionName, bool defaultValue=false)
Add a boolean value to the translator options.
Utility class that parses the file translator options passed through by Maya.
Definition: FileTranslatorOptions.h:17
float getFloat(const char *const str) const
Given the text name of an option, returns the floating point value for that option.
Definition: FileTranslatorOptions.h:63
bool addString(const char *optionName, const char *const defaultValue="")
Add a string value to the translator options.
bool boolControlsVisibility(const char *controller, const char *controlled, bool invertBehaviour=false)
For a given boolean option (the controller), if enabled the 'controlled' option will be editable...
bool addInt(const char *optionName, int defaultValue=0)
Add an integer value to the translator options.
bool addFrame(const char *frameName)
add a new frame layout under which to group a set of controls. There must be at least 1 frame created...
MStatus generateScript(OptionsParser &optionParser, MString &defaultOptionString)
This method generates the MEL script for the import/export GUI, and evaluates it behind the scenes...
bool addFloat(const char *optionName, float defaultValue=0.0f)
Add a float value to the translator options.
FileTranslatorOptions(const char *fileTranslatorName)
ctor
MStatus parse(const MString &optionString)
Given a string containing a semi-colon separated list of options passed to a file translator plugin...