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

refactoring

parent ef16c6d7
No related branches found
No related tags found
No related merge requests found
...@@ -918,6 +918,8 @@ onelabWindow::onelabWindow(int deltaFontSize) ...@@ -918,6 +918,8 @@ onelabWindow::onelabWindow(int deltaFontSize)
_tree->connectorstyle(FL_TREE_CONNECTOR_SOLID); _tree->connectorstyle(FL_TREE_CONNECTOR_SOLID);
_tree->showroot(0); _tree->showroot(0);
_itemWidth = (int)(0.5 * _tree->w());
_butt[0] = new Fl_Button(width - 2*WB - 2*BB, height - WB - BH, BB, BH, "Check"); _butt[0] = new Fl_Button(width - 2*WB - 2*BB, height - WB - BH, BB, BH, "Check");
_butt[0]->callback(onelab_cb, (void*)"check"); _butt[0]->callback(onelab_cb, (void*)"check");
_butt[1] = new Fl_Button(width - WB - BB, height - WB - BH, BB, BH, "Compute"); _butt[1] = new Fl_Button(width - WB - BB, height - WB - BH, BB, BH, "Compute");
...@@ -951,60 +953,35 @@ onelabWindow::onelabWindow(int deltaFontSize) ...@@ -951,60 +953,35 @@ onelabWindow::onelabWindow(int deltaFontSize)
FL_NORMAL_SIZE += _deltaFontSize; FL_NORMAL_SIZE += _deltaFontSize;
} }
void onelabWindow::rebuildTree() void onelabWindow::_addParameter(onelab::number &p)
{ {
FL_NORMAL_SIZE -= _deltaFontSize; Fl_Tree_Item *n = _tree->add(p.getName().c_str());
int width = (int)(0.5 * _tree->w());
std::vector<std::string> closed;
for (Fl_Tree_Item *n = _tree->first(); n; n = n->next())
if(n->is_close()) closed.push_back(getPath(n));
_tree->clear();
_tree->sortorder(FL_TREE_SORT_ASCENDING);
_tree->selectmode(FL_TREE_SELECT_NONE);
for(unsigned int i = 0; i < _treeWidgets.size(); i++)
Fl::delete_widget(_treeWidgets[i]);
_treeWidgets.clear();
for(unsigned int i = 0; i < _treeStrings.size(); i++)
free(_treeStrings[i]);
_treeStrings.clear();
std::vector<onelab::number> numbers;
onelab::server::instance()->get(numbers);
for(unsigned int i = 0; i < numbers.size(); i++){
if(!numbers[i].getVisible()) continue;
Fl_Tree_Item *n = _tree->add(numbers[i].getName().c_str());
n->labelsize(FL_NORMAL_SIZE + 5); n->labelsize(FL_NORMAL_SIZE + 5);
std::string label = numbers[i].getShortName(); std::string label = p.getShortName();
_tree->begin(); _tree->begin();
if(numbers[i].getChoices().size() == 2 && if(p.getChoices().size() == 2 && p.getChoices()[0] == 0 && p.getChoices()[1] == 1){
numbers[i].getChoices()[0] == 0 && Fl_Check_Button *but = new Fl_Check_Button(1, 1, _itemWidth, 1);
numbers[i].getChoices()[1] == 1){
Fl_Check_Button *but = new Fl_Check_Button(1, 1, width, 1);
_treeWidgets.push_back(but); _treeWidgets.push_back(but);
but->copy_label(label.c_str()); but->copy_label(label.c_str());
but->value(numbers[i].getValue()); but->value(p.getValue());
but->callback(onelab_check_button_cb, (void*)n); but->callback(onelab_check_button_cb, (void*)n);
n->widget(but); n->widget(but);
if(numbers[i].getAttribute("Highlight").size()) if(p.getAttribute("Highlight").size())
n->labelbgcolor(FL_YELLOW); n->labelbgcolor(FL_YELLOW);
} }
else{ else{
inputRange *but = new inputRange inputRange *but = new inputRange
(1, 1, width, 1, onelab::parameter::maxNumber()); (1, 1, _itemWidth, 1, onelab::parameter::maxNumber());
_treeWidgets.push_back(but); _treeWidgets.push_back(but);
but->copy_label(label.c_str()); but->copy_label(label.c_str());
but->value(numbers[i].getValue()); but->value(p.getValue());
but->minimum(numbers[i].getMin()); but->minimum(p.getMin());
but->maximum(numbers[i].getMax()); but->maximum(p.getMax());
but->step(numbers[i].getStep()); but->step(p.getStep());
but->choices(numbers[i].getChoices()); but->choices(p.getChoices());
but->loop(numbers[i].getAttribute("Loop")); but->loop(p.getAttribute("Loop"));
but->graph(numbers[i].getAttribute("Graph")); but->graph(p.getAttribute("Graph"));
if(numbers[i].getAttribute("Highlight").size()) if(p.getAttribute("Highlight").size())
but->color(FL_YELLOW); but->color(FL_YELLOW);
but->align(FL_ALIGN_RIGHT); but->align(FL_ALIGN_RIGHT);
but->callback(onelab_input_range_cb, (void*)n); but->callback(onelab_input_range_cb, (void*)n);
...@@ -1014,33 +991,31 @@ void onelabWindow::rebuildTree() ...@@ -1014,33 +991,31 @@ void onelabWindow::rebuildTree()
_tree->end(); _tree->end();
} }
std::vector<onelab::string> strings; void onelabWindow::_addParameter(onelab::string &p)
onelab::server::instance()->get(strings); {
for(unsigned int i = 0; i < strings.size(); i++){ Fl_Tree_Item *n = _tree->add(p.getName().c_str());
if(!strings[i].getVisible()) continue;
Fl_Tree_Item *n = _tree->add(strings[i].getName().c_str());
n->labelsize(FL_NORMAL_SIZE + 5); n->labelsize(FL_NORMAL_SIZE + 5);
std::string label = strings[i].getShortName(); std::string label = p.getShortName();
_tree->begin(); _tree->begin();
Fl_Input_Choice *but = new Fl_Input_Choice(1, 1, width, 1); Fl_Input_Choice *but = new Fl_Input_Choice(1, 1, _itemWidth, 1);
_treeWidgets.push_back(but); _treeWidgets.push_back(but);
but->copy_label(label.c_str()); but->copy_label(label.c_str());
std::vector<Fl_Menu_Item> menu; std::vector<Fl_Menu_Item> menu;
for(unsigned int j = 0; j < strings[i].getChoices().size(); j++){ for(unsigned int j = 0; j < p.getChoices().size(); j++){
// need to manually manage the label strings // need to manually manage the label strings
char *str = strdup(strings[i].getChoices()[j].c_str()); char *str = strdup(p.getChoices()[j].c_str());
_treeStrings.push_back(str); _treeStrings.push_back(str);
bool divider = (strings[i].getKind() == "file" && bool divider = (p.getKind() == "file" &&
j == strings[i].getChoices().size() - 1); j == p.getChoices().size() - 1);
Fl_Menu_Item it = {str, 0, 0, 0, divider ? FL_MENU_DIVIDER : 0}; Fl_Menu_Item it = {str, 0, 0, 0, divider ? FL_MENU_DIVIDER : 0};
menu.push_back(it); menu.push_back(it);
} }
if(strings[i].getKind() == "file"){ if(p.getKind() == "file"){
Fl_Menu_Item it = {"Choose...", 0, onelab_input_choice_file_chooser_cb, (void*)n}; Fl_Menu_Item it = {"Choose...", 0, onelab_input_choice_file_chooser_cb, (void*)n};
menu.push_back(it); menu.push_back(it);
Fl_Menu_Item it2 = {"Edit...", 0, onelab_input_choice_file_edit_cb, (void*)n}; Fl_Menu_Item it2 = {"Edit...", 0, onelab_input_choice_file_edit_cb, (void*)n};
menu.push_back(it2); menu.push_back(it2);
if(GuessFileFormatFromFileName(strings[i].getValue()) >= 0){ if(GuessFileFormatFromFileName(p.getValue()) >= 0){
Fl_Menu_Item it3 = {"Merge...", 0, onelab_input_choice_file_merge_cb, (void*)n}; Fl_Menu_Item it3 = {"Merge...", 0, onelab_input_choice_file_merge_cb, (void*)n};
menu.push_back(it3); menu.push_back(it3);
} }
...@@ -1048,8 +1023,8 @@ void onelabWindow::rebuildTree() ...@@ -1048,8 +1023,8 @@ void onelabWindow::rebuildTree()
Fl_Menu_Item it = {0}; Fl_Menu_Item it = {0};
menu.push_back(it); menu.push_back(it);
but->menubutton()->copy(&menu[0]); but->menubutton()->copy(&menu[0]);
but->value(strings[i].getValue().c_str()); but->value(p.getValue().c_str());
if(strings[i].getAttribute("Highlight").size()) if(p.getAttribute("Highlight").size())
but->input()->color(FL_YELLOW); but->input()->color(FL_YELLOW);
but->align(FL_ALIGN_RIGHT); but->align(FL_ALIGN_RIGHT);
but->callback(onelab_input_choice_cb, (void*)n); but->callback(onelab_input_choice_cb, (void*)n);
...@@ -1058,10 +1033,45 @@ void onelabWindow::rebuildTree() ...@@ -1058,10 +1033,45 @@ void onelabWindow::rebuildTree()
_tree->end(); _tree->end();
} }
void onelabWindow::rebuildTree()
{
FL_NORMAL_SIZE -= _deltaFontSize;
_itemWidth = (int)(0.5 * _tree->w());
std::vector<std::string> closed;
for (Fl_Tree_Item *n = _tree->first(); n; n = n->next())
if(n->is_close()) closed.push_back(getPath(n));
_tree->clear();
_tree->sortorder(FL_TREE_SORT_ASCENDING);
_tree->selectmode(FL_TREE_SELECT_NONE);
for(unsigned int i = 0; i < _treeWidgets.size(); i++)
Fl::delete_widget(_treeWidgets[i]);
_treeWidgets.clear();
for(unsigned int i = 0; i < _treeStrings.size(); i++)
free(_treeStrings[i]);
_treeStrings.clear();
std::vector<onelab::number> numbers;
onelab::server::instance()->get(numbers);
for(unsigned int i = 0; i < numbers.size(); i++){
if(!numbers[i].getVisible()) continue;
_addParameter(numbers[i]);
}
std::vector<onelab::string> strings;
onelab::server::instance()->get(strings);
for(unsigned int i = 0; i < strings.size(); i++){
if(!strings[i].getVisible()) continue;
_addParameter(strings[i]);
}
for(Fl_Tree_Item *n = _tree->first(); n; n = n->next()){ for(Fl_Tree_Item *n = _tree->first(); n; n = n->next()){
if(n->has_children()){ if(n->has_children()){
_tree->begin(); _tree->begin();
Fl_Box *but = new Fl_Box(1, 1, width, 1); Fl_Box *but = new Fl_Box(1, 1, _itemWidth, 1);
but->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE); but->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
_treeWidgets.push_back(but); _treeWidgets.push_back(but);
onelab::string o(n->label()); onelab::string o(n->label());
...@@ -1234,8 +1244,9 @@ void onelabWindow::removeSolver(const std::string &name) ...@@ -1234,8 +1244,9 @@ void onelabWindow::removeSolver(const std::string &name)
void solver_cb(Fl_Widget *w, void *data) void solver_cb(Fl_Widget *w, void *data)
{ {
int num = (intptr_t)data; Msg::ResetErrorCounter();
int num = (intptr_t)data;
if(num >= 0){ if(num >= 0){
std::string name = opt_solver_name(num, GMSH_GET, ""); std::string name = opt_solver_name(num, GMSH_GET, "");
std::string exe = opt_solver_executable(num, GMSH_GET, ""); std::string exe = opt_solver_executable(num, GMSH_GET, "");
......
...@@ -29,6 +29,9 @@ class onelabWindow{ ...@@ -29,6 +29,9 @@ class onelabWindow{
std::string _title; std::string _title;
int _deltaFontSize; int _deltaFontSize;
bool _stop; bool _stop;
int _itemWidth;
void _addParameter(onelab::number &p);
void _addParameter(onelab::string &p);
public: public:
onelabWindow(int deltaFontSize=0); onelabWindow(int deltaFontSize=0);
int x(){ return _win->x(); } int x(){ return _win->x(); }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment