From b23d37c1779e419ba188fb57675f327158dcbcb3 Mon Sep 17 00:00:00 2001 From: jfa Date: Thu, 12 Sep 2024 22:10:35 +0100 Subject: [PATCH] Import/export documentation has been extended --- src/ExchangeAPI/ExchangeAPI_Export.h | 3 + src/ExchangePlugin/doc/TUI_exportPart.rst | 12 +++ .../doc/examples/save_session.py | 88 +++++++++++++++++++ src/ExchangePlugin/doc/exportFeature.rst | 19 ++++ 4 files changed, 122 insertions(+) create mode 100644 src/ExchangePlugin/doc/examples/save_session.py diff --git a/src/ExchangeAPI/ExchangeAPI_Export.h b/src/ExchangeAPI/ExchangeAPI_Export.h index 4500c95db..c36fb7e53 100644 --- a/src/ExchangeAPI/ExchangeAPI_Export.h +++ b/src/ExchangeAPI/ExchangeAPI_Export.h @@ -194,6 +194,9 @@ PyObject* exportToXAOMem(const std::shared_ptr & thePart, /** \ingroup CPPHighAPI * \brief Export selected features or the whole part to the binary file. + * \param thePart Part document + * \param theFilePath File to store the part (recommended extension is .shaperpart) + * \param Selected objects list. If empty, the whole part is saved. */ EXCHANGEAPI_EXPORT void exportPart( const std::shared_ptr & thePart, diff --git a/src/ExchangePlugin/doc/TUI_exportPart.rst b/src/ExchangePlugin/doc/TUI_exportPart.rst index 58e70a79a..391f8fb62 100644 --- a/src/ExchangePlugin/doc/TUI_exportPart.rst +++ b/src/ExchangePlugin/doc/TUI_exportPart.rst @@ -10,3 +10,15 @@ Export File :download:`Download this script ` + + .. _tui_save_session: + +Save Session +============ + +.. literalinclude:: examples/save_session.py + :linenos: + :language: python + +:download:`Download this script ` + diff --git a/src/ExchangePlugin/doc/examples/save_session.py b/src/ExchangePlugin/doc/examples/save_session.py new file mode 100644 index 000000000..7ab18a591 --- /dev/null +++ b/src/ExchangePlugin/doc/examples/save_session.py @@ -0,0 +1,88 @@ +# Copyright (C) 2021-2024 CEA, EDF +# +# 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 +# + +import os +from salome.shaper import model + +from tempfile import TemporaryDirectory +from ModelAPI import * +from GeomAPI import GeomAPI_Shape +import PrimitivesAPI + +model.begin() +partSet = model.moduleDocument() + +### Create Part 1 +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) + +### Create Part 2 +Part_2 = model.addPart(partSet) +Part_2_doc = Part_2.document() +Cyl_1 = model.addCylinder(Part_2_doc, 10, 13) + +model.end() + +model.checkResult(Box_1, model, 1, [0], [1], [6], [24], [48]) +model.testResultsVolumes(Box_1, [1000]) +model.checkResult(Cyl_1, model, 1, [0], [1], [3], [6], [12]) +model.testResultsVolumes(Cyl_1, [4084.07045]) + +# Save/load document +with TemporaryDirectory() as tmp_dir: + aSession = ModelAPI_Session.get() + + # Save + aFiles = StringList() + aSession.save(tmp_dir, aFiles) + + # Close and Load again + aSession.closeAll() + assert(aSession.load(tmp_dir)) + + # Check data + partSet = aSession.moduleDocument() + assert(partSet.size("Parts") == 2) + + # Access data of Part 1 + aPart1 = modelAPI_ResultPart(objectToResult(partSet.object("Parts", 0))) + aSession.startOperation() + aPart1.activate() + aSession.finishOperation() + aPart1Doc = aPart1.partDoc() + aBoxF = objectToFeature(aPart1Doc.objectByName("Features", "Box_1")) + aBox = PrimitivesAPI.PrimitivesAPI_Box(aBoxF) + model.checkResult(aBox, model, 1, [0], [1], [6], [24], [48]) + model.testResultsVolumes(aBox, [1000]) + + aSession.startOperation() + aSession.setActiveDocument(partSet) + aSession.finishOperation() + + # Access data of Part 2 + aPart2 = modelAPI_ResultPart(objectToResult(partSet.object("Parts", 1))) + aSession.startOperation() + aPart2.activate() + aSession.finishOperation() + aPart2Doc = aPart2.partDoc() + aCylF = objectToFeature(aPart2Doc.objectByName("Features", "Cylinder_1")) + aCyl = PrimitivesAPI.PrimitivesAPI_Cylinder(aCylF) + model.checkResult(aCyl, model, 1, [0], [1], [3], [6], [12]) + model.testResultsVolumes(aCyl, [4084.07045]) diff --git a/src/ExchangePlugin/doc/exportFeature.rst b/src/ExchangePlugin/doc/exportFeature.rst index e8f88c2d3..a14bc3449 100644 --- a/src/ExchangePlugin/doc/exportFeature.rst +++ b/src/ExchangePlugin/doc/exportFeature.rst @@ -18,6 +18,23 @@ The **Export file** dialog will be opened: Specify file name and press **Save** button to export the file. **Cancel** button cancels the operation. +**TUI Command**: + +One cannot export entire PartSet into a single file from python interface, but it is possible to save Shaper session contents into a directory: + +.. py:function:: ModelAPI_Session.save(FolderNameString, FilesList) + + :param string: The folder name to save in + :param list: A list of stored files (output) + +Result +"""""" + +The Result of operation is some exported files. + +**See Also** a sample TUI Script of :ref:`tui_save_session` operation. + + Export Part ----------- @@ -58,6 +75,8 @@ If the PartSet is active, only results (construction elements) of this PartSet m :param string: The file name :param list: A list of exporting objects, if necessary + *Note:* You can also pass the entire PartSet as the first argument to export features created in it (those that are at global level, not within parts). + Result """""" -- 2.39.2