Salome HOME
Issue #2155 Trim removes multi-rotation constraint, undo leads to wrong DOF
[modules/shaper.git] / src / Model / Model_AttributeSelectionList.cpp
index a6d25f7ad727fa7122b4ab756809b4c1e2d6a730..caaee41f407425e0767de254bfb905c8e4c3f496 100644 (file)
 #include "Model_Events.h"
 #include "Model_Data.h"
 
+#include <GeomAPI_Shape.h>
+
 #include <TDF_AttributeIterator.hxx>
 #include <TDF_ChildIterator.hxx>
 #include <TDF_RelocationTable.hxx>
+#include <TDF_DeltaOnAddition.hxx>
 #include <TopAbs_ShapeEnum.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Shape.hxx>
@@ -20,6 +23,7 @@
 #include <BRep_Tool.hxx>
 #include <TNaming_Builder.hxx>
 #include <TNaming_Iterator.hxx>
+#include <TNaming_NamedShape.hxx>
 #include <NCollection_List.hxx>
 
 void Model_AttributeSelectionList::append(
@@ -45,6 +49,7 @@ void Model_AttributeSelectionList::append(
     std::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aNewLab));
   if (owner()) {
     aNewAttr->setObject(owner());
+    aNewAttr->setParent(this);
   }
   aNewAttr->setID(id());
   mySize->Set(aNewTag);
@@ -66,6 +71,7 @@ void Model_AttributeSelectionList::append(
     std::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aNewLab));
   if (owner()) {
     aNewAttr->setObject(owner());
+    aNewAttr->setParent(this);
   }
   aNewAttr->setID(id());
   mySize->Set(aNewTag);
@@ -155,8 +161,8 @@ static void copyAttrs(TDF_Label theSource, TDF_Label theDestination) {
     // for named shape copy exact shapes (in NamedShape Paste method the CopyTool is used)
     Handle(TNaming_NamedShape) aNS = Handle(TNaming_NamedShape)::DownCast(anAttrIter.Value());
     if (aNS.IsNull()) {
-      // no relocation, empty map
-      Handle(TDF_RelocationTable) aRelocTable = new TDF_RelocationTable();
+      // no special relocation, empty map, but self-relocation is on: copy references w/o changes
+      Handle(TDF_RelocationTable) aRelocTable = new TDF_RelocationTable(Standard_True);
       anAttrIter.Value()->Paste(aTargetAttr, aRelocTable);
     } else {
       CopyNS(aNS, aTargetAttr);
@@ -213,14 +219,15 @@ bool Model_AttributeSelectionList::isInList(const ResultPtr& theContext,
     std::map<ResultPtr, std::list<std::shared_ptr<GeomAPI_Shape> > >::iterator aContext =
       myCash.find(theContext);
     if (aContext != myCash.end()) {
-      // iterate shapes because "isEqual" method must be called for each shape
+      // iterate shapes because "isSame" method must be called for each shape
       std::list<std::shared_ptr<GeomAPI_Shape> >::iterator aShapes = aContext->second.begin();
       for(; aShapes != aContext->second.end(); aShapes++) {
         if (!theSubShape.get()) {
           if (!aShapes->get())
             return true;
         } else {
-          if (theSubShape->isEqual(*aShapes))
+          // we need to call here isSame instead of isEqual to do not check shapes orientation
+          if (theSubShape->isSame(*aShapes))
             return true;
         }
       }
@@ -238,7 +245,8 @@ bool Model_AttributeSelectionList::isInList(const ResultPtr& theContext,
             return true;
           }
         } else {
-          if (aValue->isEqual(theSubShape)) // shapes are equal
+          // we need to call here isSame instead of isEqual to do not check shapes orientation
+          if (aValue->isSame(theSubShape)) // shapes are equal
             return true;
         }
       }
@@ -272,6 +280,7 @@ std::shared_ptr<ModelAPI_AttributeSelection>
   aNewAttr->setID(id());
   if (owner()) {
     aNewAttr->setObject(owner());
+    aNewAttr->setParent(this);
   }
   return aNewAttr;
 }
@@ -288,6 +297,7 @@ void Model_AttributeSelectionList::clear()
         std::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aLab));
       if (owner()) {
         aNewAttr->setObject(owner());
+        aNewAttr->setParent(this);
       }
       REMOVE_BACK_REF(aNewAttr->context());