From 2dd1a94461d084411809714975a4e1e0643f8c6b Mon Sep 17 00:00:00 2001
From: Amaury Johnan <amjohnen@gmail.com>
Date: Wed, 17 Sep 2014 16:30:24 +0000
Subject: [PATCH] fix bug extruded volume: The parser wanted to create extruded
 volume begining systematically from 1. Thus, when there already existed
 volumes with number 1,2,3,etc, extruded volumes was created.

---
 Common/OpenFile.cpp | 18 +-----------------
 Geo/Geo.cpp         | 13 +++++++++++++
 Geo/Geo.h           |  2 ++
 3 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/Common/OpenFile.cpp b/Common/OpenFile.cpp
index b6f67986bc..bb175c76bb 100644
--- a/Common/OpenFile.cpp
+++ b/Common/OpenFile.cpp
@@ -152,22 +152,6 @@ void AddToTemporaryBoundingBox(double x, double y, double z)
   for(int i = 0; i < 3; i++) CTX::instance()->cg[i] = temp_bb.center()[i];
 }
 
-static void ComputeMaxEntityNum()
-{
-  GModel::current()->getGEOInternals()->MaxPointNum =
-    std::max(GModel::current()->getGEOInternals()->MaxPointNum,
-             GModel::current()->getMaxElementaryNumber(0));
-  GModel::current()->getGEOInternals()->MaxLineNum =
-    std::max(GModel::current()->getGEOInternals()->MaxLineNum,
-             GModel::current()->getMaxElementaryNumber(1));
-  GModel::current()->getGEOInternals()->MaxSurfaceNum =
-    std::max(GModel::current()->getGEOInternals()->MaxSurfaceNum,
-             GModel::current()->getMaxElementaryNumber(2));
-  GModel::current()->getGEOInternals()->MaxVolumeNum =
-    std::max(GModel::current()->getGEOInternals()->MaxVolumeNum,
-             GModel::current()->getMaxElementaryNumber(3));
-}
-
 static std::vector<gmshFILE> openedFiles;
 
 int ParseFile(const std::string &fileName, bool close, bool warnIfMissing)
@@ -484,7 +468,7 @@ int MergeFile(const std::string &fileName, bool warnIfMissing, bool setWindowTit
     }
   }
 
-  ComputeMaxEntityNum();
+  GModel::current()->getGEOInternals()->ComputeMaxEntityNum();
   if(setBoundingBox) SetBoundingBox();
   CTX::instance()->geom.draw = 1;
   CTX::instance()->mesh.changed = ENT_ALL;
diff --git a/Geo/Geo.cpp b/Geo/Geo.cpp
index dc09d2882f..8f955dc7b7 100644
--- a/Geo/Geo.cpp
+++ b/Geo/Geo.cpp
@@ -4544,6 +4544,7 @@ void GEO_Internals::alloc_all()
 {
   MaxPointNum = MaxLineNum = MaxLineLoopNum = MaxSurfaceNum = 0;
   MaxSurfaceLoopNum = MaxVolumeNum = MaxPhysicalNum = 0;
+  ComputeMaxEntityNum();
   Points = Tree_Create(sizeof(Vertex *), compareVertex);
   Curves = Tree_Create(sizeof(Curve *), compareCurve);
   EdgeLoops = Tree_Create(sizeof(EdgeLoop *), compareEdgeLoop);
@@ -4574,6 +4575,18 @@ void GEO_Internals::reset_physicals()
   List_Reset(PhysicalGroups);
 }
 
+void GEO_Internals::ComputeMaxEntityNum()
+{
+  MaxPointNum =
+    std::max(MaxPointNum, GModel::current()->getMaxElementaryNumber(0));
+  MaxLineNum =
+    std::max(MaxLineNum, GModel::current()->getMaxElementaryNumber(1));
+  MaxSurfaceNum =
+    std::max(MaxSurfaceNum, GModel::current()->getMaxElementaryNumber(2));
+  MaxVolumeNum =
+    std::max(MaxVolumeNum, GModel::current()->getMaxElementaryNumber(3));
+}
+
 int select_contour(int type, int num, List_T * List)
 {
   int k = 0;
diff --git a/Geo/Geo.h b/Geo/Geo.h
index 024c7adb16..f454c47959 100644
--- a/Geo/Geo.h
+++ b/Geo/Geo.h
@@ -297,6 +297,8 @@ class GEO_Internals{
   void reset_physicals();
   std::map<int,int> periodicFaces;
   std::map<int,int> periodicEdges;
+
+  void ComputeMaxEntityNum();
 };
 
 class Shape{
-- 
GitLab