diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp index fd9002a207b6fe333a24331d8c46055b84d9d14f..c868fa05010b45a31ea73dcdba2442de7d82dd8c 100644 --- a/Fltk/Callbacks.cpp +++ b/Fltk/Callbacks.cpp @@ -1,4 +1,4 @@ -// $Id: Callbacks.cpp,v 1.498 2006-12-16 15:58:19 geuzaine Exp $ +// $Id: Callbacks.cpp,v 1.499 2006-12-18 19:47:37 geuzaine Exp $ // // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle // @@ -618,130 +618,50 @@ void file_merge_cb(CALLBACK_ARGS) WID->set_context(menu_post, 0); } -int _save_options(char *name) -{ - return options_dialog(name); -} - -int _save_geo(char *name) -{ - CreateOutputFile(name, FORMAT_GEO); - return 1; -} - -int _save_msh(char *name) -{ - return msh_dialog(name); -} - -int _save_pos(char *name) -{ - CreateOutputFile(name, FORMAT_POS); - return 1; -} - -int _save_unv(char *name) -{ - return unv_dialog(name); -} - -int _save_mesh(char *name) -{ - CreateOutputFile(name, FORMAT_MESH); - return 1; -} - -int _save_bdf(char *name) -{ - return bdf_dialog(name); -} - -int _save_vrml(char *name) -{ - CreateOutputFile(name, FORMAT_VRML); - return 1; -} - -int _save_stl(char *name) -{ - return stl_dialog(name); -} - -int _save_cgns(char *name) -{ - CreateOutputFile(name, FORMAT_CGNS); - return 1; -} - -int _save_ps(char *name) -{ - return gl2ps_dialog(name, "PS Options", FORMAT_PS); -} - -int _save_eps(char *name) -{ - return gl2ps_dialog(name, "EPS Options", FORMAT_EPS); -} - -int _save_pdf(char *name) -{ - return gl2ps_dialog(name, "PDF Options", FORMAT_PDF); -} - -int _save_svg(char *name) -{ - return gl2ps_dialog(name, "SVG Options", FORMAT_SVG); -} - -int _save_tex(char *name) -{ - CreateOutputFile(name, FORMAT_TEX); - return 1; -} - -int _save_jpeg(char *name) -{ - return jpeg_dialog(name); -} - -int _save_png(char *name) -{ - return generic_bitmap_dialog(name, "PNG Options", FORMAT_PNG); -} - -int _save_gif(char *name) -{ - return gif_dialog(name); -} - -int _save_ppm(char *name) -{ - return generic_bitmap_dialog(name, "PPM Options", FORMAT_PPM); -} - -int _save_yuv(char *name) -{ - return generic_bitmap_dialog(name, "YUV Options", FORMAT_YUV); -} +int _save_msh(char *name){ return msh_dialog(name); } +int _save_pos(char *name){ return generic_mesh_dialog(name, "POS Options", FORMAT_POS); } +int _save_options(char *name){ return options_dialog(name); } +int _save_geo(char *name){ CreateOutputFile(name, FORMAT_GEO); return 1; } +int _save_unv(char *name){ return generic_mesh_dialog(name, "UNV Options", FORMAT_UNV); } +int _save_mesh(char *name){ return generic_mesh_dialog(name, "MESH Options", FORMAT_MESH); } +int _save_bdf(char *name){ return bdf_dialog(name); } +int _save_stl(char *name){ return stl_dialog(name); } +int _save_vrml(char *name){ return generic_mesh_dialog(name, "VRML Options", FORMAT_VRML); } +int _save_cgns(char *name){ CreateOutputFile(name, FORMAT_CGNS); return 1; } +int _save_eps(char *name){ return gl2ps_dialog(name, "EPS Options", FORMAT_EPS); } +int _save_gif(char *name){ return gif_dialog(name); } +int _save_jpeg(char *name){ return jpeg_dialog(name); } +int _save_tex(char *name){ CreateOutputFile(name, FORMAT_TEX); return 1; } +int _save_pdf(char *name){ return gl2ps_dialog(name, "PDF Options", FORMAT_PDF); } +int _save_png(char *name){ return generic_bitmap_dialog(name, "PNG Options", FORMAT_PNG); } +int _save_ps(char *name){ return gl2ps_dialog(name, "PS Options", FORMAT_PS); } +int _save_ppm(char *name){ return generic_bitmap_dialog(name, "PPM Options", FORMAT_PPM); } +int _save_svg(char *name){ return gl2ps_dialog(name, "SVG Options", FORMAT_SVG); } +int _save_yuv(char *name){ return generic_bitmap_dialog(name, "YUV Options", FORMAT_YUV); } int _save_auto(char *name) { switch(GuessFileFormatFromFileName(name)){ - case FORMAT_OPT : return _save_options(name); - case FORMAT_MSH : return _save_msh(name); - case FORMAT_UNV : return _save_unv(name); - case FORMAT_BDF : return _save_bdf(name); - case FORMAT_STL : return _save_stl(name); - case FORMAT_CGNS : return _save_cgns(name); - case FORMAT_PS : return _save_ps(name); - case FORMAT_EPS : return _save_eps(name); - case FORMAT_PDF : return _save_pdf(name); - case FORMAT_SVG : return _save_svg(name); - case FORMAT_JPEG : return _save_jpeg(name); - case FORMAT_PNG : return _save_png(name); - case FORMAT_GIF : return _save_gif(name); - case FORMAT_PPM : return _save_ppm(name); - case FORMAT_YUV : return _save_yuv(name); + case FORMAT_MSH : return _save_msh(name); + case FORMAT_POS : return _save_pos(name); + case FORMAT_OPT : return _save_options(name); + case FORMAT_GEO : return _save_geo(name); + case FORMAT_UNV : return _save_unv(name); + case FORMAT_MESH : return _save_mesh(name); + case FORMAT_BDF : return _save_bdf(name); + case FORMAT_STL : return _save_stl(name); + case FORMAT_VRML : return _save_vrml(name); + case FORMAT_CGNS : return _save_cgns(name); + case FORMAT_EPS : return _save_eps(name); + case FORMAT_GIF : return _save_gif(name); + case FORMAT_JPEG : return _save_jpeg(name); + case FORMAT_TEX : return _save_tex(name); + case FORMAT_PDF : return _save_pdf(name); + case FORMAT_PNG : return _save_png(name); + case FORMAT_PS : return _save_ps(name); + case FORMAT_PPM : return _save_ppm(name); + case FORMAT_SVG : return _save_svg(name); + case FORMAT_YUV : return _save_yuv(name); default : CreateOutputFile(name, FORMAT_AUTO); return 1; diff --git a/Fltk/GUI_Extras.cpp b/Fltk/GUI_Extras.cpp index 04ba05ece340fc8a59bbc4cd1218e3431f92a63a..023253124c1c56b8e00a33b0644f183600abd513 100644 --- a/Fltk/GUI_Extras.cpp +++ b/Fltk/GUI_Extras.cpp @@ -1,4 +1,4 @@ -// $Id: GUI_Extras.cpp,v 1.29 2006-12-16 05:43:20 geuzaine Exp $ +// $Id: GUI_Extras.cpp,v 1.30 2006-12-18 19:47:37 geuzaine Exp $ // // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle // @@ -218,40 +218,27 @@ int perspective_editor() return 0; } -// save jpeg dialog +// Generic save bitmap dialog -int jpeg_dialog(char *name) +int generic_bitmap_dialog(char *name, char *title, int format) { - struct _jpeg_dialog{ + struct _generic_bitmap_dialog{ Fl_Window *window; - Fl_Value_Slider *s[2]; Fl_Check_Button *b; Fl_Button *ok, *cancel; }; - static _jpeg_dialog *dialog = NULL; + static _generic_bitmap_dialog *dialog = NULL; const int BH = 2 * CTX.fontsize + 1; const int BB = 7 * CTX.fontsize; const int WB = 7; if(!dialog){ - dialog = new _jpeg_dialog; - int h = 3 * WB + 4 * BH, w = 2 * BB + 3 * WB, y = WB; + dialog = new _generic_bitmap_dialog; + int h = 3 * WB + 2 * BH, w = 2 * BB + 3 * WB, y = WB; // not a "Dialog_Window" since it is modal - dialog->window = new Fl_Double_Window(w, h, "JPEG Options"); + dialog->window = new Fl_Double_Window(w, h); dialog->window->box(GMSH_WINDOW_BOX); - dialog->s[0] = new Fl_Value_Slider(WB, y, BB, BH, "Quality"); y += BH; - dialog->s[0]->type(FL_HOR_SLIDER); - dialog->s[0]->align(FL_ALIGN_RIGHT); - dialog->s[0]->minimum(1); - dialog->s[0]->maximum(100); - dialog->s[0]->step(1); - dialog->s[1] = new Fl_Value_Slider(WB, y, BB, BH, "Smoothing"); y += BH; - dialog->s[1]->type(FL_HOR_SLIDER); - dialog->s[1]->align(FL_ALIGN_RIGHT); - dialog->s[1]->minimum(0); - dialog->s[1]->maximum(100); - dialog->s[1]->step(1); dialog->b = new Fl_Check_Button(WB, y, 2 * BB + WB, BH, "Print text strings"); y += BH; dialog->b->type(FL_TOGGLE_BUTTON); dialog->ok = new Fl_Return_Button(WB, y + WB, BB, BH, "OK"); @@ -261,8 +248,7 @@ int jpeg_dialog(char *name) dialog->window->hotspot(dialog->window); } - dialog->s[0]->value(CTX.print.jpeg_quality); - dialog->s[1]->value(CTX.print.jpeg_smoothing); + dialog->window->label(title); dialog->b->value(CTX.print.text); dialog->window->show(); @@ -272,10 +258,8 @@ int jpeg_dialog(char *name) Fl_Widget* o = Fl::readqueue(); if (!o) break; if (o == dialog->ok) { - opt_print_jpeg_quality(0, GMSH_SET | GMSH_GUI, (int)dialog->s[0]->value()); - opt_print_jpeg_smoothing(0, GMSH_SET | GMSH_GUI, (int)dialog->s[1]->value()); opt_print_text(0, GMSH_SET | GMSH_GUI, (int)dialog->b->value()); - CreateOutputFile(name, FORMAT_JPEG); + CreateOutputFile(name, format); dialog->window->hide(); return 1; } @@ -288,27 +272,40 @@ int jpeg_dialog(char *name) return 0; } -// save generic bitmap dialog +// Save jpeg dialog -int generic_bitmap_dialog(char *name, char *title, int format) +int jpeg_dialog(char *name) { - struct _generic_bitmap_dialog{ + struct _jpeg_dialog{ Fl_Window *window; + Fl_Value_Slider *s[2]; Fl_Check_Button *b; Fl_Button *ok, *cancel; }; - static _generic_bitmap_dialog *dialog = NULL; + static _jpeg_dialog *dialog = NULL; const int BH = 2 * CTX.fontsize + 1; const int BB = 7 * CTX.fontsize; const int WB = 7; if(!dialog){ - dialog = new _generic_bitmap_dialog; - int h = 3 * WB + 2 * BH, w = 2 * BB + 3 * WB, y = WB; + dialog = new _jpeg_dialog; + int h = 3 * WB + 4 * BH, w = 2 * BB + 3 * WB, y = WB; // not a "Dialog_Window" since it is modal - dialog->window = new Fl_Double_Window(w, h); + dialog->window = new Fl_Double_Window(w, h, "JPEG Options"); dialog->window->box(GMSH_WINDOW_BOX); + dialog->s[0] = new Fl_Value_Slider(WB, y, BB, BH, "Quality"); y += BH; + dialog->s[0]->type(FL_HOR_SLIDER); + dialog->s[0]->align(FL_ALIGN_RIGHT); + dialog->s[0]->minimum(1); + dialog->s[0]->maximum(100); + dialog->s[0]->step(1); + dialog->s[1] = new Fl_Value_Slider(WB, y, BB, BH, "Smoothing"); y += BH; + dialog->s[1]->type(FL_HOR_SLIDER); + dialog->s[1]->align(FL_ALIGN_RIGHT); + dialog->s[1]->minimum(0); + dialog->s[1]->maximum(100); + dialog->s[1]->step(1); dialog->b = new Fl_Check_Button(WB, y, 2 * BB + WB, BH, "Print text strings"); y += BH; dialog->b->type(FL_TOGGLE_BUTTON); dialog->ok = new Fl_Return_Button(WB, y + WB, BB, BH, "OK"); @@ -318,7 +315,8 @@ int generic_bitmap_dialog(char *name, char *title, int format) dialog->window->hotspot(dialog->window); } - dialog->window->label(title); + dialog->s[0]->value(CTX.print.jpeg_quality); + dialog->s[1]->value(CTX.print.jpeg_smoothing); dialog->b->value(CTX.print.text); dialog->window->show(); @@ -328,8 +326,10 @@ int generic_bitmap_dialog(char *name, char *title, int format) Fl_Widget* o = Fl::readqueue(); if (!o) break; if (o == dialog->ok) { + opt_print_jpeg_quality(0, GMSH_SET | GMSH_GUI, (int)dialog->s[0]->value()); + opt_print_jpeg_smoothing(0, GMSH_SET | GMSH_GUI, (int)dialog->s[1]->value()); opt_print_text(0, GMSH_SET | GMSH_GUI, (int)dialog->b->value()); - CreateOutputFile(name, format); + CreateOutputFile(name, FORMAT_JPEG); dialog->window->hide(); return 1; } @@ -342,7 +342,7 @@ int generic_bitmap_dialog(char *name, char *title, int format) return 0; } -// save gif dialog +// Save gif dialog int gif_dialog(char *name) { @@ -409,7 +409,7 @@ int gif_dialog(char *name) return 0; } -// save ps/eps/pdf dialog +// Save ps/eps/pdf dialog static void activate_gl2ps_choices(int format, int quality, Fl_Check_Button *b[5]) { @@ -537,7 +537,7 @@ int gl2ps_dialog(char *name, char *title, int format) return 0; } -// save options dialog +// Save options dialog int options_dialog(char *name) { @@ -592,38 +592,27 @@ int options_dialog(char *name) return 0; } -// save msh dialog +// Generic save mesh dialog -int msh_dialog(char *name) +int generic_mesh_dialog(char *name, char *title, int format) { - struct _msh_dialog{ + struct _generic_mesh_dialog{ Fl_Window *window; Fl_Check_Button *b; - Fl_Choice *c; Fl_Button *ok, *cancel; }; - static _msh_dialog *dialog = NULL; - - static Fl_Menu_Item formatmenu[] = { - {"Version 1.0", 0, 0, 0}, - {"Version 2.0 ASCII", 0, 0, 0}, - {"Version 2.0 Binary", 0, 0, 0}, - {0} - }; + static _generic_mesh_dialog *dialog = NULL; const int BH = 2 * CTX.fontsize + 1; const int BB = 7 * CTX.fontsize; const int WB = 7; if(!dialog){ - dialog = new _msh_dialog; - int h = 3 * WB + 3 * BH, w = 2 * BB + 3 * WB, y = WB; + dialog = new _generic_mesh_dialog; + int h = 3 * WB + 2 * BH, w = 2 * BB + 3 * WB, y = WB; // not a "Dialog_Window" since it is modal - dialog->window = new Fl_Double_Window(w, h, "MSH Options"); + dialog->window = new Fl_Double_Window(w, h); dialog->window->box(GMSH_WINDOW_BOX); - dialog->c = new Fl_Choice(WB, y, BB + BB / 2, BH, "Format"); y += BH; - dialog->c->menu(formatmenu); - dialog->c->align(FL_ALIGN_RIGHT); dialog->b = new Fl_Check_Button(WB, y, 2 * BB + WB, BH, "Save all (ignore physicals)"); y += BH; dialog->b->type(FL_TOGGLE_BUTTON); dialog->ok = new Fl_Return_Button(WB, y + WB, BB, BH, "OK"); @@ -633,8 +622,7 @@ int msh_dialog(char *name) dialog->window->hotspot(dialog->window); } - dialog->c->value((CTX.mesh.msh_file_version == 1.0) ? 0 : - CTX.mesh.msh_binary ? 2 : 1); + dialog->window->label(title); dialog->b->value(CTX.mesh.save_all); dialog->window->show(); @@ -644,12 +632,8 @@ int msh_dialog(char *name) Fl_Widget* o = Fl::readqueue(); if (!o) break; if (o == dialog->ok) { - opt_mesh_msh_file_version(0, GMSH_SET | GMSH_GUI, - (dialog->c->value() == 0) ? 1. : 2.); - opt_mesh_msh_binary(0, GMSH_SET | GMSH_GUI, - (dialog->c->value() == 2) ? 1 : 0); opt_mesh_save_all(0, GMSH_SET | GMSH_GUI, dialog->b->value()); - CreateOutputFile(name, FORMAT_MSH); + CreateOutputFile(name, format); dialog->window->hide(); return 1; } @@ -662,27 +646,38 @@ int msh_dialog(char *name) return 0; } -// save unv dialog +// Save msh dialog -int unv_dialog(char *name) +int msh_dialog(char *name) { - struct _unv_dialog{ + struct _msh_dialog{ Fl_Window *window; Fl_Check_Button *b; + Fl_Choice *c; Fl_Button *ok, *cancel; }; - static _unv_dialog *dialog = NULL; + static _msh_dialog *dialog = NULL; + + static Fl_Menu_Item formatmenu[] = { + {"Version 1.0", 0, 0, 0}, + {"Version 2.0 ASCII", 0, 0, 0}, + {"Version 2.0 Binary", 0, 0, 0}, + {0} + }; const int BH = 2 * CTX.fontsize + 1; const int BB = 7 * CTX.fontsize; const int WB = 7; if(!dialog){ - dialog = new _unv_dialog; - int h = 3 * WB + 2 * BH, w = 2 * BB + 3 * WB, y = WB; + dialog = new _msh_dialog; + int h = 3 * WB + 3 * BH, w = 2 * BB + 3 * WB, y = WB; // not a "Dialog_Window" since it is modal - dialog->window = new Fl_Double_Window(w, h, "UNV Options"); + dialog->window = new Fl_Double_Window(w, h, "MSH Options"); dialog->window->box(GMSH_WINDOW_BOX); + dialog->c = new Fl_Choice(WB, y, BB + BB / 2, BH, "Format"); y += BH; + dialog->c->menu(formatmenu); + dialog->c->align(FL_ALIGN_RIGHT); dialog->b = new Fl_Check_Button(WB, y, 2 * BB + WB, BH, "Save all (ignore physicals)"); y += BH; dialog->b->type(FL_TOGGLE_BUTTON); dialog->ok = new Fl_Return_Button(WB, y + WB, BB, BH, "OK"); @@ -692,6 +687,8 @@ int unv_dialog(char *name) dialog->window->hotspot(dialog->window); } + dialog->c->value((CTX.mesh.msh_file_version == 1.0) ? 0 : + CTX.mesh.msh_binary ? 2 : 1); dialog->b->value(CTX.mesh.save_all); dialog->window->show(); @@ -701,8 +698,12 @@ int unv_dialog(char *name) Fl_Widget* o = Fl::readqueue(); if (!o) break; if (o == dialog->ok) { + opt_mesh_msh_file_version(0, GMSH_SET | GMSH_GUI, + (dialog->c->value() == 0) ? 1. : 2.); + opt_mesh_msh_binary(0, GMSH_SET | GMSH_GUI, + (dialog->c->value() == 2) ? 1 : 0); opt_mesh_save_all(0, GMSH_SET | GMSH_GUI, dialog->b->value()); - CreateOutputFile(name, FORMAT_UNV); + CreateOutputFile(name, FORMAT_MSH); dialog->window->hide(); return 1; } @@ -715,13 +716,14 @@ int unv_dialog(char *name) return 0; } -// save bdf dialog +// Save bdf dialog int bdf_dialog(char *name) { struct _bdf_dialog{ Fl_Window *window; Fl_Choice *c; + Fl_Check_Button *b; Fl_Button *ok, *cancel; }; static _bdf_dialog *dialog = NULL; @@ -739,13 +741,15 @@ int bdf_dialog(char *name) if(!dialog){ dialog = new _bdf_dialog; - int h = 3 * WB + 2 * BH, w = 2 * BB + 3 * WB, y = WB; + int h = 3 * WB + 3 * BH, w = 2 * BB + 3 * WB, y = WB; // not a "Dialog_Window" since it is modal dialog->window = new Fl_Double_Window(w, h, "BDF Options"); dialog->window->box(GMSH_WINDOW_BOX); dialog->c = new Fl_Choice(WB, y, BB + BB / 2, BH, "Format"); y += BH; dialog->c->menu(formatmenu); dialog->c->align(FL_ALIGN_RIGHT); + dialog->b = new Fl_Check_Button(WB, y, 2 * BB + WB, BH, "Save all (ignore physicals)"); y += BH; + dialog->b->type(FL_TOGGLE_BUTTON); dialog->ok = new Fl_Return_Button(WB, y + WB, BB, BH, "OK"); dialog->cancel = new Fl_Button(2 * WB + BB, y + WB, BB, BH, "Cancel"); dialog->window->set_modal(); @@ -754,6 +758,7 @@ int bdf_dialog(char *name) } dialog->c->value(CTX.mesh.bdf_field_format); + dialog->b->value(CTX.mesh.save_all); dialog->window->show(); while(dialog->window->shown()){ @@ -763,6 +768,7 @@ int bdf_dialog(char *name) if (!o) break; if (o == dialog->ok) { opt_mesh_bdf_field_format(0, GMSH_SET | GMSH_GUI, dialog->c->value()); + opt_mesh_save_all(0, GMSH_SET | GMSH_GUI, dialog->b->value()); CreateOutputFile(name, FORMAT_BDF); dialog->window->hide(); return 1; @@ -776,13 +782,14 @@ int bdf_dialog(char *name) return 0; } -// save stl dialog +// Save stl dialog int stl_dialog(char *name) { struct _stl_dialog{ Fl_Window *window; Fl_Choice *c; + Fl_Check_Button *b; Fl_Button *ok, *cancel; }; static _stl_dialog *dialog = NULL; @@ -799,13 +806,15 @@ int stl_dialog(char *name) if(!dialog){ dialog = new _stl_dialog; - int h = 3 * WB + 2 * BH, w = 2 * BB + 3 * WB, y = WB; + int h = 3 * WB + 3 * BH, w = 2 * BB + 3 * WB, y = WB; // not a "Dialog_Window" since it is modal dialog->window = new Fl_Double_Window(w, h, "STL Options"); dialog->window->box(GMSH_WINDOW_BOX); dialog->c = new Fl_Choice(WB, y, BB + BB / 2, BH, "Format"); y += BH; dialog->c->menu(formatmenu); dialog->c->align(FL_ALIGN_RIGHT); + dialog->b = new Fl_Check_Button(WB, y, 2 * BB + WB, BH, "Save all (ignore physicals)"); y += BH; + dialog->b->type(FL_TOGGLE_BUTTON); dialog->ok = new Fl_Return_Button(WB, y + WB, BB, BH, "OK"); dialog->cancel = new Fl_Button(2 * WB + BB, y + WB, BB, BH, "Cancel"); dialog->window->set_modal(); @@ -814,6 +823,7 @@ int stl_dialog(char *name) } dialog->c->value(CTX.mesh.stl_binary ? 1 : 0); + dialog->b->value(CTX.mesh.save_all); dialog->window->show(); while(dialog->window->shown()){ @@ -823,6 +833,7 @@ int stl_dialog(char *name) if (!o) break; if (o == dialog->ok) { opt_mesh_stl_binary(0, GMSH_SET | GMSH_GUI, dialog->c->value()); + opt_mesh_save_all(0, GMSH_SET | GMSH_GUI, dialog->b->value()); CreateOutputFile(name, FORMAT_STL); dialog->window->hide(); return 1; diff --git a/Fltk/GUI_Extras.h b/Fltk/GUI_Extras.h index 976eab81ad270db658ce4b7c2e9f24d6029a4d26..c5b70db991ebe4e087221c4df8e03d415583a958 100644 --- a/Fltk/GUI_Extras.h +++ b/Fltk/GUI_Extras.h @@ -32,10 +32,10 @@ int perspective_editor(); int jpeg_dialog(char *filename); int gif_dialog(char *filename); int generic_bitmap_dialog(char *filename, char *title, int format); +int generic_mesh_dialog(char *filename, char *title, int format); int gl2ps_dialog(char *filename, char *title, int format); int options_dialog(char *filename); int msh_dialog(char *filename); -int unv_dialog(char *filename); int bdf_dialog(char *filename); int stl_dialog(char *filename); diff --git a/Geo/GModel.h b/Geo/GModel.h index 3a9faa67e0ddbd16c255e4a5dcaf581c17cc36fa..6368d14030362ee508f4dd6d775f3e9ab88b3119 100644 --- a/Geo/GModel.h +++ b/Geo/GModel.h @@ -180,28 +180,33 @@ class GModel bool saveAll=false, double scalingFactor=1.0); // Mesh statistics (as Gmsh post-processing views) - int writePOS(const std::string &name, double scalingFactor=1.0); + int writePOS(const std::string &name, + bool saveAll=false, double scalingFactor=1.0); // Stereo lithography format int readSTL(const std::string &name, double tolerance=1.e-3); - int writeSTL(const std::string &name, bool binary=false, double scalingFactor=1.0); + int writeSTL(const std::string &name, bool binary=false, + bool saveAll=false, double scalingFactor=1.0); // Inventor/VRML format int readVRML(const std::string &name); - int writeVRML(const std::string &name, double scalingFactor=1.0); + int writeVRML(const std::string &name, + bool saveAll=false, double scalingFactor=1.0); // I-deas universal mesh format int readUNV(const std::string &name); - int writeUNV(const std::string &name, bool saveAll=false, double scalingFactor=1.0); + int writeUNV(const std::string &name, + bool saveAll=false, double scalingFactor=1.0); // Medit (INRIA) mesh format int readMESH(const std::string &name); - int writeMESH(const std::string &name, double scalingFactor=1.0); + int writeMESH(const std::string &name, + bool saveAll=false, double scalingFactor=1.0); // Nastran Bulk Data File format int readBDF(const std::string &name); - int writeBDF(const std::string &name, int format=0, bool saveAll=false, - double scalingFactor=1.0); + int writeBDF(const std::string &name, int format=0, + bool saveAll=false, double scalingFactor=1.0); // CFD General Notation System files int readCGNS(const std::string &name); diff --git a/Geo/GModelIO_Mesh.cpp b/Geo/GModelIO_Mesh.cpp index b4de3bc8c279d84e4493ae408903ebbdf2b3df17..80a7c85243b210caaf33f2bcced1f5a0298acf5b 100644 --- a/Geo/GModelIO_Mesh.cpp +++ b/Geo/GModelIO_Mesh.cpp @@ -1,4 +1,4 @@ -// $Id: GModelIO_Mesh.cpp,v 1.5 2006-12-03 04:00:58 geuzaine Exp $ +// $Id: GModelIO_Mesh.cpp,v 1.6 2006-12-18 19:47:38 geuzaine Exp $ // // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle // @@ -709,7 +709,7 @@ int GModel::writeMSH(const std::string &name, double version, bool binary, return 1; } -int GModel::writePOS(const std::string &name, double scalingFactor) +int GModel::writePOS(const std::string &name, bool saveAll, double scalingFactor) { FILE *fp = fopen(name.c_str(), "w"); if(!fp){ @@ -719,19 +719,23 @@ int GModel::writePOS(const std::string &name, double scalingFactor) int status = getMeshStatus(); + if(noPhysicalGroups()) saveAll = true; + if(status >= 3){ fprintf(fp, "View \"Volumes\" {\n"); fprintf(fp, "T2(1.e5,30,%d){\"Elementary Entity\", \"Element Number\", " "\"Gamma\", \"Eta\", \"Rho\"};\n", (1<<16)|(4<<8)); for(riter it = firstRegion(); it != lastRegion(); ++it) { - for(unsigned int i = 0; i < (*it)->tetrahedra.size(); i++) - (*it)->tetrahedra[i]->writePOS(fp, scalingFactor, (*it)->tag()); - for(unsigned int i = 0; i < (*it)->hexahedra.size(); i++) - (*it)->hexahedra[i]->writePOS(fp, scalingFactor, (*it)->tag()); - for(unsigned int i = 0; i < (*it)->prisms.size(); i++) - (*it)->prisms[i]->writePOS(fp, scalingFactor, (*it)->tag()); - for(unsigned int i = 0; i < (*it)->pyramids.size(); i++) - (*it)->pyramids[i]->writePOS(fp, scalingFactor, (*it)->tag()); + if(saveAll || (*it)->physicals.size()){ + for(unsigned int i = 0; i < (*it)->tetrahedra.size(); i++) + (*it)->tetrahedra[i]->writePOS(fp, scalingFactor, (*it)->tag()); + for(unsigned int i = 0; i < (*it)->hexahedra.size(); i++) + (*it)->hexahedra[i]->writePOS(fp, scalingFactor, (*it)->tag()); + for(unsigned int i = 0; i < (*it)->prisms.size(); i++) + (*it)->prisms[i]->writePOS(fp, scalingFactor, (*it)->tag()); + for(unsigned int i = 0; i < (*it)->pyramids.size(); i++) + (*it)->pyramids[i]->writePOS(fp, scalingFactor, (*it)->tag()); + } } fprintf(fp, "};\n"); } @@ -741,10 +745,12 @@ int GModel::writePOS(const std::string &name, double scalingFactor) fprintf(fp, "T2(1.e5,30,%d){\"Elementary Entity\", \"Element Number\", " "\"Gamma\", \"Eta\", \"Rho\"};\n", (1<<16)|(4<<8)); for(fiter it = firstFace(); it != lastFace(); ++it) { - for(unsigned int i = 0; i < (*it)->triangles.size(); i++) - (*it)->triangles[i]->writePOS(fp, scalingFactor, (*it)->tag()); - for(unsigned int i = 0; i < (*it)->quadrangles.size(); i++) - (*it)->quadrangles[i]->writePOS(fp, scalingFactor, (*it)->tag()); + if(saveAll || (*it)->physicals.size()){ + for(unsigned int i = 0; i < (*it)->triangles.size(); i++) + (*it)->triangles[i]->writePOS(fp, scalingFactor, (*it)->tag()); + for(unsigned int i = 0; i < (*it)->quadrangles.size(); i++) + (*it)->quadrangles[i]->writePOS(fp, scalingFactor, (*it)->tag()); + } } fprintf(fp, "};\n"); } @@ -754,8 +760,10 @@ int GModel::writePOS(const std::string &name, double scalingFactor) fprintf(fp, "T2(1.e5,30,%d){\"Elementary Entity\", \"Element Number\", " "\"Gamma\", \"Eta\", \"Rho\"};\n", (1<<16)|(4<<8)); for(eiter it = firstEdge(); it != lastEdge(); ++it) { - for(unsigned int i = 0; i < (*it)->lines.size(); i++) - (*it)->lines[i]->writePOS(fp, scalingFactor, (*it)->tag()); + if(saveAll || (*it)->physicals.size()){ + for(unsigned int i = 0; i < (*it)->lines.size(); i++) + (*it)->lines[i]->writePOS(fp, scalingFactor, (*it)->tag()); + } } fprintf(fp, "};\n"); } @@ -880,7 +888,8 @@ int GModel::readSTL(const std::string &name, double tolerance) return 1; } -int GModel::writeSTL(const std::string &name, bool binary, double scalingFactor) +int GModel::writeSTL(const std::string &name, bool binary, bool saveAll, + double scalingFactor) { FILE *fp = fopen(name.c_str(), binary ? "wb" : "w"); if(!fp){ @@ -888,23 +897,31 @@ int GModel::writeSTL(const std::string &name, bool binary, double scalingFactor) return 0; } - if(!binary) + if(noPhysicalGroups()) saveAll = true; + + if(!binary){ fprintf(fp, "solid Created by Gmsh\n"); + } else{ char header[80]; strncpy(header, "Created by Gmsh", 80); fwrite(header, sizeof(char), 80, fp); unsigned int nfacets = 0; - for(fiter it = firstFace(); it != lastFace(); ++it) - nfacets += (*it)->triangles.size() + 2 * (*it)->quadrangles.size(); + for(fiter it = firstFace(); it != lastFace(); ++it){ + if(saveAll || (*it)->physicals.size()){ + nfacets += (*it)->triangles.size() + 2 * (*it)->quadrangles.size(); + } + } fwrite(&nfacets, sizeof(unsigned int), 1, fp); } for(fiter it = firstFace(); it != lastFace(); ++it) { - for(unsigned int i = 0; i < (*it)->triangles.size(); i++) - (*it)->triangles[i]->writeSTL(fp, binary, scalingFactor); - for(unsigned int i = 0; i < (*it)->quadrangles.size(); i++) - (*it)->quadrangles[i]->writeSTL(fp, binary, scalingFactor); + if(saveAll || (*it)->physicals.size()){ + for(unsigned int i = 0; i < (*it)->triangles.size(); i++) + (*it)->triangles[i]->writeSTL(fp, binary, scalingFactor); + for(unsigned int i = 0; i < (*it)->quadrangles.size(); i++) + (*it)->quadrangles[i]->writeSTL(fp, binary, scalingFactor); + } } if(!binary) @@ -1067,7 +1084,7 @@ int GModel::readVRML(const std::string &name) return 1; } -int GModel::writeVRML(const std::string &name, double scalingFactor) +int GModel::writeVRML(const std::string &name, bool saveAll, double scalingFactor) { FILE *fp = fopen(name.c_str(), "w"); if(!fp){ @@ -1075,6 +1092,8 @@ int GModel::writeVRML(const std::string &name, double scalingFactor) return 0; } + if(noPhysicalGroups()) saveAll = true; + renumberMeshVertices(); fprintf(fp, "#VRML V1.0 ascii\n"); @@ -1096,25 +1115,29 @@ int GModel::writeVRML(const std::string &name, double scalingFactor) fprintf(fp, "}\n"); for(eiter it = firstEdge(); it != lastEdge(); ++it){ - fprintf(fp, "DEF Curve%d IndexedLineSet {\n", (*it)->tag()); - fprintf(fp, " coordIndex [\n"); - for(unsigned int i = 0; i < (*it)->lines.size(); i++) - (*it)->lines[i]->writeVRML(fp); - fprintf(fp, " ]\n"); - fprintf(fp, "}\n"); + if(saveAll || (*it)->physicals.size()){ + fprintf(fp, "DEF Curve%d IndexedLineSet {\n", (*it)->tag()); + fprintf(fp, " coordIndex [\n"); + for(unsigned int i = 0; i < (*it)->lines.size(); i++) + (*it)->lines[i]->writeVRML(fp); + fprintf(fp, " ]\n"); + fprintf(fp, "}\n"); + } } for(fiter it = firstFace(); it != lastFace(); ++it){ - fprintf(fp, "DEF Surface%d IndexedFaceSet {\n", (*it)->tag()); - fprintf(fp, " coordIndex [\n"); - for(unsigned int i = 0; i < (*it)->triangles.size(); i++) - (*it)->triangles[i]->writeVRML(fp); - for(unsigned int i = 0; i < (*it)->quadrangles.size(); i++) - (*it)->quadrangles[i]->writeVRML(fp); - fprintf(fp, " ]\n"); - fprintf(fp, "}\n"); + if(saveAll || (*it)->physicals.size()){ + fprintf(fp, "DEF Surface%d IndexedFaceSet {\n", (*it)->tag()); + fprintf(fp, " coordIndex [\n"); + for(unsigned int i = 0; i < (*it)->triangles.size(); i++) + (*it)->triangles[i]->writeVRML(fp); + for(unsigned int i = 0; i < (*it)->quadrangles.size(); i++) + (*it)->quadrangles[i]->writeVRML(fp); + fprintf(fp, " ]\n"); + fprintf(fp, "}\n"); + } } - + fclose(fp); return 1; } @@ -1282,7 +1305,6 @@ int GModel::writeUNV(const std::string &name, bool saveAll, double scalingFactor return 0; } - // if there are no physicals we save all the elements if(noPhysicalGroups()) saveAll = true; renumberMeshVertices(); @@ -1427,7 +1449,7 @@ int GModel::readMESH(const std::string &name) return 1; } -int GModel::writeMESH(const std::string &name, double scalingFactor) +int GModel::writeMESH(const std::string &name, bool saveAll, double scalingFactor) { FILE *fp = fopen(name.c_str(), "w"); if(!fp){ @@ -1435,6 +1457,8 @@ int GModel::writeMESH(const std::string &name, double scalingFactor) return 0; } + if(noPhysicalGroups()) saveAll = true; + fprintf(fp, " MeshVersionFormatted 1\n"); fprintf(fp, " Dimension\n"); fprintf(fp, " 3\n"); @@ -1457,32 +1481,46 @@ int GModel::writeMESH(const std::string &name, double scalingFactor) int numTriangles = 0, numQuadrangles = 0, numTetrahedra = 0; for(fiter it = firstFace(); it != lastFace(); ++it){ - numTriangles += (*it)->triangles.size(); - numQuadrangles += (*it)->quadrangles.size(); + if(saveAll || (*it)->physicals.size()){ + numTriangles += (*it)->triangles.size(); + numQuadrangles += (*it)->quadrangles.size(); + } } for(riter it = firstRegion(); it != lastRegion(); ++it){ - numTetrahedra += (*it)->tetrahedra.size(); + if(saveAll || (*it)->physicals.size()){ + numTetrahedra += (*it)->tetrahedra.size(); + } } + if(numTriangles){ fprintf(fp, " Triangles\n"); fprintf(fp, " %d\n", numTriangles); - for(fiter it = firstFace(); it != lastFace(); ++it) - for(unsigned int i = 0; i < (*it)->triangles.size(); i++) - (*it)->triangles[i]->writeMESH(fp, (*it)->tag()); + for(fiter it = firstFace(); it != lastFace(); ++it){ + if(saveAll || (*it)->physicals.size()){ + for(unsigned int i = 0; i < (*it)->triangles.size(); i++) + (*it)->triangles[i]->writeMESH(fp, (*it)->tag()); + } + } } if(numQuadrangles){ fprintf(fp, " Quadrilaterals\n"); fprintf(fp, " %d\n", numQuadrangles); - for(fiter it = firstFace(); it != lastFace(); ++it) - for(unsigned int i = 0; i < (*it)->triangles.size(); i++) - (*it)->quadrangles[i]->writeMESH(fp, (*it)->tag()); + for(fiter it = firstFace(); it != lastFace(); ++it){ + if(saveAll || (*it)->physicals.size()){ + for(unsigned int i = 0; i < (*it)->triangles.size(); i++) + (*it)->quadrangles[i]->writeMESH(fp, (*it)->tag()); + } + } } if(numTetrahedra){ fprintf(fp, " Tetrahedra\n"); fprintf(fp, " %d\n", numTetrahedra); - for(riter it = firstRegion(); it != lastRegion(); ++it) - for(unsigned int i = 0; i < (*it)->tetrahedra.size(); i++) - (*it)->tetrahedra[i]->writeMESH(fp, (*it)->tag()); + for(riter it = firstRegion(); it != lastRegion(); ++it){ + if(saveAll || (*it)->physicals.size()){ + for(unsigned int i = 0; i < (*it)->tetrahedra.size(); i++) + (*it)->tetrahedra[i]->writeMESH(fp, (*it)->tag()); + } + } } fprintf(fp, " End\n"); @@ -1757,6 +1795,8 @@ int GModel::writeBDF(const std::string &name, int format, bool saveAll, return 0; } + if(noPhysicalGroups()) saveAll = true; + renumberMeshVertices(); fprintf(fp, "$ Created by Gmsh\n"); @@ -1775,24 +1815,30 @@ int GModel::writeBDF(const std::string &name, int format, bool saveAll, (*it)->mesh_vertices[i]->writeBDF(fp, format, scalingFactor); for(eiter it = firstEdge(); it != lastEdge(); ++it){ - for(unsigned int i = 0; i < (*it)->lines.size(); i++) - (*it)->lines[i]->writeBDF(fp, format, (*it)->tag()); + if(saveAll || (*it)->physicals.size()){ + for(unsigned int i = 0; i < (*it)->lines.size(); i++) + (*it)->lines[i]->writeBDF(fp, format, (*it)->tag()); + } } for(fiter it = firstFace(); it != lastFace(); ++it){ - for(unsigned int i = 0; i < (*it)->triangles.size(); i++) - (*it)->triangles[i]->writeBDF(fp, format, (*it)->tag()); - for(unsigned int i = 0; i < (*it)->quadrangles.size(); i++) - (*it)->quadrangles[i]->writeBDF(fp, format, (*it)->tag()); + if(saveAll || (*it)->physicals.size()){ + for(unsigned int i = 0; i < (*it)->triangles.size(); i++) + (*it)->triangles[i]->writeBDF(fp, format, (*it)->tag()); + for(unsigned int i = 0; i < (*it)->quadrangles.size(); i++) + (*it)->quadrangles[i]->writeBDF(fp, format, (*it)->tag()); + } } for(riter it = firstRegion(); it != lastRegion(); ++it){ - for(unsigned int i = 0; i < (*it)->tetrahedra.size(); i++) - (*it)->tetrahedra[i]->writeBDF(fp, format, (*it)->tag()); - for(unsigned int i = 0; i < (*it)->hexahedra.size(); i++) - (*it)->hexahedra[i]->writeBDF(fp, format, (*it)->tag()); - for(unsigned int i = 0; i < (*it)->prisms.size(); i++) - (*it)->prisms[i]->writeBDF(fp, format, (*it)->tag()); - for(unsigned int i = 0; i < (*it)->pyramids.size(); i++) - (*it)->pyramids[i]->writeBDF(fp, format, (*it)->tag()); + if(saveAll || (*it)->physicals.size()){ + for(unsigned int i = 0; i < (*it)->tetrahedra.size(); i++) + (*it)->tetrahedra[i]->writeBDF(fp, format, (*it)->tag()); + for(unsigned int i = 0; i < (*it)->hexahedra.size(); i++) + (*it)->hexahedra[i]->writeBDF(fp, format, (*it)->tag()); + for(unsigned int i = 0; i < (*it)->prisms.size(); i++) + (*it)->prisms[i]->writeBDF(fp, format, (*it)->tag()); + for(unsigned int i = 0; i < (*it)->pyramids.size(); i++) + (*it)->pyramids[i]->writeBDF(fp, format, (*it)->tag()); + } } fprintf(fp, "ENDDATA\n"); diff --git a/Parser/CreateFile.cpp b/Parser/CreateFile.cpp index b52a0c4f4fd1ecf6d21f26e23a5e351e30a91f62..4859c3888decea44e0bef6c352a724ad57a23df7 100644 --- a/Parser/CreateFile.cpp +++ b/Parser/CreateFile.cpp @@ -1,4 +1,4 @@ -// $Id: CreateFile.cpp,v 1.11 2006-11-27 22:22:17 geuzaine Exp $ +// $Id: CreateFile.cpp,v 1.12 2006-12-18 19:47:38 geuzaine Exp $ // // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle // @@ -53,30 +53,30 @@ int GuessFileFormatFromFileName(char *name) if(len <= 0) strcpy(ext, ""); - if (!strcmp(ext, ".geo")) return FORMAT_GEO; - else if(!strcmp(ext, ".msh")) return FORMAT_MSH; - else if(!strcmp(ext, ".pos")) return FORMAT_POS; - else if(!strcmp(ext, ".opt")) return FORMAT_OPT; - else if(!strcmp(ext, ".unv")) return FORMAT_UNV; - else if(!strcmp(ext, ".stl")) return FORMAT_STL; - else if(!strcmp(ext, ".cgns")) return FORMAT_CGNS; - else if(!strcmp(ext, ".mesh")) return FORMAT_MESH; - else if(!strcmp(ext, ".bdf")) return FORMAT_BDF; - else if(!strcmp(ext, ".nas")) return FORMAT_BDF; - else if(!strcmp(ext, ".wrl")) return FORMAT_VRML; - else if(!strcmp(ext, ".vrml")) return FORMAT_VRML; - else if(!strcmp(ext, ".gif")) return FORMAT_GIF; - else if(!strcmp(ext, ".jpg")) return FORMAT_JPEG; - else if(!strcmp(ext, ".jpeg")) return FORMAT_JPEG; - else if(!strcmp(ext, ".png")) return FORMAT_PNG; - else if(!strcmp(ext, ".ps")) return FORMAT_PS; - else if(!strcmp(ext, ".eps")) return FORMAT_EPS; - else if(!strcmp(ext, ".pdf")) return FORMAT_PDF; - else if(!strcmp(ext, ".tex")) return FORMAT_TEX; - else if(!strcmp(ext, ".svg")) return FORMAT_SVG; - else if(!strcmp(ext, ".ppm")) return FORMAT_PPM; - else if(!strcmp(ext, ".yuv")) return FORMAT_YUV; - else return -1; + if (!strcmp(ext, ".geo")) return FORMAT_GEO; + else if(!strcmp(ext, ".msh")) return FORMAT_MSH; + else if(!strcmp(ext, ".pos")) return FORMAT_POS; + else if(!strcmp(ext, ".opt")) return FORMAT_OPT; + else if(!strcmp(ext, ".unv")) return FORMAT_UNV; + else if(!strcmp(ext, ".stl")) return FORMAT_STL; + else if(!strcmp(ext, ".cgns")) return FORMAT_CGNS; + else if(!strcmp(ext, ".mesh")) return FORMAT_MESH; + else if(!strcmp(ext, ".bdf")) return FORMAT_BDF; + else if(!strcmp(ext, ".nas")) return FORMAT_BDF; + else if(!strcmp(ext, ".wrl")) return FORMAT_VRML; + else if(!strcmp(ext, ".vrml")) return FORMAT_VRML; + else if(!strcmp(ext, ".gif")) return FORMAT_GIF; + else if(!strcmp(ext, ".jpg")) return FORMAT_JPEG; + else if(!strcmp(ext, ".jpeg")) return FORMAT_JPEG; + else if(!strcmp(ext, ".png")) return FORMAT_PNG; + else if(!strcmp(ext, ".ps")) return FORMAT_PS; + else if(!strcmp(ext, ".eps")) return FORMAT_EPS; + else if(!strcmp(ext, ".pdf")) return FORMAT_PDF; + else if(!strcmp(ext, ".tex")) return FORMAT_TEX; + else if(!strcmp(ext, ".svg")) return FORMAT_SVG; + else if(!strcmp(ext, ".ppm")) return FORMAT_PPM; + else if(!strcmp(ext, ".yuv")) return FORMAT_YUV; + else return -1; } void GetDefaultFileName(int format, char *name) @@ -149,11 +149,12 @@ void CreateOutputFile(char *filename, int format) break; case FORMAT_STL: - GMODEL->writeSTL(name, CTX.mesh.stl_binary, CTX.mesh.scaling_factor); + GMODEL->writeSTL(name, CTX.mesh.stl_binary, + CTX.mesh.save_all, CTX.mesh.scaling_factor); break; case FORMAT_VRML: - GMODEL->writeVRML(name, CTX.mesh.scaling_factor); + GMODEL->writeVRML(name, CTX.mesh.save_all, CTX.mesh.scaling_factor); break; case FORMAT_UNV: @@ -161,12 +162,13 @@ void CreateOutputFile(char *filename, int format) break; case FORMAT_MESH: - GMODEL->writeMESH(name, CTX.mesh.scaling_factor); + GMODEL->writeMESH(name, + CTX.mesh.save_all, CTX.mesh.scaling_factor); break; case FORMAT_BDF: - GMODEL->writeBDF(name, CTX.mesh.bdf_field_format, CTX.mesh.save_all, - CTX.mesh.scaling_factor); + GMODEL->writeBDF(name, CTX.mesh.bdf_field_format, + CTX.mesh.save_all, CTX.mesh.scaling_factor); break; case FORMAT_CGNS: @@ -174,7 +176,7 @@ void CreateOutputFile(char *filename, int format) break; case FORMAT_POS: - GMODEL->writePOS(name); + GMODEL->writePOS(name, CTX.mesh.save_all, CTX.mesh.scaling_factor); break; case FORMAT_GEO: