From 84a023cdbee5af55331362d045b7ec372ade6492 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Wed, 10 Jul 2013 18:37:45 +0000
Subject: [PATCH] when deleting a model, when no other model is visible, make
 the last one visible

---
 Geo/GModel.cpp | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp
index 316631bcfe..c051fe1031 100644
--- a/Geo/GModel.cpp
+++ b/Geo/GModel.cpp
@@ -93,13 +93,23 @@ GModel::~GModel()
 {
   std::vector<GModel*>::iterator it = std::find(list.begin(), list.end(), this);
   if(it != list.end()) list.erase(it);
+
+  if(getVisibility()){
+    // if no other model is visible, make the last one visible
+    bool othervisible = false;
+    for(unsigned int i = 0; i < list.size(); i++){
+      if(list[i]->getVisibility()) othervisible = true;
+    }
+    if(!othervisible && list.size())
+      list.back()->setVisibility(1);
+  }
+
   destroy();
   _deleteGEOInternals();
   _deleteOCCInternals();
 #if defined(HAVE_MESH)
   delete _fields;
 #endif
-
   if(_factory)
     delete _factory;
 }
-- 
GitLab