diff --git a/Common/CommandLine.cpp b/Common/CommandLine.cpp index d616de0380df27c46f9d5d998e74cfbf2cd004fa..28b2cbe054a47193938daca5b78500375dd9dab7 100644 --- a/Common/CommandLine.cpp +++ b/Common/CommandLine.cpp @@ -300,7 +300,7 @@ void Get_Options(int argc, char *argv[]) // convert mesh to latest binary format if(GModel::current()->getMeshStatus() > 0){ CTX.mesh.msh_file_version = 2.0; - CTX.mesh.msh_binary = 1; + CTX.mesh.binary = 1; CreateOutputFile(filename, FORMAT_MSH); } i++; @@ -475,7 +475,7 @@ void Get_Options(int argc, char *argv[]) } else if(!strcmp(argv[i] + 1, "bin")) { i++; - CTX.mesh.stl_binary = CTX.mesh.msh_binary = 1; + CTX.mesh.binary = 1; } else if(!strcmp(argv[i] + 1, "algo")) { i++; diff --git a/Common/Context.h b/Common/Context.h index 76fe3a90d58e099f899299d869fe75df0cbcd049..0140f048adf42e01bb410d71616f64d8fafd183d 100644 --- a/Common/Context.h +++ b/Common/Context.h @@ -169,7 +169,7 @@ class Context_T { int min_circ_points, min_curv_points; double normals, tangents, explode; int color_carousel; - int save_all, save_groups_of_nodes, stl_binary, msh_binary, bdf_field_format; + int save_all, save_groups_of_nodes, binary, bdf_field_format; int smooth_normals, reverse_all_normals; double angle_smooth_normals; double allow_swap_edge_angle; diff --git a/Common/CreateFile.cpp b/Common/CreateFile.cpp index f65c4fa0e37657b8cd9d689ec9ff98b8938a0df4..262d2e7005580317b9bbbd0f71213a730f14db58 100644 --- a/Common/CreateFile.cpp +++ b/Common/CreateFile.cpp @@ -136,12 +136,12 @@ void CreateOutputFile(const char *filename, int format) break; case FORMAT_MSH: - GModel::current()->writeMSH(name, CTX.mesh.msh_file_version, CTX.mesh.msh_binary, + GModel::current()->writeMSH(name, CTX.mesh.msh_file_version, CTX.mesh.binary, CTX.mesh.save_all, CTX.mesh.scaling_factor); break; case FORMAT_STL: - GModel::current()->writeSTL(name, CTX.mesh.stl_binary, + GModel::current()->writeSTL(name, CTX.mesh.binary, CTX.mesh.save_all, CTX.mesh.scaling_factor); break; @@ -155,7 +155,7 @@ void CreateOutputFile(const char *filename, int format) break; case FORMAT_VTK: - GModel::current()->writeVTK(name, CTX.mesh.msh_binary, CTX.mesh.save_all, + GModel::current()->writeVTK(name, CTX.mesh.binary, CTX.mesh.save_all, CTX.mesh.scaling_factor); break; diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h index b6042e56badd7727d02a1b185b7435cedde3d1a6..3da6f3546b829920ba6ea664b6fefc737129f5c1 100644 --- a/Common/DefaultOptions.h +++ b/Common/DefaultOptions.h @@ -897,6 +897,8 @@ StringXNumber MeshOptions_Number[] = { { F|O, "BdfFieldFormat" , opt_mesh_bdf_field_format , 1. , "Field format for Nastran BDF files (0=free, 1=small, 2=large)" }, + { F|O, "Binary" , opt_mesh_binary , 0. , + "Write mesh files in binary format (if possible)" }, { F|O, "C1Continuity" , opt_mesh_c1 , 0. , "Impose C1 continuity to high order meshes (only valid in 2D plane and ElemenOrder = 2)" }, @@ -994,8 +996,6 @@ StringXNumber MeshOptions_Number[] = { "Minimum number of points used to mesh a circle" }, { F|O, "MinimumCurvePoints" , opt_mesh_min_curv_points, 3. , "Minimum number of points used to mesh a (non-straight) curve" }, - { F|O, "MshBinary" , opt_mesh_msh_binary , 0. , - "Write MSH files in binary format?" }, { F|O, "MshFileVersion" , opt_mesh_msh_file_version , 2.0 , "Version of the MSH file format to use" }, @@ -1080,8 +1080,6 @@ StringXNumber MeshOptions_Number[] = { "Number of smoothing steps of internal edges for high order meshes" }, { F|O, "SmoothNormals" , opt_mesh_smooth_normals , 0. , "Smooth the mesh normals?" }, - { F|O, "StlBinary" , opt_mesh_stl_binary , 0. , - "Save STL files in binary format?" }, { F|O, "SurfaceEdges" , opt_mesh_surfaces_edges , 1. , "Display edges of surface mesh?" }, { F|O, "SurfaceFaces" , opt_mesh_surfaces_faces , 0. , diff --git a/Common/Options.cpp b/Common/Options.cpp index ad89e023aee1587d8418661e3c591c46d336841c..300d2d191a5c2513ebcbe695d255d163d2043bce 100644 --- a/Common/Options.cpp +++ b/Common/Options.cpp @@ -5066,18 +5066,11 @@ double opt_mesh_msh_file_version(OPT_ARGS_NUM) return CTX.mesh.msh_file_version; } -double opt_mesh_msh_binary(OPT_ARGS_NUM) +double opt_mesh_binary(OPT_ARGS_NUM) { if(action & GMSH_SET) - CTX.mesh.msh_binary = (int)val; - return CTX.mesh.msh_binary; -} - -double opt_mesh_stl_binary(OPT_ARGS_NUM) -{ - if(action & GMSH_SET) - CTX.mesh.stl_binary = (int)val; - return CTX.mesh.stl_binary; + CTX.mesh.binary = (int)val; + return CTX.mesh.binary; } double opt_mesh_bdf_field_format(OPT_ARGS_NUM) diff --git a/Common/Options.h b/Common/Options.h index e2b4408be53144862f2d57f357648416a9e69e5b..d14062799947b3b29cf3a5de026d3464e37b0101 100644 --- a/Common/Options.h +++ b/Common/Options.h @@ -469,8 +469,7 @@ double opt_mesh_light_lines(OPT_ARGS_NUM); double opt_mesh_light_two_side(OPT_ARGS_NUM); double opt_mesh_format(OPT_ARGS_NUM); double opt_mesh_msh_file_version(OPT_ARGS_NUM); -double opt_mesh_msh_binary(OPT_ARGS_NUM); -double opt_mesh_stl_binary(OPT_ARGS_NUM); +double opt_mesh_binary(OPT_ARGS_NUM); double opt_mesh_bdf_field_format(OPT_ARGS_NUM); double opt_mesh_nb_smoothing(OPT_ARGS_NUM); double opt_mesh_algo2d(OPT_ARGS_NUM); diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp index 5f454c0c49a352e92aa8ff583eb9a68bbc602fe5..f1ae67e96495ad0ac1d53ca41f2b9c792f86bac7 100644 --- a/Fltk/Callbacks.cpp +++ b/Fltk/Callbacks.cpp @@ -650,13 +650,13 @@ int _save_options(const char *name){ return options_dialog(name); } int _save_geo(const char *name){ return geo_dialog(name); } int _save_cgns(const char *name){ return cgns_write_dialog(name); } int _save_unv(const char *name){ return unv_dialog(name); } -int _save_vtk(const char *name){ return generic_mesh_dialog(name, "VTK Options", FORMAT_VTK); } -int _save_med(const char *name){ return generic_mesh_dialog(name, "MED Options", FORMAT_MED); } -int _save_mesh(const char *name){ return generic_mesh_dialog(name, "MESH Options", FORMAT_MESH); } +int _save_vtk(const char *name){ return generic_mesh_dialog(name, "VTK Options", FORMAT_VTK, true); } +int _save_med(const char *name){ return generic_mesh_dialog(name, "MED Options", FORMAT_MED, false); } +int _save_mesh(const char *name){ return generic_mesh_dialog(name, "MESH Options", FORMAT_MESH, false); } int _save_bdf(const char *name){ return bdf_dialog(name); } -int _save_p3d(const char *name){ return generic_mesh_dialog(name, "P3D Options", FORMAT_P3D); } -int _save_stl(const char *name){ return stl_dialog(name); } -int _save_vrml(const char *name){ return generic_mesh_dialog(name, "VRML Options", FORMAT_VRML); } +int _save_p3d(const char *name){ return generic_mesh_dialog(name, "P3D Options", FORMAT_P3D, false); } +int _save_stl(const char *name){ return generic_mesh_dialog(name, "STL Options", FORMAT_STL, true); } +int _save_vrml(const char *name){ return generic_mesh_dialog(name, "VRML Options", FORMAT_VRML, false); } int _save_eps(const char *name){ return gl2ps_dialog(name, "EPS Options", FORMAT_EPS); } int _save_gif(const char *name){ return gif_dialog(name); } int _save_jpeg(const char *name){ return jpeg_dialog(name); } diff --git a/Fltk/GUI_Extras.cpp b/Fltk/GUI_Extras.cpp index b76ce92bb4cf07c22109aa6635334c2b5d3c90bd..2ad2245e0becd8d3173aa3eeb782850be04dfe88 100644 --- a/Fltk/GUI_Extras.cpp +++ b/Fltk/GUI_Extras.cpp @@ -835,60 +835,6 @@ int pos_dialog(const char *name) return 0; } -// Generic save mesh dialog - -int generic_mesh_dialog(const char *name, const char *title, int format) -{ - struct _generic_mesh_dialog{ - Fl_Window *window; - Fl_Check_Button *b; - Fl_Button *ok, *cancel; - }; - static _generic_mesh_dialog *dialog = NULL; - - const int BH = 2 * GetFontSize() + 1; - const int BB = 7 * GetFontSize() + 9; - const int WB = 7; - - if(!dialog){ - 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); - dialog->window->box(GMSH_WINDOW_BOX); - dialog->b = new Fl_Check_Button(WB, y, 2 * BB + WB, BH, "Save all (ignore physical groups)"); 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(); - dialog->window->end(); - dialog->window->hotspot(dialog->window); - } - - dialog->window->label(title); - dialog->b->value(CTX.mesh.save_all ? 1 : 0); - dialog->window->show(); - - while(dialog->window->shown()){ - Fl::wait(); - for (;;) { - Fl_Widget* o = Fl::readqueue(); - if (!o) break; - if (o == dialog->ok) { - opt_mesh_save_all(0, GMSH_SET | GMSH_GUI, dialog->b->value() ? 1 : 0); - CreateOutputFile(name, format); - dialog->window->hide(); - return 1; - } - if (o == dialog->window || o == dialog->cancel){ - dialog->window->hide(); - return 0; - } - } - } - return 0; -} - // Save msh dialog int msh_dialog(const char *name) @@ -931,7 +877,7 @@ int msh_dialog(const char *name) } dialog->c->value((CTX.mesh.msh_file_version == 1.0) ? 0 : - CTX.mesh.msh_binary ? 2 : 1); + CTX.mesh.binary ? 2 : 1); dialog->b->value(CTX.mesh.save_all ? 1 : 0); dialog->window->show(); @@ -943,8 +889,8 @@ int msh_dialog(const char *name) 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_binary(0, GMSH_SET | GMSH_GUI, + (dialog->c->value() == 2) ? 1 : 0); opt_mesh_save_all(0, GMSH_SET | GMSH_GUI, dialog->b->value() ? 1 : 0); CreateOutputFile(name, FORMAT_MSH); dialog->window->hide(); @@ -1082,17 +1028,18 @@ int bdf_dialog(const char *name) return 0; } -// Save stl dialog +// Generic mesh dialog -int stl_dialog(const char *name) +int generic_mesh_dialog(const char *name, const char *title, int format, + bool binary_support) { - struct _stl_dialog{ + struct _generic_mesh_dialog{ Fl_Window *window; Fl_Choice *c; Fl_Check_Button *b; Fl_Button *ok, *cancel; }; - static _stl_dialog *dialog = NULL; + static _generic_mesh_dialog *dialog = NULL; static Fl_Menu_Item formatmenu[] = { {"ASCII", 0, 0, 0}, @@ -1105,10 +1052,10 @@ int stl_dialog(const char *name) const int WB = 7; if(!dialog){ - dialog = new _stl_dialog; + dialog = new _generic_mesh_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, "STL 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); @@ -1122,7 +1069,12 @@ int stl_dialog(const char *name) dialog->window->hotspot(dialog->window); } - dialog->c->value(CTX.mesh.stl_binary ? 1 : 0); + dialog->window->label(title); + dialog->c->value(CTX.mesh.binary ? 1 : 0); + if(binary_support) + dialog->c->activate(); + else + dialog->c->deactivate(); dialog->b->value(CTX.mesh.save_all ? 1 : 0); dialog->window->show(); @@ -1132,9 +1084,9 @@ int stl_dialog(const char *name) Fl_Widget* o = Fl::readqueue(); if (!o) break; if (o == dialog->ok) { - opt_mesh_stl_binary(0, GMSH_SET | GMSH_GUI, dialog->c->value()); + opt_mesh_binary(0, GMSH_SET | GMSH_GUI, dialog->c->value()); opt_mesh_save_all(0, GMSH_SET | GMSH_GUI, dialog->b->value() ? 1 : 0); - CreateOutputFile(name, FORMAT_STL); + CreateOutputFile(name, format); dialog->window->hide(); return 1; } diff --git a/Fltk/GUI_Extras.h b/Fltk/GUI_Extras.h index a34cb0f0023864dc03c7a43b829c9cd87e20e482..1cec1ab425a425fd54f97a9646ba96f0f819ff4c 100644 --- a/Fltk/GUI_Extras.h +++ b/Fltk/GUI_Extras.h @@ -22,14 +22,14 @@ int jpeg_dialog(const char *filename); int gif_dialog(const char *filename); int geo_dialog(const char *filename); int generic_bitmap_dialog(const char *filename, const char *title, int format); -int generic_mesh_dialog(const char *filename, const char *title, int format); +int generic_mesh_dialog(const char *filename, const char *title, int format, + bool binary_supports); int gl2ps_dialog(const char *filename, const char *title, int format); int options_dialog(const char *filename); int pos_dialog(const char *filename); int msh_dialog(const char *filename); int unv_dialog(const char *filename); int bdf_dialog(const char *filename); -int stl_dialog(const char *filename); int latex_dialog(const char *filename); int cgns_write_dialog(const char *filename); void partition_dialog(); diff --git a/Geo/GModelIO_Mesh.cpp b/Geo/GModelIO_Mesh.cpp index 41fef3126f09ba71ec01d665eee9fc7b23c2e3c5..67c21b817ad057be03ce8b28346391baad7d228a 100644 --- a/Geo/GModelIO_Mesh.cpp +++ b/Geo/GModelIO_Mesh.cpp @@ -1970,14 +1970,15 @@ int GModel::writeVTK(const std::string &name, bool binary, bool saveAll, int numElements = 0, totalNumInt = 0; for(unsigned int i = 0; i < entities.size(); i++){ if(entities[i]->physicals.size() || saveAll){ - numElements += entities[i]->getNumMeshElements(); for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ - if(entities[i]->getMeshElement(j)->getTypeForVTK()) + if(entities[i]->getMeshElement(j)->getTypeForVTK()){ + numElements++; totalNumInt += entities[i]->getMeshElement(j)->getNumVertices() + 1; + } } } } - + // print vertex indices in ascii or binary fprintf(fp, "CELLS %d %d\n", numElements, totalNumInt); for(unsigned int i = 0; i < entities.size(); i++){