13 #include <argos3/core/config.h>
14 #include <argos3/core/wrappers/lua/lua_controller.h>
15 #include <argos3/core/simulator/simulator.h>
16 #include <argos3/core/simulator/space/space.h>
17 #include <argos3/core/simulator/entity/composable_entity.h>
18 #include <argos3/core/simulator/entity/controllable_entity.h>
19 #include <argos3/core/wrappers/lua/lua_utility.h>
21 #include <QApplication>
22 #include <QDockWidget>
23 #include <QFileDialog>
24 #include <QHeaderView>
27 #include <QMessageBox>
31 #include <QTemporaryFile>
32 #include <QTextStream>
34 #include <QTableWidget>
42 static QString SCRIPT_TEMPLATE =
43 "-- Use Shift + Click to select a robot\n"
44 "-- When a robot is selected, its variables appear in this editor\n\n"
45 "-- Use Ctrl + Click (Cmd + Click on Mac) to move a selected robot to a different location\n\n\n\n"
46 "-- Put your global variables here\n\n\n\n"
47 "--[[ This function is executed every time you press the 'execute' button ]]\n"
49 " -- put your code here\n"
51 "--[[ This function is executed at each time step\n"
52 " It must contain the logic of your controller ]]\n"
54 " -- put your code here\n"
56 "--[[ This function is executed every time you press the 'reset'\n"
57 " button in the GUI. It is supposed to restore the state\n"
58 " of the controller to whatever it was right after init() was\n"
59 " called. The state of sensors and actuators is reset\n"
60 " automatically by ARGoS. ]]\n"
62 " -- put your code here\n"
64 "--[[ This function is executed only once, when the robot is removed\n"
65 " from the simulation ]]\n"
66 "function destroy()\n"
67 " -- put your code here\n"
74 QMainWindow(pc_parent),
75 m_pcMainWindow(pc_parent),
79 m_pcLuaMessageTable(NULL) {
81 m_pcStatusbar =
new QStatusBar(
this);
82 setStatusBar(m_pcStatusbar);
84 CreateLuaMessageTable();
86 PopulateLuaControllers();
88 CreateLuaStateDocks();
113 m_pcCodeEditor->setPlainText(SCRIPT_TEMPLATE);
123 QString strNewFileName =
124 QFileDialog::getOpenFileName(
this,
127 "Lua Files (*.lua)");
128 if (!strNewFileName.isEmpty()) {
129 OpenFile(strNewFileName);
138 QAction* pcAction = qobject_cast<QAction*>(sender());
140 OpenFile(pcAction->data().toString());
148 if (m_strFileName.isEmpty()) {
151 return SaveFile(m_strFileName);
159 QString strNewFileName =
160 QFileDialog::getSaveFileName(
this,
163 "Lua Files (*.lua)");
164 if (strNewFileName.isEmpty())
166 return SaveFile(strNewFileName);
172 static QString DetectLuaC() {
173 QProcess cLuaCompiler;
174 cLuaCompiler.start(
"luac", QStringList() <<
"-v");
176 if(!cLuaCompiler.waitForStarted()) {
181 cLuaCompiler.waitForFinished();
182 if(QString(cLuaCompiler.readAllStandardOutput()).mid(4,3) ==
"5.2") {
185 cLuaCompiler.start(
"luac5.2", QStringList() <<
"-v");
186 if(!cLuaCompiler.waitForStarted()) {
192 cLuaCompiler.waitForFinished();
201 QApplication::setOverrideCursor(Qt::WaitCursor);
205 m_pcLuaMessageTable->clearContents();
206 m_pcLuaMessageTable->setRowCount(1);
208 QTemporaryFile cByteCode;
209 if(! cByteCode.open()) {
210 SetMessage(0,
"ALL",
"Can't create bytecode file.");
211 QApplication::restoreOverrideCursor();
218 QString cLuaC = DetectLuaC();
221 for(
size_t i = 0; i < m_vecControllers.size(); ++i) {
222 m_vecControllers[i]->SetLuaScript(m_strFileName.toStdString());
226 QProcess cLuaCompiler;
227 cLuaCompiler.start(cLuaC, QStringList() <<
"-o" << cByteCode.fileName() << m_strFileName);
228 if(! cLuaCompiler.waitForFinished()) {
229 SetMessage(0,
"ALL", QString(cLuaCompiler.readAllStandardError()));
230 QApplication::restoreOverrideCursor();
233 if(cLuaCompiler.exitCode() != 0) {
234 SetMessage(0,
"ALL", QString(cLuaCompiler.readAllStandardError()));
235 QApplication::restoreOverrideCursor();
238 SetMessage(0,
"ALL",
"Compilation successful.");
240 for(
size_t i = 0; i < m_vecControllers.size(); ++i) {
241 m_vecControllers[i]->SetLuaScript(cByteCode.fileName().toStdString());
245 if(m_pcLuaVariableDock->isVisible()) {
247 m_vecControllers[m_unSelectedRobot]->GetLuaState());
249 if(m_pcLuaFunctionDock->isVisible()) {
251 m_vecControllers[m_unSelectedRobot]->GetLuaState());
255 QApplication::restoreOverrideCursor();
256 statusBar()->showMessage(tr(
"Execution started"), 2000);
263 if(! m_pcFindDialog) {
266 m_pcFindDialog->show();
273 setWindowModified(m_pcCodeEditor->document()->isModified());
279 bool CQTOpenGLLuaMainWindow::MaybeSave() {
280 if(m_pcCodeEditor->document()->isModified()) {
281 QMessageBox::StandardButton tReply;
282 tReply = QMessageBox::warning(
this, tr(
"ARGoS v" ARGOS_VERSION
"-" ARGOS_RELEASE
" - Lua Editor"),
283 tr(
"The document has been modified.\n"
284 "Do you want to save your changes?"),
285 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
286 if (tReply == QMessageBox::Save)
288 else if (tReply == QMessageBox::Cancel)
297 void CQTOpenGLLuaMainWindow::PopulateLuaControllers() {
302 for(CSpace::TMapPerType::iterator it = tControllables.begin();
303 it != tControllables.end();
306 CControllableEntity* pcControllable = any_cast<CControllableEntity*>(it->second);
307 CLuaController* pcLuaController =
dynamic_cast<CLuaController*
>(&(pcControllable->GetController()));
308 if(pcLuaController) {
310 m_vecControllers.push_back(pcLuaController);
311 m_vecRobots.push_back(&pcControllable->GetParent());
314 LOGERR <<
"[WARNING] Entity \""
315 << pcControllable->GetParent().GetId()
316 <<
"\" does not have a Lua controller associated"
325 void CQTOpenGLLuaMainWindow::ReadSettings() {
327 cSettings.beginGroup(
"LuaEditor");
328 resize(cSettings.value(
"size", QSize(640,480)).toSize());
329 move(cSettings.value(
"position", QPoint(0,0)).toPoint());
330 cSettings.endGroup();
336 void CQTOpenGLLuaMainWindow::WriteSettings() {
338 cSettings.beginGroup(
"LuaEditor");
339 cSettings.setValue(
"size", size());
340 cSettings.setValue(
"position", pos());
341 cSettings.endGroup();
347 void CQTOpenGLLuaMainWindow::CreateCodeEditor() {
349 m_pcCodeEditor =
new CQTOpenGLLuaEditor(
this);
350 setCentralWidget(m_pcCodeEditor);
351 m_pcCodeEditor->setPlainText(SCRIPT_TEMPLATE);
353 connect(m_pcCodeEditor->document(), SIGNAL(contentsChanged()),
362 void CQTOpenGLLuaMainWindow::CreateLuaMessageTable() {
363 m_pcLuaMsgDock =
new QDockWidget(tr(
"Messages"),
this);
364 m_pcLuaMsgDock->setObjectName(
"LuaMessageDock");
365 m_pcLuaMsgDock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
366 m_pcLuaMsgDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
367 m_pcLuaMessageTable =
new QTableWidget();
368 m_pcLuaMessageTable->setColumnCount(3);
369 QStringList listHeaders;
370 listHeaders << tr(
"Robot")
373 m_pcLuaMessageTable->setHorizontalHeaderLabels(listHeaders);
374 m_pcLuaMessageTable->horizontalHeader()->setStretchLastSection(
true);
375 m_pcLuaMessageTable->setSelectionBehavior(QAbstractItemView::SelectRows);
376 m_pcLuaMessageTable->setSelectionMode(QAbstractItemView::SingleSelection);
377 m_pcLuaMsgDock->setWidget(m_pcLuaMessageTable);
378 addDockWidget(Qt::BottomDockWidgetArea, m_pcLuaMsgDock);
379 connect(m_pcLuaMessageTable, SIGNAL(itemSelectionChanged()),
381 m_pcLuaMsgDock->hide();
387 void CQTOpenGLLuaMainWindow::CreateLuaStateDocks() {
389 m_pcLuaVariableDock =
new QDockWidget(tr(
"Variables"),
this);
390 m_pcLuaVariableDock->setObjectName(
"LuaVariableDock");
391 m_pcLuaVariableDock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
392 m_pcLuaVariableDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
393 m_pcLuaVariableTree =
new QTreeView();
394 m_pcLuaVariableDock->setWidget(m_pcLuaVariableTree);
395 addDockWidget(Qt::LeftDockWidgetArea, m_pcLuaVariableDock);
396 m_pcLuaVariableDock->hide();
398 m_pcLuaFunctionDock =
new QDockWidget(tr(
"Functions"),
this);
399 m_pcLuaFunctionDock->setObjectName(
"LuaFunctionDock");
400 m_pcLuaFunctionDock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
401 m_pcLuaFunctionDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
402 m_pcLuaFunctionTree =
new QTreeView();
403 m_pcLuaFunctionDock->setWidget(m_pcLuaFunctionTree);
404 addDockWidget(Qt::LeftDockWidgetArea, m_pcLuaFunctionDock);
405 m_pcLuaFunctionDock->hide();
407 connect(&(m_pcMainWindow->
GetOpenGLWidget()), SIGNAL(EntitySelected(CEntity*)),
409 connect(&(m_pcMainWindow->
GetOpenGLWidget()), SIGNAL(EntityDeselected(CEntity*)),
416 void CQTOpenGLLuaMainWindow::CreateFileActions() {
418 cFileNewIcon.addPixmap(QPixmap(m_pcMainWindow->
GetIconDir() +
"/new.png"));
419 m_pcFileNewAction =
new QAction(cFileNewIcon, tr(
"&New"),
this);
420 m_pcFileNewAction->setToolTip(tr(
"Create a new file"));
421 m_pcFileNewAction->setStatusTip(tr(
"Create a new file"));
422 m_pcFileNewAction->setShortcut(QKeySequence::New);
423 connect(m_pcFileNewAction, SIGNAL(triggered()),
426 cFileOpenIcon.addPixmap(QPixmap(m_pcMainWindow->
GetIconDir() +
"/open.png"));
427 m_pcFileOpenAction =
new QAction(cFileOpenIcon, tr(
"&Open..."),
this);
428 m_pcFileOpenAction->setToolTip(tr(
"Open a file"));
429 m_pcFileOpenAction->setStatusTip(tr(
"Open a file"));
430 m_pcFileOpenAction->setShortcut(QKeySequence::Open);
431 connect(m_pcFileOpenAction, SIGNAL(triggered()),
433 for (
int i = 0; i < MAX_RECENT_FILES; ++i) {
434 m_pcFileOpenRecentAction[i] =
new QAction(
this);
435 m_pcFileOpenRecentAction[i]->setVisible(
false);
436 connect(m_pcFileOpenRecentAction[i], SIGNAL(triggered()),
440 cFileSaveIcon.addPixmap(QPixmap(m_pcMainWindow->
GetIconDir() +
"/save.png"));
441 m_pcFileSaveAction =
new QAction(cFileSaveIcon, tr(
"&Save"),
this);
442 m_pcFileSaveAction->setToolTip(tr(
"Save the current file"));
443 m_pcFileSaveAction->setStatusTip(tr(
"Save the current file"));
444 m_pcFileSaveAction->setShortcut(QKeySequence::Save);
445 connect(m_pcFileSaveAction, SIGNAL(triggered()),
447 QIcon cFileSaveAsIcon;
448 cFileSaveAsIcon.addPixmap(QPixmap(m_pcMainWindow->
GetIconDir() +
"/saveas.png"));
449 m_pcFileSaveAsAction =
new QAction(cFileSaveAsIcon, tr(
"S&ave as..."),
this);
450 m_pcFileSaveAsAction->setToolTip(tr(
"Save the current file under a new name"));
451 m_pcFileSaveAsAction->setStatusTip(tr(
"Save the current file under a new name"));
452 m_pcFileSaveAsAction->setShortcut(QKeySequence::SaveAs);
453 connect(m_pcFileSaveAsAction, SIGNAL(triggered()),
455 QMenu* pcMenu = menuBar()->addMenu(tr(
"&File"));
456 pcMenu->addAction(m_pcFileNewAction);
457 pcMenu->addSeparator();
458 pcMenu->addAction(m_pcFileOpenAction);
459 pcMenu->addSeparator();
460 pcMenu->addAction(m_pcFileSaveAction);
461 pcMenu->addAction(m_pcFileSaveAsAction);
462 m_pcFileSeparateRecentAction = pcMenu->addSeparator();
463 for (
int i = 0; i < MAX_RECENT_FILES; ++i) {
464 pcMenu->addAction(m_pcFileOpenRecentAction[i]);
466 QToolBar* pcToolBar = addToolBar(tr(
"File"));
467 pcToolBar->setObjectName(
"FileToolBar");
468 pcToolBar->setIconSize(QSize(32,32));
469 pcToolBar->addAction(m_pcFileNewAction);
470 pcToolBar->addAction(m_pcFileOpenAction);
471 pcToolBar->addAction(m_pcFileSaveAction);
478 void CQTOpenGLLuaMainWindow::CreateEditActions() {
480 cEditUndoIcon.addPixmap(QPixmap(m_pcMainWindow->
GetIconDir() +
"/undo.png"));
481 m_pcEditUndoAction =
new QAction(cEditUndoIcon, tr(
"&Undo"),
this);
482 m_pcEditUndoAction->setToolTip(tr(
"Undo last operation"));
483 m_pcEditUndoAction->setStatusTip(tr(
"Undo last operation"));
484 m_pcEditUndoAction->setShortcut(QKeySequence::Undo);
485 connect(m_pcEditUndoAction, SIGNAL(triggered()),
486 m_pcCodeEditor, SLOT(undo()));
488 cEditRedoIcon.addPixmap(QPixmap(m_pcMainWindow->
GetIconDir() +
"/redo.png"));
489 m_pcEditRedoAction =
new QAction(cEditRedoIcon, tr(
"&Redo"),
this);
490 m_pcEditRedoAction->setToolTip(tr(
"Redo last operation"));
491 m_pcEditRedoAction->setStatusTip(tr(
"Redo last operation"));
492 m_pcEditRedoAction->setShortcut(QKeySequence::Redo);
493 connect(m_pcEditRedoAction, SIGNAL(triggered()),
494 m_pcCodeEditor, SLOT(redo()));
496 cEditCopyIcon.addPixmap(QPixmap(m_pcMainWindow->
GetIconDir() +
"/copy.png"));
497 m_pcEditCopyAction =
new QAction(cEditCopyIcon, tr(
"&Copy"),
this);
498 m_pcEditCopyAction->setToolTip(tr(
"Copy selected text into clipboard"));
499 m_pcEditCopyAction->setStatusTip(tr(
"Copy selected text into clipboard"));
500 m_pcEditCopyAction->setShortcut(QKeySequence::Copy);
501 connect(m_pcEditCopyAction, SIGNAL(triggered()),
502 m_pcCodeEditor, SLOT(copy()));
504 cEditCutIcon.addPixmap(QPixmap(m_pcMainWindow->
GetIconDir() +
"/cut.png"));
505 m_pcEditCutAction =
new QAction(cEditCutIcon, tr(
"&Cut"),
this);
506 m_pcEditCutAction->setToolTip(tr(
"Move selected text into clipboard"));
507 m_pcEditCutAction->setStatusTip(tr(
"Move selected text into clipboard"));
508 m_pcEditCutAction->setShortcut(QKeySequence::Cut);
509 connect(m_pcEditCutAction, SIGNAL(triggered()),
510 m_pcCodeEditor, SLOT(cut()));
511 QIcon cEditPasteIcon;
512 cEditPasteIcon.addPixmap(QPixmap(m_pcMainWindow->
GetIconDir() +
"/paste.png"));
513 m_pcEditPasteAction =
new QAction(cEditPasteIcon, tr(
"&Paste"),
this);
514 m_pcEditPasteAction->setToolTip(tr(
"Paste text from clipboard"));
515 m_pcEditPasteAction->setStatusTip(tr(
"Paste text from clipboard"));
516 m_pcEditPasteAction->setShortcut(QKeySequence::Paste);
517 connect(m_pcEditPasteAction, SIGNAL(triggered()),
518 m_pcCodeEditor, SLOT(paste()));
527 QMenu* pcMenu = menuBar()->addMenu(tr(
"&Edit"));
528 pcMenu->addAction(m_pcEditUndoAction);
529 pcMenu->addAction(m_pcEditRedoAction);
530 pcMenu->addSeparator();
531 pcMenu->addAction(m_pcEditCopyAction);
532 pcMenu->addAction(m_pcEditCutAction);
533 pcMenu->addAction(m_pcEditPasteAction);
536 QToolBar* pcToolBar = addToolBar(tr(
"Edit"));
537 pcToolBar->setObjectName(
"EditToolBar");
538 pcToolBar->setIconSize(QSize(32,32));
539 pcToolBar->addAction(m_pcEditUndoAction);
540 pcToolBar->addAction(m_pcEditRedoAction);
541 pcToolBar->addSeparator();
542 pcToolBar->addAction(m_pcEditCopyAction);
543 pcToolBar->addAction(m_pcEditCutAction);
544 pcToolBar->addAction(m_pcEditPasteAction);
551 void CQTOpenGLLuaMainWindow::CreateCodeActions() {
552 QIcon cCodeExecuteIcon;
553 cCodeExecuteIcon.addPixmap(QPixmap(m_pcMainWindow->
GetIconDir() +
"/execute.png"));
554 m_pcCodeExecuteAction =
new QAction(cCodeExecuteIcon, tr(
"&Execute"),
this);
555 m_pcCodeExecuteAction->setToolTip(tr(
"Execute code"));
556 m_pcCodeExecuteAction->setStatusTip(tr(
"Execute code"));
557 m_pcCodeExecuteAction->setShortcut(tr(
"Ctrl+E"));
558 connect(m_pcCodeExecuteAction, SIGNAL(triggered()),
560 QMenu* pcMenu = menuBar()->addMenu(tr(
"&Code"));
561 pcMenu->addAction(m_pcCodeExecuteAction);
562 QToolBar* pcToolBar = addToolBar(tr(
"Code"));
563 pcToolBar->setObjectName(
"CodeToolBar");
564 pcToolBar->setIconSize(QSize(32,32));
565 pcToolBar->addAction(m_pcCodeExecuteAction);
571 void CQTOpenGLLuaMainWindow::OpenFile(
const QString& str_path) {
572 QFile cFile(str_path);
573 if(! cFile.open(QFile::ReadOnly | QFile::Text)) {
574 QMessageBox::warning(
this, tr(
"ARGoS v" ARGOS_VERSION
"-" ARGOS_RELEASE
" - Lua Editor"),
575 tr(
"Cannot read file %1:\n%2.")
577 .arg(cFile.errorString()));
580 QApplication::setOverrideCursor(Qt::WaitCursor);
581 m_pcCodeEditor->setPlainText(cFile.readAll());
582 QApplication::restoreOverrideCursor();
583 SetCurrentFile(str_path);
584 statusBar()->showMessage(tr(
"File loaded"), 2000);
590 bool CQTOpenGLLuaMainWindow::SaveFile(
const QString& str_path) {
591 QFile cFile(str_path);
592 if(! cFile.open(QFile::WriteOnly | QFile::Text)) {
593 QMessageBox::warning(
this, tr(
"ARGoS v" ARGOS_VERSION
"-" ARGOS_RELEASE
" - Lua Editor"),
594 tr(
"Cannot write file %1:\n%2.")
596 .arg(cFile.errorString()));
599 QTextStream cOut(&cFile);
600 QApplication::setOverrideCursor(Qt::WaitCursor);
601 cOut << m_pcCodeEditor->toPlainText();
602 QApplication::restoreOverrideCursor();
603 SetCurrentFile(str_path);
604 statusBar()->showMessage(tr(
"File saved"), 2000);
611 void CQTOpenGLLuaMainWindow::SetCurrentFile(
const QString& str_path) {
612 m_strFileName = str_path;
613 QString strShownName;
614 if(m_strFileName.isEmpty()) {
615 strShownName =
"untitled";
618 strShownName = StrippedFileName(m_strFileName);
620 setWindowTitle(tr(
"%1[*] - ARGoS v" ARGOS_VERSION
"-" ARGOS_RELEASE
" - Lua Editor").arg(strShownName));
621 if(!m_strFileName.isEmpty()) {
622 m_pcCodeEditor->document()->setModified(
false);
623 setWindowModified(
false);
625 cSettings.beginGroup(
"LuaEditor");
626 QStringList listFiles = cSettings.value(
"recent_files").toStringList();
627 listFiles.removeAll(m_strFileName);
628 listFiles.prepend(m_strFileName);
629 while(listFiles.size() > MAX_RECENT_FILES) {
630 listFiles.removeLast();
632 cSettings.setValue(
"recent_files", listFiles);
633 cSettings.endGroup();
637 m_pcCodeEditor->document()->setModified(
true);
638 setWindowModified(
true);
647 m_pcLuaMessageTable->clearContents();
648 m_pcLuaMessageTable->setRowCount(m_vecControllers.size());
649 for(
size_t i = 0; i < m_vecControllers.size(); ++i) {
650 if(! m_vecControllers[i]->IsOK()) {
652 QString::fromStdString(m_vecControllers[i]->GetId()),
653 QString::fromStdString(m_vecControllers[i]->GetErrorMessage()));
657 m_pcLuaMessageTable->setRowCount(nRow);
662 m_pcLuaMsgDock->hide();
670 QList<QTableWidgetItem*> listSel = m_pcLuaMessageTable->selectedItems();
671 if(! listSel.empty()) {
672 int nLine = listSel[1]->data(Qt::DisplayRole).toInt();
673 QTextCursor cCursor = m_pcCodeEditor->textCursor();
674 int nCurLine = cCursor.blockNumber();
675 if(nCurLine < nLine) {
676 cCursor.movePosition(QTextCursor::NextBlock,
677 QTextCursor::MoveAnchor,
678 nLine - nCurLine - 1);
680 else if(nCurLine > nLine) {
681 cCursor.movePosition(QTextCursor::PreviousBlock,
682 QTextCursor::MoveAnchor,
683 nCurLine - nLine + 1);
685 cCursor.movePosition(QTextCursor::StartOfBlock);
686 m_pcCodeEditor->setTextCursor(cCursor);
687 m_pcCodeEditor->setFocus();
696 if(pcSelectedEntity != NULL) {
698 m_unSelectedRobot = 0;
699 while(!bFound && m_unSelectedRobot < m_vecRobots.size()) {
700 if(m_vecRobots[m_unSelectedRobot] == pcSelectedEntity) {
708 m_vecControllers[m_unSelectedRobot]->GetLuaState() != NULL) {
712 m_pcLuaVariableTree);
715 pcVarModel, SLOT(Refresh(
int)));
716 connect(m_pcMainWindow, SIGNAL(ExperimentReset()),
717 pcVarModel, SLOT(Refresh()));
718 connect(pcVarModel, SIGNAL(modelReset()),
720 Qt::QueuedConnection);
721 m_pcLuaVariableTree->setModel(pcVarModel);
722 m_pcLuaVariableTree->setRootIndex(pcVarModel->
index(0, 0));
723 m_pcLuaVariableTree->expandAll();
724 m_pcLuaVariableDock->show();
728 m_pcLuaFunctionTree);
731 pcFunModel, SLOT(Refresh(
int)));
732 connect(m_pcMainWindow, SIGNAL(ExperimentReset()),
733 pcFunModel, SLOT(Refresh()));
734 connect(pcFunModel, SIGNAL(modelReset()),
736 Qt::QueuedConnection);
737 m_pcLuaFunctionTree->setModel(pcFunModel);
738 m_pcLuaFunctionTree->setRootIndex(pcFunModel->
index(0, 0));
739 m_pcLuaFunctionTree->expandAll();
740 m_pcLuaFunctionDock->show();
749 disconnect(&(m_pcMainWindow->
GetOpenGLWidget()), SIGNAL(StepDone(
int)),
750 m_pcLuaVariableTree->model(), SLOT(Refresh(
int)));
751 disconnect(m_pcMainWindow, SIGNAL(ExperimentReset()),
752 m_pcLuaVariableTree->model(), SLOT(Refresh()));
753 disconnect(m_pcLuaVariableTree->model(), SIGNAL(modelReset()),
755 m_pcLuaVariableDock->hide();
756 delete m_pcLuaVariableTree->model();
757 m_pcLuaVariableTree->setModel(NULL);
758 disconnect(&(m_pcMainWindow->
GetOpenGLWidget()), SIGNAL(StepDone(
int)),
759 m_pcLuaFunctionTree->model(), SLOT(Refresh(
int)));
760 disconnect(m_pcMainWindow, SIGNAL(ExperimentReset()),
761 m_pcLuaFunctionTree->model(), SLOT(Refresh()));
762 disconnect(m_pcLuaFunctionTree->model(), SIGNAL(modelReset()),
764 m_pcLuaFunctionDock->hide();
765 delete m_pcLuaFunctionTree->model();
766 m_pcLuaFunctionTree->setModel(NULL);
773 m_pcLuaVariableTree->setRootIndex(m_pcLuaVariableTree->model()->index(0, 0));
774 m_pcLuaVariableTree->expandAll();
781 m_pcLuaFunctionTree->setRootIndex(m_pcLuaFunctionTree->model()->index(0, 0));
782 m_pcLuaFunctionTree->expandAll();
788 void CQTOpenGLLuaMainWindow::UpdateRecentFiles() {
790 cSettings.beginGroup(
"LuaEditor");
791 QStringList listFiles = cSettings.value(
"recent_files").toStringList();
792 int nRecentFiles = qMin(listFiles.size(), (
int)MAX_RECENT_FILES);
793 for(
int i = 0; i < nRecentFiles; ++i) {
794 m_pcFileOpenRecentAction[i]->setText(tr(
"&%1 %2").arg(i+1).arg(StrippedFileName(listFiles[i])));
795 m_pcFileOpenRecentAction[i]->setData(listFiles[i]);
796 m_pcFileOpenRecentAction[i]->setVisible(
true);
798 for(
int i = nRecentFiles; i < MAX_RECENT_FILES; ++i) {
799 m_pcFileOpenRecentAction[i]->setVisible(
false);
801 m_pcFileSeparateRecentAction->setVisible(nRecentFiles > 0);
802 cSettings.endGroup();
808 void CQTOpenGLLuaMainWindow::SetMessage(
int n_row,
809 const QString& str_robot_id,
810 const QString& str_message) {
811 QStringList listFields = str_message.split(
":",
812 #
if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
815 QString::KeepEmptyParts,
817 Qt::CaseInsensitive);
818 m_pcLuaMessageTable->setItem(
820 new QTableWidgetItem(str_robot_id));
821 if(listFields.size() == 3) {
822 m_pcLuaMessageTable->setItem(
824 new QTableWidgetItem(listFields[1]));
825 m_pcLuaMessageTable->setItem(
827 new QTableWidgetItem(listFields[2]));
829 else if(listFields.size() == 4) {
830 m_pcLuaMessageTable->setItem(
832 new QTableWidgetItem(listFields[2]));
833 m_pcLuaMessageTable->setItem(
835 new QTableWidgetItem(listFields[3]));
838 m_pcLuaMessageTable->setItem(
840 new QTableWidgetItem(str_message));
842 m_pcLuaMsgDock->show();
848 QString CQTOpenGLLuaMainWindow::StrippedFileName(
const QString& str_path) {
849 return QFileInfo(str_path).fileName();
855 void CQTOpenGLLuaMainWindow::closeEvent(QCloseEvent* pc_event) {
The namespace containing all the ARGoS related code.
CARGoSLog LOGERR(std::cerr, SLogColor(ARGOS_LOG_ATTRIBUTE_BRIGHT, ARGOS_LOG_COLOR_RED))
Basic class for an entity that contains other entities.
CSpace & GetSpace() const
Returns a reference to the simulated space.
static CSimulator & GetInstance()
Returns the instance to the CSimulator class.
std::map< std::string, CAny, std::less< std::string > > TMapPerType
A map of entities indexed by type description.
void HandleEntityDeselection(CEntity *pc_entity)
void FunctionTreeChanged()
CQTOpenGLLuaMainWindow(CQTOpenGLMainWindow *pc_parent)
void HandleEntitySelection(CEntity *pc_entity)
virtual ~CQTOpenGLLuaMainWindow()
void HandleMsgTableSelection()
void CheckLuaStatus(int n_step)
void VariableTreeChanged()
virtual QModelIndex index(int n_row, int n_column, const QModelIndex &c_parent=QModelIndex()) const
void SuspendExperiment()
Suspends an experiment due to an error.
const QString & GetIconDir() const
CQTOpenGLWidget & GetOpenGLWidget()
void ResumeExperiment()
Resumes a suspended experiment.