From 5ad3aea995c869a648f82e3d529c2c2c09cf1fdc Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Thu, 26 Jul 2007 14:49:06 +0000
Subject: [PATCH] more work on reparam gui

---
 Fltk/GUI_Projection.cpp | 246 +++++++++++++++++++---------------------
 Fltk/GUI_Projection.h   |  53 +++++++++
 2 files changed, 169 insertions(+), 130 deletions(-)
 create mode 100644 Fltk/GUI_Projection.h

diff --git a/Fltk/GUI_Projection.cpp b/Fltk/GUI_Projection.cpp
index 8bf0566ba0..6df613c8c0 100644
--- a/Fltk/GUI_Projection.cpp
+++ b/Fltk/GUI_Projection.cpp
@@ -1,119 +1,102 @@
-#include "Gmsh.h"
-#include "GmshUI.h"
-#include "GModel.h"
-#include "projectionFace.h"
 #include "Draw.h"
 #include "Options.h"
 #include "Context.h"
 #include "SelectBuffer.h"
-#include "GUI.h"
-#include "Shortcut_Window.h"
-
-#include <FL/Fl_Toggle_Button.H>
-#include <FL/Fl_Round_Button.H>
+#include "GUI_Projection.h"
 
 extern GModel *GMODEL;
 extern Context_T CTX;
 
