From: mpv Date: Thu, 12 Sep 2019 08:14:55 +0000 (+0300) Subject: Make export to XAO working with groups BOPs and whole features in groups selected. X-Git-Tag: V9_4_0a2~4^2~107 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9f251783e55f12d37ce7795d8f3b30d478a711a0;p=modules%2Fshaper.git Make export to XAO working with groups BOPs and whole features in groups selected. --- diff --git a/src/CollectionPlugin/CMakeLists.txt b/src/CollectionPlugin/CMakeLists.txt index 936dd87e7..6df779866 100644 --- a/src/CollectionPlugin/CMakeLists.txt +++ b/src/CollectionPlugin/CMakeLists.txt @@ -148,4 +148,5 @@ ADD_UNIT_TESTS( TestGroupSubstraction_Error2.py Test2977.py TestGroupWholeResult1.py + TestGroupWholeResult2.py ) diff --git a/src/CollectionPlugin/Test/TestGroupWholeResult2.py b/src/CollectionPlugin/Test/TestGroupWholeResult2.py new file mode 100644 index 000000000..31114c321 --- /dev/null +++ b/src/CollectionPlugin/Test/TestGroupWholeResult2.py @@ -0,0 +1,47 @@ +# Copyright (C) 2014-2019 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 +# + +# Tests python API for the whole result (by feature) in group selection +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Group_1 = model.addGroup(Part_1_doc, "Faces", [model.selection("COMPOUND", "all-in-Box_1")]) +Group_2 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Box_1_1/Left"), model.selection("FACE", "Box_1_1/Top")]) +GroupSubstraction_1 = model.addGroupSubstraction(Part_1_doc, [model.selection("COMPOUND", "Group_1")], [model.selection("COMPOUND", "Group_2")]) +model.end() + +aResultShape = GroupSubstraction_1.feature().firstResult().shape() + +from GeomAPI import GeomAPI_ShapeIterator +anIter = GeomAPI_ShapeIterator(aResultShape) +aNum = 0 +while anIter.more(): + aFace = anIter.current() + assert(aFace.isFace()) + aNum = aNum + 1 + anIter.next() + +assert(aNum == 4) # 6 from the whole result minus 2 from the second group (local selection) + + +assert(model.checkPythonDump()) diff --git a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp index 60cae7e2f..f38b1c605 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp @@ -256,8 +256,42 @@ static bool isInResults(AttributeSelectionListPtr theSelection, // if context is in results, return true for(int a = 0; a < theSelection->size(); a++) { AttributeSelectionPtr anAttr = theSelection->value(a); - ResultBodyPtr aSelected= std::dynamic_pointer_cast(anAttr->context()); - if (aSelected.get() && theCashedResults.count(aSelected)) + ResultPtr aContext = anAttr->context(); + // check is it group selected for groups BOP + if (aContext.get() && aContext->groupName() == ModelAPI_ResultGroup::group()) { + // it is impossible by used results check which result is used in this group result, + // so check the results shapes is it in results of this document or not + FeaturePtr aSelFeature = + std::dynamic_pointer_cast(theSelection->owner()); + if (!aSelFeature.get() || aSelFeature->results().empty()) + continue; + GeomShapePtr aGroupResShape = aSelFeature->firstResult()->shape(); + + std::set::iterator allResultsIter = theCashedResults.begin(); + for(; allResultsIter != theCashedResults.end(); allResultsIter++) { + GeomShapePtr aResultShape = (*allResultsIter)->shape(); + + GeomAPI_Shape::ShapeType aType = + GeomAPI_Shape::shapeTypeByStr(theSelection->selectionType()); + GeomAPI_ShapeExplorer aGroupResExp(aGroupResShape, aType); + for(; aGroupResExp.more(); aGroupResExp.next()) { + if (aResultShape->isSubShape(aGroupResExp.current(), false)) + return true; // at least one shape of the group is in the used results + } + } + } + ResultBodyPtr aSelected = std::dynamic_pointer_cast(anAttr->context()); + if (!aSelected.get()) { // try to get selected feature and all its results + FeaturePtr aContextFeature = anAttr->contextFeature(); + if (aContextFeature.get() && !aContextFeature->results().empty()) { + const std::list& allResluts = aContextFeature->results(); + std::list::const_iterator aResIter = allResluts.cbegin(); + for(; aResIter != allResluts.cend(); aResIter++) { + if (aResIter->get() && theCashedResults.count(*aResIter)) + return true; + } + } + } else if (aSelected.get() && theCashedResults.count(aSelected)) return true; } return false; @@ -372,6 +406,8 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName) for (int aGroupIndex = 0; aGroupIndex < aGroupCount; ++aGroupIndex) { ResultGroupPtr aResultGroup = std::dynamic_pointer_cast( (*aDoc)->object(ModelAPI_ResultGroup::group(), aGroupIndex)); + if (!aResultGroup.get() || !aResultGroup->shape().get()) + continue; FeaturePtr aGroupFeature = (*aDoc)->feature(aResultGroup); @@ -391,26 +427,15 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName) aResultGroup->data()->name()); try { - for (int aSelectionIndex = 0; aSelectionIndex < aSelectionList->size(); ++aSelectionIndex){ - AttributeSelectionPtr aSelection = aSelectionList->value(aSelectionIndex); - GeomShapePtr aSelShape = aSelection->value(); - if (!aSelShape.get() && aSelection->context().get()) { - aSelShape = aSelection->context()->shape(); - } - - std::list allSubs; - allSubShapes(aSelShape, aSelType, allSubs); - - std::list::iterator anIter = allSubs.begin(); - for(; anIter != allSubs.end(); anIter++) { - int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, *anIter); - if (aReferenceID == 0) // selected value does not found in the exported shape - continue; - std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID); - int anElementID = - aXao.getGeometry()->getElementIndexByReference(aGroupDimension, aReferenceString); - aXaoGroup->add(anElementID); - } + GeomAPI_ShapeExplorer aGroupResExplorer(aResultGroup->shape(), aSelType); + for(; aGroupResExplorer.more(); aGroupResExplorer.next()) { + int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aGroupResExplorer.current()); + if (aReferenceID == 0) // selected value does not found in the exported shape + continue; + std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID); + int anElementID = + aXao.getGeometry()->getElementIndexByReference(aGroupDimension, aReferenceString); + aXaoGroup->add(anElementID); } } catch (XAO::XAO_Exception& e) { // LCOV_EXCL_START