From 79e2c7404c976e40e54197c5951bfd4317cdb3cd Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Thu, 10 Sep 2015 00:01:52 +0000
Subject: [PATCH] limit export name length

---
 Geo/Chain.cpp    |  6 +++---
 Geo/Chain.h      | 14 +++++++++-----
 Geo/Homology.cpp |  2 +-
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/Geo/Chain.cpp b/Geo/Chain.cpp
index 02efc4d15f..c837aa7d6b 100644
--- a/Geo/Chain.cpp
+++ b/Geo/Chain.cpp
@@ -27,7 +27,8 @@ void updateFltk()
 #endif
 }
 
-std::string convertInt(int number){
+std::string convertInt(int number)
+{
   std::stringstream stream;
   stream << number;
   return stream.str();
@@ -49,8 +50,7 @@ inline void ElemChain::_sortVertexIndices()
 }
 
 void findEntitiesInPhysicalGroups
-(GModel* m, const std::vector<int>& physicalGroups,
-std::vector<GEntity*>& entities)
+(GModel* m, const std::vector<int>& physicalGroups, std::vector<GEntity*>& entities)
 {
   std::map<int, std::vector<GEntity*> > groups[4];
   m->getPhysicalGroups(groups);
diff --git a/Geo/Chain.h b/Geo/Chain.h
index fb1f2afb3e..f1b73ac2e0 100644
--- a/Geo/Chain.h
+++ b/Geo/Chain.h
@@ -465,14 +465,18 @@ Chain<C>& Chain<C>::operator*=(const C& coeff)
 }
 
 template <class C>
-int Chain<C>::addToModel(GModel* m, bool post,
-                         int physicalNumRequest) const
+int Chain<C>::addToModel(GModel* m, bool post, int physicalNumRequest) const
 {
   if(this->isZero()) {
     Msg::Info("A chain is zero element of C%d, not added to the model",
               this->getDim());
     return -1;
   }
+
+  std::string name = _name;
+  // avoid too long names, which screw up the GUI and the msh file
+  if(name.size() > 128) name.resize(128);
+
   std::vector<MElement*> elements;
   std::map<int, std::vector<double> > data;
   int dim = this->getDim();
@@ -511,16 +515,16 @@ int Chain<C>::addToModel(GModel* m, bool post,
   entityMap[entityNum] = elements;
   std::map<int, std::map<int, std::string> > physicalMap;
   std::map<int, std::string> physicalInfo;
-  physicalInfo[physicalNum] = _name;
+  physicalInfo[physicalNum] = name;
   physicalMap[entityNum] = physicalInfo;
   m->storeChain(dim, entityMap, physicalMap);
-  m->setPhysicalName(_name, dim, physicalNum);
+  m->setPhysicalName(name, dim, physicalNum);
 
 #if defined(HAVE_POST)
   if(post && CTX::instance()->batch == 0) {
     // create PView for instant visualization
     std::string pnum = convertInt(physicalNum);
-    std::string postname = pnum + "=" + _name;
+    std::string postname = pnum + "=" + name;
     PView* view = new PView(postname, "ElementData", m, data, 0., 1);
     // the user should be interested about the orientations
     int size = 30;
diff --git a/Geo/Homology.cpp b/Geo/Homology.cpp
index 77a9911042..d8f857bb3d 100644
--- a/Geo/Homology.cpp
+++ b/Geo/Homology.cpp
@@ -624,6 +624,7 @@ std::string Homology::_getDomainString(const std::vector<int>& domain,
     }
     domainString += "}";
   }
+
   return domainString;
 }
 
@@ -673,4 +674,3 @@ void Homology::storeCells(CellComplex* cellComplex, int dim)
 }
 
 #endif
-
-- 
GitLab