AnimatLab  2
Test
BodyPart.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 "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  {
47 {
48  m_lpPhysicsBody = NULL;
49  m_bSynchWithRobot = false;
52  m_iSynchCount = 0;
53 }
54 
62 {
63 
64 try
65 {
66  m_aryRobotParts.RemoveAll();
67 }
68 catch(...)
69 {Std_TraceMsg(0, "Caught Error in desctructor of BodyPart\r\n", "", -1, false, true);}
70 }
71 
72 #pragma region AccessorMutators
73 
81 {
83  m_lpPhysicsMovableItem->Physics_CollectData();
84 }
85 
99 {
101  m_lpPhysicsMovableItem->Physics_CollectExtraData();
102 }
103 
104 
116 
128 {
129  m_lpPhysicsBody = lpBody;
130 }
131 
142 {
144  m_lpPhysicsMovableItem->Physics_Resize();
145 
146  if(m_lpCallback)
148 }
149 
163 
173 
185 
195 {
196  Std_IsAboveMin((float) 0, fltVal, true, "SynchUpdateInterval", true);
197  m_fltSynchUpdateInterval = fltVal;
198 
199  if(m_lpSim)
200  {
201  float fltTimeStep = m_lpSim->PhysicsTimeStep();
202 
203  if(fltTimeStep > 0)
204  m_iSynchUpdateInterval = (int) ((m_fltSynchUpdateInterval/fltTimeStep) + 0.5);
205  else
207  }
208 }
209 
210 #pragma endregion
211 
212 void BodyPart::Selected(bool bValue, bool bSelectMultiple)
213 {
214  Node::Selected(bValue, bSelectMultiple);
215  MovableItem::Selected(bValue, bSelectMultiple);
216 }
217 
231 {
234 }
235 
236 void BodyPart::AddBodyClicked(float fltPosX, float fltPosY, float fltPosZ, float fltNormX, float fltNormY, float fltNormZ)
237 {
238  if(m_lpCallback)
239  m_lpCallback->AddBodyClicked(fltPosX, fltPosY, fltPosZ, fltNormX, fltNormY, fltNormZ);
240 }
241 
242 void BodyPart::WakeDynamics()
243 {
244  if(m_lpPhysicsBody)
245  m_lpPhysicsBody->Physics_WakeDynamics();
246 }
247 
248 #pragma region DataAccesMethods
249 
250 void BodyPart::SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
251 {
252  Node::SetSystemPointers(lpSim, lpStructure, lpModule, lpNode, bVerify);
253  m_lpMovableSim = lpSim;
254 }
255 
256 float *BodyPart::GetDataPointer(const std::string &strDataType)
257 {
258  return MovableItem::GetDataPointer(strDataType);
259 }
260 
261 bool BodyPart::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
262 {
263  if(Node::SetData(strDataType, strValue, false))
264  return true;
265 
266  if(MovableItem::SetData(strDataType, strValue, false))
267  return true;
268 
269  std::string strType = Std_CheckString(strDataType);
270 
271  if(strType == "SYNCHWITHROBOT")
272  {
273  SynchWithRobot(Std_ToBool(strValue));
274  return true;
275  }
276 
277  if(strType == "SYNCHUPDATEINTERVAL")
278  {
279  SynchUpdateInterval(atof(strValue.c_str()));
280  return true;
281  }
282 
283  //If it was not one of those above then we have a problem.
284  if(bThrowError)
285  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
286 
287  return false;
288 }
289 
290 void BodyPart::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
291 {
292  Node::QueryProperties(aryProperties);
293  MovableItem::QueryProperties(aryProperties);
294  aryProperties.Add(new TypeProperty("SynchWithRobot", AnimatPropertyType::Boolean, AnimatPropertyDirection::Set));
295  aryProperties.Add(new TypeProperty("SynchUpdateInterval", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
296 }
297 
304 CStdArray<RobotPartInterface *> *BodyPart::GetRobotPartInterfaces() {return &m_aryRobotParts;};
305 
314 void BodyPart::AddRobotPartInterface(RobotPartInterface *lpPart)
315 {
316  if(FindRobotPartListIndex(lpPart->ID(), false) == -1)
317  m_aryRobotParts.Add(lpPart);
318 };
319 
328 void BodyPart::RemoveRobotPartInterface(RobotPartInterface *lpPart)
329 {
330  int iIdx = FindRobotPartListIndex(lpPart->ID(), false);
331  if(iIdx >= 0)
332  m_aryRobotParts.RemoveAt(iIdx);
333 };
334 
344 int BodyPart::FindRobotPartListIndex(std::string strID, bool bThrowError)
345 {
346  int iCount = m_aryRobotParts.GetSize();
347  for(int iIdx=0; iIdx<iCount; iIdx++)
348  if(m_aryRobotParts[iIdx]->ID() == strID)
349  return iIdx;
350 
351  if(bThrowError)
352  THROW_PARAM_ERROR(Al_Err_lPartInterfaceIDNotFound, Al_Err_strPartInterfaceIDNotFound, "ID", strID);
353 
354  return -1;
355 }
356 
357 #pragma endregion
358 
370 {
373 }
374 
375 bool BodyPart::NeedsRobotSynch()
376 {
378  return true;
379 
380  bool bRet = false;
381 
383  {
384  m_iSynchCount = 0;
385  bRet = true;
386  }
387  else
388  m_iSynchCount++;
389 
390  return bRet;
391 }
392 
394 {
396 
397  m_iSynchCount = 0;
398 }
399 
401 {
404 }
405 
417 {
418 }
419 
420 void BodyPart::Load(CStdXml &oXml)
421 {
422  Node::Load(oXml);
423  MovableItem::Load(oXml);
424 
425  oXml.IntoElem(); //Into BodyPart Element
426 
427  SynchWithRobot(oXml.GetChildBool("SynchWithRobot", m_bSynchWithRobot));
428  SynchUpdateInterval(oXml.GetChildFloat("SynchUpdateInterval", m_fltSynchUpdateInterval));
429 
430  oXml.OutOfElem(); //OutOf BodyPart Element
431 }
432 
433  } //Environment
434 } //AnimatSim
virtual void SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
Sets the system pointers.
IPhysicsBody * m_lpPhysicsBody
Definition: BodyPart.h:31
Base class file for all Animat simulation objects.
virtual void PhysicsTimeStep(float fltVal)
Sets the integration time step for the physics engine.
Definition: Simulator.cpp:1126
virtual void Initialize()
Initializes this object.
Definition: BodyPart.cpp:400
Declares the simulation recorder class.
Simulates the entire environment.
Definition: Simulator.h:31
virtual void AddBodyClicked(float fltPosX, float fltPosY, float fltPosZ, float fltNormX, float fltNormY, float fltNormZ)=0
Called to signal to the GUI that a part was clicked while AddBody mode was active.
Simulator * m_lpMovableSim
The pointer to a Simulation.
Definition: MovableItem.h:23
virtual bool InSimulation()
Used to determine if we are running in a simulation, or in a real control mode.
Definition: Simulator.cpp:1673
Root namespace for the base simulation library for AnimatLab.
virtual void ResetSimulation()
Resets the simulation back to time 0.
Definition: BodyPart.cpp:393
virtual void UpdateData()
Called to collect any body data for this part.
Definition: BodyPart.cpp:80
Declares the body part class.
float m_fltSynchUpdateInterval
This is how often we need to update this particular adapter.
Definition: BodyPart.h:42
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
virtual std::string ID()
Gets the unique GUID ID of this object.
Definition: AnimatBase.cpp:167
virtual bool IntoElem()
Goes into the next element where the cursor is located.
Definition: StdXml.cpp:42
int m_iSynchCount
Keeps track of the last time we did a synch for the robot.
Definition: BodyPart.h:48
CStdArray< RobotPartInterface * > m_aryRobotParts
Array of pointers to robot part interfaces connected to this body part.
Definition: BodyPart.h:34
virtual void UpdatePhysicsPosFromGraphics()
Updates the physics position from graphics.
Definition: BodyPart.cpp:416
Class that stores information about types for QueryProperty information.
Definition: TypeProperty.h:35
IMovableItemCallback * m_lpCallback
Definition: MovableItem.h:98
virtual void TimeStepModified()
Notification method that the time step modified has been modified. Objects should recalculate any sli...
Definition: AnimatBase.cpp:685
virtual void Initialize()
Initializes this object.
Definition: AnimatBase.cpp:573
Declares the key frame class.
virtual float SynchUpdateInterval()
This is how often we need to update this particular adapter.
Definition: BodyPart.cpp:184
virtual void AddBodyClicked(float fltPosX, float fltPosY, float fltPosZ, float fltNormX, float fltNormY, float fltNormZ)
Called when the user clicks on this object while the AddBody mode is active.
Definition: BodyPart.cpp:236
BodyPart(void)
Default constructor.
Definition: BodyPart.cpp:46
Declares the joint class.
Declares the organism class.
bool Std_IsAboveMin(int iMinVal, int iVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
Tests if a number is above a minimum value.
virtual void SizeChanged()=0
Called to signal to the GUI that the size of the body part changed.
Declares a light object.
virtual void Resize()
Called when this object has been resized.
Definition: BodyPart.cpp:141
Declares the activated item class.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Definition: Node.cpp:199
Declares a light manager object.
virtual bool RobotAdpaterSynch()
Gets whether we need to synch the physics adapters in a simulation to the robot physics time step...
Definition: Simulator.cpp:1645
IPhysicsMovableItem * m_lpPhysicsMovableItem
Definition: MovableItem.h:103
Declares the bounding box class.
int m_iSynchUpdateInterval
The number of ticks between each call to update for this adapter till the next update time...
Definition: BodyPart.h:45
A standard xml manipulation class.
Definition: StdXml.h:19
virtual ~BodyPart(void)
Destructor.
Definition: BodyPart.cpp:61
virtual void UpdateExtraData()
UpdateData is called during this body parts sim update call, and before any of its child updates beca...
Definition: BodyPart.cpp:98
virtual bool Selected()
Tells if this items is selected or not.
Definition: AnimatBase.cpp:248
A "static" structure in the simulation.
Definition: Structure.h:84
Declares the node class.
virtual bool SynchWithRobot()
Gets whether the m_bRobotAdpaterSynch flag applies to this adapter.
Definition: BodyPart.cpp:162
virtual IPhysicsBody * PhysicsBody()
Gets the physics body interface pointer. This is an interface reference to the Vs version of this obj...
Definition: BodyPart.cpp:115
bool Std_ToBool(int iVal)
Converts a value toa bool.
virtual void Load(StdUtils::CStdXml &oXml)
Loads the item using an XML data packet.
Definition: AnimatBase.cpp:771
void Std_TraceMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bLogToFile, bool bPrintHeader)
Traces a message to the debugger window.
virtual bool GetChildBool(std::string strElementName)
Gets a bool value from the element with the specified name.
Definition: StdXml.cpp:699
virtual void VisualSelectionModeChanged(int iNewMode)
Called when the visual selection mode changed in GUI.
Base class for body parts and neural network nodes.
Definition: Node.h:25
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
virtual int FindRobotPartListIndex(std::string strID, bool bThrowError=true)
Finds the index of a robot part attached to this body part with the matching ID.
Definition: BodyPart.cpp:344
Declares the data chart manager class.
virtual void ResetSimulation()
Resets the simulation back to time 0.
Definition: Node.cpp:106
Declares the rigid body class.
virtual void TimeStepModified()
If the time step is modified then we need to recalculate the length of the delay buffer.
Definition: BodyPart.cpp:369
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
Declares the structure class.
virtual void VisualSelectionModeChanged(int iNewMode)
Visual selection mode changed.
Definition: AnimatBase.cpp:754
Declares the odor type class.
virtual void VisualSelectionModeChanged(int iNewMode)
Called when the visual selection mode changed in GUI.
Definition: BodyPart.cpp:230
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.
virtual CStdArray< RobotPartInterface * > * GetRobotPartInterfaces()
Gets a pointer to the roboto part interface associated with this body part.
Definition: BodyPart.cpp:304
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
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
Definition: Node.cpp:179