-// Copyright (C) 2013-2016 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2013-2023 CEA, EDF
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#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(""));
+ 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(""));
+ bool required, 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,
+ bool required, const std::string& defaultValue,
+ const std::string& exception /*= std::string() */)
{
xmlChar* strAttr = xmlGetProp(node, attribute);
if (strAttr == NULL)
}
int readIntegerProp(xmlNodePtr node, const xmlChar* attribute,
- const bool& required, const int& defaultValue,
+ bool required, int defaultValue,
const std::string& exception /*= std::string() */)
{
xmlChar* strAttr = xmlGetProp(node, attribute);
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);
}
}
- void exportStep(Step* step, Field* field, xmlNodePtr nodeSteps)
+ void exportStep(Step* step, Field* /*field*/, xmlNodePtr nodeSteps)
{
xmlNodePtr nodeStep = xmlNewChild(nodeSteps, 0, C_TAG_STEP, 0);
xmlNewProp(nodeStep, C_ATTR_STEP_NUMBER, BAD_CAST XaoUtils::intToString(step->getStep()).c_str());
xaoObject->setGeometry(geometry);
}
- void parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode, Geometry* geometry)
+ void parseShapeNode(xmlDocPtr /*doc*/, xmlNodePtr shapeNode, Geometry* geometry)
{
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)
-throw (XAO_Exception)
+bool XaoExporter::saveToFile(Xao* xaoObject, const std::string& fileName, const std::string& shapeFileName)
+
{
- 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;
return (char*)xmlbuff;
}
-const bool XaoExporter::readFromFile(const std::string& fileName, Xao* xaoObject)
-throw (XAO_Exception)
+bool XaoExporter::readFromFile(const std::string& fileName, Xao* xaoObject)
+
{
// parse the file and get the DOM
int options = XML_PARSE_HUGE | XML_PARSE_NOCDATA;
return true;
}
-const bool XaoExporter::setXML(const std::string& xml, Xao* xaoObject)
-throw (XAO_Exception)
+bool XaoExporter::setXML(const std::string& xml, Xao* xaoObject)
+
{
int options = XML_PARSE_HUGE | XML_PARSE_NOCDATA;
xmlDocPtr doc = xmlReadDoc(BAD_CAST xml.c_str(), "", NULL, options);