AnimatLab  2
Test
Prismatic.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 #include "IMotorizedJoint.h"
9 #include "IMovableItemCallback.h"
10 #include "ISimGUICallback.h"
11 #include "AnimatBase.h"
12 
13 #include "Node.h"
14 #include "IPhysicsMovableItem.h"
15 #include "IPhysicsBody.h"
16 #include "BoundingBox.h"
17 #include "MovableItem.h"
18 #include "BodyPart.h"
19 #include "Joint.h"
20 #include "MotorizedJoint.h"
21 #include "ReceptiveField.h"
22 #include "ContactSensor.h"
23 #include "RigidBody.h"
24 #include "ConstraintLimit.h"
25 #include "Prismatic.h"
26 #include "Structure.h"
27 #include "Organism.h"
28 #include "ActivatedItem.h"
29 #include "ActivatedItemMgr.h"
30 #include "DataChartMgr.h"
31 #include "ExternalStimuliMgr.h"
32 #include "KeyFrame.h"
33 #include "SimulationRecorder.h"
34 #include "OdorType.h"
35 #include "Odor.h"
36 #include "Light.h"
37 #include "LightManager.h"
38 #include "Simulator.h"
39 
40 namespace AnimatSim
41 {
42  namespace Environment
43  {
44  namespace Joints
45  {
53 {
54  m_lpUpperLimit = NULL;
55  m_lpLowerLimit = NULL;
56  m_lpPosFlap = NULL;
57 }
58 
66 {
67 try
68 {
69  if(m_lpUpperLimit)
70  {
71  delete m_lpUpperLimit;
72  m_lpUpperLimit = NULL;
73  }
74 
75  if(m_lpLowerLimit)
76  {
77  delete m_lpLowerLimit;
78  m_lpLowerLimit = NULL;
79  }
80 
81  if(m_lpPosFlap)
82  {
83  delete m_lpPosFlap;
84  m_lpPosFlap = NULL;
85  }
86 }
87 catch(...)
88 {Std_TraceMsg(0, "Caught Error in desctructor of Prismatic\r\n", "", -1, false, true);}
89 }
90 
101 {
102  return m_fltSize;
103 };
104 
105 
115 {
116  return m_fltSize * 3;
117 };
118 
119 void Prismatic::Enabled(bool bValue)
120 {
122  m_bEnabled = bValue;
123 }
124 
134 
144 
146 {
147  if(m_bEnableLimits)
148  {
149  if(fltPos>m_lpUpperLimit->LimitPos())
150  fltPos = m_lpUpperLimit->LimitPos();
151  if(fltPos<m_lpLowerLimit->LimitPos())
152  fltPos = m_lpLowerLimit->LimitPos();
153  }
154 
155  return fltPos;
156 }
157 
159 {
160  if(m_bEnableLimits)
162  else
163  return -1;
164 }
165 
166 bool Prismatic::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
167 {
168  std::string strType = Std_CheckString(strDataType);
169 
170  if(MotorizedJoint::SetData(strType, strValue, false))
171  return true;
172 
173  //If it was not one of those above then we have a problem.
174  if(bThrowError)
175  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
176 
177  return false;
178 }
179 
180 int Prismatic::GetTargetDataTypeIndex(const std::string &strDataType)
181 {
182  std::string strType = Std_CheckString(strDataType);
183 
184  if(strType == "DESIREDPOSITION")
185  return DESIRED_POSITION_TYPE;
186  else
187  return DESIRED_VELOCITY_TYPE;
188 
189 }
190 
191 void Prismatic::AddExternalNodeInput(int iTargetDataType, float fltInput)
192 {
193  if(iTargetDataType == DESIRED_POSITION_TYPE)
194  m_fltDesiredPosition += fltInput;
195  else
196  m_fltDesiredVelocity += fltInput;
197 }
198 
199 void Prismatic::Load(CStdXml &oXml)
200 {
201  MotorizedJoint::Load(oXml);
202 
203  oXml.IntoElem(); //Into Joint Element
204 
205  m_lpUpperLimit->SetSystemPointers(m_lpSim, m_lpStructure, NULL, this, true);
206  m_lpLowerLimit->SetSystemPointers(m_lpSim, m_lpStructure, NULL, this, true);
207  m_lpPosFlap->SetSystemPointers(m_lpSim, m_lpStructure, NULL, this, JointPosition());
208 
209  m_lpUpperLimit->Load(oXml, "UpperLimit");
210  m_lpLowerLimit->Load(oXml, "LowerLimit");
211 
212  oXml.OutOfElem(); //OutOf Joint Element
213 }
214 
215  } //Joints
216  } //Environment
217 } //AnimatSim
float BoxSize()
Gets the width of the flaps used to display the hinge in the environment.
Definition: Prismatic.cpp:114
virtual int GetTargetDataTypeIndex(const std::string &strDataType)
Used to convert a string target data type into an integer index.
Definition: Prismatic.cpp:180
Base class file for all Animat simulation objects.
Declares the simulation recorder class.
Root namespace for the base simulation library for AnimatLab.
virtual float LimitPos()
Gets the limit position.
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
Declares the key frame class.
Declares the joint class.
Declares the organism class.
Declares the prismatic 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
virtual bool Enabled()
Tells whether this node is enabled.
Definition: Node.cpp:84
virtual float GetPositionWithinLimits(float fltPos)
Gets a position value within the constraint limits.
Definition: Prismatic.cpp:145
Declares a light object.
virtual float GetLimitRange()
Gets the entire range of movement within the limits. If limits are not enabled then it returns -1...
Definition: Prismatic.cpp:158
ConstraintLimit * m_lpUpperLimit
Upper limit constring pointer.
Definition: Prismatic.h:37
Declares the activated item class.
Declares a light manager object.
Declares the bounding box class.
A standard xml manipulation class.
Definition: StdXml.h:19
virtual bool EnableMotor()
Tells if the motor is enabled.
Declares the node class.
virtual void AddExternalNodeInput(int iTargetDataType, float fltInput)
Adds an external node input.
Definition: Prismatic.cpp:191
bool m_bEnableLimits
If true then any ConstraintLimits for this joint are enabled.
Definition: Joint.h:47
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.
ConstraintLimit * m_lpLowerLimit
Lower limit constring pointer.
Definition: Prismatic.h:40
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
float m_fltSize
Scales the size of the graphics for this joint.
Definition: Joint.h:61
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
ConstraintLimit * m_lpPosFlap
Pointer to a constraint that is used to represent the position flap.
Definition: Prismatic.h:43
virtual float JointPosition()
Gets the joint position.
Definition: Joint.cpp:532
Declares the data chart manager class.
float CylinderRadius()
Gets the radius cylinder of the cylinder used to display the axis of the prismatic joint in the envir...
Definition: Prismatic.cpp:100
Declares the rigid body class.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
Declares the constraint limit class.
Declares the structure class.
Declares the odor type class.
virtual ConstraintLimit * UpperLimit()
Gets a pointer to the upper limit ConstraintLimit.
Definition: Prismatic.cpp:133
Declares the odor class.
Declares the simulator class.
virtual ConstraintLimit * LowerLimit()
Gets a pointer to the lower limit ConstraintLimit.
Definition: Prismatic.cpp:143
Declares the activated item manager class.
Declares the contact sensor class.
Declares the external stimuli manager class.
Declares the receptive field class.