Salome HOME
Use independent attribute for the shapes exported to XAO for correct processing the...
authorazv <azv@opencascade.com>
Thu, 13 Feb 2020 10:35:14 +0000 (13:35 +0300)
committerazv <azv@opencascade.com>
Thu, 13 Feb 2020 10:39:39 +0000 (13:39 +0300)
src/ExchangeAPI/ExchangeAPI_Export.cpp
src/ExchangePlugin/CMakeLists.txt
src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp
src/ExchangePlugin/ExchangePlugin_ExportFeature.h
src/ExchangePlugin/Test/Test18710.py [new file with mode: 0644]

index 2d764635a27b543c56fcc5f751cba48a17417922..87f51426c68b289fc29c24d1795f526da9a9bc58 100644 (file)
@@ -68,7 +68,7 @@ ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>&
   std::list<ModelHighAPI_Selection> 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<<", "<<aShapeSelected->value(0);
     }
index 83a6dd5702c79a2945df917a20c5df4736633365..27b3961f0452db63fe110ca55cc72239242b9dba 100644 (file)
@@ -106,6 +106,7 @@ ADD_UNIT_TESTS(
   TestExport.py
   Test2290.py
   Test2459.py
+  Test18710.py
   TestExportToXAOWithFields.py
   TestExportToXAOWithGroupNotUpdated.py
   TestExport_FiniteValidator.py
index 4eedccc2604e1078446fe24cbd99dbde9ea37b5a..05826f0a8833f8ecb8878557a9001912fd6a028f 100644 (file)
@@ -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<DocumentPtr> aDocuments; /// documents of Parts selected and used in export
   std::map<DocumentPtr, GeomTrsfPtr> 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;
index c0a79a8c5ea092bcbbba0d7fff00d3a97f0d6d7a..aa24b3d4980d62c72e4a07851f7b4d3ac5067cd1 100644 (file)
@@ -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 (file)
index 0000000..93a1fb9
--- /dev/null
@@ -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())