AnimatLab  2
Test
Cone.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 "ReceptiveField.h"
19 #include "ContactSensor.h"
20 #include "RigidBody.h"
21 #include "Cone.h"
22 #include "Structure.h"
23 #include "Organism.h"
24 #include "ActivatedItem.h"
25 #include "ActivatedItemMgr.h"
26 #include "DataChartMgr.h"
27 #include "ExternalStimuliMgr.h"
28 #include "KeyFrame.h"
29 #include "SimulationRecorder.h"
30 #include "OdorType.h"
31 #include "Odor.h"
32 #include "Light.h"
33 #include "LightManager.h"
34 #include "Simulator.h"
35 
36 namespace AnimatSim
37 {
38  namespace Environment
39  {
40  namespace Bodies
41  {
49 {
50  m_fltLowerRadius = 1;
51  m_fltUpperRadius = 1;
52  m_fltHeight = 1;
53  m_iSides = 10;
54 }
55 
63 {
64 
65 }
66 
68 
69 void Cone::LowerRadius(float fltVal, bool bUseScaling)
70 {
71  Std_IsAboveMin((float) 0, fltVal, true, "Cone.LowerRadius", true);
72  if(fltVal == 0 && m_fltUpperRadius == 0)
73  THROW_PARAM_ERROR(Al_Err_lInvalidConeRadius, Al_Err_strInvalidConeRadius, "Body", m_strName);
74 
75  if(bUseScaling)
77  else
78  m_fltLowerRadius = fltVal;
79 
80  Resize();
81 }
82 
84 
85 void Cone::UpperRadius(float fltVal, bool bUseScaling)
86 {
87  Std_IsAboveMin((float) 0, fltVal, true, "Cone.UpperRadius", true);
88  if(m_fltLowerRadius == 0 && fltVal == 0)
89  THROW_PARAM_ERROR(Al_Err_lInvalidConeRadius, Al_Err_strInvalidConeRadius, "Body", m_strName);
90 
91  if(bUseScaling)
93  else
94  m_fltUpperRadius = fltVal;
95 
96  Resize();
97 }
98 
99 
100 float Cone::Height() {return m_fltHeight;}
101 
102 void Cone::Height(float fltVal, bool bUseScaling)
103 {
104  Std_IsAboveMin((float) 0, fltVal, true, "Cone.Height");
105  if(bUseScaling)
107  else
108  m_fltHeight = fltVal;
109 
110  Resize();
111 }
112 
121 void Cone::Sides(int iVal)
122 {
123  Std_IsAboveMin((int) 10, iVal, true, "Cone.Sides", true);
124  m_iSides = iVal;
125 
126  Resize();
127 }
128 
137 int Cone::Sides() {return m_iSides;}
138 
139 bool Cone::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
140 {
141  std::string strType = Std_CheckString(strDataType);
142 
143  if(RigidBody::SetData(strType, strValue, false))
144  return true;
145 
146  if(strType == "LOWERRADIUS")
147  {
148  LowerRadius((float) atof(strValue.c_str()));
149  return true;
150  }
151 
152  if(strType == "UPPERRADIUS")
153  {
154  UpperRadius((float) atof(strValue.c_str()));
155  return true;
156  }
157 
158  if(strType == "HEIGHT")
159  {
160  Height((float) atof(strValue.c_str()));
161  return true;
162  }
163 
164  if(strType == "SIDES")
165  {
166  Sides(atoi(strValue.c_str()));
167  return true;
168  }
169 
170  //If it was not one of those above then we have a problem.
171  if(bThrowError)
172  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
173 
174  return false;
175 }
176 
177 void Cone::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
178 {
179  RigidBody::QueryProperties(aryProperties);
180 
181  aryProperties.Add(new TypeProperty("LowerRadius", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
182  aryProperties.Add(new TypeProperty("UpperRadius", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
183  aryProperties.Add(new TypeProperty("Height", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
184  aryProperties.Add(new TypeProperty("Sides", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
185 }
186 
187 void Cone::Load(CStdXml &oXml)
188 {
189  RigidBody::Load(oXml);
190 
191  oXml.IntoElem(); //Into RigidBody Element
192 
193  LowerRadius(oXml.GetChildFloat("LowerRadius", m_fltLowerRadius));
194  UpperRadius(oXml.GetChildFloat("UpperRadius", m_fltUpperRadius));
195  Height(oXml.GetChildFloat("Height"), m_fltHeight);
196  Sides(oXml.GetChildInt("Sides", m_iSides));
197 
198  oXml.OutOfElem(); //OutOf RigidBody Element
199 }
200 
201 
202  } //Bodies
203  } //Environment
204 } //AnimatSim
Base class file for all Animat simulation objects.
Declares the simulation recorder class.
float m_fltLowerRadius
The lower radius of the cone.
Definition: Cone.h:28
virtual int Sides()
Gets the number of sides used to draw the cone.
Definition: Cone.cpp:137
Root namespace for the base simulation library for AnimatLab.
Declares the body part class.
int m_iSides
The number of sides used to draw the cone.
Definition: Cone.h:37
Cone()
Default constructor.
Definition: Cone.cpp:48
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
virtual float Height()
Gets the height.
Definition: Cone.cpp:100
Declares the key frame 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.
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.
virtual float LowerRadius()
Gets the lower radius.
Definition: Cone.cpp:67
A standard xml manipulation class.
Definition: StdXml.h:19
Declares the cone class.
Declares the node class.
float m_fltHeight
The height of the cone.
Definition: Cone.h:34
virtual ~Cone()
Destructor.
Definition: Cone.cpp:62
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.
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.
float m_fltUpperRadius
The upper radius of the cone.
Definition: Cone.h:31
Declares the contact sensor class.
Declares the external stimuli manager class.
virtual float UpperRadius()
Gets the upper radius.
Definition: Cone.cpp:83
Declares the receptive field class.
std::string m_strName
The name for this object.
Definition: AnimatBase.h:61
virtual float GetChildFloat(std::string strElementName)
Gets a float value from the element with the specified name.
Definition: StdXml.cpp:617