// -------------------------------------------------------
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,
{
for (unsigned int i = 0; i < names.size(); ++i)
{
- if (i < m_nbComponents)
+ if ((int)i < m_nbComponents)
m_components[i] = names[i];
}
}
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, "
#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;