Export XAO with the shape in a seperated BREP file.

This allows to avoid too big xml files.
This commit is contained in:
Christophe Bourcier 2016-12-15 16:36:42 +01:00
parent e648381815
commit 926f7982e5
23 changed files with 158 additions and 53 deletions

View File

@ -668,7 +668,8 @@ module GEOM
in ListOfGO groups,
in ListOfFields fields,
in string author,
in string fileName );
in string fileName,
in string shapeFileName );
boolean ImportXAO( in string fileName,
out GEOM_Object shape,
out ListOfGO subShapes,

View File

@ -36,13 +36,15 @@ module GEOM
* \param fields The list of fields to export
* \param author The author of the export
* \param fileName The name of the file to export
* \param shapeFileName The name of the file to export the shape in an external file
* \return boolean indicating if export was successful.
*/
boolean ExportXAO( in GEOM::GEOM_Object shape,
in GEOM::ListOfGO groups,
in GEOM::ListOfFields fields,
in string author,
in string fileName );
in string fileName,
in string shapeFileName );
/*!
* Import a shape from XAO format

View File

@ -3633,12 +3633,14 @@ GEOM::GEOM_Object_ptr GEOM_Superv_i::ImportIGES( const char* theFileName,
CORBA::Boolean GEOM_Superv_i::ExportXAO( GEOM::GEOM_Object_ptr shape,
const GEOM::ListOfGO& groups,
const GEOM::ListOfFields& fields,
const char* author, const char* fileName )
const char* author,
const char* fileName,
const char* shapeFileName )
{
beginService( " GEOM_Superv_i::ExportXAO" );
MESSAGE("GEOM_Superv_i::ExportXAO");
getXAOPluginOp();
CORBA::Boolean isGood = myXAOOp->ExportXAO( shape, groups, fields, author, fileName );
CORBA::Boolean isGood = myXAOOp->ExportXAO( shape, groups, fields, author, fileName, shapeFileName );
endService( " GEOM_Superv_i::ExportXAO" );
return isGood;
}

View File

@ -744,7 +744,8 @@ public:
const GEOM::ListOfGO& groups,
const GEOM::ListOfFields& fields,
const char* author,
const char* fileName);
const char* fileName,
const char* shapeFileName);
CORBA::Boolean ImportXAO( const char* fileName,
GEOM::GEOM_Object_out shape,
GEOM::ListOfGO_out subShapes,

View File

@ -33,10 +33,11 @@ def GetXAOPluginOperations(self):
# @param fields The list of fields to export
# @param author The author of the file
# @param fileName The name of the file to export
# @param shapeFileName The name of the BRep file to export
# @return True if operation is successful or False otherwise
#
# @ingroup l2_import_export
def ExportXAO(self, shape, groups, fields, author, fileName):
def ExportXAO(self, shape, groups, fields, author, fileName, shapeFileName = ""):
"""
Export a shape to XAO format
@ -52,7 +53,7 @@ def ExportXAO(self, shape, groups, fields, author, fileName):
"""
from salome.geom.geomBuilder import RaiseIfFailed
anOp = GetXAOPluginOperations(self)
res = anOp.ExportXAO(shape, groups, fields, author, fileName)
res = anOp.ExportXAO(shape, groups, fields, author, fileName, shapeFileName)
RaiseIfFailed("ExportXAO", anOp)
return res

View File

@ -65,6 +65,25 @@ void BrepGeometry::setShapeString(const std::string& shape)
initIds();
}
void BrepGeometry::writeShapeFile(const std::string& fileName)
throw (XAO_Exception)
{
bool res = BRepTools::Write(m_shape, fileName.c_str());
if (!res)
throw XAO_Exception(MsgBuilder() << "Cannot write BRep file: " << fileName);
}
void BrepGeometry::readShapeFile(const std::string& fileName)
throw (XAO_Exception)
{
BRep_Builder builder;
bool res = BRepTools::Read(m_shape, fileName.c_str(), builder);
if (!res)
throw XAO_Exception(MsgBuilder() << "Cannot read BRep file: " << fileName);
initIds();
}
TopoDS_Shape BrepGeometry::getTopoDS_Shape()
{
return m_shape;

View File

@ -75,6 +75,18 @@ namespace XAO
*/
virtual void setShapeString(const std::string& shape);
/**
* Writes shape to a file
* @param fileName the path to the file
*/
virtual void writeShapeFile(const std::string& fileName) throw (XAO_Exception);
/**
* Reads shape from a file
* @param fileName the path to the file
*/
virtual void readShapeFile(const std::string& fileName) throw (XAO_Exception);
#ifdef SWIG
%pythoncode %{
def setShape(self, shape):

View File

@ -94,6 +94,8 @@ namespace XAO
virtual const std::string getShapeString() = 0;
virtual void setShapeString(const std::string& shape) = 0;
virtual void writeShapeFile(const std::string& fileName) = 0;
virtual void readShapeFile(const std::string& fileName) = 0;
const int countElements(const XAO::Dimension& dim) const throw (XAO_Exception);
const int countVertices() const { return m_vertices.getSize(); }

View File

@ -241,9 +241,9 @@ bool Xao::removeField(Field* field)
return res;
}
const bool Xao::exportXAO(const std::string& fileName)
const bool Xao::exportXAO(const std::string& fileName, const std::string& shapeFileName)
{
return XaoExporter::saveToFile(this, fileName);
return XaoExporter::saveToFile(this, fileName, shapeFileName);
}
const std::string Xao::getXML()

