AnimatLab  2
Test
SimulationRecorder.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 "Gain.h"
13 #include "Node.h"
14 #include "Link.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 "Sensor.h"
25 #include "Structure.h"
26 #include "NeuralModule.h"
27 #include "Adapter.h"
28 #include "NervousSystem.h"
29 #include "Organism.h"
30 #include "ActivatedItem.h"
31 #include "ActivatedItemMgr.h"
32 #include "DataChartMgr.h"
33 #include "ExternalStimuliMgr.h"
34 #include "KeyFrame.h"
35 #include "SimulationRecorder.h"
36 #include "OdorType.h"
37 #include "Odor.h"
38 #include "Light.h"
39 #include "LightManager.h"
40 #include "Simulator.h"
41 
42 namespace AnimatSim
43 {
44  namespace Recording
45  {
53 {}
54 
62 {}
63 
64 
66 {
67  //Lets make sure that there are no other frames that already exist that overlap with
68  //this frame that are the same type.
69  int iCount = m_aryItems.GetSize();
70  ActivatedItem *lpTest = NULL;
71  for(int iIndex=0; iIndex<iCount; iIndex++)
72  {
73  lpTest = m_aryItems[iIndex];
74 
75  if(lpTest->Overlaps(lpItem))
76  THROW_PARAM_ERROR(Al_Err_lKeyFrameOverlap, Al_Err_strKeyFrameOverlap, "Overlap Frame ID", lpTest->ID());
77  }
78 
79  ActivatedItemMgr::Add(lpItem);
80 }
81 
94 KeyFrame *SimulationRecorder::Add(std::string strType, long lStart, long lEnd)
95 {
96  KeyFrame *lpFrame = NULL;
97 
98 try
99 {
100  lpFrame = dynamic_cast<KeyFrame *>(m_lpSim->CreateObject("AnimatLab", "KeyFrame", strType));
101  if(!lpFrame)
102  THROW_TEXT_ERROR(Al_Err_lConvertingClassToType, Al_Err_strConvertingClassToType, "KeyFrame");
103 
104  lpFrame->EndSlice(lEnd);
105  lpFrame->StartSlice(lStart);
106  lpFrame->GenerateID();
107 
108  Add(lpFrame);
109 
110  lpFrame->Initialize();
111 
112  return lpFrame;
113 }
114 catch(CStdErrorInfo oError)
115 {
116  if(lpFrame) delete lpFrame;
117  RELAY_ERROR(oError);
118  return NULL;
119 }
120 catch(...)
121 {
122  if(lpFrame) delete lpFrame;
123  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
124  return NULL;
125 }
126 }
127 
128 void SimulationRecorder::Load(CStdXml &oXml)
129 {
131 
132  Reset();
133 
134  if(oXml.FindChildElement("KeyFrames", false))
135  {
136  oXml.IntoElem(); //Into KeyFrames Element
137 
138  int iCount = oXml.NumberOfChildren();
139  for(int iIndex=0; iIndex<iCount; iIndex++)
140  {
141  oXml.FindChildByIndex(iIndex);
142  LoadKeyFrame(oXml);
143  }
144 
145  oXml.OutOfElem(); //OutOf KeyFrames Element
146  }
147 }
148 
160 {
161  KeyFrame *lpFrame = NULL;
162  std::string strModuleName, strType;
163 
164 try
165 {
166  oXml.IntoElem(); //Into KeyFrame Element
167  strModuleName = oXml.GetChildString("ModuleName", "");
168  strType = oXml.GetChildString("Type");
169  oXml.OutOfElem(); //OutOf KeyFrame Element
170 
171  lpFrame = dynamic_cast<KeyFrame *>(m_lpSim->CreateObject(strModuleName, "KeyFrame", strType));
172  if(!lpFrame)
173  THROW_TEXT_ERROR(Al_Err_lConvertingClassToType, Al_Err_strConvertingClassToType, "KeyFrame");
174 
175  lpFrame->SetSystemPointers(m_lpSim, NULL, NULL, NULL, true);
176  lpFrame->Load(oXml);
177 
178  Add(lpFrame);
179  return lpFrame;
180 }
181 catch(CStdErrorInfo oError)
182 {
183  if(lpFrame) delete lpFrame;
184  RELAY_ERROR(oError);
185  return NULL;
186 }
187 catch(...)
188 {
189  if(lpFrame) delete lpFrame;
190  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
191  return NULL;
192 }
193 }
194 
195  } //Recording
196 } //AnimatSim
Base class file for all Animat simulation objects.
Declares the nervous system class.
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 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
Declares the key frame class.
KeyFrame * LoadKeyFrame(CStdXml &oXml)
Loads a new key frame.
Base class for all activated items.
Definition: ActivatedItem.h:27
Declares the joint class.
Declares the organism class.
virtual bool Overlaps(ActivatedItem *lpItem)
Query if this object overlaps the time period for another ActivatedItem.
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 long StartSlice()
Returns the starts slice for activation.
Declares the gain base class.
A standard xml manipulation class.
Definition: StdXml.h:19
virtual void Reset()
Resets this manager.
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
CStdArray< ActivatedItem * > m_aryItems
virtual int NumberOfChildren()
Gets the number of children of the current element.
Definition: StdXml.cpp:202
virtual long EndSlice()
Gets the end time slice for deactivation.
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
Declares the sensor class.
Declares the data chart manager class.
Declares the rigid body class.
virtual void GenerateID()
Generates an identifier.
Definition: KeyFrame.cpp:117
Declares the structure class.
Declares the odor type class.
virtual void Add(ActivatedItem *lpItem)
Adds a new ActivatedItem to be managed.
virtual void Initialize()
Initializes this object.
virtual void VerifySystemPointers()
Verify that system pointers have been set correctly.
Definition: AnimatBase.cpp:315
Declares the odor class.
Declares the simulator class.
Declares the neural module 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.
virtual void Add(ActivatedItem *lpItem)
Adds a new ActivatedItem to be managed.