From a41d2ac2fd8cd9425eebdcfd98adf6c27950ef87 Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 26 Mar 2019 17:22:14 +0300 Subject: [PATCH] Implementation of proposal 3 in the issue #2882 : Groups are not exported to GEOM under the shapes when there several results. To export results without joining them into compound. In this case group that contains selection on several results must be splitted into several groups (with same name), located under the corresponding results. --- salomeRun_rel.bat | 2 +- .../CollectionPlugin_Validators.cpp | 16 ++- src/ConnectorAPI/Test/TestExportToGEOM.py | 9 +- .../TestExportToGEOMAllGroupsAndFields.py | 28 +++--- .../ConnectorPlugin_ExportFeature.py | 60 ++++++----- src/ExchangeAPI/ExchangeAPI_Export.cpp | 33 +++++++ src/ExchangeAPI/ExchangeAPI_Export.h | 20 +++- .../ExchangePlugin_ExportFeature.cpp | 99 +++++++++++++++---- src/Model/Model_ResultBody.cpp | 4 +- src/ModelAPI/ModelAPI_ResultBody.h | 4 +- 10 files changed, 198 insertions(+), 77 deletions(-) diff --git a/salomeRun_rel.bat b/salomeRun_rel.bat index 03ab278f6..2cfabdae9 100644 --- a/salomeRun_rel.bat +++ b/salomeRun_rel.bat @@ -12,4 +12,4 @@ call env_Salome.bat @SET SHAPER_ROOT_DIR=%ROOT_DIR%\install @SET SalomeAppConfig=%SHAPER_ROOT_DIR%\share\salome\resources\shaper;%GUI_ROOT_DIR%\share\salome\resources\gui -start %PYTHONBIN% "%KERNEL_ROOT_DIR%\bin\salome\envSalome.py" "%PYTHONBIN%" "%KERNEL_ROOT_DIR%\bin\salome\runSalome.py" %* +start %PYTHONBIN% "%KERNEL_ROOT_DIR%\bin\salome\envSalome.py" "%PYTHONBIN%" "%KERNEL_ROOT_DIR%\bin\salome\runSalome.py" --modules=SHAPER,GEOM,SMESH %* diff --git a/src/CollectionPlugin/CollectionPlugin_Validators.cpp b/src/CollectionPlugin/CollectionPlugin_Validators.cpp index 0c765092e..d644c13f6 100644 --- a/src/CollectionPlugin/CollectionPlugin_Validators.cpp +++ b/src/CollectionPlugin/CollectionPlugin_Validators.cpp @@ -29,17 +29,15 @@ bool CollectionPlugin_FieldValidator::isValid(const FeaturePtr& theFeature, { AttributeSelectionListPtr aSelList = theFeature->selectionList(CollectionPlugin_Field::SELECTED_ID()); + std::string aTypeStr = aSelList->selectionType(); + if (aTypeStr == "part") + return true; if (aSelList->isInitialized()) { int aSize = aSelList->size(); - std::string aTypeStr = aSelList->selectionType(); - if (aTypeStr == "part") - return true; - else { - bool aIsDefined = aSize > 0; - if (!aIsDefined) - theError = "Selection list is not initialized"; - return aIsDefined; - } + bool aIsDefined = aSize > 0; + if (!aIsDefined) + theError = "Selection list is not initialized"; + return aIsDefined; } theError = "Selection list is not initialized"; return false; diff --git a/src/ConnectorAPI/Test/TestExportToGEOM.py b/src/ConnectorAPI/Test/TestExportToGEOM.py index 0c8614887..9efb1bba0 100644 --- a/src/ConnectorAPI/Test/TestExportToGEOM.py +++ b/src/ConnectorAPI/Test/TestExportToGEOM.py @@ -90,10 +90,10 @@ def testSeveralExportsToGEOM(): Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Translation_1_1"), model.selection("SOLID", "Box_2_1")]) Group_1 = model.addGroup(Part_1_doc, [model.selection("FACE", "Partition_1_1_1/Modified_Face&Box_1_1/Bottom"), model.selection("FACE", "Box_2_1/Top")]) model.do() - model.end() # First export to GEOM model.exportToGEOM(Part_1_doc) + model.end() # Check that the GEOM object has 1 compsolid and 2 solids geomObject_1 = getLastGEOMShape() @@ -105,15 +105,18 @@ def testSeveralExportsToGEOM(): assert geompy.NumberOfFaces(geomGroup_1) == 2 # Add a third box + model.begin() Box_3 = model.addBox(Part_1_doc, 10, 10, 10) Translation_2 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_3_1")], model.selection("EDGE", "PartSet/OX"), 20) + model.do() # Second export to GEOM model.exportToGEOM(Part_1_doc) + model.end() - # Check that the GEOM object has 3 solids + # Check that the last exported GEOM object is 1 solids geomObject_2 = getLastGEOMShape() - assert geompy.NumberOfSolids(geomObject_2) == 3 + assert geompy.NumberOfSolids(geomObject_2) == 1 # Dump the salome study (only CORBA modules, SHAPER dump is not in it) tempdir = tempfile.gettempdir() diff --git a/src/ConnectorAPI/Test/TestExportToGEOMAllGroupsAndFields.py b/src/ConnectorAPI/Test/TestExportToGEOMAllGroupsAndFields.py index 416d2ad5f..0048ebc6b 100644 --- a/src/ConnectorAPI/Test/TestExportToGEOMAllGroupsAndFields.py +++ b/src/ConnectorAPI/Test/TestExportToGEOMAllGroupsAndFields.py @@ -117,8 +117,8 @@ def testGroupsAndFieldsExportToGEOM(): Field_4 = model.addField(Part_1_doc, 1, "DOUBLE", 1, ["Comp 1"], Field_4_objects) Field_4.result().setName("Field_vertices") Field_4.addStep(0, 0, [[0], [1], [1], [1], [1], [1], [1], [1], [1], [2], [2], [2], [2], [3], [3], [3], [3]]) - model.exportToGEOM(Part_1_doc) model.do() + model.exportToGEOM(Part_1_doc) model.end() # check the groups content by the coordinates of a point on its sub-shapes @@ -130,55 +130,55 @@ def checkGroupByCoords(group, coords, tolerance=1e-7): ## Check the result imported in GEOM def checkResultInGEOM(): - geomObject_1 = getLastGEOMShape() + geomObject_1 = getLastGEOMShape() # the second, translation result group_1_GEOM = getSubObject(geomObject_1, 1) assert group_1_GEOM.GetName() == 'faces_top' - assert geompy.NumberOfFaces(group_1_GEOM) == 3 + assert geompy.NumberOfFaces(group_1_GEOM) == 1 # 2 faces are in the first result, only one here # coordinates of the barycenters of the faces of Group_1 - coords_1 = [[-5, 5, 10], [10, 10, 20], [25, 5, 10]] + coords_1 = [[25, 5, 10]] checkGroupByCoords(group_1_GEOM, coords_1) group_2_GEOM = getSubObject(geomObject_1, 2) assert group_2_GEOM.GetName() == 'edges_x' - assert geompy.NumberOfEdges(group_2_GEOM) == 3 + assert geompy.NumberOfEdges(group_2_GEOM) == 1 # 2 edges are in the first result, only one here # coordinates of the barycenters of the edges of Group_2 - coords_2 = [[-5, 0, 0], [10, 0, 0], [25, 0, 0]] + coords_2 = [[25, 0, 0]] checkGroupByCoords(group_2_GEOM, coords_2) group_3_GEOM = getSubObject(geomObject_1, 3) assert group_3_GEOM.GetName() == 'vertices_bottom' - assert geompy.NumberOfSubShapes(group_3_GEOM, geompy.ShapeType["VERTEX"]) == 8 + assert geompy.NumberOfSubShapes(group_3_GEOM, geompy.ShapeType["VERTEX"]) == 3 # 3 of 8 # coordinates of the points of of Group_3 - coords_3 = [[-10, 0, 0], [-10, 10, 0], [0, 10, 0], [0, 20, 0], [20, 20, 0], [20, 10, 0], [30, 10, 0], [30, 0, 0]] + coords_3 = [[20, 10, 0], [30, 10, 0], [30, 0, 0]] checkGroupByCoords(group_3_GEOM, coords_3) group_4_GEOM = getSubObject(geomObject_1, 4) assert group_4_GEOM.GetName() == 'solids_small' - assert geompy.NumberOfSolids(group_4_GEOM) == 2 + assert geompy.NumberOfSolids(group_4_GEOM) == 1 # 1 of 2 # coordinates of the barycenters of the solids of Group_4 - coords_4 = [[-5, 5, 5], [25, 5, 5]] + coords_4 = [[25, 5, 5]] checkGroupByCoords(group_4_GEOM, coords_4) field_1_GEOM = getSubObject(geomObject_1, 5) assert field_1_GEOM.GetName() == 'Field_solids' - assert field_1_GEOM.GetStep(0).GetValues() == [1.0, 2.0, 3.0] + assert field_1_GEOM.GetStep(0).GetValues() == [3.0] field_2_GEOM = getSubObject(geomObject_1, 6) assert field_2_GEOM.GetName() == 'Field_faces' - assert field_2_GEOM.GetStep(0).GetValues() == [0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 2.0] + assert field_2_GEOM.GetStep(0).GetValues() == [0.0, 0.0, 0.0, 0.0, 1.0, 2.0] field_3_GEOM = getSubObject(geomObject_1, 7) assert field_3_GEOM.GetName() == 'Field_edges' - assert field_3_GEOM.GetStep(0).GetValues() == [2.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 3.0, 0.0, 1.0, 0.0, 3.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 1.0, 0.0, 0.0, 0.0] + assert field_3_GEOM.GetStep(0).GetValues() == [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 1.0, 0.0, 0.0, 0.0] field_4_GEOM = getSubObject(geomObject_1, 8) assert field_4_GEOM.GetName() == 'Field_vertices' - assert field_4_GEOM.GetStep(0).GetValues() == [2.0, 1.0, 2.0, 1.0, 0.0, 0.0, 0.0, 1.0, 2.0, 2.0, 1.0, 3.0, 0.0, 3.0, 1.0, 0.0, 0.0, 0.0, 1.0, 3.0, 1.0, 3.0, 1.0] + assert field_4_GEOM.GetStep(0).GetValues() == [0.0, 0.0, 0.0, 1.0, 3.0, 1.0, 3.0, 1.0] pass diff --git a/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py b/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py index 8bde3eec7..338161d4a 100644 --- a/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py +++ b/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py @@ -57,7 +57,7 @@ class ExportFeature(ModelAPI.ModelAPI_Feature): def getKind(self): return ExportFeature.ID() - ## This feature is action: has no property pannel and executes immediately. + ## This feature is action: has no property panel and executes immediately. def isAction(self): return True @@ -67,32 +67,38 @@ class ExportFeature(ModelAPI.ModelAPI_Feature): ## Export the results, groups and fields via XAO def exportViaXAO(self): - tmpXAOFile = getTmpFileName("xao") - self.tmpXAOFile = tmpXAOFile - #print "Export to %s"%tmpXAOFile - exportXAO = ExchangeAPI.exportToXAO(self.Part, tmpXAOFile, "automatic_shaper_export_to_XAO") - if not os.path.exists(tmpXAOFile) or os.stat(tmpXAOFile).st_size == 0: - exportXAO.feature().setError("Error in exportToXAO. No XAO file has been created.") - return - imported, shape, subShapes, groups, fields = self.geompy.ImportXAO(tmpXAOFile) - self.geompy.addToStudy( shape, shape.GetName() ) - # add sub-shapes and groups to the object browser - for obj in subShapes + groups: - name = obj.GetName() - self.geompy.addToStudyInFather(shape, obj, name) - # add fields to the object browser - for field in fields: - name = field.GetName() - self.geompy.addToStudyInFather(shape, field, name) - # add steps to the object browser - steps = field.getSteps() - for i_step in steps: - step = field.getStep(i_step) - i_stamp = step.GetStamp() - step_name = "Step %i %i"%(i_step, i_stamp) - self.geompy.addToStudyInFather( field, step, step_name ) - # Remove the temporary file - os.remove(tmpXAOFile) + # iterate all results of Part, export one by one due to issue 2882 + for aResIndex in range(self.Part.size(model.ModelAPI_ResultBody_group())): + anObject = self.Part.object(model.ModelAPI_ResultBody_group(), aResIndex) + aResult = model.objectToResult(anObject) + if not aResult is None: + tmpXAOFile = getTmpFileName("xao") + self.tmpXAOFile = tmpXAOFile + #print "Export to %s"%tmpXAOFile + exportXAO = ExchangeAPI.exportToXAO(self.Part, tmpXAOFile, model.selection(aResult), "automatic_shaper_export_to_XAO") + if not os.path.exists(tmpXAOFile) or os.stat(tmpXAOFile).st_size == 0: + exportXAO.feature().setError("Error in exportToXAO. No XAO file has been created.") + return + imported, shape, subShapes, groups, fields = self.geompy.ImportXAO(tmpXAOFile) + self.geompy.addToStudy( shape, shape.GetName() ) + # add sub-shapes and groups to the object browser + for obj in subShapes + groups: + name = obj.GetName() + self.geompy.addToStudyInFather(shape, obj, name) + # add fields to the object browser + for field in fields: + name = field.GetName() + self.geompy.addToStudyInFather(shape, field, name) + # add steps to the object browser + steps = field.getSteps() + for i_step in steps: + step = field.getStep(i_step) + i_stamp = step.GetStamp() + step_name = "Step %i %i"%(i_step, i_stamp) + self.geompy.addToStudyInFather( field, step, step_name ) + # Remove the temporary file + os.remove(tmpXAOFile) + pass pass ## Exports all shapes and groups into the GEOM module. diff --git a/src/ExchangeAPI/ExchangeAPI_Export.cpp b/src/ExchangeAPI/ExchangeAPI_Export.cpp index 10ea38426..1e7e54aa8 100644 --- a/src/ExchangeAPI/ExchangeAPI_Export.cpp +++ b/src/ExchangeAPI/ExchangeAPI_Export.cpp @@ -24,6 +24,7 @@ #include #include #include +#include //-------------------------------------------------------------------------------------- ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr& theFeature) @@ -50,6 +51,27 @@ ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr& apply(); // finish operation to make sure the export is done on the current state of the history } +ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr& theFeature, + const std::string & theFilePath, const ModelHighAPI_Selection& theResult, + const std::string & theAuthor, const std::string & theGeometryName) + : ModelHighAPI_Interface(theFeature) +{ + initialize(); + fillAttribute("XAO", theFeature->string(ExchangePlugin_ExportFeature::EXPORT_TYPE_ID())); + fillAttribute(theFilePath, theFeature->string(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID())); + fillAttribute(theAuthor, theFeature->string(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID())); + fillAttribute(theGeometryName, + theFeature->string(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID())); + fillAttribute("XAO", theFeature->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID())); + std::list aListOfOneSel; + aListOfOneSel.push_back(theResult); + fillAttribute(aListOfOneSel, + theFeature->selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID())); + execute(); + apply(); // finish operation to make sure the export is done on the current state of the history +} + + /// Constructor with values for export in other formats than XAO. ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr& theFeature, const std::string & theFilePath, @@ -149,4 +171,15 @@ ExportPtr exportToXAO(const std::shared_ptr & thePart, return ExportPtr(new ExchangeAPI_Export(aFeature, theFilePath, theAuthor, theGeometryName)); } +ExportPtr exportToXAO(const std::shared_ptr & thePart, + const std::string & theFilePath, const ModelHighAPI_Selection& theSelectedShape, + const std::string & theAuthor, const std::string & theGeometryName) +{ + apply(); // finish previous operation to make sure all previous operations are done + std::shared_ptr aFeature = + thePart->addFeature(ExchangePlugin_ExportFeature::ID()); + // special internal case when for XAO a selection list is filled + return ExportPtr(new ExchangeAPI_Export(aFeature, theFilePath, theSelectedShape, "XAO")); +} + //-------------------------------------------------------------------------------------- diff --git a/src/ExchangeAPI/ExchangeAPI_Export.h b/src/ExchangeAPI/ExchangeAPI_Export.h index 927a07127..6cfddfd8f 100644 --- a/src/ExchangeAPI/ExchangeAPI_Export.h +++ b/src/ExchangeAPI/ExchangeAPI_Export.h @@ -52,6 +52,14 @@ public: const std::string & theAuthor = std::string(), const std::string & theGeometryName = std::string()); + /// Constructor with values for XAO of selected result export. + EXCHANGEAPI_EXPORT + explicit ExchangeAPI_Export(const std::shared_ptr& theFeature, + const std::string & theFilePath, + const ModelHighAPI_Selection& theResult, + const std::string & theAuthor, + const std::string & theGeometryName = std::string()); + /// Constructor with values for export in other formats than XAO. EXCHANGEAPI_EXPORT explicit ExchangeAPI_Export(const std::shared_ptr& theFeature, @@ -97,7 +105,7 @@ ExportPtr exportToFile(const std::shared_ptr & thePart, const std::string & theFileFormat = std::string()); /**\ingroup CPPHighAPI - * \brief Export XAO + * \brief Exports to XAO file all results of the current document */ EXCHANGEAPI_EXPORT ExportPtr exportToXAO(const std::shared_ptr & thePart, @@ -105,6 +113,16 @@ ExportPtr exportToXAO(const std::shared_ptr & thePart, const std::string & theAuthor = std::string(), const std::string & theGeometryName = std::string()); +/**\ingroup CPPHighAPI +* \brief Exports to XAO file the selected result with groups parts related to it only. +*/ +EXCHANGEAPI_EXPORT +ExportPtr exportToXAO(const std::shared_ptr & thePart, + const std::string & theFilePath, + const ModelHighAPI_Selection& theSelectedShape, + const std::string & theAuthor = std::string(), + const std::string & theGeometryName = std::string()); + //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- #endif /* SRC_EXCHANGEAPI_EXCHANGEAPI_EXPORT_H_ */ diff --git a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp index 7ae2e133f..a8ecc73c1 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #include @@ -212,6 +213,37 @@ static std::string valToString(const ModelAPI_AttributeTables::Value& theVal, return aStr.str(); } +/// Returns true if something in selection is presented in the results list +static bool isInResults(AttributeSelectionListPtr theSelection, + const std::list& theResults, + std::set& theCashedResults) +{ + // collect all results into a cashed set + if (theCashedResults.empty()) { + std::list aResults; + std::list::const_iterator aRes = theResults.cbegin(); + for(; aRes != theResults.cend(); aRes++) { + if (theCashedResults.count(*aRes)) + continue; + else + theCashedResults.insert(*aRes); + std::list aResults; + ModelAPI_Tools::allSubs(*aRes, aResults, false); + for(std::list::iterator aR = aResults.begin(); aR != aResults.end(); aR++) { + theCashedResults.insert(std::dynamic_pointer_cast(*aR)); + } + } + } + // 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)) + return true; + } + return false; +} + void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName) { try { @@ -227,16 +259,39 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName) // make shape for export from all results std::list aShapes; std::list aResults; - int aBodyCount = document()->size(ModelAPI_ResultBody::group()); - for (int aBodyIndex = 0; aBodyIndex < aBodyCount; ++aBodyIndex) { - ResultBodyPtr aResultBody = - std::dynamic_pointer_cast( - document()->object(ModelAPI_ResultBody::group(), aBodyIndex)); - if (!aResultBody.get()) - continue; - aShapes.push_back(aResultBody->shape()); - aResults.push_back(aResultBody); + + AttributeSelectionListPtr aSelection = selectionList(SELECTION_LIST_ID()); + bool aIsSelection = aSelection->isInitialized() && aSelection->size() > 0; + if (aIsSelection) { // a mode for export to geom result by result + for(int a = 0; a < aSelection->size(); a++) { + AttributeSelectionPtr anAttr = aSelection->value(a); + ResultBodyPtr aBodyContext = std::dynamic_pointer_cast(anAttr->context()); + if (aBodyContext.get() && !aBodyContext->isDisabled() && aBodyContext->shape().get()) { + aResults.push_back(aBodyContext); + GeomShapePtr aShape = anAttr->value(); + if (!aShape.get()) + aShape = aBodyContext->shape(); + aShapes.push_back(aShape); + } + } + } else { + int aBodyCount = document()->size(ModelAPI_ResultBody::group()); + for (int aBodyIndex = 0; aBodyIndex < aBodyCount; ++aBodyIndex) { + ResultBodyPtr aResultBody = + std::dynamic_pointer_cast( + document()->object(ModelAPI_ResultBody::group(), aBodyIndex)); + if (!aResultBody.get()) + continue; + aShapes.push_back(aResultBody->shape()); + aResults.push_back(aResultBody); + } + } + if (aShapes.empty()) { + setError("No shapes to export"); + return; } + + GeomShapePtr aShape = (aShapes.size() == 1) ? *aShapes.begin() : GeomAlgoAPI_CompoundBuilder::compound(aShapes); @@ -250,7 +305,7 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName) // geometry name std::string aGeometryName = string(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID())->value(); - if (aGeometryName.empty() && aBodyCount == 1) { + if (aGeometryName.empty() && aResults.size() == 1) { // get the name from the first result ResultBodyPtr aResultBody = *aResults.begin(); aGeometryName = aResultBody->data()->name(); @@ -258,6 +313,8 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName) aXao.getGeometry()->setName(aGeometryName); + std::set allResultsCashed; // cash to speed up searching in all results selected + // groups int aGroupCount = document()->size(ModelAPI_ResultGroup::group()); for (int aGroupIndex = 0; aGroupIndex < aGroupCount; ++aGroupIndex) { @@ -270,6 +327,9 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName) AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list"); + if (!isInResults(aSelectionList, aResults, allResultsCashed))// skip group not used in results + continue; + // conversion of dimension std::string aSelectionType = aSelectionList->selectionType(); std::string aDimensionString = @@ -290,6 +350,9 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName) 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); @@ -318,13 +381,17 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName) AttributeSelectionListPtr aSelectionList = aFieldFeature->selectionList("selected"); + std::string aSelectionType = aSelectionList->selectionType(); + bool isWholePart = aSelectionType == "part"; + + if (!isWholePart && + !isInResults(aSelectionList, aResults, allResultsCashed))// skip field not used in results + continue; // conversion of dimension - std::string aSelectionType = aSelectionList->selectionType(); std::string aDimensionString = ExchangePlugin_Tools::selectionType2xaoDimension(aSelectionType); XAO::Dimension aFieldDimension = XAO::XaoUtils::stringToDimension(aDimensionString); - bool isWholePart = aSelectionType == "part"; // get tables and their type std::shared_ptr aTables = aFieldFeature->tables("values"); std::string aTypeString = ExchangePlugin_Tools::valuesType2xaoType(aTables->type()); @@ -358,13 +425,9 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName) if (!isWholePart) { // element index actually is the ID of the selection AttributeSelectionPtr aSelection = aSelectionList->value(aRow - 1); - - // 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); anElementID = diff --git a/src/Model/Model_ResultBody.cpp b/src/Model/Model_ResultBody.cpp index 4f442842e..1be002979 100644 --- a/src/Model/Model_ResultBody.cpp +++ b/src/Model/Model_ResultBody.cpp @@ -125,9 +125,9 @@ ResultBodyPtr Model_ResultBody::subResult(const int theIndex, bool forTree) cons return mySubs.at(theIndex); } -bool Model_ResultBody::isSub(ObjectPtr theObject, int& theIndex) const +bool Model_ResultBody::isSub(ObjectPtr theResult, int& theIndex) const { - std::map::const_iterator aFound = mySubsMap.find(theObject); + std::map::const_iterator aFound = mySubsMap.find(theResult); if (aFound != mySubsMap.end()) { theIndex = aFound->second; return true; diff --git a/src/ModelAPI/ModelAPI_ResultBody.h b/src/ModelAPI/ModelAPI_ResultBody.h index 0991119bd..c585280cc 100644 --- a/src/ModelAPI/ModelAPI_ResultBody.h +++ b/src/ModelAPI/ModelAPI_ResultBody.h @@ -86,9 +86,9 @@ public: MODELAPI_EXPORT virtual std::shared_ptr subResult( const int theIndex, bool forTree = false) const = 0; - /// Returns true if feature or result belong to this composite feature as subs + /// Returns true if theResult belong to this composite result as sub. /// Returns theIndex - zero based index of sub if found - MODELAPI_EXPORT virtual bool isSub(ObjectPtr theObject, int& theIndex) const = 0; + MODELAPI_EXPORT virtual bool isSub(ObjectPtr theResult, int& theIndex) const = 0; /// \brief Stores the shape (called by the execution method). /// param[in] theShape shape to store. -- 2.39.2