Skip to content
Snippets Groups Projects
Commit 5ad3aea9 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

more work on reparam gui
parent 1cff28e0
Branches
Tags
No related merge requests found
#include "Gmsh.h"
#include "GmshUI.h"
#include "GModel.h"
#include "projectionFace.h"
#include "Draw.h" #include "Draw.h"
#include "Options.h" #include "Options.h"
#include "Context.h" #include "Context.h"
#include "SelectBuffer.h" #include "SelectBuffer.h"
#include "GUI.h" #include "GUI_Projection.h"
#include "Shortcut_Window.h"
#include <FL/Fl_Toggle_Button.H>
#include <FL/Fl_Round_Button.H>
extern GModel *GMODEL; extern GModel *GMODEL;
extern Context_T CTX; extern Context_T CTX;
void select_cb(Fl_Widget *w, void *data); void uvPlot::draw()
void browse_cb(Fl_Widget *w, void *data); {
void update_cb(Fl_Widget *w, void *data); // draw background
void close_cb(Fl_Widget *w, void *data); fl_color(FL_WHITE);
void action_cb(Fl_Widget *w, void *data); fl_rectf(0, 0, w(), h());
void compute_cb(Fl_Widget *w, void *data);
// draw points
class uvPlot : public Fl_Window{ fl_color(FL_BLACK);
private: if(_u.size() != _v.size()) return;
std::vector<double> _u, _v; for(unsigned int i = 0; i < _u.size(); i++)
void draw() fl_rect(_u[i] * w(), _v[i] * h(), 3, 3);
{
// draw background fl_font(FL_HELVETICA, 14);
fl_color(FL_WHITE); fl_draw("Hello", w() / 2, h() / 2);
fl_rectf(0, 0, w(), h()); }
// draw points
fl_color(FL_BLACK); projectionEditor::projectionEditor(std::vector<projectionFace*> &faces)
if(_u.size() != _v.size()) return; : _faces(faces)
for(unsigned int i = 0; i < _u.size(); i++) {
fl_rect(_u[i] * w(), _v[i] * h(), 3, 3); // 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: o->end();
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(); } Fl_Toggle_Button *b1 =
}; new Fl_Toggle_Button(width - WB - 1.5 * BB, WB, 1.5 * BB, BH, "Hide unselected");
b1->callback(hide_cb);
class projectionEditor{
private: Fl_Button *b2 =
std::vector<projectionFace*> _faces; new Fl_Button(width - WB - 1.5 * BB, WB + BH, 1.5 * BB, BH, "Save selection");
Fl_Window *_window; b2->callback(save_cb, this);
Fl_Value_Input *_input[20];
Fl_Hold_Browser *_browser; _browser = new Fl_Hold_Browser(WB, 2 * WB + 3 * BH, BB, 5 * BH);
Fl_Round_Button *_select[3]; _browser->callback(browse_cb, this);
uvPlot *_uvPlot; for(unsigned int i = 0; i < _faces.size(); i++){
public: _browser->add("test");
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);
} }
void show()
{ Fl_Scroll *s = new Fl_Scroll(2 * WB + BB, 2 * WB + 3 * BH, width - 3 * WB - BB, 5 * BH);
_window->show(); for(int i = 0; i < 20; i++){
for(int i = 0; i < 3; i++) _input[i] = new Fl_Value_Input(2 * WB + BB, 2 * WB + (i + 3) * BH, BB, BH);
if(_select[i]->value()) _select[i]->do_callback(); _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; } s->end();
projectionFace *face() { return 0; } // return current projection face
void reset(){} // reset all parameters to default values _uvPlot = new uvPlot(WB, 3 * WB + 8 * BH, width - 2 * WB, height - 5 * WB - 9 * BH);
void save(){} // save all parameters to a file _uvPlot->end();
void load(){} // load parameters from file
}; 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) void browse_cb(Fl_Widget *w, void *data)
{ {
...@@ -144,23 +127,17 @@ void update_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) void select_cb(Fl_Widget *w, void *data)
{ {
char *str = (char*)data; projectionEditor *e = (projectionEditor*)data;
int what;
if(!strcmp(str, "Points")){ int what = e->getSelectionMode();
CTX.pick_elements = 0; char *str;
what = ENT_POINT;
} switch(what){
else if(!strcmp(str, "Elements")){ case ENT_ALL: CTX.pick_elements = 1; str = "Elements"; break;
CTX.pick_elements = 1; case ENT_POINT: CTX.pick_elements = 0; str = "Points"; break;
what = ENT_ALL; case ENT_SURFACE: CTX.pick_elements = 0; str = "Surfaces"; break;
} default: return;
else if(!strcmp(str, "Surfaces")){
CTX.pick_elements = 0;
what = ENT_SURFACE;
} }
else
return;
std::vector<GVertex*> vertices; std::vector<GVertex*> vertices;
std::vector<GEdge*> edges; std::vector<GEdge*> edges;
...@@ -168,8 +145,8 @@ void select_cb(Fl_Widget *w, void *data) ...@@ -168,8 +145,8 @@ void select_cb(Fl_Widget *w, void *data)
std::vector<GRegion*> regions; std::vector<GRegion*> regions;
std::vector<MElement*> elements; std::vector<MElement*> elements;
std::vector<MElement*> ele; std::vector<MElement*> &ele(e->getElements());
std::vector<GEntity*> ent; std::vector<GEntity*> &ent(e->getEntities());
while(1) { while(1) {
CTX.mesh.changed = ENT_ALL; CTX.mesh.changed = ENT_ALL;
...@@ -252,17 +229,26 @@ void close_cb(Fl_Widget *w, void *data) ...@@ -252,17 +229,26 @@ void close_cb(Fl_Widget *w, void *data)
if(data) ((Fl_Window *) data)->hide(); 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; CTX.hide_unselected = !CTX.hide_unselected;
if(!strcmp(str, "Hide")){ CTX.mesh.changed = ENT_ALL;
CTX.hide_unselected = !CTX.hide_unselected; Draw();
CTX.mesh.changed = ENT_ALL; }
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) void compute_cb(Fl_Widget *w, void *data)
......
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment