From 6eb15b99ec88282c37d23495b0ec2ef034ca8cba Mon Sep 17 00:00:00 2001
From: Stefan Reither <stef.reither@web.de>
Date: Tue, 5 Sep 2017 15:31:53 +0200
Subject: [PATCH] add more detailled error messages while starting and ending
 statecharts to StatechartEditor

---
 .../StateTreeController.cpp                   | 26 ++++++++++++-------
 .../StatechartEditorController.cpp            |  9 ++++++-
 2 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/StateTreeController.cpp b/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/StateTreeController.cpp
index 70680f64..12be46ba 100644
--- a/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/StateTreeController.cpp
+++ b/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/StateTreeController.cpp
@@ -135,17 +135,17 @@ StateTreeController::StateTreeController(Ice::CommunicatorPtr ic, VariantInfoPtr
     //stateActions.append(actionGenerateStateBaseClass);
     stateActions.append(actionGenerateStateCPP);
 
-    for (QAction * a : groupActions)
+    for (QAction* a : groupActions)
     {
         a->setIconVisibleInMenu(true);
     }
 
-    for (QAction * a : folderActions)
+    for (QAction* a : folderActions)
     {
         a->setIconVisibleInMenu(true);
     }
 
-    for (QAction * a : stateActions)
+    for (QAction* a : stateActions)
     {
         a->setIconVisibleInMenu(true);
     }
@@ -1031,7 +1031,7 @@ void StateTreeController::onRenameState()
             auto groups = stateTreeModel->getGroups();
             stateTreeModel->clear();
 
-            for (const auto & c : rootNode->getChildren())
+            for (const auto& c : rootNode->getChildren())
             {
                 if (c->isGroup())
                 {
@@ -1041,7 +1041,7 @@ void StateTreeController::onRenameState()
 
             if (StateRenamer::RenameState(d.getInstanceRenameInfos(), node, d.getNewStateName(), group))
             {
-                for (const StatechartGroupPtr & g : groups)
+                for (const StatechartGroupPtr& g : groups)
                 {
                     ARMARX_VERBOSE_S << "reloading " << g->getName();
                     auto loadedGroup = loadAndAddGroup(g->getDefinitionFilePath());
@@ -1232,7 +1232,15 @@ void StateTreeController::onExecuteGroup()
 
 void StateTreeController::onStatechartFinished(int exitCode)
 {
-    ARMARX_INFO_S << "Exited with code " << exitCode;
+    auto process = qobject_cast<QProcess*>(sender());
+    if (process)
+    {
+        ARMARX_INFO_S << process->pid() <<  " exited with code " << exitCode;
+    }
+    else
+    {
+        ARMARX_INFO_S << "Exited with code " << exitCode;
+    }
 }
 /*
 void StateTreeController::onGenerateStateBaseClass()
@@ -1314,7 +1322,7 @@ void StateTreeController::onCloneGroup()
 
         if (d.exec() == QDialog::Accepted)
         {
-            for (const auto & g : d.getGroupsToClone())
+            for (const auto& g : d.getGroupsToClone())
             {
                 if (!g.first->existsCMakeLists())
                 {
@@ -1373,7 +1381,7 @@ void StateTreeController::onRenameGroup()
                 ARMARX_VERBOSE_S << "removing groups from tree view";
                 stateTreeModel->clear();
 
-                for (const auto & c : rootNode->getChildren())
+                for (const auto& c : rootNode->getChildren())
                 {
                     if (c->isGroup())
                     {
@@ -1381,7 +1389,7 @@ void StateTreeController::onRenameGroup()
                     }
                 }
 
-                for (const StatechartGroupPtr & g : d.getAllGroups())
+                for (const StatechartGroupPtr& g : d.getAllGroups())
                 {
                     if (g->getGroupPath() == group->getGroupPath())
                     {
diff --git a/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/StatechartEditorController.cpp b/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/StatechartEditorController.cpp
index ec901129..de14daf0 100644
--- a/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/StatechartEditorController.cpp
+++ b/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/StatechartEditorController.cpp
@@ -517,9 +517,16 @@ namespace armarx
                     changeToWaiting = true;
                 }
             }
+            catch (const Ice::Exception& e)
+            {
+                ARMARX_ERROR_S << "querying state of " << proxyName << " failed:\n" << e.what() << std::endl << e.ice_stackTrace();
+                labelText = "Waiting for statechart group to start (ice-exception catched)";
+                changeToWaiting = true;
+            }
+
             catch (...)
             {
-                labelText = "Waiting for statechart group to start";
+                labelText = "Waiting for statechart group to start (exception catched)";
                 changeToWaiting = true;
             }
 
-- 
GitLab