From 15854f5a98ef51dc055661a929cc8bf415698534 Mon Sep 17 00:00:00 2001 From: fps Date: Fri, 12 Apr 2013 15:43:32 +0000 Subject: [PATCH] export the brep + create the file on the client side --- idl/GEOM_Gen.idl | 8 +-- idl/GEOM_Superv.idl | 4 +- src/GEOMGUI/GEOM_msg_en.ts | 8 +++ src/GEOMGUI/GEOM_msg_fr.ts | 9 +++- .../GEOMImpl_IImportExportOperations.cxx | 49 ++++++++++--------- .../GEOMImpl_IImportExportOperations.hxx | 6 +-- src/GEOM_I/GEOM_IImportExportOperations_i.cc | 19 ++++--- src/GEOM_I/GEOM_IImportExportOperations_i.hh | 8 +-- src/GEOM_I_Superv/GEOM_Superv_i.cc | 6 +-- src/GEOM_I_Superv/GEOM_Superv_i.hh | 4 +- .../ImportExportGUI_ExportXAODlg.cxx | 32 +++++++----- src/XAO/Geometry.cxx | 7 ++- src/XAO/Geometry.hxx | 2 +- 13 files changed, 98 insertions(+), 64 deletions(-) diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 2949b27ef..eb69c45b8 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -4013,25 +4013,25 @@ module GEOM { /*! * Export a shape to XAO Format - * \param fileName The name of the exported file * \param shape The shape to export * \param groups The list of groups to export * \param fields The list of fields to export + * \param xao The exported XAO * \return boolean indicating if export was succeful. */ - boolean ExportXAO(in string fileName, in GEOM_Object shape, in ListOfGO groups, in ListOfGO fields); + boolean ExportXAO(in GEOM_Object shape, in ListOfGO groups, in ListOfGO fields, out string xao); /*! * Import a shape from XAO Format - * \param fileName The name of the imported file + * \param xao The XAO data to import * \param shape The imported shape * \param groups The list of imported groups * \param fields The list of imported fields * \return boolean indicating if import was succeful. */ - //boolean ImportXAO(in string fileName, out GEOM_Object shape, out ListOfGO groups, out ListOfGO fields); + //boolean ImportXAO(in string xao, out GEOM_Object shape, out ListOfGO groups, out ListOfGO fields); /*@@ insert new functions before this line @@ do not remove this line @@*/ }; diff --git a/idl/GEOM_Superv.idl b/idl/GEOM_Superv.idl index 8ab115aab..3859474cf 100644 --- a/idl/GEOM_Superv.idl +++ b/idl/GEOM_Superv.idl @@ -626,8 +626,8 @@ module GEOM //-----------------------------------------------------------// // ImportExportOperations // //-----------------------------------------------------------// - boolean ExportXAO(in string fileName, in GEOM_Object exportingShape, - in GEOM_List groups, in GEOM_List fields); + boolean ExportXAO(in GEOM_Object exportingShape, + in GEOM_List groups, in GEOM_List fields, out string xao); // boolean ImportXAO(in string fileName, out GEOM_Object exportingShape, // out GEOM_List groups, out GEOM_List fields); diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index 9a9da47b3..3e4930d7c 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -4888,10 +4888,18 @@ be specified in meters). GEOM_IMPORTEXPORT_204 Export XAO + + GEOM_SELECT_EXPORT_XAO + Export to XAO + XAO_FILES XAO files (*.xao) + + TOOLS_IMPORTEXPORT + Import / Export + BasicGUI_CurveDlg diff --git a/src/GEOMGUI/GEOM_msg_fr.ts b/src/GEOMGUI/GEOM_msg_fr.ts index dea9cceb5..d3b61091e 100644 --- a/src/GEOMGUI/GEOM_msg_fr.ts +++ b/src/GEOMGUI/GEOM_msg_fr.ts @@ -4887,11 +4887,18 @@ le paramètre '%1' aux préférences du module Géométrie.GEOM_IMPORTEXPORT_204 Export XAO + + GEOM_SELECT_EXPORT_XAO + Export XAO + XAO_FILES Fichiers XAO (*.xao) - + + TOOLS_IMPORTEXPORT + Import / Export + BasicGUI_CurveDlg diff --git a/src/GEOMImpl/GEOMImpl_IImportExportOperations.cxx b/src/GEOMImpl/GEOMImpl_IImportExportOperations.cxx index 01b7f80be..641e7d435 100644 --- a/src/GEOMImpl/GEOMImpl_IImportExportOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IImportExportOperations.cxx @@ -111,17 +111,17 @@ GEOMImpl_IImportExportOperations::~GEOMImpl_IImportExportOperations() //============================================================================= /*! * Export a shape to XAO Format - * \param fileName The name of the exported file * \param shape The shape to export * \param groups The list of groups to export * \param fields The list of fields to export + * \param xao The exported XAO. * \return boolean indicating if export was succeful. */ //============================================================================= -bool GEOMImpl_IImportExportOperations::ExportXAO(const std::string fileName, - Handle(GEOM_Object) shape, +bool GEOMImpl_IImportExportOperations::ExportXAO(Handle(GEOM_Object) shape, std::list groupList, - std::list fieldList) + std::list fieldList, + char*& xao) { SetErrorCode(KO); @@ -245,27 +245,32 @@ bool GEOMImpl_IImportExportOperations::ExportXAO(const std::string fileName, xaoObject->addGroup(group); } - xaoObject->exportToFile(fileName.c_str()); + const char* data = xaoObject->getXML(); + xao = new char[strlen(data)]; + strcpy(xao, data); + delete data; // make a Python command - /*TCollection_AsciiString fileNameStr = fileName.c_str(); GEOM::TPythonDump pd(exportFunction); - std::list::iterator itG = groupList.begin(); - std::list::iterator itF = fieldList.begin(); - //pd << /*isGood <<**" = geompy.ExportXAO(" << shape << ", " << fileNameStr.ToCString() << ", ["; - - pd << (*itG++); - while (itG != groupList.end()) - { - pd << ", " << (*itG++); - } - pd << "], ["; - pd << (*itF++); - while (itF != fieldList.end()) - { - pd << ", " << (*itF++); - } - pd << "])";*/ + pd << "exported = geompy.ExportXAO("; + + pd << shape << "shpae, [], [], xao"; + pd << ")"; + +// std::list::iterator itG = groupList.begin(); +// pd << (*itG++); +// while (itG != groupList.end()) +// { +// pd << ", " << (*itG++); +// } +// pd << "], ["; +// std::list::iterator itF = fieldList.begin(); +// pd << (*itF++); +// while (itF != fieldList.end()) +// { +// pd << ", " << (*itF++); +// } +// pd << "])"; SetErrorCode(OK); diff --git a/src/GEOMImpl/GEOMImpl_IImportExportOperations.hxx b/src/GEOMImpl/GEOMImpl_IImportExportOperations.hxx index fcc19c39d..66992b855 100644 --- a/src/GEOMImpl/GEOMImpl_IImportExportOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IImportExportOperations.hxx @@ -44,10 +44,10 @@ public: Standard_EXPORT GEOMImpl_IImportExportOperations(GEOM_Engine* engine, int docID); Standard_EXPORT ~GEOMImpl_IImportExportOperations(); - Standard_EXPORT bool ExportXAO (const std::string fileName, - Handle(GEOM_Object) shape, + Standard_EXPORT bool ExportXAO(Handle(GEOM_Object) shape, std::list groupList, - std::list fieldList); + std::list fieldList, + char*& xao); // Standard_EXPORT bool ImportXAO (const std::string fileName, // Handle(GEOM_Object) shape, // std::list groupList, diff --git a/src/GEOM_I/GEOM_IImportExportOperations_i.cc b/src/GEOM_I/GEOM_IImportExportOperations_i.cc index e9c257a48..2bef07a51 100644 --- a/src/GEOM_I/GEOM_IImportExportOperations_i.cc +++ b/src/GEOM_I/GEOM_IImportExportOperations_i.cc @@ -64,17 +64,17 @@ GEOM_IImportExportOperations_i::~GEOM_IImportExportOperations_i() * \return boolean indicating if export was succeful. */ //============================================================================= -CORBA::Boolean GEOM_IImportExportOperations_i::ExportXAO(const char* fileName, - GEOM::GEOM_Object_ptr shape, const GEOM::ListOfGO& groups, const GEOM::ListOfGO& fields) +CORBA::Boolean GEOM_IImportExportOperations_i::ExportXAO(GEOM::GEOM_Object_ptr shape, + const GEOM::ListOfGO& groups, const GEOM::ListOfGO& fields, CORBA::String_out xao) { bool isGood = false; - //Set a not done flag + // Set a not done flag GetOperations()->SetNotDone(); // Get the reference shape Handle(GEOM_Object) reference = GetObjectImpl(shape); - //Get the reference groups + // Get the reference groups int ind = 0; std::list groupsObj; for (; ind < groups.length(); ind++) @@ -84,7 +84,7 @@ CORBA::Boolean GEOM_IImportExportOperations_i::ExportXAO(const char* fileName, groupsObj.push_back(gobj); } - //Get the reference point + // Get the reference fields ind = 0; std::list fieldsObj; for (; ind < fields.length(); ind++) @@ -97,7 +97,10 @@ CORBA::Boolean GEOM_IImportExportOperations_i::ExportXAO(const char* fileName, if (!reference.IsNull()) { // Export XAO - isGood = GetOperations()->ExportXAO(fileName, reference, groupsObj, fieldsObj); + char* data; + isGood = GetOperations()->ExportXAO(reference, groupsObj, fieldsObj, data); + xao = CORBA::string_dup(data); + delete data; } return isGood; @@ -106,14 +109,14 @@ CORBA::Boolean GEOM_IImportExportOperations_i::ExportXAO(const char* fileName, //============================================================================= /*! * Import a shape from XAO Format - * \param fileName The name of the imported file + * \param xao The XAO data to import * \param shape The imported shape * \param groups The list of imported groups * \param fields The list of imported fields * \return boolean indicating if import was succeful. */ //============================================================================= -//bool GEOMImpl_IImportExportOperations::ImportXAO(const std::string fileName, +//bool GEOMImpl_IImportExportOperations::ImportXAO(const std::xao fileName, // Handle(GEOM_Object), // std::list > groups, // std::list > fields) diff --git a/src/GEOM_I/GEOM_IImportExportOperations_i.hh b/src/GEOM_I/GEOM_IImportExportOperations_i.hh index f47460bd8..547405e1e 100644 --- a/src/GEOM_I/GEOM_IImportExportOperations_i.hh +++ b/src/GEOM_I/GEOM_IImportExportOperations_i.hh @@ -42,11 +42,11 @@ public: ::GEOMImpl_IImportExportOperations* theImpl); ~GEOM_IImportExportOperations_i(); - CORBA::Boolean ExportXAO (const char* fileName, - GEOM::GEOM_Object_ptr shape, + CORBA::Boolean ExportXAO (GEOM::GEOM_Object_ptr shape, const GEOM::ListOfGO& groups, - const GEOM::ListOfGO& fields); - CORBA::Boolean ImportXAO (const char* fileName, GEOM::GEOM_Object_out shape, + const GEOM::ListOfGO& fields, + CORBA::String_out xao); + CORBA::Boolean ImportXAO (const char* xao, GEOM::GEOM_Object_out shape, GEOM::ListOfGO_out groups, GEOM::ListOfGO_out fields); /*@@ insert new functions before this line @@ do not remove this line @@*/ diff --git a/src/GEOM_I_Superv/GEOM_Superv_i.cc b/src/GEOM_I_Superv/GEOM_Superv_i.cc index 6846808ac..408299870 100644 --- a/src/GEOM_I_Superv/GEOM_Superv_i.cc +++ b/src/GEOM_I_Superv/GEOM_Superv_i.cc @@ -3451,8 +3451,8 @@ GEOM::GEOM_Object_ptr GEOM_Superv_i::MakeDividedCylinder (CORBA::Double theR, //============================================================================= // ExportXAO //============================================================================= -CORBA::Boolean GEOM_Superv_i::ExportXAO (const char* fileName, GEOM::GEOM_Object_ptr shape, - GEOM::GEOM_List_ptr groups, GEOM::GEOM_List_ptr fields) +CORBA::Boolean GEOM_Superv_i::ExportXAO (GEOM::GEOM_Object_ptr shape, + GEOM::GEOM_List_ptr groups, GEOM::GEOM_List_ptr fields, CORBA::String_out xao) { beginService( " GEOM_Superv_i::ExportXAO" ); MESSAGE("GEOM_Superv_i::ExportXAO"); @@ -3463,7 +3463,7 @@ CORBA::Boolean GEOM_Superv_i::ExportXAO (const char* fileName, GEOM::GEOM_Object if (GEOM_List_i* fieldList = dynamic_cast*>(GetServant(fields, myPOA).in())) { - CORBA::Boolean isGood = myImportExportOp->ExportXAO(fileName, shape, groupList->GetList(), fieldList->GetList()); + CORBA::Boolean isGood = myImportExportOp->ExportXAO(shape, groupList->GetList(), fieldList->GetList(), xao); endService( " GEOM_Superv_i::ExportXAO" ); return isGood; } diff --git a/src/GEOM_I_Superv/GEOM_Superv_i.hh b/src/GEOM_I_Superv/GEOM_Superv_i.hh index f66cfbcf5..c0e7351d4 100644 --- a/src/GEOM_I_Superv/GEOM_Superv_i.hh +++ b/src/GEOM_I_Superv/GEOM_Superv_i.hh @@ -715,8 +715,8 @@ public: //-----------------------------------------------------------// // ImportExport Operations // //-----------------------------------------------------------// - CORBA::Boolean ExportXAO(const char* fileName, - GEOM::GEOM_Object_ptr shape, GEOM::GEOM_List_ptr groups, GEOM::GEOM_List_ptr fields); + CORBA::Boolean ExportXAO(GEOM::GEOM_Object_ptr shape, + GEOM::GEOM_List_ptr groups, GEOM::GEOM_List_ptr fields, CORBA::String_out xao); // CORBA::Boolean ImportXAO(const char* fileName, GEOM::GEOM_Object_out shape, // GEOM::GEOM_List_out groups, GEOM::GEOM_List_out fields); /*@@ insert new functions before this line @@ do not remove this line @@*/ diff --git a/src/ImportExportGUI/ImportExportGUI_ExportXAODlg.cxx b/src/ImportExportGUI/ImportExportGUI_ExportXAODlg.cxx index 845f74243..76d250646 100644 --- a/src/ImportExportGUI/ImportExportGUI_ExportXAODlg.cxx +++ b/src/ImportExportGUI/ImportExportGUI_ExportXAODlg.cxx @@ -273,7 +273,8 @@ void ImportExportGUI_ExportXAODlg::SetEditCurrentArgument() //================================================================================= void ImportExportGUI_ExportXAODlg::btnFileSelectClicked() { - QString selFile = QFileDialog::getSaveFileName(this, tr("GEOM_SELECT_XAO"), QString(), tr("XAO_FILES")); + QString selFile = QFileDialog::getSaveFileName(this, tr("GEOM_SELECT_EXPORT_XAO"), + QString(), tr("XAO_FILES")); if (!selFile.isEmpty()) { ledFileName->setText(selFile); @@ -338,15 +339,15 @@ bool ImportExportGUI_ExportXAODlg::execute(ObjectList& objects) GEOM::ListOfGO_var groups = new GEOM::ListOfGO(); groups->length(selGroups.count()); int i = 0; - for (QList::iterator it = selGroups.begin(); it != selGroups.end(); ++it) - { - QListWidgetItem* item = (*it); - int index = item->data(Qt::UserRole).toInt(); - groups[i++] = m_groups[index].copy(); - } - - // get selected fields - QList selFields = lstFields->selectedItems(); + for (QList::iterator it = selGroups.begin(); it != selGroups.end(); ++it) + { + QListWidgetItem* item = (*it); + int index = item->data(Qt::UserRole).toInt(); + groups[i++] = m_groups[index].copy(); + } + + // get selected fields + QList selFields = lstFields->selectedItems(); GEOM::ListOfGO_var fields = new GEOM::ListOfGO(); fields->length(m_fields.count()); for (QList::iterator it = selFields.begin(); it != selFields.end(); ++it) @@ -358,8 +359,15 @@ bool ImportExportGUI_ExportXAODlg::execute(ObjectList& objects) // call engine function GEOM::GEOM_IImportExportOperations_var ieOp = GEOM::GEOM_IImportExportOperations::_narrow(getOperation()); - res = ieOp->ExportXAO(ledFileName->text().toStdString().c_str(), - m_mainObj, groups, fields); + char* xao; + res = ieOp->ExportXAO(m_mainObj, groups, fields, xao); + + // dump xao to file + ofstream exportFile; + exportFile.open(ledFileName->text().toStdString().c_str()); + exportFile << xao; + exportFile.close(); + delete xao; return res; } diff --git a/src/XAO/Geometry.cxx b/src/XAO/Geometry.cxx index 5dc25f751..d02ca6b0a 100644 --- a/src/XAO/Geometry.cxx +++ b/src/XAO/Geometry.cxx @@ -54,7 +54,7 @@ Geometry::~Geometry() { } -void Geometry::setShape(TopoDS_Shape shape) +void Geometry::setShape(const TopoDS_Shape& shape) { m_shape = shape; @@ -82,7 +82,10 @@ const char* Geometry::getBREP() { std::ostringstream streamShape; BRepTools::Write(m_shape, streamShape); - return streamShape.str().c_str(); + std::string data = streamShape.str(); + char* res = new char[data.size()]; + strcpy(res, data.c_str()); + return res; } void Geometry::initListIds(const Standard_Integer shapeType) diff --git a/src/XAO/Geometry.hxx b/src/XAO/Geometry.hxx index aaf4b6bd6..e083be912 100644 --- a/src/XAO/Geometry.hxx +++ b/src/XAO/Geometry.hxx @@ -58,7 +58,7 @@ namespace XAO { return m_shape; } - void setShape(TopoDS_Shape shape); + void setShape(const TopoDS_Shape& shape); const char* getBREP(); void setShape(const char* brep); -- 2.39.2