From d8cd2ffe86b8c1bd9b77183c9746cf89adec2d90 Mon Sep 17 00:00:00 2001 From: Francois Henrotte <francois.henrotte@ulg.ac.be> Date: Fri, 23 Nov 2012 17:11:13 +0000 Subject: [PATCH] --- contrib/onelab/Makefile | 6 ++++++ contrib/onelab/OnelabClients.cpp | 6 ++++-- contrib/onelab/OnelabParser.cpp | 16 ++++++++++------ contrib/onelab/loader.cpp | 19 ------------------- contrib/onelab/metamodel.cpp | 24 ++++++++++++++++++++++++ contrib/onelab/metamodel.h | 8 ++++++++ 6 files changed, 52 insertions(+), 27 deletions(-) diff --git a/contrib/onelab/Makefile b/contrib/onelab/Makefile index 8d780dae8e..0079571bdf 100644 --- a/contrib/onelab/Makefile +++ b/contrib/onelab/Makefile @@ -4,6 +4,7 @@ SOURCES=myOS StringUtils mathex OnelabClients OnelabMessage OnelabParser metamod COMMON_DIR=$(GMSH_DIR)/Common ONELAB_DIR=$(GMSH_DIR)/contrib/onelab MATHEX_DIR=$(GMSH_DIR)/contrib/MathEx +CPPFLAGS+= $(shell python-config --includes) -fPIC OBJDIR=objects @@ -52,4 +53,9 @@ $(OBJDIR)/%.o : %.cpp $(ONELAB_DIR)/*.h clean : $(RM) $(TARGETS) $(OBJDIR)/*.o +onelab_wrap.cpp : onelab.i + swig -python -c++ -o $@ $< + +_onelab.so : $(OBJECTS) $(OBJDIR)/onelab_wrap.o + $(CXX) -bundle -flat_namespace -undefined suppress $(OBJECTS) $(OBJDIR)/onelab_wrap.o -o _onelab.so .PRECIOUS: $(OBJDIR)/%.o diff --git a/contrib/onelab/OnelabClients.cpp b/contrib/onelab/OnelabClients.cpp index 8284666cf6..9255ddb3ae 100644 --- a/contrib/onelab/OnelabClients.cpp +++ b/contrib/onelab/OnelabClients.cpp @@ -468,7 +468,7 @@ bool localSolverClient::buildRmCommand(std::string &cmd){ split = SplitOLFileName(choices[i]); cmd.append(split[1] + " "); } - return true; + if(choices.size()) return true; } return false; } @@ -1206,7 +1206,8 @@ std::string ftoa(const double x){ int mySystem(std::string commandLine){ //Don't use OLMsg::Info here otherwise the message appears twice //in the Gmsh message window. - std::cout << "Onelab: Calling <" << commandLine << ">" << std::endl; + if(OLMsg::GetVerbosity()) + std::cout << "Onelab: Calling <" << commandLine << ">" << std::endl; return SystemCall(commandLine.c_str(), true); } @@ -1269,6 +1270,7 @@ std::string quote(const std::string &in){ } std::string unquote(const std::string &in) { + if(in.empty()) return ""; size_t pos0=in.find_first_not_of(" "); size_t pos=in.find_last_not_of(" "); if( (pos0 != std::string::npos) && (!in.compare(pos0,1,"\""))) diff --git a/contrib/onelab/OnelabParser.cpp b/contrib/onelab/OnelabParser.cpp index ffe4291c0f..d7fd7ff5af 100644 --- a/contrib/onelab/OnelabParser.cpp +++ b/contrib/onelab/OnelabParser.cpp @@ -107,7 +107,7 @@ void MetaModel::saveCommandLines(){ } } else - OLMsg::Error("The file <%s> cannot be opened",fileName.c_str()); + OLMsg::Warning("The file <%s> cannot be opened",fileName.c_str()); infile.close(); //save client command lines @@ -623,8 +623,10 @@ void localSolverClient::parse_sentence(std::string line) { else OLMsg::Error("Wrong number of arguments for range <%s>", name.c_str()); + set(numbers[0]); } - set(numbers[0]); + else + OLMsg::Error("The parameter <%s> does not exist",name.c_str()); } } else if(!action.compare("withinRange")){ @@ -640,6 +642,8 @@ void localSolverClient::parse_sentence(std::string line) { numbers[0].setValue(numbers[0].getMax()); set(numbers[0]); } + else + OLMsg::Error("The parameter <%s> does not exist",name.c_str()); } else if(!action.compare("setValue")){ // a set request together with a setReadOnly(1) forces @@ -662,9 +666,8 @@ void localSolverClient::parse_sentence(std::string line) { strings[0].setReadOnly(1); set(strings[0]); } - else{ + else OLMsg::Error("The parameter <%s> does not exist",name.c_str()); - } } } else if(!action.compare("resetChoices")){ @@ -1586,7 +1589,8 @@ void MetaModel::client_sentence(const std::string &name, bool changed = onelab::server::instance()->getChanged(c->getName()); bool started = isStarted(changed); - std::cout << c->getName() << " active=" << c->getActive() << " changed=" << changed << " started=" << started << " errors=" << OLMsg::GetErrorCount() << std::endl; + if(OLMsg::GetVerbosity()) + std::cout << c->getName() << " active=" << c->getActive() << " changed=" << changed << " started=" << started << " errors=" << OLMsg::GetErrorCount() << std::endl; if(started) c->compute(); } } @@ -1638,7 +1642,7 @@ void MetaModel::client_sentence(const std::string &name, } } else if(!action.compare("merge")){ - if(isTodo(COMPUTE) && !OLMsg::GetErrorCount()){ + if(isTodo(COMPUTE) && !OLMsg::GetErrorCount() && (OLMsg::hasGmsh)){ std::vector<std::string> choices; for(unsigned int i = 0; i < arguments.size(); i++){ choices.push_back(resolveGetVal(arguments[i])); diff --git a/contrib/onelab/loader.cpp b/contrib/onelab/loader.cpp index c8cfacc16b..9ac1123599 100644 --- a/contrib/onelab/loader.cpp +++ b/contrib/onelab/loader.cpp @@ -1,5 +1,4 @@ #include "StringUtils.h" -//#include "onelabUtils.h" #include "OnelabClients.h" #include "metamodel.h" #include <algorithm> @@ -141,24 +140,6 @@ std::string showClientStatus(){ return sstream.str(); } -bool setParameter(const std::string &name, const std::string &value){ - std::vector<onelab::number> numbers; - std::vector<onelab::string> strings; - onelab::server::instance()->get(numbers,name); - if (numbers.size()) { - numbers[0].setValue(atof(value.c_str())); - return onelab::server::instance()->set(numbers[0]); - } - else{ - onelab::server::instance()->get(strings,name); - if (strings.size()) { - strings[0].setValue(value); - return onelab::server::instance()->set(strings[0]); - } - else - OLMsg::Error("The parameter <%s> does not exist", name.c_str()); - } -} bool menu() { int choice, counter1=0, counter2=0; diff --git a/contrib/onelab/metamodel.cpp b/contrib/onelab/metamodel.cpp index 7869dc7569..71fb77e8f3 100644 --- a/contrib/onelab/metamodel.cpp +++ b/contrib/onelab/metamodel.cpp @@ -1,6 +1,30 @@ #include "OnelabClients.h" #include "metamodel.h" +/* PYTHON functions */ + +void modelName(const std::string &name, const std::string &wdir=""){ + OLMsg::InitializeOnelab("onelab"); + OLMsg::SetOnelabString("Arguments/FileName",name); + OLMsg::SetOnelabString("Arguments/WorkingDir",wdir); + OLMsg::SetVerbosity(0); +} + +void setNumber(const std::string &name, const double value){ + OLMsg::SetOnelabNumber(name, value); +} +void setString(const std::string &name, const std::string &value){ + OLMsg::SetOnelabString(name, value); +} +double getNumber(const std::string &name){ + return OLMsg::GetOnelabNumber(name); +} +std::string getString(const std::string &name){ + return OLMsg::GetOnelabString(name); +} + + +/* Interface Gmsh - Metamodels */ void initializeMetamodel(const std::string &loaderName, onelab::client *olclient, void (*gui_wait_fct)(double time)) { diff --git a/contrib/onelab/metamodel.h b/contrib/onelab/metamodel.h index b98354e5f1..701f3368f0 100644 --- a/contrib/onelab/metamodel.h +++ b/contrib/onelab/metamodel.h @@ -9,3 +9,11 @@ namespace onelab{ class client; } int metamodel(const std::string &todo); void initializeMetamodel(const std::string &, onelab::client *, void (*wait)(double time)); + +/* PYTHON functions */ + +void modelName(const std::string &name, const std::string &wdir); +void setNumber(const std::string &name, const double value); +void setString(const std::string &name, const std::string &value); +double getNumber(const std::string &name); +std::string getString(const std::string &name); -- GitLab