AnimatLab  2
Test
Box.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 #include "IMovableItemCallback.h"
9 #include "ISimGUICallback.h"
10 #include "AnimatBase.h"
11 
12 #include "Node.h"
13 #include "IPhysicsMovableItem.h"
14 #include "IPhysicsBody.h"
15 #include "BoundingBox.h"
16 #include "MovableItem.h"
17 #include "BodyPart.h"
18 #include "Joint.h"
19 #include "ReceptiveField.h"
20 #include "ContactSensor.h"
21 #include "RigidBody.h"
22 #include "Box.h"
23 #include "Structure.h"
24 #include "Organism.h"
25 #include "ActivatedItem.h"
26 #include "ActivatedItemMgr.h"
27 #include "DataChartMgr.h"
28 #include "ExternalStimuliMgr.h"
29 #include "KeyFrame.h"
30 #include "SimulationRecorder.h"
31 #include "OdorType.h"
32 #include "Odor.h"
33 #include "Light.h"
34 #include "LightManager.h"
35 #include "Simulator.h"
36 
37 namespace AnimatSim
38 {
39  namespace Environment
40  {
41  namespace Bodies
42  {
50 {
51  m_fltLength = 1;
52  m_fltWidth = 1;
53  m_fltHeight = 1;
55  m_iWidthSections = 1;
57 }
58 
66 {
67 }
68 
69 float Box::Length() {return m_fltLength;}
70 
71 void Box::Length(float fltVal, bool bUseScaling)
72 {
73  Std_IsAboveMin((float) 0, fltVal, true, "BoxSize.Length");
74  if(bUseScaling)
76  else
77  m_fltLength = fltVal;
78 
79  Resize();
80 }
81 
82 float Box::Width() {return m_fltWidth;}
83 
84 void Box::Width(float fltVal, bool bUseScaling)
85 {
86  Std_IsAboveMin((float) 0, fltVal, true, "BoxSize.Width");
87  if(bUseScaling)
89  else
90  m_fltWidth = fltVal;
91 
92  Resize();
93 }
94 
95 float Box::Height() {return m_fltHeight;}
96 
97 void Box::Height(float fltVal, bool bUseScaling)
98 {
99  Std_IsAboveMin((float) 0, fltVal, true, "BoxSize.Height");
100  if(bUseScaling)
102  else
103  m_fltHeight = fltVal;
104 
105  Resize();
106 }
107 
116 void Box::LengthSections(int iVal)
117 {
118  Std_IsAboveMin((int) 0, iVal, true, "BoxSize.LengthSections");
119  m_iLengthSections = iVal;
120 
121  Resize();
122 }
123 
133 
142 void Box::WidthSections(int iVal)
143 {
144  Std_IsAboveMin((int) 0, iVal, true, "BoxSize.WidthSections");
145  m_iWidthSections = iVal;
146 
147  Resize();
148 }
149 
159 
168 void Box::HeightSections(int iVal)
169 {
170  Std_IsAboveMin((int) 0, iVal, true, "BoxSize.HeightSections");
171  m_iHeightSections = iVal;
172 
173  Resize();
174 }
175 
185 
195 
205 
215 
216 
217 bool Box::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
218 {
219  std::string strType = Std_CheckString(strDataType);
220 
221  if(RigidBody::SetData(strType, strValue, false))
222  return true;
223 
224  if(strType == "LENGTH")
225  {
226  Length((float) atof(strValue.c_str()));
227  return true;
228  }
229 
230  if(strType == "WIDTH")
231  {
232  Width((float) atof(strValue.c_str()));
233  return true;
234  }
235 
236  if(strType == "HEIGHT")
237  {
238  Height((float) atof(strValue.c_str()));
239  return true;
240  }
241 
242  if(strType == "LENGTHSECTIONS")
243  {
244  LengthSections(atoi(strValue.c_str()));
245  return true;
246  }
247 
248  if(strType == "WIDTHSECTIONS")
249  {
250  WidthSections(atoi(strValue.c_str()));
251  return true;
252  }
253 
254  if(strType == "HEIGHTSECTIONS")
255  {
256  HeightSections(atoi(strValue.c_str()));
257  return true;
258  }
259 
260  //If it was not one of those above then we have a problem.
261  if(bThrowError)
262  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
263 
264  return false;
265 }
266 
267 void Box::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
268 {
269  RigidBody::QueryProperties(aryProperties);
270 
271  aryProperties.Add(new TypeProperty("Length", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
272  aryProperties.Add(new TypeProperty("Width", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
273  aryProperties.Add(new TypeProperty("Height", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
274  aryProperties.Add(new TypeProperty("LengthSections", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
275  aryProperties.Add(new TypeProperty("WidthSections", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
276  aryProperties.Add(new TypeProperty("HeightSections", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
277 }
278 
279 void Box::Load(CStdXml &oXml)
280 {
281  RigidBody::Load(oXml);
282 
283  oXml.IntoElem(); //Into RigidBody Element
284 
285  Length(oXml.GetChildFloat("Length", m_fltLength));
286  Width(oXml.GetChildFloat("Width", m_fltWidth));
287  Height(oXml.GetChildFloat("Height", m_fltHeight));
288 
289  LengthSections(oXml.GetChildInt("LengthSections", m_iLengthSections));
290  WidthSections(oXml.GetChildInt("WidthSections", m_iWidthSections));
291  HeightSections(oXml.GetChildInt("HeightSections", m_iHeightSections));
292 
293  oXml.OutOfElem(); //OutOf RigidBody Element
294 }
295 
296  } //Bodies
297  } //Environment
298 } //AnimatSim
Base class file for all Animat simulation objects.
Declares the simulation recorder class.
virtual float WidthSegmentSize()
Gets the width segment size.
Definition: Box.cpp:204
Root namespace for the base simulation library for AnimatLab.
int m_iHeightSections
The number of sections to split the box height into.
Definition: Box.h:61
Declares the body part class.
int m_iWidthSections
The number of sections to split the box width into.
Definition: Box.h:55
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
virtual bool IntoElem()
Goes into the next element where the cursor is located.
Definition: StdXml.cpp:42
virtual int HeightSections()
Gets the height sections.
Definition: Box.cpp:184
Class that stores information about types for QueryProperty information.
Definition: TypeProperty.h:35
Declares the key frame class.
virtual float Width()
Gets the width of the box.
Definition: Box.cpp:82
Declares the joint class.
Declares the organism class.
virtual int GetChildInt(std::string strElementName)
Gets an integer value from the element with the specified name.
Definition: StdXml.cpp:456
bool Std_IsAboveMin(int iMinVal, int iVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
Tests if a number is above a minimum value.
Declares a light object.
float m_fltLength
The length dimension of the box.
Definition: Box.h:46
virtual void Resize()
Called when this object has been resized.
Definition: BodyPart.cpp:141
Declares the activated item class.
Declares a light manager object.
Declares the bounding box class.
A standard xml manipulation class.
Definition: StdXml.h:19
virtual float Length()
Gets the length of the box.
Definition: Box.cpp:69
Declares the node class.
virtual float LengthSegmentSize()
Gets the length segment size.
Definition: Box.cpp:194
virtual int LengthSections()
Gets the length sections.
Definition: Box.cpp:132
float m_fltWidth
The width dimension of the box.
Definition: Box.h:52
int m_iLengthSections
The number of sections to split the box length into.
Definition: Box.h:49
float m_fltHeight
The height dimension of the box.
Definition: Box.h:58
Box()
Default constructor.
Definition: Box.cpp:49
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
Declares the data chart manager class.
Declares the rigid body class.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
virtual float HeightSegmentSize()
Gets the height segment size.
Definition: Box.cpp:214
Declares the structure class.
Declares the box class.
virtual float Height()
Gets the height of the box.
Definition: Box.cpp:95
Declares the odor type class.
virtual float InverseDistanceUnits()
Gets the inverse distance units.
Definition: Simulator.cpp:1742
Declares the odor class.
Declares the simulator class.
virtual ~Box()
Destructor.
Definition: Box.cpp:65
Declares the activated item manager class.
Declares the contact sensor class.
Declares the external stimuli manager class.
virtual int WidthSections()
Gets the width sections.
Definition: Box.cpp:158
Declares the receptive field class.
virtual float GetChildFloat(std::string strElementName)
Gets a float value from the element with the specified name.
Definition: StdXml.cpp:617