~ubuntu-branches/ubuntu/wily/opencollada/wily-proposed

« back to all changes in this revision

Viewing changes to Externals/MayaDataModel/include/MayaDMCommands.h

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2015-05-14 17:23:27 UTC
  • Revision ID: package-import@ubuntu.com-20150514172327-f862u8envms01fra
Tags: upstream-0.1.0~20140703.ddf8f47+dfsg1
ImportĀ upstreamĀ versionĀ 0.1.0~20140703.ddf8f47+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2008-2009 NetAllied Systems GmbH
 
3
 
 
4
    This file is part of MayaDataModel.
 
5
 
 
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
 
9
*/
 
10
#ifndef __MayaDM_COMMANDS_H__
 
11
#define __MayaDM_COMMANDS_H__
 
12
 
 
13
namespace MayaDM
 
14
{
 
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.
 
20
        */
 
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, 
 
24
                bool world = false ) 
 
25
        {
 
26
                fprintf ( file, "parent" );
 
27
 
 
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" );
 
35
 
 
36
                fprintf ( file, " \"%s\"", childName.c_str () );
 
37
                if ( strcmp ( parentName.c_str (), "" ) != 0 )
 
38
                {
 
39
                        fprintf ( file, " \"%s\"", parentName.c_str () );
 
40
                }
 
41
                fprintf ( file, ";\n" );
 
42
        }
 
43
        
 
44
        /** This command parents (moves) shapes under a new group, removes
 
45
        shapes from an existing group, or adds/removes parents.
 
46
        */
 
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 ) 
 
50
        {
 
51
                parent(file, childName, parentName, absolute, addObject, noConnections, relative, removeObject, true, world);
 
52
        }
 
53
 
 
54
    /**
 
55
     * Class to help handling the flags of an Attribute.
 
56
     */
 
57
    class AttributeFlag
 
58
    {
 
59
    private:
 
60
        std::string mFlagName;
 
61
        std::string mFlagValue;
 
62
        bool mQuotations;
 
63
 
 
64
    public:
 
65
        AttributeFlag ( 
 
66
            const std::string& flagName, 
 
67
            const std::string& flagValue, 
 
68
            const bool quotations = true )
 
69
            : mFlagName ( flagName )
 
70
            , mFlagValue ( flagValue )
 
71
            , mQuotations ( quotations )
 
72
        {}
 
73
        virtual ~AttributeFlag () {}
 
74
 
 
75
        const std::string& getFlagName () const { return mFlagName; }
 
76
        const std::string& getFlagValue () const { return mFlagValue; }
 
77
        const bool& getQuotations () const { return mQuotations; }
 
78
    };
 
79
 
 
80
    /**
 
81
    * Method to add an attribute to a maya node.
 
82
    */
 
83
    static void addAttr ( 
 
84
        FILE* file, 
 
85
        const std::string& nodeName, 
 
86
        const std::string& attributeName, 
 
87
        const std::string& flagName,
 
88
        const std::string& flagValue )
 
89
    {
 
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" );
 
94
    }
 
95
 
 
96
    /**
 
97
     * Method to add an attribute to a maya node.
 
98
     */
 
99
    static bool addAttr ( 
 
100
        FILE* file, 
 
101
        const std::string& nodeName, 
 
102
        const std::string& attributeName, 
 
103
        const AttributeFlag& attributeFlag )
 
104
    {
 
105
        if ( !file ) 
 
106
        {
 
107
            std::cerr << "addAttr: file not valid! Can't add Attribute!" << std::endl;
 
108
            return false;
 
109
        }
 
110
        fprintf ( file, "addAttr -ln \"%s\"", attributeName.c_str() );
 
111
 
 
112
        if ( attributeFlag.getQuotations () )
 
113
            fprintf ( file, " -%s \"%s\"", attributeFlag.getFlagName ().c_str (), attributeFlag.getFlagValue ().c_str () );
 
114
        else
 
115
            fprintf ( file, " -%s %s", attributeFlag.getFlagName ().c_str (), attributeFlag.getFlagValue ().c_str () );
 
116
 
 
117
        fprintf ( file, " %s", nodeName.c_str() );
 
118
        fprintf ( file, ";\n" );
 
119
 
 
120
        return true;
 
121
    }
 
