From: mpv Date: Tue, 10 Sep 2019 13:55:08 +0000 (+0300) Subject: Task #3005 : To be able to create a group on a whole result. Export to XAO and GEOM... X-Git-Tag: V9_4_0a2~4^2~118 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2df35f62c4741dc49a95ececaf04c1e5f6bf685e;p=modules%2Fshaper.git Task #3005 : To be able to create a group on a whole result. Export to XAO and GEOM support. --- 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