StatechartEditorController.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
25 
26 #include <filesystem>
27 
28 #include <QCoreApplication>
29 #include <QInputDialog>
30 #include <QLabel>
31 #include <QMessageBox>
32 #include <QTimer>
33 
34 #include <IceUtil/UUID.h>
35 
36 #include <SimoxUtility/algorithm/string/string_tools.h>
37 
40 #include <ArmarXCore/interface/statechart/RemoteStateOffererIce.h>
41 
44 
45 #include "../StatechartViewerPlugin/view/StateItem.h"
46 #include "../StatechartViewerPlugin/view/StatechartView.h"
47 #include "io/GroupXmlReader.h"
48 #include "io/GroupXmlWriter.h"
49 #include "model/StateTreeModel.h"
53 
54 namespace armarx
55 {
56 
58  // editor(NULL)
59  watcher(NULL)
60  {
61  // For jsonobject double/float serilization on german/spanish pcs....
62  setlocale(LC_ALL, "C");
63 
64  QSettings s("KIT", "ArmarXStatechartEditor");
65  config.lockRemoteStates = s.value("lockRemoteStates", true).toBool();
66  config.searchPaths = s.value("searchPaths").toStringList();
67  }
68 
70  {
72  }
73 
74  void
76  {
77  ARMARX_INFO << "Updating auto-storage config";
78  QSettings s("KIT", "ArmarXStatechartEditor");
79  s.setValue("lockRemoteStates", config.lockRemoteStates);
80  s.setValue("searchPaths", config.searchPaths);
81  }
82 
83  QStringList
85  {
86  QStringList result;
87  if (basePath.isEmpty())
88  {
89  return result;
90  }
91  try
92  {
93  int i = 0;
94 
95  for (std::filesystem::recursive_directory_iterator end, dir(basePath.toUtf8().data());
96  dir != end && getState() < eManagedIceObjectExiting;
97  ++dir, i++)
98  {
99  std::string path(dir->path().c_str());
100  // search for all statechart group xml files
101  if (dir->path().extension() == ".scgxml")
102  {
103  // skip groups in deprecated folders
104  if (path.find("deprecated") != std::string::npos)
105  {
106  ARMARX_INFO << "Skipping deprecated Statechart Group " << path;
107  }
108  else
109  {
110  result << dir->path().c_str();
111  }
112  }
113 
114  if (i % 100 == 0)
115  {
116  QCoreApplication::processEvents();
117  }
118  }
119  }
120  catch (std::exception& e)
121  {
122  ARMARX_WARNING << "Invalid filepath: " << e.what();
123  }
124 
125  return result;
126  }
127 
128  void
130  {
131  packageTool.reset(new ArmarXPackageToolInterface());
132  }
133 
134  void
136  {
137  QTimer::singleShot(0, this, SLOT(initWidget()));
138  stateWatcher = new StateWatcher();
139  getArmarXManager()->addObject(
140  stateWatcher, "StateWatcher" + IceUtil::generateUUID(), false);
141  }
142 
143  void
145  {
146  }
147 
148  void
150  {
151  if (executionStatusTask)
152  {
153  executionStatusTask->stop();
154  }
155  }
156 
157  void
159  {
160  // searchPaths = settings->value("paths").toStringList();
161  // int size = settings->beginReadArray("groups");
162  // for(int row = 0; row < size; row++)
163  // {
164  // settings->setArrayIndex(row);
165  // config.groupsToLoad.push_back(settings->value("path").toString());
166  // }
167  // settings->endArray();
168  if (!profiles)
169  {
171  Application::getInstance()->getArmarXPackageNames());
172  }
173 
174  if (settings->contains("selectedProfile"))
175  {
176  config.selectedProfile = profiles->getProfileByName(
177  settings->value("selectedProfile").toString().toStdString());
178  }
179  else if (getConfigDialog(getWidget())->exec() == QDialog::Accepted)
180  {
181  configured();
182  }
183  else
184  {
185  config.selectedProfile = profiles->getProfileByName(profiles->GetRootName());
186  }
187 
188  config.openAllStatesWasSelected = settings->value("openAllStatesSelected", false).toBool();
189  }
190 
191  void
193  {
194  // settings->setValue("paths", searchPaths);
195  // if(treeController)
196  // {
197  // settings->beginWriteArray("groups");
198  // for(int row = 0; row < treeController->rowCount(); row++)
199  // {
200  // QModelIndex index = treeController->index(row, 0);
201  // auto node = treeController->getNode(index);
202  //
203  // settings->setArrayIndex(row);
204  // settings->setValue("path", node->getGroup()->getDefinitionFilePath());
205  // }
206  // settings->endArray();
207  // }
208 
210  {
211  settings->setValue("selectedProfile",
212  QString::fromStdString(config.selectedProfile->getName()));
213  }
214 
215  settings->setValue("openAllStatesSelected", config.openAllStatesWasSelected);
216  }
217 
218  void
220  {
221  StateTreeNodePtr node = treeController->getNode(index);
222 
223  if (node && node->getState())
224  {
225  int index = editor->getStateTabWidget()->getStateTab(node->getState());
226  getTipDialog()->showMessage(
227  "You can move states by holding the SHIFT + left click button. You can move the "
228  "scene by holding ALT + move mouse.",
229  "State Interaction");
230 
231  if (index < 0)
232  {
233  editor->getStateTabWidget()->addStateTab(node->getState());
234  }
235  else
236  {
237  editor->getStateTabWidget()->setCurrentIndex(index);
238  }
239  }
240  }
241 
242  void
244  {
245  treeController->saveAll();
246  }
247 
248  void
250  {
251  StatechartView* view = editor->getUI()->stateTabWidget->stateview(index);
252 
253  if (view && view->getStateInstance() && view->getStateInstance()->getStateClass())
254  {
255  treeController->selectNodeByState(view->getStateInstance()->getStateClass());
257  view->showSubSubstates(editor->ui->actionShow_Subsubstates->isChecked());
258  }
259  }
260 
261  void
263  {
264  QList<QString> selectedProxies;
265  // enable statechart context generation for new groups by default
267  "",
268  packageTool,
269  variantInfo,
270  selectedProxies,
271  true,
272  profiles);
273 
274  if (d.exec() == QDialog::Accepted)
275  {
276  StatechartGroupPtr g = treeController->addNewGroup(d.getGroupName(),
277  d.getGroupPath(),
279  d.getPackageName(),
280  d.getProxies(),
282  d.getConfigurations());
283  }
284  }
285 
286  void
288  {
292  if (d.exec() == QDialog::Accepted)
293  {
295  config.searchPaths.removeDuplicates();
297  // d.setPaths(config.searchPaths);
298  // d.setRemoteStatesLocked(config.lockRemoteStates);
299  // if(d.exec() == QDialog::Accepted)
300  // {
301  // config.searchPaths = d.getPaths();
302  // searchAndAddPaths(config.searchPaths);
304  stateEditorController->setLockRemoteStatesByDefault(config.lockRemoteStates);
306  }
307  }
308 
309  void
311  {
312  editor->getUI()->treeViewProgressBar->show();
313  editor->getUI()->treeViewProgressBar->setMaximum(groups.size());
314  int i = 1;
315  foreach (QString groupPath, groups)
316  {
317  treeController->onOpenGroup(groupPath);
318  editor->getUI()->treeViewProgressBar->setValue(i);
319  i++;
320  qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
321  }
322  editor->getUI()->treeViewProgressBar->hide();
323  }
324 
325  void
327  {
328  paths.removeDuplicates();
329  QStringList groups;
330  foreach (QString path, paths)
331  {
332  groups.append(findAllStatechartGroupDefinitions(path.trimmed()));
333  }
334  openStatechartGroups(groups);
335  }
336 
337  void
339  {
340  StatechartView* view = editor->getUI()->stateTabWidget->currentStateview();
341 
342  if (view)
343  {
344  connect(view,
345  SIGNAL(selectedStateChanged(statechartmodel::StateInstancePtr)),
346  this,
348  }
349  }
350 
351  void
353  {
354  if (stateInstance && stateInstance->getStateClass())
355  {
356  StateTreeNodePtr node = treeController->getNodeByState(stateInstance->getStateClass());
357 
358  if (node)
359  {
360  std::string filePath = node->getBoostCppFilePath().c_str();
361  showCodeFileContent(QString::fromStdString(filePath));
362  }
363  }
364  }
365 
366  void
368  {
369  watcher->removePath(path);
370  std::string fileContent;
371 
372  if (std::filesystem::exists(path.toUtf8().data()))
373  {
374  watcher->addPath(path);
375  fileContent = RapidXmlReader::ReadFileContents(path.toUtf8().data());
376  }
377  else
378  {
379  fileContent = "<cpp missing>";
380  }
381 
382  int line = editor->getUI()->textEditCppCode->textCursor().blockNumber();
383  QTextCursor cursor = editor->getUI()->textEditCppCode->textCursor();
384  cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, line);
385  editor->getUI()->textEditCppCode->setText(QString::fromUtf8(fileContent.c_str()));
386  editor->getUI()->textEditCppCode->setTextCursor(cursor);
387  }
388 
389  void
391  {
392  editor->getUI()->textEditCppCode->find("::CreateInstance(");
393  editor->getUI()->textEditCppCode->find("::onEnter()", QTextDocument::FindBackward);
394  }
395 
396  void
398  {
399  editor->getUI()->textEditCppCode->find("::CreateInstance(");
400  editor->getUI()->textEditCppCode->find("::run()", QTextDocument::FindBackward);
401  }
402 
403  void
405  {
406  editor->getUI()->textEditCppCode->find("::CreateInstance(");
407  editor->getUI()->textEditCppCode->find("::onBreak()", QTextDocument::FindBackward);
408  }
409 
410  void
412  {
413  editor->getUI()->textEditCppCode->find("::CreateInstance(");
414  editor->getUI()->textEditCppCode->find("::onExit()", QTextDocument::FindBackward);
415  }
416 
417  void
419  {
421 
422  if (editor->getUI()->stateTabWidget->currentStateview())
423  {
424 
425  auto selection =
426  editor->getUI()->stateTabWidget->currentStateview()->getScene()->selectedItems();
427 
428  for (QGraphicsItem* item : selection)
429  {
430  StateItem* stateItem = dynamic_cast<StateItem*>(item);
431 
432  if (stateItem)
433  {
434  if (stateItem->getStateInstance())
435  {
436  state = stateItem->getStateInstance()->getStateClass();
437 
438  if (state)
439  {
440  break;
441  }
442  }
443  }
444  }
445  }
446 
447  if (state)
448  {
449  auto node = treeController->getNodeByState(state);
450 
451  if (node && node->isState())
452  {
453  treeController->openStateCPP(node);
454  }
455  }
456  else
457  {
458  showMessageBox("No state with a StateClass is selected");
459  }
460  }
461 
462  void
464  {
465  editor->getStateTabWidget()->clear();
466  }
467 
468  void
470  {
471  StatechartView* view = editor->getUI()->stateTabWidget->currentStateview();
472  if (!executedOpenedGroup)
473  {
474  if (view)
475  {
476  auto node =
477  treeController->getNodeByState(view->getStateInstance()->getStateClass());
478  if (node)
479  {
480  if (node->isPublic())
481  {
482  treeController->executeGroupWithDependencies(
483  node->getGroup(),
484  view->getStateInstance()->getStateClass()->getStateName());
485  executedOpenedGroup = node->getGroup();
486  editor->getUI()->toolButtonRunState->setIcon(QIcon(":/icons/delete.ico"));
487  editor->getUI()->toolButtonRunState->setToolTip(
488  "Stop the Statechart Group");
489  editor->getUI()->toolButtonWatchStateExecution->setEnabled(false);
490  editor->getUI()->labelExecutionState->setVisible(true);
491  alreadyWatchingState = false;
492  executionStatusTask->start();
493  }
494  else
495  {
496  QMessageBox::warning(
497  editor,
498  "Execution not possible",
499  "You can only execute public state. Right-click on the state in the "
500  "tree view on the left and select 'Public State'.");
501  }
502  }
503  }
504  else
505  {
506  QMessageBox::warning(
507  editor,
508  "Execution not possible",
509  "You need to open a state before executing it with this button.");
510  }
511  }
512  else
513  {
514  if (executedOpenedGroup)
515  {
516  treeController->stopGroupExecutionWithDependencies(executedOpenedGroup);
517  executedOpenedGroup.reset();
518  executionStatusTask->stop();
519  editor->getUI()->labelExecutionState->setVisible(false);
520  }
521  editor->getUI()->toolButtonRunState->setToolTip("Start the Statechart Group");
522  editor->getUI()->toolButtonRunState->setIcon(QIcon(":/icons/run.svg"));
523  editor->getUI()->toolButtonWatchStateExecution->setEnabled(true);
524  if (view)
525  {
526  view->getScene()->clearActiveSubstates();
527  }
528  std::function<void(StateItem * state)> unsubscriptionLamba;
529  unsubscriptionLamba = [&](StateItem* state)
530  {
531  stateWatcher->unsubscribeState(state);
532  for (auto stateInstance : state->getSubstateItems())
533  {
534  if (stateInstance)
535  {
536  unsubscriptionLamba(stateInstance);
537  }
538  }
539  };
540  unsubscriptionLamba(view->getScene()->getTopLevelStateItem());
541  }
542  }
543 
544  void
545  StatechartEditorController::updateExecutionButtonStatus()
546  {
547  bool changeToWaiting = false;
548  QString labelText = "";
549  if (executedOpenedGroup)
550  {
551  std::string proxyName =
552  executedOpenedGroup->getName().toStdString() + "StateComponentAppManager";
553  std::string objName = config.selectedProfile->getName() +
554  executedOpenedGroup->getName().toStdString() +
555  "RemoteStateOfferer";
556  ArmarXManagerInterfacePrx stateComponentProxy =
557  getProxy<ArmarXManagerInterfacePrx>(proxyName, false, "", false);
558  try
559  {
560  if (getArmarXManager()->getIceManager()->isObjectReachable(objName))
561  {
562  // Dont need to do anything, the RemoteStateOfferer is already running.
563  }
564  else if (stateComponentProxy)
565  {
566  auto state = stateComponentProxy->getObjectState(objName);
567  if (state != eManagedIceObjectStarted)
568  {
569  Ice::StringSeq deps;
570  for (auto elem :
571  stateComponentProxy->getObjectConnectivity(objName).dependencies)
572  {
573  ManagedIceObjectDependencyBasePtr dep = elem.second;
574  if (!dep->getResolved())
575  {
576  if (deps.size() >= 2)
577  {
578  deps.push_back("...");
579  break;
580  }
581  else
582  {
583  deps.push_back(dep->getName());
584  }
585  }
586  }
587  labelText = "Waiting for dependencies: " +
588  QString::fromStdString(simox::alg::join(deps, ", "));
589  changeToWaiting = true;
590  }
591  }
592  else
593  {
594  labelText = "Waiting for statechart group to start";
595  changeToWaiting = true;
596  }
597  }
598  catch (const Ice::Exception& e)
599  {
600  labelText = "Waiting for statechart group to start (ice-exception catched)";
601  changeToWaiting = true;
602  }
603 
604  catch (...)
605  {
606  labelText = "Waiting for statechart group to start (exception catched)";
607  changeToWaiting = true;
608  }
609 
610  if (!changeToWaiting)
611  {
612  labelText = "Statechart group is running";
613  if (editor->getUI()->toolButtonWatchStateExecution->isChecked() &&
614  !alreadyWatchingState)
615  {
616  watchState(objName);
617  }
618  }
619  }
620  QMetaObject::invokeMethod(editor->getUI()->labelExecutionState,
621  "setText",
622  Qt::QueuedConnection,
623  Q_ARG(QString, labelText));
624  // editor->getUI()->labelExecutionState->setText(labelText);
625  }
626 
627  void
628  StatechartEditorController::watchState(const std::string& objName)
629  {
630  RemoteStateOffererInterfacePrx statechartHandler =
631  getProxy<RemoteStateOffererInterfacePrx>(objName, false, "", false);
632  // ARMARX_INFO << deactivateSpam(4) << "getting proxy for " << objName;
633  StatechartView* view = editor->getUI()->stateTabWidget->currentStateview();
634  if (view)
635  {
636  std::string globalStateName =
637  "TopLevel->" +
638  view->getStateInstance()->getStateClass()->getStateName().toStdString();
639  QMap<QString, StateInstanceData> instanceData =
640  view->getScene()->getStateInstanceData();
641  auto toplevelPathString = view->getScene()->getTopLevelStateItem()->getFullStatePath();
642  auto asyncResult =
643  statechartHandler->begin_getStatechartInstanceByGlobalIdStr(globalStateName);
644  while (!asyncResult->isCompleted())
645  {
646  if (getState() >= eManagedIceObjectExiting)
647  {
648  return;
649  }
650  usleep(10000);
651  // qApp->processEvents();
652  }
653  armarx::StateIceBasePtr stateptr =
654  statechartHandler->end_getStatechartInstanceByGlobalIdStr(asyncResult);
655  if (!stateptr)
656  {
657  // ARMARX_WARNING_S << deactivateSpam(4) << "Could not find state with name " << globalStateName;
658  }
659  else
660  {
661 
662 
663  std::function<void(StateIceBasePtr iceState, StateItem * state)> subscriptionLamba;
664  subscriptionLamba = [&](StateIceBasePtr iceState, StateItem* state)
665  {
666  stateWatcher->subscribeToState(iceState, state);
667  size_t i = 0;
668  for (auto stateInstance : state->getSubstateItems())
669  {
670  if (stateInstance->getStateInstance()->getStateClass() &&
671  iceState->subStateList.size() > i)
672  {
673  subscriptionLamba(
674  StateIceBasePtr::dynamicCast(iceState->subStateList.at(i)),
675  stateInstance);
676  }
677  i++;
678  }
679  };
680  subscriptionLamba(stateptr, view->getScene()->getTopLevelStateItem());
681 
682  alreadyWatchingState = true;
683  }
684  }
685  }
686 
687  QPointer<QWidget>
689  {
690  if (!editor)
691  {
692  // QWidget* w = qobject_cast<QWidget*>(new StatechartEditorMainWindow());
693  editor = new StatechartEditorMainWindow();
694  }
695 
696  return qobject_cast<QWidget*>(editor);
697  }
698 
699  void
700  StatechartEditorController::initWidget()
701  {
702  getWidget()->setFocusPolicy(Qt::WheelFocus);
703 
704 
705  ARMARX_INFO << "selectedProfile: " << config.selectedProfile->getFullName();
706  ARMARX_INFO << "profile packages: " << config.selectedProfile->getAllPackages();
707  variantInfo = VariantInfo::ReadInfoFiles(
708  {"ArmarXCore"},
709  true,
710  false); // read core variantinfo file in case the root profile is selected
711  for (const auto& eventuallyNamespacedPackage : config.selectedProfile->getAllPackages())
712  {
714  eventuallyNamespacedPackage, "", true, variantInfo);
715  }
716  editor->setCommunicator(getIceManager()->getCommunicator());
717  editor->setVariantInfo(variantInfo);
718  editor->setCurrentProfile(config.selectedProfile);
719  editor->getUI()->toolBarViewControl->addWidget(new QLabel(
720  QString::fromStdString("Selected Profile: " + config.selectedProfile->getFullName())));
721  editor->getUI()->toolBarViewControl->insertWidget(
722  editor->getUI()->actionEdit_State_Properties, new QLabel("Active State:"));
723 
724  QList<QVariant> header;
725  header.push_back(QString("TEST"));
726  treeController.reset(new StateTreeController(getIceManager()->getCommunicator(),
727  variantInfo,
728  header,
729  editor->getUI()->treeViewGroups,
730  editor->getUI()->lineEditStateSearch,
731  packageTool,
732  profiles,
734  this));
735 
736 
737  QStringList searchPaths;
739  {
740  for (std::string eventuallyNamespacedPackage : config.selectedProfile->getAllPackages())
741  {
742  // check for namespaced package
743  const auto elements = simox::alg::split(eventuallyNamespacedPackage, "::");
744  ARMARX_IMPORTANT << VAROUT(elements);
745 
746  const std::string cmakePackageName =
747  simox::alg::replace_all(eventuallyNamespacedPackage, "::", "_");
748 
749  for (const auto& includePath :
750  CMakePackageFinder(cmakePackageName).getIncludePathList())
751  {
752  ARMARX_IMPORTANT << VAROUT(includePath);
753 
754  if (elements.size() == 1) // standard packages
755  {
756  std::filesystem::path packageStatechartPath(includePath.c_str());
757  packageStatechartPath /= cmakePackageName;
758  packageStatechartPath /= "statecharts";
759 
760  if (std::filesystem::exists(packageStatechartPath) &&
761  !std::filesystem::exists(
762  packageStatechartPath /
763  "cmake_install.cmake")) // do not add the build dir
764  {
765  ARMARX_VERBOSE << "Adding statechart search path: "
766  << packageStatechartPath.string();
767  searchPaths.push_back(packageStatechartPath.c_str());
768  }
769  }
770 
771  if (elements.size() == 2) // special handling of namespaced packages
772  {
773  std::filesystem::path packageStatechartPathArmarXPackage(
774  includePath.c_str());
775 
776  packageStatechartPathArmarXPackage /= elements.at(0);
777  packageStatechartPathArmarXPackage /= elements.at(1);
778  packageStatechartPathArmarXPackage /= "statecharts";
779 
780  ARMARX_IMPORTANT << VAROUT(packageStatechartPathArmarXPackage);
781 
782  if (std::filesystem::exists(packageStatechartPathArmarXPackage) &&
783  !std::filesystem::exists(
784  packageStatechartPathArmarXPackage /
785  "cmake_install.cmake")) // do not add the build dir
786  {
787  ARMARX_IMPORTANT << "Adding statechart search path: "
788  << packageStatechartPathArmarXPackage.string();
789  searchPaths.push_back(packageStatechartPathArmarXPackage.c_str());
790  }
791  }
792  }
793  }
794  }
795  config.searchPaths.removeDuplicates();
796 
797 
798  connect(editor->getUI()->actionNew_State_Definition,
799  SIGNAL(triggered()),
800  treeController.get(),
801  SLOT(onNewStateDefinition()));
802  connect(editor->getUI()->actionDelete_State_Definition,
803  SIGNAL(triggered()),
804  treeController.get(),
805  SLOT(onDeleteNode()));
806  connect(editor->getUI()->treeViewGroups,
807  SIGNAL(doubleClicked(QModelIndex)),
808  SLOT(treeviewGroupsDoubleClicked(QModelIndex)));
809  connect(editor->getUI()->actionSave_State, SIGNAL(triggered()), SLOT(requestSave()));
810  connect(editor->getUI()->stateTabWidget,
811  SIGNAL(currentChanged(int)),
812  SLOT(onStateTabChanged(int)));
813  connect(editor->getUI()->actionNew_Statechart_Group,
814  SIGNAL(triggered()),
815  this,
817  connect(editor->getUI()->actionOpenStatechartGroup,
818  SIGNAL(triggered()),
819  treeController.get(),
820  SLOT(onOpenGroup()));
821  connect(editor->getUI()->actionSettings,
822  SIGNAL(triggered()),
823  this,
825  connect(editor->getUI()->toolButtonRunState,
826  SIGNAL(clicked(bool)),
827  this,
828  SLOT(executeOpenedState(bool)));
829 
830  connect(treeController.get(), SIGNAL(closeAllTabsRequested()), this, SLOT(closeAllTabs()));
831 
832  // setup plugin specific shortcuts
833  editor->getUI()->actionOpenStatechartGroup->setShortcutContext(
834  Qt::WidgetWithChildrenShortcut);
835  editor->getUI()->actionOpenStatechartGroup->setShortcut(tr("Ctrl+O"));
836  getWidget()->addAction(editor->getUI()->actionOpenStatechartGroup);
837 
838 
839  stateEditorController.reset(new StateEditorController(editor,
840  treeController,
842  variantInfo,
844  getTipDialog()));
845  stateEditorController->setLockRemoteStatesByDefault(config.lockRemoteStates);
846  connect(editor->getUI()->stateTabWidget,
847  SIGNAL(currentChanged(int)),
848  this,
849  SLOT(connectToView(int)),
850  Qt::UniqueConnection);
851  connect(editor->getUI()->radioOnEnter,
852  SIGNAL(clicked()),
853  this,
854  SLOT(showOnEnterFunction()),
855  Qt::UniqueConnection);
856  connect(editor->getUI()->radioOnBreak,
857  SIGNAL(clicked()),
858  this,
859  SLOT(showOnBreakFunction()),
860  Qt::UniqueConnection);
861  connect(editor->getUI()->radioRun,
862  SIGNAL(clicked()),
863  this,
864  SLOT(showRunFunction()),
865  Qt::UniqueConnection);
866  connect(editor->getUI()->radioOnExit,
867  SIGNAL(clicked()),
868  this,
869  SLOT(showOnExitFunction()),
870  Qt::UniqueConnection);
871 
872 
873  connect(
874  editor->getUI()->btnOpenCppCode, SIGNAL(clicked()), this, SLOT(openSelectedState()));
875 
876  watcher = new QFileSystemWatcher(editor);
877  connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(showCodeFileContent(QString)));
878 
879  searchAndOpenPaths(config.searchPaths + searchPaths);
880  // OpenStatechartGroups(config.groupsToLoad);
881  // config.groupsToLoad.clear();
882  treeController->collapseAll();
883  executionStatusTask = new PeriodicTask<StatechartEditorController>(
884  this, &StatechartEditorController::updateExecutionButtonStatus, 300);
885  }
886 
887  bool
889  {
890  // QSettings s("KIT", "ArmarXStatechartEditor");
891  // saveSettings(&s);
893  }
894 
895  void
897  {
899  qobject_cast<StatechartEditorConfigDialog*>(getConfigDialog(getWidget()));
902  }
903 
904 } // namespace armarx
905 
906 QPointer<QDialog>
908 {
909  if (!dialog)
910  {
912  Application::getInstance()->getArmarXPackageNames());
913  dialog = new StatechartEditorConfigDialog(profiles, parent);
914  }
915 
916  return qobject_cast<StatechartEditorConfigDialog*>(dialog);
917 }
armarx::StatechartEditorConfigDialog::getSelectedProfile
StatechartProfilePtr getSelectedProfile()
Definition: StatechartEditorConfigDialog.cpp:52
armarx::StatechartView::getScene
StateScene * getScene() const
Definition: StatechartView.h:54
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
armarx::ManagedIceObject::getIceManager
IceManagerPtr getIceManager() const
Returns the IceManager.
Definition: ManagedIceObject.cpp:353
armarx::StatechartEditorController::Config::lockRemoteStates
bool lockRemoteStates
Definition: StatechartEditorController.h:213
armarx::StatechartEditorController::treeviewGroupsDoubleClicked
void treeviewGroupsDoubleClicked(QModelIndex index)
Definition: StatechartEditorController.cpp:219
armarx::EditStatechartGroupDialog::getProxies
QList< QString > getProxies() const
Definition: EditStatechartGroupDialog.cpp:252
armarx::StatechartEditorSettingsDialog::setPaths
void setPaths(QStringList paths)
Definition: StatechartEditorSettingsDialog.cpp:66
armarx::RapidXmlReader::ReadFileContents
static std::string ReadFileContents(const std::string &path)
Definition: RapidXmlReader.h:462
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::StateScene::clearActiveSubstates
void clearActiveSubstates()
Definition: StateScene.cpp:69
armarx::StateTreeNodePtr
std::shared_ptr< StateTreeNode > StateTreeNodePtr
Definition: StatechartGroupDefs.h:31
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::StatechartEditorController::showCodeFileContent
void showCodeFileContent(const QString &path)
Definition: StatechartEditorController.cpp:367
armarx::StatechartEditorController::getConfigDialog
QPointer< QDialog > getConfigDialog(QWidget *parent) override
getConfigDialog returns a pointer to the a configuration widget of this controller.
Definition: StatechartEditorController.cpp:907
armarx::StateItem::getStateInstance
statechartmodel::StateInstancePtr getStateInstance() const
Definition: StateItem.h:70
armarx::StatechartEditorSettingsDialog::setRemoteStatesLocked
void setRemoteStatesLocked(bool locked)
Definition: StatechartEditorSettingsDialog.cpp:54
armarx::ManagedIceObject::getArmarXManager
ArmarXManagerPtr getArmarXManager() const
Returns the ArmarX manager used to add and remove components.
Definition: ManagedIceObject.cpp:348
armarx::ManagedIceObject::getState
int getState() const
Retrieve current state of the ManagedIceObject.
Definition: ManagedIceObject.cpp:725
armarx::StateWatcher
Definition: StateWatcher.h:36
armarx::StatechartEditorSettingsDialog::getPaths
QStringList getPaths() const
Definition: StatechartEditorSettingsDialog.cpp:48
armarx::StatechartEditorController::showStatechartEditorSettingsDialog
void showStatechartEditorSettingsDialog()
Definition: StatechartEditorController.cpp:287
armarx::StatechartEditorController::~StatechartEditorController
~StatechartEditorController() override
Definition: StatechartEditorController.cpp:69
armarx::StatechartEditorController::openStatechartGroups
void openStatechartGroups(QStringList groups)
Definition: StatechartEditorController.cpp:310
StatechartEditorMainWindow.h
armarx::StatechartEditorController::searchAndOpenPaths
void searchAndOpenPaths(QStringList paths)
Definition: StatechartEditorController.cpp:326
EditStatechartGroupDialog.h
armarx::ArmarXPackageToolInterface
The ArmarXPackageToolInterface class.
Definition: ArmarXPackageToolInterface.h:38
armarx::StatechartEditorController::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: StatechartEditorController.cpp:149
armarx::StatechartEditorController::Config::selectedProfile
StatechartProfilePtr selectedProfile
Definition: StatechartEditorController.h:215
armarx::StatechartEditorController::onClose
bool onClose() override
onClose is called before the DockWidget is closed.
Definition: StatechartEditorController.cpp:888
armarx::StatechartEditorController::Config::openAllStatesWasSelected
bool openAllStatesWasSelected
Definition: StatechartEditorController.h:214
armarx::statechartmodel::StateInstancePtr
std::shared_ptr< StateInstance > StateInstancePtr
Definition: StateInstance.h:138
armarx::StatechartEditorController::Config::searchPaths
QStringList searchPaths
Definition: StatechartEditorController.h:211
armarx::StatechartEditorController::StatechartEditorController
StatechartEditorController()
Definition: StatechartEditorController.cpp:57
armarx::StatechartEditorController::configured
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
Definition: StatechartEditorController.cpp:896
armarx::ArmarXWidgetController::getTipDialog
QPointer< TipDialog > getTipDialog() const
Returns the default instance for the TipDialog used by all widgets (if not set otherwise).
Definition: ArmarXWidgetController.cpp:130
armarx::StateScene::getTopLevelStateItem
StateItem * getTopLevelStateItem() const
Definition: StateScene.cpp:130
armarx::StatechartView
Definition: StatechartView.h:44
armarx::StatechartEditorController::showNewStatechartGroupDialog
void showNewStatechartGroupDialog()
Definition: StatechartEditorController.cpp:262
armarx::StatechartEditorSettingsDialog
Definition: StatechartEditorSettingsDialog.h:34
armarx::StatechartEditorController::closeAllTabs
void closeAllTabs()
Definition: StatechartEditorController.cpp:463
armarx::EditStatechartGroupDialog
Definition: EditStatechartGroupDialog.h:44
armarx::VariantInfo::ReadInfoFilesRecursive
static VariantInfoPtr ReadInfoFilesRecursive(const std::string &rootPackageName, const std::string &rootPackagePath, bool showErrors, VariantInfoPtr variantInfo=VariantInfoPtr())
Definition: VariantInfo.cpp:347
armarx::StatechartEditorController::connectToView
void connectToView(int tabIndex)
Definition: StatechartEditorController.cpp:338
armarx::StatechartEditorSettingsDialog::getRemoteStatesLocked
bool getRemoteStatesLocked() const
Definition: StatechartEditorSettingsDialog.cpp:60
armarx::StatechartView::showSubSubstates
void showSubSubstates(bool show=true)
Definition: StatechartView.cpp:169
StateTreeModel.h
armarx::StatechartEditorController::requestSave
void requestSave()
Definition: StatechartEditorController.cpp:243
armarx::StatechartEditorController::showOnExitFunction
void showOnExitFunction()
Definition: StatechartEditorController.cpp:411
armarx::Application::getInstance
static ApplicationPtr getInstance()
Retrieve shared pointer to the application object.
Definition: Application.cpp:289
armarx::StatechartEditorController::getWidget
QPointer< QWidget > getWidget() override
getWidget returns a pointer to the a widget of this controller.
Definition: StatechartEditorController.cpp:688
armarx::VariantInfo::ReadInfoFiles
static VariantInfoPtr ReadInfoFiles(const std::vector< std::string > &packages, bool showErrors=true, bool throwOnError=true)
Definition: VariantInfo.cpp:414
GroupXmlWriter.h
armarx::EditStatechartGroupDialog::getConfigurations
QMap< QString, QString > getConfigurations() const
Definition: EditStatechartGroupDialog.cpp:274
armarx::StatechartEditorController::saveSettings
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
Definition: StatechartEditorController.cpp:192
armarx::EditStatechartGroupDialog::getGroupDescription
QString getGroupDescription() const
Definition: EditStatechartGroupDialog.cpp:203
armarx::StatechartGroupPtr
std::shared_ptr< StatechartGroup > StatechartGroupPtr
Definition: StatechartGroupDefs.h:34
armarx::EditStatechartGroupDialog::getGroupPath
QString getGroupPath() const
Definition: EditStatechartGroupDialog.cpp:174
armarx::StatechartEditorMainWindow
Definition: StatechartEditorMainWindow.h:46
armarx::EditStatechartGroupDialog::contextGenerationEnabled
bool contextGenerationEnabled() const
Definition: EditStatechartGroupDialog.cpp:269
armarx::StatechartEditorController::config
struct armarx::StatechartEditorController::Config config
armarx::StatechartEditorController::showOnBreakFunction
void showOnBreakFunction()
Definition: StatechartEditorController.cpp:404
armarx::ArmarXWidgetController::showMessageBox
static int showMessageBox(const QString &msg)
Definition: ArmarXWidgetController.cpp:166
armarx::StatechartEditorController::showRunFunction
void showRunFunction()
Definition: StatechartEditorController.cpp:397
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
StatechartEditorSettingsDialog.h
armarx::StatechartEditorController::executeOpenedState
void executeOpenedState(bool)
Definition: StatechartEditorController.cpp:469
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:182
armarx::EditStatechartGroupDialog::NewGroup
@ NewGroup
Definition: EditStatechartGroupDialog.h:49
StateTabWidget.h
armarx::EditStatechartGroupDialog::getGroupName
QString getGroupName() const
Definition: EditStatechartGroupDialog.cpp:169
GroupXmlReader.h
armarx::EditStatechartGroupDialog::getPackageName
QString getPackageName() const
Definition: EditStatechartGroupDialog.cpp:208
armarx::StatechartEditorController::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: StatechartEditorController.cpp:144
armarx::statechartmodel::StatePtr
std::shared_ptr< State > StatePtr
Definition: State.h:46
armarx::StateItem
Definition: StateItem.h:58
TipDialog.h
armarx::StatechartView::getStateInstance
statechartmodel::StateInstancePtr getStateInstance() const
Definition: StatechartView.cpp:86
armarx::StatechartProfiles::ReadProfileFiles
static StatechartProfilesPtr ReadProfileFiles(const std::vector< std::string > &packages)
Definition: StatechartProfiles.cpp:47
StatechartEditorController.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
ArmarXDataPath.h
armarx::ManagedIceObject::getCommunicator
Ice::CommunicatorPtr getCommunicator() const
Definition: ManagedIceObject.cpp:431
armarx::StatechartEditorController::loadSettings
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
Definition: StatechartEditorController.cpp:158
armarx::StatechartEditorController::showOnEnterFunction
void showOnEnterFunction()
Definition: StatechartEditorController.cpp:390
armarx::StatechartEditorController::openSelectedState
void openSelectedState()
Definition: StatechartEditorController.cpp:418
armarx::StatechartEditorController::storeAutoSaveSettings
void storeAutoSaveSettings()
Definition: StatechartEditorController.cpp:75
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx::ArmarXComponentWidgetController::onClose
bool onClose() override
If you overwrite this method, make sure to call this implementation at the end of your implementation...
Definition: ArmarXComponentWidgetController.cpp:42
armarx::StatechartEditorController::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: StatechartEditorController.cpp:135
armarx::StatechartEditorController::findAllStatechartGroupDefinitions
QStringList findAllStatechartGroupDefinitions(const QString &basePath)
Definition: StatechartEditorController.cpp:84
armarx::StatechartEditorConfigDialog
Definition: StatechartEditorConfigDialog.h:33
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::StatechartEditorController::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: StatechartEditorController.cpp:129
Application.h
armarx::StatechartEditorConfigDialog::openAllStatesIsSelected
bool openAllStatesIsSelected()
Definition: StatechartEditorConfigDialog.cpp:66
armarx::StateItem::getSubstateItems
QVector< StateItem * > getSubstateItems() const
Definition: StateItem.cpp:682
armarx::StatechartEditorController::showStateCode
void showStateCode(statechartmodel::StateInstancePtr stateInstance)
Definition: StatechartEditorController.cpp:352
armarx::split
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelpers.cpp:36
armarx::StatechartEditorController::onStateTabChanged
void onStateTabChanged(int index)
Definition: StatechartEditorController.cpp:249