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{
}
};
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)
{
// receive a message on the associated GmshServer; 'master' is only used when
......@@ -205,6 +255,7 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master)
}
else if(ptype == "number"){
onelab::number p; p.fromChar(message);
if(!tryToSetGmshNumberOption(p)){
if(type == GmshSocket::GMSH_PARAMETER_UPDATE){
std::vector<onelab::number> par; get(par, name);
if(par.size()) {
......@@ -220,8 +271,10 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master)
#endif
}
}
}
else if(ptype == "string"){
onelab::string p; p.fromChar(message);
if(!tryToSetGmshStringOption(p)){
if(type == GmshSocket::GMSH_PARAMETER_UPDATE){
std::vector<onelab::string> par; get(par, name);
if(par.size()){
......@@ -230,6 +283,7 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master)
}
set(p);
}
}
else
Msg::Error("Unknown ONELAB parameter type: %s", ptype.c_str());
}
......@@ -244,40 +298,18 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master)
}
else if(ptype == "number"){
std::vector<onelab::number> par; get(par, name);
if(par.empty()){ // try to see if it's not a Gmsh option
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)){
par.resize(1);
par[0].setName(name);
par[0].setValue(val);
reply = par[0].toChar();
}
}
}
else{
if(par.empty())
reply = tryToGetGmshNumberOption(name);
else
reply = par[0].toChar();
}
}
else if(ptype == "string"){
std::vector<onelab::string> par; get(par, name);
if(par.empty()){ // try to see if it's not a Gmsh option
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)){
par.resize(1);
par[0].setName(name);
par[0].setValue(val);
reply = par[0].toChar();
}
}
}
else{
if(par.empty())
reply = tryToGetGmshStringOption(name);
else
reply = par[0].toChar();
}
}
else
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.
Please register or to comment