Hi, everyone. Exporting data to a file, whether it is a mesh definition or image, is one of the main use cases of a mesh generator. I also noticed that the question of how to export data is posted often in Gmsh's mailing list. Right now, Gmsh provides this functionality through the "Save As..." menu, and although this works well I've found that sometimes it would be preferable if this feature could be used in a tad more straight-forward way.
To make this use case a bit more straight-forward, I tweaked Gmsh's file menu to add an "Export" menu, which includes options to export the mesh, postprocessing info, image, or a movie. This menu offers users a clear way to do what they want to do, and the ability to unequivocally discover where they need to go in the GUI to export specific bits of information. I've attached the patch that implements this feature. The patch was created with regards the current stable version (v2.11.0) as was made available through Gmsh's site. The patch adds the "Export" menu, the respective submenu entries, and a callback for each export option. The export callbacks were based on the file_save_as_cb() callback function. The "Save as" menu was left untouched due to potential implications regarding backward compatibility. If this patch is of any interest, feel free to use it. Best regards, Rui Maciel
From f112acfb0922492aa1955fd86c58853260211bc9 Mon Sep 17 00:00:00 2001 From: Rui Maciel <[email protected]> Date: Fri, 4 Mar 2016 10:23:47 +0000 Subject: [PATCH] Added export menu and menu items --- Fltk/graphicWindow.cpp | 195 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) diff --git a/Fltk/graphicWindow.cpp b/Fltk/graphicWindow.cpp index c2f0c8a..5f59d39 100644 --- a/Fltk/graphicWindow.cpp +++ b/Fltk/graphicWindow.cpp @@ -468,6 +468,193 @@ static void file_save_as_cb(Fl_Widget *w, void *data) } } +static void file_export_mesh_cb(Fl_Widget *w, void *data) +{ + static patXfunc formats[] = { + {"Guess From Extension" TT "*.*", _save_auto}, + {"Gmsh MSH" TT "*.msh", _save_msh}, + {"Abaqus INP" TT "*.inp", _save_inp}, + {"CELUM" TT "*.celum", _save_celum}, +#if defined(HAVE_LIBCGNS) + {"CGNS (Experimental)" TT "*.cgns", _save_cgns}, +#endif + {"Diffpack 3D" TT "*.diff", _save_diff}, + {"I-deas Universal" TT "*.unv", _save_unv}, + {"Iridum" TT "*.ir3", _save_ir3}, +#if defined(HAVE_MED) + {"MED" TT "*.med", _save_med}, +#endif + {"INRIA Medit" TT "*.mesh", _save_mesh}, + {"CEA Triangulation" TT "*.mail", _save_mail}, + {"Nastran Bulk Data File" TT "*.bdf", _save_bdf}, + {"Plot3D Structured Mesh" TT "*.p3d", _save_p3d}, + {"STL Surface" TT "*.stl", _save_stl}, + {"VRML Surface" TT "*.wrl", _save_vrml}, + {"VTK" TT "*.vtk", _save_vtk}, + {"PLY2 Surface" TT "*.ply2", _save_ply2}, + {"SU2" TT "*.su2", _save_su2}, + }; + int nbformats = sizeof(formats) / sizeof(formats[0]); + static char *pat = 0; + if(!pat) { + pat = new char[nbformats * 256]; + strcpy(pat, formats[0].pat); + for(int i = 1; i < nbformats; i++) { + strcat(pat, NN); + strcat(pat, formats[i].pat); + } + } + + test: + if(fileChooser(FILE_CHOOSER_CREATE, "Save As", pat)) { + std::string name = fileChooserGetName(1); + if(CTX::instance()->confirmOverwrite) { + if(!StatFile(name)) + if(!fl_choice("File '%s' already exists.\n\nDo you want to replace it?", + "Cancel", "Replace", 0, name.c_str())) + goto test; + } + int i = fileChooserGetFilter(); + if(i >= 0 && i < nbformats){ + if(!formats[i].func(name.c_str())) goto test; + } + else{ // handle any additional automatic fltk filter + if(!_save_auto(name.c_str())) goto test; + } + } +} + +static void file_export_postprocessing_cb(Fl_Widget *w, void *data) +{ + static patXfunc formats[] = { + {"Guess From Extension" TT "*.*", _save_auto}, + {"Post-processing - Gmsh POS" TT "*.pos", _save_view_pos}, + {"Post-processing - X3D (X3D)" TT "*.x3d", _save_view_x3d}, +#if defined(HAVE_MED) + {"Post-processing - MED" TT "*.rmed", _save_view_med}, +#endif + {"Post-processing - Generic TXT" TT "*.txt", _save_view_txt}, + {"Post-processing - Mesh Statistics" TT "*.pos", _save_mesh_stat}, + {"Post-processing - Adapted data" TT "*.pvtu", _save_view_adapt_pvtu}, + }; + int nbformats = sizeof(formats) / sizeof(formats[0]); + static char *pat = 0; + if(!pat) { + pat = new char[nbformats * 256]; + strcpy(pat, formats[0].pat); + for(int i = 1; i < nbformats; i++) { + strcat(pat, NN); + strcat(pat, formats[i].pat); + } + } + + test: + if(fileChooser(FILE_CHOOSER_CREATE, "Save As", pat)) { + std::string name = fileChooserGetName(1); + if(CTX::instance()->confirmOverwrite) { + if(!StatFile(name)) + if(!fl_choice("File '%s' already exists.\n\nDo you want to replace it?", + "Cancel", "Replace", 0, name.c_str())) + goto test; + } + int i = fileChooserGetFilter(); + if(i >= 0 && i < nbformats){ + if(!formats[i].func(name.c_str())) goto test; + } + else{ // handle any additional automatic fltk filter + if(!_save_auto(name.c_str())) goto test; + } + } +} + +static void file_export_image_cb(Fl_Widget *w, void *data) +{ + static patXfunc formats[] = { + {"Guess From Extension" TT "*.*", _save_auto}, + {"Encapsulated PostScript" TT "*.eps", _save_eps}, + {"GIF" TT "*.gif", _save_gif}, +#if defined(HAVE_LIBJPEG) + {"JPEG" TT "*.jpg", _save_jpeg}, +#endif + {"LaTeX" TT "*.tex", _save_tex}, + {"PDF" TT "*.pdf", _save_pdf}, +#if defined(HAVE_LIBPNG) + {"PNG" TT "*.png", _save_png}, + {"PGF" TT "*.pgf", _save_pgf}, +#endif + {"PostScript" TT "*.ps", _save_ps}, + {"PPM" TT "*.ppm", _save_ppm}, + {"SVG" TT "*.svg", _save_svg}, + {"YUV" TT "*.yuv", _save_yuv}, + }; + int nbformats = sizeof(formats) / sizeof(formats[0]); + static char *pat = 0; + if(!pat) { + pat = new char[nbformats * 256]; + strcpy(pat, formats[0].pat); + for(int i = 1; i < nbformats; i++) { + strcat(pat, NN); + strcat(pat, formats[i].pat); + } + } + + test: + if(fileChooser(FILE_CHOOSER_CREATE, "Save As", pat)) { + std::string name = fileChooserGetName(1); + if(CTX::instance()->confirmOverwrite) { + if(!StatFile(name)) + if(!fl_choice("File '%s' already exists.\n\nDo you want to replace it?", + "Cancel", "Replace", 0, name.c_str())) + goto test; + } + int i = fileChooserGetFilter(); + if(i >= 0 && i < nbformats){ + if(!formats[i].func(name.c_str())) goto test; + } + else{ // handle any additional automatic fltk filter + if(!_save_auto(name.c_str())) goto test; + } + } +} + +static void file_export_movie_cb(Fl_Widget *w, void *data) +{ + static patXfunc formats[] = { + {"Guess From Extension" TT "*.*", _save_auto}, +#if defined(HAVE_MPEG_ENCODE) + {"Movie - MPEG" TT "*.mpg", _save_mpeg}, +#endif + }; + int nbformats = sizeof(formats) / sizeof(formats[0]); + static char *pat = 0; + if(!pat) { + pat = new char[nbformats * 256]; + strcpy(pat, formats[0].pat); + for(int i = 1; i < nbformats; i++) { + strcat(pat, NN); + strcat(pat, formats[i].pat); + } + } + + test: + if(fileChooser(FILE_CHOOSER_CREATE, "Save As", pat)) { + std::string name = fileChooserGetName(1); + if(CTX::instance()->confirmOverwrite) { + if(!StatFile(name)) + if(!fl_choice("File '%s' already exists.\n\nDo you want to replace it?", + "Cancel", "Replace", 0, name.c_str())) + goto test; + } + int i = fileChooserGetFilter(); + if(i >= 0 && i < nbformats){ + if(!formats[i].func(name.c_str())) goto test; + } + else{ // handle any additional automatic fltk filter + if(!_save_auto(name.c_str())) goto test; + } + } +} + #undef TT #undef NN @@ -1988,6 +2175,14 @@ static Fl_Menu_Item bar_table[] = { {0}, {"&Rename...", FL_CTRL+'r', (Fl_Callback *)file_rename_cb, 0}, {"Save &As...", FL_CTRL+'s', (Fl_Callback *)file_save_as_cb, 0}, + {"Export", 0, 0, 0, FL_MENU_DIVIDER | FL_SUBMENU}, + {"Mesh", 0, (Fl_Callback *)file_export_mesh_cb, 0}, + {"Postprocessing", 0, (Fl_Callback *)file_export_postprocessing_cb, 0}, + {"Image", 0, (Fl_Callback *)file_export_image_cb, 0}, +#if defined(HAVE_MPEG_ENCODE) + {"Movie", 0, (Fl_Callback *)file_export_movie_cb, 0}, +#endif + {0}, {"Sa&ve Mesh", FL_CTRL+FL_SHIFT+'s', (Fl_Callback *)mesh_save_cb, 0}, {"Save Model Options", FL_CTRL+'j', (Fl_Callback *)file_options_save_cb, (void*)"file"}, {"Save Options As Default", FL_CTRL+FL_SHIFT+'j', (Fl_Callback *)file_options_save_cb, (void*)"default", FL_MENU_DIVIDER}, -- 1.7.10.4
_______________________________________________ gmsh mailing list [email protected] http://onelab.info/mailman/listinfo/gmsh
