qtopengl_main_window.cpp
Go to the documentation of this file.
1 
7 #include "qtopengl_widget.h"
8 #include "qtopengl_log_stream.h"
10 #include "qtopengl_main_window.h"
11 
12 #include <argos3/core/config.h>
13 #include <argos3/core/utility/plugins/dynamic_loading.h>
14 #include <argos3/core/utility/logging/argos_log.h>
15 #include <argos3/core/simulator/simulator.h>
16 #include <argos3/core/simulator/loop_functions.h>
17 
18 #include <QtCore/QVariant>
19 #include <QAction>
20 #include <QActionGroup>
21 #include <QtWidgets/QApplication>
22 #include <QtWidgets/QDockWidget>
23 #include <QtWidgets/QHeaderView>
24 #include <QtWidgets/QLCDNumber>
25 #include <QtWidgets/QPushButton>
26 #include <QtWidgets/QSpinBox>
27 #include <QtWidgets/QDoubleSpinBox>
28 #include <QtWidgets/QStatusBar>
29 #include <QtWidgets/QWidget>
30 #include <QLabel>
31 #include <QCloseEvent>
32 #include <QMessageBox>
33 #include <QDir>
34 #include <QFile>
35 #include <QTextStream>
36 #include <QToolBar>
37 #include <QLayout>
38 #include <QMenuBar>
39 #include <QSettings>
40 
41 namespace argos {
42 
43  /****************************************/
44  /****************************************/
45 
46  class CQTOpenGLLayout : public QLayout {
47 
48  public:
49 
51  m_pcQTOpenGLItem(nullptr) {
52  setContentsMargins(0, 0, 0, 0);
53  }
54 
55  virtual ~CQTOpenGLLayout() {
56  if(m_pcQTOpenGLItem != nullptr) {
57  delete m_pcQTOpenGLItem;
58  }
59  }
60 
61  virtual void addItem(QLayoutItem* item) {
62  if(m_pcQTOpenGLItem != nullptr) {
63  delete m_pcQTOpenGLItem;
64  }
65  m_pcQTOpenGLItem = item;
66  }
67  virtual int count() const {
68  return (m_pcQTOpenGLItem != nullptr) ? 1 : 0;
69  }
70 
71  virtual QLayoutItem* itemAt(int index) const {
72  return (index == 0) ? m_pcQTOpenGLItem : nullptr;
73  }
74 
75  virtual QLayoutItem* takeAt(int index) {
76  if(index == 0) {
77  QLayoutItem* pcRetVal = m_pcQTOpenGLItem;
78  m_pcQTOpenGLItem = nullptr;
79  return pcRetVal;
80  }
81  else {
82  return nullptr;
83  }
84  }
85 
86  virtual QSize sizeHint () const {
87  return QSize(640,480);
88  }
89  virtual void setGeometry(const QRect& r) {
90  /* Set the layout geometry */
91  QLayout::setGeometry(r);
92  if(m_pcQTOpenGLItem != nullptr) {
93  /* Calculate the candidate sizes for the QTOpenGL widget */
94  /* One is height-driven */
95  QRect cCandidate1(r.x(), r.y(), (r.height() * 4) / 3, r.height());
96  /* The other is width-driven */
97  QRect cCandidate2(r.x(), r.y(), r.width(), (r.width() * 3) / 4);
98  /* Pick the one that fits the rectangle better */
99  if(r.contains(cCandidate1)) {
100  /* Horizontal padding needed */
101  int nPadding = (r.width() - cCandidate1.width()) / 2;
102  cCandidate1.translate(nPadding, 0);
103  m_pcQTOpenGLItem->setGeometry(cCandidate1);
104  }
105  else {
106  /* Vertical padding needed */
107  int nPadding = (r.height() - cCandidate2.height()) / 2;
108  cCandidate2.translate(0, nPadding);
109  m_pcQTOpenGLItem->setGeometry(cCandidate2);
110  }
111  }
112  }
113 
114  private:
115 
116  QLayoutItem* m_pcQTOpenGLItem;
117 
118  };
119 
120  /****************************************/
121  /****************************************/
122 
124  m_pcUserFunctions(nullptr) {
125  /* Main window settings */
126  std::string strTitle;
127  GetNodeAttributeOrDefault<std::string>(t_tree, "title", strTitle, "ARGoS v" ARGOS_VERSION "-" ARGOS_RELEASE);
128  setWindowTitle(tr(strTitle.c_str()));
129  /* Restore settings, if any */
130  ReadSettingsPreCreation();
131  /* Add a status bar */
132  m_pcStatusbar = new QStatusBar(this);
133  setStatusBar(m_pcStatusbar);
134  /* Create actions */
135  CreateExperimentActions();
136  CreateCameraActions();
137  // CreatePOVRayActions();
138  CreateHelpActions();
139  /* Create user functions */
140  CreateUserFunctions(t_tree);
141  /* Create the central widget */
142  CreateOpenGLWidget(t_tree);
143  /* Create menus */
144  CreateExperimentMenu();
145  CreateCameraMenu();
146  // CreatePOVRayMenu();
147  CreateHelpMenu();
148  /* Create toolbars */
149  CreateExperimentToolBar();
150  CreateCameraToolBar();
151  /* Create the message dock window */
152  CreateLogMessageDock();
153  /* Restore settings, if any */
154  ReadSettingsPostCreation();
155  /* Creates the signal/slot connections */
156  CreateConnections();
157  /* Set experiment state */
158  m_eExperimentState = EXPERIMENT_INITIALIZED;
159  /* Should we play instantly? */
160  bool bAutoPlay = false;
161  GetNodeAttributeOrDefault(t_tree, "autoplay", bAutoPlay, bAutoPlay);
162  if (bAutoPlay) {
163  if (m_pcOpenGLWidget->GetFrameGrabData().HeadlessGrabbing) {
165  } else {
166  PlayExperiment();
167  }
168  }
169  }
170 
171  /****************************************/
172  /****************************************/
173 
175  delete m_pcUserFunctions;
176  delete m_pcLogStream;
177  delete m_pcLogErrStream;
178  if(m_bWasLogColored) {
181  }
182  }
183 
184  /****************************************/
185  /****************************************/
186 
187  void CQTOpenGLMainWindow::ReadSettingsPreCreation() {
188  QSettings cSettings;
189  cSettings.beginGroup("MainWindow");
190  resize(cSettings.value("size", QSize(640,480)).toSize());
191  move(cSettings.value("position", QPoint(0,0)).toPoint());
192  m_strIconDir = QString::fromStdString(CSimulator::GetInstance().GetInstallationDirectory());
193  m_strIconDir += "/include/argos3/plugins/simulator/visualizations/qt-opengl/icons/";
194  m_strTextureDir = QString::fromStdString(CSimulator::GetInstance().GetInstallationDirectory());
195  m_strTextureDir += "/include/argos3/plugins/simulator/visualizations/qt-opengl/textures/";
196  m_strModelDir = QString::fromStdString(CSimulator::GetInstance().GetInstallationDirectory());
197  m_strModelDir += "/include/argos3/plugins/simulator/visualizations/qt-opengl/models/";
198  cSettings.endGroup();
199  }
200 
201  /****************************************/
202  /****************************************/
203 
204  void CQTOpenGLMainWindow::ReadSettingsPostCreation() {
205  QSettings cSettings;
206  cSettings.beginGroup("MainWindow");
207  restoreState(cSettings.value("docks").toByteArray());
208  cSettings.endGroup();
209  }
210 
211  /****************************************/
212  /****************************************/
213 
214  void CQTOpenGLMainWindow::WriteSettings() {
215  QSettings cSettings;
216  cSettings.beginGroup("MainWindow");
217  cSettings.setValue("docks", saveState());
218  cSettings.setValue("size", size());
219  cSettings.setValue("position", pos());
220  cSettings.endGroup();
221  }
222 
223  /****************************************/
224  /****************************************/
225 
226  void CQTOpenGLMainWindow::CreateExperimentActions() {
227  /* Add the play action */
228  QIcon cPlayIcon;
229  cPlayIcon. addPixmap(QPixmap(m_strIconDir + "/play.png"));
230  m_pcPlayAction = new QAction(cPlayIcon, tr("&Play"), this);
231  m_pcPlayAction->setShortcut(Qt::Key_P);
232  m_pcPlayAction->setToolTip(tr("Play experiment"));
233  m_pcPlayAction->setStatusTip(tr("Play experiment"));
234  if(! CSimulator::GetInstance().IsRealTimeClock()) {
235  /* Add the step action */
236  QIcon cStepIcon;
237  cStepIcon.addPixmap(QPixmap(m_strIconDir + "/step.png"));
238  m_pcStepAction = new QAction(cStepIcon, tr("&Step"), this);
239  m_pcStepAction->setToolTip(tr("Step experiment"));
240  m_pcStepAction->setStatusTip(tr("Step experiment"));
241  m_pcStepAction->setShortcut(Qt::Key_X);
242  /* Add the fast forward action */
243  QIcon cFastForwardIcon;
244  cFastForwardIcon.addPixmap(QPixmap(m_strIconDir + "/fast_forward.png"));
245  m_pcFastForwardAction = new QAction(cFastForwardIcon, tr("&Fast Forward"), this);
246  m_pcFastForwardAction->setToolTip(tr("Fast forward experiment"));
247  m_pcFastForwardAction->setStatusTip(tr("Fast forward experiment"));
248  m_pcFastForwardAction->setShortcut(Qt::Key_F);
249  /* Add the pause action */
250  QIcon cPauseIcon;
251  cPauseIcon. addPixmap(QPixmap(m_strIconDir + "/pause.png"));
252  m_pcPauseAction = new QAction(cPauseIcon, tr("&Pause"), this);
253  m_pcPauseAction->setShortcut(Qt::Key_O);
254  m_pcPauseAction->setToolTip(tr("Pause experiment"));
255  m_pcPauseAction->setStatusTip(tr("Pause experiment"));
256  m_pcPauseAction->setEnabled(false);
257  }
258  /* Add the terminate action */
259  QIcon cTerminateIcon;
260  cTerminateIcon.addPixmap(QPixmap(m_strIconDir + "/stop.png"));
261  m_pcTerminateAction = new QAction(cTerminateIcon, tr("&Terminate"), this);
262  m_pcTerminateAction->setShortcut(Qt::Key_T);
263  m_pcTerminateAction->setToolTip(tr("Terminate experiment"));
264  m_pcTerminateAction->setStatusTip(tr("Terminate experiment"));
265  m_pcTerminateAction->setEnabled(false);
266  /* Add the reset action */
267  QIcon cResetIcon;
268  cResetIcon.addPixmap(QPixmap(m_strIconDir + "/reset.png"));
269  m_pcResetAction = new QAction(cResetIcon, tr("&Reset"), this);
270  m_pcResetAction->setToolTip(tr("Reset experiment"));
271  m_pcResetAction->setStatusTip(tr("Reset experiment"));
272  m_pcResetAction->setShortcut(Qt::Key_R);
273  m_pcResetAction->setEnabled(false);
274  /* Add the capture action */
275  QIcon cCaptureIcon;
276  cCaptureIcon.addPixmap(QPixmap(m_strIconDir + "/record.png"));
277  m_pcCaptureAction = new QAction(cCaptureIcon, tr("&Capture"), this);
278  m_pcCaptureAction->setToolTip(tr("Capture frames"));
279  m_pcCaptureAction->setStatusTip(tr("Capture frames"));
280  m_pcCaptureAction->setCheckable(true);
281  m_pcCaptureAction->setShortcut(Qt::Key_C);
282  /* Add the quit action */
283  m_pcQuitAction = new QAction(tr("&Quit"), this);
284  m_pcQuitAction->setStatusTip(tr("Quit the simulator"));
285  }
286 
287  /****************************************/
288  /****************************************/
289 
290  void CQTOpenGLMainWindow::CreateCameraActions() {
291  /* Add the switch camera buttons */
292  m_pcSwitchCameraActionGroup = new QActionGroup(this);
293  QIcon cCameraIcon;
294  cCameraIcon.addPixmap(QPixmap(m_strIconDir + "/camera.png"));
295  for(UInt32 i = 0; i < 12; ++i) {
296  QAction* pcAction = new QAction(cCameraIcon, tr(QString("Camera %1").arg(i+1).toLatin1().data()), m_pcSwitchCameraActionGroup);
297  pcAction->setToolTip(tr(QString("Switch to camera %1").arg(i+1).toLatin1().data()));
298  pcAction->setStatusTip(tr(QString("Switch to camera %1").arg(i+1).toLatin1().data()));
299  pcAction->setCheckable(true);
300  pcAction->setShortcut(Qt::Key_F1 + i);
301  pcAction->setData(i);
302  m_pcSwitchCameraActions.push_back(pcAction);
303  }
304  m_pcSwitchCameraActions.first()->setChecked(true);
305  /* Add the show camera XML button */
306  m_pcShowCameraXMLAction = new QAction(tr("&Show XML..."), this);
307  m_pcShowCameraXMLAction->setStatusTip(tr("Show XML configuration for all cameras"));
308  }
309 
310  /****************************************/
311  /****************************************/
312 
313  // void CQTOpenGLMainWindow::CreatePOVRayActions() {
314  // /* Add the POVRay XML button */
315  // QIcon cPOVRayXMLIcon;
316  // m_pcPOVRayXMLAction = new QAction(cPOVRayXMLIcon, tr("&Edit XML"), this);
317  // m_pcPOVRayXMLAction->setToolTip(tr("Edit POV-Ray XML configuration"));
318  // m_pcPOVRayXMLAction->setStatusTip(tr("Edit POV-Ray XML configuration"));
319  // /* Add the POVRay Preview button */
320  // QIcon cPOVRayPreviewIcon;
321  // m_pcPOVRayPreviewAction = new QAction(cPOVRayPreviewIcon, tr("&Preview"), this);
322  // m_pcPOVRayPreviewAction->setToolTip(tr("Preview POV-Ray rendering of this scene"));
323  // m_pcPOVRayPreviewAction->setStatusTip(tr("Preview POV-Ray rendering of this scene"));
324  // }
325 
326  /****************************************/
327  /****************************************/
328 
329  void CQTOpenGLMainWindow::CreateHelpActions() {
330  /* Add the 'about qt' button */
331  m_pcAboutQTAction = new QAction(tr("About &Qt"), this);
332  m_pcAboutQTAction->setStatusTip(tr("Show the Qt library's About box"));
333  }
334 
335  /****************************************/
336  /****************************************/
337 
338  void CQTOpenGLMainWindow::CreateExperimentToolBar() {
339  m_pcExperimentToolBar = addToolBar(tr("Experiment"));
340  m_pcExperimentToolBar->setObjectName("ExperimentToolBar");
341  m_pcExperimentToolBar->setIconSize(QSize(32,32));
342  m_pcCurrentStepLCD = new QLCDNumber(m_pcExperimentToolBar);
343  m_pcCurrentStepLCD->setToolTip(tr("Current step"));
344  m_pcCurrentStepLCD->setDigitCount(6);
345  m_pcCurrentStepLCD->setSegmentStyle(QLCDNumber::Flat);
346  m_pcExperimentToolBar->addWidget(m_pcCurrentStepLCD);
347  m_pcExperimentToolBar->addSeparator();
348  if(! CSimulator::GetInstance().IsRealTimeClock()) {
349  m_pcExperimentToolBar->addAction(m_pcStepAction);
350  }
351  m_pcExperimentToolBar->addAction(m_pcPlayAction);
352  if(! CSimulator::GetInstance().IsRealTimeClock()) {
353  m_pcExperimentToolBar->addAction(m_pcPauseAction);
354  m_pcExperimentToolBar->addAction(m_pcFastForwardAction);
355  m_pcDrawFrameEvery = new QSpinBox(m_pcExperimentToolBar);
356  m_pcDrawFrameEvery->setToolTip(tr("Draw frame every X steps when in fast-forward"));
357  m_pcDrawFrameEvery->setMinimum(1);
358  m_pcDrawFrameEvery->setMaximum(999);
359  m_pcDrawFrameEvery->setValue(1);
360  m_pcExperimentToolBar->addWidget(m_pcDrawFrameEvery);
361  }
362  m_pcExperimentToolBar->addSeparator();
363  m_pcExperimentToolBar->addAction(m_pcTerminateAction);
364  m_pcExperimentToolBar->addAction(m_pcResetAction);
365  m_pcExperimentToolBar->addSeparator();
366  m_pcExperimentToolBar->addAction(m_pcCaptureAction);
367  }
368 
369  /****************************************/
370  /****************************************/
371 
372  void CQTOpenGLMainWindow::CreateExperimentMenu() {
373  m_pcExperimentMenu = menuBar()->addMenu(tr("&Experiment"));
374  m_pcExperimentMenu->addAction(m_pcPlayAction);
375  if(! CSimulator::GetInstance().IsRealTimeClock()) {
376  m_pcExperimentMenu->addAction(m_pcPauseAction);
377  m_pcExperimentMenu->addAction(m_pcFastForwardAction);
378  m_pcExperimentMenu->addAction(m_pcStepAction);
379  }
380  m_pcExperimentMenu->addSeparator();
381  m_pcExperimentMenu->addAction(m_pcTerminateAction);
382  m_pcExperimentMenu->addAction(m_pcResetAction);
383  m_pcExperimentMenu->addSeparator();
384  m_pcExperimentMenu->addAction(m_pcCaptureAction);
385  m_pcExperimentMenu->addSeparator();
386  m_pcExperimentMenu->addAction(m_pcQuitAction);
387  }
388 
389  /****************************************/
390  /****************************************/
391 
392  void CQTOpenGLMainWindow::CreateCameraToolBar() {
393  m_pcCameraToolBar = new QToolBar(tr("Camera"));
394  m_pcCameraToolBar->setAllowedAreas(Qt::LeftToolBarArea |
395  Qt::RightToolBarArea |
396  Qt::BottomToolBarArea);
397  m_pcCameraToolBar->setObjectName("CameraToolBar");
398  m_pcCameraToolBar->setIconSize(QSize(32,32));
399  m_pcCameraToolBar->addActions(m_pcSwitchCameraActions);
400  m_pcCameraToolBar->addSeparator();
401  m_pcFocalLength = new QDoubleSpinBox(m_pcCameraToolBar);
402  m_pcFocalLength->setToolTip(tr("Set the focal length of the current camera"));
403  m_pcFocalLength->setSuffix("mm");
404  m_pcFocalLength->setDecimals(1);
405  m_pcFocalLength->setSingleStep(1.0f);
406  m_pcFocalLength->setRange(1.0f, 999.0f);
407  m_pcFocalLength->setValue(m_pcOpenGLWidget->GetCamera().GetPlacement(0).LensFocalLength * 1000.0f);
408  m_pcCameraToolBar->addWidget(m_pcFocalLength);
409  addToolBar(Qt::LeftToolBarArea, m_pcCameraToolBar);
410  }
411 
412  /****************************************/
413  /****************************************/
414 
415  void CQTOpenGLMainWindow::CreateCameraMenu() {
416  m_pcCameraMenu = menuBar()->addMenu(tr("&Camera"));
417  m_pcCameraMenu->addActions(m_pcSwitchCameraActions);
418  m_pcCameraMenu->addAction(m_pcShowCameraXMLAction);
419  }
420 
421  /****************************************/
422  /****************************************/
423 
424  // void CQTOpenGLMainWindow::CreatePOVRayMenu() {
425  // m_pcPOVRayMenu = menuBar()->addMenu(tr("&POVRay"));
426  // m_pcPOVRayMenu->addAction(m_pcPOVRayPreviewAction);
427  // m_pcPOVRayMenu->addAction(m_pcPOVRayXMLAction);
428  // }
429 
430  /****************************************/
431  /****************************************/
432 
433  void CQTOpenGLMainWindow::CreateHelpMenu() {
434  m_pcHelpMenu = menuBar()->addMenu(tr("&?"));
435  m_pcHelpMenu->addAction(m_pcAboutQTAction);
436  }
437 
438  /****************************************/
439  /****************************************/
440 
441  void CQTOpenGLMainWindow::CreateOpenGLWidget(TConfigurationNode& t_tree) {
442  /* Create the surface format */
443  QSurfaceFormat cFormat = QSurfaceFormat::defaultFormat();
444  cFormat.setSamples(4);
445  cFormat.setDepthBufferSize(24);
446  /* Create the widget */
447  QWidget* pcPlaceHolder = new QWidget(this);
448  m_pcOpenGLWidget = new CQTOpenGLWidget(pcPlaceHolder, *this, *m_pcUserFunctions);
449  m_pcOpenGLWidget->setFormat(cFormat);
450  m_pcOpenGLWidget->setCursor(QCursor(Qt::OpenHandCursor));
451  if(NodeExists(t_tree, "camera")) {
452  TConfigurationNode& tCameraNode = GetNode(t_tree, "camera");
453  m_pcOpenGLWidget->GetCamera().Init(tCameraNode);
454  }
455  m_pcOpenGLWidget->GetFrameGrabData().Init(t_tree);
456 
457  /* Set headless grabbing frame size after it has been parsed */
458  if (m_pcOpenGLWidget->GetFrameGrabData().HeadlessGrabbing) {
459  setMinimumSize(m_pcOpenGLWidget->GetFrameGrabData().Size);
460  m_pcOpenGLWidget->SetDrawFrameEvery(
461  m_pcOpenGLWidget->GetFrameGrabData().HeadlessFrameRate);
462  } else {
463  setMinimumSize(QSize(320, 240));
464  }
465  /* Invert mouse controls? */
466  bool bInvertMouse;
467  GetNodeAttributeOrDefault(t_tree, "invert_mouse", bInvertMouse, false);
468  m_pcOpenGLWidget->SetInvertMouse(bInvertMouse);
469  /* Show boundary walls? */
470  bool bShowBoundary;
471  GetNodeAttributeOrDefault(t_tree, "show_boundary", bShowBoundary, true);
472  m_pcOpenGLWidget->SetShowBoundary(bShowBoundary);
473  /* Set the window as the central widget */
474  auto* pcQTOpenGLLayout = new CQTOpenGLLayout();
475  pcQTOpenGLLayout->addWidget(m_pcOpenGLWidget);
476  pcPlaceHolder->setLayout(pcQTOpenGLLayout);
477  setCentralWidget(pcPlaceHolder);
478  /* Initialize the user functions */
479  if(NodeExists(t_tree, "user_functions")) {
480  /* Use the passed user functions */
481  /* Get data from XML */
482  TConfigurationNode tNode = GetNode(t_tree, "user_functions");
483  m_pcUserFunctions->Init(tNode);
484  }
485  }
486 
487  /****************************************/
488  /****************************************/
489 
490  void CQTOpenGLMainWindow::CreateLogMessageDock() {
491  /* Store the log color flag to be able to restore at exit */
492  m_bWasLogColored = LOG.IsColoredOutput();
493  /* Create a dockable window */
494  m_pcLogDock = new QDockWidget(tr("Log"), this);
495  m_pcLogDock->setObjectName("LogDockWindow");
496  m_pcLogDock->setFeatures(QDockWidget::DockWidgetMovable |
497  QDockWidget::DockWidgetFloatable);
498  m_pcLogDock->setAllowedAreas(Qt::LeftDockWidgetArea |
499  Qt::RightDockWidgetArea |
500  Qt::BottomDockWidgetArea);
501  /* Create a textual window to be used as a buffer */
502  m_pcDockLogBuffer = new QTextEdit();
503  m_pcDockLogBuffer->setReadOnly(true);
504  LOG.Flush(); /* Write all the pending stuff */
505  LOG.DisableColoredOutput(); /* Colors are not necessary */
506  m_pcDockLogBuffer->append("<b>[t=0]</b> Log started."); /* Write something in the buffer */
507  /* Redirect stdout to the buffer */
508  m_pcLogStream = new CQTOpenGLLogStream(LOG.GetStream(), m_pcDockLogBuffer);
509  /* Add the dockable window to the main widget */
510  m_pcLogDock->setWidget(m_pcDockLogBuffer);
511  addDockWidget(Qt::RightDockWidgetArea, m_pcLogDock);
512  /* Create a dockable window */
513  m_pcLogErrDock = new QDockWidget(tr("LogErr"), this);
514  m_pcLogErrDock->setObjectName("LogErrDockWindow");
515  m_pcLogErrDock->setFeatures(QDockWidget::DockWidgetMovable |
516  QDockWidget::DockWidgetFloatable);
517  m_pcLogErrDock->setAllowedAreas(Qt::LeftDockWidgetArea |
518  Qt::RightDockWidgetArea |
519  Qt::BottomDockWidgetArea);
520  /* Create a textual window to be used as a buffer */
521  m_pcDockLogErrBuffer = new QTextEdit();
522  m_pcDockLogErrBuffer->setReadOnly(true);
523  LOGERR.Flush(); /* Write all the pending stuff */
524  LOGERR.DisableColoredOutput(); /* Colors are not necessary */
525  m_pcDockLogErrBuffer->append("<b>[t=0]</b> LogErr started."); /* Write something in the buffer */
526  /* Redirect stderr to the buffer */
527  m_pcLogErrStream = new CQTOpenGLLogStream(LOGERR.GetStream(), m_pcDockLogErrBuffer);
528  m_pcLogErrDock->setWidget(m_pcDockLogErrBuffer);
529  /* Add the dockable window to the main widget */
530  addDockWidget(Qt::RightDockWidgetArea, m_pcLogErrDock);
531 
532  }
533 
534  /****************************************/
535  /****************************************/
536 
537  void CQTOpenGLMainWindow::CreateConnections() {
538  /* Play button pressed */
539  connect(m_pcPlayAction, SIGNAL(triggered()),
540  this, SLOT(PlayExperiment()));
541  /* Reset button pressed */
542  connect(m_pcResetAction, SIGNAL(triggered()),
543  this, SLOT(ResetExperiment()));
544  /* A experiment step has been completed */
545  connect(m_pcOpenGLWidget, SIGNAL(StepDone(int)),
546  m_pcCurrentStepLCD, SLOT(display(int)));
547  /* The experiment has been completed */
548  connect(m_pcOpenGLWidget, SIGNAL(ExperimentDone()),
549  this, SLOT(TerminateExperiment()));
550  /* The experiment has been completed */
551  connect(m_pcTerminateAction, SIGNAL(triggered()),
552  this, SLOT(TerminateExperiment()));
553  if(! CSimulator::GetInstance().IsRealTimeClock()) {
554  /* Pause button pressed */
555  connect(m_pcPauseAction, SIGNAL(triggered()),
556  this, SLOT(PauseExperiment()));
557  /* Step button pressed */
558  connect(m_pcStepAction, SIGNAL(triggered()),
559  this, SLOT(StepExperiment()));
560  /* Fast forward button pressed */
561  connect(m_pcFastForwardAction, SIGNAL(triggered()),
562  this, SLOT(FastForwardExperiment()));
563  /* 'Draw frame every' spin box value changed */
564  connect(m_pcDrawFrameEvery, SIGNAL(valueChanged(int)),
565  m_pcOpenGLWidget, SLOT(SetDrawFrameEvery(int)));
566  }
567  // /* POV-Ray XML button pressed */
568  // connect(m_pcPOVRayXMLAction, SIGNAL(triggered()),
569  // this, SLOT(POVRaySceneXMLPopUp()));
570  // /* POV-Ray XML button pressed */
571  // connect(m_pcPOVRayPreviewAction, SIGNAL(triggered()),
572  // this, SLOT(POVRayScenePreview()));
573  /* Capture button toggled */
574  connect(m_pcCaptureAction, SIGNAL(triggered(bool)),
575  m_pcOpenGLWidget, SLOT(SetGrabFrame(bool)));
576  /* Quit the simulator */
577  connect(m_pcQuitAction, SIGNAL(triggered()),
578  qApp, SLOT(quit()));
579  /* Show the 'About Qt' dialog */
580  connect(m_pcAboutQTAction, SIGNAL(triggered()),
581  qApp, SLOT(aboutQt()));
582  /* Toggle the camera */
583  connect(m_pcSwitchCameraActionGroup, SIGNAL(triggered(QAction*)),
584  this, SLOT(SwitchCamera(QAction*)));
585  connect(this, SIGNAL(CameraSwitched(int)),
586  m_pcOpenGLWidget, SLOT(SetCamera(int)));
587  /* Camera focal length */
588  connect(m_pcFocalLength, SIGNAL(valueChanged(double)),
589  m_pcOpenGLWidget, SLOT(SetCameraFocalLength(double)));
590  /* POV-Ray XML button pressed */
591  connect(m_pcShowCameraXMLAction, SIGNAL(triggered()),
592  this, SLOT(CameraXMLPopUp()));
593  }
594 
595  /****************************************/
596  /****************************************/
597 
598  void CQTOpenGLMainWindow::CreateUserFunctions(TConfigurationNode& t_tree) {
599  /* Parse XML for user functions */
600  if(NodeExists(t_tree, "user_functions")) {
601  /* Use the passed user functions */
602  /* Get data from XML */
603  TConfigurationNode tNode = GetNode(t_tree, "user_functions");
604  std::string strLabel, strLibrary;
605  GetNodeAttribute(tNode, "label", strLabel);
606  GetNodeAttributeOrDefault(tNode, "library", strLibrary, strLibrary);
607  try {
608  /* Load the library */
609  if(strLibrary != "") {
610  CDynamicLoading::LoadLibrary(strLibrary);
611  }
612  /* Create the user functions */
613  m_pcUserFunctions = CFactory<CQTOpenGLUserFunctions>::New(strLabel);
614  m_pcUserFunctions->SetMainWindow(*this);
615  }
616  catch(CARGoSException& ex) {
617  THROW_ARGOSEXCEPTION_NESTED("Failed opening QTOpenGL user function library", ex);
618  }
619  }
620  else {
621  /* Use standard (empty) user functions */
622  m_pcUserFunctions = new CQTOpenGLUserFunctions;
623  m_pcUserFunctions->SetMainWindow(*this);
624  }
625  }
626 
627  /****************************************/
628  /****************************************/
629 
630  void CQTOpenGLMainWindow::closeEvent(QCloseEvent* pc_event) {
631  m_pcUserFunctions->Destroy();
632  WriteSettings();
633  pc_event->accept();
634  }
635 
636  /****************************************/
637  /****************************************/
638 
640  /* Make sure we are in the right state */
641  if(m_eExperimentState != EXPERIMENT_INITIALIZED &&
642  m_eExperimentState != EXPERIMENT_PAUSED) {
643  LOGERR << "[BUG] CQTOpenGLMainWindow::PlayExperiment() called in wrong state: "
644  << m_eExperimentState
645  << std::endl;
646  LOGERR.Flush();
647  return;
648  }
649  /* Toggle action states */
650  m_pcPlayAction->setEnabled(false);
651  m_pcResetAction->setEnabled(false);
652  m_pcTerminateAction->setEnabled(true);
653  if(! CSimulator::GetInstance().IsRealTimeClock()) {
654  m_pcPauseAction->setEnabled(true);
655  m_pcFastForwardAction->setEnabled(false);
656  m_pcStepAction->setEnabled(false);
657  }
658  /* Call OpenGL widget */
659  m_pcOpenGLWidget->PlayExperiment();
660  /* Change state and emit signals */
661  m_eExperimentState = EXPERIMENT_PLAYING;
662  if(m_eExperimentState == EXPERIMENT_INITIALIZED) {
663  /* The experiment has just been started */
664  emit ExperimentStarted();
665  }
666  emit ExperimentPlaying();
667  }
668 
669  /****************************************/
670  /****************************************/
671 
673  /* Make sure we are in the right state */
674  if(m_eExperimentState != EXPERIMENT_INITIALIZED &&
675  m_eExperimentState != EXPERIMENT_PAUSED) {
676  LOGERR << "[BUG] CQTOpenGLMainWindow::FastForwardExperiment() called in wrong state: "
677  << m_eExperimentState
678  << std::endl;
679  LOGERR.Flush();
680  return;
681  }
682  /* Toggle action states */
683  m_pcPlayAction->setEnabled(false);
684  m_pcPauseAction->setEnabled(true);
685  m_pcResetAction->setEnabled(false);
686  m_pcTerminateAction->setEnabled(true);
687  m_pcFastForwardAction->setEnabled(false);
688  m_pcStepAction->setEnabled(false);
689  /* Call OpenGL widget */
690  m_pcOpenGLWidget->FastForwardExperiment();
691  /* Change state and emit signals */
692  m_eExperimentState = EXPERIMENT_FAST_FORWARDING;
693  if(m_eExperimentState == EXPERIMENT_INITIALIZED) {
694  /* The experiment has just been started */
695  emit ExperimentStarted();
696  }
698  }
699 
700  /****************************************/
701  /****************************************/
702 
704  /* Make sure we are in the right state */
705  if(m_eExperimentState != EXPERIMENT_INITIALIZED &&
706  m_eExperimentState != EXPERIMENT_PAUSED) {
707  LOGERR << "[BUG] CQTOpenGLMainWindow::StepExperiment() called in wrong state: "
708  << m_eExperimentState
709  << std::endl;
710  LOGERR.Flush();
711  return;
712  }
713  /* Toggle action states */
714  m_pcPlayAction->setEnabled(true);
715  m_pcResetAction->setEnabled(false);
716  m_pcTerminateAction->setEnabled(true);
717  m_pcFastForwardAction->setEnabled(true);
718  m_pcStepAction->setEnabled(true);
719  /* Call OpenGL widget */
720  m_pcOpenGLWidget->StepExperiment();
721  /* Change state and emit signals */
722  m_eExperimentState = EXPERIMENT_PAUSED;
723  emit ExperimentPaused();
724  }
725 
726  /****************************************/
727  /****************************************/
728 
730  /* Make sure we are in the right state */
731  if(m_eExperimentState != EXPERIMENT_PLAYING &&
732  m_eExperimentState != EXPERIMENT_FAST_FORWARDING) {
733  LOGERR << "[BUG] CQTOpenGLMainWindow::PauseExperiment() called in wrong state: "
734  << m_eExperimentState
735  << std::endl;
736  LOGERR.Flush();
737  return;
738  }
739  /* Toggle action states */
740  m_pcPlayAction->setEnabled(true);
741  m_pcResetAction->setEnabled(false);
742  m_pcTerminateAction->setEnabled(true);
743  if(! CSimulator::GetInstance().IsRealTimeClock()) {
744  m_pcPauseAction->setEnabled(false);
745  m_pcFastForwardAction->setEnabled(true);
746  m_pcStepAction->setEnabled(true);
747  }
748  /* Call OpenGL widget */
749  m_pcOpenGLWidget->PauseExperiment();
750  /* Change state and emit signals */
751  m_eExperimentState = EXPERIMENT_PAUSED;
752  emit ExperimentPaused();
753  }
754 
755  /****************************************/
756  /****************************************/
757 
759  /* Make sure we are in the right state */
760  if(m_eExperimentState != EXPERIMENT_PLAYING &&
761  m_eExperimentState != EXPERIMENT_PAUSED &&
762  m_eExperimentState != EXPERIMENT_FAST_FORWARDING &&
763  m_eExperimentState != EXPERIMENT_SUSPENDED) {
764  LOGERR << "[BUG] CQTOpenGLMainWindow::TerminateExperiment() called in wrong state: "
765  << m_eExperimentState
766  << std::endl;
767  LOGERR.Flush();
768  return;
769  }
770  /* Call OpenGL widget */
771  m_pcOpenGLWidget->PauseExperiment();
772  /* Toggle action states */
773  m_pcPlayAction->setEnabled(false);
774  m_pcResetAction->setEnabled(true);
775  m_pcTerminateAction->setEnabled(false);
776  m_pcCaptureAction->setEnabled(false);
777  m_pcCaptureAction->setChecked(false);
778  if(! CSimulator::GetInstance().IsRealTimeClock()) {
779  m_pcPauseAction->setEnabled(false);
780  m_pcStepAction->setEnabled(false);
781  m_pcFastForwardAction->setEnabled(false);
782  }
783  /* Call ARGoS to terminate the experiment */
786  LOG.Flush();
787  LOGERR.Flush();
788  /* Change state and emit signal */
789  m_eExperimentState = EXPERIMENT_DONE;
790  emit ExperimentDone();
791 
792  /*
793  * Invisible window does not close automatically when simulation finishes
794  */
795  if (m_pcOpenGLWidget->GetFrameGrabData().HeadlessGrabbing) {
796  qApp->exit();
797  }
798  }
799 
800  /****************************************/
801  /****************************************/
802 
804  /* Make sure we are in the right state */
805  if(m_eExperimentState != EXPERIMENT_SUSPENDED &&
806  m_eExperimentState != EXPERIMENT_DONE) {
807  LOGERR << "[BUG] CQTOpenGLMainWindow::ResetExperiment() called in wrong state: "
808  << m_eExperimentState
809  << std::endl;
810  LOGERR.Flush();
811  return;
812  }
813  /* Toggle action states */
814  m_pcPlayAction->setEnabled(true);
815  m_pcResetAction->setEnabled(false);
816  m_pcTerminateAction->setEnabled(false);
817  m_pcCaptureAction->setEnabled(true);
818  m_pcCaptureAction->setChecked(false);
819  if(! CSimulator::GetInstance().IsRealTimeClock()) {
820  m_pcPauseAction->setEnabled(false);
821  m_pcStepAction->setEnabled(true);
822  m_pcFastForwardAction->setEnabled(true);
823  }
824  /* Reset step counter and log */
825  m_pcCurrentStepLCD->display(0);
826  m_pcDockLogBuffer->setHtml("<b>[t=0]</b> Log restarted.");
827  m_pcDockLogErrBuffer->setHtml("<b>[t=0]</b> LogErr restarted.");
828  /* Call OpenGL widget */
829  m_pcOpenGLWidget->ResetExperiment();
830  m_pcUserFunctions->Reset();
831  /* Change state and emit signal */
832  m_eExperimentState = EXPERIMENT_INITIALIZED;
833  emit ExperimentReset();
834  }
835 
836  /****************************************/
837  /****************************************/
838 
840  /* Toggle action states */
841  m_pcPlayAction->setEnabled(false);
842  m_pcResetAction->setEnabled(true);
843  m_pcTerminateAction->setEnabled(true);
844  m_pcCaptureAction->setEnabled(false);
845  m_pcCaptureAction->setChecked(false);
846  if(! CSimulator::GetInstance().IsRealTimeClock()) {
847  m_pcPauseAction->setEnabled(false);
848  m_pcStepAction->setEnabled(false);
849  m_pcFastForwardAction->setEnabled(false);
850  }
851  /* Call OpenGL widget */
852  m_pcOpenGLWidget->PauseExperiment();
853  /* Change state and emit signal */
854  m_eExperimentState = EXPERIMENT_SUSPENDED;
855  emit ExperimentSuspended();
856  }
857 
858  /****************************************/
859  /****************************************/
860 
862  /* Make sure we are in the right state */
863  if(m_eExperimentState != EXPERIMENT_SUSPENDED) {
864  LOGERR << "[BUG] CQTOpenGLMainWindow::ResumeExperiment() called in wrong state: "
865  << m_eExperimentState
866  << std::endl;
867  LOGERR.Flush();
868  return;
869  }
870  /* Toggle action states */
871  m_pcPlayAction->setEnabled(true);
872  m_pcResetAction->setEnabled(false);
873  m_pcTerminateAction->setEnabled(false);
874  m_pcCaptureAction->setEnabled(true);
875  if(! CSimulator::GetInstance().IsRealTimeClock()) {
876  m_pcStepAction->setEnabled(true);
877  m_pcFastForwardAction->setEnabled(true);
878  }
879  /* Change state and emit signal */
880  m_eExperimentState = EXPERIMENT_PAUSED;
881  emit ExperimentResumed();
882  }
883 
884  /****************************************/
885  /****************************************/
886 
888  /* Set the text window up */
889  auto* pcXMLOutput = new QTextEdit();
890  /* Calculate the geometry of the window so that it's 1/4 of the main window
891  and placed in the exact center of it */
892  QRect cGeom = geometry();
893  cGeom.setBottomRight(geometry().center());
894  cGeom.moveCenter(geometry().center());
895  pcXMLOutput->setGeometry(cGeom);
896  /* This window steals all input */
897  pcXMLOutput->setWindowModality(Qt::ApplicationModal);
898  /* You can't modify its contents (but can copy-paste them) */
899  pcXMLOutput->setReadOnly(true);
900  /* Set nice document name and window title */
901  pcXMLOutput->setDocumentTitle("Active camera configuration");
902  pcXMLOutput->setWindowTitle("Active camera configuration");
903  /* Set the actual text to visualize */
904  pcXMLOutput->setPlainText(GetCameraXMLData());
905  /* Finally, show the resulting window */
906  pcXMLOutput->show();
907  }
908 
909  /****************************************/
910  /****************************************/
911 
912  // void CQTOpenGLMainWindow::POVRaySceneXMLPopUp() {
913  // /* Set the text window up */
914  // QTextEdit* pcPOVRayOutput = new QTextEdit();
915  // /* Calculate the geometry of the window so that it's 1/4 of the main window
916  // and placed in the exact center of it */
917  // QRect cGeom = geometry();
918  // cGeom.setBottomRight(geometry().center());
919  // cGeom.moveCenter(geometry().center());
920  // pcPOVRayOutput->setGeometry(cGeom);
921  // /* This window steals all input */
922  // pcPOVRayOutput->setWindowModality(Qt::ApplicationModal);
923  // /* You can't modify its contents (but can copy-paste them) */
924  // pcPOVRayOutput->setReadOnly(true);
925  // /* Set nice document name and window title */
926  // pcPOVRayOutput->setDocumentTitle("ARGoS-POVRay XML camera config");
927  // pcPOVRayOutput->setWindowTitle("ARGoS-POVRay XML camera config");
928  // /* Set the actual text to visualize */
929  // pcPOVRayOutput->setPlainText(GetPOVRaySceneXMLData());
930  // /* Finally, show the resulting window */
931  // pcPOVRayOutput->show();
932  // }
933 
934  /****************************************/
935  /****************************************/
936 
938  QString strResult("<camera>\n <placements>\n");
939  /* Get a reference to the camera */
940  CQTOpenGLCamera& cCamera = m_pcOpenGLWidget->GetCamera();
941  /* Get its position and target */
942  const CQTOpenGLCamera::SPlacement& sPlacement = cCamera.GetActivePlacement();
943  const CVector3& cPos = sPlacement.Position;
944  const CVector3& cLookAt = sPlacement.Target;
945  const CVector3& cUp = sPlacement.Up;
946  strResult.append(
947  QString(" <placement index=\"0\" position=\"%2,%3,%4\" look_at=\"%5,%6,%7\" up=\"%8,%9,%10\" lens_focal_length=\"%11\" />\n")
948  .arg(cPos.GetX())
949  .arg(cPos.GetY())
950  .arg(cPos.GetZ())
951  .arg(cLookAt.GetX())
952  .arg(cLookAt.GetY())
953  .arg(cLookAt.GetZ())
954  .arg(cUp.GetX())
955  .arg(cUp.GetY())
956  .arg(cUp.GetZ())
957  .arg(sPlacement.LensFocalLength * 1000.0f));
958  strResult.append(" </placements>\n</camera>\n");
959  return strResult;
960  }
961 
962  /****************************************/
963  /****************************************/
964 
965  // QString CQTOpenGLMainWindow::GetPOVRaySceneXMLData() {
966  // /* Get the current experiment step */
967  // UInt32 unStep = CSimulator::GetInstance().GetSpace().GetExperimentClock();
968  // /* Get a reference to the camera */
969  // const CQTOpenGLCamera& cCamera = m_pcOpenGLWidget->GetCamera();
970  // /* Get its current position and target */
971  // const CVector3& cPos = cCamera.GetPosition();
972  // const CVector3& cLookAt = cCamera.GetTarget();
973  // /* Get the environment node and its contents from the 'povray_render', if defined */
974  // TConfigurationNode& tExperiment = CSimulator::GetInstance().GetConfigurationRoot();
975  // TConfigurationNode& tVisualization = GetNode(tExperiment, "visualization");
976  // QString strPOVRayEnvironment;
977  // if(NodeExists(tVisualization,"povray_render")) {
978  // TConfigurationNode& tPOVRayVisualization = GetNode(tVisualization, "povray_render");
979  // TConfigurationNode& tPOVRayEnvironment = GetNode(tPOVRayVisualization, "environment");
980  // std::string strPOVRayEnvironmentNodeContent = tPOVRayEnvironment.ToString(tPOVRayEnvironment);
981  // strPOVRayEnvironment = strPOVRayEnvironmentNodeContent.c_str();
982  // }
983 
984  // /* Return the XML portion */
985  // return QString(
986  // "%1\n"
987  // "<scene step=\"%2\">\n"
988  // " <camera type=\"normal\"\n"
989  // " position=\"%3,%4,%5\"\n"
990  // " look_at=\"%6,%7,%8\"\n"
991  // " focal_length=\"%9\" />\n"
992  // "</scene>\n"
993  // )
994  // .arg(strPOVRayEnvironment)
995  // .arg(unStep)
996  // .arg(cPos.GetX())
997  // .arg(cPos.GetY())
998  // .arg(cPos.GetZ())
999  // .arg(cLookAt.GetX())
1000  // .arg(cLookAt.GetY())
1001  // .arg(cLookAt.GetZ())
1002  // .arg(cCamera.GetLensFocalLength() * 1000.0f);
1003  // }
1004 
1005  /****************************************/
1006  /****************************************/
1007 
1008  // void CQTOpenGLMainWindow::POVRayScenePreview() {
1009  // try {
1010  // /* Initialize the POV-Ray working directory */
1011  // QDir cDirectory(QDir::tempPath() + "/argos-povray");
1012  // /* Erase it if it exists */
1013  // if(cDirectory.exists()) {
1014  // if(::system(QString("rm -rf %1").arg(cDirectory.absolutePath()).toAscii().data()) != 0) {
1015  // THROW_ARGOSEXCEPTION("Could not remove directory \"" <<
1016  // cDirectory.absolutePath().toAscii().data() << "\".");
1017  // }
1018  // }
1019  // /* Create the directory */
1020  // if(::system(QString("mkdir %1").arg(cDirectory.absolutePath()).toAscii().data()) != 0) {
1021  // THROW_ARGOSEXCEPTION("Could not create directory \"" <<
1022  // cDirectory.absolutePath().toAscii().data() << "\".");
1023  // }
1024  // /* Now create the XML file that will contain the POV-Ray scene configuration */
1025  // QFile cPOVRayXMLConf(cDirectory.absolutePath() + "/argos-povray.xml");
1026  // cPOVRayXMLConf.open(QFile::WriteOnly | QFile::Truncate);
1027  // /* Associate a text stream to perform writing to it */
1028  // QTextStream cPOVRayXMLConfStream(&cPOVRayXMLConf);
1029  // /* Write the configuration */
1030  // cPOVRayXMLConfStream << "<povray_render id=\"pov\" output_folder=\"" << cDirectory.absolutePath() << "\">\n";
1031  // cPOVRayXMLConfStream << GetPOVRaySceneXMLData();
1032  // cPOVRayXMLConfStream << "</povray_render>\n";
1033  // cPOVRayXMLConf.close();
1034  // /* Now parse this file as an ARGoS TConfigurationTree */
1035  // ticpp::Document tPOVRayXMLConfTree(cPOVRayXMLConf.fileName().toAscii().data());
1036  // tPOVRayXMLConfTree.LoadFile();
1037  // /* It's time to create the POV-Ray visualization */
1038  // CPovrayRender cPOVRayRender;
1039  // cPOVRayRender.Init(*tPOVRayXMLConfTree.FirstChildElement());
1040  // /* Write the .pov frame file */
1041  // cPOVRayRender.WriteOneFrame(cDirectory.absolutePath().append("/pov/frame.pov").toAscii().data());
1042  // /* Eventually, call POV-Ray to render the file */
1043  // if(::system(QString("cd %1 && ")
1044  // .arg(cDirectory.absolutePath())
1045  // .append("./render_single_frame_on_pc.sh pov/frame.pov")
1046  // .toAscii().data()) !=0) {
1047  // THROW_ARGOSEXCEPTION("Could not create POV-Ray preview");
1048  // }
1049  // }
1050  // catch(CARGoSException& ex) {
1051  // QString strError = QString("Error creating POV-Ray preview\n%1").arg(QString(ex.what()));
1052  // QMessageBox::critical(this,
1053  // tr("ARGoS v2.0"),
1054  // strError,
1055  // QMessageBox::Ok);
1056  // }
1057  // }
1058 
1059  /****************************************/
1060  /****************************************/
1061 
1062  void CQTOpenGLMainWindow::SwitchCamera(QAction* pc_action) {
1063  emit CameraSwitched(pc_action->data().toInt());
1064  m_pcFocalLength->setValue(m_pcOpenGLWidget->GetCamera().GetActivePlacement().LensFocalLength * 1000.0f);
1065  }
1066 
1067  /****************************************/
1068  /****************************************/
1069 
1070 }
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception.
unsigned int UInt32
32-bit unsigned integer.
Definition: datatypes.h:97
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
CARGoSLog LOGERR(std::cerr, SLogColor(ARGOS_LOG_ATTRIBUTE_BRIGHT, ARGOS_LOG_COLOR_RED))
Definition: argos_log.h:180
TConfigurationNode & GetNode(TConfigurationNode &t_node, const std::string &str_tag)
Given a tree root node, returns the first of its child nodes with the wanted name.
void GetNodeAttributeOrDefault(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer, const T &t_default)
Returns the value of a node's attribute, or the passed default value.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
CARGoSLog LOG(std::cout, SLogColor(ARGOS_LOG_ATTRIBUTE_BRIGHT, ARGOS_LOG_COLOR_GREEN))
Definition: argos_log.h:179
bool NodeExists(TConfigurationNode &t_node, const std::string &str_tag)
Given a tree root node, returns true if one of its child nodes has the wanted name.
void GetNodeAttribute(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer)
Returns the value of a node's attribute.
virtual void PostExperiment()
Executes user-defined logic when the experiment finishes.
CLoopFunctions & GetLoopFunctions()
Returns a reference to the loop functions associated to the current experiment.
Definition: simulator.h:236
void Terminate()
Puts an end to the simulation.
Definition: simulator.h:283
static CSimulator & GetInstance()
Returns the instance to the CSimulator class.
Definition: simulator.cpp:78
bool IsColoredOutput() const
Definition: argos_log.h:118
std::ostream & GetStream()
Definition: argos_log.h:122
void DisableColoredOutput()
Definition: argos_log.h:114
void EnableColoredOutput()
Definition: argos_log.h:110
A 3D vector class.
Definition: vector3.h:31
Real GetX() const
Returns the x coordinate of this vector.
Definition: vector3.h:105
Real GetY() const
Returns the y coordinate of this vector.
Definition: vector3.h:121
Real GetZ() const
Returns the z coordinate of this vector.
Definition: vector3.h:137
static TDLHandle LoadLibrary(const std::string &str_lib)
Loads a dynamic library.
static TYPE * New(const std::string &str_label)
Creates a new object of type TYPE
Definition: factory_impl.h:48
SPlacement & GetPlacement(UInt32 n_index)
void Init(TConfigurationNode &t_tree)
SPlacement & GetActivePlacement()
CVector3 Up
The local Z axis of the camera in the global reference frame.
CVector3 Position
The position of the camera in the global reference frame.
Real LensFocalLength
The focal length of the lens (if this was a real camera)
CVector3 Target
What we are looking at in the global reference frame.
virtual QSize sizeHint() const
virtual void setGeometry(const QRect &r)
virtual QLayoutItem * itemAt(int index) const
virtual QLayoutItem * takeAt(int index)
virtual void addItem(QLayoutItem *item)
void FastForwardExperiment()
Fast forwards the experiment.
void SuspendExperiment()
Suspends an experiment due to an error.
void ExperimentReset()
Emitted when the experiment has been reset.
void StepExperiment()
Executes one experiment time step.
void PlayExperiment()
Plays the experiment.
void ExperimentSuspended()
Emitted when the experiment has been suspended.
void ExperimentDone()
Emitted when the experiment is finished.
void ExperimentStarted()
Emitted when the experiment has just been started.
void ExperimentResumed()
Emitted when the experiment has just been resumed.
void ResumeExperiment()
Resumes a suspended experiment.
void CameraSwitched(int n_camera)
Emitted whenever the user presses a camera button to switch camera.
void ExperimentPaused()
Emitted when the experiment has been paused.
void ExperimentPlaying()
Emitted when the experiment has (re)started playing.
void ResetExperiment()
Resets the state of the experiment to its state right after initialization.
void PauseExperiment()
Pauses the experiment.
CQTOpenGLMainWindow(TConfigurationNode &t_tree)
void ExperimentFastForwarding()
Emitted when the experiment has (re)started fast-forwarding.
void TerminateExperiment()
Terminates the execution of the experiment.
void SetMainWindow(CQTOpenGLMainWindow &c_main_win)
Sets the QTOpenGL main window for these user functions.
virtual void Destroy()
Undoes whatever was done by Init().
virtual void Init(TConfigurationNode &t_tree)
Initializes the resource.
virtual void Reset()
Resets the resource.
void StepExperiment()
Executes one experiment time step.
void SetShowBoundary(bool b_show_boundary)
Sets whether the boundary walls should be rendered.
void FastForwardExperiment()
Fast forwards the experiment.
void PlayExperiment()
Plays the experiment.
void ResetExperiment()
Resets the state of the experiment to its state right after initialization.
CQTOpenGLCamera & GetCamera()
Returns a reference to the camera.
void SetInvertMouse(bool b_invert_mouse)
Sets whether the mouse should be inverted when moving.
SFrameGrabData & GetFrameGrabData()
Returns the current frame grabbing data.
void SetDrawFrameEvery(int n_every)
When fast-forwarding, sets every how many steps a frame must be drawn.
void PauseExperiment()
Pauses the experiment.
void Init(TConfigurationNode &t_tree)