ADD_TEST(${TEST_NAME} python ${PYTHON_TEST_DRIVER} ${TIMEOUT} ${tfile}.py)
SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}")
ENDFOREACH()
+
+FOREACH(tfile ${TEST_NAMES_ADV})
+ SET(TEST_NAME ${COMPONENT_NAME}_${tfile})
+ ADD_TEST(${TEST_NAME} python ${PYTHON_TEST_DRIVER} ${TIMEOUT} ${tfile}.py)
+ SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${SALOME_TEST_LABEL_ADV}")
+ENDFOREACH()
--- /dev/null
+# Copyright (C) 2014-2022 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
+#
+
+"""
+ TestExportXAOMem.py
+ Unit test of ExchangePlugin_ExportFeature class
+"""
+
+#=========================================================================
+# Initialization of the test
+#=========================================================================
+
+import salome
+salome.standalone()
+salome.salome_init(1)
+
+import os
+import math
+import tempfile
+
+from ModelAPI import *
+from GeomAlgoAPI import *
+from salome.shaper import model
+
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New()
+
+#=========================================================================
+# test Export XAO to memory buffer (bytes array)
+#=========================================================================
+def testExportXAOMem():
+
+ model.begin()
+ partSet = model.moduleDocument()
+ Part_1 = model.addPart(partSet)
+ Part_1_doc = Part_1.document()
+ Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
+ Group_1 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Box_1_1/Top")])
+ Box_2 = model.addBox(Part_1_doc, 20, 20, 20)
+ model.do()
+
+ # Export to memory buffer (bytes array)
+ Export_buff1 = model.exportToXAOMem(Part_1_doc, model.selection("SOLID", "Box_1_1"), 'XAO')
+ Export_buff2 = model.exportToXAOMem(Part_1_doc, model.selection("SOLID", "Box_2_1"), 'XAO')
+ model.end()
+
+ # check buffer length
+ # export to XAO file and compare size of file and size of buffer
+ #assert(len(Export_buff1) == 4392)
+ #assert(len(Export_buff2) == 4287)
+ with tempfile.TemporaryDirectory() as tmpdirname:
+ tmpfilename = os.path.join(tmpdirname, "Box.xao")
+ Export_1 = model.exportToXAO(Part_1_doc, tmpfilename, model.selection("SOLID", "Box_1_1"), 'XAO')
+ file_stats = os.stat(tmpfilename)
+ assert(len(Export_buff1) == file_stats.st_size)
+
+ Export_2 = model.exportToXAO(Part_1_doc, tmpfilename, model.selection("SOLID", "Box_2_1"), 'XAO')
+ file_stats = os.stat(tmpfilename)
+ assert(len(Export_buff2) == file_stats.st_size)
+ pass
+
+ # Import to GEOM
+ (imported1, b1, [], [Group_1], []) = geompy.ImportXAOMem(Export_buff1, theName="Box1")
+ (imported2, b2, [], [] , []) = geompy.ImportXAOMem(Export_buff2, theName="Box2")
+
+ # Check result 1
+ aTol = 1.e-7
+ Props = geompy.BasicProperties(b1)
+ # surface area
+ aSurface = 600
+ assert (math.fabs(Props[1] - aSurface) < aTol), "The surface is wrong: expected = {0}, real = {1}".format(aSurface, Props[1])
+
+ Props = geompy.BasicProperties(Group_1)
+ # surface area
+ aSurface = 100
+ assert (math.fabs(Props[1] - aSurface) < aTol), "The surface is wrong: expected = {0}, real = {1}".format(aSurface, Props[1])
+
+ # Check result 2
+ Props = geompy.BasicProperties(b2)
+ # surface area
+ aSurface = 2400
+ assert (math.fabs(Props[1] - aSurface) < aTol), "The surface is wrong: expected = {0}, real = {1}".format(aSurface, Props[1])
+
+if __name__ == '__main__':
+ #=========================================================================
+ # Export a shape into XAO memory buffer
+ #=========================================================================
+ testExportXAOMem()
+ #=========================================================================
+ # End of test
+ #=========================================================================
--- /dev/null
+# Copyright (C) 2022-2023 CEA, EDF, OPEN CASCADE
+#
+# 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
+#
+
+"""
+ TestImportXAOMem.py
+ Unit test of ExchangePlugin_ImportFeature class
+"""
+
+#=========================================================================
+# Initialization of the test
+#=========================================================================
+
+import salome
+salome.standalone()
+salome.salome_init(1)
+
+import os
+import math
+import tempfile
+
+from ModelAPI import *
+from GeomAPI import *
+from GeomAlgoAPI import *
+from salome.shaper import model
+
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New()
+
+#=========================================================================
+# test Import XAO from memory buffer (bytes array)
+#=========================================================================
+def testImportXAOMem():
+
+ # Export from GEOM
+ Box_1 = geompy.MakeBoxDXDYDZ(10, 10, 10)
+ Group_1 = geompy.CreateGroup(Box_1, geompy.ShapeType["FACE"])
+ geompy.UnionIDs(Group_1, [33])
+ geompy.addToStudy( Box_1, 'Box_1_1' )
+ geompy.addToStudyInFather( Box_1, Group_1, 'Group_1' )
+
+ Export_buff = geompy.ExportXAOMem(Box_1, [Group_1], [], "XAO")
+
+ # check buffer length
+ # export to XAO file and compare size of file and size of buffer
+ #assert(len(Export_buff) == 4392)
+ with tempfile.TemporaryDirectory() as tmpdirname:
+ tmpfilename = os.path.join(tmpdirname, "Box.xao")
+ exported = geompy.ExportXAO(Box_1, [Group_1], [], "XAO", tmpfilename, "")
+ file_stats = os.stat(tmpfilename)
+ print(file_stats.st_size)
+ assert(len(Export_buff) == file_stats.st_size)
+ pass
+
+ # Import to SHAPER
+ model.begin()
+ partSet = model.moduleDocument()
+ Part_1 = model.addPart(partSet)
+ Part_1_doc = Part_1.document()
+
+ Import_1 = model.addImportXAOMem(Part_1_doc, Export_buff)
+ model.do()
+ Import_1.subFeature(0).setName("Group_1")
+ Import_1.subFeature(0).result().setName("Group_1")
+ Import_1.setName("Box_1")
+ Import_1.result().setName("Box_1_1")
+
+ model.end()
+
+ # Check result
+ assert(Import_1.feature().error() == "")
+ model.testNbResults(Import_1, 1)
+ model.testNbSubResults(Import_1, [0])
+ model.testNbSubShapes(Import_1, GeomAPI_Shape.SOLID, [1])
+ model.testNbSubShapes(Import_1, GeomAPI_Shape.FACE, [6])
+ model.testNbSubShapes(Import_1, GeomAPI_Shape.EDGE, [24])
+ model.testNbSubShapes(Import_1, GeomAPI_Shape.VERTEX, [48])
+ model.testResultsVolumes(Import_1, [1000])
+ model.testResultsAreas(Import_1, [600])
+
+ # check groups are the same in both parts
+ assert(Part_1_doc.size("Groups") == 1)
+ res1 = objectToResult(Part_1_doc.object("Groups", 0))
+ assert(res1 is not None)
+ res1It = GeomAPI_ShapeExplorer(res1.shape(), GeomAPI_Shape.FACE)
+ assert(res1It.more())
+ shape1 = res1It.current()
+ res1It.next()
+ assert(not res1It.more())
+ p1 = res1.shape().middlePoint()
+ aTol = 1.e-7
+ assert(math.fabs(p1.x() - 5) <= aTol and math.fabs(p1.y() - 5) <= aTol and math.fabs(p1.z() - 10) <= aTol), "({}, {}, {}) != ({}, {}, {})".format(p1.x(), p1.y(), p1.z(), 5, 5, 10)
+
+if __name__ == '__main__':
+ #=========================================================================
+ # Import a shape from XAO memory buffer
+ #=========================================================================
+ testImportXAOMem()
+ #=========================================================================
+ # End of test
+ #=========================================================================
TestImportSTL
TestImportSTEP
)
+
+SET(TEST_NAMES_ADV
+ TestExportXAOMem
+ TestImportXAOMem
+)
)
SET(PROJECT_LIBRARIES
+ Locale
ModelAPI
ModelHighAPI
GeomAlgoAPI
INCLUDE_DIRECTORIES(
${PROJECT_SOURCE_DIR}/src/Events
+ ${PROJECT_SOURCE_DIR}/src/Locale
${PROJECT_SOURCE_DIR}/src/ModelAPI
${PROJECT_SOURCE_DIR}/src/ModelHighAPI
${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI
//--------------------------------------------------------------------------------------
#include <ExchangePlugin_ExportPart.h>
//--------------------------------------------------------------------------------------
+#include <Locale_Convert.h>
+//--------------------------------------------------------------------------------------
#include <ModelAPI_Document.h>
#include <ModelAPI_Feature.h>
#include <ModelHighAPI_Tools.h>
#include <ModelHighAPI_Services.h>
#include <ModelHighAPI_Selection.h>
//--------------------------------------------------------------------------------------
+#include <algorithm>
+//--------------------------------------------------------------------------------------
ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature)
: ModelHighAPI_Interface(theFeature)
apply(); // finish operation to make sure the export is done on the current state of the history
}
-
-
+/// Constructor with values for XAO of selected result export.
ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature,
- const std::string & theFilePath, const ModelHighAPI_Selection& theResult,
- const std::string & theAuthor, const std::string & theGeometryName)
+ const std::string & theFilePath,
+ const ModelHighAPI_Selection& theResult,
+ const std::string & theAuthor,
+ const std::string & theGeometryName)
: ModelHighAPI_Interface(theFeature)
{
initialize();
apply(); // finish operation to make sure the export is done on the current state of the history
}
-
+/// Constructor with values for XAO of selected result export to memory buffer.
+ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const ModelHighAPI_Selection& theResult,
+ const std::string & theAuthor,
+ const std::string & theGeometryName)
+ : ModelHighAPI_Interface(theFeature)
+{
+ initialize();
+ fillAttribute("XAOMem", theFeature->string(ExchangePlugin_ExportFeature::EXPORT_TYPE_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<ModelHighAPI_Selection> aListOfOneSel;
+ aListOfOneSel.push_back(theResult);
+ fillAttribute(aListOfOneSel,
+ theFeature->selectionList(ExchangePlugin_ExportFeature::XAO_SELECTION_LIST_ID()));
+ execute(true);
+ 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<ModelAPI_Feature>& theFeature,
FeaturePtr aBase = feature();
const std::string& aDocName = theDumper.name(aBase->document());
- theDumper << aBase << " = model.";
-
std::string exportType = aBase->string(ExchangePlugin_ExportFeature::EXPORT_TYPE_ID())->value();
+ if (exportType == "XAOMem") {
+ std::string aGeometryName =
+ aBase->string(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID())->value();
+
+ theDumper << "aXAOBuff";
+ std::string aGeometryNamePy;
+ if (! aGeometryName.empty()) {
+ aGeometryNamePy = aGeometryName;
+ }
+ else {
+ aGeometryNamePy = Locale::Convert::toString(aBase->data()->name());
+ }
+ if (! aGeometryNamePy.empty()) {
+ // add shape name
+ std::replace(aGeometryNamePy.begin(), aGeometryNamePy.end(), ' ', '_');
+ theDumper << "_" << aGeometryNamePy;
+ }
+ theDumper << " = model.exportToXAOMem(" << aDocName;
+ AttributeSelectionListPtr aShapeSelected =
+ aBase->selectionList(ExchangePlugin_ExportFeature::XAO_SELECTION_LIST_ID());
+ if (aShapeSelected->isInitialized() && aShapeSelected->size() == 1) {
+ theDumper << ", " << aShapeSelected->value(0);
+ }
+
+ std::string theAuthor = aBase->string(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID())->value();
+ if (! theAuthor.empty())
+ theDumper << ", '" << theAuthor << "'";
+ if (! aGeometryName.empty())
+ theDumper << ", '" << aGeometryName << "'";
+ theDumper << ")" << std::endl;
+ return;
+ }
+
+ theDumper << aBase << " = model.";
+
if (exportType == "XAO") {
std::string aTmpXAOFile =
- aBase->string(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID())->value();
+ aBase->string(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID())->value();
correctSeparators(aTmpXAOFile);
theDumper << "exportToXAO(" << aDocName << ", '" << aTmpXAOFile << "'" ;
AttributeSelectionListPtr aShapeSelected =
if (! theAuthor.empty())
theDumper << ", '" << theAuthor << "'";
std::string theGeometryName =
- aBase->string(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID())->value();
+ aBase->string(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID())->value();
if (! theGeometryName.empty())
theDumper << ", '" << theGeometryName << "'";
theDumper << ")" << std::endl;
}
ExportPtr exportToXAO(const std::shared_ptr<ModelAPI_Document> & thePart,
- const std::string & theFilePath, const ModelHighAPI_Selection& theSelectedShape,
- const std::string & /*theAuthor*/, const std::string & /*theGeometryName*/)
+ 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<ModelAPI_Feature> aFeature =
return ExportPtr(new ExchangeAPI_Export(aFeature, theFilePath, theSelectedShape, "XAO"));
}
+PyObject* exportToXAOMem(const std::shared_ptr<ModelAPI_Document> & thePart,
+ 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<ModelAPI_Feature> aFeature =
+ thePart->addFeature(ExchangePlugin_ExportFeature::ID());
+ ExportPtr aXAOExportAPI (new ExchangeAPI_Export
+ (aFeature, theSelectedShape, theAuthor, theGeometryName));
+ std::string aBuff = aFeature->string(ExchangePlugin_ExportFeature::MEMORY_BUFFER_ID())->value();
+ return PyBytes_FromString(aBuff.c_str());
+}
+
void exportPart(const std::shared_ptr<ModelAPI_Document> & thePart,
const std::string & theFilePath,
const std::list<ModelHighAPI_Selection> & theSelected)
#include <ModelHighAPI_Macro.h>
#include <ExchangePlugin_ExportFeature.h>
+
+#include <Python.h>
+
//--------------------------------------------------------------------------------------
class ModelHighAPI_Selection;
class ModelHighAPI_Double;
/// Constructor with values for STL of selected result export.
EXCHANGEAPI_EXPORT
- explicit ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature,
- const std::string & theFilePath,
- const ModelHighAPI_Selection& theSelectedShape,
- const ModelHighAPI_Double& theDeflectionRelative ,
- const ModelHighAPI_Double& theDeflectionAbsolute,
- const bool theIsRelative,
- const bool theIsASCII);
+ explicit ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::string & theFilePath,
+ const ModelHighAPI_Selection& theSelectedShape,
+ const ModelHighAPI_Double& theDeflectionRelative ,
+ const ModelHighAPI_Double& theDeflectionAbsolute,
+ const bool theIsRelative,
+ const bool theIsASCII);
/// Constructor with values for XAO of selected result export.
EXCHANGEAPI_EXPORT
- explicit ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature,
- const std::string & theFilePath,
- const ModelHighAPI_Selection& theResult,
- const std::string & theAuthor,
- const std::string & theGeometryName = std::string());
+ explicit ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::string & theFilePath,
+ const ModelHighAPI_Selection& theResult,
+ const std::string & theAuthor,
+ const std::string & theGeometryName = std::string());
+
+ /// Constructor with values for XAO of selected result export to memory buffer.
+ EXCHANGEAPI_EXPORT
+ explicit ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ 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
EXCHANGEAPI_EXPORT
virtual ~ExchangeAPI_Export();
- INTERFACE_15(ExchangePlugin_ExportFeature::ID(),
- exportType, ExchangePlugin_ExportFeature::EXPORT_TYPE_ID(),
- ModelAPI_AttributeString, /** ExportType */,
- filePath, ExchangePlugin_ExportFeature::FILE_PATH_ID(),
- ModelAPI_AttributeString, /** file path */,
- xaoFilePath, ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID(),
- ModelAPI_AttributeString, /** xao_file_path */,
- fileFormat, ExchangePlugin_ExportFeature::FILE_FORMAT_ID(),
- ModelAPI_AttributeString, /** file format */,
- selectionList, ExchangePlugin_ExportFeature::SELECTION_LIST_ID(),
- ModelAPI_AttributeString, /** selection list */,
- xaoAuthor, ExchangePlugin_ExportFeature::XAO_AUTHOR_ID(),
- ModelAPI_AttributeString, /** xao author */,
- xaoGeometryName, ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID(),
- ModelAPI_AttributeString, /** xao geometry name */,
- stlFilePath, ExchangePlugin_ExportFeature::STL_FILE_PATH_ID(),
- ModelAPI_AttributeString, /** stl_file_path */,
- stlobjectselected, ExchangePlugin_ExportFeature::STL_OBJECT_SELECTED(),
- ModelAPI_AttributeSelection, /** Object selected to export in stl file*/,
- stldeflectionType, ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE(),
- ModelAPI_AttributeString, /** Type of the defelection */,
- stlrelative, ExchangePlugin_ExportFeature::STL_RELATIVE(),
- ModelAPI_AttributeDouble, /** Relative*/,
- stlabsolute, ExchangePlugin_ExportFeature::STL_ABSOLUTE(),
- ModelAPI_AttributeDouble, /** Absolute */,
- stlfileType, ExchangePlugin_ExportFeature::STL_FILE_TYPE(),
- ModelAPI_AttributeString, /** Type of the stl file*/,
- stldeflectionTypeabsolute,
+ INTERFACE_16(ExchangePlugin_ExportFeature::ID(),
+ exportType, ExchangePlugin_ExportFeature::EXPORT_TYPE_ID(),
+ ModelAPI_AttributeString, /** ExportType */,
+ filePath, ExchangePlugin_ExportFeature::FILE_PATH_ID(),
+ ModelAPI_AttributeString, /** file path */,
+ xaoFilePath, ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID(),
+ ModelAPI_AttributeString, /** xao_file_path */,
+ fileFormat, ExchangePlugin_ExportFeature::FILE_FORMAT_ID(),
+ ModelAPI_AttributeString, /** file format */,
+ selectionList, ExchangePlugin_ExportFeature::SELECTION_LIST_ID(),
+ ModelAPI_AttributeString, /** selection list */,
+ xaoAuthor, ExchangePlugin_ExportFeature::XAO_AUTHOR_ID(),
+ ModelAPI_AttributeString, /** xao author */,
+ xaoGeometryName, ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID(),
+ ModelAPI_AttributeString, /** xao geometry name */,
+ stlFilePath, ExchangePlugin_ExportFeature::STL_FILE_PATH_ID(),
+ ModelAPI_AttributeString, /** stl_file_path */,
+ stlobjectselected, ExchangePlugin_ExportFeature::STL_OBJECT_SELECTED(),
+ ModelAPI_AttributeSelection, /** Object selected to export in stl file*/,
+ stldeflectionType, ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE(),
+ ModelAPI_AttributeString, /** Type of the defelection */,
+ stlrelative, ExchangePlugin_ExportFeature::STL_RELATIVE(),
+ ModelAPI_AttributeDouble, /** Relative*/,
+ stlabsolute, ExchangePlugin_ExportFeature::STL_ABSOLUTE(),
+ ModelAPI_AttributeDouble, /** Absolute */,
+ stlfileType, ExchangePlugin_ExportFeature::STL_FILE_TYPE(),
+ ModelAPI_AttributeString, /** Type of the stl file*/,
+ stldeflectionTypeabsolute,
ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE_ABSOLUTE(),
- ModelAPI_AttributeString, /** Type of the defelection */,
- stldeflectionTyperelative,
+ ModelAPI_AttributeString, /** Type of the defelection */,
+ stldeflectionTyperelative,
ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE_RELATIVE(),
- ModelAPI_AttributeString, /** Type of the defelection */)
+ ModelAPI_AttributeString, /** Type of the defelection */,
+ memoryBuff, ExchangePlugin_ExportFeature::MEMORY_BUFFER_ID(),
+ ModelAPI_AttributeString, /** Bytes*/)
/// Dump wrapped feature
EXCHANGEAPI_EXPORT
*/
EXCHANGEAPI_EXPORT
ExportPtr exportToXAO(const std::shared_ptr<ModelAPI_Document> & thePart,
- const std::string & theFilePath,
- const ModelHighAPI_Selection& theSelectedShape,
- const std::string & theAuthor = std::string(),
- const std::string & theGeometryName = std::string());
+ const std::string & theFilePath,
+ const ModelHighAPI_Selection& theSelectedShape,
+ const std::string & theAuthor = std::string(),
+ const std::string & theGeometryName = std::string());
+
+/**\ingroup CPPHighAPI
+* \brief Exports to XAO format buffer the selected result with groups parts related to it only.
+*/
+EXCHANGEAPI_EXPORT
+PyObject* exportToXAOMem(const std::shared_ptr<ModelAPI_Document> & thePart,
+ const ModelHighAPI_Selection& theSelectedShape,
+ const std::string & theAuthor = std::string(),
+ const std::string & theGeometryName = std::string());
/** \ingroup CPPHighAPI
//--------------------------------------------------------------------------------------
#include <ExchangePlugin_ImportPart.h>
//--------------------------------------------------------------------------------------
+#include <Locale_Convert.h>
+//--------------------------------------------------------------------------------------
#include <ModelHighAPI_Dumper.h>
#include <ModelHighAPI_Services.h>
#include <ModelHighAPI_Tools.h>
setFilePath(theFilePath);
}
+ExchangeAPI_Import::ExchangeAPI_Import(
+ const std::shared_ptr<ModelAPI_Feature> & theFeature,
+ const std::string & /*theFilePath*/,
+ const std::string & theBuffer)
+: ModelHighAPI_Interface(theFeature)
+{
+ if (initialize()) {
+ fillAttribute("XAOMem", myimportType);
+ fillAttribute(theBuffer, mymemoryBuffer);
+ execute();
+ }
+}
+
ExchangeAPI_Import::ExchangeAPI_Import(
const std::shared_ptr<ModelAPI_Feature> & theFeature,
const std::string & theFilePath,
std::string aPartName = theDumper.name(aBase->document());
AttributeStringPtr aImportTypeAttr =
- aBase->string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID());
+ aBase->string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID());
std::string aFormat = aImportTypeAttr->value();
- std::string aFilePath;
- if (aFormat == "STEP" || aFormat == "STP")
- {
- aFilePath = aBase->string(ExchangePlugin_ImportFeature::STEP_FILE_PATH_ID())->value();
- } else {
- aFilePath = aBase->string(ExchangePlugin_ImportFeature::FILE_PATH_ID())->value();
- }
- std::string aFrom = "\\";
- std::string aTo = "\\\\";
- for(std::size_t aPos = aFilePath.find(aFrom);
- aPos != std::string::npos;
- aPos = aFilePath.find(aFrom, aPos)) {
- aFilePath.replace(aPos, aFrom.size(), aTo);
- aPos += aTo.size();
+ if (aFormat == "XAOMem") {
+ theDumper << aBase << " = model.addImportXAOMem(" << aPartName << ", aXAOBuff";
+ std::string aGeometryNamePy = Locale::Convert::toString(aBase->data()->name());
+ if (! aGeometryNamePy.empty()) {
+ // add shape name
+ std::replace(aGeometryNamePy.begin(), aGeometryNamePy.end(), ' ', '_');
+ theDumper << "_" << aGeometryNamePy;
+ }
+ theDumper << ")" << std::endl;
}
- std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(aFilePath);
- if (anExtension == "STP" || anExtension == "STEP"){
+ else {
+ std::string aFilePath;
+ if (aFormat == "STEP" || aFormat == "STP") {
+ aFilePath = aBase->string(ExchangePlugin_ImportFeature::STEP_FILE_PATH_ID())->value();
+ } else {
+ aFilePath = aBase->string(ExchangePlugin_ImportFeature::FILE_PATH_ID())->value();
+ }
+
+ std::string aFrom = "\\";
+ std::string aTo = "\\\\";
+ for (std::size_t aPos = aFilePath.find(aFrom);
+ aPos != std::string::npos;
+ aPos = aFilePath.find(aFrom, aPos)) {
+ aFilePath.replace(aPos, aFrom.size(), aTo);
+ aPos += aTo.size();
+ }
+ std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(aFilePath);
+ if (anExtension == "STP" || anExtension == "STEP") {
theDumper << aBase << " = model.addImportSTEP(" << aPartName << ", \""
<< aFilePath << "\"" ;
theDumper << ", " << scalInterUnits()->value()
<< ", " << materials()->value()
<< ", " << colors()->value() << ")"<< std::endl;
- } else {
+ }
+ else {
theDumper << aBase << " = model.addImport(" << aPartName << ", \""
- << aFilePath << "\")" << std::endl;
+ << aFilePath << "\")" << std::endl;
+ }
}
// to make import have results
return ImportPtr(new ExchangeAPI_Import(aFeature, theFilePath));
}
+ImportPtr addImportXAOMem(const std::shared_ptr<ModelAPI_Document> & thePart,
+ PyObject* theBuffer)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ExchangeAPI_Import::ID());
+ std::string aString (PyBytes_AsString(theBuffer));
+ return ImportPtr(new ExchangeAPI_Import(aFeature, "", aString));
+}
+
ImportPtr addImportSTEP(
const std::shared_ptr<ModelAPI_Document> & thePart,
const std::string & theFilePath,
#include <ModelHighAPI_Macro.h>
#include <ModelHighAPI_Reference.h>
#include <ModelHighAPI_Selection.h>
+
+#include <Python.h>
//--------------------------------------------------------------------------------------
+
/**\class ExchangeAPI_Import
* \ingroup CPPHighAPI
* \brief Interface for Import feature
/// Constructor without values
EXCHANGEAPI_EXPORT
explicit ExchangeAPI_Import(const std::shared_ptr<ModelAPI_Feature> & theFeature);
+
/// Constructor with values
EXCHANGEAPI_EXPORT
ExchangeAPI_Import(const std::shared_ptr<ModelAPI_Feature> & theFeature,
const std::string & theFilePath);
+ /// Constructor with values for XAO import from memory buffer
+ EXCHANGEAPI_EXPORT
+ ExchangeAPI_Import(const std::shared_ptr<ModelAPI_Feature> & theFeature,
+ const std::string & theFilePath,
+ const std::string & theBuffer);
+
/// Constructor with values for Step file
EXCHANGEAPI_EXPORT
ExchangeAPI_Import(const std::shared_ptr<ModelAPI_Feature> & theFeature,
EXCHANGEAPI_EXPORT
virtual ~ExchangeAPI_Import();
- INTERFACE_6(ExchangePlugin_ImportFeature::ID(),
+ INTERFACE_7(ExchangePlugin_ImportFeature::ID(),
filePath, ExchangePlugin_ImportFeature::FILE_PATH_ID(),
ModelAPI_AttributeString, /** File path */,
importType, ExchangePlugin_ImportFeature::IMPORT_TYPE_ID(),
materials, ExchangePlugin_ImportFeature::STEP_MATERIALS_ID(),
ModelAPI_AttributeBoolean, /** Materials */,
colors, ExchangePlugin_ImportFeature::STEP_COLORS_ID(),
- ModelAPI_AttributeBoolean, /** Colors */
+ ModelAPI_AttributeBoolean, /** Colors */,
+ memoryBuffer, ExchangePlugin_ImportFeature::MEMORY_BUFFER_ID(),
+ ModelAPI_AttributeString, /** Bytes */
)
/// Set point values
ImportPtr addImport(const std::shared_ptr<ModelAPI_Document> & thePart,
const std::string & theFilePath);
+/**\ingroup CPPHighAPI
+ * \brief Create Import feature to import XAO data from bytes buffer
+ */
+EXCHANGEAPI_EXPORT
+ImportPtr addImportXAOMem(const std::shared_ptr<ModelAPI_Document> & thePart,
+ PyObject* theBuffer);
+
/**\ingroup CPPHighAPI
* \brief Create Import Step feature
*/
#include <ModelAPI_AttributeIntArray.h>
#include <ModelAPI_AttributeTables.h>
#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeBoolean.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Object.h>
data()->addAttribute(ExchangePlugin_ExportFeature::STL_FILE_TYPE(),
ModelAPI_AttributeString::typeId());
+ // export to memory buffer (implemented for XAO format only)
+ data()->addAttribute(ExchangePlugin_ExportFeature::MEMORY_BUFFER_ID(),
+ ModelAPI_AttributeString::typeId());
+
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
ExchangePlugin_ExportFeature::XAO_FILE_PATH_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());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
+ ExchangePlugin_ExportFeature::MEMORY_BUFFER_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") {
+ if (aTypeAttr->isInitialized() &&
+ (aTypeAttr->value() == "XAO" || aTypeAttr->value() == "XAOMem")) {
bool aWasBlocked = data()->blockSendAttributeUpdated(true, false);
AttributeSelectionListPtr aSelList = selectionList(SELECTION_LIST_ID());
AttributeSelectionListPtr aXAOSelList = selectionList(XAO_SELECTION_LIST_ID());
this->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID());
std::string aFormat = aFormatAttr->value();
+ bool isMemoryExport = false;
+ AttributeStringPtr aTypeAttr = string(EXPORT_TYPE_ID());
+ if (aTypeAttr->isInitialized() && aTypeAttr->value() == "XAOMem")
+ isMemoryExport = true;
+
AttributeStringPtr aFilePathAttr =
this->string(ExchangePlugin_ExportFeature::FILE_PATH_ID());
std::string aFilePath = aFilePathAttr->value();
- if (aFilePath.empty())
+ if (aFilePath.empty() && !isMemoryExport)
return;
- exportFile(aFilePath, aFormat);
+ exportFile(aFilePath, aFormat, isMemoryExport);
}
void ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
- const std::string& theFormat)
+ const std::string& theFormat,
+ const bool isMemoryExport)
{
std::string aFormatName = theFormat;
if (aFormatName.empty()) { // get default format for the extension
+ if (isMemoryExport) return;
+
// ".brep" -> "BREP"
std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFileName);
if (anExtension == "BREP" || anExtension == "BRP") {
}
if (aFormatName == "XAO") {
- exportXAO(theFileName);
+ exportXAO(theFileName, isMemoryExport);
return;
- }else if (aFormatName == "STL") {
+ } else if (aFormatName == "STL") {
exportSTL(theFileName);
return;
}
/// Returns XAO string by the value from the table
static std::string valToString(const ModelAPI_AttributeTables::Value& theVal,
- const ModelAPI_AttributeTables::ValueType& theType) {
+ const ModelAPI_AttributeTables::ValueType& theType)
+{
std::ostringstream aStr; // the resulting string value
switch(theType) {
case ModelAPI_AttributeTables::BOOLEAN:
}
-void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
+void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName,
+ const bool isMemoryExport)
{
try {
// get the name from the first result
ResultPtr aResultBody = *aResults.begin();
aGeometryName = Locale::Convert::toString(aResultBody->data()->name());
+ if (isMemoryExport) {
+ // for python dump
+ string(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID())->setValue(aGeometryName);
+ // or
+ //data()->setName(Locale::Convert::toWString(aGeometryName));
+ }
}
aXao.getGeometry()->setName(aGeometryName);
}
// exporting
- XAOExport(theFileName, &aXao, anError);
+ if (isMemoryExport) {
+ string(ExchangePlugin_ExportFeature::MEMORY_BUFFER_ID())->setValue(XAOExportMem(&aXao, anError));
+ }
+ else {
+ XAOExport(theFileName, &aXao, anError);
+ }
if (!anError.empty()) {
setError("An error occurred while exporting " + theFileName + ": " + anError);
static const std::string MY_XAO_GEOMETRY_NAME_ID("xao_geometry_name");
return MY_XAO_GEOMETRY_NAME_ID;
}
+ /// attribute string memory buffer
+ inline static const std::string& MEMORY_BUFFER_ID()
+ {
+ static const std::string MY_MEMORY_BUFFER_ID("memory_buffer");
+ return MY_MEMORY_BUFFER_ID;
+ }
+
/// Default constructor
EXCHANGEPLUGIN_EXPORT ExchangePlugin_ExportFeature();
/// Default destructor
protected:
/// Performs export of the file
EXCHANGEPLUGIN_EXPORT void exportFile(const std::string& theFileName,
- const std::string& theFormat);
+ const std::string& theFormat,
+ const bool isMemoryExport);
/// Performs export to XAO file
- EXCHANGEPLUGIN_EXPORT void exportXAO(const std::string& theFileName);
+ EXCHANGEPLUGIN_EXPORT void exportXAO(const std::string& theFileName,
+ const bool isMemoryExport);
/// Performs export to STL file
EXCHANGEPLUGIN_EXPORT void exportSTL(const std::string& theFileName);
data()->addAttribute(STEP_MATERIALS_ID(), ModelAPI_AttributeBoolean::typeId());
data()->addAttribute(STEP_COLORS_ID(), ModelAPI_AttributeBoolean::typeId());
data()->addAttribute(STEP_SCALE_INTER_UNITS_ID(), ModelAPI_AttributeBoolean::typeId());
+ data()->addAttribute(MEMORY_BUFFER_ID(), ModelAPI_AttributeString::typeId());
ModelAPI_Session::get()->validators()->registerNotObligatory(
getKind(), ExchangePlugin_ImportFeature::STEP_COLORS_ID());
getKind(), ExchangePlugin_ImportFeature::STEP_FILE_PATH_ID());
ModelAPI_Session::get()->validators()->registerNotObligatory(
getKind(), ExchangePlugin_ImportFeature::FILE_PATH_ID());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(
+ getKind(), ExchangePlugin_ImportFeature::MEMORY_BUFFER_ID());
}
/*
* Computes or recomputes the results
{
AttributeStringPtr aImportTypeAttr = string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID());
std::string aFormat = aImportTypeAttr->value();
- AttributeStringPtr aFilePathAttr;
- if (aFormat == "STEP" || aFormat == "STP")
- {
- aFilePathAttr = string(ExchangePlugin_ImportFeature::STEP_FILE_PATH_ID());
- } else {
- aFilePathAttr = string(ExchangePlugin_ImportFeature::FILE_PATH_ID());
+
+ if (aFormat == "XAOMem") {
+ // Import from memory buffer
+ AttributeStringPtr aMemoryBuffAttr =
+ string(ExchangePlugin_ImportFeature::MEMORY_BUFFER_ID());
+ std::string aMemoryBuff = aMemoryBuffAttr->value();
+ if (aMemoryBuff.empty()) {
+ setError("Memory buffer is empty.");
+ return;
+ }
+ importXAO("", aMemoryBuff, true);
}
- std::string aFilePath = aFilePathAttr->value();
- if (aFilePath.empty()) {
- setError("File path is empty.");
- return;
+ else {
+ // Import from file
+ AttributeStringPtr aFilePathAttr;
+ if (aFormat == "STEP" || aFormat == "STP") {
+ aFilePathAttr = string(ExchangePlugin_ImportFeature::STEP_FILE_PATH_ID());
+ }
+ else {
+ aFilePathAttr = string(ExchangePlugin_ImportFeature::FILE_PATH_ID());
+ }
+ std::string aFilePath = aFilePathAttr->value();
+ if (aFilePath.empty()) {
+ setError("File path is empty.");
+ return;
+ }
+ importFile(aFilePath);
}
-
- importFile(aFilePath);
}
void ExchangePlugin_Import_ImageFeature::execute()
}
}
-void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName)
+void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName,
+ const std::string& theMemoryBuff,
+ const bool isMemoryImport)
{
+ std::string aDataSource = theFileName;
+
try {
std::string anError;
XAO::Xao aXao;
- std::shared_ptr<GeomAPI_Shape> aGeomShape = XAOImport(theFileName, anError, &aXao);
+ std::shared_ptr<GeomAPI_Shape> aGeomShape;
+ if (isMemoryImport) {
+ aGeomShape = XAOImportMem(theMemoryBuff, anError, &aXao);
+ aDataSource = "memory buffer";
+ }
+ else
+ aGeomShape = XAOImport(theFileName, anError, &aXao);
if (!anError.empty()) {
- setError("An error occurred while importing " + theFileName + ": " + anError);
+ setError("An error occurred while importing " + aDataSource + ": " + anError);
return;
}
// use the geometry name or the file name for the feature
std::string aBodyName = aXaoGeometry->getName();
- if (aBodyName.empty())
+ if (aBodyName.empty() && !isMemoryImport)
aBodyName = GeomAlgoAPI_Tools::File_Tools::name(theFileName);
data()->setName(Locale::Convert::toWString(aBodyName));
// LCOV_EXCL_START
} catch (XAO::XAO_Exception& e) {
std::string anError = e.what();
- setError("An error occurred while importing " + theFileName + ": " + anError);
+ setError("An error occurred while importing " + aDataSource + ": " + anError);
return;
}
// LCOV_EXCL_STOP
static const std::string MY_STEP_COLORS_ID("step_colors");
return MY_STEP_COLORS_ID;
}
+ /// attribute memory buffer
+ inline static const std::string& MEMORY_BUFFER_ID()
+ {
+ static const std::string MY_MEMORY_BUFFER_ID("memory_buffer");
+ return MY_MEMORY_BUFFER_ID;
+ }
/// Returns the unique kind of a feature
EXCHANGEPLUGIN_EXPORT virtual const std::string& getKind() override
{
EXCHANGEPLUGIN_EXPORT void importFile(const std::string& theFileName) override;
/// Performs the import of XAO file
- EXCHANGEPLUGIN_EXPORT void importXAO(const std::string& theFileName);
+ EXCHANGEPLUGIN_EXPORT void importXAO(const std::string& theFileName,
+ const std::string& theMemoryBuff = std::string(),
+ const bool isMemoryImport = false);
private:
/// Set groups of color
:param string: The name of the author, empty by default
:param string: The name for the shape processed in GEOMETRY module, empty by default
+.. py:function:: aBuffer = model.exportToXAOMem(Part_doc, Object, Author="", GeometryName="")
+
+ This function enables passing data in XAO format from SHAPER to GEOM through a memory buffer (bytes array), without creation of real file on disk.
+
+ :param object: A being exported object
+ :param string: The name of the author, empty by default
+ :param string: The name for the shape processed in GEOMETRY module, empty by default
+
Result
""""""
:param part: The current part object
:param string: A file name string.
+.. py:function:: model.addImportXAOMem(Part_doc, aBuffer)
+
+ This function allows importing data in XAO format from GEOM through a memory buffer (bytes array), without creation of real file on disk.
+
+ :param part: The current part object
+ :param aBuffer: A byte array with data in XAO format.
+
Result
""""""
placeholder="Please input the geometry name">
</stringvalue>
</case>
+ <case id="XAOMem" title="XAOMem" internal="1">
+ <stringvalue id="xao_author"
+ label="Author"
+ placeholder="Please input the author">
+ </stringvalue>
+ <stringvalue id="xao_geometry_name"
+ label="Geometry name"
+ placeholder="Please input the geometry name">
+ </stringvalue>
+ </case>
<case id="STL" title="STL">
<export_file_selector id="stl_file_path"
type="save"
<feature id="ImportMacro" title="Import" tooltip="Import a file" icon="icons/Exchange/import.png"
helpfile="importFeature.html"
internal="1">
- <switch id="ImportType">
- <case id="Regular" title="BREP, XAO, IGES, STL">
- <file_selector id="file_path" title="Import file" path="">
+ <switch id="ImportType">
+ <case id="Regular" title="BREP, XAO, IGES, STL">
+ <file_selector id="file_path" title="Import file" path="">
<validator id="ExchangePlugin_ImportFormat" parameters="BREP|BRP:BREP,IGES|IGS:IGES,XAO:XAO,STL:STL" />
- </file_selector>
- <choice id="target_part"
- string_list_attribute="target_parts_list"
- label="Import to"
- tooltip="Select the part to import the document" />
- </case>
- <case id="STEP" title="STEP">
+ </file_selector>
+ <choice id="target_part"
+ string_list_attribute="target_parts_list"
+ label="Import to"
+ tooltip="Select the part to import the document" />
+ </case>
+ <case id="STEP" title="STEP">
<file_selector id="step_file_path" title="Import file" path="">
<validator id="ExchangePlugin_ImportFormat" parameters="STEP|STP:STEP" />
</file_selector>
<choice id="step_target_part"
- string_list_attribute="step_target_parts_list"
- label="Import to"
- tooltip="Select the part to import the document" />
+ string_list_attribute="step_target_parts_list"
+ label="Import to"
+ tooltip="Select the part to import the document" />
<groupbox title="STEP options">
<boolvalue id="step_scale_inter_units"
- label="Scale to International System of Units"
- default="true"/>
+ label="Scale to International System of Units"
+ default="true"/>
<groupbox title="Create groups from">
<boolvalue id="step_materials"
- label="Materials"
- default="false"/>
+ label="Materials"
+ default="false"/>
<boolvalue id="step_colors"
- label="Colors"
- default="false"/>
+ label="Colors"
+ default="false"/>
</groupbox>
</groupbox>
</case>
+ <case id="XAOMem" title="XAOMem" internal="1">
+ </case>
</switch>
-</feature>
+ </feature>
+
<feature id="ImportImageMacro" title="Import" tooltip="Import a file" icon="icons/Exchange/import.png"
helpfile="importFeature.html"
internal="1">
label="Import to"
tooltip="Select the image to import the document" />
</feature>
+
<feature id="Import" title="Import" tooltip="Import a file" icon="icons/Exchange/import.png"
helpfile="importFeature.html" internal="1">
<switch id="ImportType">
</file_selector>
<groupbox title="STEP options">
<boolvalue id="step_scale_inter_units"
- label="Scale to International System of Units"
- default="true"/>
+ label="Scale to International System of Units"
+ default="true"/>
<groupbox title="Create groups from">
<boolvalue id="step_materials"
- label="Materials"
- default="false"/>
+ label="Materials"
+ default="false"/>
<boolvalue id="step_colors"
- label="Colors"
- default="false"/>
+ label="Colors"
+ default="false"/>
</groupbox>
</groupbox>
</case>
+ <case id="XAOMem" title="XAOMem" internal="1">
+ </case>
</switch>
</feature>
<feature id="ImportImage" title="Import" tooltip="Import a file" icon="icons/Exchange/import.png"
helpfile="exportFeature.html" internal="1">
<source path="export_widget.xml" />
</feature>
+
<feature id="Dump" title="Dump" tooltip="Dump Python script" icon="icons/Exchange/dump.png"
helpfile="dumpFeature.html" abort_confirmation="false">
<export_file_selector id="file_path"
label="Import to"
tooltip="Select the part to import the document" />
</feature>
+
<feature id="ExportPart" title="Export part" tooltip="Export structure of the Part to file" icon="icons/Exchange/export_part.png"
helpfile="exportFeature.html"
internal="1">
}
return true;
}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+const std::string XAOExportMem(XAO::Xao* theXao,
+ std::string& theError)
+{
+ std::string aRetBuff ("");
+
+#ifdef _DEBUG
+ std::cout << "Export XAO into memory buffer " << std::endl;
+#endif
+
+ if (!theXao) {
+ theError = "An invalid argument.";
+ return aRetBuff;
+ }
+
+ try {
+ XAO::BrepGeometry* aGeometry = dynamic_cast<XAO::BrepGeometry*>(theXao->getGeometry());
+ TopoDS_Shape aShape = aGeometry->getTopoDS_Shape();
+ bool aWasFree = aShape.Free(); // make top level topology free, same as imported
+ if (!aWasFree)
+ aShape.Free(Standard_True);
+
+ aRetBuff = XAO::XaoExporter::saveToXml(theXao);
+
+ if (!aWasFree)
+ aShape.Free(Standard_False);
+ } catch (XAO::XAO_Exception& e) {
+ theError = e.what();
+ return aRetBuff;
+ }
+ return aRetBuff;
+}
XAO::Xao* theXao,
std::string& theError);
+/// Implementation of the export XAO to memory buffer (std::string)
+GEOMALGOAPI_EXPORT
+const std::string XAOExportMem(XAO::Xao* theXao,
+ std::string& theError);
+
#endif /* GEOMALGOAPI_XAOEXPORT_H_ */
aGeomShape->setImpl(new TopoDS_Shape(aShape));
return aGeomShape;
}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+std::shared_ptr<GeomAPI_Shape> XAOImportMem(const std::string& theMemoryBuff,
+ std::string& theError,
+ XAO::Xao* theXao)
+{
+#ifdef _DEBUG
+ std::cout << "Import XAO from file " << theFileName << std::endl;
+#endif
+ if (theMemoryBuff.empty() || !theXao) {
+ theError = "An invalid argument.";
+ return std::shared_ptr<GeomAPI_Shape>();
+ }
+
+ TopoDS_Shape aShape;
+ try {
+ if (XAO::XaoExporter::setXML(theMemoryBuff, theXao)) {
+ XAO::Geometry* aGeometry = theXao->getGeometry();
+ XAO::Format aFormat = aGeometry->getFormat();
+ if (aFormat == XAO::BREP) {
+ if (XAO::BrepGeometry* aBrepGeometry = dynamic_cast<XAO::BrepGeometry*>(aGeometry))
+ aShape = aBrepGeometry->getTopoDS_Shape();
+ } else {
+ theError = "Unsupported XAO geometry format:" + XAO::XaoUtils::shapeFormatToString(aFormat);
+ aShape.Nullify();
+ }
+ } else {
+ theError = "XAO object was not read successful";
+ aShape.Nullify();
+ }
+ } catch (XAO::XAO_Exception& e) {
+ theError = e.what();
+ aShape.Nullify();
+ }
+
+ std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+ aGeomShape->setImpl(new TopoDS_Shape(aShape));
+ return aGeomShape;
+}
std::string& theError,
XAO::Xao* theXao);
+/// Implementation of the import XAO data from memory buffer
+GEOMALGOAPI_EXPORT
+std::shared_ptr<GeomAPI_Shape> XAOImportMem(const std::string& theMemoryBuff,
+ std::string& theError,
+ XAO::Xao* theXao);
+
#endif /* GEOMALGOAPI_XAOIMPORT_H_ */
//it's pages recursively and setup into the widget.
if (myWidgetApi->toChildWidget()) {
do {
+ if (myWidgetApi->getBooleanAttribute(ATTR_INTERNAL, false)) continue;
QString aPageName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
QString aTooltip = qs(myWidgetApi->getProperty(FEATURE_TOOLTIP));
QString aCaseId = qs(myWidgetApi->getProperty(_ID));
"""Package for Exchange plugin for the Parametric Geometry API of the Modeler.
"""
-from ExchangeAPI import addImport, addImportSTEP, exportToFile, exportToXAO, exportToSTL
+from ExchangeAPI import addImport, addImportXAOMem, addImportSTEP
+from ExchangeAPI import exportToFile, exportToXAO, exportToXAOMem, exportToSTL
from ExchangeAPI import exportPart, importPart, addImportImage
from .tools import *
xmlChar *xmlbuff;
int buffersize;
- xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1); // format = 1 for node indentation
+ //xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1); // format = 1 for node indentation
+ // save with encoding to correspond to "saveToFile" and provide the same file size
+ xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, "UTF-8", 1); // format = 1 for node indentation
xmlFreeDoc(doc);
xmlCleanupGlobals();