Salome HOME
Fix for the issue #19726 : Placement failed because of wrong name in face selection.
authormpv <mikhail.ponikarov@opencascade.com>
Wed, 24 Jun 2020 14:09:56 +0000 (17:09 +0300)
committervsr <vsr@opencascade.com>
Fri, 3 Jul 2020 15:42:45 +0000 (18:42 +0300)
Call update in history of attribute created for the external part selection.

src/Model/Model_AttributeSelection.h
src/Model/Model_Objects.cpp
src/Model/Model_ResultPart.cpp
src/Model/Model_Update.cpp
src/ModelAPI/CMakeLists.txt
src/ModelAPI/ModelAPI_AttributeSelection.h
src/ModelAPI/Test/Test19726.py [new file with mode: 0644]

index 193f2d1dde31ebe410a0ab1c243a69aae5cb9362..3ee60386a8aeb4026a47ea5caf404b0a052b863f 100644 (file)
@@ -122,7 +122,7 @@ public:
   /// Updates the arguments of selection if something was affected by creation
   /// or reorder of features upper in the history line (issue #1757)
   /// Returns theRemove true if this attribute must be removed (become deleted)
-  MODEL_EXPORT virtual void updateInHistory(bool& theRemove);
+  MODEL_EXPORT virtual void updateInHistory(bool& theRemove) override;
 
   // Implementation of the name generator method from the Selector package
   // This method returns the context name by the label of the sub-selected shape
index 69955315d99dfaa6886197997d7697067b2064a0..ce23976c3b7feae52fde59411bc1d9e5a8c4e5d8 100644 (file)
@@ -2028,6 +2028,8 @@ FeaturePtr Model_Objects::lastFeature()
 
 bool Model_Objects::isLater(FeaturePtr theLater, FeaturePtr theCurrent) const
 {
+  if (theLater->getKind() == "InternalSelectionInPartFeature")
+    return true;
   std::shared_ptr<Model_Data> aLaterD = std::static_pointer_cast<Model_Data>(theLater->data());
   std::shared_ptr<Model_Data> aCurrentD = std::static_pointer_cast<Model_Data>(theCurrent->data());
   if (aLaterD.get() && aLaterD->isValid() && aCurrentD.get() && aCurrentD->isValid()) {
index 044893237ec599e8bef4d356bc5b6b0f19da9d8c..3c52f0986756e0152b4e7d4a6f0cc0802bb0d4f6 100644 (file)
@@ -327,7 +327,11 @@ bool Model_ResultPart::updateInPart(const int theIndex)
     AttributeSelectionListPtr aSelAttr = aDoc->selectionInPartFeature();
     AttributeSelectionPtr aThisAttr = aSelAttr->value(theIndex - 1);
     if (aThisAttr.get()) {
-      return aThisAttr->update();
+      if (aThisAttr->update()) {
+        bool aRemove = false;
+        aThisAttr->updateInHistory(aRemove);
+        return true; // it was updated
+      }
     }
   }
   return false; // something is wrong
index 4deb924bf578992afe002dd7b8853f0a90a3aa45..a2bcdfacbcbb937ed1e2792b68c20157071532f5 100644 (file)
@@ -21,7 +21,6 @@
 #include <Model_Document.h>
 #include <Model_Data.h>
 #include <Model_Objects.h>
-#include <Model_AttributeSelection.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
@@ -1087,8 +1086,8 @@ void Model_Update::updateSelection(const std::set<std::shared_ptr<ModelAPI_Objec
       (*anObj)->data()->attributes(ModelAPI_AttributeSelection::typeId());
     std::list<AttributePtr>::iterator aRefsIter = aRefs.begin();
     for (; aRefsIter != aRefs.end(); aRefsIter++) {
-      std::shared_ptr<Model_AttributeSelection> aSel =
-        std::dynamic_pointer_cast<Model_AttributeSelection>(*aRefsIter);
+      AttributeSelectionPtr aSel =
+        std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(*aRefsIter);
       bool aRemove = false;
       aSel->updateInHistory(aRemove);
     }
@@ -1099,12 +1098,12 @@ void Model_Update::updateSelection(const std::set<std::shared_ptr<ModelAPI_Objec
       std::shared_ptr<ModelAPI_AttributeSelectionList> aSel =
         std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(*aRefsIter);
       for(int a = aSel->size() - 1; a >= 0; a--) {
-        std::shared_ptr<Model_AttributeSelection> aSelAttr =
-          std::dynamic_pointer_cast<Model_AttributeSelection>(aSel->value(a));
+        AttributeSelectionPtr aSelAttr =
+          std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aSel->value(a));
         if (aSelAttr.get()) {
-          bool theRemove = false;
-          aSelAttr->updateInHistory(theRemove);
-          if (theRemove) {
+          bool aRemove = false;
+          aSelAttr->updateInHistory(aRemove);
+          if (aRemove) {
             aRemoveSet.insert(a);
           }
         }
index 4f04867ec9f0b847459b152795701eee5b2a3164..4ac152b264143322b9cf9f707f0700be516254f7 100644 (file)
@@ -261,4 +261,5 @@ ADD_UNIT_TESTS(TestConstants.py
                Test19058.py
                Test19217.py
                Test19707.py
+               Test19726.py
 )
index aba0818d9ff7c4e627cb8a7b25f4cfa9b13b541d..fa5b5605319026dc5d26e6918e58a3191f6545ff 100644 (file)
@@ -123,6 +123,11 @@ class ModelAPI_AttributeSelection : public ModelAPI_Attribute
   /// Makes the current local selection becomes all sub-shapes with same base geometry.
   MODELAPI_EXPORT virtual void combineGeometrical() = 0;
 
+  /// Updates the arguments of selection if something was affected by creation
+  /// or reorder of features upper in the history line.
+  /// Returns theRemove true if this attribute must be removed (become deleted)
+  MODELAPI_EXPORT virtual void updateInHistory(bool& theRemove) = 0;
+
  protected:
   /// Objects are created for features automatically
   MODELAPI_EXPORT ModelAPI_AttributeSelection();
diff --git a/src/ModelAPI/Test/Test19726.py b/src/ModelAPI/Test/Test19726.py
new file mode 100644 (file)
index 0000000..f6e82b2
--- /dev/null
@@ -0,0 +1,49 @@
+# 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
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# 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
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+from salome.shaper import model
+from ModelAPI import *
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ"))
+SketchCircle_1 = Sketch_1.addCircle(18.39021699364881, 11.50401662688171, 4.123179523509023)
+model.do()
+Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2r")], model.selection(), 10, 0)
+model.do()
+Translation_1 = model.addTranslation(partSet, [model.selection("COMPOUND", "Part_1/")], axis = model.selection("EDGE", "Part_1/([Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2][Extrusion_1_1/From_Face])([Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2][Extrusion_1_1/To_Face])"), distance = 20, keepSubResults = True)
+aName1 = Translation_1.axisObject().namingName()
+model.end()
+
+# update the extrusion in the part, so, outside the part selection must be moved in history
+model.begin()
+Rotation_1 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Extrusion_1_1")], axis = model.selection("EDGE", "PartSet/OY"), angle = 45)
+model.do()
+aSession = ModelAPI_Session.get()
+aSession.setActiveDocument(partSet)
+model.end()
+
+# check that name was changed to the rotation
+aName2 = Translation_1.axisObject().namingName()
+assert(aName1 != aName2)
+assert(len(aName2) > 7)
+
+assert(model.checkPythonDump())