From: mzn Date: Wed, 22 Aug 2018 07:55:31 +0000 (+0300) Subject: Update XAO package from GEOM. X-Git-Tag: SHAPER_V9_1_0RC1~44 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=eed17cc8c10bbd4046a584aa4351eb78427bc756;p=modules%2Fshaper.git Update XAO package from GEOM. --- diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_XAOExport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_XAOExport.cpp index dafa7ca0c..da570238b 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_XAOExport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_XAOExport.cpp @@ -68,7 +68,7 @@ bool XAOExport(const std::string& theFileName, } try { - XAO::XaoExporter::saveToFile(theXao, theFileName); + XAO::XaoExporter::saveToFile(theXao, theFileName, ""); } catch (XAO::XAO_Exception& e) { theError = e.what(); return false; diff --git a/src/XAO/XAO_BrepGeometry.cxx b/src/XAO/XAO_BrepGeometry.cxx index fb59e2cd5..f59edc305 100644 --- a/src/XAO/XAO_BrepGeometry.cxx +++ b/src/XAO/XAO_BrepGeometry.cxx @@ -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; @@ -78,7 +97,7 @@ void BrepGeometry::setTopoDS_Shape(const TopoDS_Shape& shape) void BrepGeometry::initIds() { - // intialization of Ids + // initialization of Ids initListIds(TopAbs_VERTEX, m_vertices); initListIds(TopAbs_EDGE, m_edges); initListIds(TopAbs_FACE, m_faces); diff --git a/src/XAO/XAO_BrepGeometry.hxx b/src/XAO/XAO_BrepGeometry.hxx index 59d19ba54..e57823384 100644 --- a/src/XAO/XAO_BrepGeometry.hxx +++ b/src/XAO/XAO_BrepGeometry.hxx @@ -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): diff --git a/src/XAO/XAO_Field.cxx b/src/XAO/XAO_Field.cxx index 3fa7c8c19..0ef35b169 100644 --- a/src/XAO/XAO_Field.cxx +++ b/src/XAO/XAO_Field.cxx @@ -34,18 +34,17 @@ using namespace XAO; // ------------------------------------------------------- Field::Field(const XAO::Dimension& dimension, - const int& nbElements, const int& nbComponents, const std::string& name) - : m_name(name), m_dimension(dimension), m_nbElements(nbElements), m_nbComponents(nbComponents) + const int& nbElements, const int& nbComponents, const std::string& name) + : m_name(name), m_dimension(dimension), + m_nbComponents(nbComponents), m_components(nbComponents, ""), + m_nbElements(nbElements) { - m_components.reserve(nbComponents); - for (int i = 0; i < nbComponents; ++i) - m_components.push_back(""); } Field::~Field() { - for (unsigned int i = 0; i < m_steps.size(); ++i) - delete m_steps[i]; + for (unsigned int i = 0; i < m_steps.size(); ++i) + delete m_steps[i]; } Field* Field::createField(const XAO::Type& type, const XAO::Dimension& dimension, @@ -83,7 +82,7 @@ throw (XAO_Exception) { for (unsigned int i = 0; i < names.size(); ++i) { - if (i < m_nbComponents) + if ((int)i < m_nbComponents) m_components[i] = names[i]; } } @@ -130,7 +129,7 @@ throw (XAO_Exception) void Field::checkStepIndex(const int& step) throw (XAO_Exception) { - if (step < m_steps.size() && step >= 0) + if (step < (int)m_steps.size() && step >= 0) return; throw XAO_Exception(MsgBuilder() << "Step index is out of range [0, " diff --git a/src/XAO/XAO_Field.hxx b/src/XAO/XAO_Field.hxx index d6d9abebd..be5dcff2a 100644 --- a/src/XAO/XAO_Field.hxx +++ b/src/XAO/XAO_Field.hxx @@ -47,7 +47,7 @@ namespace XAO protected: /** * Constructor. - * @param dimension the dimension ot the field. + * @param dimension the dimension of the field. * @param nbElements the number of elements. * @param nbComponents the number of components. * @param name the name of the field. @@ -56,7 +56,6 @@ namespace XAO const int& nbElements, const int& nbComponents, const std::string& name); public: - /** /** * Creates a Field of the given type. * @param type the type of the field to create. diff --git a/src/XAO/XAO_Geometry.hxx b/src/XAO/XAO_Geometry.hxx index 698843c9e..34760ca34 100644 --- a/src/XAO/XAO_Geometry.hxx +++ b/src/XAO/XAO_Geometry.hxx @@ -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(); } diff --git a/src/XAO/XAO_Group.cxx b/src/XAO/XAO_Group.cxx index c2799c559..3ca39684c 100644 --- a/src/XAO/XAO_Group.cxx +++ b/src/XAO/XAO_Group.cxx @@ -43,7 +43,7 @@ Group::~Group() void Group::checkIndex(const int& element) throw (XAO_Exception) { - if (element < m_elements.size() && element >= 0) + if (element < (int)m_elements.size() && element >= 0) return; throw XAO_Exception(MsgBuilder() << "Index of element is out of range [0, " diff --git a/src/XAO/XAO_Xao.cxx b/src/XAO/XAO_Xao.cxx index 4e9652a26..1ec749b35 100644 --- a/src/XAO/XAO_Xao.cxx +++ b/src/XAO/XAO_Xao.cxx @@ -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() diff --git a/src/XAO/XAO_Xao.hxx b/src/XAO/XAO_Xao.hxx index 82c891b82..c7d839c3f 100644 --- a/src/XAO/XAO_Xao.hxx +++ b/src/XAO/XAO_Xao.hxx @@ -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. diff --git a/src/XAO/XAO_XaoExporter.cxx b/src/XAO/XAO_XaoExporter.cxx index f0ca278fe..fd13841b8 100644 --- a/src/XAO/XAO_XaoExporter.cxx +++ b/src/XAO/XAO_XaoExporter.cxx @@ -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,13 +116,15 @@ 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, - 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) @@ -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()); - 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); @@ -361,11 +382,20 @@ namespace { { 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 { @@ -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; diff --git a/src/XAO/XAO_XaoExporter.hxx b/src/XAO/XAO_XaoExporter.hxx index 966e76386..d633ecb08 100644 --- a/src/XAO/XAO_XaoExporter.hxx +++ b/src/XAO/XAO_XaoExporter.hxx @@ -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); /**