diff --git a/Common/GmshSocket.h b/Common/GmshSocket.h index 627879510b33f9c2c40dac1c43d3b6553b2455c9..b49d56bb82496233147ba5eed5ecc7b614680be9 100644 --- a/Common/GmshSocket.h +++ b/Common/GmshSocket.h @@ -83,6 +83,7 @@ class GmshSocket{ GMSH_PARAMETER_NOT_FOUND = 29, GMSH_SPEED_TEST = 30, GMSH_PARAMETER_CLEAR = 31, + GMSH_PARAMETER_UPDATE = 32, GMSH_OPTION_1 = 100, GMSH_OPTION_2 = 101, GMSH_OPTION_3 = 102, diff --git a/Common/onelabUtils.cpp b/Common/onelabUtils.cpp index 40a73d44db83765fe2b8a216d6ef92b6cd22dbb2..02fd8ccee74ad2d92bb24e5526c93d2d0022877a 100644 --- a/Common/onelabUtils.cpp +++ b/Common/onelabUtils.cpp @@ -352,23 +352,16 @@ namespace onelabUtils { return redraw; } - // x is the parameter as on server - // y is the argument of set - // The routine updates x on basis of y. - // If the parameter is not yet defined, set(y) as is - // If the parameter is already defined, priority must be given to the server state - // for all items editable from the GUI, i.e. value, range, Loop, Graph, Closed. - // If y.getReadOnly() is true, the value of y overrides that of x - - + // update x using y, giving priority to any settings in x that can be set in + // the GUI. The value of x is only changed if y is read-only. double updateNumber(onelab::number &x, onelab::number &y, const bool readOnlyRange) { bool noRange = true, noChoices = true, noLoop = true; bool noGraph = true, noClosed = true; if(y.getReadOnly()){ - x.setValue(y.getValue()); // use set value - x.setReadOnly(1); // makes the field "value" non-editable in the GUI + x.setValue(y.getValue()); + x.setReadOnly(true); } double val = x.getValue(); @@ -385,19 +378,18 @@ namespace onelabUtils { if(x.getAttribute("Graph").size()) noGraph = false; if(x.getAttribute("Closed").size()) noClosed = false; - // send updated parameter to server if(noRange){ bool noRangeEither = true; if(y.getMin() != -onelab::parameter::maxNumber() || y.getMax() != onelab::parameter::maxNumber() || y.getStep() != 0.) noRangeEither = false; if(!noRangeEither){ - x.setMin(y.getMin()); + x.setMin(y.getMin()); x.setMax(y.getMax()); } else{ // if no range/min/max/step info is provided, try to compute a reasonnable - // range and step (this makes the gui much nicer to use) + // range and step (this makes the GUI much nicer to use) bool isInteger = (floor(val) == val); double fact = isInteger ? 5. : 20.; if(val > 0){ @@ -424,18 +416,18 @@ namespace onelabUtils { if(noLoop) x.setAttribute("Loop", y.getAttribute("Loop")); if(noGraph) x.setAttribute("Graph", y.getAttribute("Graph")); if(noClosed) x.setAttribute("Closed", y.getAttribute("Closed")); - return val; } - + // update x using y, giving priority to any settings in x that can be set in + // the GUI. The value of x is only changed if y is read-only. std::string updateString(onelab::string &x, onelab::string &y) { bool noChoices = true, noClosed = true, noMultipleSelection = true; if(y.getReadOnly()){ - x.setValue(y.getValue()); // use set value - x.setReadOnly(1); // makes the field "value" non-editable in the GUI + x.setValue(y.getValue()); + x.setReadOnly(true); } std::string val = x.getValue(); diff --git a/Fltk/onelabGroup.cpp b/Fltk/onelabGroup.cpp index e6dda2b0cdbc917ee09a558bc11bd137ef0bd091..bfe90e7571d1c95a57c459a145326fbfbd32c2ee 100644 --- a/Fltk/onelabGroup.cpp +++ b/Fltk/onelabGroup.cpp @@ -193,105 +193,74 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master) } break; case GmshSocket::GMSH_PARAMETER: + case GmshSocket::GMSH_PARAMETER_UPDATE: { - std::string version, type, name; - onelab::parameter::getInfoFromChar(message, version, type, name); + std::string version, ptype, name; + onelab::parameter::getInfoFromChar(message, version, ptype, name); if(onelab::parameter::version() != version){ Msg::Error("OneLab version mismatch (server: %s / client: %s)", onelab::parameter::version().c_str(), version.c_str()); } - else if(type == "number"){ - onelab::number p; p.fromChar(message); set(p); - if(p.getName() == getName() + "/Progress") - if(FlGui::available()) - FlGui::instance()->setProgress(p.getLabel().c_str(), p.getValue(), - p.getMin(), p.getMax()); - } - else if(type == "string"){ - onelab::string p; p.fromChar(message); set(p); - } - else if(type == "region"){ - onelab::region p; p.fromChar(message); set(p); - } - else if(type == "function"){ - onelab::function p; p.fromChar(message); set(p); - } - else - Msg::Error("Unknown OneLab parameter type: %s", type.c_str()); - } - break; - case 32: //case GmshSocket::GMSH_PARAMETER_UPDATE: - { - std::string version, type, name; - onelab::parameter::getInfoFromChar(message, version, type, name); - if(onelab::parameter::version() != version){ - Msg::Error("OneLab version mismatch (server: %s / client: %s)", - onelab::parameter::version().c_str(), version.c_str()); - } - else if(type == "number"){ - onelab::number p; - std::vector<onelab::number> par; get(par, name); - if(par.size() == 1) { - p = par[0]; - onelab::number y; y.fromChar(message); - onelabUtils::updateNumber(p,y); - } - else - p.fromChar(message); - set(p); + else if(ptype == "number"){ + onelab::number p; p.fromChar(message); + if(type == GmshSocket::GMSH_PARAMETER_UPDATE){ + std::vector<onelab::number> par; get(par, name); + if(par.size()) { + onelab::number y = p; p = par[0]; onelabUtils::updateNumber(p, y); + } + } + set(p); if(p.getName() == getName() + "/Progress") if(FlGui::available()) FlGui::instance()->setProgress(p.getLabel().c_str(), p.getValue(), p.getMin(), p.getMax()); } - else if(type == "string"){ - onelab::string p; - std::vector<onelab::string> par; get(par, name); - if(par.size() == 1){ - p = par[0]; - onelab::string y; y.fromChar(message); - onelabUtils::updateString(p,y); + else if(ptype == "string"){ + onelab::string p; p.fromChar(message); + if(type == GmshSocket::GMSH_PARAMETER_UPDATE){ + std::vector<onelab::string> par; get(par, name); + if(par.size()){ + onelab::string y = p; p = par[0]; onelabUtils::updateString(p,y); + } } - else - p.fromChar(message); - set(p); + set(p); } - else if(type == "region"){ + else if(ptype == "region"){ onelab::region p; p.fromChar(message); set(p); } - else if(type == "function"){ + else if(ptype == "function"){ onelab::function p; p.fromChar(message); set(p); } else - Msg::Error("Unknown OneLab parameter type: %s", type.c_str()); + Msg::Error("Unknown OneLab parameter type: %s", ptype.c_str()); } break; case GmshSocket::GMSH_PARAMETER_QUERY: { - std::string version, type, name, reply; - onelab::parameter::getInfoFromChar(message, version, type, name); + std::string version, ptype, name, reply; + onelab::parameter::getInfoFromChar(message, version, ptype, name); if(onelab::parameter::version() != version){ Msg::Error("OneLab version mismatch (server: %s / client: %s)", onelab::parameter::version().c_str(), version.c_str()); } - else if(type == "number"){ + else if(ptype == "number"){ std::vector<onelab::number> par; get(par, name); if(par.size() == 1) reply = par[0].toChar(); } - else if(type == "string"){ + else if(ptype == "string"){ std::vector<onelab::string> par; get(par, name); if(par.size() == 1) reply = par[0].toChar(); } - else if(type == "region"){ + else if(ptype == "region"){ std::vector<onelab::region> par; get(par, name); if(par.size() == 1) reply = par[0].toChar(); } - else if(type == "function"){ + else if(ptype == "function"){ std::vector<onelab::function> par; get(par, name); if(par.size() == 1) reply = par[0].toChar(); } else - Msg::Error("Unknown OneLab parameter type in query: %s", type.c_str()); + Msg::Error("Unknown OneLab parameter type in query: %s", ptype.c_str()); if(reply.size()){ getGmshServer()->SendMessage @@ -306,40 +275,40 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master) break; case GmshSocket::GMSH_PARAMETER_QUERY_ALL: { - std::string version, type, name, reply; + std::string version, ptype, name, reply; std::vector<std::string> replies; - onelab::parameter::getInfoFromChar(message, version, type, name); + onelab::parameter::getInfoFromChar(message, version, ptype, name); if(onelab::parameter::version() != version){ Msg::Error("OneLab version mismatch (server: %s / client: %s)", onelab::parameter::version().c_str(), version.c_str()); } - else if(type == "number"){ + else if(ptype == "number"){ std::vector<onelab::number> numbers; get(numbers); for(std::vector<onelab::number>::iterator it = numbers.begin(); it != numbers.end(); it++) replies.push_back((*it).toChar()); } - else if(type == "string"){ + else if(ptype == "string"){ std::vector<onelab::string> strings; get(strings); for(std::vector<onelab::string>::iterator it = strings.begin(); it != strings.end(); it++) replies.push_back((*it).toChar()); } - else if(type == "region"){ + else if(ptype == "region"){ std::vector<onelab::region> regions; get(regions); for(std::vector<onelab::region>::iterator it = regions.begin(); it != regions.end(); it++) replies.push_back((*it).toChar()); } - else if(type == "function"){ + else if(ptype == "function"){ std::vector<onelab::function> functions; get(functions); for(std::vector<onelab::function>::iterator it = functions.begin(); it != functions.end(); it++) replies.push_back((*it).toChar()); } else - Msg::Error("Unknown OneLab parameter type in query: %s", type.c_str()); + Msg::Error("Unknown OneLab parameter type in query: %s", ptype.c_str()); for(unsigned int i = 0; i < replies.size(); i++) getGmshServer()->SendMessage (GmshSocket::GMSH_PARAMETER_QUERY_ALL, replies[i].size(), &replies[i][0]); - reply = "Sent all OneLab " + type + "s"; + reply = "Sent all OneLab " + ptype + "s"; getGmshServer()->SendMessage (GmshSocket::GMSH_PARAMETER_QUERY_END, reply.size(), &reply[0]); }