122
 
 
123
    /**
 
124
    * Method to add an attribute with one flag to the currently selected maya node.
 
125
    */
 
126
    static bool addAttr ( 
 
127
        FILE* file, 
 
128
        const std::string& attributeName, 
 
129
        const std::string& flagName,
 
130
        const std::string& flagValue )
 
131
    {
 
132
        if ( !file ) 
 
133
        {
 
134
            std::cerr << "addAttr: file not valid! Can't add Attribute!" << std::endl;
 
135
            return false;
 
136
        }
 
137
        fprintf ( file, "\taddAttr -ln \"%s\"", attributeName.c_str() );
 
138
        fprintf ( file, " -%s \"%s\"", flagName.c_str (), flagValue.c_str () );
 
139
        fprintf ( file, ";\n" );
 
140
 
 
141
        return true;
 
142
    }
 
143
 
 
144
    /**
 
145
    * Method to add an attribute to the currently selected maya node.
 
146
    */
 
147
    static bool addAttr ( 
 
148
        FILE* file, 
 
149
        const std::string& attributeName, 
 
150
        const AttributeFlag& attributeFlag )
 
151
    {
 
152
        if ( !file ) 
 
153
        {
 
154
            std::cerr << "addAttr: file not valid! Can't add Attribute!" << std::endl;
 
155
            return false;
 
156
        }
 
157
        fprintf ( file, "\taddAttr -ln \"%s\"", attributeName.c_str() );
 
158
 
 
159
        if ( attributeFlag.getQuotations () )
 
160
            fprintf ( file, " -%s \"%s\"", attributeFlag.getFlagName ().c_str (), attributeFlag.getFlagValue ().c_str () );
 
161
        else
 
162
            fprintf ( file, " -%s %s", attributeFlag.getFlagName ().c_str (), attributeFlag.getFlagValue ().c_str () );
 
163
 
 
164
        fprintf ( file, ";\n" );
 
165
 
 
166
        return true;
 
167
    }
 
168
 
 
169
    /**
 
170
    * Method to add an attribute with multiple flags to the currently selected maya node.
 
171
    */
 
172
    static bool addAttr ( 
 
173
        FILE* file, 
 
174
        const std::string& attributeName, 
 
175
        const std::vector<AttributeFlag>& attributeFlags )
 
176
    {
 
177
        if ( !file ) 
 
178
        {
 
179
            std::cerr << "addAttr: file not valid! Can't add Attribute!" << std::endl;
 
180
            return false;
 
181
        }
 
182
        fprintf ( file, "\taddAttr -ln \"%s\"", attributeName.c_str() );
 
183
        for ( size_t i=0; i<attributeFlags.size (); ++i )
 
184
        {
 
185
            if ( attributeFlags[i].getQuotations () == false )
 
186
                fprintf ( file, " -%s %s", attributeFlags[i].getFlagName ().c_str (), attributeFlags[i].getFlagValue ().c_str () );
 
187
            else
 
188
                fprintf ( file, " -%s \"%s\"", attributeFlags[i].getFlagName ().c_str (), attributeFlags[i].getFlagValue ().c_str () );
 
189
        }
 
190
        fprintf ( file, ";\n" );
 
191
 
 
192
        return true;
 
193
    }
 
194
 
 
195
    /**
 
196
    * Method to set an attribute's value of an maya node.
 
197
    */
 
198
    static void setAttr ( 
 
199
        FILE* file, 
 
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 )
 
205
    {
 
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" );
 
211
    }
 
212
 
 
213
    /**
 
214
    * Method to set an attribute's value of the currently selected maya node.
 
215
    */
 
216
    static void setAttr ( 
 
217
        FILE* file, 
 
218
        const std::string& attributeName, 
 
219
        const std::string& flagName,
 
220
        const std::string& flagValue, 
 
221
        const std::string& attributeValue )
 
222
    {
 
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" );
 
228
    }
 
229
 
 
230
    /**
 
231
    * Method to set an attribute's value of the currently selected maya node.
 
232
    */
 
233
    static void setAttr ( 
 
234
        FILE* file, 
 
235
        const std::string& attributeName, 
 
236
        const std::vector<AttributeFlag>& attributeFlags, 
 
237
        const std::string& attributeValue )
 
