1 /*
2     Copyright (c) 2008-2009 NetAllied Systems GmbH
3 
4     This file is part of COLLADASaxFrameworkLoader.
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 
11 #ifndef __COLLADASAXFWL_KINEMATICSINTERMEDIATEDATA_H__
12 #define __COLLADASAXFWL_KINEMATICSINTERMEDIATEDATA_H__
13 
14 #include "COLLADASaxFWLPrerequisites.h"
15 #include "COLLADASaxFWLUtils.h"
16 #include "COLLADASaxFWLSidAddress.h"
17 #include "COLLADASaxFWLIntermediateTargetable.h"
18 
19 #include "COLLADAFWTransformation.h"
20 
21 #include "COLLADABUHashFunctions.h"
22 #include "COLLADABUURI.h"
23 #include "COLLADABUhash_map.h"
24 
25 #include <list>
26 
27 
28 namespace COLLADAFW
29 {
30 	class Joint;
31 }
32 
33 
34 namespace COLLADASaxFWL
35 {
36 	class SidTreeNode;
37 
38 	typedef std::vector<COLLADAFW::Transformation*> TransformationList;
39 
40 	/** An instance within kinematics.*/
41 	class KinematicInstance : public IntermediateTargetableTemplate<INTERMEDIATETARGETABLE_TYPE::KINEMATICS_INSTANCE>
42 	{
43 	private:
44 		/** The URI of the referenced element in the COLLADA file.*/
45 		COLLADABU::URI mUrl;
46 
47 		/** The unique id of the frame work object, that will replace the instance in the kinematics model.*/
48 		COLLADAFW::UniqueId mReplacingObjectUniqueId;
49 
50 	public:
KinematicInstance(COLLADABU::URI url)51 		KinematicInstance(COLLADABU::URI url) : mUrl(url){}
52 
KinematicInstance(COLLADABU::URI url,COLLADAFW::UniqueId replacingObjectUniqueId)53 		KinematicInstance(COLLADABU::URI url, COLLADAFW::UniqueId replacingObjectUniqueId) : mUrl(url), mReplacingObjectUniqueId(replacingObjectUniqueId){}
54 
getUrl()55 		const COLLADABU::URI& getUrl() const { return mUrl; }
56 
57 		/** The unique id of the frame work object, that will replace the instance in the kinematics model.*/
getReplacingObjectUniqueId()58 		const COLLADAFW::UniqueId& getReplacingObjectUniqueId() const { return mReplacingObjectUniqueId; }
59 
60 		/** The unique id of the frame work object, that will replace the instance in the kinematics model.*/
setReplacingObjectUniqueId(COLLADAFW::UniqueId replacingObjectUniqueId)61 		void setReplacingObjectUniqueId(COLLADAFW::UniqueId replacingObjectUniqueId) { mReplacingObjectUniqueId = replacingObjectUniqueId; }
62 	};
63 
64 
65 	class  KinematicAttachment;
66 
67 	typedef std::vector<KinematicAttachment*> KinematicAttachmentList;
68 
69 	/** A link within a kinematics model.*/
70 	class KinematicLink : public IntermediateTargetableTemplate<INTERMEDIATETARGETABLE_TYPE::KINEMATICLINK>
71 	{
72 	private:
73 		KinematicAttachmentList mAttachments;
74 		TransformationList mTransformations;
75 	public:
~KinematicLink()76 		~KinematicLink(){ deleteVector(mAttachments); deleteVector(mTransformations); }
77 
78 		/** Adds an attachment to the link. The link will be deleted on destruction.*/
addAttachment(KinematicAttachment * attachement)79 		void addAttachment( KinematicAttachment* attachement ) { mAttachments.push_back(attachement); }
80 
81 		/** Adds a transformation to the link. The transformation will be deleted on destruction.*/
addTransformation(COLLADAFW::Transformation * transformation)82 		void addTransformation( COLLADAFW::Transformation* transformation ) { mTransformations.push_back(transformation); }
83 
getAttachments()84 		const KinematicAttachmentList& getAttachments() const { return mAttachments; }
85 
getTransformations()86 		const TransformationList& getTransformations() const { return mTransformations; }
87 	};
88 
89 	typedef std::vector<KinematicLink*> KinematicLinkList;
90 
91 	/** An attachment within a kinematics model.*/
92 	class KinematicAttachment : public IntermediateTargetableTemplate<INTERMEDIATETARGETABLE_TYPE::KINEMATICATTACHMENT>
93 	{
94 	public:
95 		enum Type { FULL, START, END };
96 	private:
97 		KinematicLink mLink;
98 		Type mType;
99 		TransformationList mTransformations;
100 		SidAddress mJoint;
101 	public:
KinematicAttachment(Type type,const SidAddress & joint)102 		KinematicAttachment( Type type, const SidAddress& joint )
103 			: mType(type)
104 			, mJoint(joint)
105 		{}
106 
~KinematicAttachment()107 		~KinematicAttachment(){ deleteVector(mTransformations); }
108 
getLink()109 		const KinematicLink& getLink() const { return mLink; }
getLink()110 		KinematicLink& getLink(){ return mLink; }
111 
getType()112 		Type getType() const { return mType; }
113 
getJoint()114 		const SidAddress& getJoint() const { return mJoint; }
115 
116 		/** Adds a transformation to the link. The transformation will be deleted on destruction.*/
addTransformation(COLLADAFW::Transformation * transformation)117 		void addTransformation( COLLADAFW::Transformation* transformation ) { mTransformations.push_back(transformation); }
118 
getTransformations()119 		const TransformationList& getTransformations() const { return mTransformations; }
120 	};
121 
122 
123 	/** A kinematics model as described in COLLADA.*/
124 	class KinematicsModel: public IntermediateTargetableTemplate<INTERMEDIATETARGETABLE_TYPE::KINEMATICMODEL>
125 	{
126 	private:
127 		KinematicLinkList mBaseLinks;
128 
129 		/** The id of the kinematics model.*/
130 		COLLADABU::URI mUrl;
131 
132 		/** The name of the kinematics model.*/
133 		String mName;
134 
135 		SidTreeNode* mSidTreeNode;
136 	public:
137 		KinematicsModel(const COLLADABU::URI& url, const char* name );
138 
139 		~KinematicsModel();
140 
addBaseLink(KinematicLink * baseLink)141 		void addBaseLink( KinematicLink* baseLink ) { mBaseLinks.push_back(baseLink); }
142 
getBaseLinks()143 		const KinematicLinkList& getBaseLinks() const { return mBaseLinks; }
144 
145 		/** The name of the kinematics model.*/
getName()146 		const String& getName() const { return mName; }
147 
148 		/** The id of the kinematics model.*/
getUrl()149 		const COLLADABU::URI& getUrl() const { return mUrl; }
150 
getSidTreeNode()151 		SidTreeNode* getSidTreeNode() const { return mSidTreeNode; }
setSidTreeNode(SidTreeNode * val)152 		void setSidTreeNode(SidTreeNode* val) { mSidTreeNode = val; }
153 	};
154 
155 
156 	class AxisInfo
157 	{
158 	private:
159 		/** The joint primitive which axes is referenced by the AxisInfo.*/
160 		SidAddress mJointPrimitiveAddress;
161 
162 		/** True if the joint is active, false otherwise. Defaults to true.*/
163 		bool mIsActive;
164 
165 		/** True if the joint is locked, false otherwise. Defaults to false.*/
166 		bool mIsLocked;
167 
168 		/** The index of the axis in the roboter. 1-base, 0 meas unset.*/
169 		int mIndex;
170 	public:
171 
172 		/** Constructor. */
AxisInfo(SidAddress jointPrimitiveAddress)173 		AxisInfo(SidAddress jointPrimitiveAddress)
174 			: mJointPrimitiveAddress(jointPrimitiveAddress)
175 			, mIsActive(true)
176 			, mIsLocked(false)
177 			, mIndex(0)
178 		{}
179 
180 		/** Destructor. */
~AxisInfo()181 		virtual ~AxisInfo(){}
182 
183 		/** The joint primitive which axes is referenced by the AxisInfo.*/
getJointPrimitiveRefAddress()184 		const SidAddress& getJointPrimitiveRefAddress() const { return mJointPrimitiveAddress; }
185 
186 		/** The joint primitive which axes is referenced by the AxisInfo.*/
setJointPrimitiveAddress(const SidAddress & jointPrimitiveAddress)187 		void setJointPrimitiveAddress( const SidAddress& jointPrimitiveAddress) { mJointPrimitiveAddress = jointPrimitiveAddress; }
188 
189 		/** True if the joint is active, false otherwise .*/
getIsActive()190 		bool getIsActive() const { return mIsActive; }
191 
192 		/** True if the joint is active, false otherwise .*/
setIsActive(bool isActive)193 		void setIsActive(bool isActive) { mIsActive = isActive; }
194 
195 		/** True if the joint is locked, false otherwise .*/
getIsLocked()196 		bool getIsLocked() const { return mIsLocked; }
197 
198 		/** True if the joint is locked, false otherwise .*/
setIsLocked(bool isLocked)199 		void setIsLocked(bool isLocked) { mIsLocked = isLocked; }
200 
201 		/** The index of the axis in the roboter. 1-base, 0 meas unset.*/
getIndex()202 		int getIndex() const { return mIndex; }
203 
204 		/** The index of the axis in the roboter. 1-base, 0 meas unset.*/
setIndex(int index)205 		void setIndex(int index) { mIndex = index; }
206 	};
207 
208 	typedef std::vector<AxisInfo> AxisInfoList;
209 
210 
211 	/** New param as it appears in formula and kinematics */
212 	class KinematicsNewParam
213 	{
214 	public:
215 		enum ValueType { VALUETYPE_UNKNOWN, VALUETYPE_FLOAT, VALUETYPE_INT, VALUETYPE_BOOL, VALUETYPE_SIDREF};
216 	private:
217 		/** Value type of the new param.*/
218 		ValueType mValueType;
219 
220 
221 		union Value
222 		{
223 			double _double;
224 			int _int;
225 			bool _bool;
226 			SidAddress* _sidref;
227 		} mValue;
228 
229 		/** The name of the new param (sid in COLLADA).*/
230 		String mName;
231 	public:
232 
233 		/** Constructor. */
KinematicsNewParam(ValueType valueType)234 		KinematicsNewParam(ValueType valueType)
235 			: mValueType(valueType)
236 		{
237 			switch ( mValueType )
238 			{
239 			case VALUETYPE_BOOL:
240 				mValue._bool = true;
241 				break;
242 			case VALUETYPE_FLOAT:
243 				mValue._double = 0;
244 				break;
245 			case VALUETYPE_INT:
246 				mValue._int = 0;
247 				break;
248 			case VALUETYPE_SIDREF:
249 				mValue._sidref = 0;
250 				break;
251 			case VALUETYPE_UNKNOWN:
252 				break;
253 			}
254 		}
255 
256 		/** Destructor. */
~KinematicsNewParam()257 		virtual ~KinematicsNewParam(){deleteSidRef();}
258 
259 		/** Returns the value type of the new param.*/
getValueType()260 		ValueType getValueType() const { return mValueType; }
261 
262 		/** Sets the value type of the new param.*/
263 //		void setValueType(ValueType valueType) { mValueType = valueType; }
264 
265 		/** Returns the double value of the new param. Type must be VALUETYPE_FLOAT.*/
getDoubleValue()266 		double getDoubleValue() const { return mValue._double; }
267 
268 		/** Sets the double value of the new param. Type will be set to VALUETYPE_FLOAT.*/
setDoubleValue(double doubleValue)269 		void setDoubleValue(double doubleValue) { deleteSidRef(); mValue._double = doubleValue; mValueType = VALUETYPE_FLOAT; }
270 
271 		/** Returns the int value of the new param. Type must be VALUETYPE_INT.*/
getIntValue()272 		int getIntValue() const { return mValue._int; }
273 
274 		/** Sets the int value of the new param. Type will be set to VALUETYPE_INT.*/
setIntValue(int intValue)275 		void setIntValue(int intValue) { deleteSidRef(); mValue._int = intValue; mValueType = VALUETYPE_INT; }
276 
277 		/** Returns the bool value of the new param. Type must be VALUETYPE_BOOL.*/
getBoolValue()278 		bool getBoolValue() const { return mValue._bool; }
279 
280 		/** Sets the bool value of the new param. Type will be set to VALUETYPE_BOOL.*/
setBoolValue(bool boolValue)281 		void setBoolValue(bool boolValue) { deleteSidRef(); mValue._bool = boolValue; mValueType = VALUETYPE_BOOL; }
282 
283 		/** Returns the sidref value of the new param. Type must be VALUETYPE_SIDREF.*/
getSidrefValue()284 		const SidAddress* getSidrefValue() const { return mValue._sidref; }
285 
286 		/** Sets the sidref value of the new param. Type will be set to VALUETYPE_SIDREF.*/
setSidrefValue(const SidAddress & sidrefValue)287 		void setSidrefValue( const SidAddress& sidrefValue) { deleteSidRef(); mValue._sidref = new SidAddress(sidrefValue); mValueType = VALUETYPE_SIDREF; }
288 
289 		/** Returns the name of the new param (sid in COLLADA).*/
getName()290 		const String& getName() const { return mName; }
291 
292 		/** Returns the name of the new param (sid in COLLADA).*/
setName(const String & name)293 		void setName(const String& name) { mName = name; }
294 
295 	private:
deleteSidRef()296 		void deleteSidRef()
297 		{
298 			if ( mValueType == VALUETYPE_SIDREF)
299 			{
300 				delete mValue._sidref;
301 				mValue._sidref = 0;
302 			}
303 		}
304 
305 		/** Disable default copy ctor. */
306 		KinematicsNewParam( const KinematicsNewParam& pre );
307 
308 		/** Disable default assignment operator. */
309 		const KinematicsNewParam& operator= ( const KinematicsNewParam& pre );
310 
311 
312 	};
313 
314 	typedef COLLADABU::hash_map<String/*sid*/, KinematicsNewParam*> KinematicsNewParams;
315 
316 
317 	class KinematicsInstanceKinematicsModel : public KinematicInstance
318 	{
319 	private:
320 		KinematicsNewParams mKinematicsNewParams;
321 	public:
KinematicsInstanceKinematicsModel(const COLLADABU::URI & uRL)322 		KinematicsInstanceKinematicsModel( const COLLADABU::URI& uRL)
323 			: KinematicInstance(uRL){}
324 
~KinematicsInstanceKinematicsModel()325 		~KinematicsInstanceKinematicsModel() { deleteMap(mKinematicsNewParams);}
326 
327 		void addKinematicsNewParam(KinematicsNewParam* newParam);
328 
getKinematicsNewParams()329 		const KinematicsNewParams& getKinematicsNewParams() const { return mKinematicsNewParams; }
330 
getKinematicsNewParams()331 		KinematicsNewParams& getKinematicsNewParams() { return mKinematicsNewParams; }
332 
333 		KinematicsNewParam* getNewParamBySid(const String& sid)const;
334 
335 	};
336 
337 	typedef std::list<KinematicsInstanceKinematicsModel> KinematicsInstanceKinematicsModels;
338 
339 	/** A kinematics controller as described in COLLADA articulated system.*/
340 	class KinematicsController: public IntermediateTargetableTemplate<INTERMEDIATETARGETABLE_TYPE::KINEMATICCONTROLLER>
341 	{
342 	private:
343 		/** The id of the kinematics controller.*/
344 		COLLADABU::URI mUri;
345 
346 		/** The name of the kinematics controller.*/
347 		String mName;
348 
349 		AxisInfoList mAxisInfos;
350 		KinematicsInstanceKinematicsModels mKinematicsInstanceKinematicsModels;
351 
352 	public:
KinematicsController(const COLLADABU::URI & uri,const String & name)353 		KinematicsController(const COLLADABU::URI& uri, const String& name )
354 			: mUri( uri ), mName(name) {}
355 
~KinematicsController()356 		~KinematicsController(){}
357 
358 		/** The name of the kinematics controller.*/
getName()359 		const String& getName() const { return mName; }
360 
361 		/** The id of the kinematics controller.*/
getUri()362 		const COLLADABU::URI& getUri() const { return mUri; }
363 
getAxisInfos()364 		const AxisInfoList& getAxisInfos() const { return mAxisInfos; }
getAxisInfos()365 		AxisInfoList& getAxisInfos(){ return mAxisInfos; }
366 
getKinematicsInstanceKinematicsModels()367 		const KinematicsInstanceKinematicsModels& getKinematicsInstanceKinematicsModels() const { return mKinematicsInstanceKinematicsModels; }
getKinematicsInstanceKinematicsModels()368 		KinematicsInstanceKinematicsModels& getKinematicsInstanceKinematicsModels() { return mKinematicsInstanceKinematicsModels; }
369 	};
370 
371 
372 	/** Bind as it appears in kinematics */
373 	class KinematicsBind
374 	{
375 	public:
376 		enum ValueType { VALUETYPE_UNKNOWN, VALUETYPE_FLOAT, VALUETYPE_INT, VALUETYPE_BOOL, VALUETYPE_SIDREF, VALUETYPE_PARAM};
377 	private:
378 		/** Value type of the bind.*/
379 		ValueType mValueType;
380 
381 		union Value
382 		{
383 			double _double;
384 			int _int;
385 			bool _bool;
386 			SidAddress* _sidref;
387 			String* _param;
388 		} mValue;
389 
390 		/** The symbol of the bind (sid in COLLADA).*/
391 		String mSymbol;
392 	public:
393 
394 		/** Constructor. */
395 		KinematicsBind(ValueType valueType);
396 
397 		/** Constructor. */
398 		KinematicsBind();
399 
400 		/** Destructor. */
~KinematicsBind()401 		virtual ~KinematicsBind(){deleteAll();}
402 
403 		/** Returns the value type of the bind.*/
getValueType()404 		ValueType getValueType() const { return mValueType; }
405 
406 		/** Sets the value type of the bind.*/
407 		//		void setValueType(ValueType valueType) { mValueType = valueType; }
408 
409 		/** Returns the double value of the bind. Type must be VALUETYPE_FLOAT.*/
getDoubleValue()410 		double getDoubleValue() const { return mValue._double; }
411 
412 		/** Sets the double value of the bind. Type will be set to VALUETYPE_FLOAT.*/
setDoubleValue(double doubleValue)413 		void setDoubleValue(double doubleValue) { deleteAll(); mValue._double = doubleValue; mValueType = VALUETYPE_FLOAT; }
414 
415 		/** Returns the int value of the bind. Type must be VALUETYPE_INT.*/
getIntValue()416 		int getIntValue() const { return mValue._int; }
417 
418 		/** Sets the int value of the bind. Type will be set to VALUETYPE_INT.*/
setIntValue(int intValue)419 		void setIntValue(int intValue) { deleteAll(); mValue._int = intValue; mValueType = VALUETYPE_INT; }
420 
421 		/** Returns the bool value of the bind. Type must be VALUETYPE_BOOL.*/
getBoolValue()422 		bool getBoolValue() const { return mValue._bool; }
423 
424 		/** Sets the bool value of the bind. Type will be set to VALUETYPE_BOOL.*/
setBoolValue(bool boolValue)425 		void setBoolValue(bool boolValue) { deleteAll(); mValue._bool = boolValue; mValueType = VALUETYPE_BOOL; }
426 
427 		/** Returns the sidref value of the bind. Type must be VALUETYPE_SIDREF.*/
getSidrefValue()428 		const SidAddress* getSidrefValue() const { return mValue._sidref; }
429 
430 		/** Sets the sidref value of the bind. Type will be set to VALUETYPE_SIDREF.*/
setSidrefValue(const SidAddress & sidrefValue)431 		void setSidrefValue( const SidAddress& sidrefValue) { deleteAll(); mValue._sidref = new SidAddress(sidrefValue); mValueType = VALUETYPE_SIDREF; }
432 
433 		/** Returns the param ref of the bind. Type must be VALUETYPE_PARAM.*/
getParamValue()434 		const String* getParamValue() const { return mValue._param; }
435 
436 		/** Sets the param value of the bind. Type will be set to VALUETYPE_PARAM.*/
setParamValue(const String & paramValue)437 		void setParamValue( const String& paramValue) { deleteAll(); mValue._param = new String(paramValue); mValueType = VALUETYPE_PARAM; }
438 
439 		/** Returns the name of the bind (sid in COLLADA).*/
getSymbol()440 		const String& getSymbol() const { return mSymbol; }
441 
442 		/** Returns the name of the bind (sid in COLLADA).*/
setSymbol(const String & symbol)443 		void setSymbol(const String& symbol) { mSymbol = symbol; }
444 
445 	private:
deleteSidRef()446 		void deleteSidRef()
447 		{
448 			if ( mValueType == VALUETYPE_SIDREF)
449 			{
450 				delete mValue._sidref;
451 				mValue._sidref = 0;
452 			}
453 		}
454 
deleteParam()455 		void deleteParam()
456 		{
457 			if ( mValueType == VALUETYPE_PARAM)
458 			{
459 				delete mValue._param;
460 				mValue._param = 0;
461 			}
462 		}
463 
deleteAll()464 		void deleteAll()
465 		{
466 			deleteSidRef();
467 			deleteParam();
468 		}
469 
470 		/** Disable default copy ctor. */
471 		KinematicsBind( const KinematicsBind& pre );
472 
473 		/** Disable default assignment operator. */
474 		const KinematicsBind& operator= ( const KinematicsBind& pre );
475 	};
476 
477 	typedef std::vector<KinematicsBind*> KinematicsBinds;
478 
479 
480 
481 	/** A kinematics controller as described in COLLADA articulated system.*/
482 	class KinematicsInstanceArticulatedSystem : public KinematicInstance
483 	{
484 	private:
485 		KinematicsNewParams mKinematicsNewParams;
486 		KinematicsBinds mKinematicsBinds;
487 
488 	public:
KinematicsInstanceArticulatedSystem(const COLLADABU::URI & uRL)489 		KinematicsInstanceArticulatedSystem( const COLLADABU::URI& uRL)
490 			: KinematicInstance(uRL){}
491 
492 		~KinematicsInstanceArticulatedSystem();
493 
addBind(KinematicsBind * bind)494 		void addBind( KinematicsBind* bind) { mKinematicsBinds.push_back(bind); }
495 
496 	};
497 
498 	typedef std::vector<KinematicsInstanceArticulatedSystem*> KinematicsInstanceArticulatedSystems;
499 
500 	/** A kinematics scene as described in COLLADA articulated system.*/
501 	class KinematicsScene: public IntermediateTargetableTemplate<INTERMEDIATETARGETABLE_TYPE::KINEMATICSCENE>
502 	{
503 	private:
504 		/** The id of the kinematics scene.*/
505 		COLLADABU::URI mUri;
506 
507 		/** The name of the kinematics scene.*/
508 		String mName;
509 
510 		KinematicsInstanceArticulatedSystems mKinematicsInstanceArticulatedSystems;
511 
512 		KinematicsInstanceKinematicsModels mKinematicsInstanceKinematicsModels;
513 
514 	public:
KinematicsScene(const COLLADABU::URI & uri,const String & name)515 		KinematicsScene(const COLLADABU::URI& uri, const String& name )
516 			: mUri( uri ), mName(name) {}
517 
518 		~KinematicsScene();
519 
520 		void addInstanceArticulatedSystem(KinematicsInstanceArticulatedSystem* kinematicsInstanceArticulatedSystem);
521 
getKinematicsInstanceArticulatedSystems()522 		const KinematicsInstanceArticulatedSystems& getKinematicsInstanceArticulatedSystems() const { return mKinematicsInstanceArticulatedSystems; }
523 
524 		void addInstanceKinematicsModel(KinematicsInstanceKinematicsModel* kinematicsInstanceKinematicsModel);
525 
getKinematicsInstanceKinematicsModels()526 		const KinematicsInstanceKinematicsModels& getKinematicsInstanceKinematicsModels() const { return mKinematicsInstanceKinematicsModels; }
527 
getKinematicsInstanceKinematicsModels()528 		KinematicsInstanceKinematicsModels& getKinematicsInstanceKinematicsModels() { return mKinematicsInstanceKinematicsModels; }
529 
530 		/** The id of the kinematics scene.*/
getUri()531 		const COLLADABU::URI& getUri() const { return mUri; }
532 	};
533 
534 
535 	/** Bind as it appears in kinematics */
536 	class KinematicsSidrefOrParam
537 	{
538 	public:
539 		enum ValueType { VALUETYPE_UNKNOWN, VALUETYPE_PARAM, VALUETYPE_SIDREF};
540 	private:
541 		/** Value type of the bind.*/
542 		ValueType mValueType;
543 
544 		union Value
545 		{
546 			SidAddress* _sidref;
547 			String* _param;
548 		} mValue;
549 
550 		/** The symbol of the bind (sid in COLLADA).*/
551 		String mSymbol;
552 	public:
553 
554 		/** Constructor. */
555 		KinematicsSidrefOrParam(ValueType axisType);
556 
557 		/** Constructor. */
KinematicsSidrefOrParam()558 		KinematicsSidrefOrParam() : mValueType(VALUETYPE_UNKNOWN){}
559 
560 		/** Destructor. */
~KinematicsSidrefOrParam()561 		virtual ~KinematicsSidrefOrParam(){deleteAll();}
562 
563 		/** Returns the value type SidrefOrParam.*/
getValueType()564 		ValueType getValueType() const { return mValueType; }
565 
566 		/** Returns the sidref value SidrefOrParam. Type must be VALUETYPE_SIDREF.*/
getSidrefValue()567 		const SidAddress* getSidrefValue() const { return mValue._sidref; }
568 
569 		/** Sets the sidref value SidrefOrParam. Type will be set to VALUETYPE_SIDREF.*/
570 		void setSidrefValue( const SidAddress& sidrefValue);
571 
572 		/** Returns the param ref SidrefOrParam. Type must be VALUETYPE_PARAM.*/
getParamValue()573 		const String* getParamValue() const { return mValue._param; }
574 
575 		/** Sets the param value SidrefOrParam. Type will be set to VALUETYPE_PARAM.*/
576 		void setParamValue( const String& paramValue);
577 	private:
578 		void deleteSidRef();
579 
580 		void deleteParam();
581 
582 		void deleteAll();
583 
584 		/** Disable default copy ctor. */
585 		KinematicsSidrefOrParam( const KinematicsSidrefOrParam& pre );
586 
587 		/** Disable default assignment operator. */
588 		const KinematicsSidrefOrParam& operator= ( const KinematicsSidrefOrParam& pre );
589 	};
590 
591 	typedef KinematicsSidrefOrParam KinematicsAxis;
592 
593 	/** Bind as it appears in kinematics */
594 	class KinematicsFloatOrParam
595 	{
596 	public:
597 		enum ValueType { VALUETYPE_UNKNOWN, VALUETYPE_PARAM, VALUETYPE_FLOAT};
598 	private:
599 		/** Value type of the bind.*/
600 		ValueType mValueType;
601 
602 		union Value
603 		{
604 			float _float;
605 			String* _param;
606 		} mValue;
607 
608 		/** The symbol of the bind (sid in COLLADA).*/
609 		String mSymbol;
610 	public:
611 
612 		/** Constructor. */
613 		KinematicsFloatOrParam(ValueType axisType);
614 
615 		/** Constructor. */
KinematicsFloatOrParam()616 		KinematicsFloatOrParam() : mValueType(VALUETYPE_UNKNOWN){}
617 
618 		/** Destructor. */
~KinematicsFloatOrParam()619 		virtual ~KinematicsFloatOrParam(){deleteParam();}
620 
621 		/** Returns the axis type FloatOrParam.*/
getValueType()622 		ValueType getValueType() const { return mValueType; }
623 
624 		/** Returns the sidref value FloatOrParam. Type must be VALUETYPE_FLOAT.*/
getFloatValue()625 		float getFloatValue() const { return mValue._float; }
626 
627 		/** Sets the sidref value FloatOrParam. Type will be set to VALUETYPE_FLOAT.*/
setFloatValue(float value)628 		void setFloatValue( float value) { deleteParam(); mValue._float=value; mValueType = VALUETYPE_FLOAT; }
629 
630 		/** Returns the param ref FloatOrParam. Type must be VALUETYPE_PARAM.*/
getParamValue()631 		const String* getParamValue() const { return mValue._param; }
632 
633 		/** Sets the param value FloatOrParam. Type will be set to VALUETYPE_PARAM.*/
setParamValue(const String & paramValue)634 		void setParamValue( const String& paramValue) { deleteParam(); mValue._param = new String(paramValue); mValueType = VALUETYPE_PARAM; }
635 	private:
deleteParam()636 		void deleteParam()
637 		{
638 			if ( mValueType == VALUETYPE_PARAM)
639 			{
640 				delete mValue._param;
641 				mValue._param = 0;
642 			}
643 		}
644 
645 		/** Disable default copy ctor. */
646 		KinematicsFloatOrParam( const KinematicsFloatOrParam& pre );
647 
648 		/** Disable default assignment operator. */
649 		const KinematicsFloatOrParam& operator= ( const KinematicsFloatOrParam& pre );
650 	};
651 
652 	typedef KinematicsFloatOrParam KinematicsValue;
653 
654 	/** bind_joint_axis as it appears in kinematics */
655 	class KinematicsBindJointAxis
656 	{
657 	private:
658 
659 		/** The target of the bind (sid in COLLADA).*/
660 		SidAddress mTarget;
661 
662 		/** The axis.*/
663 		KinematicsAxis mAxis;
664 
665 		/** The value of the axis.*/
666 		KinematicsValue mValue;
667 	public:
668 
669 		/** Constructor. */
KinematicsBindJointAxis(SidAddress target)670 		KinematicsBindJointAxis(SidAddress target) : mTarget(target){}
671 
672 		/** Destructor. */
~KinematicsBindJointAxis()673 		virtual ~KinematicsBindJointAxis(){}
674 
675 		/** Returns the target of the bind (sid in COLLADA).*/
getTarget()676 		const SidAddress& getTarget() const { return mTarget; }
677 
678 		/** Sets the target of the bind (sid in COLLADA).*/
setTarget(const SidAddress & target)679 		void setTarget( const SidAddress& target) { mTarget = target; }
680 
681 		/** Returns the axis.*/
getAxis()682 		const KinematicsAxis& getAxis() const { return mAxis; }
683 
684 		/** Returns the axis.*/
getAxis()685 		KinematicsAxis& getAxis(){ return mAxis; }
686 
687 		/** Returns the value.*/
getValue()688 		const KinematicsValue& getValue() const { return mValue; }
689 
690 		/** Returns the value.*/
getValue()691 		KinematicsValue& getValue(){ return mValue; }
692 
693 	private:
694 		/** Disable default copy ctor. */
695 		KinematicsBindJointAxis( const KinematicsBindJointAxis& pre );
696 
697 		/** Disable default assignment operator. */
698 		const KinematicsBindJointAxis& operator= ( const KinematicsBindJointAxis& pre );
699 	};
700 
701 	typedef std::vector<KinematicsBindJointAxis*> KinematicsBindJointAxes;
702 
703 
704 	/** instance_kinematics_scene as it appears in kinematics */
705 	class KinematicsInstanceKinematicsScene
706 	{
707 	private:
708 
709 		/** The url of the instantiate kinematics scene.*/
710 		COLLADABU::URI mUrl;
711 
712 		KinematicsBindJointAxes mBindJointAxes;
713 
714 		// file id
715 
716 	public:
717 
718 		/** Constructor. */
KinematicsInstanceKinematicsScene()719 		KinematicsInstanceKinematicsScene(){}
720 
721 		/** Destructor. */
722 		virtual ~KinematicsInstanceKinematicsScene();
723 
724 		/** The url of the instantiate kinematics scene.*/
getUrl()725 		COLLADABU::URI getUrl() const { return mUrl; }
726 
727 		/** The url of the instantiate kinematics scene.*/
setUrl(COLLADABU::URI url)728 		void setUrl(COLLADABU::URI url) { mUrl = url; }
729 
addBindJointAxis(KinematicsBindJointAxis * bindJointAxis)730 		void addBindJointAxis(KinematicsBindJointAxis* bindJointAxis) { mBindJointAxes.push_back(bindJointAxis);}
731 
getBindJointAxes()732 		const KinematicsBindJointAxes& getBindJointAxes() const { return mBindJointAxes; }
733 	private:
734 		/** Disable default copy ctor. */
735 		KinematicsInstanceKinematicsScene( const KinematicsInstanceKinematicsScene& pre );
736 
737 		/** Disable default assignment operator. */
738 		const KinematicsInstanceKinematicsScene& operator= ( const KinematicsInstanceKinematicsScene& pre );
739 	};
740 
741 
742     /** Kinematics data that needs to be stored while parsing a COLLADA file. This data is used to
743 	build the kinematics model, after the entire file has been parsed.
744 	All the heap instances of FW classes are created by using FW_NEW, instances of other classes by using new.*/
745 	class KinematicsIntermediateData
746 	{
747 	public:
748 		/** List of Joints.*/
749 		typedef std::vector< COLLADAFW::Joint* > JointList;
750 
751 		/** List of instance instances.*/
752 		typedef std::vector< KinematicInstance* > KinematicInstanceList;
753 
754 		/** List of kinematic models.*/
755 		typedef COLLADABU::hash_map< COLLADABU::URI, KinematicsModel* > KinematicsModelMap;
756 
757 		/** List of kinematic controllers.*/
758 		typedef COLLADABU::hash_map< COLLADABU::URI, KinematicsController* > KinematicsControllerMap;
759 
760 		/** List of kinematic scenes.*/
761 		typedef COLLADABU::hash_map< COLLADABU::URI, KinematicsScene* > KinematicsSceneMap;
762 
763 		/** List of instance kinematics scenes.*/
764 		typedef std::vector<KinematicsInstanceKinematicsScene*> KinematicsInstanceKinematicsScenes;
765 
766 	private:
767 		/** List of all joints already created. They will be written as part of kinematics.*/
768 		JointList mJoints;
769 
770 		/** List of all instance joints already created. They will be written as part of kinematics.*/
771 		KinematicInstanceList mInstanceJoints;
772 
773 		/** List of all kinematic models already created. They will be written as part of kinematics.*/
774 		KinematicsModelMap mKinematicsModels;
775 
776 		/** List of all kinematic controller already created. They will be written as part of kinematics.*/
777 		KinematicsControllerMap mKinematicsControllers;
778 
779 		/** List of all kinematic scenes already created. They will be written as part of kinematics.*/
780 		KinematicsSceneMap mKinematicsScenes;
781 
782 		/** The only instance kinematics scenes.*/
783 		KinematicsInstanceKinematicsScenes mInstanceKinematicsScenes;
784 
785 	public:
786 
787 		/** Returns the list of all joints already created. They will be written as part of kinematics.*/
getJoints()788 		const JointList& getJoints() const { return mJoints; }
789 
790 		/** Returns the list of all joints already created. They will be written as part of kinematics.*/
getJoints()791 		JointList& getJoints() { return mJoints; }
792 
793 		/** Returns the list of all InstanceJoints already created. They will be written as part of kinematics.*/
getInstanceJoints()794 		const KinematicInstanceList& getInstanceJoints() const { return mInstanceJoints; }
795 
796 		/** Returns the list of all InstanceJoints already created. They will be written as part of kinematics.*/
getInstanceJoints()797 		KinematicInstanceList& getInstanceJoints() { return mInstanceJoints; }
798 
799 		/** List of all kinematic models already created. They will be written as part of kinematics.*/
getKinematicsModels()800 		const KinematicsModelMap& getKinematicsModels() const { return mKinematicsModels; }
801 
802 		/** List of all kinematic models already created. They will be written as part of kinematics.*/
getKinematicsModels()803 		KinematicsModelMap& getKinematicsModels() { return mKinematicsModels; }
804 
805 		/** List of all kinematic controllers already created. They will be written as part of kinematics.*/
getKinematicsControllers()806 		const KinematicsControllerMap& getKinematicsControllers() const { return mKinematicsControllers; }
807 
808 		/** List of all kinematic controllers already created. They will be written as part of kinematics.*/
getKinematicsControllers()809 		KinematicsControllerMap& getKinematicsControllers() { return mKinematicsControllers; }
810 
811 		/** List of all kinematic scenes already created. They will be written as part of kinematics.*/
getKinematicsScenes()812 		const KinematicsSceneMap& getKinematicsScenes() const { return mKinematicsScenes; }
813 
814 		/** List of all kinematic scenes already created. They will be written as part of kinematics.*/
getKinematicsScenes()815 		KinematicsSceneMap& getKinematicsScenes() { return mKinematicsScenes; }
816 
817 		/** List of all instance kinematic scenes already created. They will be written as part of kinematics.*/
getInstanceKinematicsScenes()818 		const KinematicsInstanceKinematicsScenes& getInstanceKinematicsScenes() const { return mInstanceKinematicsScenes; }
819 
820 		/** List of all instance kinematic scenes already created. They will be written as part of kinematics.*/
getInstanceKinematicsScenes()821 		KinematicsInstanceKinematicsScenes& getInstanceKinematicsScenes() { return mInstanceKinematicsScenes; }
822 
823         /** Constructor. */
824 		KinematicsIntermediateData();
825 
826         /** Destructor. */
827 		virtual ~KinematicsIntermediateData();
828 
829 	private:
830 
831         /** Disable default copy ctor. */
832 		KinematicsIntermediateData( const KinematicsIntermediateData& pre );
833 
834         /** Disable default assignment operator. */
835 		const KinematicsIntermediateData& operator= ( const KinematicsIntermediateData& pre );
836 
837 	};
838 
839 } // namespace COLLADASAXFWL
840 
841 #endif // __COLLADASAXFWL_KINEMATICSINTERMEDIATEDATA_H__
842