From 903c754b32c6d34dcade31335939d02d3ca8a553 Mon Sep 17 00:00:00 2001
From: Mirko Waechter <mirko.waechter@kit.edu>
Date: Fri, 17 Jun 2016 18:28:27 +0200
Subject: [PATCH] added sanity checks

---
 .../StatechartViewerPlugin/model/State.cpp            | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/source/ArmarXGui/gui-plugins/StatechartViewerPlugin/model/State.cpp b/source/ArmarXGui/gui-plugins/StatechartViewerPlugin/model/State.cpp
index 96cc9531..601e88c1 100644
--- a/source/ArmarXGui/gui-plugins/StatechartViewerPlugin/model/State.cpp
+++ b/source/ArmarXGui/gui-plugins/StatechartViewerPlugin/model/State.cpp
@@ -375,6 +375,10 @@ StateInstancePtr statechartmodel::State::addSubstate(StateInstancePtr stateInsta
     {
         return StateInstancePtr();
     }
+    if (stateInstance->getStateClass() && !checkSubstate(stateInstance->getStateClass()))
+    {
+        return StateInstancePtr();
+    }
 
     substates.insert(stateInstance->getInstanceName(), stateInstance);
 
@@ -545,6 +549,10 @@ StateInstancePtr statechartmodel::State::replaceSubstate(QString stateInstanceNa
     if (it != substates.end())
     {
         // TODO: This should also try to keep all transitions
+        if (newInstance->getStateClass() && !checkSubstate(newInstance->getStateClass()))
+        {
+            return StateInstancePtr();
+        }
         removeSubstate(stateInstanceName);
         newInstance->setPosition(it.value()->getTopLeft());
         return addSubstate(newInstance);
@@ -1070,10 +1078,11 @@ bool statechartmodel::State::checkSubstate(StatePtr newState) const
     {
         return false;
     }
-
     return true;
 }
 
+
+
 TransitionPtr statechartmodel::State::findTransition(TransitionCPtr t) const
 {
     for (int i = 0 ; i < transitions.size(); i++)
-- 
GitLab