From cdf7975c59634dea7ae31bf023996d8518c5762e Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Tue, 30 Mar 2010 16:38:46 +0000 Subject: [PATCH] easy way to hide/show mesh + set clscale directly from the main gui window --- Fltk/FlGui.cpp | 11 +------ Fltk/extraDialogs.cpp | 66 ++++++++++++++++++++++++++++++--------- Fltk/extraDialogs.h | 1 + Fltk/graphicWindow.cpp | 64 ++++++++++++++++++++++++++++++++++--- Fltk/graphicWindow.h | 2 +- benchmarks/stl/artery.geo | 2 +- benchmarks/stl/pelvis.geo | 6 ++-- 7 files changed, 117 insertions(+), 35 deletions(-) diff --git a/Fltk/FlGui.cpp b/Fltk/FlGui.cpp index a361218f8b..7fc4630808 100644 --- a/Fltk/FlGui.cpp +++ b/Fltk/FlGui.cpp @@ -582,16 +582,7 @@ int FlGui::testGlobalShortcuts(int event) status = 2; } else if(Fl::test_shortcut(FL_ALT + 'm')) { - int old = opt_mesh_points(0, GMSH_GET, 0) || - opt_mesh_lines(0, GMSH_GET, 0) || - opt_mesh_surfaces_edges(0, GMSH_GET, 0) || - opt_mesh_surfaces_faces(0, GMSH_GET, 0); - opt_mesh_points(0, GMSH_SET | GMSH_GUI, !old); - opt_mesh_lines(0, GMSH_SET | GMSH_GUI, !old); - opt_mesh_surfaces_edges(0, GMSH_SET | GMSH_GUI, !old); - opt_mesh_surfaces_faces(0, GMSH_SET | GMSH_GUI, !old); - opt_mesh_volumes_edges(0, GMSH_SET | GMSH_GUI, !old); - opt_mesh_volumes_faces(0, GMSH_SET | GMSH_GUI, !old); + status_options_cb(0, (void *)"M"); status = 2; } else if(Fl::test_shortcut(FL_ALT + 't')) { diff --git a/Fltk/extraDialogs.cpp b/Fltk/extraDialogs.cpp index a505d62a51..8f7298c2a5 100644 --- a/Fltk/extraDialogs.cpp +++ b/Fltk/extraDialogs.cpp @@ -90,13 +90,7 @@ int arrowEditor(const char *title, double &a, double &b, double &c) // Perspective editor (aka z-clipping planes factor slider) -static void persp_change_factor(Fl_Widget* w, void* data) -{ - opt_general_clip_factor(0, GMSH_SET|GMSH_GUI, ((Fl_Slider*)w)->value()); - drawContext::global()->draw(); -} - -class Release_Slider : public Fl_Slider { +class Release_Slider : public Fl_Value_Slider { int handle(int event) { switch (event) { @@ -105,14 +99,20 @@ class Release_Slider : public Fl_Slider { window()->hide(); return 1; default: - return Fl_Slider::handle(event); + return Fl_Value_Slider::handle(event); } }; public: Release_Slider(int x, int y, int w, int h, const char *l=0) - : Fl_Slider(x, y, w, h, l) {} + : Fl_Value_Slider(x, y, w, h, l) {} }; +static void persp_change_factor(Fl_Widget* w, void* data) +{ + opt_general_clip_factor(0, GMSH_SET|GMSH_GUI, ((Fl_Value_Slider*)w)->value()); + drawContext::global()->draw(); +} + int perspectiveEditor() { struct _editor{ @@ -123,12 +123,12 @@ int perspectiveEditor() if(!editor){ editor = new _editor; - editor->window = new Fl_Menu_Window(20, 100); + editor->window = new Fl_Menu_Window(150, 20); if(CTX::instance()->nonModalWindows) editor->window->set_non_modal(); - editor->sa = new Release_Slider(0, 0, 20, 100); - editor->sa->type(FL_VERT_NICE_SLIDER); - editor->sa->minimum(12); - editor->sa->maximum(0.75); + editor->sa = new Release_Slider(0, 0, 150, 20); + editor->sa->type(FL_HOR_NICE_SLIDER); + editor->sa->minimum(0.75); + editor->sa->maximum(12); editor->sa->callback(persp_change_factor); editor->window->border(0); editor->window->end(); @@ -143,6 +143,44 @@ int perspectiveEditor() return 0; } +// Perspective editor (aka z-clipping planes factor slider) + +static void mesh_size_factor(Fl_Widget* w, void* data) +{ + opt_mesh_lc_factor(0, GMSH_SET|GMSH_GUI, ((Fl_Value_Slider*)w)->value()); + drawContext::global()->draw(); +} + +int meshSizeEditor() +{ + struct _editor{ + Fl_Menu_Window *window; + Release_Slider *sa; + }; + static _editor *editor = 0; + + if(!editor){ + editor = new _editor; + editor->window = new Fl_Menu_Window(150, 20); + if(CTX::instance()->nonModalWindows) editor->window->set_non_modal(); + editor->sa = new Release_Slider(0, 0, 150, 20); + editor->sa->type(FL_HOR_NICE_SLIDER); + editor->sa->minimum(0.1); + editor->sa->maximum(2); + editor->sa->callback(mesh_size_factor); + editor->window->border(0); + editor->window->end(); + } + + editor->window->hotspot(editor->window); + editor->sa->value(CTX::instance()->mesh.lcFactor); + + if(editor->window->non_modal() && !editor->window->shown()) + editor->window->show(); // fix ordering + editor->window->show(); + return 0; +} + // Model chooser static void model_switch_cb(Fl_Widget* w, void *data) diff --git a/Fltk/extraDialogs.h b/Fltk/extraDialogs.h index 5f36976a67..bbfafbddb0 100644 --- a/Fltk/extraDialogs.h +++ b/Fltk/extraDialogs.h @@ -10,6 +10,7 @@ int arrowEditor(const char *title, double &a, double &b, double &c); int perspectiveEditor(); +int meshSizeEditor(); int modelChooser(); std::string connectionChooser(); std::string patternChooser(); diff --git a/Fltk/graphicWindow.cpp b/Fltk/graphicWindow.cpp index 6dea613748..300cb1a03e 100644 --- a/Fltk/graphicWindow.cpp +++ b/Fltk/graphicWindow.cpp @@ -79,10 +79,18 @@ static void gmsh_rotate(Fl_Color c) static void gmsh_models(Fl_Color c) { fl_color(c); - bl; vv(-0.8,-0.8); vv(-0.3,-0.8); vv(-0.3,-0.3); vv(-0.8,-0.3); el; - bl; vv(0.3,-0.8); vv(0.8,-0.8); vv(0.8,-0.3); vv(0.3,-0.3); el; - bl; vv(-0.8,0.3); vv(-0.3,0.3); vv(-0.3,0.8); vv(-0.8,0.8); el; - bl; vv(0.3,0.3); vv(0.8,0.3); vv(0.8,0.8); vv(0.3,0.8); el; + bl; vv(-0.8,-0.8); vv(0.8,-0.8); el; + bl; vv(-0.8,-0.4); vv(0.8,-0.4); el; + bl; vv(-0.8,-0.); vv(0.8,-0.); el; + bl; vv(-0.8,0.4); vv(0.8,0.4); el; + bl; vv(-0.8,0.8); vv(0.8,0.8); el; +} + +static void gmsh_clscale(Fl_Color c) +{ + fl_color(c); + bl; vv(-0.8,0.8); vv(-0.2,0.8); vv(-0.8,0.2); el; + bl; vv(-0.3,0.4); vv(0.8,0.4); vv(-0.3,-0.8); el; } #undef vv @@ -205,6 +213,43 @@ void status_options_cb(Fl_Widget *w, void *data) } drawContext::global()->draw(); } + else if(!strcmp(str, "M")){ // toggle mesh display + static int value = 1; + static int old_p = (int)opt_mesh_points(0, GMSH_GET, 0.); + static int old_l = (int)opt_mesh_lines(0, GMSH_GET, 0.); + static int old_se = (int)opt_mesh_surfaces_edges(0, GMSH_GET, 0.); + static int old_sf = (int)opt_mesh_surfaces_faces(0, GMSH_GET, 0.); + static int old_ve = (int)opt_mesh_volumes_edges(0, GMSH_GET, 0.); + static int old_vf = (int)opt_mesh_volumes_faces(0, GMSH_GET, 0.); + if(!value){ // retore visibility + value = 1; + opt_mesh_points(0, GMSH_SET | GMSH_GUI, old_p); + opt_mesh_lines(0, GMSH_SET | GMSH_GUI, old_l); + opt_mesh_surfaces_edges(0, GMSH_SET | GMSH_GUI, old_se); + opt_mesh_surfaces_faces(0, GMSH_SET | GMSH_GUI, old_sf); + opt_mesh_volumes_edges(0, GMSH_SET | GMSH_GUI, old_ve); + opt_mesh_volumes_faces(0, GMSH_SET | GMSH_GUI, old_vf); + } + else{ + value = 0; + old_p = (int)opt_mesh_points(0, GMSH_GET, 0.); + old_l = (int)opt_mesh_lines(0, GMSH_GET, 0.); + old_se = (int)opt_mesh_surfaces_edges(0, GMSH_GET, 0.); + old_sf = (int)opt_mesh_surfaces_faces(0, GMSH_GET, 0.); + old_ve = (int)opt_mesh_volumes_edges(0, GMSH_GET, 0.); + old_vf = (int)opt_mesh_volumes_faces(0, GMSH_GET, 0.); + opt_mesh_points(0, GMSH_SET | GMSH_GUI, 0); + opt_mesh_lines(0, GMSH_SET | GMSH_GUI, 0); + opt_mesh_surfaces_edges(0, GMSH_SET | GMSH_GUI, 0); + opt_mesh_surfaces_faces(0, GMSH_SET | GMSH_GUI, 0); + opt_mesh_volumes_edges(0, GMSH_SET | GMSH_GUI, 0); + opt_mesh_volumes_faces(0, GMSH_SET | GMSH_GUI, 0); + } + drawContext::global()->draw(); + } + else if(!strcmp(str, "clscale")){ + meshSizeEditor(); + } else if(!strcmp(str, "S")){ // mouse selection if(CTX::instance()->mouseSelection){ opt_general_mouse_selection(0, GMSH_SET | GMSH_GUI, 0); @@ -356,6 +401,7 @@ graphicWindow::graphicWindow(bool main, int numTiles) fl_add_symbol("gmsh_ortho", gmsh_ortho, 1); fl_add_symbol("gmsh_rotate", gmsh_rotate, 1); fl_add_symbol("gmsh_models", gmsh_models, 1); + fl_add_symbol("gmsh_clscale", gmsh_clscale, 1); first = false; } @@ -411,6 +457,14 @@ graphicWindow::graphicWindow(bool main, int numTiles) butt[8]->callback(status_options_cb, (void *)"p"); butt[8]->tooltip("Toggle projection mode (Alt+o or Alt+Shift+o)"); x += sw; + butt[12] = new Fl_Button(x, glheight + 2, sw, sht, "M"); + butt[12]->callback(status_options_cb, (void *)"M"); + butt[12]->tooltip("Toggle mesh visibility (Alt+m)"); + x += sw; + butt[13] = new Fl_Button(x, glheight + 2, sw, sht, "@-1gmsh_clscale"); + butt[13]->callback(status_options_cb, (void *)"clscale"); + butt[13]->tooltip("Change mesh element size factor"); + x += sw; butt[9] = new Fl_Button(x, glheight + 2, sw, sht, "S"); butt[9]->callback(status_options_cb, (void *)"S"); butt[9]->tooltip("Toggle mouse selection ON/OFF (Escape)"); @@ -436,7 +490,7 @@ graphicWindow::graphicWindow(bool main, int numTiles) butt[11]->deactivate(); x += sw; - for(int i = 0; i < 12; i++) { + for(int i = 0; i < 14; i++) { butt[i]->box(FL_FLAT_BOX); butt[i]->selection_color(FL_WHITE); butt[i]->align(FL_ALIGN_CENTER | FL_ALIGN_INSIDE | FL_ALIGN_CLIP); diff --git a/Fltk/graphicWindow.h b/Fltk/graphicWindow.h index 5e2b536069..9547b4a317 100644 --- a/Fltk/graphicWindow.h +++ b/Fltk/graphicWindow.h @@ -22,7 +22,7 @@ class graphicWindow{ Fl_Tile *tile; std::vector<openglWindow*> gl; Fl_Box *bottom; - Fl_Button *butt[12]; + Fl_Button *butt[14]; Fl_Box *label[2]; int minWidth, minHeight; public: diff --git a/benchmarks/stl/artery.geo b/benchmarks/stl/artery.geo index 1462ff2384..ca2580777a 100644 --- a/benchmarks/stl/artery.geo +++ b/benchmarks/stl/artery.geo @@ -4,6 +4,6 @@ Mesh.CharacteristicLengthFactor=0.05; Merge "artery.stl"; CreateTopology; -Compound Surface(100)={1} Conformal; +Compound Surface(100)={1} Harmonic; Physical Surface(101)={100}; \ No newline at end of file diff --git a/benchmarks/stl/pelvis.geo b/benchmarks/stl/pelvis.geo index 534f8ecc7e..85a5e381c2 100644 --- a/benchmarks/stl/pelvis.geo +++ b/benchmarks/stl/pelvis.geo @@ -1,15 +1,13 @@ Mesh.CharacteristicLengthFactor=0.1; -Mesh.Algorithm3D = 4; //Frontal (4) Delaunay(1) +Mesh.Algorithm3D = 1; //Frontal (4) Delaunay(1) Merge "pelvis.stl"; -Compound Surface(200)={1} Conformal; +Compound Surface(200)={1};// Conformal; Surface Loop(300)={200}; Volume(301)={300}; Physical Surface (501)={200}; Physical Volume(502)={301}; - - -- GitLab