From f59e7d619ac8d1e18c61bf2688ac9387328a1757 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Sat, 26 May 2012 14:44:17 +0000 Subject: [PATCH] import physical groups as onelab regions --- Common/GmshMessage.cpp | 30 +++++++++++++++++++++++++++++- Common/GmshMessage.h | 1 + Common/OpenFile.cpp | 2 ++ Fltk/onelabWindow.cpp | 28 ---------------------------- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/Common/GmshMessage.cpp b/Common/GmshMessage.cpp index 02feed5553..d6a2b9183b 100644 --- a/Common/GmshMessage.cpp +++ b/Common/GmshMessage.cpp @@ -649,7 +649,7 @@ void Msg::ExchangeOnelabParameter(const std::string &key, std::vector<onelab::number> ps; _onelabClient->get(ps, name); bool noRange = true, noChoices = true, noLoop = true, noGraph = true; - if(ps.size()){ + if(ps.size()){ if(ps[0].getReadOnly()) ps[0].setValue(val[0]); // use value from gmsh else @@ -697,6 +697,34 @@ void Msg::ExchangeOnelabParameter(const std::string &key, #endif } +void Msg::ImportPhysicalsAsOnelabRegions() +{ +#if defined(HAVE_ONELAB) + if(_onelabClient){ + std::map<int, std::vector<GEntity*> > groups[4]; + GModel::current()->getPhysicalGroups(groups); + for(int dim = 0; dim < 3; dim++){ + for(std::map<int, std::vector<GEntity*> >::iterator it = groups[dim].begin(); + it != groups[dim].end(); it++){ + // create "read-only" onelab region + std::string name = GModel::current()->getPhysicalName(dim, it->first); + std::ostringstream num; + num << it->first; + if(name.empty()) + name = std::string("Physical") + + ((dim == 3) ? "Volume" : (dim == 2) ? "Surface" : + (dim == 1) ? "Line" : "Point") + num.str(); + name.insert(0, "Gmsh/Physical groups/"); + onelab::region p(name, num.str()); + p.setDimension(dim); + p.setReadOnly(true); + _onelabClient->set(p); + } + } + } +#endif +} + void Msg::FinalizeOnelab() { #if defined(HAVE_ONELAB) diff --git a/Common/GmshMessage.h b/Common/GmshMessage.h index d6ede43e89..18dafee6d3 100644 --- a/Common/GmshMessage.h +++ b/Common/GmshMessage.h @@ -90,6 +90,7 @@ class Msg { std::vector<double> &val, std::map<std::string, std::vector<double> > &fopt, std::map<std::string, std::vector<std::string> > &copt); + static void ImportPhysicalsAsOnelabRegions(); }; #endif diff --git a/Common/OpenFile.cpp b/Common/OpenFile.cpp index b5d8afd98f..1044a5bc89 100644 --- a/Common/OpenFile.cpp +++ b/Common/OpenFile.cpp @@ -425,6 +425,8 @@ int MergeFile(std::string fileName, bool warnIfMissing) } #endif + Msg::ImportPhysicalsAsOnelabRegions(); + if(!status) Msg::Error("Error loading '%s'", fileName.c_str()); Msg::StatusBar(2, true, "Done reading '%s'", fileName.c_str()); diff --git a/Fltk/onelabWindow.cpp b/Fltk/onelabWindow.cpp index efb98fe20a..6a0ad4b8b0 100644 --- a/Fltk/onelabWindow.cpp +++ b/Fltk/onelabWindow.cpp @@ -673,31 +673,6 @@ static void updateOnelabGraphs() drawContext::global()->draw(); } -static void importPhysicalGroups(onelab::client *c, GModel *m) -{ - std::map<int, std::vector<GEntity*> > groups[4]; - m->getPhysicalGroups(groups); - for(int dim = 0; dim < 3; dim++){ - for(std::map<int, std::vector<GEntity*> >::iterator it = groups[dim].begin(); - it != groups[dim].end(); it++){ - // create "read-only" onelab region - std::string name = m->getPhysicalName(dim, it->first); - std::ostringstream num; - num << it->first; - if(name.empty()) - name = std::string("Physical") + - ((dim == 3) ? "Volume" : (dim == 2) ? "Surface" : - (dim == 1) ? "Line" : "Point") + num.str(); - name.insert(0, "Gmsh/Physical groups/"); - onelab::region p(name, num.str()); - p.setDimension(dim); - p.setReadOnly(true); - //p.setVisible(false); - c->set(p); - } - } -} - static void runGmshClient(const std::string &action) { onelab::server::citer it = onelab::server::instance()->findClient("Gmsh"); @@ -712,7 +687,6 @@ static void runGmshClient(const std::string &action) // first pass is special to prevent model reload, as well as // remeshing if a mesh file already exists on disk modelName = GModel::current()->getName(); - importPhysicalGroups(c, GModel::current()); if(!StatFile(mshFileName)) onelab::server::instance()->setChanged(false, "Gmsh"); } @@ -724,7 +698,6 @@ static void runGmshClient(const std::string &action) // the model name has changed modelName = GModel::current()->getName(); geometry_reload_cb(0, 0); - importPhysicalGroups(c, GModel::current()); } } else if(action == "compute"){ @@ -735,7 +708,6 @@ static void runGmshClient(const std::string &action) // changed modelName = GModel::current()->getName(); geometry_reload_cb(0, 0); - importPhysicalGroups(c, GModel::current()); if(FlGui::instance()->onelab->meshAuto()){ mesh_3d_cb(0, 0); CreateOutputFile(mshFileName, CTX::instance()->mesh.fileFormat); -- GitLab