AnimatLab  2
Test
Plane.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 "Plane.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_fltDensity = 0;
52  m_bFreeze = true;
53 
54  m_ptSize.Set(200, 200, 0);
55 }
56 
64 {
65 
66 }
67 
78 float Plane::CornerX() {return m_oAbsPosition.x-(m_ptSize.x/2.0f);}
79 
90 float Plane::CornerY() {return m_oAbsPosition.y-(m_ptSize.y/2.0f);}
91 
104 float Plane::GridX() {return (float) m_iWidthSegments;}
105 
118 float Plane::GridY() {return (float) m_iLengthSegments;}
119 
128 CStdFPoint Plane::Size() {return m_ptSize;}
129 
141 void Plane::Size(CStdFPoint ptPoint, bool bUseScaling)
142 {
143  if(ptPoint.x <= 0)
144  THROW_PARAM_ERROR(Al_Err_lInavlidPlaneSize, Al_Err_strInavlidPlaneSize, "X Size", ptPoint.x);
145  if(ptPoint.y <= 0)
146  THROW_PARAM_ERROR(Al_Err_lInavlidPlaneSize, Al_Err_strInavlidPlaneSize, "Y Size", ptPoint.y);
147 
148  if(bUseScaling)
149  m_ptSize = ptPoint * m_lpSim->InverseDistanceUnits();
150  else
151  m_ptSize = ptPoint;
152 
153  Resize();
154 }
155 
156 void Plane::Size(std::string strXml, bool bUseScaling)
157 {
158  CStdXml oXml;
159  oXml.Deserialize(strXml);
160  oXml.FindElement("Root");
161  oXml.FindChildElement("Size");
162 
163  CStdFPoint vPos;
164  Std_LoadPoint(oXml, "Size", vPos);
165  Size(vPos, bUseScaling);
166 }
167 
178 int Plane::WidthSegments() {return m_iWidthSegments;}
179 
191 void Plane::WidthSegments(int iVal)
192 {
193  Std_IsAboveMin((int) 0, iVal, true, "Plane.WidthSegments");
194  m_iWidthSegments = iVal;
195 
196  Resize();
197 }
198 
209 int Plane::LengthSegments() {return m_iLengthSegments;}
210 
222 void Plane::LengthSegments(int iVal)
223 {
224  Std_IsAboveMin((int) 0, iVal, true, "Plane.LengthSegments");
225  m_iLengthSegments = iVal;
226 
227  Resize();
228 }
229 
230 bool Plane::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
231 {
232  std::string strType = Std_CheckString(strDataType);
233 
234  if(RigidBody::SetData(strType, strValue, false))
235  return true;
236 
237  if(strType == "SIZE")
238  {
239  Size(strValue);
240  return true;
241  }
242 
243  if(strType == "LENGTHSEGMENTS")
244  {
245  LengthSegments(atoi(strValue.c_str()));
246  return true;
247  }
248 
249  if(strType == "WIDTHSEGMENTS")
250  {
251  WidthSegments(atoi(strValue.c_str()));
252  return true;
253  }
254 
255  //If it was not one of those above then we have a problem.
256  if(bThrowError)
257  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
258 
259  return false;
260 }
261 
262 void Plane::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
263 {
264  RigidBody::QueryProperties(aryProperties);
265 
266  aryProperties.Add(new TypeProperty("Size", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
267  aryProperties.Add(new TypeProperty("LengthSegments", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
268  aryProperties.Add(new TypeProperty("WidthSegments", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
269 }
270 
271 void Plane::Load(CStdXml &oXml)
272 {
273  RigidBody::Load(oXml);
274 
275  //Plane is always frozen
276  m_bFreeze = true;
277 
278  oXml.IntoElem(); //Into RigidBody Element
279 
280  CStdFPoint vPos;
281  Std_LoadPoint(oXml, "Size", vPos);
282  Size(vPos);
283 
284  WidthSegments(oXml.GetChildInt("WidthSegments", m_iWidthSegments));
285  LengthSegments(oXml.GetChildInt("LengthSegments", m_iLengthSegments));
286 
287  oXml.OutOfElem(); //OutOf RigidBody Element
288 }
289 
290  } //Bodies
291  } //Environment
292 } //AnimatSim
Plane()
Default constructor.
Definition: Plane.cpp:49
virtual void Deserialize(std::string &strXml)
Deserializes a string into an xml document.
Definition: StdXml.cpp:162
Base class file for all Animat simulation objects.
Declares the simulation recorder class.
virtual float GridY()
Gets the length of a segment for the y dimension of the plane.
Definition: Plane.cpp:118
virtual bool FindChildElement(std::string strElementName, bool fThrowError=true)
Finds a child element by name.
Definition: StdXml.cpp:256
Root namespace for the base simulation library for AnimatLab.
Declares the body part class.
virtual bool FindElement(std::string strElementName, bool fThrowError=true)
Finds an element with the specified name.
Definition: StdXml.cpp:179
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
Class that stores information about types for QueryProperty information.
Definition: TypeProperty.h:35
Declares the key frame class.
virtual float CornerX()
Gets the corner x coordinate.
Definition: Plane.cpp:78
Declares the plane class.
virtual CStdFPoint Size()
Gets the size of the visible plane.
Definition: Plane.cpp:128
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.
virtual float GridX()
Gets the width of a segment for the x dimension of the plane.
Definition: Plane.cpp:104
Declares a light object.
virtual void Resize()
Called when this object has been resized.
Definition: BodyPart.cpp:141
Declares the activated item class.
Declares a light manager object.
float m_fltDensity
Uniform density for the rigid body.
Definition: RigidBody.h:79
virtual int WidthSegments()
Gets the width segments.
Definition: Plane.cpp:178
Declares the bounding box class.
A standard xml manipulation class.
Definition: StdXml.h:19
Declares the node class.
virtual int LengthSegments()
Gets the length segments.
Definition: Plane.cpp:209
virtual ~Plane()
Destructor.
Definition: Plane.cpp:63
virtual float CornerY()
Gets the corner y coordinate.
Definition: Plane.cpp:90
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.
bool Std_LoadPoint(CStdXml &oXml, std::string strName, CStdIPoint &oPoint, bool bThrowError)
Standard load point.
Declares the structure class.
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.
Declares the activated item manager class.
Declares the contact sensor class.
Declares the external stimuli manager class.
Declares the receptive field class.