AnimatLab  2
Test
Node.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 "Link.h"
14 #include "IPhysicsMovableItem.h"
15 #include "IPhysicsBody.h"
16 #include "BoundingBox.h"
17 #include "MovableItem.h"
18 #include "BodyPart.h"
19 #include "Gain.h"
20 #include "Adapter.h"
21 #include "Joint.h"
22 #include "ReceptiveField.h"
23 #include "ContactSensor.h"
24 #include "RigidBody.h"
25 #include "Structure.h"
26 #include "NeuralModule.h"
27 #include "NervousSystem.h"
28 #include "Organism.h"
29 #include "ActivatedItem.h"
30 #include "ActivatedItemMgr.h"
31 #include "DataChartMgr.h"
32 #include "ExternalStimuliMgr.h"
33 #include "KeyFrame.h"
34 #include "SimulationRecorder.h"
35 #include "OdorType.h"
36 #include "Odor.h"
37 #include "Light.h"
38 #include "LightManager.h"
39 #include "Simulator.h"
40 
41 namespace AnimatSim
42 {
50 {
51  m_lpOrganism = NULL;
52  m_bEnabled = true;
54  m_fltEnabled = 0;
55 }
56 
64 {
65 
66 try
67 {
68 }
69 catch(...)
70 {Std_TraceMsg(0, "Caught Error in desctructor of Node\r\n", "", -1, false, true);}
71 }
72 
84 bool Node::Enabled() {return m_bEnabled;}
85 
96 void Node::Enabled(bool bValue)
97 {
98  m_bEnabled = bValue;
99  m_fltEnabled = (float) m_bEnabled;
100 
101  //If the sim is running then we do not set the history flag. Only set it if changed while the sim is not running.
102  if(!m_lpSim->SimRunning())
104 }
105 
107 {
109 
110  //Reset the enabled state to the value that it had before the sim started.
111  //It is possible that stimuli turned off the enabled state during the simulation.
113 }
114 
115 void Node::Kill(bool bState)
116 {
117  if(bState)
118  Enabled(false);
119  else
121 }
122 
123 void Node::Copy(CStdSerialize *lpSource)
124 {
125  AnimatBase::Copy(lpSource);
126 
127  Node *lpOrig = dynamic_cast<Node *>(lpSource);
128 
129  m_lpOrganism = lpOrig->m_lpOrganism;
130  m_bInitEnabled = lpOrig->m_bInitEnabled;
131  m_fltEnabled = lpOrig->m_fltEnabled;
132 }
133 
141 {}
142 
157 int Node::GetTargetDataTypeIndex(const std::string &strDataType)
158 {
159  return 0;
160 }
161 
162 void Node::SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
163 {
164  AnimatBase::SetSystemPointers(lpSim, lpStructure, lpModule, lpNode, false);
165 
166  m_lpOrganism = dynamic_cast<Organism *>(lpStructure);
167 
168  if(bVerify) VerifySystemPointers();
169 }
170 
172 {
174 
175  if(!m_lpStructure)
176  THROW_PARAM_ERROR(Al_Err_lStructureNotDefined, Al_Err_strStructureNotDefined, "Link: ", m_strID);
177 }
178 
179 bool Node::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
180 {
181  std::string strType = Std_CheckString(strDataType);
182 
183  if(AnimatBase::SetData(strType, strValue, false))
184  return true;
185 
186  if(strType == "ENABLED")
187  {
188  Enabled(Std_ToBool(strValue));
189  return true;
190  }
191 
192  //If it was not one of those above then we have a problem.
193  if(bThrowError)
194  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
195 
196  return false;
197 }
198 
199 void Node::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
200 {
201  AnimatBase::QueryProperties(aryProperties);
202 
203  aryProperties.Add(new TypeProperty("Enabled", AnimatPropertyType::Boolean, AnimatPropertyDirection::Both));
204 }
205 
206 } //AnimatSim
virtual void SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
Sets the system pointers.
virtual void ResetSimulation()
Resets the simulation back to time 0.
Definition: AnimatBase.cpp:587
virtual ~Node()
Destructor.
Definition: Node.cpp:63
Base class file for all Animat simulation objects.
Declares the nervous system class.
bool m_bInitEnabled
Keeps track of the enabled state at sim startup.
Definition: Node.h:32
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
virtual void Kill(bool bState=true)
Kills.
Definition: Node.cpp:115
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
float m_fltEnabled
This is used for reporting the enabled state in a GetDataPointer call.
Definition: Node.h:35
virtual int GetTargetDataTypeIndex(const std::string &strDataType)
Used to convert a string target data type into an integer index.
Definition: Node.cpp:157
Node()
Default constructor.
Definition: Node.cpp:49
Class that stores information about types for QueryProperty information.
Definition: TypeProperty.h:35
Declares the key frame class.
Declares the joint class.
Declares the organism class.
virtual bool SimRunning()
Gets whether the simulation is running.
Definition: Simulator.cpp:673
Organism * m_lpOrganism
The pointer to this node's organism.
Definition: Node.h:29
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
virtual bool Enabled()
Tells whether this node is enabled.
Definition: Node.cpp:84
std::string m_strID
The unique Id for this object.
Definition: AnimatBase.h:55
Declares a light object.
Declares the activated item class.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Definition: Node.cpp:199
Declares a light manager object.
Declares the bounding box class.
Declares the gain base class.
A "static" structure in the simulation.
Definition: Structure.h:84
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
bool Std_ToBool(int iVal)
Converts a value toa bool.
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.
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
A dynamic organism that is controlled by a neural network.
Definition: Organism.h:31
Base class for body parts and neural network nodes.
Definition: Node.h:25
Declares the data chart manager class.
virtual void ResetSimulation()
Resets the simulation back to time 0.
Definition: Node.cpp:106
Declares the rigid body class.
virtual void VerifySystemPointers()
Verify that system pointers have been set correctly.
Definition: Node.cpp:171
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
Declares the structure class.
Declares the odor type class.
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.
virtual void UpdateData()
Updates any reporting data for this time step.
Definition: Node.cpp:140
Declares the neural module class.
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
Declares the receptive field 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: Node.cpp:179