From b5da02ae0c5bd71ae4de028e4e350b3182e16f18 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Sun, 29 Oct 2017 09:39:57 +0100 Subject: [PATCH] new ServerAction attribute to reset onelab variables: e.g. ServerAction "Reset" or SeverAction "Reset var1 var2". (ServerAction "Reset" replaces GmshOption "Reset", which is still supported but deprecated) --- Common/GmshMessage.cpp | 1 + Fltk/onelabGroup.cpp | 46 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/Common/GmshMessage.cpp b/Common/GmshMessage.cpp index 91df709b87..46be74aee5 100644 --- a/Common/GmshMessage.cpp +++ b/Common/GmshMessage.cpp @@ -1211,6 +1211,7 @@ static void _setStandardOptions(onelab::parameter *p, if(copt.count("Highlight")) p->setAttribute("Highlight", copt["Highlight"][0]); if(copt.count("Macro")) p->setAttribute("Macro", copt["Macro"][0]); if(copt.count("GmshOption")) p->setAttribute("GmshOption", copt["GmshOption"][0]); + if(copt.count("ServerAction")) p->setAttribute("ServerAction", copt["ServerAction"][0]); if(copt.count("Units")) p->setAttribute("Units", copt["Units"][0]); if(copt.count("AutoCheck")) // for backward compatibility p->setAttribute("AutoCheck", copt["AutoCheck"][0]); diff --git a/Fltk/onelabGroup.cpp b/Fltk/onelabGroup.cpp index d0c25bcbf1..302bc3134d 100644 --- a/Fltk/onelabGroup.cpp +++ b/Fltk/onelabGroup.cpp @@ -649,25 +649,49 @@ void onelabGroup::openCloseViewButton(int num) } } -template <class T> -static void setGmshOption(T &n) +static bool serverAction(const std::string &action) { - std::string opt = n.getAttribute("GmshOption"); - if(opt.empty()) return; - if(opt == "ResetDatabase"){ // special option to reset the onelab db + printf("server action %s\n", action.c_str()); + if(action == "ResetDatabase"){ // reset the onelab db resetDb(false); FlGui::instance()->rebuildTree(false); - return; + return true; } - if(opt == "Reset"){ // reset db + models except current one + else if(action == "Reset"){ // reset db + models except current one resetDb(false); for(int i = PView::list.size() - 1; i >= 0; i--) delete PView::list[i]; for(int i = GModel::list.size() - 1; i >= 0; i--) if(GModel::list[i] != GModel::current()) delete GModel::list[i]; FlGui::instance()->rebuildTree(false); - return; + return true; + } + else if(!action.compare(0, 5, "Reset")){ // reset some variables + std::vector<std::string> what = onelab::parameter::split(action, ' '); + for(unsigned int i = 1; i < what.size(); i++){ + Msg::Debug("Clearing variable '%s'", what[i].c_str()); + onelab::server::instance()->clear(what[i]); + } + FlGui::instance()->rebuildTree(false); + return true; } + return false; +} + +template <class T> +static void performServerAction(T &n) +{ + std::string opt = n.getAttribute("ServerAction"); + if(opt.empty()) return; + serverAction(opt); +} + +template <class T> +static void setGmshOption(T &n) +{ + std::string opt = n.getAttribute("GmshOption"); + if(opt.empty()) return; + if(serverAction(opt)) return; // for backward compatibility: std::string::size_type dot = opt.find('.'); if(dot == std::string::npos) return; GmshSetOption(opt.substr(0, dot), opt.substr(dot + 1), n.getValue()); @@ -685,6 +709,7 @@ static void onelab_number_check_button_cb(Fl_Widget *w, void *data) onelab::number old = numbers[0]; numbers[0].setValue(o->value()); setGmshOption(numbers[0]); + performServerAction(numbers[0]); onelab::server::instance()->set(numbers[0]); autoCheck(old, numbers[0]); } @@ -702,6 +727,7 @@ static void onelab_number_choice_cb(Fl_Widget *w, void *data) onelab::number old = numbers[0]; if(o->value() < (int)choices.size()) numbers[0].setValue(choices[o->value()]); setGmshOption(numbers[0]); + performServerAction(numbers[0]); onelab::server::instance()->set(numbers[0]); autoCheck(old, numbers[0]); } @@ -727,6 +753,7 @@ static void onelab_number_input_range_cb(Fl_Widget *w, void *data) numbers[0].setAttribute("Loop", o->loop()); numbers[0].setAttribute("Graph", o->graph()); setGmshOption(numbers[0]); + performServerAction(numbers[0]); onelab::server::instance()->set(numbers[0]); updateGraphs(); autoCheck(old, numbers[0]); @@ -846,6 +873,7 @@ static void onelab_string_button_cb(Fl_Widget *w, void *data) MergeFile(tmp); } setGmshOption(strings[0]); + performServerAction(strings[0]); autoCheck(strings[0], strings[0], true); drawContext::global()->draw(); } @@ -862,6 +890,7 @@ static void onelab_string_input_cb(Fl_Widget *w, void *data) onelab::string old = strings[0]; strings[0].setValue(o->value()); setGmshOption(strings[0]); + performServerAction(strings[0]); onelab::server::instance()->set(strings[0]); autoCheck(old, strings[0]); } @@ -889,6 +918,7 @@ static void onelab_string_input_choice_cb(Fl_Widget *w, void *data) if(choices.size()) strings[0].setAttribute("MultipleSelection", choices); setGmshOption(strings[0]); + performServerAction(strings[0]); onelab::server::instance()->set(strings[0]); autoCheck(old, strings[0]); } -- GitLab