From 1242f3fd014393edde19c7f2f28c3b55c21ccb05 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Sun, 13 Mar 2005 17:58:38 +0000
Subject: [PATCH] - better test for drawing geo+mesh bbox - ask if we want to
 uncompress gz files during merge

---
 Fltk/Callbacks.cpp  | 12 +++----
 Graphics/Mesh.cpp   | 20 +++++++----
 Parser/OpenFile.cpp | 87 ++++++++++++++++++++++++++-------------------
 3 files changed, 69 insertions(+), 50 deletions(-)

diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp
index 7a6ccf12ee..80f38f4071 100644
--- a/Fltk/Callbacks.cpp
+++ b/Fltk/Callbacks.cpp
@@ -1,4 +1,4 @@
-// $Id: Callbacks.cpp,v 1.346 2005-03-12 20:17:41 geuzaine Exp $
+// $Id: Callbacks.cpp,v 1.347 2005-03-13 17:58:37 geuzaine Exp $
 //
 // Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle
 //
@@ -501,7 +501,7 @@ void file_new_cb(CALLBACK_ARGS)
     char *name = file_chooser_get_name(1);
     struct stat buf;
     if(!stat(name, &buf)){
-      if(fl_ask("%s already exists.\n\nDo you want to erase it?", name))
+      if(fl_ask("File '%s' already exists.\n\nDo you want to erase it?", name))
 	unlink(name);
       else
 	goto test;
@@ -740,7 +740,7 @@ void file_save_as_cb(CALLBACK_ARGS)
     if(CTX.confirm_overwrite) {
       struct stat buf;
       if(!stat(name, &buf))
-        if(!fl_ask("%s already exists.\n\nDo you want to replace it?", name))
+        if(!fl_ask("File '%s' already exists.\n\nDo you want to replace it?", name))
           goto test;
     }
     i = file_chooser_get_filter();
@@ -761,7 +761,7 @@ void file_rename_cb(CALLBACK_ARGS)
     if(CTX.confirm_overwrite) {
       struct stat buf;
       if(!stat(name, &buf))
-        if(!fl_ask("%s already exists.\n\nDo you want to replace it?", name))
+        if(!fl_ask("File '%s' already exists.\n\nDo you want to replace it?", name))
           goto test;
     }
     rename(CTX.filename, name);
@@ -1216,7 +1216,7 @@ void message_save_cb(CALLBACK_ARGS)
     if(CTX.confirm_overwrite) {
       struct stat buf;
       if(!stat(name, &buf))
-        if(!fl_ask("%s already exists.\n\nDo you want to replace it?", name))
+        if(!fl_ask("File '%s' already exists.\n\nDo you want to replace it?", name))
           goto test;
     }
     WID->save_message(name);
@@ -3246,7 +3246,7 @@ static void _view_save_as(int view_num, char *title, int type)
     if(CTX.confirm_overwrite) {
       struct stat buf;
       if(!stat(name, &buf))
-        if(!fl_ask("%s already exists.\n\nDo you want to replace it?", name))
+        if(!fl_ask("File '%s' already exists.\n\nDo you want to replace it?", name))
           goto test;
     }
     WriteView(v, name, type, 0);
diff --git a/Graphics/Mesh.cpp b/Graphics/Mesh.cpp
index 56fced8ca0..d1384ba3a4 100644
--- a/Graphics/Mesh.cpp
+++ b/Graphics/Mesh.cpp
@@ -1,4 +1,4 @@
-// $Id: Mesh.cpp,v 1.122 2005-03-12 07:52:56 geuzaine Exp $
+// $Id: Mesh.cpp,v 1.123 2005-03-13 17:58:37 geuzaine Exp $
 //
 // Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle
 //
@@ -140,11 +140,15 @@ void Draw_Mesh(Mesh * M)
   if(CTX.render_mode == GMSH_SELECT)
     return;
 
-  // draw the bounding box of the mesh if we are in fast redraw mode
-  // and there is no geometry
- 
-  if((CTX.draw_bbox && (Tree_Nbr(M->Vertices) || Tree_Nbr(M->Points))) ||
-     (!CTX.mesh.draw && Tree_Nbr(M->Vertices) && !Tree_Nbr(M->Points))) {
+  // draw the bounding box if we asked for it and we have a geometry
+  // or a mesh, or if we are in fast redraw mode and there is no
+  // geometry but there is a mesh
+  
+  int somegeo = 
+    Tree_Nbr(M->Points) || Tree_Nbr(M->Curves) || Tree_Nbr(M->Surfaces);
+
+  if((CTX.draw_bbox && (somegeo || Tree_Nbr(M->Vertices))) ||
+     (!CTX.mesh.draw && !somegeo && Tree_Nbr(M->Vertices))) {
     glColor4ubv((GLubyte *) & CTX.color.fg);
     glLineWidth(CTX.line_width);
     gl2psLineWidth(CTX.line_width * CTX.print.eps_line_width_factor);
@@ -198,6 +202,8 @@ void Draw_Mesh(Mesh * M)
 			      CTX.mesh.cut_planec, CTX.mesh.cut_planed);
   }
 
+  // draw the axes
+
   if(CTX.axes){
     glColor4ubv((GLubyte *) & CTX.color.axes);
     glLineWidth(CTX.line_width);
@@ -206,7 +212,7 @@ void Draw_Mesh(Mesh * M)
       Draw_Axes(CTX.axes, CTX.axes_tics, CTX.axes_format, CTX.axes_label, 
 		CTX.axes_position);
     }
-    else if(Tree_Nbr(M->Vertices) || Tree_Nbr(M->Points)){
+    else if(somegeo || Tree_Nbr(M->Vertices)){
       double bb[6] = { CTX.min[0], CTX.max[0],
 		       CTX.min[1], CTX.max[1],
 		       CTX.min[2], CTX.max[2] };
diff --git a/Parser/OpenFile.cpp b/Parser/OpenFile.cpp
index 2b8073254a..41f79e70f4 100644
--- a/Parser/OpenFile.cpp
+++ b/Parser/OpenFile.cpp
@@ -1,4 +1,4 @@
-// $Id: OpenFile.cpp,v 1.72 2005-03-01 17:47:54 geuzaine Exp $
+// $Id: OpenFile.cpp,v 1.73 2005-03-13 17:58:38 geuzaine Exp $
 //
 // Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle
 //
@@ -71,6 +71,19 @@ void FixWindowsPath(char *in, char *out){
 #endif
 }
 
+void SplitFileName(char *name, char *base, char *ext)
+{
+  strcpy(base, name);
+  strcpy(ext, "");
+  for(int i = strlen(name)-1; i >= 0; i--){
+    if(name[i] == '.'){
+      strcpy(ext, &name[i]);
+      base[i] = '\0';
+      break;
+    }
+  }
+}
+
 void SetBoundingBox(double xmin, double xmax,
 		    double ymin, double ymax, 
 		    double zmin, double zmax)
@@ -264,9 +277,24 @@ void ParseString(char *str)
   }
 }
 
+void SetProjectName(char *name)
+{
+  char base[356], ext[256];
+  SplitFileName(name, base, ext);
+
+  strncpy(CTX.filename, name, 255);
+  strncpy(CTX.base_filename, base, 255);
+  strncpy(THEM->name, CTX.base_filename, 255);
+
+#if defined(HAVE_FLTK)
+  if(!CTX.batch)
+    WID->set_title(CTX.filename);
+#endif
+}
+
 int MergeProblem(char *name, int warn_if_missing)
 {
-  char ext[5], tmp[256];
+  char ext[256], base[256], tmp[256];
   int status;
   FILE *fp;
 
@@ -276,13 +304,25 @@ int MergeProblem(char *name, int warn_if_missing)
     return 0;
   }
 
-  if(strlen(name) > 4) {
-    strncpy(ext, &name[strlen(name) - 4], 5);
-  }
-  else {
-    strcpy(ext, "");
-  }
+  SplitFileName(name, base, ext);
 
+#if defined(HAVE_FLTK)
+  if(!CTX.batch) {
+    if(!strcmp(ext, ".gz")) {
+      // the real solution would be to rewrite all our I/O functions in
+      // terms of gzFile, but until then, this is better than nothing
+      if(fl_ask("File '%s' is in gzip format.\n\nDo you want to uncompress it?", name)){
+	fclose(fp);
+	sprintf(tmp, "gunzip -c %s > %s", name, base);
+	SystemCall(tmp);
+	if(!strcmp(CTX.filename, name)) // this is the project file
+	  SetProjectName(base);
+	return MergeProblem(base);
+      }
+    }
+  }
+#endif
+  
   if(!strcmp(ext, ".ppm") || !strcmp(ext, ".pnm")) {
     // An image file is used as an input, we transform it onto a post
     // pro file that could be used as a background mesh. We should
@@ -335,8 +375,6 @@ int MergeProblem(char *name, int warn_if_missing)
 
 void OpenProblem(char *name)
 {
-  char ext[6];
-
   if(CTX.threads_lock) {
     Msg(INFO, "I'm busy! Ask me that later...");
     return;
@@ -349,34 +387,9 @@ void OpenProblem(char *name)
   // Initialize pseudo random mesh generator to the same seed
   srand(1);
 
-  strncpy(CTX.filename, name, 255);
-  strncpy(CTX.base_filename, name, 255);
-
-  if(strlen(name) > 4) {
-    strncpy(ext, &name[strlen(name) - 4], 5);
-  }
-  else {
-    strcpy(ext, "");
-  }
-
-  if(!strcmp(ext, ".geo") || !strcmp(ext, ".GEO") ||
-     !strcmp(ext, ".msh") || !strcmp(ext, ".MSH") ||
-     !strcmp(ext, ".stl") || !strcmp(ext, ".STL") ||
-     !strcmp(ext, ".sms") || !strcmp(ext, ".SMS") ||
-     !strcmp(ext, ".ppm") || !strcmp(ext, ".PPM") ||
-     !strcmp(ext, ".pnm") || !strcmp(ext, ".PNM") ||
-     !strcmp(ext, ".pos") || !strcmp(ext, ".POS")) {
-    CTX.base_filename[strlen(name) - 4] = '\0';
-  }
-
-  strncpy(THEM->name, CTX.base_filename, 255);
-
-#if defined(HAVE_FLTK)
-  if(!CTX.batch)
-    WID->set_title(CTX.filename);
-#endif
+  SetProjectName(name);
 
-  int status = MergeProblem(CTX.filename);
+  int status = MergeProblem(name);
 
   ApplyLcFactor(THEM);
 
-- 
GitLab