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

refactoring

parent e1c6e43b
No related branches found
No related tags found
No related merge requests found
......@@ -206,9 +206,9 @@ bool onelab::localNetworkClient::run()
std::string computeCommand = (ps.empty() ? "" : ps[0].getValue());
if(modelName.size()) command.append(" \"" + modelName + "\"");
if(action == "check")
command.append(" "+checkCommand) ;
command.append(" "+ checkCommand) ;
else if(action == "compute")
command.append(" "+computeCommand);
command.append(" "+ computeCommand);
}
command.append(" " + getSocketSwitch() + " \"" + getName() + "\" %s");
}
......@@ -1062,30 +1062,39 @@ static bool getFlColor(const std::string &str, Fl_Color &c)
return false;
}
void onelabWindow::_addParameter(onelab::number &p)
template<class T>
void onelabWindow::_addParameter(T &p)
{
std::string label = p.getShortName();
std::vector<double> choices = p.getChoices();
bool highlight = false;
Fl_Color c;
if(getFlColor(p.getAttribute("Highlight"), c)) highlight = true;
Fl_Tree_Item *n = _tree->add(p.getName().c_str());
n->labelsize(FL_NORMAL_SIZE + 5);
_tree->begin();
Fl_Widget *widget;
Fl_Widget *widget = _addParameterWidget(p, n, highlight, c);
_treeWidgets.push_back(widget);
widget->copy_label(p.getShortName().c_str());
n->widget(widget);
_tree->end();
}
Fl_Widget *onelabWindow::_addParameterWidget(onelab::number &p, Fl_Tree_Item *n,
bool highlight, Fl_Color c)
{
// non-editable value
if(p.getReadOnly()){
// non-editable value
Fl_Output *but = new Fl_Output(1, 1, _itemWidth, 1);
char tmp[128];
sprintf(tmp, "%g", p.getValue());
but->value(tmp);
but->align(FL_ALIGN_RIGHT);
if(highlight) but->color(c);
widget = but;
return but;
}
else if(choices.size() && choices.size() == p.getValueLabels().size()){
// enumeration (display choices as value labels, not numbers)
// enumeration (display choices as value labels, not numbers)
if(p.getChoices().size() &&
p.getChoices().size() == p.getValueLabels().size()){
Fl_Choice *but = new Fl_Choice(1, 1, _itemWidth, 1);
std::vector<Fl_Menu_Item> menu;
std::map<double, std::string> labels(p.getValueLabels());
......@@ -1099,167 +1108,113 @@ void onelabWindow::_addParameter(onelab::number &p)
Fl_Menu_Item it = {0};
menu.push_back(it);
but->copy(&menu[0]);
for(unsigned int i = 0; i < choices.size(); i++){
if(p.getValue() == choices[i]){
for(unsigned int i = 0; i < p.getChoices().size(); i++){
if(p.getValue() == p.getChoices()[i]){
but->value(i);
break;
}
}
but->callback(onelab_choice_cb, (void*)n);
but->align(FL_ALIGN_RIGHT);
if(highlight) n->labelbgcolor(c);
widget = but;
return but;
}
else if(choices.size() == 2 && choices[0] == 0 && choices[1] == 1){
// check box (boolean choice)
// check box (boolean choice)
if(p.getChoices().size() == 2 &&
p.getChoices()[0] == 0 && p.getChoices()[1] == 1){
Fl_Check_Button *but = new Fl_Check_Button(1, 1, _itemWidth, 1);
but->value(p.getValue());
but->callback(onelab_check_button_cb, (void*)n);
if(highlight) n->labelbgcolor(c);
widget = but;
}
else{
// general number input
inputRange *but = new inputRange
(1, 1, _itemWidth, 1, onelab::parameter::maxNumber());
but->value(p.getValue());
but->minimum(p.getMin());
but->maximum(p.getMax());
but->step(p.getStep());
but->choices(p.getChoices());
but->loop(p.getAttribute("Loop"));
but->graph(p.getAttribute("Graph"));
but->callback(onelab_input_range_cb, (void*)n);
but->when(FL_WHEN_RELEASE | FL_WHEN_ENTER_KEY);
if(highlight) but->color(c);
widget = but;
}
_treeWidgets.push_back(widget);
widget->copy_label(label.c_str());
widget->align(FL_ALIGN_RIGHT);
n->widget(widget);
_tree->end();
return but;
}
// general number input
inputRange *but = new inputRange
(1, 1, _itemWidth, 1, onelab::parameter::maxNumber());
but->value(p.getValue());
but->minimum(p.getMin());
but->maximum(p.getMax());
but->step(p.getStep());
but->choices(p.getChoices());
but->loop(p.getAttribute("Loop"));
but->graph(p.getAttribute("Graph"));
but->callback(onelab_input_range_cb, (void*)n);
but->when(FL_WHEN_RELEASE | FL_WHEN_ENTER_KEY);
but->align(FL_ALIGN_RIGHT);
if(highlight) but->color(c);
return but;
}
void onelabWindow::_addParameter(onelab::string &p)
Fl_Widget *onelabWindow::_addParameterWidget(onelab::string &p, Fl_Tree_Item *n,
bool highlight, Fl_Color c)
{
std::string label = p.getShortName();
std::vector<std::string> choices = p.getChoices();
bool highlight = false;
Fl_Color c;
if(getFlColor(p.getAttribute("Highlight"), c)) highlight = true;
Fl_Tree_Item *n = _tree->add(p.getName().c_str());
n->labelsize(FL_NORMAL_SIZE + 5);
_tree->begin();
Fl_Widget *widget;
// non-editable value
if(p.getReadOnly()){
// non-editable value
Fl_Output *but = new Fl_Output(1, 1, _itemWidth, 1);
but->value(p.getValue().c_str());
but->align(FL_ALIGN_RIGHT);
if(highlight) but->color(c);
widget = but;
return but;
}
// general string input
Fl_Input_Choice *but = new Fl_Input_Choice(1, 1, _itemWidth, 1);
std::vector<Fl_Menu_Item> menu;
for(unsigned int j = 0; j < p.getChoices().size(); j++){
char *str = strdup(p.getChoices()[j].c_str());
_treeStrings.push_back(str);
bool divider = (p.getKind() == "file" &&
j == p.getChoices().size() - 1);
Fl_Menu_Item it = {str, 0, 0, 0, divider ? FL_MENU_DIVIDER : 0};
menu.push_back(it);
}
else{
// general string input
Fl_Input_Choice *but = new Fl_Input_Choice(1, 1, _itemWidth, 1);
std::vector<Fl_Menu_Item> menu;
for(unsigned int j = 0; j < choices.size(); j++){
char *str = strdup(choices[j].c_str());
_treeStrings.push_back(str);
bool divider = (p.getKind() == "file" &&
j == choices.size() - 1);
Fl_Menu_Item it = {str, 0, 0, 0, divider ? FL_MENU_DIVIDER : 0};
menu.push_back(it);
}
if(p.getKind() == "file"){
Fl_Menu_Item it = {"Choose...", 0, onelab_input_choice_file_chooser_cb, (void*)n};
menu.push_back(it);
Fl_Menu_Item it2 = {"Edit...", 0, onelab_input_choice_file_edit_cb, (void*)n};
menu.push_back(it2);
if(GuessFileFormatFromFileName(p.getValue()) >= 0){
Fl_Menu_Item it3 = {"Merge...", 0, onelab_input_choice_file_merge_cb, (void*)n};
menu.push_back(it3);
}
}
Fl_Menu_Item it = {0};
if(p.getKind() == "file"){
Fl_Menu_Item it = {"Choose...", 0, onelab_input_choice_file_chooser_cb, (void*)n};
menu.push_back(it);
but->menubutton()->copy(&menu[0]);
but->value(p.getValue().c_str());
but->callback(onelab_input_choice_cb, (void*)n);
but->when(FL_WHEN_RELEASE | FL_WHEN_ENTER_KEY);
if(highlight) but->input()->color(c);
widget = but;
Fl_Menu_Item it2 = {"Edit...", 0, onelab_input_choice_file_edit_cb, (void*)n};
menu.push_back(it2);
if(GuessFileFormatFromFileName(p.getValue()) >= 0){
Fl_Menu_Item it3 = {"Merge...", 0, onelab_input_choice_file_merge_cb, (void*)n};
menu.push_back(it3);
}
}
_treeWidgets.push_back(widget);
widget->copy_label(label.c_str());
widget->align(FL_ALIGN_RIGHT);
n->widget(widget);
_tree->end();
Fl_Menu_Item it = {0};
menu.push_back(it);
but->menubutton()->copy(&menu[0]);
but->value(p.getValue().c_str());
but->callback(onelab_input_choice_cb, (void*)n);
but->when(FL_WHEN_RELEASE | FL_WHEN_ENTER_KEY);
but->align(FL_ALIGN_RIGHT);
if(highlight) but->input()->color(c);
return but;
}
void onelabWindow::_addParameter(onelab::region &p)
Fl_Widget *onelabWindow::_addParameterWidget(onelab::region &p, Fl_Tree_Item *n,
bool highlight, Fl_Color c)
{
std::string label = p.getShortName();
std::vector<std::set<std::string> > choices = p.getChoices();
bool highlight = false;
Fl_Color c;
if(getFlColor(p.getAttribute("Highlight"), c)) highlight = true;
Fl_Tree_Item *n = _tree->add(p.getName().c_str());
n->labelsize(FL_NORMAL_SIZE + 5);
_tree->begin();
Fl_Widget *widget;
if(1){//p.getReadOnly()){
// non-editable value
// non-editable value
//if(p.getReadOnly()){
Fl_Output *but = new Fl_Output(1, 1, _itemWidth, 1);
but->value("TODO groups");
but->align(FL_ALIGN_RIGHT);
if(highlight) but->color(c);
widget = but;
}
else{
// general group input
}
_treeWidgets.push_back(widget);
widget->copy_label(label.c_str());
widget->align(FL_ALIGN_RIGHT);
n->widget(widget);
_tree->end();
return but;
//}
}
void onelabWindow::_addParameter(onelab::function &p)
Fl_Widget *onelabWindow::_addParameterWidget(onelab::function &p, Fl_Tree_Item *n,
bool highlight, Fl_Color c)
{
std::string label = p.getShortName();
std::vector<std::map<std::string, std::string> > choices = p.getChoices();
bool highlight = false;
Fl_Color c;
if(getFlColor(p.getAttribute("Highlight"), c)) highlight = true;
Fl_Tree_Item *n = _tree->add(p.getName().c_str());
n->labelsize(FL_NORMAL_SIZE + 5);
_tree->begin();
Fl_Widget *widget;
if(1){//p.getReadOnly()){
// non-editable value
// non-editable value
//if(p.getReadOnly()){
Fl_Output *but = new Fl_Output(1, 1, _itemWidth, 1);
but->value("TODO function");
but->align(FL_ALIGN_RIGHT);
if(highlight) but->color(c);
widget = but;
}
else{
// general function input
}
_treeWidgets.push_back(widget);
widget->copy_label(label.c_str());
widget->align(FL_ALIGN_RIGHT);
n->widget(widget);
_tree->end();
return but;
//}
}
void onelabWindow::rebuildTree()
......
......@@ -30,10 +30,15 @@ class onelabWindow{
int _deltaFontSize;
bool _stop;
int _itemWidth;
void _addParameter(onelab::number &p);
void _addParameter(onelab::string &p);
void _addParameter(onelab::region &p);
void _addParameter(onelab::function &p);
template <class T> void _addParameter(T &p);
Fl_Widget *_addParameterWidget(onelab::number &p, Fl_Tree_Item *n,
bool highlight, Fl_Color c);
Fl_Widget *_addParameterWidget(onelab::string &p, Fl_Tree_Item *n,
bool highlight, Fl_Color c);
Fl_Widget *_addParameterWidget(onelab::region &p, Fl_Tree_Item *n,
bool highlight, Fl_Color c);
Fl_Widget *_addParameterWidget(onelab::function &p, Fl_Tree_Item *n,
bool highlight, Fl_Color c);
public:
onelabWindow(int deltaFontSize=0);
int x(){ return _win->x(); }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment