* Python API for export/import of features.
* Fix the problem when exporting to unavailable directory.
#include "ExchangeAPI_Export.h"
//--------------------------------------------------------------------------------------
+#include <ExchangePlugin_ExportPart.h>
+//--------------------------------------------------------------------------------------
#include <ModelAPI_Document.h>
#include <ModelAPI_Feature.h>
#include <ModelHighAPI_Tools.h>
return ExportPtr(new ExchangeAPI_Export(aFeature, theFilePath, theSelectedShape, "XAO"));
}
+void exportPart(const std::shared_ptr<ModelAPI_Document> & thePart,
+ const std::string & theFilePath,
+ const std::list<ModelHighAPI_Selection> & theSelected)
+{
+ FeaturePtr aFeature = thePart->addFeature(ExchangePlugin_ExportPart::ID());
+ aFeature->string(ExchangePlugin_ExportPart::FILE_PATH_ID())->setValue(theFilePath);
+ if (!theSelected.empty()) {
+ fillAttribute(theSelected,
+ aFeature->selectionList(ExchangePlugin_ExportPart::SELECTION_LIST_ID()));
+ }
+ // restart transaction to execute and delete the marcro-feature
+ apply();
+}
//--------------------------------------------------------------------------------------
const std::string & theAuthor = std::string(),
const std::string & theGeometryName = std::string());
+
+/** \ingroup CPPHighAPI
+ * \brief Export selected features or the whole part to the binary file.
+ */
+EXCHANGEAPI_EXPORT void exportPart(
+ const std::shared_ptr<ModelAPI_Document> & thePart,
+ const std::string & theFilePath,
+ const std::list<ModelHighAPI_Selection> & theSelected = std::list<ModelHighAPI_Selection>());
+
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
#endif /* SRC_EXCHANGEAPI_EXCHANGEAPI_EXPORT_H_ */
#include "ExchangeAPI_Import.h"
//--------------------------------------------------------------------------------------
+#include <ExchangePlugin_ImportPart.h>
+//--------------------------------------------------------------------------------------
#include <ModelHighAPI_Dumper.h>
+#include <ModelHighAPI_Services.h>
#include <ModelHighAPI_Tools.h>
//--------------------------------------------------------------------------------------
#include <algorithm>
std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ExchangeAPI_Import::ID());
return ImportPtr(new ExchangeAPI_Import(aFeature, theFilePath));
}
+
+void importPart(const std::shared_ptr<ModelAPI_Document> & thePart,
+ const std::string & theFilePath,
+ const ModelHighAPI_Reference & theAfterThis)
+{
+ static const bool THE_VISIBLE_FEATURE = false;
+ FeaturePtr aCurrentFeature;
+ if (theAfterThis.feature()) {
+ aCurrentFeature = thePart->currentFeature(THE_VISIBLE_FEATURE);
+ thePart->setCurrentFeature(theAfterThis.feature(), THE_VISIBLE_FEATURE);
+ }
+
+ FeaturePtr aFeature = thePart->addFeature(ExchangePlugin_ImportPart::ID());
+ aFeature->string(ExchangePlugin_ImportPart::FILE_PATH_ID())->setValue(theFilePath);
+ // restart transaction to execute and delete the marcro-feature
+ apply();
+
+ // restore current feature
+ if (aCurrentFeature)
+ thePart->setCurrentFeature(aCurrentFeature, THE_VISIBLE_FEATURE);
+}
#include <ModelHighAPI_Interface.h>
#include <ModelHighAPI_Macro.h>
+#include <ModelHighAPI_Reference.h>
+#include <ModelHighAPI_Selection.h>
//--------------------------------------------------------------------------------------
/**\class ExchangeAPI_Import
* \ingroup CPPHighAPI
ImportPtr addImport(const std::shared_ptr<ModelAPI_Document> & thePart,
const std::string & theFilePath);
+/** \ingroup CPPHighAPI
+ * \brief Import features from the file to the document after the current feature (or to the end).
+ */
+EXCHANGEAPI_EXPORT void importPart(
+ const std::shared_ptr<ModelAPI_Document> & thePart,
+ const std::string & theFilePath,
+ const ModelHighAPI_Reference & theAfterThis = ModelHighAPI_Reference());
+
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
#endif /* SRC_EXCHANGEAPI_EXCHANGEAPI_IMPORT_H_ */
{
data()->addAttribute(FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
data()->addAttribute(FILE_FORMAT_ID(), ModelAPI_AttributeString::typeId());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FILE_FORMAT_ID());
data()->addAttribute(SELECTION_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), SELECTION_LIST_ID());
}
#include <TopExp_Explorer.hxx>
#include <TopoDS_Shape.hxx>
+#include <OSD_Directory.hxx>
#include <OSD_File.hxx>
#include <OSD_Path.hxx>
+#include <OSD_Protection.hxx>
#include <CDF_Session.hxx>
#include <CDF_Directory.hxx>
+#include <UTL.hxx>
#include <climits>
#ifndef WIN32
{
PCDM_StoreStatus aStatus;
try {
+ // create the directory to save the document
+ OSD_Path aPathToFile = UTL::Path(theFilename);
+ aPathToFile.SetName("");
+ aPathToFile.SetExtension("");
+ OSD_Directory aBaseDir(aPathToFile);
+ if (!aBaseDir.Exists())
+ aBaseDir.Build(OSD_Protection());
+ // save the document
aStatus = theApp->SaveAs(theDoc, theFilename);
}
catch (Standard_Failure const& anException) {
"""Package for Exchange plugin for the Parametric Geometry API of the Modeler.
"""
-from ExchangeAPI import addImport, exportToFile, exportToXAO
\ No newline at end of file
+from ExchangeAPI import addImport, exportToFile, exportToXAO
+from ExchangeAPI import exportPart, importPart
+
+from .tools import *
--- /dev/null
+# Copyright (C) 2019 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
+#
+
+import os
+import tempfile
+
+# Generate temporary file name
+def tempFileName():
+ tempDir = tempfile.TemporaryDirectory()
+ return os.path.join(tempDir.name, "temp.shaperpart")
+
+def removeFile(theFilename):
+ try: os.remove(theFilename)
+ except OSError: pass
+ assert not os.path.exists(theFilename), "Cannot remove file {}".format(theFilename)