From 198f3f84e844fb43125fb94154955fded9b8bcd6 Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 10 Sep 2019 16:55:08 +0300 Subject: [PATCH] Task #3005 : To be able to create a group on a whole result. Export to XAO and GEOM support. --- .../ExchangePlugin_ExportFeature.cpp | 49 +++++++++++++------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp index da17f46b8..60cae7e2f 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp @@ -38,6 +38,7 @@ #include #include +#include #include #include @@ -262,6 +263,21 @@ static bool isInResults(AttributeSelectionListPtr theSelection, return false; } +/// Returns all sub-shapes of the given shape in theResult +static void allSubShapes(const GeomShapePtr theShape, GeomAPI_Shape::ShapeType theType, + std::list& theResult) +{ + if (theShape->shapeType() == theType) { + theResult.push_back(theShape); + } else { + GeomAPI_DataMapOfShapeShape aUnique; // to keep only unique shapes + for(GeomAPI_ShapeExplorer anExp(theShape, theType); anExp.more(); anExp.next()) { + if (aUnique.bind(anExp.current(), anExp.current())) + theResult.push_back(anExp.current()); + } + } +} + void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName) { try { @@ -366,6 +382,7 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName) // conversion of dimension std::string aSelectionType = aSelectionList->selectionType(); + GeomAPI_Shape::ShapeType aSelType = GeomAPI_Shape::shapeTypeByStr(aSelectionType); std::string aDimensionString = ExchangePlugin_Tools::selectionType2xaoDimension(aSelectionType); XAO::Dimension aGroupDimension = XAO::XaoUtils::stringToDimension(aDimensionString); @@ -376,22 +393,24 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName) 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(); + } - // complex conversion of reference id to element index - // gives bad id in case the selection is done from python script - // => using GeomAlgoAPI_CompoundBuilder::id instead - // int aReferenceID_old = aSelection->Id(); - - int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aSelection->value()); - - 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); + 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); + } } } catch (XAO::XAO_Exception& e) { // LCOV_EXCL_START -- 2.39.2