-void select_cb(Fl_Widget *w, void *data);
-void browse_cb(Fl_Widget *w, void *data);
-void update_cb(Fl_Widget *w, void *data);
-void close_cb(Fl_Widget *w, void *data);
-void action_cb(Fl_Widget *w, void *data);
-void compute_cb(Fl_Widget *w, void *data);
-
-class uvPlot : public Fl_Window{
- private:
-  std::vector<double> _u, _v;
-  void draw()
-  {
-    // draw background
-    fl_color(FL_WHITE);
-    fl_rectf(0, 0, w(), h());
-    // draw points
-    fl_color(FL_BLACK);
-    if(_u.size() != _v.size()) return;
-    for(unsigned int i = 0; i < _u.size(); i++)
-      fl_rect(_u[i] * w(), _v[i] * h(), 3, 3);
+void uvPlot::draw()
+{
+  // draw background
+  fl_color(FL_WHITE);
+  fl_rectf(0, 0, w(), h());
+
+  // draw points
+  fl_color(FL_BLACK);
+  if(_u.size() != _v.size()) return;
+  for(unsigned int i = 0; i < _u.size(); i++)
+    fl_rect(_u[i] * w(), _v[i] * h(), 3, 3);
+
+  fl_font(FL_HELVETICA, 14);
+  fl_draw("Hello", w() / 2, h() / 2);
+}
+
+projectionEditor::projectionEditor(std::vector<projectionFace*> &faces) 
+  : _faces(faces)
+{
+  // construct GUI in terms of standard sizes
+  const int BH = 2 * GetFontSize() + 1, BB = 7 * GetFontSize(), WB = 7;
+  const int width = 3.5 * BB, height = 18 * BH;
+  
+  // create all widgets (we construct this once, we never deallocate!)
+  _window = new Dialog_Window(width, height, "Reparameterize");
+  
+  new Fl_Box(WB, WB + BH, 0.5 * BB, BH, "Select:");
+
+  Fl_Group *o = new Fl_Group(WB, WB, 2 * BB, 3 * BH);
+  _select[0] = new Fl_Round_Button(2 * WB + 0.5 * BB, WB, BB, BH, "Points");
+  _select[0]->value(1);
+  _select[1] = new Fl_Round_Button(2 * WB + 0.5 * BB, WB + BH, BB, BH, "Elements");
+  _select[2] = new Fl_Round_Button(2 * WB + 0.5 * BB, WB + 2 * BH, BB, BH, "Surfaces");
+  for(int i = 0; i < 3; i++){
+    _select[i]->callback(select_cb, this);
+    _select[i]->type(FL_RADIO_BUTTON);
   }
- public:
-  uvPlot(int x, int y, int w, int h, const char *l=0) : Fl_Window(x, y, w, h, l){}
-  void fill(std::vector<double> &u, std::vector<double> &v){ _u = u; _v = v; redraw(); }
-};
-
-class projectionEditor{
- private:
-  std::vector<projectionFace*> _faces;
-  Fl_Window *_window;
-  Fl_Value_Input *_input[20];
-  Fl_Hold_Browser *_browser;
-  Fl_Round_Button *_select[3];
-  uvPlot *_uvPlot;
- public:
-  projectionEditor(std::vector<projectionFace*> &faces) : _faces(faces)
-  {
-    const int BH = 2 * GetFontSize() + 1, BB = 7 * GetFontSize(), WB = 7;
-    const int width = 3.5 * BB, height = 18 * BH;
-    _window = new Dialog_Window(width, height, "Reparameterize");
-    new Fl_Box(WB, WB + BH, 0.5 * BB, BH, "Select:");
-    Fl_Group *o = new Fl_Group(WB, WB, 2 * BB, 3 * BH);
-    _select[0] = new Fl_Round_Button(2 * WB + 0.5 * BB, WB, BB, BH, "Points");
-    _select[0]->callback(select_cb, (void*)"Points");
-    _select[0]->value(1);
-    _select[1] = new Fl_Round_Button(2 * WB + 0.5 * BB, WB + BH, BB, BH, "Elements");
-    _select[1]->callback(select_cb, (void*)"Elements");
-    _select[2] = new Fl_Round_Button(2 * WB + 0.5 * BB, WB + 2 * BH, BB, BH, "Surfaces");
-    _select[2]->callback(select_cb, (void*)"Surfaces");
-    for(int i = 0; i < 3; i++) 
-      _select[i]->type(FL_RADIO_BUTTON);
-    o->end();
-    Fl_Toggle_Button *b1 = new Fl_Toggle_Button(width - WB - 1.5 * BB, WB, 1.5 * BB, BH, 
-						"Hide unselected");
-    b1->callback(action_cb, (void*)"Hide");
-    Fl_Button *b2 = new Fl_Button(width - WB - 1.5 * BB, WB + BH, 1.5 * BB, BH, 
-				  "Save selection");
-    b2->callback(action_cb, (void*)"Save");
-    _browser = new Fl_Hold_Browser(WB, 2 * WB + 3 * BH, BB, 5 * BH);
-    _browser->callback(browse_cb, this);
-    for(unsigned int i = 0; i < _faces.size(); i++){
-      _browser->add("test");
-    }
-    Fl_Scroll *s = new Fl_Scroll(2 * WB + BB, 2 * WB + 3 * BH, width - 3 * WB - BB, 5 * BH);
-    for(int i = 0; i < 20; i++){
-      _input[i] = new Fl_Value_Input(2 * WB + BB, 2 * WB + (i + 3) * BH, BB, BH);
-      _input[i]->align(FL_ALIGN_RIGHT);
-      _input[i]->callback(update_cb, this);
-      _input[i]->minimum(0.);
-      _input[i]->maximum(1.);
-      _input[i]->step(0.01);
-      //_input[i]->hide();
-    }
-    s->end();
-    _uvPlot = new uvPlot(WB, 3 * WB + 8 * BH, width - 2 * WB, height - 5 * WB - 9 * BH);
-    _uvPlot->end();
-    Fl_Button *b3 = new Fl_Button(width - 2 * WB - 2 * BB, height - WB - BH, BB, BH, 
-				  "Compute");
-    b3->callback(compute_cb, this);
-    Fl_Button *b4 = new Fl_Button(width - WB - BB, height - WB - BH, BB, BH, 
-				  "Cancel");
-    b4->callback(close_cb, _window);
-    _window->end();
-    _window->hotspot(_window);
-    _window->resizable(_uvPlot);
-    _window->size_range(width, 0.75 * height);
+  o->end();
+  
+  Fl_Toggle_Button *b1 = 
+    new Fl_Toggle_Button(width - WB - 1.5 * BB, WB, 1.5 * BB, BH, "Hide unselected");
+  b1->callback(hide_cb);
+
+  Fl_Button *b2 = 
+    new Fl_Button(width - WB - 1.5 * BB, WB + BH, 1.5 * BB, BH, "Save selection");
+  b2->callback(save_cb, this);
+
+  _browser = new Fl_Hold_Browser(WB, 2 * WB + 3 * BH, BB, 5 * BH);
+  _browser->callback(browse_cb, this);
+  for(unsigned int i = 0; i < _faces.size(); i++){
+    _browser->add("test");
   }
-  void show()
-  {
-    _window->show();
-    for(int i = 0; i < 3; i++)
-      if(_select[i]->value()) _select[i]->do_callback();
+
+  Fl_Scroll *s = new Fl_Scroll(2 * WB + BB, 2 * WB + 3 * BH, width - 3 * WB - BB, 5 * BH);
+  for(int i = 0; i < 20; i++){
+    _input[i] = new Fl_Value_Input(2 * WB + BB, 2 * WB + (i + 3) * BH, BB, BH);
+    _input[i]->align(FL_ALIGN_RIGHT);
+    _input[i]->callback(update_cb, this);
+    _input[i]->minimum(0.);
+    _input[i]->maximum(1.);
+    _input[i]->step(0.01);
+    //_input[i]->hide();
   }
-  uvPlot *uv() { return _uvPlot; }
-  projectionFace *face() { return 0; } // return current projection face
-  void reset(){} // reset all parameters to default values
-  void save(){} // save all parameters to a file
-  void load(){}  // load parameters from file
-};
+  s->end();
+
+  _uvPlot = new uvPlot(WB, 3 * WB + 8 * BH, width - 2 * WB, height - 5 * WB - 9 * BH);
+  _uvPlot->end();
+
+  Fl_Button *b3 = 
+    new Fl_Button(width - 2 * WB - 2 * BB, height - WB - BH, BB, BH, "Compute");
+  b3->callback(compute_cb, this);
+
+  Fl_Button *b4 = 
+    new Fl_Button(width - WB - BB, height - WB - BH, BB, BH, "Cancel");
+  b4->callback(close_cb, _window);
+
+  _window->end();
+  _window->hotspot(_window);
+  _window->resizable(_uvPlot);
+  _window->size_range(width, 0.75 * height);
+}
+
+int projectionEditor::getSelectionMode() 
+{ 
+  if(_select[0]->value())
+    return ENT_POINT;
+  else if(_select[2]->value())
+    return ENT_SURFACE;
+  return ENT_ALL;
+}
 
 void browse_cb(Fl_Widget *w, void *data)
 {
@@ -144,23 +127,17 @@ void update_cb(Fl_Widget *w, void *data)
 
 void select_cb(Fl_Widget *w, void *data)
 {
-  char *str = (char*)data;
-  int what;
+  projectionEditor *e = (projectionEditor*)data;
 
-  if(!strcmp(str, "Points")){
-    CTX.pick_elements = 0;
-    what = ENT_POINT;
-  }
-  else if(!strcmp(str, "Elements")){
-    CTX.pick_elements = 1;
-    what = ENT_ALL;
-  }
-  else if(!strcmp(str, "Surfaces")){
-    CTX.pick_elements = 0;
-    what = ENT_SURFACE;
+  int what = e->getSelectionMode();
+  char *str;
+
+  switch(what){
+  case ENT_ALL: CTX.pick_elements = 1; str = "Elements"; break;
+  case ENT_POINT: CTX.pick_elements = 0; str = "Points"; break;
+  case ENT_SURFACE: CTX.pick_elements = 0; str = "Surfaces"; break;
+  default: return;
   }
-  else
-    return;
 
   std::vector<GVertex*> vertices;
   std::vector<GEdge*> edges;
@@ -168,8 +145,8 @@ void select_cb(Fl_Widget *w, void *data)
   std::vector<GRegion*> regions;
   std::vector<MElement*> elements;
 
-  std::vector<MElement*> ele;
-  std::vector<GEntity*> ent;
+  std::vector<MElement*> &ele(e->getElements());
+  std::vector<GEntity*> &ent(e->getEntities());
 
   while(1) {
     CTX.mesh.changed = ENT_ALL;
@@ -252,17 +229,26 @@ void close_cb(Fl_Widget *w, void *data)
   if(data) ((Fl_Window *) data)->hide();
 }
 
-void action_cb(Fl_Widget *w, void *data)
+void hide_cb(Fl_Widget *w, void *data)
 {
-  char *str = (char*)data;
-  if(!strcmp(str, "Hide")){
-    CTX.hide_unselected = !CTX.hide_unselected;
-    CTX.mesh.changed = ENT_ALL;
+  CTX.hide_unselected = !CTX.hide_unselected;
+  CTX.mesh.changed = ENT_ALL;
+  Draw();
+}
+
+void save_cb(Fl_Widget *w, void *data)
+{
+  projectionEditor *e = (projectionEditor*)data;
+
+  std::vector<GEntity*> &ent(e->getEntities());
+  for(unsigned int i = 0; i < ent.size(); i++){
+    printf("entity %d\n", ent[i]->tag());
   }
-  else if(!strcmp(str, "Save")){
-    Msg(GERROR, "Save not implemented yet!");
+
+  std::vector<MElement*> &ele(e->getElements());
+  for(unsigned int i = 0; i < ele.size(); i++){
+    printf("element %d\n", ele[i]->getNum());
   }
-  Draw();
 }
 
 void compute_cb(Fl_Widget *w, void *data)
diff --git a/Fltk/GUI_Projection.h b/Fltk/GUI_Projection.h
new file mode 100644
index 0000000000..31ca298b03
--- /dev/null
+++ b/Fltk/GUI_Projection.h
@@ -0,0 +1,53 @@
+#ifndef _GUI_PROJECTION_H_
+#define _GUI_PROJECTION_H_
+
+#include "Gmsh.h"
+#include "GmshUI.h"
+#include "GModel.h"
+#include "projectionFace.h"
+
+#include <vector>
+
+#include "GUI.h"
+#include "Shortcut_Window.h"
+#include <FL/Fl_Toggle_Button.H>
+#include <FL/Fl_Round_Button.H>
+
+void select_cb(Fl_Widget *w, void *data);
+void browse_cb(Fl_Widget *w, void *data);
+void update_cb(Fl_Widget *w, void *data);
+void close_cb(Fl_Widget *w, void *data);
+void hide_cb(Fl_Widget *w, void *data);
+void save_cb(Fl_Widget *w, void *data);
+void compute_cb(Fl_Widget *w, void *data);
+
+class uvPlot : public Fl_Window {
+ private:
+  std::vector<double> _u, _v;
+  void draw();
+ public:
+  uvPlot(int x, int y, int w, int h, const char *l=0) : Fl_Window(x, y, w, h, l){}
+  void fill(std::vector<double> &u, std::vector<double> &v){ _u = u; _v = v; redraw(); }
+};
+
+class projectionEditor {
+ private:
+  std::vector<projectionFace*> _faces;
+  std::vector<MElement*> _elements;
+  std::vector<GEntity*> _entities;
+  Fl_Window *_window;
+  Fl_Value_Input *_input[20];
+  Fl_Hold_Browser *_browser;
+  Fl_Round_Button *_select[3];
+  uvPlot *_uvPlot;
+ public:
+  projectionEditor(std::vector<projectionFace*> &faces);
+  void show(){ _window->show(); select_cb(0, this); }
+  uvPlot *uv() { return _uvPlot; }
+  std::vector<MElement*> &getElements() { return _elements; }
+  std::vector<GEntity*> &getEntities() { return _entities; }
+  std::vector<projectionFace*> &getProjectionFaces() { return _faces; }
+  int getSelectionMode();
+};
+
+#endif
-- 
GitLab