Salome HOME
Fix the problem of the sketch plane update
[modules/shaper.git] / src / Model / Model_ResultConstruction.cpp
index 6dc346aa0d27bdc5a8dd6da55b90db06609b2467..272cb7338a24527bc298cd3b8807e42d9544fce8 100644 (file)
@@ -55,7 +55,6 @@ Standard_GUID kIS_INFINITE("dea8cc5a-53f2-49c1-94e8-a947bed20a9f");
 // identifier of the result not in history
 Standard_GUID kIS_IN_HISTORY("a9aec01c-805e-44d1-b5d2-a63f06522f8a");
 
-
 void Model_ResultConstruction::colorConfigInfo(std::string& theSection, std::string& theName,
                                        std::string& theDefault)
 {
@@ -67,8 +66,7 @@ void Model_ResultConstruction::colorConfigInfo(std::string& theSection, std::str
 void Model_ResultConstruction::setShape(std::shared_ptr<GeomAPI_Shape> theShape)
 {
   if (myShape != theShape) {
-    if (!isInfinite())
-      storeShape(theShape);
+    storeShape(theShape);
     if (!theShape.get() || !theShape->isEqual(myShape)) {
       static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
       ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), anEvent);
@@ -238,7 +236,7 @@ void Model_ResultConstruction::storeShape(std::shared_ptr<GeomAPI_Shape> theShap
     std::shared_ptr<Model_Document> aMyDoc =
       std::dynamic_pointer_cast<Model_Document>(document());
     const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
-    if (aShape.ShapeType() == TopAbs_VERTEX) {
+    if (isInfinite() || aShape.ShapeType() == TopAbs_VERTEX) {
       aShapeLab.ForgetAllAttributes(); // clear all previously stored
       TNaming_Builder aBuilder(aShapeLab);
       aBuilder.Generated(aShape);
@@ -255,15 +253,6 @@ void Model_ResultConstruction::storeShape(std::shared_ptr<GeomAPI_Shape> theShap
         TNaming_Builder aBuilder(aSubLab);
         aBuilder.Generated(anExp.Current());
         std::string aVertexName = aMyName + "_" + (anIndex == 1 ? "StartVertex" : "EndVertex");
-        // check this name is already used
-        ResultPtr aThisRes;
-        do {
-          static std::string anEmpty;
-          static bool aUnique;
-          aThisRes = aMyDoc->findByName(aVertexName, anEmpty, aUnique);
-          if (aThisRes.get() && aThisRes.get() != this)
-            aVertexName += "x";
-        } while(aThisRes.get() && aThisRes.get() != this);
         TDataStd_Name::Set(aSubLab, aVertexName.c_str());
         aMyDoc->addNamingName(aSubLab, aVertexName);
       }
@@ -406,7 +395,7 @@ void Model_ResultConstruction::storeShape(std::shared_ptr<GeomAPI_Shape> theShap
           std::stringstream aName;
           aName<<"Face";
           TopExp_Explorer aPutEdges(aFaceToPut, TopAbs_EDGE);
-          TNaming_Builder* anEdgesBuilder = 0;
+          TNaming_Builder *anEdgesBuilder = 0, *aVerticesBuilder = 0;
           for(TColStd_ListOfInteger::Iterator anIter(aNewInd); anIter.More(); anIter.Next()) {
             int anIndex = anIter.Value();
             int aModIndex = anIndex > 0 ? anIndex : -anIndex;
@@ -429,20 +418,43 @@ void Model_ResultConstruction::storeShape(std::shared_ptr<GeomAPI_Shape> theShap
               }
               anEdgesBuilder->Modify(anEdgeIndices.Find(aModIndex), aPutEdges.Current());
             }
+            // put also modified vertices, otherwise vertex of original edge has no history
+            if (anEdgeIndices.IsBound(aModIndex)) {
+              TopExp_Explorer aVExpOld(anEdgeIndices.Find(aModIndex), TopAbs_VERTEX);
+              TopExp_Explorer aVExpNew(aPutEdges.Current(), TopAbs_VERTEX);
+              for(; aVExpNew.More() && aVExpOld.More(); aVExpNew.Next(), aVExpOld.Next()) {
+                if (!aVExpOld.Current().IsSame(aVExpNew.Current())) {
+                  if (!aVerticesBuilder) {
+                    TDF_Label aVertLabel = aLab.FindChild(2);
+                    aVerticesBuilder = new TNaming_Builder(aVertLabel);
+                    std::ostringstream aSubName;
+                    // tag is needed for Test1922 to distinguish sub-edges of different faces
+                    aSubName<<"SubVertex_"<<aCurrentTag;
+                    TDataStd_Name::Set(aVertLabel, aSubName.str().c_str());
+                  }
+                  aVerticesBuilder->Modify(aVExpOld.Current(), aVExpNew.Current());
+
+                }
+              }
+            }
             aPutEdges.Next();
           }
+          if (anEdgesBuilder)
+            delete anEdgesBuilder;
+          if (aVerticesBuilder)
+            delete aVerticesBuilder;
           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
+          int aWireTag = 3; // first tag is for SubEdge-s, second - for vertices
           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;
+            if (aWireTag > 3)
+              aWireName<<"_"<<aWireTag - 2;
             TDataStd_Name::Set(aWireLab, aWireName.str().c_str());
             aMyDoc->addNamingName(aWireLab, aWireName.str());
             aWireTag++;