Salome HOME
updated copyright message
[modules/shaper.git] / src / Selector / Selector_Intersect.cpp
index 5d003a2a98d69723828b5ae22d3abff4f7f744cf..7af473b271be1dacb53cc38cc574fa02360e5d22 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // 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_Intersect.h>
@@ -23,6 +22,8 @@
 #include <Selector_NameGenerator.h>
 #include <Selector_NExplode.h>
 
+#include <Locale_Convert.h>
+
 #include <TNaming_NamedShape.hxx>
 #include <TDataStd_Name.hxx>
 #include <TDataStd_Integer.hxx>
@@ -37,6 +38,7 @@
 Selector_Intersect::Selector_Intersect() : Selector_AlgoWithSubs()
 {
   myWeakIndex = -1; // no index by default
+  myRecomputeWeakIndex = false;
 }
 
 // returns the sub-shapes of theSubType which belong to all theShapes (so, common or intersection)
@@ -63,6 +65,8 @@ static void commonShapes(const TopoDS_ListOfShape& theShapes, TopAbs_ShapeEnum t
 
 bool Selector_Intersect::select(const TopoDS_Shape theContext, const TopoDS_Shape theValue)
 {
+  if (!useIntersections())
+    return false;
   myShapeType = theValue.ShapeType();
   TopAbs_ShapeEnum aSelectionType = myShapeType;
   // try to find the shape of the higher level type in the context shape
@@ -132,7 +136,7 @@ bool Selector_Intersect::select(const TopoDS_Shape theContext, const TopoDS_Shap
       TopoDS_ListOfShape::Iterator anInt(aLastIntersectors);
       for (; anInt.More(); anInt.Next()) {
         Selector_Algo* aSubAlgo = Selector_Algo::select(theContext, anInt.Value(),
-          newSubLabel(), baseDocument(), geometricalNaming(), useNeighbors(), useIntersections());
+          newSubLabel(), baseDocument(), geometricalNaming(), useNeighbors(), false);
         if (!append(aSubAlgo))
           break; // if some selector is failed, stop and search another solution
       }
@@ -166,7 +170,6 @@ bool Selector_Intersect::restore()
     return false;
   myShapeType = TopAbs_ShapeEnum(aShapeTypeAttr->Get());
   // restore sub-selectors
-  bool aSubResult = true;
   for(TDF_ChildIterator aSub(label(), false); aSub.More(); aSub.Next()) {
     Selector_Algo* aSubSel = restoreByLab(aSub.Value(), baseDocument());
     if (!append(aSubSel, false)) {
@@ -180,30 +183,30 @@ bool Selector_Intersect::restore()
   return true;
 }
 
-TDF_Label Selector_Intersect::restoreByName(std::string theName,
+TDF_Label Selector_Intersect::restoreByName(std::wstring theName,
   const TopAbs_ShapeEnum theShapeType, Selector_NameGenerator* theNameGenerator)
 {
   myShapeType = theShapeType;
   TDF_Label aContext;
-  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) {
-      std::string aSubStr = theName.substr(aStart + 1, anEndPos - aStart - 1);
-      if (aSubStr.find(weakNameID()) == 0) { // weak name identifier
-        std::string aWeakIndex = aSubStr.substr(weakNameID().size());
-        myWeakIndex = atoi(aWeakIndex.c_str());
+  for(size_t aStart = 0; aStart != std::wstring::npos; aStart = theName.find(L'[', aStart + 1)) {
+    size_t anEndPos = theName.find(L']', aStart + 1);
+    if (anEndPos != std::wstring::npos) {
+      std::wstring aSubStr = theName.substr(aStart + 1, anEndPos - aStart - 1);
+      size_t aFoundOldWeak = aSubStr.find(oldWeakNameID());
+      size_t aFoundNewWeak = aFoundOldWeak != std::wstring::npos ?
+                             aSubStr.find(weakNameID()) :
+                             aFoundOldWeak;
+      if (aFoundOldWeak == 0 || aFoundNewWeak == 0) { // weak name identifier
+        std::wstring aWeakIndex = aSubStr.substr(aFoundOldWeak + oldWeakNameID().size());
+        myWeakIndex = atoi(Locale::Convert::toString(aWeakIndex).c_str());
+        myRecomputeWeakIndex = aFoundOldWeak == 0;
         continue;
       }
       TopAbs_ShapeEnum aSubShapeType = TopAbs_FACE;
-      if (anEndPos != std::string::npos && anEndPos + 1 < theName.size()) {
-        char aShapeChar = theName[anEndPos + 1];
-        if (theName[anEndPos + 1] != '[') {
+      if (anEndPos != std::wstring::npos && anEndPos + 1 < theName.size()) {
+        wchar_t aShapeChar = theName[anEndPos + 1];
+        if (theName[anEndPos + 1] != L'[') {
           switch(aShapeChar) {
-          case 'c': aSubShapeType = TopAbs_COMPOUND; break;
-          case 'o': aSubShapeType = TopAbs_COMPSOLID; break;
-          case 's': aSubShapeType = TopAbs_SOLID; break;
-          case 'h': aSubShapeType = TopAbs_SHELL; break;
-          case 'w': aSubShapeType = TopAbs_WIRE; break;
           case 'e': aSubShapeType = TopAbs_EDGE; break;
           case 'v': aSubShapeType = TopAbs_VERTEX; break;
           default:;
@@ -212,8 +215,8 @@ TDF_Label Selector_Intersect::restoreByName(std::string theName,
       }
       TDF_Label aSubContext;
       Selector_Algo* aSubSel =
-        Selector_Algo::restoreByName(
-          newSubLabel(), baseDocument(), aSubStr, aSubShapeType, theNameGenerator, aSubContext);
+        Selector_Algo::restoreByName(newSubLabel(), baseDocument(), aSubStr, aSubShapeType,
+          geometricalNaming(), theNameGenerator, aSubContext);
       if (!append(aSubSel))
         return TDF_Label();
 
@@ -249,8 +252,9 @@ bool Selector_Intersect::solve(const TopoDS_Shape& theContext)
   commonShapes(aSubSelectorShapes, myShapeType, aCommon);
   if (aCommon.Extent() != 1) {
     if (myWeakIndex != -1) {
-      Selector_NExplode aNexp(aCommon);
+      Selector_NExplode aNexp(aCommon, myRecomputeWeakIndex);
       aResult = aNexp.shape(myWeakIndex);
+      myRecomputeWeakIndex = false;
     } else if (geometricalNaming() && aCommon.Extent() > 1) {
       // check results are on the same geometry, create compound
       TopoDS_ListOfShape::Iterator aCommonIter(aCommon);
@@ -281,9 +285,9 @@ bool Selector_Intersect::solve(const TopoDS_Shape& theContext)
   return false;
 }
 
-std::string Selector_Intersect::name(Selector_NameGenerator* theNameGenerator)
+std::wstring Selector_Intersect::name(Selector_NameGenerator* theNameGenerator)
 {
-  std::string aResult;
+  std::wstring aResult;
   // add names of sub-components one by one in "[]" +optionally [weak_name_1]
   std::list<Selector_Algo*>::const_iterator aSubSel = list().cbegin();
   for(; aSubSel != list().cend(); aSubSel++) {
@@ -295,20 +299,15 @@ std::string Selector_Intersect::name(Selector_NameGenerator* theNameGenerator)
       TopAbs_ShapeEnum aSubType = aSubVal.ShapeType();
       if (aSubType != TopAbs_FACE) { // in case the sub shape type must be stored
         switch(aSubType) {
-        case TopAbs_COMPOUND: aResult += "c"; break;
-        case TopAbs_COMPSOLID: aResult += "o"; break;
-        case TopAbs_SOLID: aResult += "s"; break;
-        case TopAbs_SHELL: aResult += "h"; break;
-        case TopAbs_WIRE: aResult += "w"; break;
-        case TopAbs_EDGE: aResult += "e"; break;
-        case TopAbs_VERTEX: aResult += "v"; break;
+        case TopAbs_EDGE: aResult += L"e"; break;
+        case TopAbs_VERTEX: aResult += L"v"; break;
         default:;
         }
       }
     }
   }
   if (myWeakIndex != -1) {
-    std::ostringstream aWeakStr;
+    std::wostringstream aWeakStr;
     aWeakStr<<"["<<weakNameID()<<myWeakIndex<<"]";
     aResult += aWeakStr.str();
   }