mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2024-11-11 16:19:17 +05:00
Minimize external dependencies: libxml2 is only needed locally for XAO package
This commit is contained in:
parent
61270f9872
commit
fbf4b96ba0
@ -30,6 +30,8 @@
|
||||
#include "XAO_StringField.hxx"
|
||||
#include "XAO_XaoExporter.hxx"
|
||||
|
||||
#include <libxml/xmlstring.h>
|
||||
|
||||
using namespace XAO;
|
||||
|
||||
const xmlChar* C_XAO_VERSION = (xmlChar*)"1.0";
|
||||
|
@ -82,7 +82,38 @@ namespace XAO
|
||||
|
||||
using namespace XAO;
|
||||
|
||||
std::string XaoExporter::readStringProp(xmlNodePtr node, const xmlChar* attribute,
|
||||
namespace {
|
||||
xmlDocPtr exportXMLDoc(Xao* xaoObject);
|
||||
void exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePtr xao);
|
||||
void exportGeometricElements(Geometry* xaoGeometry, xmlNodePtr topology,
|
||||
XAO::Dimension dim, const xmlChar* colTag, const xmlChar* eltTag);
|
||||
void exportGroups(Xao* xaoObject, xmlNodePtr xao);
|
||||
void exportFields(Xao* xaoObject, xmlNodePtr xao);
|
||||
void exportStep(Step* step, Field* field, xmlNodePtr nodeSteps);
|
||||
|
||||
void parseXMLDoc(xmlDocPtr doc, Xao* xaoObject);
|
||||
void parseXaoNode(xmlDocPtr doc, xmlNodePtr xaoNode, Xao* xaoObject);
|
||||
void parseGeometryNode(xmlDocPtr doc, xmlNodePtr geometryNode, Xao* xaoObject);
|
||||
void parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode, Geometry* geometry);
|
||||
void parseTopologyNode(xmlNodePtr topologyNode, Geometry* geometry);
|
||||
void parseVerticesNode(xmlNodePtr verticesNode, Geometry* geometry);
|
||||
void parseEdgesNode(xmlNodePtr edgesNode, Geometry* geometry);
|
||||
void parseFacesNode(xmlNodePtr facesNode, Geometry* geometry);
|
||||
void parseSolidsNode(xmlNodePtr solidsNode, Geometry* geometry);
|
||||
void parseGroupsNode(xmlNodePtr groupsNode, Xao* xaoObject);
|
||||
void parseGroupNode(xmlNodePtr groupNode, Xao* xaoObject);
|
||||
|
||||
void parseFieldsNode(xmlNodePtr fieldsNode, Xao* xaoObject);
|
||||
void parseFieldNode(xmlNodePtr fieldNode, Xao* xaoObject);
|
||||
void parseStepNode(xmlNodePtr stepNode, Field* field);
|
||||
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(""));
|
||||
int readIntegerProp(xmlNodePtr node, const xmlChar* attribute,
|
||||
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() */)
|
||||
{
|
||||
@ -106,7 +137,7 @@ std::string XaoExporter::readStringProp(xmlNodePtr node, const xmlChar* attribut
|
||||
return res;
|
||||
}
|
||||
|
||||
int XaoExporter::readIntegerProp(xmlNodePtr node, const xmlChar* attribute,
|
||||
int readIntegerProp(xmlNodePtr node, const xmlChar* attribute,
|
||||
const bool& required, const int& defaultValue,
|
||||
const std::string& exception /*= std::string() */)
|
||||
{
|
||||
@ -130,31 +161,7 @@ int XaoExporter::readIntegerProp(xmlNodePtr node, const xmlChar* attribute,
|
||||
return res;
|
||||
}
|
||||
|
||||
const bool XaoExporter::saveToFile(Xao* xaoObject, const std::string& fileName)
|
||||
throw (XAO_Exception)
|
||||
{
|
||||
xmlDocPtr doc = exportXMLDoc(xaoObject);
|
||||
xmlSaveFormatFileEnc(fileName.c_str(), doc, "UTF-8", 1); // format = 1 for node indentation
|
||||
xmlFreeDoc(doc);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::string XaoExporter::saveToXml(Xao* xaoObject)
|
||||
throw (XAO_Exception)
|
||||
{
|
||||
xmlDocPtr doc = exportXMLDoc(xaoObject);
|
||||
|
||||
xmlChar *xmlbuff;
|
||||
int buffersize;
|
||||
xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1); // format = 1 for node indentation
|
||||
xmlFreeDoc(doc);
|
||||
xmlCleanupGlobals();
|
||||
|
||||
return (char*)xmlbuff;
|
||||
}
|
||||
|
||||
xmlDocPtr XaoExporter::exportXMLDoc(Xao* xaoObject)
|
||||
xmlDocPtr exportXMLDoc(Xao* xaoObject)
|
||||
{
|
||||
// Creating the Xml document
|
||||
xmlDocPtr masterDocument = xmlNewDoc(BAD_CAST "1.0");
|
||||
@ -175,7 +182,7 @@ xmlDocPtr XaoExporter::exportXMLDoc(Xao* xaoObject)
|
||||
return masterDocument;
|
||||
}
|
||||
|
||||
void XaoExporter::exportGeometricElements(Geometry* xaoGeometry,
|
||||
void exportGeometricElements(Geometry* xaoGeometry,
|
||||
xmlNodePtr topology, XAO::Dimension dim, const xmlChar* colTag, const xmlChar* eltTag)
|
||||
{
|
||||
xmlNodePtr vertices = xmlNewChild(topology, 0, colTag, 0);
|
||||
@ -192,7 +199,7 @@ void XaoExporter::exportGeometricElements(Geometry* xaoGeometry,
|
||||
}
|
||||
}
|
||||
|
||||
void XaoExporter::exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePtr xao)
|
||||
void exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePtr xao)
|
||||
{
|
||||
// Geometric part
|
||||
xmlNodePtr geometry = xmlNewChild(xao, 0, C_TAG_GEOMETRY, 0);
|
||||
@ -212,7 +219,7 @@ void XaoExporter::exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePt
|
||||
exportGeometricElements(xaoGeometry, topology, XAO::SOLID, C_TAG_SOLIDS, C_TAG_SOLID);
|
||||
}
|
||||
|
||||
void XaoExporter::exportGroups(Xao* xaoObject, xmlNodePtr xao)
|
||||
void exportGroups(Xao* xaoObject, xmlNodePtr xao)
|
||||
{
|
||||
xmlNodePtr groups = xmlNewChild(xao, 0, C_TAG_GROUPS, 0);
|
||||
xmlNewProp(groups, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoObject->countGroups()).c_str());
|
||||
@ -235,7 +242,7 @@ void XaoExporter::exportGroups(Xao* xaoObject, xmlNodePtr xao)
|
||||
}
|
||||
}
|
||||
|
||||
void XaoExporter::exportFields(Xao* xaoObject, xmlNodePtr xao)
|
||||
void exportFields(Xao* xaoObject, xmlNodePtr xao)
|
||||
{
|
||||
xmlNodePtr fields = xmlNewChild(xao, 0, C_TAG_FIELDS, 0);
|
||||
xmlNewProp(fields, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoObject->countFields()).c_str());
|
||||
@ -270,7 +277,7 @@ void XaoExporter::exportFields(Xao* xaoObject, xmlNodePtr xao)
|
||||
}
|
||||
}
|
||||
|
||||
void XaoExporter::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());
|
||||
@ -293,36 +300,7 @@ void XaoExporter::exportStep(Step* step, Field* field, xmlNodePtr nodeSteps)
|
||||
}
|
||||
}
|
||||
|
||||
const bool XaoExporter::readFromFile(const std::string& fileName, Xao* xaoObject)
|
||||
throw (XAO_Exception)
|
||||
{
|
||||
// parse the file and get the DOM
|
||||
int options = XML_PARSE_HUGE || XML_PARSE_NOCDATA;
|
||||
xmlDocPtr doc = xmlReadFile(fileName.c_str(), NULL, options);
|
||||
if (doc == NULL)
|
||||
{
|
||||
throw XAO_Exception("Cannot read XAO file");
|
||||
}
|
||||
|
||||
parseXMLDoc(doc, xaoObject);
|
||||
return true;
|
||||
}
|
||||
|
||||
const bool XaoExporter::setXML(const std::string& xml, Xao* xaoObject)
|
||||
throw (XAO_Exception)
|
||||
{
|
||||
int options = XML_PARSE_HUGE || XML_PARSE_NOCDATA;
|
||||
xmlDocPtr doc = xmlReadDoc(BAD_CAST xml.c_str(), "", NULL, options);
|
||||
if (doc == NULL)
|
||||
{
|
||||
throw XAO_Exception("Cannot read XAO stream");
|
||||
}
|
||||
|
||||
parseXMLDoc(doc, xaoObject);
|
||||
return true;
|
||||
}
|
||||
|
||||
void XaoExporter::parseXMLDoc(xmlDocPtr doc, Xao* xaoObject)
|
||||
void parseXMLDoc(xmlDocPtr doc, Xao* xaoObject)
|
||||
{
|
||||
// Get the root element node
|
||||
xmlNodePtr root = xmlDocGetRootElement(doc);
|
||||
@ -335,7 +313,7 @@ void XaoExporter::parseXMLDoc(xmlDocPtr doc, Xao* xaoObject)
|
||||
xmlCleanupParser(); // free globals
|
||||
}
|
||||
|
||||
void XaoExporter::parseXaoNode(xmlDocPtr doc, xmlNodePtr xaoNode, Xao* xaoObject)
|
||||
void parseXaoNode(xmlDocPtr doc, xmlNodePtr xaoNode, Xao* xaoObject)
|
||||
{
|
||||
std::string version = readStringProp(xaoNode, C_ATTR_XAO_VERSION, false, "");
|
||||
if (version != "")
|
||||
@ -355,7 +333,7 @@ void XaoExporter::parseXaoNode(xmlDocPtr doc, xmlNodePtr xaoNode, Xao* xaoObject
|
||||
}
|
||||
}
|
||||
|
||||
void XaoExporter::parseGeometryNode(xmlDocPtr doc, xmlNodePtr geometryNode, Xao* xaoObject)
|
||||
void parseGeometryNode(xmlDocPtr doc, xmlNodePtr geometryNode, Xao* xaoObject)
|
||||
{
|
||||
// get the shape and topo nodes
|
||||
xmlNodePtr shapeNode = NULL;
|
||||
@ -379,7 +357,7 @@ void XaoExporter::parseGeometryNode(xmlDocPtr doc, xmlNodePtr geometryNode, Xao*
|
||||
xaoObject->setGeometry(geometry);
|
||||
}
|
||||
|
||||
void XaoExporter::parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode, Geometry* geometry)
|
||||
void parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode, Geometry* geometry)
|
||||
{
|
||||
if (geometry->getFormat() == XAO::BREP)
|
||||
{
|
||||
@ -396,7 +374,7 @@ void XaoExporter::parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode, Geometry*
|
||||
}
|
||||
}
|
||||
|
||||
void XaoExporter::parseTopologyNode(xmlNodePtr topologyNode, Geometry* geometry)
|
||||
void parseTopologyNode(xmlNodePtr topologyNode, Geometry* geometry)
|
||||
{
|
||||
for (xmlNodePtr node = topologyNode->children; node; node = node->next)
|
||||
{
|
||||
@ -411,7 +389,7 @@ void XaoExporter::parseTopologyNode(xmlNodePtr topologyNode, Geometry* geometry)
|
||||
}
|
||||
}
|
||||
|
||||
void XaoExporter::parseVerticesNode(xmlNodePtr verticesNode, Geometry* geometry)
|
||||
void parseVerticesNode(xmlNodePtr verticesNode, Geometry* geometry)
|
||||
{
|
||||
int count = readIntegerProp(verticesNode, C_ATTR_COUNT, true, -1);
|
||||
geometry->setCountVertices(count);
|
||||
@ -429,7 +407,7 @@ void XaoExporter::parseVerticesNode(xmlNodePtr verticesNode, Geometry* geometry)
|
||||
}
|
||||
}
|
||||
|
||||
void XaoExporter::parseEdgesNode(xmlNodePtr edgesNode, Geometry* geometry)
|
||||
void parseEdgesNode(xmlNodePtr edgesNode, Geometry* geometry)
|
||||
{
|
||||
int count = readIntegerProp(edgesNode, C_ATTR_COUNT, true, -1);
|
||||
geometry->setCountEdges(count);
|
||||
@ -447,7 +425,7 @@ void XaoExporter::parseEdgesNode(xmlNodePtr edgesNode, Geometry* geometry)
|
||||
}
|
||||
}
|
||||
|
||||
void XaoExporter::parseFacesNode(xmlNodePtr facesNode, Geometry* geometry)
|
||||
void parseFacesNode(xmlNodePtr facesNode, Geometry* geometry)
|
||||
{
|
||||
int count = readIntegerProp(facesNode, C_ATTR_COUNT, true, -1);
|
||||
geometry->setCountFaces(count);
|
||||
@ -465,7 +443,7 @@ void XaoExporter::parseFacesNode(xmlNodePtr facesNode, Geometry* geometry)
|
||||
}
|
||||
}
|
||||
|
||||
void XaoExporter::parseSolidsNode(xmlNodePtr solidsNode, Geometry* geometry)
|
||||
void parseSolidsNode(xmlNodePtr solidsNode, Geometry* geometry)
|
||||
{
|
||||
int count = readIntegerProp(solidsNode, C_ATTR_COUNT, true, -1);
|
||||
geometry->setCountSolids(count);
|
||||
@ -483,7 +461,7 @@ void XaoExporter::parseSolidsNode(xmlNodePtr solidsNode, Geometry* geometry)
|
||||
}
|
||||
}
|
||||
|
||||
void XaoExporter::parseGroupsNode(xmlNodePtr groupsNode, Xao* xaoObject)
|
||||
void parseGroupsNode(xmlNodePtr groupsNode, Xao* xaoObject)
|
||||
{
|
||||
for (xmlNodePtr node = groupsNode->children; node; node = node->next)
|
||||
{
|
||||
@ -494,7 +472,7 @@ void XaoExporter::parseGroupsNode(xmlNodePtr groupsNode, Xao* xaoObject)
|
||||
}
|
||||
}
|
||||
|
||||
void XaoExporter::parseGroupNode(xmlNodePtr groupNode, Xao* xaoObject)
|
||||
void parseGroupNode(xmlNodePtr groupNode, Xao* xaoObject)
|
||||
{
|
||||
std::string strDimension = readStringProp(groupNode, C_ATTR_GROUP_DIM, true, "");
|
||||
XAO::Dimension dim = XaoUtils::stringToDimension(strDimension);
|
||||
@ -513,7 +491,7 @@ void XaoExporter::parseGroupNode(xmlNodePtr groupNode, Xao* xaoObject)
|
||||
}
|
||||
}
|
||||
|
||||
void XaoExporter::parseFieldsNode(xmlNodePtr fieldsNode, Xao* xaoObject)
|
||||
void parseFieldsNode(xmlNodePtr fieldsNode, Xao* xaoObject)
|
||||
{
|
||||
for (xmlNodePtr node = fieldsNode->children; node; node = node->next)
|
||||
{
|
||||
@ -524,7 +502,7 @@ void XaoExporter::parseFieldsNode(xmlNodePtr fieldsNode, Xao* xaoObject)
|
||||
}
|
||||
}
|
||||
|
||||
void XaoExporter::parseFieldNode(xmlNodePtr fieldNode, Xao* xaoObject)
|
||||
void parseFieldNode(xmlNodePtr fieldNode, Xao* xaoObject)
|
||||
{
|
||||
std::string strDimension = readStringProp(fieldNode, C_ATTR_FIELD_DIMENSION, true, "");
|
||||
XAO::Dimension dim = XaoUtils::stringToDimension(strDimension);
|
||||
@ -583,7 +561,7 @@ void XaoExporter::parseFieldNode(xmlNodePtr fieldNode, Xao* xaoObject)
|
||||
}
|
||||
}
|
||||
|
||||
void XaoExporter::parseStepNode(xmlNodePtr stepNode, Field* field)
|
||||
void parseStepNode(xmlNodePtr stepNode, Field* field)
|
||||
{
|
||||
int stepNumber = readIntegerProp(stepNode, C_ATTR_STEP_NUMBER, true, -1);
|
||||
Step* step = field->addNewStep(stepNumber);
|
||||
@ -603,7 +581,7 @@ void XaoExporter::parseStepNode(xmlNodePtr stepNode, Field* field)
|
||||
}
|
||||
}
|
||||
|
||||
void XaoExporter::parseStepElementNode(xmlNodePtr eltNode, Step* step)
|
||||
void parseStepElementNode(xmlNodePtr eltNode, Step* step)
|
||||
{
|
||||
int index = readIntegerProp(eltNode, C_ATTR_ELT_INDEX, true, -1);
|
||||
|
||||
@ -624,3 +602,57 @@ void XaoExporter::parseStepElementNode(xmlNodePtr eltNode, Step* step)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const bool XaoExporter::saveToFile(Xao* xaoObject, const std::string& fileName)
|
||||
throw (XAO_Exception)
|
||||
{
|
||||
xmlDocPtr doc = exportXMLDoc(xaoObject);
|
||||
xmlSaveFormatFileEnc(fileName.c_str(), doc, "UTF-8", 1); // format = 1 for node indentation
|
||||
xmlFreeDoc(doc);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::string XaoExporter::saveToXml(Xao* xaoObject)
|
||||
throw (XAO_Exception)
|
||||
{
|
||||
xmlDocPtr doc = exportXMLDoc(xaoObject);
|
||||
|
||||
xmlChar *xmlbuff;
|
||||
int buffersize;
|
||||
xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1); // format = 1 for node indentation
|
||||
xmlFreeDoc(doc);
|
||||
xmlCleanupGlobals();
|
||||
|
||||
return (char*)xmlbuff;
|
||||
}
|
||||
|
||||
const bool XaoExporter::readFromFile(const std::string& fileName, Xao* xaoObject)
|
||||
throw (XAO_Exception)
|
||||
{
|
||||
// parse the file and get the DOM
|
||||
int options = XML_PARSE_HUGE || XML_PARSE_NOCDATA;
|
||||
xmlDocPtr doc = xmlReadFile(fileName.c_str(), NULL, options);
|
||||
if (doc == NULL)
|
||||
{
|
||||
throw XAO_Exception("Cannot read XAO file");
|
||||
}
|
||||
|
||||
parseXMLDoc(doc, xaoObject);
|
||||
return true;
|
||||
}
|
||||
|
||||
const bool XaoExporter::setXML(const std::string& xml, Xao* xaoObject)
|
||||
throw (XAO_Exception)
|
||||
{
|
||||
int options = XML_PARSE_HUGE || XML_PARSE_NOCDATA;
|
||||
xmlDocPtr doc = xmlReadDoc(BAD_CAST xml.c_str(), "", NULL, options);
|
||||
if (doc == NULL)
|
||||
{
|
||||
throw XAO_Exception("Cannot read XAO stream");
|
||||
}
|
||||
|
||||
parseXMLDoc(doc, xaoObject);
|
||||
return true;
|
||||
}
|
||||
|
@ -21,8 +21,6 @@
|
||||
#ifndef __XAO_XAOEXPORTER_HXX__
|
||||
#define __XAO_XAOEXPORTER_HXX__
|
||||
|
||||
#include <libxml/parser.h>
|
||||
|
||||
#include "XAO_Xao.hxx"
|
||||
#include "XAO_Geometry.hxx"
|
||||
#include "XAO_Group.hxx"
|
||||
@ -71,37 +69,6 @@ namespace XAO
|
||||
*/
|
||||
static const bool setXML(const std::string& xml, Xao* xaoObject)
|
||||
throw (XAO_Exception);
|
||||
|
||||
private:
|
||||
static xmlDocPtr exportXMLDoc(Xao* xaoObject);
|
||||
static void exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePtr xao);
|
||||
static void exportGeometricElements(Geometry* xaoGeometry, xmlNodePtr topology,
|
||||
XAO::Dimension dim, const xmlChar* colTag, const xmlChar* eltTag);
|
||||
static void exportGroups(Xao* xaoObject, xmlNodePtr xao);
|
||||
static void exportFields(Xao* xaoObject, xmlNodePtr xao);
|
||||
static void exportStep(Step* step, Field* field, xmlNodePtr nodeSteps);
|
||||
|
||||
static void parseXMLDoc(xmlDocPtr doc, Xao* xaoObject);
|
||||
static void parseXaoNode(xmlDocPtr doc, xmlNodePtr xaoNode, Xao* xaoObject);
|
||||
static void parseGeometryNode(xmlDocPtr doc, xmlNodePtr geometryNode, Xao* xaoObject);
|
||||
static void parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode, Geometry* geometry);
|
||||
static void parseTopologyNode(xmlNodePtr topologyNode, Geometry* geometry);
|
||||
static void parseVerticesNode(xmlNodePtr verticesNode, Geometry* geometry);
|
||||
static void parseEdgesNode(xmlNodePtr edgesNode, Geometry* geometry);
|
||||
static void parseFacesNode(xmlNodePtr facesNode, Geometry* geometry);
|
||||
static void parseSolidsNode(xmlNodePtr solidsNode, Geometry* geometry);
|
||||
static void parseGroupsNode(xmlNodePtr groupsNode, Xao* xaoObject);
|
||||
static void parseGroupNode(xmlNodePtr groupNode, Xao* xaoObject);
|
||||
|
||||
static void parseFieldsNode(xmlNodePtr fieldsNode, Xao* xaoObject);
|
||||
static void parseFieldNode(xmlNodePtr fieldNode, Xao* xaoObject);
|
||||
static void parseStepNode(xmlNodePtr stepNode, Field* field);
|
||||
static void parseStepElementNode(xmlNodePtr eltNode, Step* step);
|
||||
|
||||
static std::string readStringProp(xmlNodePtr node, const xmlChar* attribute,
|
||||
const bool& required, const std::string& defaultValue, const std::string& exception = std::string(""));
|
||||
static int readIntegerProp(xmlNodePtr node, const xmlChar* attribute,
|
||||
const bool& required, const int& defaultValue, const std::string& exception = std::string(""));
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user