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 #include "COLLADASaxFWLStableHeaders.h"
12 #include "COLLADASaxFWLKinematicsIntermediateData.h"
13 #include "COLLADASaxFWLUtils.h"
14 
15 #include "COLLADAFWJoint.h"
16 
17 
18 namespace COLLADASaxFWL
19 {
20 
21 	//------------------------------
KinematicsModel(const COLLADABU::URI & url,const char * name)22 	KinematicsModel::KinematicsModel( const COLLADABU::URI& url, const char* name )
23 		: mUrl(url)
24 		, mName(name)
25 		, mSidTreeNode(0)
26 	{
27 	}
28 
29 	//------------------------------
~KinematicsModel()30 	KinematicsModel::~KinematicsModel()
31 	{
32 		// delete base links
33 		deleteVector(mBaseLinks);
34 	}
35 
36 	//------------------------------
KinematicsIntermediateData()37 	KinematicsIntermediateData::KinematicsIntermediateData()
38 	{
39 	}
40 
41 
42 	//------------------------------
KinematicsBind(ValueType valueType)43 	KinematicsBind::KinematicsBind( ValueType valueType ) : mValueType(valueType)
44 	{
45 		switch ( mValueType )
46 		{
47 		case VALUETYPE_BOOL:
48 			mValue._bool = true;
49 			break;
50 		case VALUETYPE_FLOAT:
51 			mValue._double = 0;
52 			break;
53 		case VALUETYPE_INT:
54 			mValue._int = 0;
55 			break;
56 		case VALUETYPE_SIDREF:
57 			mValue._sidref = 0;
58 			break;
59 		case VALUETYPE_PARAM:
60 			mValue._param = 0;
61 			break;
62         case VALUETYPE_UNKNOWN:
63             break;
64 		}
65 	}
66 
67 	//------------------------------
KinematicsBind()68 	KinematicsBind::KinematicsBind( ) : mValueType(VALUETYPE_UNKNOWN)
69 	{}
70 
71 	//------------------------------
~KinematicsInstanceArticulatedSystem()72 	KinematicsInstanceArticulatedSystem::~KinematicsInstanceArticulatedSystem()
73 	{
74 		// delete kinematic binds
75 		deleteVector(mKinematicsBinds);
76 	}
77 
78     //------------------------------
~KinematicsIntermediateData()79 	KinematicsIntermediateData::~KinematicsIntermediateData()
80 	{
81 		// delete joints
82 		deleteVectorFW(mJoints);
83 
84 		// delete joint instances
85 		deleteVectorFW(mInstanceJoints);
86 
87 		// delete kinematic models
88 		deleteMap(mKinematicsModels);
89 
90 		// delete kinematic controllers
91 		deleteMap(mKinematicsControllers);
92 
93 		// delete  instance kinematics scenes
94 		deleteVector(mInstanceKinematicsScenes);
95 	}
96 
97 	//------------------------------
~KinematicsScene()98 	KinematicsScene::~KinematicsScene()
99 	{
100 		// delete kinematics instance articulated systems
101 		deleteVector(mKinematicsInstanceArticulatedSystems);
102 	}
103 
104 	//------------------------------
addInstanceArticulatedSystem(KinematicsInstanceArticulatedSystem * kinematicsInstanceArticulatedSystem)105 	void KinematicsScene::addInstanceArticulatedSystem( KinematicsInstanceArticulatedSystem* kinematicsInstanceArticulatedSystem )
106 	{
107 		mKinematicsInstanceArticulatedSystems.push_back( kinematicsInstanceArticulatedSystem );
108 	}
109 
110 	//------------------------------
KinematicsSidrefOrParam(ValueType axisType)111 	KinematicsSidrefOrParam::KinematicsSidrefOrParam( ValueType axisType )
112 	{
113 		switch ( mValueType )
114 		{
115 		case VALUETYPE_SIDREF:
116 			mValue._sidref = 0;
117 			break;
118 		case VALUETYPE_PARAM:
119 			mValue._param = 0;
120 			break;
121         case VALUETYPE_UNKNOWN:
122             break;
123 		}
124 	}
125 
126 	//------------------------------
setParamValue(const String & paramValue)127 	void KinematicsSidrefOrParam::setParamValue( const String& paramValue )
128 	{
129 		deleteAll();
130 		mValue._param = new String(paramValue);
131 		mValueType = VALUETYPE_PARAM;
132 	}
133 
134 	//------------------------------
setSidrefValue(const SidAddress & sidrefValue)135 	void KinematicsSidrefOrParam::setSidrefValue( const SidAddress& sidrefValue )
136 	{
137 		deleteAll();
138 		mValue._sidref = new SidAddress(sidrefValue);
139 		mValueType = VALUETYPE_SIDREF;
140 	}
141 
142 	//------------------------------
deleteSidRef()143 	void KinematicsSidrefOrParam::deleteSidRef()
144 	{
145 		if ( mValueType == VALUETYPE_SIDREF)
146 		{
147 			delete mValue._sidref;
148 			mValue._sidref = 0;
149 		}
150 	}
151 
152 	//------------------------------
deleteParam()153 	void KinematicsSidrefOrParam::deleteParam()
154 	{
155 		if ( mValueType == VALUETYPE_PARAM)
156 		{
157 			delete mValue._param;
158 			mValue._param = 0;
159 		}
160 	}
161 
162 	//------------------------------
deleteAll()163 	void KinematicsSidrefOrParam::deleteAll()
164 	{
165 		deleteSidRef();
166 		deleteParam();
167 	}
168 
169 	//------------------------------
KinematicsFloatOrParam(ValueType axisType)170 	KinematicsFloatOrParam::KinematicsFloatOrParam( ValueType axisType )
171 	{
172 		switch ( mValueType )
173 		{
174 		case VALUETYPE_FLOAT:
175 			mValue._float = std::numeric_limits<float>::quiet_NaN();
176 			break;
177 		case VALUETYPE_PARAM:
178 			mValue._param = 0;
179 			break;
180         case VALUETYPE_UNKNOWN:
181             break;
182 		}
183 	}
184 
185 	//------------------------------
~KinematicsInstanceKinematicsScene()186 	KinematicsInstanceKinematicsScene::~KinematicsInstanceKinematicsScene()
187 	{
188 		// delete BindJointAxes
189 		deleteVector(mBindJointAxes);
190 	}
191 
192 	//------------------------------
addKinematicsNewParam(KinematicsNewParam * newParam)193 	void KinematicsInstanceKinematicsModel::addKinematicsNewParam( KinematicsNewParam* newParam )
194 	{
195 		const String& name = newParam->getName();
196 		mKinematicsNewParams.insert(std::make_pair(name, newParam));
197 	}
198 
199 	//------------------------------
getNewParamBySid(const String & sid) const200 	KinematicsNewParam* KinematicsInstanceKinematicsModel::getNewParamBySid( const String& sid ) const
201 	{
202 		KinematicsNewParams::const_iterator it =  mKinematicsNewParams.find(sid);
203 		if ( it != mKinematicsNewParams.end() )
204 		{
205 			return it->second;
206 		}
207 		else
208 		{
209 			return 0;
210 		}
211 	}
212 
213 } // namespace COLLADASaxFWL
214