AnimatLab  2
Test
PassThroughLinkage.cpp
1 #include "StdAfx.h"
2 #include "IMovableItemCallback.h"
3 #include "ISimGUICallback.h"
4 #include "IMotorizedJoint.h"
5 #include "AnimatBase.h"
6 
7 #include "Node.h"
8 #include "Link.h"
9 #include "IPhysicsMovableItem.h"
10 #include "IPhysicsBody.h"
11 #include "Gain.h"
12 #include "BoundingBox.h"
13 #include "MovableItem.h"
14 #include "BodyPart.h"
15 #include "Joint.h"
16 #include "ReceptiveField.h"
17 #include "ContactSensor.h"
18 #include "RigidBody.h"
19 #include "Structure.h"
20 #include "NeuralModule.h"
21 #include "Adapter.h"
22 #include "NervousSystem.h"
23 #include "Organism.h"
24 #include "ActivatedItem.h"
25 #include "ActivatedItemMgr.h"
26 #include "DataChartMgr.h"
27 #include "ExternalStimuliMgr.h"
28 #include "KeyFrame.h"
29 #include "SimulationRecorder.h"
30 #include "OdorType.h"
31 #include "Odor.h"
32 #include "Light.h"
33 #include "LightManager.h"
34 #include "Simulator.h"
35 
36 #include "RobotInterface.h"
37 #include "RobotIOControl.h"
38 #include "RemoteControlLinkage.h"
39 #include "PassThroughLinkage.h"
40 #include "RemoteControl.h"
41 
42 namespace AnimatSim
43 {
44  namespace Robotics
45  {
46 
47 PassThroughLinkage::PassThroughLinkage(void)
48 {
49  m_lpGain = NULL;
50 }
51 
52 PassThroughLinkage::~PassThroughLinkage(void)
53 {
54 try
55 {
56  if(m_lpGain)
57  {
58  delete m_lpGain;
59  m_lpGain = NULL;
60  }
61 }
62 catch(...)
63 {Std_TraceMsg(0, "Caught Error in desctructor of PassThroughLinkage\r\n", "", -1, false, true);}
64 }
65 
75 
76 void PassThroughLinkage::SetGain(Gain *lpGain)
77 {
78  if(m_lpGain)
79  {
80  delete m_lpGain;
81  m_lpGain = NULL;
82  }
83 
84  m_lpGain = lpGain;
86 }
87 
96 void PassThroughLinkage::AddGain(std::string strXml)
97 {
98  CStdXml oXml;
99  oXml.Deserialize(strXml);
100  oXml.FindElement("Root");
101  oXml.FindChildElement("Gain");
102 
103  SetGain(LoadGain(m_lpSim, "Gain", oXml));
104 }
105 
106 
107 bool PassThroughLinkage::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
108 {
109  std::string strType = Std_CheckString(strDataType);
110 
111  if(RemoteControlLinkage::SetData(strType, strValue, false))
112  return true;
113 
114  if(strType == "GAIN")
115  {
116  AddGain(strValue);
117  return true;
118  }
119 
120  //If it was not one of those above then we have a problem.
121  if(bThrowError)
122  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
123 
124  return false;
125 }
126 
127 void PassThroughLinkage::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
128 {
130  aryProperties.Add(new TypeProperty("Gain", AnimatPropertyType::Xml, AnimatPropertyDirection::Set));
131 }
132 
133 #pragma endregion
134 
135 float PassThroughLinkage::CalculateAppliedValue(float fltData)
136 {
137  if(m_lpGain)
138  return m_lpGain->CalculateGain(fltData);
139  else
140  return 0;
141 }
142 
143 void PassThroughLinkage::Load(CStdXml &oXml)
144 {
145  RemoteControlLinkage::Load(oXml);
146 
147  oXml.IntoElem(); //Into Link Element
148  if(oXml.FindChildElement("Gain", false))
149  SetGain(LoadGain(m_lpSim, "Gain", oXml));
150 
151  oXml.OutOfElem(); //OutOf Link Element
152 }
153 
154 
155 
156  }
157 }
virtual Gain * GetGain()
Gets the poitner to the gain function.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
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.
Declares the Robot IO control interface base 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
Root namespace for the base simulation library for AnimatLab.
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 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
virtual bool IntoElem()
Goes into the next element where the cursor is located.
Definition: StdXml.cpp:42
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
Class that stores information about types for QueryProperty information.
Definition: TypeProperty.h:35
The Gain base class.
Definition: Gain.h:35
Declares the key frame class.
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
Gain * m_lpGain
Pointer to the Gain that will be used to convert the source value into the target value...
Declares a light object.
Declares the activated item class.
Declares a light manager object.
Declares the bounding box class.
Declares the gain base class.
A standard xml manipulation class.
Definition: StdXml.h:19
Declares the node class.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
virtual void AddGain(std::string strXml)
Creates and adds a gain object.
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 OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
Declares the data chart manager class.
Declares the rigid body class.
virtual float CalculateGain(float fltInput)=0
Calculates the gain.
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.
Declares the robotics inerface for animatlab.
Declares the odor class.
Declares the simulator class.
Declares the neural module class.
Declares the activated item 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.
Declares the contact sensor class.
Declares the external stimuli manager class.
Gain * LoadGain(Simulator *lpSim, std::string strName, CStdXml &oXml)
Loads a gain object.
Definition: Gain.cpp:287
Declares the receptive field class.