- // groups
- int aGroupCount = document()->size(ModelAPI_ResultGroup::group());
- for (int aGroupIndex = 0; aGroupIndex < aGroupCount; ++aGroupIndex) {
- ResultGroupPtr aResultGroup =
- std::dynamic_pointer_cast<ModelAPI_ResultGroup>(
- document()->object(ModelAPI_ResultGroup::group(), aGroupIndex));
-
- FeaturePtr aGroupFeature = document()->feature(aResultGroup);
-
- AttributeSelectionListPtr aSelectionList =
- aGroupFeature->selectionList("group_list");
-
- // conversion of dimension
- std::string aSelectionType = aSelectionList->selectionType();
- std::string aDimensionString =
- ExchangePlugin_Tools::selectionType2xaoDimension(aSelectionType);
- XAO::Dimension aGroupDimension = XAO::XaoUtils::stringToDimension(aDimensionString);
-
- XAO::Group* aXaoGroup = aXao.addGroup(aGroupDimension,
- aResultGroup->data()->name());
-
- try {
- for (int aSelectionIndex = 0; aSelectionIndex < aSelectionList->size(); ++aSelectionIndex) {
- AttributeSelectionPtr aSelection = aSelectionList->value(aSelectionIndex);
-
- // 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());
-
- std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
- int anElementID =
- aXao.getGeometry()->getElementIndexByReference(aGroupDimension, aReferenceString);
-
- aXaoGroup->add(anElementID);
+ std::set<ResultPtr> allResultsCashed; // cash to speed up searching in all results selected
+
+ // iterate all documents used
+ if (aDocuments.empty())
+ aDocuments.push_back(document());
+ std::list<DocumentPtr>::iterator aDoc = aDocuments.begin();
+ for(; aDoc != aDocuments.end(); aDoc++) {
+ // groups
+ int aGroupCount = (*aDoc)->size(ModelAPI_ResultGroup::group());
+ for (int aGroupIndex = 0; aGroupIndex < aGroupCount; ++aGroupIndex) {
+ ResultGroupPtr aResultGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(
+ (*aDoc)->object(ModelAPI_ResultGroup::group(), aGroupIndex));
+ if (!aResultGroup.get() || !aResultGroup->shape().get())
+ continue;
+
+ FeaturePtr aGroupFeature = (*aDoc)->feature(aResultGroup);
+
+ AttributeSelectionListPtr aSelectionList =
+ aGroupFeature->selectionList("group_list");
+ if (!ModelAPI_Tools::isInResults(aSelectionList,
+ aResults,
+ allResultsCashed))// skip group not used in result
+ continue;
+
+ // 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);
+
+ XAO::Group* aXaoGroup = aXao.addGroup(aGroupDimension,
+ Locale::Convert::toString(aResultGroup->data()->name()));
+
+ try {
+ GeomAPI_ShapeExplorer aGroupResExplorer(aResultGroup->shape(), aSelType);
+ for(; aGroupResExplorer.more(); aGroupResExplorer.next()) {
+ GeomShapePtr aGroupShape = aGroupResExplorer.current();
+ if (aDocTrsf.find(*aDoc) != aDocTrsf.end())
+ aGroupShape->move(aDocTrsf[*aDoc]);
+ int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aGroupShape);
+ 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
+ std::string msg = "An error occurred while exporting group " +
+ Locale::Convert::toString(aResultGroup->data()->name());
+ msg += ".\n";
+ msg += e.what();
+ msg += "\n";
+ msg += "=> skipping this group from XAO export.";
+ Events_InfoMessage("ExportFeature", msg, this).send();
+ aXao.removeGroup(aXaoGroup);
+ // LCOV_EXCL_STOP