Salome HOME
Make SHAPER STUDY fields exported in SMESH into MED file
[modules/shaper.git] / src / Selector / Selector_Container.cpp
index 32d7134ee937b0a0b0505c54bb9ba3ab3d9b2523..44d1b1e92d4c75f4d481ad629125afc2d89673cd 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include <Selector_Container.h>
@@ -73,7 +72,7 @@ bool Selector_Container::restore()
   // restore sub-selectors
   bool aSubResult = true;
   for(TDF_ChildIterator aSub(label(), false); aSub.More(); aSub.Next()) {
-    Selector_Algo* aSubSel = restoreByLab(aSub.Value());
+    Selector_Algo* aSubSel = restoreByLab(aSub.Value(), baseDocument());
     if (!append(aSubSel, false)) {
       break; // some empty label left in the end
     }
@@ -89,6 +88,17 @@ TDF_Label Selector_Container::restoreByName(std::string theName,
   for(size_t aStart = 0; aStart != std::string::npos; aStart = theName.find('[', aStart + 1)) {
     size_t anEndPos = theName.find(']', aStart + 1);
     if (anEndPos != std::string::npos) {
+      // there could be sub-intersections, so, [[...]] case; searching for other open-bracket
+      size_t aNextStart = theName.find('[', aStart + 1);
+      while(aNextStart != std::string::npos && aNextStart < anEndPos) {
+        anEndPos = theName.find(']', anEndPos + 1);
+        if (anEndPos == std::string::npos) {
+          return TDF_Label(); // invalid parentheses
+        }
+        aNextStart = theName.find('[', aNextStart + 1);
+      }
+      if (anEndPos == std::string::npos)
+        return TDF_Label(); // invalid parentheses
       std::string aSubStr = theName.substr(aStart + 1, anEndPos - aStart - 1);
       TopAbs_ShapeEnum aSubShapeType = TopAbs_FACE;
       switch (myShapeType) {
@@ -98,8 +108,8 @@ TDF_Label Selector_Container::restoreByName(std::string theName,
       }
       TDF_Label aSubContext;
       Selector_Algo* aSubSel =
-        Selector_Algo::restoreByName(
-          label(), baseDocument(), aSubStr, aSubShapeType, theNameGenerator, aSubContext);
+        Selector_Algo::restoreByName(newSubLabel(), baseDocument(), aSubStr, aSubShapeType,
+          geometricalNaming(), theNameGenerator, aSubContext);
       if (!append(aSubSel))
         return TDF_Label();
 
@@ -116,6 +126,7 @@ TDF_Label Selector_Container::restoreByName(std::string theName,
       }
     } else
       return TDF_Label(); // invalid parentheses
+    aStart = anEndPos; // for recursive parenthesis set start on the current end
   }
   return aContext;
 }