From aa56c224d53bb383b6489c67ccc5d9c60fe193ec Mon Sep 17 00:00:00 2001 From: mpv Date: Wed, 22 Aug 2018 17:17:16 +0300 Subject: [PATCH] Fix for the issue #2588 : Invalid selection when select feature --- src/FeaturesPlugin/CMakeLists.txt | 1 + .../FeaturesPlugin_MultiRotation.cpp | 4 +- .../FeaturesPlugin_MultiTranslation.cpp | 4 +- .../FeaturesPlugin_Placement.cpp | 2 +- .../FeaturesPlugin_Rotation.cpp | 2 +- .../FeaturesPlugin_Symmetry.cpp | 6 +-- .../FeaturesPlugin_Translation.cpp | 6 +-- .../FeaturesPlugin_ValidatorTransform.cpp | 13 ++++- src/FeaturesPlugin/Test/Test2588.py | 49 +++++++++++++++++++ 9 files changed, 74 insertions(+), 13 deletions(-) create mode 100644 src/FeaturesPlugin/Test/Test2588.py diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index db68e4533..47fea06c9 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -325,4 +325,5 @@ ADD_UNIT_TESTS(TestExtrusion.py TestBooleanCommon_CompSolidCompound_CompSolidCompound.py Test2596.py Test2592.py + Test2588.py ) diff --git a/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp b/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp index 3bd55a63a..5f8870f59 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp @@ -135,7 +135,7 @@ void FeaturesPlugin_MultiRotation::performRotation1D() for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++, aContext++) { std::shared_ptr aBaseShape = *anObjectsIt; - bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group(); + bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group(); // Setting result. if (isPart) { @@ -277,7 +277,7 @@ void FeaturesPlugin_MultiRotation::performRotation2D() for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++, aContext++) { std::shared_ptr aBaseShape = *anObjectsIt; - bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group(); + bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group(); std::shared_ptr aDir = GeomAlgoAPI_ShapeTools::buildDirFromAxisAndShape(aBaseShape, anAxis); diff --git a/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp index 4ef723603..d23742c6d 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp @@ -136,7 +136,7 @@ void FeaturesPlugin_MultiTranslation::performOneDirection() for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++, aContext++) { std::shared_ptr aBaseShape = *anObjectsIt; - bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group(); + bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group(); // Setting result. if (isPart) { @@ -291,7 +291,7 @@ void FeaturesPlugin_MultiTranslation::performTwoDirection() for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++, aContext++) { std::shared_ptr aBaseShape = *anObjectsIt; - bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group(); + bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group(); // Setting result. if (isPart) { diff --git a/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp b/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp index 96b9d01fc..ab932f01d 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp @@ -160,7 +160,7 @@ void FeaturesPlugin_Placement::execute() anObjectsIt++, aContext++) { // for part results just set transformation - if ((*aContext)->groupName() == ModelAPI_ResultPart::group()) { + if (aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group()) { ResultPartPtr anOrigin = std::dynamic_pointer_cast(*aContext); ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex); aResultPart->setTrsf(aContextRes, aTrsf); diff --git a/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp b/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp index 1c6daf732..07d2d575c 100755 --- a/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp @@ -123,7 +123,7 @@ void FeaturesPlugin_Rotation::performTranslationByAxisAndAngle() for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++, aContext++) { std::shared_ptr aBaseShape = *anObjectsIt; - bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group(); + bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group(); // Setting result. if (isPart) { diff --git a/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp b/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp index 16e184688..d50b74aa2 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp @@ -139,7 +139,7 @@ void FeaturesPlugin_Symmetry::performSymmetryByPoint() for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++, aContext++) { std::shared_ptr aBaseShape = *anObjectsIt; - bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group(); + bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group(); // Setting result. if (isPart) { @@ -216,7 +216,7 @@ void FeaturesPlugin_Symmetry::performSymmetryByAxis() for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++, aContext++) { std::shared_ptr aBaseShape = *anObjectsIt; - bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group(); + bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group(); // Setting result. if (isPart) { @@ -295,7 +295,7 @@ void FeaturesPlugin_Symmetry::performSymmetryByPlane() for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++, aContext++) { std::shared_ptr aBaseShape = *anObjectsIt; - bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group(); + bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group(); // Setting result. if (isPart) { diff --git a/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp b/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp index f2978df94..0da4b6acc 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp @@ -136,7 +136,7 @@ void FeaturesPlugin_Translation::performTranslationByAxisAndDistance() for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++, aContext++) { std::shared_ptr aBaseShape = *anObjectsIt; - bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group(); + bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group(); // Setting result. if (isPart) { @@ -218,7 +218,7 @@ void FeaturesPlugin_Translation::performTranslationByDimensions() for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++, aContext++) { std::shared_ptr aBaseShape = *anObjectsIt; - bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group(); + bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group(); // Setting result. if (isPart) { @@ -313,7 +313,7 @@ void FeaturesPlugin_Translation::performTranslationByTwoPoints() for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++, aContext++) { std::shared_ptr aBaseShape = *anObjectsIt; - bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group(); + bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group(); // Setting result. if (isPart) { diff --git a/src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.cpp b/src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.cpp index 13a0292e0..694915de7 100755 --- a/src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.cpp @@ -51,9 +51,20 @@ bool FeaturesPlugin_ValidatorTransform::isValid(const AttributePtr& theAttribute std::shared_ptr aSelAttribute = aCurSelList->value(i); ResultPtr aResult = aSelAttribute->context(); if (!aResult) { + // this could be a whole feature selected + FeaturePtr aFeature = aSelAttribute->contextFeature(); + if (aFeature.get() && aFeature->results().size() > 0) { + if (aFeature->firstResult()->groupName() != ModelAPI_ResultBody::group()) { + anErrorGroupName = aFeature->firstResult()->groupName(); + aValid = false; + break; + } + continue; + } theError = "Invalid selection."; return false; - } if (isPartSetDocument) // PartSet document: Result Part is valid + } + if (isPartSetDocument) // PartSet document: Result Part is valid aValid = aResult->groupName() == ModelAPI_ResultPart::group(); else { // Part document: Result CompSolid is valid aValid = aResult->groupName() == ModelAPI_ResultBody::group(); diff --git a/src/FeaturesPlugin/Test/Test2588.py b/src/FeaturesPlugin/Test/Test2588.py new file mode 100644 index 000000000..6b8f4763f --- /dev/null +++ b/src/FeaturesPlugin/Test/Test2588.py @@ -0,0 +1,49 @@ +## Copyright (C) 2014-2017 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 SketchAPI import * + +from salome.shaper import model + +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("YOZ")) +SketchCircle_1 = Sketch_1.addCircle(0, 0, 2) +SketchCircle_1.result().setColor(225, 0, 0) +SketchCircle_1.results()[1].setColor(225, 0, 0) +SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False) +SketchPoint_1 = SketchProjection_1.createdFeature() +SketchPoint_1.result().setColor(170, 0, 225) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchCircle_1.center(), SketchAPI_Point(SketchPoint_1).coordinates()) +SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], 2) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2f")], model.selection(), 10, 0) +Symmetry_1 = model.addSymmetry(Part_1_doc, [model.selection("COMPOUND", "all-in-Extrusion_1")], model.selection("VERTEX", "Sketch_1/Vertex-SketchCircle_1-SketchProjection_1-SketchPoint_1"), True) +LinearCopy_1 = model.addMultiTranslation(Part_1_doc, [model.selection("COMPOUND", "all-in-Symmetry_1")], model.selection("EDGE", "PartSet/OY"), 5, 3) +AngularCopy_1 = model.addMultiRotation(Part_1_doc, [model.selection("COMPOUND", "all-in-LinearCopy_1")], model.selection("EDGE", "PartSet/OZ"), 45, 8) +model.end() + +from GeomAPI import GeomAPI_Shape + +model.testNbSubShapes(AngularCopy_1, GeomAPI_Shape.SOLID, [48]) + +assert(model.checkPythonDump()) -- 2.39.2