From 9c8fac88f4027cf43b4d579013a6a1604d17190e Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Tue, 2 Feb 2016 19:28:31 +0000 Subject: [PATCH] better export of physical groups to onelab --- Common/GmshMessage.cpp | 54 ++++++++++++++++++++++++++++++------------ Common/GmshMessage.h | 2 +- Common/OpenFile.cpp | 5 ++-- Fltk/graphicWindow.cpp | 2 ++ 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/Common/GmshMessage.cpp b/Common/GmshMessage.cpp index f8a0b6d6dc..9939ac2931 100644 --- a/Common/GmshMessage.cpp +++ b/Common/GmshMessage.cpp @@ -1255,30 +1255,54 @@ void Msg::UndefineOnelabParameter(const std::string &name) #endif } -void Msg::ImportPhysicalsAsOnelabRegions() +void Msg::ImportPhysicalGroupsInOnelab() { #if defined(HAVE_ONELAB) if(_onelabClient){ std::map<int, std::vector<GEntity*> > groups[4]; GModel::current()->getPhysicalGroups(groups); + int size = 0; + for(int dim = 0; dim <= 3; dim++) + size += groups[dim].size(); + onelab::number n("Gmsh/Number of physical groups", size); + n.setReadOnly(true); + n.setVisible(false); + n.setAttribute("Closed", "1"); + _onelabClient->set(n); + + onelab::number nd("Gmsh/Model dimension", GModel::current()->getDim()); + nd.setReadOnly(true); + nd.setVisible(false); + nd.setAttribute("Closed", "1"); + _onelabClient->set(nd); + + int index = 1; 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 + int num = it->first; 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); - p.setVisible(false); - p.setAttribute("Closed", "1"); - _onelabClient->set(p); + char tmp[256]; + if(name.empty()){ + sprintf(tmp, "Physical %s %d", (dim == 3) ? "Volume " : (dim == 2) ? "Surface " : + (dim == 1) ? "Line " : "Point ", num); + name = tmp; + } + sprintf(tmp, "Gmsh/Physical group %d/", index); + std::string str = tmp; + onelab::number n1(str + "Dimension", dim); + n1.setReadOnly(true); + n1.setVisible(false); + _onelabClient->set(n1); + onelab::number n2(str + "Number", num); + n2.setReadOnly(true); + n2.setVisible(false); + _onelabClient->set(n2); + onelab::string s(str + "Name", name); + s.setReadOnly(true); + s.setVisible(false); + _onelabClient->set(s); + index++; } } } diff --git a/Common/GmshMessage.h b/Common/GmshMessage.h index bf6504b60c..8d209e1bcb 100644 --- a/Common/GmshMessage.h +++ b/Common/GmshMessage.h @@ -146,7 +146,7 @@ class Msg { std::map<std::string, std::vector<std::string> > &copt); static void UndefineOnelabParameter(const std::string &name); static void RunOnelabClient(const std::string &name, const std::string &exe=""); - static void ImportPhysicalsAsOnelabRegions(); + static void ImportPhysicalGroupsInOnelab(); }; #endif diff --git a/Common/OpenFile.cpp b/Common/OpenFile.cpp index cdbe0a1a71..b01ed4e917 100644 --- a/Common/OpenFile.cpp +++ b/Common/OpenFile.cpp @@ -361,7 +361,6 @@ int MergeFile(const std::string &fileName, bool warnIfMissing, bool setWindowTit CTX::instance()->launchSolverAtStartup = num; CTX::instance()->solverToRun = num; // used in ONELAB2 return 1; - } else if(ext == ".py" || ext == ".PY" || ext == ".m" || ext == ".M" || @@ -518,6 +517,8 @@ int MergeFile(const std::string &fileName, bool warnIfMissing, bool setWindowTit CTX::instance()->geom.draw = 1; CTX::instance()->mesh.changed = ENT_ALL; + Msg::ImportPhysicalGroupsInOnelab(); + #if defined(HAVE_FLTK) && defined(HAVE_POST) if(FlGui::available()){ // go directly to the first non-empty step after the one that is requested @@ -529,8 +530,6 @@ int MergeFile(const std::string &fileName, bool warnIfMissing, bool setWindowTit } #endif - Msg::ImportPhysicalsAsOnelabRegions(); - if(!status) Msg::Error("Error loading '%s'", fileName.c_str()); Msg::StatusBar(true, "Done reading '%s'", fileName.c_str()); diff --git a/Fltk/graphicWindow.cpp b/Fltk/graphicWindow.cpp index c2c7146a92..ca249f1135 100644 --- a/Fltk/graphicWindow.cpp +++ b/Fltk/graphicWindow.cpp @@ -1326,6 +1326,8 @@ static void action_point_line_surface_volume(int action, int mode, const char *w FlGui::instance()->physicalContext->append, FlGui::instance()->physicalContext->mode); FlGui::instance()->physicalContext->show(action == 7 ? false : true); + // ask clients to update the tree using the new physical definition + onelab_cb(0, (void*)"check"); break; case 8: add_charlength(List1, GModel::current()->getFileName(), -- GitLab