AnimatLab  2
Test
EnablerStimulus.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 "ExternalStimulus.h"
34 #include "ExternalInputStimulus.h"
35 #include "EnablerStimulus.h"
36 #include "KeyFrame.h"
37 #include "SimulationRecorder.h"
38 #include "OdorType.h"
39 #include "Odor.h"
40 #include "Light.h"
41 #include "LightManager.h"
42 #include "Simulator.h"
43 
44 namespace AnimatSim
45 {
46  namespace ExternalStimuli
47  {
55 {
56  m_bEnableWhenActive = true;
57 }
58 
66 {
67 
68 try
69 {
70 }
71 catch(...)
72 {Std_TraceMsg(0, "Caught Error in desctructor of EnablerStimulus\r\n", "", -1, false, true);}
73 }
74 
75 std::string EnablerStimulus::Type() {return "EnablerInput";}
76 
86 
95 void EnablerStimulus::TargetNodeID(std::string strID)
96 {
97  if(Std_IsBlank(strID))
98  THROW_ERROR(Al_Err_lBodyIDBlank, Al_Err_strBodyIDBlank);
99  m_strTargetNodeID = strID;
100 }
101 
112 
123 
125 {
127 
128  m_lpNode = dynamic_cast<Node *>(m_lpSim->FindByID(m_strTargetNodeID));
129 }
130 
132 {
134 
136  m_lpNode->Enabled(true);
137  else
138  m_lpNode->Enabled(false);
139 }
140 
142 {
143 }
144 
146 {
148 
150  m_lpNode->Enabled(false);
151  else
152  m_lpNode->Enabled(true);
153 }
154 
155 bool EnablerStimulus::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
156 {
157  std::string strType = Std_CheckString(strDataType);
158 
159  if(ExternalStimulus::SetData(strDataType, strValue, false))
160  return true;
161 
162  if(strType == "ENABLEWHENACTIVE")
163  {
164  EnableWhenActive(Std_ToBool(strValue));
165  return true;
166  }
167 
168  //If it was not one of those above then we have a problem.
169  if(bThrowError)
170  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
171 
172  return false;
173 }
174 
175 void EnablerStimulus::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
176 {
177  ExternalStimulus::QueryProperties(aryProperties);
178 
179  aryProperties.Add(new TypeProperty("EnableWhenActive", AnimatPropertyType::Boolean, AnimatPropertyDirection::Set));
180 }
181 
182 void EnablerStimulus::Load(CStdXml &oXml)
183 {
184  ActivatedItem::Load(oXml);
185 
186  oXml.IntoElem(); //Into Simulus Element
187 
188  TargetNodeID(oXml.GetChildString("BodyID"));
189  EnableWhenActive(oXml.GetChildBool("EnableWhenActive", m_bEnableWhenActive));
190 
191  oXml.OutOfElem(); //OutOf Simulus Element
192 
193 }
194 
195  } //ExternalStimuli
196 } //VortexAnimatSim
197 
198 
199 
200 
virtual bool EnableWhenActive()
Tells if the node is enabled when active. This is used to control if we are enabling the node during ...
Declares the external stimulus base class.
Base class file for all Animat simulation objects.
Declares the nervous system class.
virtual void Activate()
Activates this item.
Declares the simulation recorder class.
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
virtual bool IntoElem()
Goes into the next element where the cursor is located.
Definition: StdXml.cpp:42
virtual void Activate()
Activates this item.
Class that stores information about types for QueryProperty information.
Definition: TypeProperty.h:35
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
std::string m_strTargetNodeID
GUID ID of the target node to enable.
Declares the key frame 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.
virtual std::string Type()
returns the string type name of this object.
virtual void Initialize()
Initializes this object.
Declares the joint class.
virtual void Deactivate()
Deactivates this item.
Declares the organism class.
virtual bool Enabled()
Tells whether this node is enabled.
Definition: Node.cpp:84
Declares a light object.
Declares the activated item class.
Declares a light manager object.
virtual void StepSimulation()
Step the simulation for this object.
Declares the enabler stimulus class.
Declares the bounding box class.
Declares the gain base class.
bool m_bEnableWhenActive
Tells whether the node is enabled while stimulus is active or not.
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
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 AnimatBase * FindByID(std::string strID, bool bThrowError=true)
Searches for the object with the specified ID.
Definition: Simulator.cpp:4008
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.
virtual bool GetChildBool(std::string strElementName)
Gets a bool value from the element with the specified name.
Definition: StdXml.cpp:699
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
virtual void Deactivate()
Deactivates this item.
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.
Declares the structure class.
Declares the odor type class.
virtual void Initialize()
Initializes this object.
Declares the odor class.
Declares the simulator class.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Declares the neural module class.
virtual std::string TargetNodeID()
Gets the GUID ID of the target node that will be enabled.
Declares the activated item manager class.
Declares the contact sensor class.
Declares the external stimuli manager class.
Declares the external input stimulus class.
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.