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

allow to set a Gmsh option just by using its name (same as was done for...

allow to set a Gmsh option just by using its name (same as was done for getting Gmsh options). This allows to simply use e.g.

SetNumber["Geometry.Points", 0];

in GetDP to configure Gmsh. (The old way, i.e., using the "GmshOption" attribute still works, but only triggers option changes when an action is undertaken in the gui)


parent 19fa0c2c
No related branches found
No related tags found
No related merge requests found
...@@ -149,6 +149,56 @@ class onelabGmshServer : public GmshServer{ ...@@ -149,6 +149,56 @@ class onelabGmshServer : public GmshServer{
} }
}; };
static std::string tryToGetGmshNumberOption(const std::string &name)
{
std::string reply;
std::string::size_type dot = name.find('.');
if(dot != std::string::npos){
double val;
if(GmshGetOption(name.substr(0, dot), name.substr(dot + 1), val)){
onelab::number par(name, val);
reply = par.toChar();
}
}
return reply;
}
static std::string tryToGetGmshStringOption(const std::string &name)
{
std::string reply;
std::string::size_type dot = name.find('.');
if(dot != std::string::npos){
std::string val;
if(GmshGetOption(name.substr(0, dot), name.substr(dot + 1), val)){
onelab::string par(name, val);
reply = par.toChar();
}
}
return reply;
}
static bool tryToSetGmshNumberOption(onelab::number &p)
{
std::string name = p.getName();
std::string::size_type dot = name.find('.');
if(dot != std::string::npos){
double val = p.getValue();
return GmshSetOption(name.substr(0, dot), name.substr(dot + 1), val);
}
return false;
}
static bool tryToSetGmshStringOption(onelab::string &p)
{
std::string name = p.getName();
std::string::size_type dot = name.find('.');
if(dot != std::string::npos){
std::string val = p.getValue();
return GmshSetOption(name.substr(0, dot), name.substr(dot + 1), val);
}
return false;
}
bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master) bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master)
{ {
// receive a message on the associated GmshServer; 'master' is only used when // receive a message on the associated GmshServer; 'master' is only used when
...@@ -205,30 +255,34 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master) ...@@ -205,30 +255,34 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master)
} }
else if(ptype == "number"){ else if(ptype == "number"){
onelab::number p; p.fromChar(message); onelab::number p; p.fromChar(message);
if(type == GmshSocket::GMSH_PARAMETER_UPDATE){ if(!tryToSetGmshNumberOption(p)){
std::vector<onelab::number> par; get(par, name); if(type == GmshSocket::GMSH_PARAMETER_UPDATE){
if(par.size()) { std::vector<onelab::number> par; get(par, name);
onelab::number y = p; p = par[0]; onelabUtils::updateNumber(p, y); if(par.size()) {
onelab::number y = p; p = par[0]; onelabUtils::updateNumber(p, y);
}
} }
} set(p);
set(p); if(p.getName() == getName() + "/Progress"){
if(p.getName() == getName() + "/Progress"){
#if defined(HAVE_FLTK) #if defined(HAVE_FLTK)
if(FlGui::available()) if(FlGui::available())
FlGui::instance()->setProgress(p.getLabel().c_str(), p.getValue(), FlGui::instance()->setProgress(p.getLabel().c_str(), p.getValue(),
p.getMin(), p.getMax()); p.getMin(), p.getMax());
#endif #endif
}
} }
} }
else if(ptype == "string"){ else if(ptype == "string"){
onelab::string p; p.fromChar(message); onelab::string p; p.fromChar(message);
if(type == GmshSocket::GMSH_PARAMETER_UPDATE){ if(!tryToSetGmshStringOption(p)){
std::vector<onelab::string> par; get(par, name); if(type == GmshSocket::GMSH_PARAMETER_UPDATE){
if(par.size()){ std::vector<onelab::string> par; get(par, name);
onelab::string y = p; p = par[0]; onelabUtils::updateString(p,y); if(par.size()){
onelab::string y = p; p = par[0]; onelabUtils::updateString(p,y);
}
} }
} set(p);
set(p); }
} }
else else
Msg::Error("Unknown ONELAB parameter type: %s", ptype.c_str()); Msg::Error("Unknown ONELAB parameter type: %s", ptype.c_str());
...@@ -244,39 +298,17 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master) ...@@ -244,39 +298,17 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master)
} }
else if(ptype == "number"){ else if(ptype == "number"){
std::vector<onelab::number> par; get(par, name); std::vector<onelab::number> par; get(par, name);
if(par.empty()){ // try to see if it's not a Gmsh option if(par.empty())
std::string::size_type dot = name.find('.'); reply = tryToGetGmshNumberOption(name);
if(dot != std::string::npos){ else
double val;
if(GmshGetOption(name.substr(0, dot), name.substr(dot + 1), val)){
par.resize(1);
par[0].setName(name);
par[0].setValue(val);
reply = par[0].toChar();
}
}
}
else{
reply = par[0].toChar(); reply = par[0].toChar();
}
} }
else if(ptype == "string"){ else if(ptype == "string"){
std::vector<onelab::string> par; get(par, name); std::vector<onelab::string> par; get(par, name);
if(par.empty()){ // try to see if it's not a Gmsh option if(par.empty())
std::string::size_type dot = name.find('.'); reply = tryToGetGmshStringOption(name);
if(dot != std::string::npos){ else
std::string val;
if(GmshGetOption(name.substr(0, dot), name.substr(dot + 1), val)){
par.resize(1);
par[0].setName(name);
par[0].setValue(val);
reply = par[0].toChar();
}
}
}
else{
reply = par[0].toChar(); reply = par[0].toChar();
}
} }
else else
Msg::Error("Unknown ONELAB parameter type in query: %s", ptype.c_str()); Msg::Error("Unknown ONELAB parameter type in query: %s", ptype.c_str());
......
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