AnimatLab  2
Test
Hud.cpp
1 
7 #include "StdAfx.h"
8 #include "IMovableItemCallback.h"
9 #include "ISimGUICallback.h"
10 #include "AnimatBase.h"
11 #include "HudItem.h"
12 #include "Hud.h"
13 
14 #include "Node.h"
15 #include "IPhysicsMovableItem.h"
16 #include "IPhysicsBody.h"
17 #include "BoundingBox.h"
18 #include "MovableItem.h"
19 #include "BodyPart.h"
20 #include "Joint.h"
21 #include "ReceptiveField.h"
22 #include "ContactSensor.h"
23 #include "RigidBody.h"
24 #include "Structure.h"
25 #include "Organism.h"
26 #include "ActivatedItem.h"
27 #include "ActivatedItemMgr.h"
28 #include "DataChartMgr.h"
29 #include "ExternalStimuliMgr.h"
30 #include "KeyFrame.h"
31 #include "SimulationRecorder.h"
32 #include "OdorType.h"
33 #include "Odor.h"
34 #include "Light.h"
35 #include "LightManager.h"
36 #include "Simulator.h"
37 
38 namespace AnimatSim
39 {
40 
48 {
49 }
50 
58 {
59 
60 try
61 {
62  m_aryHudItems.RemoveAll();
63 }
64 catch(...)
65 {Std_TraceMsg(0, "Caught Error in desctructor of Hud\r\n", "", -1, false, true);}
66 }
67 
68 void Hud::Reset()
69 {
70  m_aryHudItems.RemoveAll();
71 }
72 
74 {
75  int iCount = m_aryHudItems.GetSize();
76  for(int iIndex = 0; iIndex < iCount; iIndex++)
77  m_aryHudItems[iIndex]->ResetSimulation();
78 }
79 
80 void Hud::Update()
81 {
82  HudItem *lpItem = NULL;
83  int iCount = m_aryHudItems.GetSize();
84  for(int iIndex = 0; iIndex < iCount; iIndex++)
85  {
86  lpItem = m_aryHudItems[iIndex];
87  lpItem->Update();
88  }
89 }
90 
91 void Hud::Load(CStdXml &oXml)
92 {
93  AnimatBase::Load(oXml);
94 
95  m_aryHudItems.RemoveAll();
96 
97  oXml.IntoElem(); //Into Hud Element
98 
99  if(oXml.FindChildElement("HudItems", false))
100  {
101  //*** Begin Loading HudItems. *****
102  oXml.IntoChildElement("HudItems");
103 
104  int iCount = oXml.NumberOfChildren();
105  HudItem *lpItem = NULL;
106  for(int iIndex=0; iIndex<iCount; iIndex++)
107  {
108  oXml.FindChildByIndex(iIndex);
109  lpItem = LoadHudItem(oXml);
110  m_aryHudItems.Add(lpItem);
111  }
112 
113  oXml.OutOfElem();
114  //*** End Loading HudItems. *****
115  }
116 
117  oXml.OutOfElem(); //Outof Hud Element
118 }
119 
120 HudItem *Hud::LoadHudItem(CStdXml &oXml)
121 {
122  HudItem *lpItem=NULL;
123  std::string strModuleName, strType;
124 
125 try
126 {
127  oXml.IntoElem(); //Into Column Element
128  strModuleName = oXml.GetChildString("ModuleName", "");
129  strType = oXml.GetChildString("Type");
130  oXml.OutOfElem(); //OutOf Column Element
131 
132  lpItem = dynamic_cast<HudItem *>(m_lpSim->CreateObject(strModuleName, "HudItem", strType));
133  if(!lpItem)
134  THROW_TEXT_ERROR(Al_Err_lConvertingClassToType, Al_Err_strConvertingClassToType, "HudItem");
135 
136  lpItem->SetSystemPointers(m_lpSim, NULL, NULL, NULL, true);
137  lpItem->Load(oXml);
138 
139  return lpItem;
140 }
141 catch(CStdErrorInfo oError)
142 {
143  if(lpItem) delete lpItem;
144  RELAY_ERROR(oError);
145  return NULL;
146 }
147 catch(...)
148 {
149  if(lpItem) delete lpItem;
150  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
151  return NULL;
152 }
153 }
154 
155 
156 } //AnimatSim
virtual void ResetSimulation()
Resets the simulation back to time 0.
Definition: Hud.cpp:73
Base class file for all Animat simulation objects.
Declares the simulation recorder class.
virtual void SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
Sets the system pointers.
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.
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
Information about the standard error.
Definition: StdErrorInfo.h:19
virtual bool IntoElem()
Goes into the next element where the cursor is located.
Definition: StdXml.cpp:42
Declares the key frame class.
Declares the joint class.
Declares the organism class.
Declares a light object.
Declares the activated item class.
virtual CStdSerialize * CreateObject(std::string strModule, std::string strClassName, std::string strType, bool bThrowError=true)
Creates an object using a class factory.
Definition: Simulator.cpp:3440
Declares a light manager object.
Declares the bounding box class.
virtual ~Hud()
Destructor.
Definition: Hud.cpp:57
virtual void Reset()
Resets this object.
Definition: Hud.cpp:68
A standard xml manipulation class.
Definition: StdXml.h:19
Declares the node class.
virtual std::string GetChildString(std::string strElementName)
Gets a string value from the element with the specified name.
Definition: StdXml.cpp:307
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 int NumberOfChildren()
Gets the number of children of the current element.
Definition: StdXml.cpp:202
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
Hud()
Default constructor.
Definition: Hud.cpp:47
Declares the data chart manager class.
Declares the rigid body class.
virtual bool IntoChildElement(std::string strElementName, bool bThrowError=true)
Goes into the child element with the specified name.
Definition: StdXml.cpp:278
Declares the structure class.
Declares the odor type class.
Declares the odor class.
Declares the simulator class.
virtual bool FindChildByIndex(int iIndex, bool bThrowError=true)
Finds a child element by index.
Definition: StdXml.cpp:225
Declares the activated item manager class.
Declares the contact sensor class.
Declares the external stimuli manager class.
Declares the receptive field class.