2
Copyright (c) 2008-2009 NetAllied Systems GmbH
4
This file is part of MayaDataModel.
6
Licensed under the MIT Open Source License,
7
for details please see LICENSE file or the website
8
http://www.opensource.org/licenses/mit-license.php
10
#ifndef __MayaDM_COMMANDS_H__
11
#define __MayaDM_COMMANDS_H__
15
/** This command parents (moves) objects under a new group, removes
16
objects from an existing group, or adds/removes parents. The parent
17
command usually only operates on transforms. Using the shape flag
18
allows a shape that is specified to be directly parented under the
19
given transform. This is used to instance a shape node.
21
static void parent ( FILE* file, const std::string& childName, const std::string& parentName = "",
22
bool absolute = false, bool addObject = false, bool noConnections = false,
23
bool relative = false, bool removeObject = false, bool shape = false,
26
fprintf ( file, "parent" );
28
if ( absolute ) fprintf ( file, " -a" );
29
if ( addObject ) fprintf ( file, " -add" );
30
if ( noConnections ) fprintf ( file, " -nc" );
31
if ( relative ) fprintf ( file, " -r" );
32
if ( removeObject ) fprintf ( file, " -rm" );
33
if ( shape ) fprintf ( file, " -s" );
34
if ( world ) fprintf ( file, " -w" );
36
fprintf ( file, " \"%s\"", childName.c_str () );
37
if ( strcmp ( parentName.c_str (), "" ) != 0 )
39
fprintf ( file, " \"%s\"", parentName.c_str () );
41
fprintf ( file, ";\n" );
44
/** This command parents (moves) shapes under a new group, removes
45
shapes from an existing group, or adds/removes parents.
47
static void parentShape ( FILE* file, const std::string& childName, const std::string& parentName = "",
48
bool absolute = false, bool addObject = false, bool noConnections = false,
49
bool relative = false, bool removeObject = false, bool world = false )
51
parent(file, childName, parentName, absolute, addObject, noConnections, relative, removeObject, true, world);
55
* Class to help handling the flags of an Attribute.
60
std::string mFlagName;
61
std::string mFlagValue;
66
const std::string& flagName,
67
const std::string& flagValue,
68
const bool quotations = true )
69
: mFlagName ( flagName )
70
, mFlagValue ( flagValue )
71
, mQuotations ( quotations )
73
virtual ~AttributeFlag () {}
75
const std::string& getFlagName () const { return mFlagName; }
76
const std::string& getFlagValue () const { return mFlagValue; }
77
const bool& getQuotations () const { return mQuotations; }
81
* Method to add an attribute to a maya node.
85
const std::string& nodeName,
86
const std::string& attributeName,
87
const std::string& flagName,
88
const std::string& flagValue )
90
fprintf ( file, "addAttr -ln \"%s\"", attributeName.c_str() );
91
fprintf ( file, " -%s \"%s\"", flagName.c_str (), flagValue.c_str () );
92
fprintf ( file, " %s", nodeName.c_str() );
93
fprintf ( file, ";\n" );
97
* Method to add an attribute to a maya node.
101
const std::string& nodeName,
102
const std::string& attributeName,
103
const AttributeFlag& attributeFlag )
107
std::cerr << "addAttr: file not valid! Can't add Attribute!" << std::endl;
110
fprintf ( file, "addAttr -ln \"%s\"", attributeName.c_str() );
112
if ( attributeFlag.getQuotations () )
113
fprintf ( file, " -%s \"%s\"", attributeFlag.getFlagName ().c_str (), attributeFlag.getFlagValue ().c_str () );
115
fprintf ( file, " -%s %s", attributeFlag.getFlagName ().c_str (), attributeFlag.getFlagValue ().c_str () );
117
fprintf ( file, " %s", nodeName.c_str() );
118
fprintf ( file, ";\n" );
124
* Method to add an attribute with one flag to the currently selected maya node.
126
static bool addAttr (
128
const std::string& attributeName,
129
const std::string& flagName,
130
const std::string& flagValue )
134
std::cerr << "addAttr: file not valid! Can't add Attribute!" << std::endl;
137
fprintf ( file, "\taddAttr -ln \"%s\"", attributeName.c_str() );
138
fprintf ( file, " -%s \"%s\"", flagName.c_str (), flagValue.c_str () );
139
fprintf ( file, ";\n" );
145
* Method to add an attribute to the currently selected maya node.
147
static bool addAttr (
149
const std::string& attributeName,
150
const AttributeFlag& attributeFlag )
154
std::cerr << "addAttr: file not valid! Can't add Attribute!" << std::endl;
157
fprintf ( file, "\taddAttr -ln \"%s\"", attributeName.c_str() );
159
if ( attributeFlag.getQuotations () )
160
fprintf ( file, " -%s \"%s\"", attributeFlag.getFlagName ().c_str (), attributeFlag.getFlagValue ().c_str () );
162
fprintf ( file, " -%s %s", attributeFlag.getFlagName ().c_str (), attributeFlag.getFlagValue ().c_str () );
164
fprintf ( file, ";\n" );
170
* Method to add an attribute with multiple flags to the currently selected maya node.
172
static bool addAttr (
174
const std::string& attributeName,
175
const std::vector<AttributeFlag>& attributeFlags )
179
std::cerr << "addAttr: file not valid! Can't add Attribute!" << std::endl;
182
fprintf ( file, "\taddAttr -ln \"%s\"", attributeName.c_str() );
183
for ( size_t i=0; i<attributeFlags.size (); ++i )
185
if ( attributeFlags[i].getQuotations () == false )
186
fprintf ( file, " -%s %s", attributeFlags[i].getFlagName ().c_str (), attributeFlags[i].getFlagValue ().c_str () );
188
fprintf ( file, " -%s \"%s\"", attributeFlags[i].getFlagName ().c_str (), attributeFlags[i].getFlagValue ().c_str () );
190
fprintf ( file, ";\n" );
196
* Method to set an attribute's value of an maya node.
198
static void setAttr (
200
const std::string& nodeName,
201
const std::string& attributeName,
202
const std::string& flagName,
203
const std::string& flagValue,
204
const std::string& attributeValue )
206
fprintf ( file, "setAttr %s.%s", nodeName.c_str(), attributeName.c_str() );
207
fprintf ( file, " -%s \"%s\"", flagName.c_str (), flagValue.c_str () );
208
if ( strcmp ( attributeValue.c_str(), "" ) != 0 )
209
fprintf ( file, " \"%s\"", attributeValue.c_str() );
210
fprintf ( file, ";\n" );
214
* Method to set an attribute's value of the currently selected maya node.
216
static void setAttr (
218
const std::string& attributeName,
219
const std::string& flagName,
220
const std::string& flagValue,
221
const std::string& attributeValue )
223
fprintf ( file, "\tsetAttr .%s", attributeName.c_str() );
224
fprintf ( file, " -%s \"%s\"", flagName.c_str (), flagValue.c_str () );
225
if ( strcmp ( attributeValue.c_str(), "" ) != 0 )
226
fprintf ( file, " \"%s\"", attributeValue.c_str() );
227
fprintf ( file, ";\n" );
231
* Method to set an attribute's value of the currently selected maya node.
233
static void setAttr (
235
const std::string& attributeName,
236
const std::vector<AttributeFlag>& attributeFlags,
237
const std::string& attributeValue )
239
fprintf ( file, "\tsetAttr .%s", attributeName.c_str() );
240
for ( size_t i=0; i<attributeFlags.size (); ++i )
242
if ( attributeFlags[i].getQuotations () == false )
243
fprintf ( file, " -%s %s", attributeFlags[i].getFlagName ().c_str (), attributeFlags[i].getFlagValue ().c_str () );
245
fprintf ( file, " -%s \"%s\"", attributeFlags[i].getFlagName ().c_str (), attributeFlags[i].getFlagValue ().c_str () );
247
if ( strcmp ( attributeValue.c_str(), "" ) != 0 )
248
fprintf ( file, " \"%s\"", attributeValue.c_str() );
249
fprintf ( file, ";\n" );
252
static void setAttr (
254
const std::string& attributeName,
255
const std::string& flagName,
256
const bool flagValue,
257
const std::string& attributeValue )
259
fprintf ( file, "\tsetAttr .%s", attributeName.c_str() );
260
fprintf ( file, " -%s %i", flagName.c_str (), flagValue );
261
if ( strcmp ( attributeValue.c_str(), "" ) != 0 )
262
fprintf ( file, " \"%s\"", attributeValue.c_str() );
263
fprintf ( file, ";\n" );
266
static void startSetAttr ( FILE* file, std::string attributeName, std::string nodeName )
268
if ( strcmp ( nodeName.c_str(), "" ) == 0 )
269
fprintf ( file, "\tsetAttr .%s", attributeName.c_str() );
271
fprintf ( file, "setAttr %s.%s", nodeName.c_str(), attributeName.c_str() );
273
static void endSetAttr ( FILE* file )
275
fprintf ( file, ";\n" );
279
* This command is used to put objects onto or off of the active list.
280
* If none of the five flags [-add, -af, -r, -d, -tgl] are specified, the default is to replace
281
* the objects on the active list with the given list of objects. When selecting a set as in
282
* "select set1", the behaviour is for all the members of the set to become selected instead of
283
* the set itself. If you want to select a set, the "-ne/noExpand" flag must be used. With the
284
* advent of namespaces, selection by name may be confusing. To clarify, without a qualified
285
* namespace, name lookup is limited to objects in the root namespace ":".
286
* There are really two parts of a name: the namespace and the name itself which is unique
287
* within the namespace. If you want to select objects in a specific namespace, you need to
288
* include the namespace separator ":". For example, 'select -r "foo*"' is trying to look for
289
* an object with the "foo" prefix in the root namespace. It is not trying to look for all
290
* objects in the namespace with the "foo" prefix. If you want to select all objects in a
291
* namespace (foo), use 'select "foo:*"'.
292
* Note: When the application starts up, there are several dependency nodes created by the
293
* system which must exist. These objects are not deletable but are selectable. All objects
294
* (dag and dependency nodes) in the scene can be obtained using the "ls" command without any
295
* arguments. When using the "-all", "adn/allDependencyNodes" or "-ado/allDagObjects" flags,
296
* only the deletable objects are selected. The non deletable object can still be selected by
297
* explicitly specifying their name as in "select time1;".
299
* @param const std::string& obj
300
* @param bool noExpand Indicates that any set which is among the specified items should not be
301
* expanded to its list of members. This allows sets to be selected as opposed to the
302
* members of sets which is the default behaviour.
305
#define mayaSelect(file, objName, noExpand) \
307
fprintf(file, "select "); \
309
fprintf(file, "-noExpand "); \
310
fprintf(file, "%s", objName.c_str()); \
311
fprintf(file, ";\n"); \
315
* Edit the aspect ratio of the camera element.
316
* @param FILE* file The file to write the edit value.
317
* @param const std::string& name The name of the camera to edit.
318
* @param const double aspectRatio The value to set.
320
static void editCameraAspectRatio(FILE* file, const std::string& name, const double aspectRatio)
322
fprintf(file,"camera -e");
323
fprintf(file, " -ar %f", aspectRatio);
324
fprintf(file, " %s", name.c_str());
325
fprintf(file, ";\n");
329
* Edit the horizontalFieldOfView of the camera element.
330
* @param FILE* file The file to write the edit value.
331
* @param const std::string& name The name of the camera to edit.
332
* @param const double horizontalFieldOfView The value to set.
334
static void editCameraHorizontalFieldOfView(FILE* file, const std::string& name,
335
const double horizontalFieldOfView)
337
fprintf(file,"camera -e");
338
fprintf(file, " -hfv %f", horizontalFieldOfView);
339
fprintf(file, " %s", name.c_str());
340
fprintf(file, ";\n");
344
* Edit the verticalFieldOfView of the camera element.
345
* @param FILE* file The file to write the edit value.
346
* @param const std::string& name The name of the camera to edit.
347
* @param const double verticalFieldOfView The value to set.
349
static void editCameraVerticalFieldOfView(FILE* file, const std::string& name,
350
const double verticalFieldOfView)
352
fprintf(file,"camera -e");
353
fprintf(file, " -vfv %f", verticalFieldOfView);
354
fprintf(file, " %s", name.c_str());
355
fprintf(file, ";\n");
359
* Edit the orthographicWidth of the camera element.
360
* @param FILE* file The file to write the edit value.
361
* @param const std::string& name The name of the camera to edit.
362
* @param const double orthographicWidth The value to set.
364
static void editCameraOrthographicWidth(FILE* file, const std::string& name,
365
const double orthographicWidth)
367
fprintf(file,"camera -e");
368
fprintf(file, " -ow %f", orthographicWidth);
369
fprintf(file, " %s", name.c_str());
370
fprintf(file, ";\n");
375
#endif //__MayaDM_COMMANDS_H__