AnimatLab  2
Test
DataColumn.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 "DataColumn.h"
27 #include "DataChart.h"
28 #include "DataChartMgr.h"
29 #include "ExternalStimuliMgr.h"
30 #include "KeyFrame.h"
31 #include "SimulationRecorder.h"
32 #include "KeyFrame.h"
33 #include "OdorType.h"
34 #include "Odor.h"
35 #include "Light.h"
36 #include "LightManager.h"
37 #include "Simulator.h"
38 
39 namespace AnimatSim
40 {
41  namespace Charting
42  {
50 {
51  m_lpDataValue = NULL;
52  m_iAppendSpaces = 0;
53  m_bInitialized = false;
54  m_iColumnIndex = -1;
55  m_iRowIndex = -1;
56 }
57 
65 {
66  //Do not delete this pointer. It is just a reference.
67  m_lpDataValue = NULL;
68 }
69 
79 {return 1;}
80 
81 void DataColumn::Name(std::string strValue)
82 {
83  if(Std_IsBlank(strValue))
84  THROW_TEXT_ERROR(Std_Err_lBlankAttrib, Std_Err_strBlankAttrib, "Attribute: ColumnName");
85  m_strName = strValue;
86 }
87 
96 std::string DataColumn::DataType() {return m_strDataType;}
97 
106 void DataColumn::DataType(std::string strType)
107 {
108  if(Std_IsBlank(strType))
109  THROW_TEXT_ERROR(Std_Err_lBlankAttrib, Std_Err_strBlankAttrib, "Attribute: DataType");
110 
111  m_strDataType = strType;
112 }
113 
122 std::string DataColumn::TargetID() {return m_strTargetID;}
123 
132 void DataColumn::TargetID(std::string strID)
133 {
134  if(Std_IsBlank(strID))
135  THROW_TEXT_ERROR(Std_Err_lBlankAttrib, Std_Err_strBlankAttrib, "Attribute: TargetID");
136  m_strTargetID = strID;
137 }
138 
148 
157 void DataColumn::AppendSpaces(int iSpaces)
158 {
159  Std_InValidRange((int) 0, (int) 10, iSpaces, true, "AppendSpaces");
160  m_iAppendSpaces = iSpaces;
161 }
162 
172 
181 void DataColumn::ColumnIndex(int iIndex)
182 {
183  Std_IsAboveMin((int) -1, iIndex, true, "ColumnIndex", true);
184  m_iColumnIndex = iIndex;
185 }
186 
196 
205 void DataColumn::RowIndex(int iIndex)
206 {
207  Std_IsAboveMin((int) -1, iIndex, true, "RowIndex", true);
208  m_iRowIndex = iIndex;
209 }
210 
220 
229 void DataColumn::IsInitialized(bool bVal) {m_bInitialized = bVal;}
230 
240 
242 {
244 
247 
248  if(!m_lpDataValue)
249  THROW_TEXT_ERROR(Al_Err_lDataPointNotFound, Al_Err_strDataPointNotFound,
250  ("DataColumn: " + m_strID + " TargetID: " + m_strTargetID + " DataType: " + m_strDataType));
251 
252  m_bInitialized = true;
253 }
254 
256 {
257  if(!m_bInitialized)
258  Initialize();
259 }
260 
261 void DataColumn::Activate()
262 {
263 }
264 
265 void DataColumn:: Deactivate()
266 {
267 }
268 
269 bool DataColumn::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
270 {
271  std::string strType = Std_CheckString(strDataType);
272 
273  if(AnimatBase::SetData(strDataType, strValue, false))
274  return true;
275 
276  if(strType == "COLUMNINDEX")
277  {
278  ColumnIndex(atoi(strValue.c_str()));
279  return true;
280  }
281 
282  if(strType == "DATATYPE")
283  {
284  DataType(strValue);
285  Initialize();
286  return true;
287  }
288 
289  //If it was not one of those above then we have a problem.
290  if(bThrowError)
291  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
292 
293  return false;
294 }
295 
296 void DataColumn::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
297 {
298  AnimatBase::QueryProperties(aryProperties);
299 
300  aryProperties.Add(new TypeProperty("ColumnIndex", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
301  aryProperties.Add(new TypeProperty("DataType", AnimatPropertyType::String, AnimatPropertyDirection::Set));
302 }
303 
312 void DataColumn::SaveColumnNames(std::ofstream &oStream)
313 {
314  oStream << m_strName;
315 
316  if(m_iAppendSpaces > 0)
317  {
318  for(int iIndex=0; iIndex<m_iAppendSpaces; iIndex++)
319  oStream << " \t";
320  }
321 }
322 
323 void DataColumn::SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule,
324  Node *lpNode, DataChart *lpChart, bool bVerify)
325 {
326  AnimatBase::SetSystemPointers(lpSim, lpStructure, lpModule, lpNode, false);
327  m_lpChart = lpChart;
328 
329  if(bVerify) VerifySystemPointers();
330 }
331 
333 {
335 
336  if(!m_lpChart)
337  THROW_PARAM_ERROR(Al_Err_lChartNotDefined, Al_Err_strChartNotDefined, "DataColumn: ", m_strName);
338 }
339 
341 {
343 }
344 
353 {
354  if(this->m_iColumnIndex < lpColumn->m_iColumnIndex)
355  return true;
356 
357  return false;
358 }
359 
360 void DataColumn::Load(CStdXml &oXml)
361 {
362  AnimatBase::Load(oXml);
363 
364  oXml.IntoElem(); //Into DataColumn Element
365 
366  m_strName = oXml.GetChildString("ColumnName", m_strName);
367  TargetID(oXml.GetChildString("TargetID"));
368  DataType(oXml.GetChildString("DataType"));
369  AppendSpaces(oXml.GetChildInt("AppendSpaces", m_iAppendSpaces));
370  ColumnIndex(oXml.GetChildInt("Column", m_iColumnIndex));
371  RowIndex(oXml.GetChildInt("Row", m_iColumnIndex));
372 
373  oXml.OutOfElem(); //OutOf DataColumn Element
374 }
375 
389 bool LessThanDataColumnCompare(DataColumn *lpColumn1, DataColumn *lpColumn2)
390 {
391  return lpColumn1->operator<(lpColumn2);
392 }
393 
394  } //Charting
395 } //AnimatSim
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.
Simulates the entire environment.
Definition: Simulator.h:31
Root namespace for the base simulation library for AnimatLab.
virtual void SaveColumnNames(std::ofstream &oStream)
Saves this DataColumn name to the out stream for the file.
Definition: DataColumn.cpp:312
Declares the body part class.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Definition: DataColumn.cpp:296
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
virtual bool IntoElem()
Goes into the next element where the cursor is located.
Definition: StdXml.cpp:42
bool m_bInitialized
true it this chart has been initialized
Definition: DataColumn.h:46
Data column class.
Definition: DataColumn.h:24
virtual float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
Definition: AnimatBase.cpp:340
Class that stores information about types for QueryProperty information.
Definition: TypeProperty.h:35
virtual void StepSimulation()
Step the simulation for this object.
Definition: DataColumn.cpp:340
virtual void Initialize()
Initializes this object.
Definition: AnimatBase.cpp:573
Declares the key frame class.
bool Std_InValidRange(int iMinVal, int iMaxVal, int iVal, bool bThrowError, std::string strParamName)
Tests whether a number is within a valid range.
virtual int ColumnCount()
Gets the number of columns for this DataColumn.
Definition: DataColumn.cpp:78
Declares the joint class.
virtual void Initialize()
Initializes this object.
Definition: DataColumn.cpp:241
Declares the organism class.
virtual int GetChildInt(std::string strElementName)
Gets an integer value from the element with the specified name.
Definition: StdXml.cpp:456
bool Std_IsAboveMin(int iMinVal, int iVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
Tests if a number is above a minimum value.
std::string m_strID
The unique Id for this object.
Definition: AnimatBase.h:55
int m_iAppendSpaces
Determines whether how many other tabs are added after this data is written to the file...
Definition: DataColumn.h:43
Data chart base class.
Definition: DataChart.h:31
Declares a light object.
bool LessThanDataColumnCompare(DataColumn *lpColumn1, DataColumn *lpColumn2)
Compares two DataColumn items to find the one that is less than the other.
Definition: DataColumn.cpp:389
virtual std::string DataType()
Gets the data type of the variable we are collecting. This is the value passed into GetDataPointer...
Definition: DataColumn.cpp:96
Declares the activated item class.
Declares the data column class.
float * m_lpDataValue
Pointer to the data variable we are collecting.
Definition: DataColumn.h:40
Declares a light manager object.
DataChart * m_lpChart
Pointer to the parent DataChart.
Definition: DataColumn.h:34
Declares the bounding box class.
virtual std::string Name()
Gets the name of this object.
Definition: AnimatBase.cpp:195
A standard xml manipulation class.
Definition: StdXml.h:19
A "static" structure in the simulation.
Definition: Structure.h:84
Declares the node class.
virtual void AddData(int iColumn, int iRow, float fltVal)
Adds a data element to the data buffer.
Definition: DataChart.cpp:826
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Definition: AnimatBase.cpp:447
virtual std::string GetChildString(std::string strElementName)
Gets a string value from the element with the specified name.
Definition: StdXml.cpp:307
virtual float * DataValue()
Gets the pointer to the data value we are collecting.
Definition: DataColumn.cpp:239
virtual AnimatBase * FindByID(std::string strID, bool bThrowError=true)
Searches for the object with the specified ID.
Definition: Simulator.cpp:4008
virtual void Load(StdUtils::CStdXml &oXml)
Loads the item using an XML data packet.
Definition: AnimatBase.cpp:771
virtual int AppendSpaces()
Gets how many spaces to append.
Definition: DataColumn.cpp:147
std::string m_strTargetID
GUID ID of the target object that contains the variable we will be collecting.
Definition: DataColumn.h:28
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: DataColumn.cpp:269
virtual int ColumnIndex()
Gets the column index.
Definition: DataColumn.cpp:171
virtual void ReInitialize()
Re-initialize this object.
Definition: DataColumn.cpp:255
Base class for body parts and neural network nodes.
Definition: Node.h:25
AnimatBase * m_lpTarget
Pointer to the target object that contains the data variable we will be collecting.
Definition: DataColumn.h:37
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
virtual bool operator<(DataColumn *lpColumn)
Determines if this column has an index value less than the index value of the column being passed in...
Definition: DataColumn.cpp:352
Declares the data chart class.
std::string m_strDataType
The Data type of the variable we will be collecting. This is passed into the GetDataPointer method of...
Definition: DataColumn.h:31
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.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
virtual void VerifySystemPointers()
Verify that system pointers have been set correctly.
Definition: DataColumn.cpp:332
virtual void SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, DataChart *lpChart, bool bVerify)
Sets the system pointers.
virtual std::string TargetID()
Gets the GUID ID of the item to chart.
Definition: DataColumn.cpp:122
Declares the structure class.
Declares the odor type class.
virtual void VerifySystemPointers()
Verify that system pointers have been set correctly.
Definition: AnimatBase.cpp:315
DataColumn()
Default constructor.
Definition: DataColumn.cpp:49
virtual bool IsInitialized()
Query if this object is initialized.
Definition: DataColumn.cpp:219
Declares the odor class.
Declares the simulator class.
virtual int RowIndex()
Gets the row index.
Definition: DataColumn.cpp:195
Declares the activated item manager class.
Declares the contact sensor class.
Declares the external stimuli manager class.
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: AnimatBase.cpp:371
virtual ~DataColumn()
Destructor.
Definition: DataColumn.cpp:64
Declares the receptive field class.
std::string m_strName
The name for this object.
Definition: AnimatBase.h:61