AnimatLab  2
Test
SimulationWindow.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 #include "SimulationWindow.h"
12 
13 namespace AnimatSim
14 {
15 
23 {
24  m_HWND = 0;
25  m_ptPosition.Set(0, 0, 0);
26  m_ptSize.Set(500, 500, 0);
27  m_bTrackCamera = false;
28  m_bStandAlone = true;
29 }
30 
40 {
41  m_HWND = win;
42  m_ptPosition.Set(0, 0, 0);
43  m_ptSize.Set(500, 500, 0);
44  m_bTrackCamera = false;
45  m_bStandAlone = true;
46 }
47 
55 {
56 }
57 
66 void SimulationWindow::LookAtStructureID(std::string strID)
67 {
68  if(Std_IsBlank(strID))
69  m_bTrackCamera = false;
70  else
71  m_bTrackCamera = true;
72 
73  m_strLookAtStructureID = strID;
74  SetupTrackCamera(false);
75 }
76 
86 
95 void SimulationWindow::LookAtBodyID(std::string strID)
96 {
97  m_strLookAtBodyID = strID;
98  SetupTrackCamera(false);
99 }
100 
110 
120 {
121  m_bTrackCamera = bVal;
122  SetupTrackCamera(true);
123 }
124 
134 
144 
153 void SimulationWindow::WindowID(HWND win) {m_HWND = win;}
154 
164 
174 
175 #pragma region DataAccesMethods
176 
177 float *SimulationWindow::GetDataPointer(const std::string &strDataType)
178 {
179  float *lpData=NULL;
180  std::string strType = Std_CheckString(strDataType);
181 
182  //if(strType == "TIME")
183  // lpData = &m_fltTime;
184  //else
185  THROW_TEXT_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Simulator DataType: " + strDataType);
186 
187  return lpData;
188 }
189 
190 bool SimulationWindow::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
191 {
192  std::string strType = Std_CheckString(strDataType);
193 
194  if(AnimatBase::SetData(strDataType, strValue, false))
195  return true;
196 
197  if(strType == "LOOKATSTRUCTUREID")
198  {
199  LookAtStructureID(strValue);
200  return true;
201  }
202 
203  if(strType == "LOOKATBODYID")
204  {
205  LookAtBodyID(strValue);
206  return true;
207  }
208 
209  if(strType == "TRACKCAMERA")
210  {
211  UsingTrackCamera(Std_ToBool(strValue));
212  return true;
213  }
214 
215  //If it was not one of those above then we have a problem.
216  if(bThrowError)
217  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
218 
219  return false;
220 }
221 
222 void SimulationWindow::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
223 {
224  AnimatBase::QueryProperties(aryProperties);
225 
226  aryProperties.Add(new TypeProperty("LookAtStructureID", AnimatPropertyType::String, AnimatPropertyDirection::Set));
227  aryProperties.Add(new TypeProperty("LookAtBodyID", AnimatPropertyType::String, AnimatPropertyDirection::Set));
228  aryProperties.Add(new TypeProperty("TrackCamera", AnimatPropertyType::Boolean, AnimatPropertyDirection::Set));
229 }
230 
231 #pragma endregion
232 
243 void SimulationWindow::SetupTrackCamera(bool bTrackCamera, std::string strLookAtStructureID, std::string strLookAtBodyID)
244 {
245  m_bTrackCamera = bTrackCamera;
246  m_strLookAtStructureID = strLookAtStructureID;
247  m_strLookAtBodyID = strLookAtBodyID;
248  SetupTrackCamera(true);
249 }
250 
262 void SimulationWindow::SetCameraLookAt(CStdFPoint oTarget, bool bResetEyePos) {}
263 
274 void SimulationWindow::SetCameraPositionAndLookAt(CStdFPoint oCameraPos, CStdFPoint oTarget) {}
275 
288 void SimulationWindow::SetCameraPostion(CStdFPoint vCameraPos) {};
289 
290 void SimulationWindow::UpdateBackgroundColor() {}
291 
293 {}
294 
296 {}
297 
298 void SimulationWindow::Load(std::string strXml)
299 {
300  //If it is blank then skip the loading.
301  if(Std_IsBlank(strXml))
302  return;
303 
304  CStdXml oXml;
305  oXml.Deserialize(strXml);
306 
307  oXml.FindElement("WindowMgr");
308  oXml.FindChildElement("Window");
309 
310  Load(oXml);
311 }
312 
313 void SimulationWindow::Load(CStdXml &oXml)
314 {
315  AnimatBase::Load(oXml);
316 
317  oXml.IntoElem(); //Into Window Element
318 
319  if(oXml.FindChildElement("Position", false))
320  Std_LoadPoint(oXml, "Position", m_ptPosition);
321  if(oXml.FindChildElement("Size", false))
322  Std_LoadPoint(oXml, "Size", m_ptSize);
323 
324  m_bStandAlone = oXml.GetChildBool("StandAlone", m_bStandAlone);
325 
326  m_strLookAtStructureID = oXml.GetChildString("LookAtStructureID", m_strLookAtStructureID);
327  m_strLookAtBodyID = oXml.GetChildString("LookAtBodyID", m_strLookAtBodyID);
328  m_bTrackCamera = oXml.GetChildBool("TrackCamera", m_bTrackCamera);
329 
330  oXml.OutOfElem(); //OutOf Window Element
331 
332  if(m_ptPosition.x < 0 || m_ptPosition.y < 0)
333  THROW_TEXT_ERROR(Al_Err_lSimWinPosInvalid, Al_Err_strSimWinPosInvalid, "POS: (" + STR(m_ptPosition.x) + ", " + STR(m_ptPosition.y) + ")");
334  if(m_ptSize.x < 0 || m_ptSize.y < 0)
335  THROW_TEXT_ERROR(Al_Err_lSimWinSizeInvalid, Al_Err_strSimWinSizeInvalid, "Size: (" + STR(m_ptSize.x) + ", " + STR(m_ptSize.y) + ")");
336 }
337 
338 }//end namespace AnimatSim
virtual void SetupTrackCamera(bool bResetEyePos)=0
Sets up the camera tracking.
Base class file for all Animat simulation objects.
virtual void SetCameraPostion(CStdFPoint vCameraPos)
Manually sets a camera position.
Root namespace for the base simulation library for AnimatLab.
virtual float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
~SimulationWindow(void)
Destructor.
virtual std::string LookAtStructureID()
Gets the look at structure GUID ID.
Class that stores information about types for QueryProperty information.
Definition: TypeProperty.h:35
virtual bool StandAlone()
Gets whether this window stands alone from all others.
virtual std::string LookAtBodyID()
Gets the GUID ID of the RigidBody to look at.
bool m_bStandAlone
true if the window is seperate from all other windows.
CStdFPoint m_ptSize
Size of the window.
virtual void OnLoseFocus()
Called by the GUI when this window loses the focus.
HWND m_HWND
Handle of the hwnd.
Declares the simulation Windows Form.
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 bool UsingTrackCamera()
Gets wheter camera tracking is being used.
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 void SetCameraLookAt(CStdFPoint oTarget, bool bResetEyePos)
Manually sets a camera look at position.
CStdFPoint m_ptPosition
The position of the window.
bool Std_ToBool(int iVal)
Converts a value toa bool.
virtual void Load(StdUtils::CStdXml &oXml)
Loads the item using an XML data packet.
Definition: AnimatBase.cpp:771
virtual void OnGetFocus()
Called by the GUI when this window gets the focus.
bool Std_IsBlank(std::string strVal)
Trims a string and tests if a string is blank.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
bool Std_LoadPoint(CStdXml &oXml, std::string strName, CStdIPoint &oPoint, bool bThrowError)
Standard load point.
virtual void SetCameraPositionAndLookAt(CStdFPoint oCameraPos, CStdFPoint oTarget)
Manually sets a camera position and look at position.
SimulationWindow(void)
Default constructor.
virtual HWND WindowID()
Gets the HWND window identifier.
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
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.