This allows to avoid too big xml files.
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,
* \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
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;
}
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,
# @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
"""
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
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;
*/
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):
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(); }
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()
/**
* 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.
#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";
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";
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);
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,
- const std::string& exception /*= std::string() */)
+ std::string readStringProp(xmlNodePtr node, const xmlChar* attribute,
+ const bool& required, const std::string& defaultValue,
+ const std::string& exception /*= std::string() */)
{
xmlChar* strAttr = xmlGetProp(node, attribute);
if (strAttr == NULL)
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");
if (xaoObject->getGeometry() != NULL)
{
- exportGeometry(xaoObject->getGeometry(), masterDocument, xao);
+ exportGeometry(xaoObject->getGeometry(), masterDocument, xao, shapeFileName);
}
exportGroups(xaoObject, xao);
}
}
- 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);
xmlNodePtr shape = xmlNewChild(geometry, 0, C_TAG_SHAPE, 0);
xmlNewProp(shape, C_ATTR_SHAPE_FORMAT, BAD_CAST XaoUtils::shapeFormatToString(xaoGeometry->getFormat()).c_str());
- std::string txtShape = xaoGeometry->getShapeString();
- xmlNodePtr cdata = xmlNewCDataBlock(doc, BAD_CAST txtShape.c_str(), txtShape.size());
- xmlAddChild(shape, cdata);
+
+ 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);
{
if (geometry->getFormat() == XAO::BREP)
{
- xmlChar* data = xmlNodeGetContent(shapeNode->children);
- if (data == NULL)
- throw XAO_Exception("Missing BREP");
- geometry->setShapeString((char*)data);
- xmlFree(data);
+ 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
{
}
}
-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);
const std::string XaoExporter::saveToXml(Xao* xaoObject)
throw (XAO_Exception)
{
- xmlDocPtr doc = exportXMLDoc(xaoObject);
+ xmlDocPtr doc = exportXMLDoc(xaoObject, "");
xmlChar *xmlbuff;
int buffersize;
* 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);
/**
{
Xao xao("me", "1.0");
- bool res = xao.exportXAO("empty.xao");
+ bool res = xao.exportXAO("empty.xao", "");
CPPUNIT_ASSERT(res);
}
}
}
- bool res = xao.exportXAO("mygeom.xao");
+ bool res = xao.exportXAO("mygeom.xao", "");
CPPUNIT_ASSERT(res);
std::string xml = xao.getXML();
#include <QRadioButton>
#include <QGridLayout>
#include <QPushButton>
+#include <QCheckBox>
#include <QMap>
//=================================================================================
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);
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);
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;
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;
}
class QButtonGroup;
class QListWidget;
class QPushButton;
+class QCheckBox;
//=================================================================================
// class : XAOPlugin_ExportDlg
QLineEdit* ledShape;
QLineEdit* ledFileName;
QLineEdit* ledAuthor;
+ QCheckBox* ckxUseSeparateFile;
QListWidget* lstGroups;
QListWidget* lstFields;
QPushButton* btnShapeSelect;
//=============================================================================
bool
XAOPlugin_IECallBack::Export( int theDocId,
- const Handle(GEOM_Object) theOriginal,
- const TCollection_AsciiString& theFileName,
- const TCollection_AsciiString& theFormatName )
+ const Handle(GEOM_Object) theOriginal,
+ const TCollection_AsciiString& theFileName,
+ const TCollection_AsciiString& theFormatName,
+ const TCollection_AsciiString& theShapeFileName )
{
XAOPlugin_IOperations* aPluginOperations = XAOPlugin_OperationsCreator::get( GetEngine(), theDocId );
GEOMImpl_IShapesOperations* aShapesOperations = GetEngine()->GetIShapesOperations( 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;
}
~XAOPlugin_IECallBack();
virtual bool Export( int theDocId,
- const Handle(GEOM_Object) theOriginal,
- const TCollection_AsciiString& theFileName,
- const TCollection_AsciiString& theFormatName );
+ const Handle(GEOM_Object) theOriginal,
+ const TCollection_AsciiString& theFileName,
+ const TCollection_AsciiString& theFormatName,
+ const TCollection_AsciiString& theshapeFileName );
virtual
Handle(TColStd_HSequenceOfTransient) Import( int theDocId,
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);
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);
}
}
pd << "], ";
- pd << "\"" << author << "\", \"" << fileName << "\")";
+ pd << "\"" << author << "\", \"" << fileName << "\", \"" << shapeFileName << "\")";
SetErrorCode(OK);
delete xaoObject;
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,
* \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.
*/
//=============================================================================
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 GEOM::ListOfGO& groups,
+ const GEOM::ListOfFields& fields,
+ const char* author,
+ const char* fileName,
+ const char* shapeFileName)
{
bool isGood = false;
// Set a not done flag
if( !reference.IsNull() )
{
// Export XAO
- isGood = GetOperations()->ExportXAO( reference, groupsObj, fieldsObj, author, fileName );
+ isGood = GetOperations()->ExportXAO( reference, groupsObj, fieldsObj, author, fileName, shapeFileName );
}
return isGood;
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,
<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>
<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>