00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #ifndef _TASKEDSIMULATION_H_
00049 #define _TASKEDSIMULATION_H_
00050
00051 #include "simulation.h"
00052 #include "simulationtaskhandle.h"
00053 #include <string>
00054 #include <selforg/quickmp.h>
00055
00056 namespace lpzrobots {
00057
00058 class TaskedSimulation : public Simulation {
00059 public:
00060 TaskedSimulation() :
00061 Simulation(), taskId(0), simTaskHandle(0) {
00062 useOdeThread = false;
00063 useOsgThread = false;
00064 useQMPThreads = false;
00065 inTaskedMode = true;
00066 }
00067
00068 virtual ~TaskedSimulation() {
00069 }
00070
00071
00072 virtual void start(const OdeHandle&, const OsgHandle&, GlobalData& globalData,
00073 SimulationTaskHandle& simTaskHandle, int taskId) {
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 virtual bool restart(const OdeHandle&, const OsgHandle&, GlobalData& globalData, SimulationTaskHandle&,
00085 int taskId) {
00086 return false;
00087 }
00088
00089
00090
00091
00092
00093
00094
00095 virtual void addCallback(GlobalData& globalData, bool draw, bool pause, bool control, SimulationTaskHandle&,
00096 int taskId) {
00097 }
00098
00099
00100
00101
00102
00103 virtual bool command(const OdeHandle&, const OsgHandle&, GlobalData& globalData, int key, bool down,
00104 SimulationTaskHandle&, int taskId) {
00105 return false;
00106 }
00107
00108
00109
00110
00111
00112
00113 void setTaskId(int taskId) {
00114 this->taskId = taskId;
00115 if (taskId == 0)
00116 noGraphics = false;
00117 else
00118 noGraphics = true;
00119
00120 osgHandle.noGraphics=noGraphics;
00121 }
00122
00123 void setTaskNameSuffix(std::string nameSuffix) {
00124 windowName.append(nameSuffix);
00125 }
00126
00127
00128
00129
00130
00131
00132 void setSimTaskHandle(SimulationTaskHandle& simTaskHandle) {
00133 this->simTaskHandle = &simTaskHandle;
00134 }
00135
00136 private:
00137
00138
00139
00140
00141 void processCmdLine(int argc, char** argv) {
00142 Simulation::processCmdLine(argc, argv);
00143 useOdeThread = false;
00144 useOsgThread = false;
00145 useQMPThreads = false;
00146 inTaskedMode = true;
00147 if (taskId!=0) {
00148 noGraphics = true;
00149
00150 osgHandle.noGraphics=noGraphics;
00151 }
00152 }
00153
00154
00155
00156
00157
00158 virtual bool storeCfg(const char* filenamestem, const std::list<std::string>& comments = std::list<std::string>()) {
00159 return true;
00160 }
00161
00162
00163
00164
00165
00166 bool restoreCfg(const char* filenamestem) {
00167 bool result = Simulation::restoreCfg(filenamestem);
00168 useOdeThread = false;
00169 useOsgThread = false;
00170 useQMPThreads = false;
00171 inTaskedMode = true;
00172 if (taskId!=0) {
00173 noGraphics = true;
00174
00175 osgHandle.noGraphics=noGraphics;
00176 }
00177 return result;
00178 }
00179
00180 int taskId;
00181 SimulationTaskHandle* simTaskHandle;
00182 std::string nameSuffix;
00183
00184 void start(const OdeHandle& odeHandle, const OsgHandle& osgHandle, GlobalData& globalData) {
00185 QMP_CRITICAL(61);
00186 start(odeHandle, osgHandle, globalData, *simTaskHandle, taskId);
00187 QMP_END_CRITICAL(61);
00188 }
00189
00190 bool restart(const OdeHandle& odeHandle, const OsgHandle& osgHandle, GlobalData& globalData) {
00191 bool doRestart;
00192 QMP_CRITICAL(62);
00193 doRestart = restart(odeHandle, osgHandle, globalData, *simTaskHandle, taskId);
00194 QMP_END_CRITICAL(62);
00195 return doRestart;
00196 }
00197
00198 virtual void addCallback(GlobalData& globalData, bool draw, bool pause, bool control) {
00199 QMP_CRITICAL(63);
00200 addCallback(globalData, draw, pause, control, *simTaskHandle, taskId);
00201 QMP_END_CRITICAL(63);
00202 }
00203 ;
00204
00205 bool command(const OdeHandle& odeHandle, const OsgHandle& osgHandle, GlobalData& globalData, int key, bool down) {
00206 return command(odeHandle, osgHandle, globalData, key, down, *simTaskHandle, taskId);
00207 }
00208
00209 };
00210
00211 }
00212
00213 #endif