238
    {
 
239
        fprintf ( file, "\tsetAttr .%s", attributeName.c_str() );
 
240
        for ( size_t i=0; i<attributeFlags.size (); ++i )
 
241
        {
 
242
            if ( attributeFlags[i].getQuotations () == false )
 
243
                fprintf ( file, " -%s %s", attributeFlags[i].getFlagName ().c_str (), attributeFlags[i].getFlagValue ().c_str () );
 
244
            else
 
245
                fprintf ( file, " -%s \"%s\"", attributeFlags[i].getFlagName ().c_str (), attributeFlags[i].getFlagValue ().c_str () );
 
246
        }
 
247
        if ( strcmp ( attributeValue.c_str(), "" ) != 0 )
 
248
            fprintf ( file, " \"%s\"", attributeValue.c_str() );
 
249
        fprintf ( file, ";\n" );
 
250
    }
 
251
 
 
252
    static void setAttr ( 
 
253
        FILE* file, 
 
254
        const std::string& attributeName, 
 
255
        const std::string& flagName,
 
256
        const bool flagValue, 
 
257
        const std::string& attributeValue )
 
258
    {
 
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" );
 
264
    }
 
265
 
 
266
    static void startSetAttr ( FILE* file, std::string attributeName, std::string nodeName )
 
267
    {
 
268
        if ( strcmp ( nodeName.c_str(), "" ) == 0 )
 
269
            fprintf ( file, "\tsetAttr .%s", attributeName.c_str() );
 
270
        else
 
271
            fprintf ( file, "setAttr %s.%s", nodeName.c_str(), attributeName.c_str() );
 
272
    }
 
273
    static void endSetAttr ( FILE* file )
 
274
    {
 
275
        fprintf ( file, ";\n" );
 
276
    }
 
277
 
 
278
    /**
 
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;". 
 
298
     * @param FILE* file
 
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. 
 
303
     * @return const
 
304
     */
 
305
    #define mayaSelect(file, objName, noExpand) \
 
306
    {                                           \
 
307
        fprintf(file, "select ");               \
 
308
        if ( noExpand )                         \
 
309
            fprintf(file, "-noExpand ");        \
 
310
        fprintf(file, "%s", objName.c_str());   \
 
311
        fprintf(file, ";\n");                   \
 
312
    }
 
313
 
 
314
    /**
 
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.
 
319
    */
 
320
    static void editCameraAspectRatio(FILE* file, const std::string& name, const double aspectRatio)
 
321
    {                                           
 
322
        fprintf(file,"camera -e");
 
323
        fprintf(file, " -ar %f", aspectRatio);
 
324
        fprintf(file, " %s", name.c_str());
 
325
        fprintf(file, ";\n");
 
326
    }
 
327
 
 
328
    /**
 
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.
 
333
    */
 
334
    static void editCameraHorizontalFieldOfView(FILE* file, const std::string& name, 
 
335
        const double horizontalFieldOfView)
 
336
    {                                           
 
337
        fprintf(file,"camera -e");
 
338
        fprintf(file, " -hfv %f", horizontalFieldOfView);
 
339
        fprintf(file, " %s", name.c_str());
 
340
        fprintf(file, ";\n");
 
341
    }
 
342
 
 
343
    /**
 
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.
 
348
    */
 
349
    static void editCameraVerticalFieldOfView(FILE* file, const std::string& name, 
 
350
        const double verticalFieldOfView)
 
351
    {                                           
 
352
        fprintf(file,"camera -e");
 
353
        fprintf(file, " -vfv %f", verticalFieldOfView);
 
354
        fprintf(file, " %s", name.c_str());
 
355
        fprintf(file, ";\n");
 
356
    }
 
357
 
 
358
    /**
 
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.
 
363
    */
 
364
    static void editCameraOrthographicWidth(FILE* file, const std::string& name, 
 
365
        const double orthographicWidth)
 
366
    {                                           
 
367
        fprintf(file,"camera -e");
 
368
        fprintf(file, " -ow %f", orthographicWidth);
 
369
        fprintf(file, " %s", name.c_str());
 
370
        fprintf(file, ";\n");
 
371
    }
 
372
 
 
373
}
 
374
 
 
375
#endif //__MayaDM_COMMANDS_H__