AnimatLab  2
Test
DataChartMgr.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 "DataColumn.h"
32 #include "DataChart.h"
33 #include "DataChartMgr.h"
34 #include "ExternalStimuliMgr.h"
35 #include "KeyFrame.h"
36 #include "SimulationRecorder.h"
37 #include "OdorType.h"
38 #include "Odor.h"
39 #include "Light.h"
40 #include "LightManager.h"
41 #include "Simulator.h"
42 
43 namespace AnimatSim
44 {
45  namespace Charting
46  {
54 {}
55 
63 {}
64 
77 DataColumn *DataChartMgr::FindDataColumn(std::string strChartKey, std::string strColumnName, bool bThrowError)
78 {
79  DataChart *lpChart = dynamic_cast<DataChart *>(Find(strChartKey, bThrowError));
80  if(!lpChart) return NULL;
81 
82  DataColumn *lpColumn = lpChart->FindColumn(strColumnName, bThrowError);
83  return lpColumn;
84 }
85 
96 void DataChartMgr::RemoveDataColumn(std::string strChartKey, std::string strColumnName, bool bThrowError)
97 {
98  DataChart *lpChart = dynamic_cast<DataChart *>(Find(strChartKey, bThrowError));
99  if(!lpChart) return;
100 
101  lpChart->RemoveColumn(strColumnName, bThrowError);
102 }
103 
113 void DataChartMgr::AddDataColumn(std::string strChartKey, DataColumn *lpColumn)
114 {
115  DataChart *lpChart = dynamic_cast<DataChart *>(Find(strChartKey));
116  lpChart->AddColumn(lpColumn);
117 }
118 
131 bool DataChartMgr::AddDataChart(std::string strXml)
132 {
133  CStdXml oXml;
134  oXml.Deserialize(strXml);
135  oXml.FindElement("Root");
136  oXml.FindChildElement("DataChart");
137  LoadDataChart(oXml);
138  ReInitialize();
139  return true;
140 }
141 
152 bool DataChartMgr::RemoveDataChart(std::string strID)
153 {
154  Remove(strID);
155  ReInitialize();
156  return true;
157 }
158 
159 void DataChartMgr::Load(CStdXml &oXml)
160 {
162 
163  Reset();
164 
165  if(oXml.FindChildElement("DataCharts", false))
166  {
167  oXml.IntoElem(); //Into DataCharts Element
168 
169  int iCount = oXml.NumberOfChildren();
170  for(int iIndex=0; iIndex<iCount; iIndex++)
171  {
172  oXml.FindChildByIndex(iIndex);
173  LoadDataChart(oXml);
174  }
175 
176  oXml.OutOfElem(); //OutOf Environment Element
177  }
178 }
179 
192 {
193  DataChart *lpChart = NULL;
194  std::string strModuleName, strType, strFilename;
195 
196 try
197 {
198  oXml.IntoElem(); //Into DataChart Element
199  strModuleName = oXml.GetChildString("ModuleName", "");
200  strType = oXml.GetChildString("Type");
201  strFilename = oXml.GetChildString("Filename", "");
202  oXml.OutOfElem(); //OutOf DataChart Element
203 
204  lpChart = dynamic_cast<DataChart *>(m_lpSim->CreateObject(strModuleName, "DataChart", strType));
205  if(!lpChart)
206  THROW_TEXT_ERROR(Al_Err_lConvertingClassToType, Al_Err_strConvertingClassToType, "DataChart");
207 
208  lpChart->SetSystemPointers(m_lpSim, NULL, NULL, NULL, true);
209  if(!Std_IsBlank(strFilename))
210  lpChart->Load(m_lpSim->ProjectPath(), strFilename);
211  else
212  {
213  lpChart->ProjectPath(m_lpSim->ProjectPath());
214  lpChart->Load(oXml);
215  }
216 
217  Add(lpChart);
218  return lpChart;
219 }
220 catch(CStdErrorInfo oError)
221 {
222  if(lpChart) delete lpChart;
223  RELAY_ERROR(oError);
224  return NULL;
225 }
226 catch(...)
227 {
228  if(lpChart) delete lpChart;
229  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
230  return NULL;
231 }
232 }
233 
234  } //Charting
235 } //AnimatSim
236 
virtual void ReInitialize()
Re-initialize this object.
virtual void Deserialize(std::string &strXml)
Deserializes a string into an xml document.
Definition: StdXml.cpp:162
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
virtual void RemoveDataColumn(std::string strChartKey, std::string strColumnName, bool bThrowError=true)
Removes the specified data column.
Root namespace for the base simulation library for AnimatLab.
Declares the body part class.
virtual DataColumn * FindDataColumn(std::string strChartKey, std::string strColumnName, bool bThrowError=true)
Searches for a DataColumn with the specified column name.
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
DataChart * LoadDataChart(CStdXml &oXml)
Loads a data chart.
Data column class.
Definition: DataColumn.h:24
virtual void RemoveColumn(std::string strID, bool bThrowError=true)
Removes the column with the specified ID.
Definition: DataChart.cpp:619
Declares the key frame class.
Declares the joint class.
Declares the organism class.
Data chart base class.
Definition: DataChart.h:31
Declares a light object.
virtual ~DataChartMgr()
Destructor.
virtual bool AddDataChart(std::string strXml)
Adds a data chart to the manager.
Declares the activated item class.
Declares the data column class.
virtual void Load(std::string strProjectPath, std::string strConfigFile)
Loads a data chart from a file.
Definition: DataChart.cpp:867
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.
virtual DataColumn * FindColumn(std::string strID, int &iIndex, bool bThrowError)
Searches for a column that matches the specified ID.
Definition: DataChart.cpp:666
A standard xml manipulation class.
Definition: StdXml.h:19
virtual void Reset()
Resets this manager.
Declares the node class.
DataChartMgr()
Default constructor.
virtual std::string ProjectPath()
Gets the project path.
Definition: Simulator.cpp:287
virtual bool RemoveDataChart(std::string strID)
Removes the data chart described by ID.
virtual std::string GetChildString(std::string strElementName)
Gets a string value from the element with the specified name.
Definition: StdXml.cpp:307
virtual void AddDataColumn(std::string strChartKey, DataColumn *lpColumn)
Adds a data column to the specified chart.
virtual ActivatedItem * Find(std::string strID, int &iIndex, bool bThrowError)
Searches for an item with the specified ID and sets its index in the array.
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 class.
bool Std_IsBlank(std::string strVal)
Trims a string and tests if a string is blank.
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 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 std::string ProjectPath()
Gets the project path.
Definition: DataChart.cpp:346
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.
virtual void AddColumn(DataColumn *lpColumn)
Adds a column.
Definition: DataChart.cpp:594
Declares the receptive field class.
virtual void Add(ActivatedItem *lpItem)
Adds a new ActivatedItem to be managed.