Salome HOME
Merge remote-tracking branch 'remotes/origin/EDF_2020_Lot2'
[modules/shaper.git] / src / Selector / Selector_Intersect.cpp
index 07671e2f61305b4ea9e9a640ab0e4ed932b242e7..1aee58ea1e35dda1d201a865b62c59df51efab55 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2020  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
@@ -22,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>
@@ -36,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)
@@ -167,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)) {
@@ -186,19 +188,24 @@ TDF_Label Selector_Intersect::restoreByName(std::wstring theName,
 {
   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) {
+  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);
-      if (aSubStr.find(weakNameID()) == 0) { // weak name identifier
-        std::wstring aWeakIndex = aSubStr.substr(weakNameID().size());
-        myWeakIndex = stoi(aWeakIndex);
+      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()) {
+      if (anEndPos != std::wstring::npos && anEndPos + 1 < theName.size()) {
         wchar_t aShapeChar = theName[anEndPos + 1];
-        if (theName[anEndPos + 1] != '[') {
+        if (theName[anEndPos + 1] != L'[') {
           switch(aShapeChar) {
           case 'e': aSubShapeType = TopAbs_EDGE; break;
           case 'v': aSubShapeType = TopAbs_VERTEX; break;
@@ -245,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);