View File

@ -215,9 +215,10 @@ namespace XAO
/**
* Exports this XAO object to a file.
* \param fileName the name of the file to create.
* \param shapeFileName if not empty, export the shape to this external file.
* \return true is the export is successful.
*/
const bool exportXAO(const std::string& fileName);
const bool exportXAO(const std::string& fileName, const std::string& shapeFileName);
/**
* Gets the XML corresponding to this XAO.
* \return the XML as a string.

View File

@ -28,6 +28,12 @@
#include "XAO_Step.hxx"
#include "XAO_XaoUtils.hxx"
#ifdef WIN32
# define _separator_ '\\'
#else
# define _separator_ '/'
#endif
namespace XAO
{
const xmlChar* C_TAG_XAO = (xmlChar*)"XAO";
@ -39,6 +45,7 @@ namespace XAO
const xmlChar* C_TAG_SHAPE = (xmlChar*)"shape";
const xmlChar* C_ATTR_SHAPE_FORMAT = (xmlChar*)"format";
const xmlChar* C_ATTR_SHAPE_FILE = (xmlChar*)"file";
const xmlChar* C_TAG_TOPOLOGY = (xmlChar*)"topology";
const xmlChar* C_TAG_VERTICES = (xmlChar*)"vertices";
@ -83,8 +90,8 @@ namespace XAO
using namespace XAO;
namespace {
xmlDocPtr exportXMLDoc(Xao* xaoObject);
void exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePtr xao);
xmlDocPtr exportXMLDoc(Xao* xaoObject, const std::string& shapeFileName);
void exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePtr xao, const std::string& shapeFileName);
void exportGeometricElements(Geometry* xaoGeometry, xmlNodePtr topology,
XAO::Dimension dim, const xmlChar* colTag, const xmlChar* eltTag);
void exportGroups(Xao* xaoObject, xmlNodePtr xao);
@ -109,9 +116,11 @@ namespace {
void parseStepElementNode(xmlNodePtr eltNode, Step* step);
std::string readStringProp(xmlNodePtr node, const xmlChar* attribute,
const bool& required, const std::string& defaultValue, const std::string& exception = std::string(""));
const bool& required, const std::string& defaultValue,
const std::string& exception = std::string(""));
int readIntegerProp(xmlNodePtr node, const xmlChar* attribute,
const bool& required, const int& defaultValue, const std::string& exception = std::string(""));
const bool& required, const int& defaultValue,
const std::string& exception = std::string(""));
std::string readStringProp(xmlNodePtr node, const xmlChar* attribute,
const bool& required, const std::string& defaultValue,
@ -161,7 +170,7 @@ namespace {
return res;
}
xmlDocPtr exportXMLDoc(Xao* xaoObject)
xmlDocPtr exportXMLDoc(Xao* xaoObject, const std::string& shapeFileName)
{
// Creating the Xml document
xmlDocPtr masterDocument = xmlNewDoc(BAD_CAST "1.0");
@ -173,7 +182,7 @@ namespace {
if (xaoObject->getGeometry() != NULL)
{
exportGeometry(xaoObject->getGeometry(), masterDocument, xao);
exportGeometry(xaoObject->getGeometry(), masterDocument, xao, shapeFileName);
}
exportGroups(xaoObject, xao);
@ -199,7 +208,8 @@ namespace {
}
}
void exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePtr xao)
void exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePtr xao,
const std::string& shapeFileName)
{
// Geometric part
xmlNodePtr geometry = xmlNewChild(xao, 0, C_TAG_GEOMETRY, 0);
@ -207,9 +217,20 @@ namespace {
xmlNodePtr shape = xmlNewChild(geometry, 0, C_TAG_SHAPE, 0);
xmlNewProp(shape, C_ATTR_SHAPE_FORMAT, BAD_CAST XaoUtils::shapeFormatToString(xaoGeometry->getFormat()).c_str());
if (shapeFileName == "")
{
// export the shape in the XAO file
std::string txtShape = xaoGeometry->getShapeString();
xmlNodePtr cdata = xmlNewCDataBlock(doc, BAD_CAST txtShape.c_str(), txtShape.size());
xmlAddChild(shape, cdata);
}
else
{
// export the shape in an external file
xmlNewProp(shape, C_ATTR_SHAPE_FILE, BAD_CAST shapeFileName.c_str());
xaoGeometry->writeShapeFile(shapeFileName);
}
xmlNodePtr topology = xmlNewChild(geometry, 0, C_TAG_TOPOLOGY, 0);
@ -361,12 +382,21 @@ namespace {
{
if (geometry->getFormat() == XAO::BREP)
{
std::string strFile = readStringProp(shapeNode, C_ATTR_SHAPE_FILE, false, "");
if (strFile != "")
{
geometry->readShapeFile(strFile);
}
else
{
// read brep from node content
xmlChar* data = xmlNodeGetContent(shapeNode->children);
if (data == NULL)
throw XAO_Exception("Missing BREP");
geometry->setShapeString((char*)data);
xmlFree(data);
}
}
else
{
throw XAO_Exception(MsgBuilder() << "Shape format not supported: "
@ -608,10 +638,10 @@ namespace {
}
}
const bool XaoExporter::saveToFile(Xao* xaoObject, const std::string& fileName)
const bool XaoExporter::saveToFile(Xao* xaoObject, const std::string& fileName, const std::string& shapeFileName)
throw (XAO_Exception)
{
xmlDocPtr doc = exportXMLDoc(xaoObject);
xmlDocPtr doc = exportXMLDoc(xaoObject, shapeFileName);
xmlSaveFormatFileEnc(fileName.c_str(), doc, "UTF-8", 1); // format = 1 for node indentation
xmlFreeDoc(doc);
@ -621,7 +651,7 @@ throw (XAO_Exception)
const std::string XaoExporter::saveToXml(Xao* xaoObject)
throw (XAO_Exception)
{
xmlDocPtr doc = exportXMLDoc(xaoObject);
xmlDocPtr doc = exportXMLDoc(xaoObject, "");
xmlChar *xmlbuff;
int buffersize;

View File

@ -44,9 +44,10 @@ namespace XAO
* Saves the XAO object to a file.
* @param xaoObject the object to export.
* @param fileName the path of the file to create.
* @param shapeFileName if not empty save the shape in an this external file.
* @return true if the export was successful, false otherwise.
*/
static const bool saveToFile(Xao* xaoObject, const std::string& fileName)
static const bool saveToFile(Xao* xaoObject, const std::string& fileName, const std::string& shapeFileName)
throw (XAO_Exception);
/**

View File

@ -46,7 +46,7 @@ void ImportExportTest::testExportNoGeometry()
{
Xao xao("me", "1.0");
bool res = xao.exportXAO("empty.xao");
bool res = xao.exportXAO("empty.xao", "");
CPPUNIT_ASSERT(res);
}
@ -103,7 +103,7 @@ void ImportExportTest::testExportGeometry()
}
}
bool res = xao.exportXAO("mygeom.xao");
bool res = xao.exportXAO("mygeom.xao", "");
CPPUNIT_ASSERT(res);
std::string xml = xao.getXML();

View File

@ -54,6 +54,7 @@
#include <QRadioButton>
#include <QGridLayout>
#include <QPushButton>
#include <QCheckBox>
#include <QMap>
//=================================================================================
@ -101,6 +102,7 @@ XAOPlugin_ExportDlg::XAOPlugin_ExportDlg(GeometryGUI* geometryGUI, QWidget* pare
ledShape->setMinimumSize(QSize(100, 0));
int line = 0, col = 0;
// adWidget(widget, fromRow, fromColumn, rowSpan, columnSpan)
gridLayoutExport->addWidget(lblShape, line, col++, 1, 1);
gridLayoutExport->addWidget(btnShapeSelect, line, col++, 1, 1);
gridLayoutExport->addWidget(ledShape, line, col++, 1, 1);
@ -121,10 +123,17 @@ XAOPlugin_ExportDlg::XAOPlugin_ExportDlg(GeometryGUI* geometryGUI, QWidget* pare
ledAuthor = new QLineEdit(gbxExport);
line++; col = 0;
gridLayoutExport->addWidget(lblAuthor, line, col++, 2, 1);
gridLayoutExport->addWidget(lblAuthor, line, col++, 1, 1);
col++; // span
gridLayoutExport->addWidget(ledAuthor, line, col++, 1, 1);
// Line 3
ckxUseSeparateFile = new QCheckBox(tr("XAOPLUGIN_EXPORT_SHAPEFILE"), gbxExport);
line++; col = 0;
gridLayoutExport->addWidget(ckxUseSeparateFile, line, col++, 1, 2);
//****************************
// Filter Group box
QGroupBox* gbxFilter = new QGroupBox(parent);
@ -410,6 +419,12 @@ bool XAOPlugin_ExportDlg::execute()
QString author = ledAuthor->text();
QString fileName = ledFileName->text();
QString shapeFileName = QString("");//ledShapeFile->text();
if (ckxUseSeparateFile->isChecked())
{
shapeFileName = fileName;
shapeFileName.append(".brep");
}
// get selected groups
QList<QListWidgetItem*> selGroups;
@ -451,6 +466,7 @@ bool XAOPlugin_ExportDlg::execute()
GEOM::IXAOOperations_var aXAOOp = GEOM::IXAOOperations::_narrow( getOperation() );
res = aXAOOp->ExportXAO(m_mainObj, groups, fields,
author.toUtf8().constData(),
fileName.toUtf8().constData());
fileName.toUtf8().constData(),
shapeFileName.toStdString().c_str());
return res;
}

View File

@ -27,6 +27,7 @@ class QLineEdit;
class QButtonGroup;
class QListWidget;
class QPushButton;
class QCheckBox;
//=================================================================================
// class : XAOPlugin_ExportDlg
@ -58,6 +59,7 @@ private:
QLineEdit* ledShape;
QLineEdit* ledFileName;
QLineEdit* ledAuthor;
QCheckBox* ckxUseSeparateFile;
QListWidget* lstGroups;
QListWidget* lstFields;
QPushButton* btnShapeSelect;

View File

@ -50,7 +50,8 @@ bool
XAOPlugin_IECallBack::Export( int theDocId,
const Handle(GEOM_Object) theOriginal,
const TCollection_AsciiString& theFileName,
const TCollection_AsciiString& theFormatName )
const TCollection_AsciiString& theFormatName,
const TCollection_AsciiString& theShapeFileName )
{
XAOPlugin_IOperations* aPluginOperations = XAOPlugin_OperationsCreator::get( GetEngine(), theDocId );
GEOMImpl_IShapesOperations* aShapesOperations = GetEngine()->GetIShapesOperations( theDocId );
@ -63,7 +64,7 @@ XAOPlugin_IECallBack::Export( int theDocId,
lgroups.push_back( Handle(GEOM_Object)::DownCast( groups->Value(i) ) );
for (int i = 1; i <= fields->Length(); i++)
lfields.push_back( Handle(GEOM_Field)::DownCast( fields->Value(i) ) );
aPluginOperations->ExportXAO( theOriginal, lgroups, lfields, "SIMAN Author", theFileName.ToCString() );
aPluginOperations->ExportXAO( theOriginal, lgroups, lfields, "SIMAN Author", theFileName.ToCString(), theShapeFileName.ToCString() );
return true;
}

View File

@ -39,7 +39,8 @@ public:
virtual bool Export( int theDocId,
const Handle(GEOM_Object) theOriginal,
const TCollection_AsciiString& theFileName,
const TCollection_AsciiString& theFormatName );
const TCollection_AsciiString& theFormatName,
const TCollection_AsciiString& theshapeFileName );
virtual
Handle(TColStd_HSequenceOfTransient) Import( int theDocId,

View File

@ -311,7 +311,8 @@ bool XAOPlugin_IOperations::ExportXAO( Handle(GEOM_Object) shape,
std::list<Handle(GEOM_Object)> groupList,
std::list<Handle(GEOM_Field)> fieldList,
const char* author,
const char* fileName )
const char* fileName,
const char* shapeFileName )
{
SetErrorCode(KO);
@ -348,7 +349,7 @@ bool XAOPlugin_IOperations::ExportXAO( Handle(GEOM_Object) shape,
exportFields(fieldList, xaoObject, geometry);
// export the XAO to the file
xaoObject->exportXAO(fileName);
xaoObject->exportXAO(fileName, shapeFileName);
// make a Python command
GEOM::TPythonDump pd(exportFunction);
@ -378,7 +379,7 @@ bool XAOPlugin_IOperations::ExportXAO( Handle(GEOM_Object) shape,
}
}
pd << "], ";
pd << "\"" << author << "\", \"" << fileName << "\")";
pd << "\"" << author << "\", \"" << fileName << "\", \"" << shapeFileName << "\")";
SetErrorCode(OK);
delete xaoObject;

View File

@ -47,7 +47,8 @@ public:
std::list<Handle(GEOM_Object)> groupList,
std::list<Handle(GEOM_Field)> fieldList,
const char* author,
const char* fileName );
const char* fileName,
const char* shapeFileName );
bool ImportXAO( const char* fileName,
Handle(GEOM_Object)& shape,

View File

@ -55,6 +55,7 @@ XAOPlugin_IOperations_i::~XAOPlugin_IOperations_i()
* \param fields The list of fields to export
* \param author The author of the export
* \param fileName The name of the exported file
* \param shapeFileName If not empty, save to shape to this external file
* \return boolean indicating if export was succeful.
*/
//=============================================================================
@ -62,7 +63,8 @@ CORBA::Boolean XAOPlugin_IOperations_i::ExportXAO( GEOM::GEOM_Object_ptr shape,
const GEOM::ListOfGO& groups,
const GEOM::ListOfFields& fields,
const char* author,
const char* fileName)
const char* fileName,
const char* shapeFileName)
{
bool isGood = false;
// Set a not done flag
@ -94,7 +96,7 @@ CORBA::Boolean XAOPlugin_IOperations_i::ExportXAO( GEOM::GEOM_Object_ptr shape,
if( !reference.IsNull() )
{
// Export XAO
isGood = GetOperations()->ExportXAO( reference, groupsObj, fieldsObj, author, fileName );
isGood = GetOperations()->ExportXAO( reference, groupsObj, fieldsObj, author, fileName, shapeFileName );
}
return isGood;

View File

@ -47,7 +47,8 @@ public:
const GEOM::ListOfGO& groups,
const GEOM::ListOfFields& fields,
const char* author,
const char* fileName );
const char* fileName,
const char* shapeFileName );
CORBA::Boolean ImportXAO( const char* fileName,
GEOM::GEOM_Object_out shape,

View File

@ -62,6 +62,10 @@
<source>XAOPLUGIN_EXPORT_AUTHOR</source>
<translation>Author</translation>
</message>
<message>
<source>XAOPLUGIN_EXPORT_SHAPEFILE</source>
<translation>Export shape in a separate file</translation>
</message>
<message>
<source>XAOPLUGIN_EXPORT_LGROUPS</source>
<translation>Groups</translation>

View File

@ -62,6 +62,10 @@
<source>XAOPLUGIN_EXPORT_AUTHOR</source>
<translation>Auteur</translation>
</message>
<message>
<source>XAOPLUGIN_EXPORT_SHAPEFILE</source>
<translation>Exporter la forme dans un fichier séparé</translation>
</message>
<message>
<source>XAOPLUGIN_EXPORT_LGROUPS</source>
<translation>Groupes</translation>