AnimatLab  2
Test
ExternalStimuliMgr.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 "Structure.h"
25 #include "NeuralModule.h"
26 #include "Adapter.h"
27 #include "NervousSystem.h"
28 #include "Organism.h"
29 #include "ActivatedItem.h"
30 #include "ActivatedItemMgr.h"
31 #include "DataChartMgr.h"
32 #include "ExternalStimulus.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 ExternalStimuli
45  {
53 {
54 
55 }
56 
64 {
65 
66 }
67 
80 bool ExternalStimuliMgr::AddStimulus(std::string strXml)
81 {
82  CStdXml oXml;
83  oXml.Deserialize(strXml);
84  oXml.FindElement("Root");
85  oXml.FindChildElement("Stimulus");
86  ExternalStimulus *lpStim = LoadExternalStimuli(oXml);
87  lpStim->Initialize();
88 
89  return true;
90 }
91 
102 bool ExternalStimuliMgr::RemoveStimulus(std::string strID)
103 {
104  Remove(strID);
105  return true;
106 }
107 /*
108 void ExternalStimuliMgr::Load(std::string strProjectPath, std::string strFileName)
109 {
110  CStdXml oXml;
111 
112  TRACE_DEBUG("Loading external stimuli config file.\r\n" + strProjectPath + "\r\nFileName: " + strFileName);
113 
114  oXml.Load(AnimatSim::GetFilePath(strProjectPath, strFileName));
115 
116  oXml.FindElement("StimuliConfiguration");
117  oXml.FindChildElement("");
118 
119  Load(oXml);
120 
121  TRACE_DEBUG("Finished loading external stimuli config file.");
122 }
123 */
124 
125 void ExternalStimuliMgr::Load(CStdXml &oXml)
126 {
128 
129  Reset();
130 
131  if(oXml.FindChildElement("ExternalStimuli", false))
132  {
133  oXml.IntoElem(); //Into ExternalStimuli Element
134 
135  int iCount = oXml.NumberOfChildren();
136  for(int iIndex=0; iIndex<iCount; iIndex++)
137  {
138  oXml.FindChildByIndex(iIndex);
139  LoadExternalStimuli(oXml);
140  }
141 
142  oXml.OutOfElem(); //OutOf ExternalStimuli Element
143  }
144 }
145 
158 {
159  ExternalStimulus *lpStimulus = NULL;
160  std::string strModuleName, strType, strFilename;
161 
162 try
163 {
164  oXml.IntoElem(); //Into Stimulus Element
165  strModuleName = oXml.GetChildString("ModuleName", "");
166  strType = oXml.GetChildString("Type");
167  oXml.OutOfElem(); //OutOf Stimulus Element
168 
169  lpStimulus = dynamic_cast<ExternalStimulus *>(m_lpSim->CreateObject(strModuleName, "ExternalStimulus", strType));
170  if(!lpStimulus)
171  THROW_TEXT_ERROR(Al_Err_lConvertingClassToType, Al_Err_strConvertingClassToType, "ExternalStimulus");
172 
173  lpStimulus->SetSystemPointers(m_lpSim, NULL, NULL, NULL, true);
174  lpStimulus->Load(oXml);
175 
176  Add(lpStimulus);
177  return lpStimulus;
178 }
179 catch(CStdErrorInfo oError)
180 {
181  if(lpStimulus) delete lpStimulus;
182  RELAY_ERROR(oError);
183  return NULL;
184 }
185 catch(...)
186 {
187  if(lpStimulus) delete lpStimulus;
188  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
189  return NULL;
190 }
191 }
192 
193  } //ExternalStimuli
194 } //AnimatSim
195 
virtual void Deserialize(std::string &strXml)
Deserializes a string into an xml document.
Definition: StdXml.cpp:162
Declares the external stimulus base class.
Base class file for all Animat simulation objects.
Declares the nervous system class.
ExternalStimulus * LoadExternalStimuli(CStdXml &oXml)
Loads an external stimuli.
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.
virtual bool AddStimulus(std::string strXml)
Creates a new stimulus from an xml definition and adds it to the manager.
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
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
virtual bool RemoveStimulus(std::string strID)
Removes the stimulus described by strID.
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.
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
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
Declares the data chart manager class.
Declares the rigid body class.
virtual void Remove(std::string strID, bool bThrowError=true)
Removes the item with the specified ID.
Declares the structure class.
Declares the odor type class.
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.