Salome HOME
Fix for creation in GUI and unit-test for the issue #2681
[modules/shaper.git] / src / Model / Model_ResultConstruction.cpp
index 6ad810f2e6dd5c1f0d3f85c714515b40fa1e9ca8..103c5425904bf65d8e8bb299ee2a43c6f5bda36b 100644 (file)
@@ -42,6 +42,7 @@
 #include <TopoDS_ListOfShape.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopTools_MapOfShape.hxx>
+#include <NCollection_IndexedDataMap.hxx>
 
 #include <algorithm>
 
@@ -275,14 +276,15 @@ void Model_ResultConstruction::storeShape(std::shared_ptr<GeomAPI_Shape> theShap
       std::list<std::shared_ptr<GeomAPI_Shape> > aFaces;
       GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(),
         aWirePtr->norm(), aWirePtr, aFaces);
-      NCollection_DataMap<TopoDS_Face, TColStd_ListOfInteger> aNewIndices; // edges indices
+      // order is important to store faces in the same order if sketch is created from scratch
+      NCollection_IndexedDataMap<TopoDS_Face, TColStd_ListOfInteger> aNewIndices; // edges indices
       std::list<std::shared_ptr<GeomAPI_Shape> >::iterator aFIter = aFaces.begin();
       for (; aFIter != aFaces.end(); aFIter++) {
         std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(*aFIter));
         // put them to a label, trying to keep the same faces on the same labels
         if (aFace.get() && !aFace->isNull()) {
           TopoDS_Face aTopoFace = TopoDS::Face(aFace->impl<TopoDS_Shape>());
-          aNewIndices.Bind(aTopoFace, TColStd_ListOfInteger());
+          aNewIndices.Add(aTopoFace, TColStd_ListOfInteger());
           // keep new indices of sub-elements used in this face
           for (TopExp_Explorer anEdges(aTopoFace, TopAbs_EDGE); anEdges.More(); anEdges.Next()) {
             TopoDS_Edge anEdge = TopoDS::Edge(anEdges.Current());
@@ -292,7 +294,7 @@ void Model_ResultConstruction::storeShape(std::shared_ptr<GeomAPI_Shape> theShap
               int anIndex = aCurvesIndices.Find(aCurve);
               if ((aFirst > aLast) != (anEdge.Orientation() == TopAbs_REVERSED))
                 anIndex = -anIndex;
-              aNewIndices.ChangeFind(aTopoFace).Append(anIndex);
+              aNewIndices.ChangeFromKey(aTopoFace).Append(anIndex);
             }
           }
         }
@@ -300,7 +302,8 @@ void Model_ResultConstruction::storeShape(std::shared_ptr<GeomAPI_Shape> theShap
       NCollection_DataMap<int, TopoDS_Face> aFacesOrder; // faces -> tag where they must be set
       NCollection_List<TopoDS_Face> anUnorderedFaces; // faces that may be located at any index
       // searching for the best new candidate to old location
-      NCollection_DataMap<TopoDS_Face, TColStd_ListOfInteger>::Iterator aNewIter(aNewIndices);
+      NCollection_IndexedDataMap<TopoDS_Face, TColStd_ListOfInteger>::Iterator
+        aNewIter(aNewIndices);
       for (; aNewIter.More(); aNewIter.Next()) {
         double aBestFound = 0, aBestNotFound = 1.e+100;
         int aBestTag = 0;
@@ -369,7 +372,7 @@ void Model_ResultConstruction::storeShape(std::shared_ptr<GeomAPI_Shape> theShap
           aFaceBuilder.Generated(aFaceToPut);
           // store also indices of the new face edges
           Handle(TDataStd_IntPackedMap) aNewMap = TDataStd_IntPackedMap::Set(aLab);
-          const TColStd_ListOfInteger& aNewInd = aNewIndices.Find(aFaceToPut);
+          const TColStd_ListOfInteger& aNewInd = aNewIndices.FindFromKey(aFaceToPut);
           std::stringstream aName;
           aName<<"Face";
           TopExp_Explorer aPutEdges(aFaceToPut, TopAbs_EDGE);
@@ -389,7 +392,10 @@ void Model_ResultConstruction::storeShape(std::shared_ptr<GeomAPI_Shape> theShap
               if (!anEdgesBuilder) {
                 TDF_Label anEdgesLabel = aLab.FindChild(1);
                 anEdgesBuilder = new TNaming_Builder(anEdgesLabel);
-                TDataStd_Name::Set(anEdgesLabel, "SubEdge");
+                std::ostringstream aSubName;
+                // tag is needed for Test1922 to distinguish subedges of different faces
+                aSubName<<"SubEdge_"<<aCurrentTag;
+                TDataStd_Name::Set(anEdgesLabel, aSubName.str().c_str());
               }
               anEdgesBuilder->Modify(anEdgeIndices.Find(aModIndex), aPutEdges.Current());
             }
@@ -397,6 +403,20 @@ void Model_ResultConstruction::storeShape(std::shared_ptr<GeomAPI_Shape> theShap
           }
           TDataStd_Name::Set(aLab, TCollection_ExtendedString(aName.str().c_str()));
           aMyDoc->addNamingName(aLab, aName.str());
+          // put also wires to sub-labels to correctly select them instead of collection by edges
+          int aWireTag = 2; // first tag is for SubEdge-s
+          for(TopExp_Explorer aWires(aFaceToPut, TopAbs_WIRE); aWires.More(); aWires.Next()) {
+            TDF_Label aWireLab = aLab.FindChild(aWireTag);
+            TNaming_Builder aWireBuilder(aWireLab);
+            aWireBuilder.Generated(aWires.Current());
+            std::ostringstream aWireName;
+            aWireName<<aName.str()<<"_wire";
+            if (aWireTag > 2)
+              aWireName<<"_"<<aWireTag - 1;
+            TDataStd_Name::Set(aWireLab, aWireName.str().c_str());
+            aMyDoc->addNamingName(aWireLab, aWireName.str());
+            aWireTag++;
+          }
         }
       }
     }