AnimatLab  2
Test
AnimatBase.cpp
Go to the documentation of this file.
1 
10 #include "StdAfx.h"
11 #include "IMovableItemCallback.h"
12 #include "ISimGUICallback.h"
13 #include "AnimatBase.h"
14 
15 #include <sys/types.h>
16 #include <sys/stat.h>
17 #include "Gain.h"
18 #include "Node.h"
19 #include "Link.h"
20 #include "IPhysicsMovableItem.h"
21 #include "IPhysicsBody.h"
22 #include "BoundingBox.h"
23 #include "MovableItem.h"
24 #include "BodyPart.h"
25 #include "Joint.h"
26 #include "ReceptiveField.h"
27 #include "ContactSensor.h"
28 #include "RigidBody.h"
29 #include "Structure.h"
30 #include "NeuralModule.h"
31 #include "Adapter.h"
32 #include "NervousSystem.h"
33 #include "Organism.h"
34 #include "ActivatedItem.h"
35 #include "ActivatedItemMgr.h"
36 #include "DataChartMgr.h"
37 #include "ExternalStimuliMgr.h"
38 #include "KeyFrame.h"
39 #include "SimulationRecorder.h"
40 #include "OdorType.h"
41 #include "Odor.h"
42 #include "Light.h"
43 #include "LightManager.h"
44 #include "Simulator.h"
45 
46 namespace AnimatSim
47 {
48 
59 {
60  m_lpSim = NULL;
61  m_lpStructure = NULL;
62  m_lpModule = NULL;
63  m_lpNode = NULL;
65  m_bSelected = false;
66  m_bEnabled = true;
67 }
68 
81 {
82 
83 try
84 {
85  //This will remove this object from the object list of the simulation.
86  if(m_lpSim)
88 }
89 catch(...)
90 {Std_TraceMsg(0, "Caught Error in desctructor of AnimatBase\r\n", "", -1, false, true);}
91 }
92 
102 void AnimatBase::Enabled(bool bVal) {m_bEnabled = bVal;}
103 
114 
124 
134 
145 
155 
167 std::string AnimatBase::ID() {return m_strID;}
168 
179 void AnimatBase::ID(std::string strID)
180 {
181  if(Std_IsBlank(strID))
182  THROW_ERROR(Al_Err_lIDBlank, Al_Err_strIDBlank);
183 
184  m_strID = Std_CheckString(strID);
185 }
186 
195 std::string AnimatBase::Name() {return m_strName;}
196 
205 void AnimatBase::Name(std::string strValue) {m_strName = strValue;}
206 
221 std::string AnimatBase::Type() {return m_strType;}
222 
231 void AnimatBase::Type(std::string strValue) {m_strType = strValue;}
232 
249 
267 void AnimatBase::Selected(bool bValue, bool bSelectMultiple) {m_bSelected = bValue;}
268 
269 void AnimatBase::Copy(CStdSerialize *lpSource)
270 {
271  CStdSerialize::Copy(lpSource);
272 
273  AnimatBase *lpOrig = dynamic_cast<AnimatBase *>(lpSource);
274 
275  m_bEnabled = lpOrig->m_bEnabled;
276  m_lpSim = lpOrig->m_lpSim;
277  m_lpStructure = lpOrig->m_lpStructure;
278  m_lpModule = lpOrig->m_lpModule;
279  m_lpNode = lpOrig->m_lpNode;
280  m_strID = lpOrig->m_strID;
281  m_strType = lpOrig->m_strType;
282  m_strName = lpOrig->m_strName;
283  m_bSelected = lpOrig->m_bSelected;
284 }
285 
286 #pragma region DataAccesMethods
287 
288 
289 //Don't know why, but the documentation for this has to be in the .h file. When I try and put it here
290 //it is not processed by doxygen. ????
291 void AnimatBase::SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
292 {
293  m_lpSim = lpSim;
294  m_lpStructure = lpStructure;
295  m_lpModule = lpModule;
296  m_lpNode = lpNode;
297 
298  if(bVerify) VerifySystemPointers();
299 }
300 
316 {
317  if(!m_lpSim)
318  THROW_ERROR(Al_Err_lSimulationNotDefined, Al_Err_strSimulationNotDefined);
319 }
320 
340 float *AnimatBase::GetDataPointer(const std::string &strDataType)
341 {
342  //If we are using the AnimatBase function then there are no data pointer, so throw an error.
343  THROW_TEXT_ERROR(Al_Err_lDataPointNotFound, Al_Err_strDataPointNotFound, ("ID: " + m_strID + " Name: " + m_strName));
344  return NULL;
345 }
346 
371 bool AnimatBase::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
372 {
373  if(strDataType == "NAME")
374  {
375  Name(strValue);
376  return true;
377  }
378 
379  if(strDataType == "CALL_INIT")
380  {
381  this->Initialize();
382  return true;
383  }
384 
385  //If we are using the AnimatBase function then there are no data pointer, so throw an error.
386  if(bThrowError)
387  THROW_TEXT_ERROR(Al_Err_lDataPointNotFound, Al_Err_strDataPointNotFound, ("ID: " + m_strID + " Name: " + m_strName));
388  return false;
389 }
390 
406 bool AnimatBase::SetData(const std::string &strDataType, const float fltValue, bool bThrowError)
407 {
408  return SetData(strDataType, Std_ToStr(fltValue), bThrowError);
409 }
410 
426 bool AnimatBase::SetData(const std::string &strDataType, const long lValue, bool bThrowError)
427 {
428  return SetData(strDataType, Std_ToStr(lValue), bThrowError);
429 }
430 
431 
447 void AnimatBase::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
448 {
449  aryProperties.Add(new TypeProperty("Name", AnimatPropertyType::String, AnimatPropertyDirection::Set));
450 }
451 
464 bool AnimatBase::HasProperty(const std::string &strName)
465 {
466  CStdPtrArray<TypeProperty> aryProperties;
467  QueryProperties(aryProperties);
468 
469  std::string strCheck = Std_CheckString(strName);
470  int iCount = aryProperties.GetSize();
471  for(int iIdx=0; iIdx<iCount; iIdx++)
472  if(Std_CheckString(aryProperties[iIdx]->m_strName) == strCheck)
473  return true;
474 
475  return false;
476 }
477 
478 
479 AnimatPropertyType AnimatBase::PropertyType(const std::string &strName)
480 {
481  CStdPtrArray<TypeProperty> aryProperties;
482  QueryProperties(aryProperties);
483 
484  std::string strCheck = Std_CheckString(strName);
485  int iCount = aryProperties.GetSize();
486  for(int iIdx=0; iIdx<iCount; iIdx++)
487  if(Std_CheckString(aryProperties[iIdx]->m_strName) == strCheck)
488  return aryProperties[iIdx]->m_eType;
489 
490  return AnimatPropertyType::Invalid;
491 }
492 
513 bool AnimatBase::AddItem(const std::string &strItemType, const std::string &strXml, bool bThrowError, bool bDoNotInit)
514 {
515  //If we are using the AnimatBase function then there are no data pointer, so throw an error.
516  if(bThrowError)
517  THROW_TEXT_ERROR(Al_Err_lItemTypeInvalid, Al_Err_strItemTypeInvalid, ("ID: " + m_strID + " ItemType: " + strItemType));
518  return false;
519 }
520 
538 bool AnimatBase::RemoveItem(const std::string &strItemType, const std::string &strID, bool bThrowError)
539 {
540  //If we are using the AnimatBase function then there are no data pointer, so throw an error.
541  if(bThrowError)
542  THROW_TEXT_ERROR(Al_Err_lItemNotFound, Al_Err_strItemNotFound, ("ID: " + m_strID));
543  return false;
544 }
545 
546 #pragma endregion
547 
548 
549 #pragma region SimulationMethods
550 
560 
574 {
576 }
577 
588 
599 
610 
627 void AnimatBase::Kill(bool bState) {};
628 
644 
655 
666 
677 
686 
687 #pragma endregion
688 
689 #pragma region SnapshotMethods
690 
706 
722 void AnimatBase::SaveKeyFrameSnapshot(byte *aryBytes, long &lIndex) {}
723 
739 void AnimatBase::LoadKeyFrameSnapshot(byte *aryBytes, long &lIndex) {}
740 
741 #pragma endregion
742 
755 
772 {
774 
775  oXml.IntoElem();
776  m_strType = oXml.GetChildString("Type", m_strType);
778  m_strName = oXml.GetChildString("Name", m_strName);
779  Enabled(oXml.GetChildBool("Enabled", m_bEnabled));
780  oXml.OutOfElem();
781 
782  if(Std_IsBlank(m_strID))
783  THROW_ERROR(Al_Err_lIDBlank, Al_Err_strIDBlank);
784 
785  if(Std_IsBlank(m_strName))
786  m_strName = m_strID;
787 
788  //if(Std_ToLower(m_strID) == "d10da888-6478-4d60-b878-0e761b7e8ef2")
789  // m_strID = m_strID;
790 
791  //This will add this object to the object list of the simulation.
792  if(m_lpSim)
793  m_lpSim->AddToObjectList(this);
794 }
795 
796 } //AnimatSim
virtual void ResetSimulation()
Resets the simulation back to time 0.
Definition: AnimatBase.cpp:587
virtual void ReInitialize()
Re-initialize this object.
Definition: AnimatBase.cpp:609
Base class file for all Animat simulation objects.
Declares the nervous system class.
Declares the simulation recorder class.
virtual void RemoveFromObjectList(AnimatBase *lpItem)
Removes an object from the list of all simulation objects.
Definition: Simulator.cpp:4084
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
std::string Std_CreateAppID()
Gets the standard create application identifier.
virtual void LoadKeyFrameSnapshot(byte *aryBytes, long &lIndex)
Loads a key frame snapshot.
Definition: AnimatBase.cpp:739
AnimatBase()
Constructs an AnimatBase object.
Definition: AnimatBase.cpp:58
Root namespace for the base simulation library for AnimatLab.
virtual void SimPausing()
Called just before the simulation pauses.
Definition: AnimatBase.cpp:665
AnimatSim::Behavior::NeuralModule * m_lpModule
The pointer to this items parentNeuralModule. If this is not relevant for this object then this is NU...
Definition: AnimatBase.h:49
Declares the body part class.
virtual void Kill(bool bState=true)
Kills.
Definition: AnimatBase.cpp:627
virtual std::string Type()
returns the string type name of this object.
Definition: AnimatBase.cpp:221
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
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
virtual bool HasProperty(const std::string &strName)
Queries this object if it has a property with the given name.
Definition: AnimatBase.cpp:464
virtual Node * GetNode()
Gets the node.
Definition: AnimatBase.cpp:154
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 TimeStepModified()
Notification method that the time step modified has been modified. Objects should recalculate any sli...
Definition: AnimatBase.cpp:685
virtual void Initialize()
Initializes this object.
Definition: AnimatBase.cpp:573
virtual void SimStarting()
Called just before the simulation starts.
Definition: AnimatBase.cpp:654
virtual void AfterResetSimulation()
Called after a simulation reset for some objects.
Definition: AnimatBase.cpp:598
Declares the key frame class.
virtual Simulator * GetSimulator()
Gets the simulator pointer.
Definition: AnimatBase.cpp:123
Declares the joint class.
Declares the organism class.
AnimatSim::Environment::Structure * m_lpStructure
The pointer to this items parent Structure. If this is not relevant for this object then this is NULL...
Definition: AnimatBase.h:46
std::string m_strID
The unique Id for this object.
Definition: AnimatBase.h:55
Declares a light object.
Declares the activated item class.
Declares a light manager object.
virtual void Reset()
Resets this object.
Definition: AnimatBase.cpp:559
Declares the bounding box class.
virtual std::string Name()
Gets the name of this object.
Definition: AnimatBase.cpp:195
Declares the gain base class.
virtual bool Enabled()
Tells whether this item is enabled or not. This is not actually used for all objects, only specific ones. I am putting it in the base class though to prevent numerous duplications.
Definition: AnimatBase.cpp:113
A standard xml manipulation class.
Definition: StdXml.h:19
Node * m_lpNode
The pointer to this items parent Node. If this is not relevant for this object then this is NULL...
Definition: AnimatBase.h:52
virtual bool Selected()
Tells if this items is selected or not.
Definition: AnimatBase.cpp:248
A "static" structure in the simulation.
Definition: Structure.h:84
virtual void StepSimulation()
Step the simulation for this object.
Definition: AnimatBase.cpp:643
virtual bool AddItem(const std::string &strItemType, const std::string &strXml, bool bThrowError=true, bool bDoNotInit=false)
Adds a new object to this parent.
Definition: AnimatBase.cpp:513
virtual void SaveKeyFrameSnapshot(byte *aryBytes, long &lIndex)
Saves a key frame snapshot.
Definition: AnimatBase.cpp:722
virtual NeuralModule * GetNeuralModule()
Gets the neural module.
Definition: AnimatBase.cpp:144
Declares the node class.
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 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 bool GetChildBool(std::string strElementName)
Gets a bool value from the element with the specified name.
Definition: StdXml.cpp:699
Animat base class.
Definition: AnimatBase.h:36
bool m_bEnabled
Tells if this item is enabled or not. If it is not enabled then it is not run.
Definition: AnimatBase.h:40
virtual ~AnimatBase()
Destroys the AnimatBase object..
Definition: AnimatBase.cpp:80
Base class for body parts and neural network nodes.
Definition: Node.h:25
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
std::string Std_ToStr(std::string strVal)
Converts a value to a string.
virtual Structure * GetStructure()
Gets the structure for this node.
Definition: AnimatBase.cpp:133
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 SimStopping()
Called just before the simulation stops.
Definition: AnimatBase.cpp:676
virtual bool RemoveItem(const std::string &strItemType, const std::string &strID, bool bThrowError=true)
Removes a child item from this parent.
Definition: AnimatBase.cpp:538
Declares the structure class.
virtual void VisualSelectionModeChanged(int iNewMode)
Visual selection mode changed.
Definition: AnimatBase.cpp:754
Declares the odor type class.
virtual long CalculateSnapshotByteSize()
Calculates the snapshot byte size.
Definition: AnimatBase.cpp:705
Standard serialize class.
Definition: StdSerialize.h:20
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.
bool m_bSelected
Tells whether the object is selected or not.
Definition: AnimatBase.h:64
Declares the activated item manager class.
Declares the contact sensor class.
Declares the external stimuli manager class.
std::string m_strType
The type for this object. Examples are Box, Plane, Neuron, etc..
Definition: AnimatBase.h:58
virtual void AddToObjectList(AnimatBase *lpItem)
Adds an object to the list of all simulation objects.
Definition: Simulator.cpp:4068
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
Declares the receptive field class.
std::string m_strName
The name for this object.
Definition: AnimatBase.h:61