AnimatLab  2
Test
SimulationMgr.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 "BoundingBox.h"
12 #include "MovableItem.h"
13 #include "BodyPart.h"
14 #include "Joint.h"
15 #include "ReceptiveField.h"
16 #include "ContactSensor.h"
17 #include "RigidBody.h"
18 #include "Structure.h"
19 #include "NeuralModule.h"
20 #include "Adapter.h"
21 #include "NervousSystem.h"
22 #include "Organism.h"
23 #include "ActivatedItem.h"
24 #include "ActivatedItemMgr.h"
25 #include "DataChartMgr.h"
26 #include "ExternalStimuliMgr.h"
27 #include "KeyFrame.h"
28 #include "SimulationRecorder.h"
29 #include "OdorType.h"
30 #include "Odor.h"
31 #include "Light.h"
32 #include "LightManager.h"
33 #include "Simulator.h"
34 #include "SimulationThread.h"
35 #include "SimulationMgr.h"
36 
37 #include "RobotInterface.h"
38 #include "RobotIOControl.h"
39 #include "RobotPartInterface.h"
40 
41 namespace AnimatSim
42 {
43 
44 static Simulator *g_lpActiveSim = NULL;
45 
46 SimulationMgr::SimulationMgr(void)
47 {
48 }
49 
50 SimulationMgr::~SimulationMgr(void)
51 {
52 try
53 {
54  ShutdownAllSimulations();
55 }
56 catch(...)
57 {Std_TraceMsg(0, "Caught Error in desctructor of SimulationMgr\r\n", "", -1, false, true);}
58 }
59 
61 {
62  static SimulationMgr g_SimMgrInstance;
63  return g_SimMgrInstance;
64 }
65 
66 void ActiveSim(Simulator *lpActive)
67 {
68  g_lpActiveSim = lpActive;
69 }
70 
71 Simulator *ActiveSim()
72 {
73  return g_lpActiveSim;
74 }
75 
76 SimulationThread *SimulationMgr::CreateSimulation(std::string strSimFile, bool bForceNoWindows)
77 {
78  SimulationThread *lpThread = NULL;
79 
80  try
81  {
82  lpThread = new SimulationThread();
83  lpThread->StartSimulation(strSimFile, bForceNoWindows);
84  m_arySimThreads.Add(lpThread);
85  return lpThread;
86  }
87  catch(CStdErrorInfo oError)
88  {
89  if(lpThread) delete lpThread;
90  RELAY_ERROR(oError);
91  return NULL;
92  }
93  catch(...)
94  {
95  if(lpThread) delete lpThread;
96  THROW_ERROR(Al_Err_lUnknownError, Al_Err_strUnknownError);
97  return NULL;
98  }
99 }
100 
101 void SimulationMgr::ShutdownAllSimulations()
102 {
103  int iSize = m_arySimThreads.GetSize();
104  for(int iIdx=0; iIdx<iSize; iIdx++)
105  m_arySimThreads[iIdx]->ShutdownSimulation();
106 
107  m_arySimThreads.RemoveAll();
108 }
109 
110 AnimatBase *SimulationMgr::FindByID(std::string strID, bool bThrowError)
111 {
112  AnimatBase *lpFound = NULL;
113  int iSize = m_arySimThreads.GetSize();
114  for(int iIdx=0; iIdx<iSize; iIdx++)
115  {
116  Simulator *lpSim = m_arySimThreads[iIdx]->Sim();
117  if(lpSim)
118  lpFound = lpSim->FindByID(strID, false);
119  if(lpFound)
120  return lpFound;
121  }
122 
123  if(bThrowError)
124  THROW_PARAM_ERROR(Al_Err_lIDNotFound, Al_Err_strIDNotFound, "ID", strID);
125 
126  return NULL;
127 }
128 
129 
130 }
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.
Simulates the entire environment.
Definition: Simulator.h:31
Root namespace for the base simulation library for AnimatLab.
Declares the body part class.
Information about the standard error.
Definition: StdErrorInfo.h:19
static SimulationMgr & Instance()
Singleton accessor for this class.
Declares the key frame class.
Declares the joint class.
Declares the organism class.
Declares a light object.
Declares the activated item class.
Declares a light manager object.
Declares the bounding box class.
Declares the node class.
virtual AnimatBase * FindByID(std::string strID, bool bThrowError=true)
Searches for the object with the specified ID.
Definition: Simulator.cpp:4008
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.
Animat base class.
Definition: AnimatBase.h:36
Declares the data chart manager class.
Declares the rigid body class.
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.
Declares the contact sensor class.
Declares the external stimuli manager class.
Declares the receptive field class.