From: azv Date: Thu, 13 Feb 2020 10:35:14 +0000 (+0300) Subject: Use independent attribute for the shapes exported to XAO for correct processing the... X-Git-Tag: V9_5_0a1~24 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f8d8e2ad28954a28f22d37c63f4d02399d65a5fe;p=modules%2Fshaper.git Use independent attribute for the shapes exported to XAO for correct processing the Export feature related to removed shapes (issue #18710). --- diff --git a/src/ExchangeAPI/ExchangeAPI_Export.cpp b/src/ExchangeAPI/ExchangeAPI_Export.cpp index 2d764635a..87f51426c 100644 --- a/src/ExchangeAPI/ExchangeAPI_Export.cpp +++ b/src/ExchangeAPI/ExchangeAPI_Export.cpp @@ -68,7 +68,7 @@ ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr& std::list aListOfOneSel; aListOfOneSel.push_back(theResult); fillAttribute(aListOfOneSel, - theFeature->selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID())); + theFeature->selectionList(ExchangePlugin_ExportFeature::XAO_SELECTION_LIST_ID())); execute(); apply(); // finish operation to make sure the export is done on the current state of the history } @@ -130,7 +130,7 @@ void ExchangeAPI_Export::dump(ModelHighAPI_Dumper& theDumper) const correctSeparators(aTmpXAOFile); theDumper << "exportToXAO(" << aDocName << ", '" << aTmpXAOFile << "'" ; AttributeSelectionListPtr aShapeSelected = - aBase->selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID()); + aBase->selectionList(ExchangePlugin_ExportFeature::XAO_SELECTION_LIST_ID()); if (aShapeSelected->isInitialized() && aShapeSelected->size() == 1) { theDumper<<", "<value(0); } diff --git a/src/ExchangePlugin/CMakeLists.txt b/src/ExchangePlugin/CMakeLists.txt index 83a6dd570..27b3961f0 100644 --- a/src/ExchangePlugin/CMakeLists.txt +++ b/src/ExchangePlugin/CMakeLists.txt @@ -106,6 +106,7 @@ ADD_UNIT_TESTS( TestExport.py Test2290.py Test2459.py + Test18710.py TestExportToXAOWithFields.py TestExportToXAOWithGroupNotUpdated.py TestExport_FiniteValidator.py diff --git a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp index 4eedccc26..05826f0a8 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp @@ -94,6 +94,8 @@ void ExchangePlugin_ExportFeature::initAttributes() ModelAPI_AttributeString::typeId()); data()->addAttribute(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(ExchangePlugin_ExportFeature::XAO_SELECTION_LIST_ID(), + ModelAPI_AttributeSelectionList::typeId()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID()); @@ -101,6 +103,25 @@ void ExchangePlugin_ExportFeature::initAttributes() ExchangePlugin_ExportFeature::XAO_AUTHOR_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), + ExchangePlugin_ExportFeature::XAO_SELECTION_LIST_ID()); + + // to support previous version of document, move the selection list + // if the type of export operation is XAO + AttributeStringPtr aTypeAttr = string(EXPORT_TYPE_ID()); + if (aTypeAttr->isInitialized() && aTypeAttr->value() == "XAO") { + AttributeSelectionListPtr aSelList = selectionList(SELECTION_LIST_ID()); + int aSelListSize = aSelList->size(); + AttributeSelectionListPtr aXAOSelList = selectionList(XAO_SELECTION_LIST_ID()); + if (aSelListSize > 0 && aXAOSelList->size() == 0) { + for (int i = 0; i < aSelListSize; ++i) { + AttributeSelectionPtr aSelection = aSelList->value(i); + aXAOSelList->append(aSelection->context(), aSelection->value()); + } + aXAOSelList->setSelectionType(aSelList->selectionType()); + } + aSelList->clear(); + } } void ExchangePlugin_ExportFeature::attributeChanged(const std::string& theID) @@ -316,7 +337,7 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName) std::list aDocuments; /// documents of Parts selected and used in export std::map aDocTrsf; /// translation of the part - AttributeSelectionListPtr aSelection = selectionList(SELECTION_LIST_ID()); + AttributeSelectionListPtr aSelection = selectionList(XAO_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++) { @@ -577,7 +598,7 @@ bool ExchangePlugin_ExportFeature::isMacro() const if (aFormat == "XAO") { // on export to GEOm the selection attribute is filled - this is // an exceptional case where export to XAO feature must be kept - AttributeSelectionListPtr aList = aThis->selectionList(SELECTION_LIST_ID()); + AttributeSelectionListPtr aList = aThis->selectionList(XAO_SELECTION_LIST_ID()); return !aList->isInitialized() || aList->size() == 0; } return true; diff --git a/src/ExchangePlugin/ExchangePlugin_ExportFeature.h b/src/ExchangePlugin/ExchangePlugin_ExportFeature.h index c0a79a8c5..aa24b3d49 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportFeature.h +++ b/src/ExchangePlugin/ExchangePlugin_ExportFeature.h @@ -72,6 +72,12 @@ public: static const std::string MY_SELECTION_LIST_ID("selection_list"); return MY_SELECTION_LIST_ID; } + /// attribute name of xao selection list + inline static const std::string& XAO_SELECTION_LIST_ID() + { + static const std::string MY_SELECTION_LIST_ID("xao_selection_list"); + return MY_SELECTION_LIST_ID; + } /// attribute name of author for XAO format inline static const std::string& XAO_AUTHOR_ID() { diff --git a/src/ExchangePlugin/Test/Test18710.py b/src/ExchangePlugin/Test/Test18710.py new file mode 100644 index 000000000..93a1fb944 --- /dev/null +++ b/src/ExchangePlugin/Test/Test18710.py @@ -0,0 +1,56 @@ +# Copyright (C) 2020 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 +# + +from salome.shaper import model + +from GeomAPI import * +from ModelAPI import * +from SketchAPI import * + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10) +Export_1 = model.exportToXAO(Part_1_doc, '/tmp/shaper_vcnhioqf.xao', model.selection("SOLID", "Cylinder_1_1"), 'XAO') +Export_1.setName("XAO") +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +model.end() + +model.testNbResults(Part_1, 1) +model.testNbSubResults(Part_1, [0]) +model.testNbSubShapes(Part_1, GeomAPI_Shape.SOLID, [2]) +model.testNbSubShapes(Part_1, GeomAPI_Shape.FACE, [9]) +model.testNbSubShapes(Part_1, GeomAPI_Shape.EDGE, [30]) +model.testNbSubShapes(Part_1, GeomAPI_Shape.VERTEX, [60]) +model.testResultsVolumes(Part_1, [1785.39816339744857]) + +model.begin() +ModelAPI.removeFeaturesAndReferences(FeatureSet([Cylinder_1.feature()])) +model.end() + +model.testNbResults(Part_1, 1) +model.testNbSubResults(Part_1, [0]) +model.testNbSubShapes(Part_1, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Part_1, GeomAPI_Shape.FACE, [6]) +model.testNbSubShapes(Part_1, GeomAPI_Shape.EDGE, [24]) +model.testNbSubShapes(Part_1, GeomAPI_Shape.VERTEX, [48]) +model.testResultsVolumes(Part_1, [1000]) + +assert(model.checkPythonDump())