1 /*
2     Copyright (c) 2008-2009 NetAllied Systems GmbH
3 
4 	This file is part of COLLADAMaya.
5 
6     Portions of the code are:
7     Copyright (c) 2005-2007 Feeling Software Inc.
8     Copyright (c) 2005-2007 Sony Computer Entertainment America
9     Copyright (c) 2004-2005 Alias Systems Corp.
10 
11     Licensed under the MIT Open Source License,
12     for details please see LICENSE file or the website
13     http://www.opensource.org/licenses/mit-license.php
14 */
15 
16 #ifndef __COLLADA_MAYA_ATTRIBUTE_PARSER_H__
17 #define __COLLADA_MAYA_ATTRIBUTE_PARSER_H__
18 
19 #include "COLLADAMayaPrerequisites.h"
20 #include "COLLADAMayaPlatform.h"
21 
22 #include <maya/MFnDependencyNode.h>
23 #include <maya/MFnNumericData.h>
24 
25 namespace COLLADAMaya
26 {
27 
28 	/**
29 	 * Helper class used to parse a node's attributes.
30 	 */
31     class AttributeParser
32     {
33 	public:
34 
35 		/**
36 		 * Parse attributes of fnNode and call corresponding callbacks of AttributeParser object.
37 		 * @param fnNode Parsed node
38 		 * @param parser Object inheriting AttributeParser class and implementing some of the onXXX() methods.
39 		 */
40 		static void parseAttributes(MFnDependencyNode & fnNode, AttributeParser & parser);
41 
42 	protected:
43 		/**
44 		 * Callback called before parsing a plug.
45 		 * @param plug Parsed plug.
46 		 * @return false to skip plug. true to continue attribute parsing.
47 		 */
onBeforePlug(MPlug & plug)48 		virtual bool onBeforePlug(MPlug & plug) { return true; }
49 
50 		/**
51 		 * Callback called after parsing a plug.
52 		 * @param plug Parsed plug.
53 		 */
onAfterPlug(MPlug & plug)54 		virtual void onAfterPlug(MPlug & plug) { }
55 
56 		/**
57 		 * Callbacks called when parsing a plug of given type.
58 		 * @param plug Node plug associated to current attribute.
59 		 * @param name Current attribute name.
60 		 * @param value Current plug value.
61 		 */
onBoolean(MPlug & plug,const MString & name,bool value)62 		virtual void onBoolean			    (MPlug & plug, const MString & name, bool value)			                    { }
onByte(MPlug & plug,const MString & name,char value)63 		virtual void onByte				    (MPlug & plug, const MString & name, char value)			                    { }
onChar(MPlug & plug,const MString & name,char value)64 		virtual void onChar				    (MPlug & plug, const MString & name, char value)			                    { }
onShort(MPlug & plug,const MString & name,short value)65 		virtual void onShort			    (MPlug & plug, const MString & name, short value)			                    { }
onShort2(MPlug & plug,const MString & name,short value[2])66 		virtual void onShort2			    (MPlug & plug, const MString & name, short value[2])		                    { }
onShort3(MPlug & plug,const MString & name,short value[3])67 		virtual void onShort3			    (MPlug & plug, const MString & name, short value[3])		                    { }
onInteger(MPlug & plug,const MString & name,int value)68 		virtual void onInteger				(MPlug & plug, const MString & name, int value)				                    { }
onInteger2(MPlug & plug,const MString & name,int value[2])69 		virtual void onInteger2				(MPlug & plug, const MString & name, int value[2])			                    { }
onInteger3(MPlug & plug,const MString & name,int value[3])70 		virtual void onInteger3				(MPlug & plug, const MString & name, int value[3])			                    { }
onFloat(MPlug & plug,const MString & name,float value)71 		virtual void onFloat				(MPlug & plug, const MString & name, float value)			                    { }
onFloat2(MPlug & plug,const MString & name,float value[2])72 		virtual void onFloat2			    (MPlug & plug, const MString & name, float value[2])		                    { }
onFloat3(MPlug & plug,const MString & name,float value[3])73 		virtual void onFloat3			    (MPlug & plug, const MString & name, float value[3])		                    { }
onDouble(MPlug & plug,const MString & name,double value)74 		virtual void onDouble			    (MPlug & plug, const MString & name, double value)			                    { }
onDouble2(MPlug & plug,const MString & name,double value[2])75 		virtual void onDouble2			    (MPlug & plug, const MString & name, double value[2])		                    { }
onDouble3(MPlug & plug,const MString & name,double value[3])76 		virtual void onDouble3			    (MPlug & plug, const MString & name, double value[3])		                    { }
onDouble4(MPlug & plug,const MString & name,double value[4])77 		virtual void onDouble4			    (MPlug & plug, const MString & name, double value[4])		                    { }
onString(MPlug & plug,const MString & name,const MString & value)78 		virtual void onString			    (MPlug & plug, const MString & name, const MString & value)	                    { }
onEnum(MPlug & plug,const MString & name,int enumValue,const MString & enumName)79         virtual void onEnum                 (MPlug & plug, const MString & name, int enumValue, const MString & enumName)   { }
onMesh(MPlug & plug,const MString & name,MObject & meshObject)80         virtual void onMesh                 (MPlug & plug, const MString & name, MObject & meshObject)                      { }
onConnection(MPlug & plug,const MString & name,MPlug & externalPlug)81         virtual void onConnection           (MPlug & plug, const MString & name, MPlug & externalPlug)                      { }
onCompoundAttribute(MPlug & plug,const MString & name)82         virtual void onCompoundAttribute    (MPlug & plug, const MString & name)                                            { }
onAngle(MPlug & plug,const MString & name,const MAngle & angle)83         virtual void onAngle                (MPlug & plug, const MString & name, const MAngle & angle)                      { }
onAngle2(MPlug & plug,const MString & name,const MAngle angles[2])84         virtual void onAngle2               (MPlug & plug, const MString & name, const MAngle angles[2])                    { }
onAngle3(MPlug & plug,const MString & name,const MAngle angles[3])85         virtual void onAngle3               (MPlug & plug, const MString & name, const MAngle angles[3])                    { }
onAngle4(MPlug & plug,const MString & name,const MAngle angles[4])86         virtual void onAngle4               (MPlug & plug, const MString & name, const MAngle angles[4])                    { }
onDistance(MPlug & plug,const MString & name,const MDistance & distance)87         virtual void onDistance             (MPlug & plug, const MString & name, const MDistance & distance)                { }
onDistance2(MPlug & plug,const MString & name,const MDistance distances[2])88         virtual void onDistance2            (MPlug & plug, const MString & name, const MDistance distances[2])              { }
onDistance3(MPlug & plug,const MString & name,const MDistance distances[3])89         virtual void onDistance3            (MPlug & plug, const MString & name, const MDistance distances[3])              { }
onDistance4(MPlug & plug,const MString & name,const MDistance distances[4])90         virtual void onDistance4            (MPlug & plug, const MString & name, const MDistance distances[4])              { }
onTime(MPlug & plug,const MString & name,MTime & time)91         virtual void onTime                 (MPlug & plug, const MString & name, MTime & time)                              { }
onMessage(MPlug & plug,const MString & name)92         virtual void onMessage              (MPlug & plug, const MString & name)                                            { }
onMatrix(MPlug & plug,const MString & name,const MMatrix & value)93         virtual void onMatrix               (MPlug & plug, const MString & name, const MMatrix& value)                      { }
94 
95 	private:
96 		void parsePlug				(MPlug & plug);
97 		void parseNumericPlug		(MPlug & plug);
98 		void parseTypedPlug			(MPlug & plug);
99 		void parseEnumPlug			(MPlug & plug);
100 		void parseMessagePlug		(MPlug & plug);
101 		void parseMatrixPlug		(MPlug & plug);
102 		void parseCompoundPlug		(MPlug & plug);
103 		void parseUnitPlug			(MPlug & plug);
104 		void parseGenericPlug		(MPlug & plug);
105 		void parseLightDataPlug		(MPlug & plug);
106 		void parseNumericData		(MPlug & plug);
107 		void parseNumeric			(MPlug plug, MFnNumericData::Type type);
108 		void parseStringData		(MPlug & plug);
109 		void parseMeshData			(MPlug & plug);
110 		void parseComponentListData	(MPlug & plug);
111 
112 		static bool IsNumericCompoundAttribute(const MObject& attribute, MFnNumericData::Type& type);
113 
114 		friend class AutoOnAfterPlug;
115     };
116 }
117 
118 #endif // __COLLADA_MAYA_ATTRIBUTE_PARSER_H__
119