diff --git a/Common/CommandLine.cpp b/Common/CommandLine.cpp index d1b26ee21038494ee34afed17c822afc05851848..6f510040955739b8443b07e29deab31210ff29c3 100644 --- a/Common/CommandLine.cpp +++ b/Common/CommandLine.cpp @@ -316,8 +316,7 @@ void Get_Options(int argc, char *argv[]) i++; CTX.batch = 1; while(i < argc) { - char filename[256]; - sprintf(filename, "%s_new", argv[i]); + std::string fileName = std::string(argv[i]) + "_new"; #if !defined(HAVE_NO_POST) unsigned int n = PView::list.size(); #endif @@ -325,13 +324,13 @@ void Get_Options(int argc, char *argv[]) #if !defined(HAVE_NO_POST) // convert post-processing views to latest binary format for(unsigned int j = n; j < PView::list.size(); j++) - PView::list[j]->write(filename, 1, (j == n) ? false : true); + PView::list[j]->write(fileName, 1, (j == n) ? false : true); #endif // convert mesh to latest binary format if(GModel::current()->getMeshStatus() > 0){ CTX.mesh.msh_file_version = 2.0; CTX.mesh.binary = 1; - CreateOutputFile(filename, FORMAT_MSH); + CreateOutputFile(fileName, FORMAT_MSH); } i++; } diff --git a/Common/Context.h b/Common/Context.h index ca55ac1a2e0faed91efde725d70d894238179e70..c9b11a9280659b6f83a21e00319f4ba41f15e810 100644 --- a/Common/Context.h +++ b/Common/Context.h @@ -18,8 +18,8 @@ class Context_T { public : // general options std::vector<std::string> files; // all the files on the command line - const char *bgm_filename; // background mesh - const char *output_filename; // output file specified with command line option '-o' + std::string bgm_filename; // background mesh + std::string output_filename; // output file specified with command line option '-o' const char *default_filename; const char *tmp_filename; const char *session_filename; diff --git a/Common/CreateFile.cpp b/Common/CreateFile.cpp index 42e364a96f21379f24247ef00109c141e6d4ce3d..2a713bf9da92067aa57354fca92aafa301ae1d53 100644 --- a/Common/CreateFile.cpp +++ b/Common/CreateFile.cpp @@ -102,16 +102,13 @@ std::string GetDefaultFileName(int format) return name; } -void CreateOutputFile(const char *filename, int format) +void CreateOutputFile(std::string fileName, int format) { - std::string name; - if(!filename || !strlen(filename)) - name = GetDefaultFileName(format); - else - name = filename; + if(fileName.empty()) + fileName = GetDefaultFileName(format); char no_ext[256], ext[256], base[256]; - SplitFileName(name.c_str(), no_ext, ext, base); + SplitFileName(fileName.c_str(), no_ext, ext, base); int oldformat = CTX.print.format; CTX.print.format = format; @@ -128,81 +125,88 @@ void CreateOutputFile(const char *filename, int format) bool printEndMessage = true; if(format != FORMAT_AUTO) - Msg::StatusBar(2, true, "Writing '%s'", name.c_str()); + Msg::StatusBar(2, true, "Writing '%s'", fileName.c_str()); switch (format) { case FORMAT_AUTO: - CreateOutputFile(name.c_str(), GuessFileFormatFromFileName(name)); + CreateOutputFile(fileName, GuessFileFormatFromFileName(fileName)); printEndMessage = false; break; case FORMAT_OPT: - Print_Options(0, GMSH_FULLRC, 1, 1, name.c_str()); + Print_Options(0, GMSH_FULLRC, 1, 1, fileName.c_str()); break; case FORMAT_MSH: - GModel::current()->writeMSH(name, CTX.mesh.msh_file_version, CTX.mesh.binary, - CTX.mesh.save_all, CTX.mesh.save_parametric, - CTX.mesh.scaling_factor); + GModel::current()->writeMSH + (fileName, CTX.mesh.msh_file_version, CTX.mesh.binary, CTX.mesh.save_all, + CTX.mesh.save_parametric, CTX.mesh.scaling_factor); break; case FORMAT_STL: - GModel::current()->writeSTL(name, CTX.mesh.binary, - CTX.mesh.save_all, CTX.mesh.scaling_factor); + GModel::current()->writeSTL + (fileName, CTX.mesh.binary, CTX.mesh.save_all, CTX.mesh.scaling_factor); break; case FORMAT_VRML: - GModel::current()->writeVRML(name, CTX.mesh.save_all, CTX.mesh.scaling_factor); + GModel::current()->writeVRML + (fileName, CTX.mesh.save_all, CTX.mesh.scaling_factor); break; case FORMAT_UNV: - GModel::current()->writeUNV(name, CTX.mesh.save_all, CTX.mesh.save_groups_of_nodes, - CTX.mesh.scaling_factor); + GModel::current()->writeUNV + (fileName, CTX.mesh.save_all, CTX.mesh.save_groups_of_nodes, + CTX.mesh.scaling_factor); break; case FORMAT_VTK: - GModel::current()->writeVTK(name, CTX.mesh.binary, CTX.mesh.save_all, - CTX.mesh.scaling_factor, CTX.big_endian); + GModel::current()->writeVTK + (fileName, CTX.mesh.binary, CTX.mesh.save_all, CTX.mesh.scaling_factor, + CTX.big_endian); break; case FORMAT_MESH: - GModel::current()->writeMESH(name, CTX.mesh.save_all, CTX.mesh.scaling_factor); + GModel::current()->writeMESH + (fileName, CTX.mesh.save_all, CTX.mesh.scaling_factor); break; case FORMAT_BDF: - GModel::current()->writeBDF(name, CTX.mesh.bdf_field_format, - CTX.mesh.save_all, CTX.mesh.scaling_factor); + GModel::current()->writeBDF + (fileName, CTX.mesh.bdf_field_format, CTX.mesh.save_all, + CTX.mesh.scaling_factor); break; case FORMAT_DIFF: - GModel::current()->writeDIFF(name, CTX.mesh.binary, CTX.mesh.save_all, - CTX.mesh.scaling_factor); + GModel::current()->writeDIFF + (fileName, CTX.mesh.binary, CTX.mesh.save_all, CTX.mesh.scaling_factor); break; case FORMAT_P3D: - GModel::current()->writeP3D(name, CTX.mesh.save_all, CTX.mesh.scaling_factor); + GModel::current()->writeP3D + (fileName, CTX.mesh.save_all, CTX.mesh.scaling_factor); break; case FORMAT_CGNS: - GModel::current()->writeCGNS(name, CTX.mesh.zone_definition, - CTX.mesh.cgns_options, - CTX.mesh.scaling_factor); + GModel::current()->writeCGNS + (fileName, CTX.mesh.zone_definition, CTX.mesh.cgns_options, + CTX.mesh.scaling_factor); break; case FORMAT_MED: - GModel::current()->writeMED(name, CTX.mesh.save_all, CTX.mesh.scaling_factor); + GModel::current()->writeMED + (fileName, CTX.mesh.save_all, CTX.mesh.scaling_factor); break; case FORMAT_POS: - GModel::current()->writePOS(name, CTX.print.pos_elementary, CTX.print.pos_element, - CTX.print.pos_gamma, CTX.print.pos_eta, CTX.print.pos_rho, - CTX.print.pos_disto, CTX.mesh.save_all, - CTX.mesh.scaling_factor); + GModel::current()->writePOS + (fileName, CTX.print.pos_elementary, CTX.print.pos_element, + CTX.print.pos_gamma, CTX.print.pos_eta, CTX.print.pos_rho, + CTX.print.pos_disto, CTX.mesh.save_all, CTX.mesh.scaling_factor); break; case FORMAT_GEO: - GModel::current()->writeGEO(name, CTX.print.geo_labels); + GModel::current()->writeGEO(fileName, CTX.print.geo_labels); break; #if defined(HAVE_FLTK) @@ -213,8 +217,8 @@ void CreateOutputFile(const char *filename, int format) case FORMAT_PNG: { FILE *fp; - if(!(fp = fopen(name.c_str(), "wb"))) { - Msg::Error("Unable to open file '%s'", name.c_str()); + if(!(fp = fopen(fileName.c_str(), "wb"))) { + Msg::Error("Unable to open file '%s'", fileName.c_str()); break; } @@ -258,8 +262,8 @@ void CreateOutputFile(const char *filename, int format) case FORMAT_SVG: { FILE *fp; - if(!(fp = fopen(name.c_str(), "wb"))) { - Msg::Error("Unable to open file '%s'", name.c_str()); + if(!(fp = fopen(fileName.c_str(), "wb"))) { + Msg::Error("Unable to open file '%s'", fileName.c_str()); break; } @@ -337,8 +341,8 @@ void CreateOutputFile(const char *filename, int format) case FORMAT_TEX: { FILE *fp; - if(!(fp = fopen(name.c_str(), "w"))) { - Msg::Error("Unable to open file '%s'", name.c_str()); + if(!(fp = fopen(fileName.c_str(), "w"))) { + Msg::Error("Unable to open file '%s'", fileName.c_str()); break; } GLint buffsize = 0; @@ -366,7 +370,7 @@ void CreateOutputFile(const char *filename, int format) break; } - if(printEndMessage) Msg::StatusBar(2, true, "Wrote '%s'", name.c_str()); + if(printEndMessage) Msg::StatusBar(2, true, "Wrote '%s'", fileName.c_str()); CTX.print.format = oldformat; CTX.printing = 0; diff --git a/Common/CreateFile.h b/Common/CreateFile.h index 0c2e8dd354130e4de87b04eb65aaa490c6c8c760..771fd4839df2d99f98273d978959ad51aefd3498 100644 --- a/Common/CreateFile.h +++ b/Common/CreateFile.h @@ -9,6 +9,6 @@ int GuessFileFormatFromFileName(std::string fileName); std::string GetDefaultFileName(int format); -void CreateOutputFile(const char *name, int format); +void CreateOutputFile(std::string fileName, int format); #endif diff --git a/Common/Gmsh.cpp b/Common/Gmsh.cpp index d65e671ba1fc96891c70c4bf406c37725919b8dc..7f645c1a6170c315fe9cd1d9696e32276d55bd79 100644 --- a/Common/Gmsh.cpp +++ b/Common/Gmsh.cpp @@ -100,7 +100,7 @@ int GmshBatch() } #if !defined(HAVE_NO_POST) - if(CTX.bgm_filename) { + if(!CTX.bgm_filename.empty()) { MergeFile(CTX.bgm_filename); if(PView::list.size()) GModel::current()->getFields()->set_background_mesh(PView::list.size() - 1); diff --git a/Common/Options.cpp b/Common/Options.cpp index 0d34ec2ca098e51fac71b06469161f844fe40f3c..d5b8bf69ed9eab677b50d9202913683f68de78f9 100644 --- a/Common/Options.cpp +++ b/Common/Options.cpp @@ -473,8 +473,8 @@ void Init_Options(int num) // The following defaults cannot be set by the user CTX.batch = CTX.batch_after_mesh = 0; - CTX.output_filename = NULL; - CTX.bgm_filename = NULL; + CTX.output_filename = ""; + CTX.bgm_filename = ""; CTX.lc = 1.; // nice 2-D defaults for when adding points in a brand new model CTX.min[0] = CTX.min[1] = CTX.min[2] = CTX.max[2] = 0.; diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp index dfc5b97010a56fd5a31f0038f3c8cb466674cd85..a9b6b1a1f77dfa9603197de5b4bdd4b3724c07cd 100644 --- a/Fltk/GUI.cpp +++ b/Fltk/GUI.cpp @@ -71,8 +71,7 @@ GUI::GUI(int argc, char **argv) // load default system icons (for file browser) Fl_File_Icon::load_system_icons(); - // add callback to respond to the Mac Finder (when you click on a - // document) + // add callback to respond to Mac Finder #if defined(__APPLE__) fl_open_callback(OpenProjectMacFinder); #endif @@ -122,9 +121,11 @@ GUI::GUI(int argc, char **argv) // create additional graphic windows for(int i = 1; i < CTX.num_windows; i++){ - graph.push_back(new graphicWindow(false, CTX.num_tiles)); - graph.back()->win->size(400, 400); - graph.back()->win->show(); + graphicWindow *g = new graphicWindow(false, CTX.num_tiles); + g->win->resize(graph.back()->win->x() + 10, graph.back()->win->y() + 10, + graph.back()->win->w(), graph.back()->win->h()); + g->win->show(); + graph.push_back(g); } options = new optionWindow(CTX.deltafontsize); @@ -144,7 +145,7 @@ GUI::GUI(int argc, char **argv) // init solver plugin stuff callForSolverPlugin(-1); - // draw the scene + // draw for(unsigned int i = 0; i < graph.size(); i++) for(unsigned int j = 0; j < graph[i]->gl.size(); j++) graph[i]->gl[j]->redraw(); diff --git a/Fltk/Main.cpp b/Fltk/Main.cpp index 74f649ea7db241300049f20a04bf6d5dd6a0a46a..d13ac2c3932315c023596385ceb67751d3350c45 100644 --- a/Fltk/Main.cpp +++ b/Fltk/Main.cpp @@ -107,7 +107,7 @@ int main(int argc, char *argv[]) } // Read background mesh on disk - if(CTX.bgm_filename) { + if(!CTX.bgm_filename.empty()) { MergeFile(CTX.bgm_filename); if(PView::list.size()) GModel::current()->getFields()->set_background_mesh(PView::list.size() - 1); diff --git a/Fltk/menuWindow.cpp b/Fltk/menuWindow.cpp index 404f1d2c091b18c216f48758a0f89c8aea59ed4c..342b39f2ae4f9a804741a2663855c7a2c9d38ad3 100644 --- a/Fltk/menuWindow.cpp +++ b/Fltk/menuWindow.cpp @@ -1438,18 +1438,15 @@ static void geometry_physical_add_cb(Fl_Widget *w, void *data) static void mesh_save_cb(Fl_Widget *w, void *data) { - std::string name; - if(CTX.output_filename) - name = CTX.output_filename; - else - name = GetDefaultFileName(CTX.mesh.format); + std::string name = CTX.output_filename; + if(name.empty()) name = GetDefaultFileName(CTX.mesh.format); if(CTX.confirm_overwrite) { if(!StatFile(name.c_str())) if(!fl_choice("File '%s' already exists.\n\nDo you want to replace it?", "Cancel", "Replace", NULL, name.c_str())) return; } - CreateOutputFile(name.c_str(), CTX.mesh.format); + CreateOutputFile(name, CTX.mesh.format); } static void mesh_define_cb(Fl_Widget *w, void *data)