From e2e1c99ebc4015bf6d2f42f230fa5b4f0ac9c5a7 Mon Sep 17 00:00:00 2001 From: fps Date: Thu, 25 Apr 2013 14:46:57 +0000 Subject: [PATCH] add generic method to get element by type use enum instead of integer --- src/XAO/Field.cxx | 33 +++--- src/XAO/Field.hxx | 152 ++++++++++++++++--------- src/XAO/GeometricElement.cxx | 9 +- src/XAO/GeometricElement.hxx | 100 ++++++++++++++++- src/XAO/Geometry.cxx | 40 ++++++- src/XAO/Geometry.hxx | 5 +- src/XAO/Group.cxx | 12 +- src/XAO/Group.hxx | 14 +-- src/XAO/Xao.cxx | 64 ++++++++++- src/XAO/Xao.hxx | 173 ++++++++++++++++++----------- src/XAO/XaoUtils.cxx | 22 ++-- src/XAO/XaoUtils.hxx | 29 ++++- src/XAO/tests/ImportExportTest.cxx | 36 ++++-- src/XAO/tests/ImportExportTest.hxx | 4 + src/XAO/tests/Makefile.am | 19 ++++ 15 files changed, 526 insertions(+), 186 deletions(-) diff --git a/src/XAO/Field.cxx b/src/XAO/Field.cxx index 812ecf0d2..c5a087963 100644 --- a/src/XAO/Field.cxx +++ b/src/XAO/Field.cxx @@ -18,31 +18,32 @@ // // Author : Nathalie Gore (OpenCascade) +#include "Xao.hxx" #include "Field.hxx" using namespace XAO; -Field::Field() +template +Field::Field(const FieldDimension dim, const int nbComponents) + : m_name(""), m_dimension(dim) { - _myName = ""; - _myDimension = -1; - _myType = -1; - _myValuesCount = 0; - _myComponentCount = 0; - _myComponentNames = NULL; - _myStepCount = 0; - _mySteps = NULL; - _myStamps = NULL; - _myValues = NULL; + m_components.reserve(nbComponents); } -Field::~Field() +template +Field::Field(const char* name, const FieldDimension dim, const int nbComponents) + : m_name(name), m_dimension(dim) { + m_components.reserve(nbComponents); } -Field *Field::New() +template +void Field::setComponentName(const int index, const char* name) { - return new Field; -} - + if (index < m_components.size()) + { + m_components[index] = name; + } + // TODO: throw +} diff --git a/src/XAO/Field.hxx b/src/XAO/Field.hxx index 5617f3e11..8d0265d04 100644 --- a/src/XAO/Field.hxx +++ b/src/XAO/Field.hxx @@ -18,62 +18,112 @@ // // Author : Nathalie Gore (OpenCascade) -#ifndef __XAO_XAO_HXX__ -#define __XAO_XAO_HXX__ +#ifndef __XAO_FIELD_HXX__ +#define __XAO_FIELD_HXX__ #include +#include +#include + +#include "Xao.hxx" namespace XAO { - typedef enum - { - VERTEX = 0, - EDGE = 1, - FACE = 2, - SOLID = 3 - } FieldDimension; - - typedef enum - { - BOOLEAN = 0, - INTEGER = 1, - DOUBLE = 2, - STRING = 3 - } FieldType; - - class Field - { - public: - static Field *New(); - void setName(const char *name) { _myName=name; } - const char *getName() const { return _myName.c_str(); } - void setDimension(int nb) { _myDimension=nb; } - int getDimension() { return _myDimension; } - void setType(int type) { _myType=type; } - int getType() { return _myType; } - void setValuesCount(int nb) { _myValuesCount=nb; } - int getValuesCount() { return _myValuesCount; } - void setComponentCount(int nb) { _myComponentCount=nb; } - int getComponentCount() { return _myComponentCount; } - void setStepCount(int nb) { _myStepCount=nb; } - int getStepCount() { return _myStepCount; } - - private: - Field(); - ~Field(); - - private: - std::string _myName; - int _myDimension; - int _myType; - int _myValuesCount; - int _myComponentCount; - std::string *_myComponentNames; - int _myStepCount; - int *_mySteps; - double *_myStamps; - std::string **_myValues; - }; + enum FieldType + { + FIELD_BOOLEAN = 0, + FIELD_INTEGER = 1, + FIELD_DOUBLE = 2, + FIELD_STRING = 3 + }; + + enum FieldDimension + { + FIELD_VERTEX = 0, + FIELD_EDGE = 1, + FIELD_FACE = 2, + FIELD_SOLID = 3, + FIELD_WHOLE = -1 + }; + + template + class Step + { + public: + private: + int m_number; + int m_stamp; + std::map m_values; + + }; + + class IField + { + public: + virtual const char* getName() const = 0; + virtual void setName(const char* name) = 0; + virtual const FieldType getType() = 0; + virtual const FieldDimension getDimension() = 0; + virtual void setComponentName(const int index, const char* name) = 0; + virtual const int countComponents() = 0; + virtual const int getStepCount() = 0; + }; + + template + class Field : IField + { + public: + Field(const FieldDimension dim, const int nbComponents); + Field(const char* name, const FieldDimension dim, const int nbComponents); + virtual ~Field(); + + const char* getName() const + { + return m_name.c_str(); + } + void setName(const char* name) + { + m_name = name; + } + + virtual const FieldType getType(); + + const FieldDimension getDimension() + { + return m_dimension; + } + + void setComponentName(const int index, const char* name); + const int countComponents() + { + return m_components.size(); + } + + const int getStepCount() + { + return m_steps.size(); + } + + private: + std::string m_name; + FieldDimension m_dimension; + FieldType m_type; + + std::vector m_components; + std::list< Step* > m_steps; + }; + + class BooleanField : Field + { + public: + BooleanField(const FieldDimension dim, const int nbComponents); + BooleanField(const char* name, const FieldDimension dim, const int nbComponents); + + virtual const FieldType getType() + { + return FIELD_BOOLEAN; + } + }; } #endif diff --git a/src/XAO/GeometricElement.cxx b/src/XAO/GeometricElement.cxx index 264ddd386..82bbf5581 100644 --- a/src/XAO/GeometricElement.cxx +++ b/src/XAO/GeometricElement.cxx @@ -40,7 +40,6 @@ GeometricElement::GeometricElement(const char* name, const char* reference) GeometricElement::~GeometricElement() { - } GeometricElementList::GeometricElementList() @@ -83,7 +82,9 @@ const char* GeometricElementList::getName(const int index) void GeometricElementList::setName(const int index, const char* name) { if (m_count == 0 || index > m_count) + { throw SALOME_Exception("Problem with number of elements"); + } m_elements[index].setName(name); } @@ -113,9 +114,5 @@ const int GeometricElementList::getIndexByReference(const char* ref) return index; } } - - return 0; -// std::string msg = "Cannot find element with reference "; -// msg += name; -// throw SALOME_Exception(msg.c_str()); + return -1; } diff --git a/src/XAO/GeometricElement.hxx b/src/XAO/GeometricElement.hxx index 93e15b3bd..533ed3267 100644 --- a/src/XAO/GeometricElement.hxx +++ b/src/XAO/GeometricElement.hxx @@ -24,32 +24,59 @@ #include #include - - namespace XAO { + /** + * \class GeometricElement + * Generic class to manipulate a topologic element (vertex, edge, face or solid). + */ class GeometricElement { public: + /** + * Default constructor. + */ GeometricElement(); + /** + * Constructor with name and reference. + * \param name the name of the element. + * \param reference the reference of the element. + */ GeometricElement(const char* name, const char* reference); - ~GeometricElement(); + /** + * Destructor. + */ + virtual ~GeometricElement(); + /** + * Gets the name of the element. + * \return the name. + */ const char* getName() { return m_name.c_str(); } - + /** + * Sets the name of the element + * \param name the name to set. + */ void setName(const char* name) { m_name = name; } + /** + * Gets the reference of the element. + * \return the reference. + */ const char* getReference() { return m_reference.c_str(); } - + /** + * Sets the reference of the element. + * \param reference the reference to set. + */ void setReference(const char* reference) { m_reference = reference; @@ -60,21 +87,82 @@ namespace XAO std::string m_reference; }; + /** + * \class GeometricElementList + * Generic class to manipulate a list of topologic element. + */ class GeometricElementList { public: + /** + * Default constructor. + */ GeometricElementList(); + /** + * Constructor with size. + * \param nb the size to set. + */ GeometricElementList(const int nb); - ~GeometricElementList() {} + /** + * Destructor. + */ + virtual ~GeometricElementList() {} + /** + * Gets the size of the list. + * \return the size of the list. + */ int getSize() { return m_count; } + /** + * Sets the size of the list. + * \param nb the size to set. + * \warning the list will be cleared. + */ void setSize(const int nb); + /** + * Sets the name and the reference of an element. + * \param index the index of the element to set. + * \param name the name to set. + * \param reference the reference to set. + * \throw SALOME_Exception if index is bigger than the size of the list. + */ void setElement(const int index, const char* name, const char* reference); + /** + * Gets the name of an element. + * \param index the index of the element to set. + * \return the name of the element with the given index. + * \throw SALOME_Exception if index is bigger than the size of the list. + */ const char* getName(const int index); + /** + * Sets the name of an element. + * \param index the index of the element. + * \param name the name to set. + * \throw SALOME_Exception if index is bigger than the size of the list. + */ void setName(const int index, const char* name); + + /** + * Gets the reference of an element. + * \param index the index of the element. + * \return the reference of the element. + * \throw SALOME_Exception if index is bigger than the size of the list. + */ const char* getReference(const int index); + /** + * Sets the reference of an element. + * \param index the index of the element to set. + * \param reference the reference to set. + * \throw SALOME_Exception if index is bigger than the size of the list. + */ void setReference(const int index, const char* reference); + + /** + * Gets the index of an element using its reference. + * \param reference the searched reference. + * \return the index of the element or -1 if no element found. + */ const int getIndexByReference(const char* reference); private: diff --git a/src/XAO/Geometry.cxx b/src/XAO/Geometry.cxx index d02ca6b0a..182469c98 100644 --- a/src/XAO/Geometry.cxx +++ b/src/XAO/Geometry.cxx @@ -43,6 +43,8 @@ #include #include +#include + using namespace XAO; Geometry::Geometry() @@ -105,42 +107,40 @@ void Geometry::initListIds(const Standard_Integer shapeType) TopTools_IndexedMapOfShape indices; TopExp::MapShapes(m_shape, indices); - //Handle (TColStd_HArray1OfInteger) anArray; std::list indexList; TopTools_ListIteratorOfListOfShape itSub(listShape); for (int index = 1; itSub.More(); itSub.Next(), ++index) { TopoDS_Shape value = itSub.Value(); - //std::cout << "index = " << indices.FindIndex(value) << std::endl; indexList.push_back(indices.FindIndex(value)); } std::list::iterator it = indexList.begin(); switch (shapeType) { - case TopAbs_VERTEX: /* Fill vertices ids */ + case TopAbs_VERTEX: { m_vertices.setSize(indexList.size()); for (int i = 0; it != indexList.end(); it++, i++) m_vertices.setReference(i, XaoUtils::intToString((*it))); break; } - case TopAbs_EDGE: /* Fill edges ids */ + case TopAbs_EDGE: { m_edges.setSize(indexList.size()); for (int i = 0; it != indexList.end(); it++, i++) m_edges.setReference(i, XaoUtils::intToString((*it))); break; } - case TopAbs_FACE: /* Fill faces ids */ + case TopAbs_FACE: { m_faces.setSize(indexList.size()); for (int i = 0; it != indexList.end(); it++, i++) m_faces.setReference(i, XaoUtils::intToString((*it))); break; } - case TopAbs_SOLID: /* Fill solids ids */ + case TopAbs_SOLID: { m_solids.setSize(indexList.size()); for (int i = 0; it != indexList.end(); it++, i++) @@ -148,6 +148,34 @@ void Geometry::initListIds(const Standard_Integer shapeType) break; } } +} +const char* Geometry::getElementReference(const Dimension dim, const int index) +{ + if (dim == VERTEX) + return getVertexReference(index); + if (dim == EDGE) + return getEdgeReference(index); + if (dim == FACE) + return getFaceReference(index); + if (dim == SOLID) + return getSolidReference(index); + + std::cout << "getElementReference: unknown dimension" << std::endl; + throw SALOME_Exception("Unknown dimension"); +} +const int Geometry::getElementIndexByReference(const Dimension dim, const char* reference) +{ + if (dim == VERTEX) + return getVertexIndexByReference(reference); + if (dim == EDGE) + return getEdgeIndexByReference(reference); + if (dim == FACE) + return getFaceIndexByReference(reference); + if (dim == SOLID) + return getSolidIndexByReference(reference); + + std::cout << "getElementIndexByReference: unknown dimension" << std::endl; + throw SALOME_Exception("Unknown dimension"); } diff --git a/src/XAO/Geometry.hxx b/src/XAO/Geometry.hxx index e083be912..a7bc4cbbb 100644 --- a/src/XAO/Geometry.hxx +++ b/src/XAO/Geometry.hxx @@ -26,7 +26,8 @@ #include #include -# include "GeometricElement.hxx" +#include "Xao.hxx" +#include "GeometricElement.hxx" namespace XAO { @@ -92,6 +93,7 @@ namespace XAO const char* getEdgeReference(const int index) { return m_edges.getReference(index); } const char* getFaceReference(const int index) { return m_faces.getReference(index); } const char* getSolidReference(const int index) { return m_solids.getReference(index); } + const char* getElementReference(const Dimension dim, const int index); void setVertexReference(const int index, const char* reference) { m_vertices.setReference(index, reference); } void setEdgeReference(const int index, const char* reference) { m_edges.setReference(index, reference); } @@ -102,6 +104,7 @@ namespace XAO const int getEdgeIndexByReference(const char* reference) { return m_edges.getIndexByReference(reference); } const int getFaceIndexByReference(const char* reference) { return m_faces.getIndexByReference(reference); } const int getSolidIndexByReference(const char* reference) { return m_solids.getIndexByReference(reference); } + const int getElementIndexByReference(const Dimension dim, const char* reference); private: void initListIds(const Standard_Integer shapeType); diff --git a/src/XAO/Group.cxx b/src/XAO/Group.cxx index 7c52ce1ce..e6a904a55 100644 --- a/src/XAO/Group.cxx +++ b/src/XAO/Group.cxx @@ -19,12 +19,13 @@ // Author : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade) #include "Group.hxx" +#include using namespace XAO; Group::Group() { - m_dimension = 0; + m_dimension = VERTEX; m_count = 0; } @@ -32,3 +33,12 @@ Group::~Group() { } +const Dimension Group::getDimension() +{ + return m_dimension; +} + +void Group::setDimension(const Dimension dimension) +{ + m_dimension = dimension; +} diff --git a/src/XAO/Group.hxx b/src/XAO/Group.hxx index 657cdf695..d4aa7ad62 100644 --- a/src/XAO/Group.hxx +++ b/src/XAO/Group.hxx @@ -25,6 +25,8 @@ #include #include +#include "Xao.hxx" + namespace XAO { class Group @@ -42,14 +44,8 @@ namespace XAO return m_name.c_str(); } - void setDimension(int dimension) - { - m_dimension = dimension; - } - int getDimension() - { - return m_dimension; - } + const Dimension getDimension(); + void setDimension(const Dimension dim); int getCount() { @@ -68,7 +64,7 @@ namespace XAO private: std::string m_name; - int m_dimension; + Dimension m_dimension; int m_count; std::vector m_elements; }; diff --git a/src/XAO/Xao.cxx b/src/XAO/Xao.cxx index 863b928f1..ecd66548a 100644 --- a/src/XAO/Xao.cxx +++ b/src/XAO/Xao.cxx @@ -76,7 +76,6 @@ Xao::Xao() m_author = ""; m_version = (char*)C_XAO_VERSION; m_geometry = NULL; - m_nbGroups = 0; } Xao::Xao(const char* author, const char* version) @@ -84,7 +83,6 @@ Xao::Xao(const char* author, const char* version) m_author = author; m_version = version; m_geometry = NULL; - m_nbGroups = 0; } Xao::~Xao() @@ -101,6 +99,11 @@ Xao::~Xao() // } } +int Xao::countGroups() +{ + return m_groups.size(); +} + Group* Xao::getGroup(const int index) { int i = 0; @@ -113,8 +116,46 @@ Group* Xao::getGroup(const int index) return NULL; } +void Xao::addGroup(Group* group) +{ + m_groups.push_back(group); +} + +void Xao::removeGroup(Group* group) +{ + m_groups.remove(group); +} + +int Xao::countFields() +{ + return m_fields.size(); +} + +IField* Xao::getField(const int index) +{ + int i = 0; + for (std::list::iterator it = m_fields.begin(); it != m_fields.end(); ++it, ++i) + { + if (i == index) + return (*it); + } + + return NULL; +} + +void Xao::addField(IField* field) +{ + m_fields.push_back(field); +} + +void Xao::removeField(IField* field) +{ + m_fields.remove(field); +} + + -bool Xao::exportToFile(const char* fileName) +bool Xao::exportXAO(const char* fileName) { xmlDocPtr doc = exportXMLDoc(); xmlSaveFormatFileEnc(fileName, doc, "UTF-8", 2); @@ -236,10 +277,10 @@ void Xao::exportGroups(xmlNodePtr xao) } } -bool Xao::importFromFile(const char* fileName) +bool Xao::importXAO(const char* fileName) { // parse the file and get the DOM - int options = 16384; // merge cdata as text node + int options = XML_PARSE_HUGE || XML_PARSE_NOCDATA; xmlDocPtr doc = xmlReadFile(fileName, NULL, options); if (doc == NULL) { @@ -250,6 +291,19 @@ bool Xao::importFromFile(const char* fileName) return true; } +bool Xao::setXML(const char* xml) +{ + int options = XML_PARSE_HUGE || XML_PARSE_NOCDATA; + xmlDocPtr doc = xmlReadDoc(BAD_CAST xml, "", NULL, options); + if (doc == NULL) + { + throw SALOME_Exception("Cannot read XAO stream"); + } + + parseXMLDoc(doc); + return true; +} + void Xao::parseXMLDoc(xmlDocPtr doc) { // Get the root element node diff --git a/src/XAO/Xao.hxx b/src/XAO/Xao.hxx index e7d28a8bc..58c4de3a0 100644 --- a/src/XAO/Xao.hxx +++ b/src/XAO/Xao.hxx @@ -27,72 +27,113 @@ namespace XAO { - enum Kind - { - VERTEX, - EDGE, - FACE, - SOLID - }; - - class Geometry; - class Group; - class Field; - - class Xao - { - public: - Xao(); - Xao(const char* author, const char* version); - ~Xao(); - - void setAuthor(const char* author) { m_author = author; } - const char* getAuthor() { return m_author.c_str(); } - - void setVersion(const char* version) { m_version = version; } - const char* getVersion() { return m_version.c_str(); } - - void setGeometry(Geometry* geometry) { m_geometry = geometry; } - Geometry* getGeometry() { return m_geometry; } - - int countGroups() { return m_groups.size(); } - Group* getGroup(const int index); - void addGroup(Group* group) { m_groups.push_back(group); } - void removeGroup(Group* group) { m_groups.remove(group); } - - bool exportToFile(const char* fileName); - const char* getXML(); - - bool importFromFile(const char* fileName); - bool setXML(const char* xml); - - - private: - std::string m_author; - std::string m_version; - Geometry* m_geometry; - int m_nbGroups; - std::list m_groups; - //int m_nbFields; - //std::list m_fields; - - xmlDocPtr exportXMLDoc(); - void exportGeometry(xmlDocPtr doc, xmlNodePtr xao); - void exportGroups(xmlNodePtr xao); - - void parseXMLDoc(xmlDocPtr doc); - void parseXaoNode(xmlDocPtr doc, xmlNodePtr xaoNode); - void parseGeometryNode(xmlDocPtr doc, xmlNodePtr geometryNode); - void parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode); - void parseTopologyNode(xmlNodePtr topologyNode); - void parseVerticesNode(xmlNodePtr verticesNode); - void parseEdgesNode(xmlNodePtr edgesNode); - void parseFacesNode(xmlNodePtr facesNode); - void parseSolidsNode(xmlNodePtr solidsNode); - void parseGroupsNode(xmlNodePtr groupsNode); - void parseGroupNode(xmlNodePtr groupNode); - - }; + /** + * @enum Dimension + */ + enum Dimension + { + VERTEX = 0,//!< VERTEX + EDGE = 1, //!< EDGE + FACE = 2, //!< FACE + SOLID = 3 //!< SOLID + }; + + class Geometry; + class Group; + class IField; + + /** + * @class Xao + * The Xao class describes the XAO format. + */ + class Xao + { + public: + Xao(); + Xao(const char* author, const char* version); + ~Xao(); + + const char* getAuthor() + { + return m_author.c_str(); + } + void setAuthor(const char* author) + { + m_author = author; + } + + const char* getVersion() + { + return m_version.c_str(); + } + void setVersion(const char* version) + { + m_version = version; + } + + // + // Geometry + // + + Geometry* getGeometry() + { + return m_geometry; + } + void setGeometry(Geometry* geometry) + { + m_geometry = geometry; + } + + // + // Groups + // + + int countGroups(); + Group* getGroup(const int index); + void addGroup(Group* group); + void removeGroup(Group* group); + + // + // Fields + // + + int countFields(); + IField* getField(const int index); + void addField(IField* field); + void removeField(IField* field); + + // + // Import / Export + // + bool exportXAO(const char* fileName); + const char* getXML(); + + bool importXAO(const char* fileName); + bool setXML(const char* xml); + + private: + std::string m_author; + std::string m_version; + Geometry* m_geometry; + std::list m_groups; + std::list m_fields; + + xmlDocPtr exportXMLDoc(); + void exportGeometry(xmlDocPtr doc, xmlNodePtr xao); + void exportGroups(xmlNodePtr xao); + + void parseXMLDoc(xmlDocPtr doc); + void parseXaoNode(xmlDocPtr doc, xmlNodePtr xaoNode); + void parseGeometryNode(xmlDocPtr doc, xmlNodePtr geometryNode); + void parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode); + void parseTopologyNode(xmlNodePtr topologyNode); + void parseVerticesNode(xmlNodePtr verticesNode); + void parseEdgesNode(xmlNodePtr edgesNode); + void parseFacesNode(xmlNodePtr facesNode); + void parseSolidsNode(xmlNodePtr solidsNode); + void parseGroupsNode(xmlNodePtr groupsNode); + void parseGroupNode(xmlNodePtr groupNode); + }; } diff --git a/src/XAO/XaoUtils.cxx b/src/XAO/XaoUtils.cxx index 1caf8c61f..67d78236f 100644 --- a/src/XAO/XaoUtils.cxx +++ b/src/XAO/XaoUtils.cxx @@ -22,6 +22,8 @@ #include #include #include + +#include "Xao.hxx" #include "XaoUtils.hxx" @@ -34,28 +36,28 @@ const char* XaoUtils::intToString(const int value) return str.str().c_str(); } -const char* XaoUtils::dimensionToString(const int dimension) +const char* XaoUtils::dimensionToString(const Dimension dimension) { - if (dimension == 0) + if (dimension == VERTEX) return "vertex"; - if (dimension == 1) + if (dimension == EDGE) return "edge"; - if (dimension == 2) + if (dimension == FACE) return "face"; - if (dimension == 3) + if (dimension == SOLID) return "solid"; throw SALOME_Exception("Bad dimension"); } -const int XaoUtils::stringToDimension(const char* dimension) +const Dimension XaoUtils::stringToDimension(const char* dimension) { if (strcmp(dimension, "vertex") == 0) - return 0; + return VERTEX; if (strcmp(dimension, "edge") == 0) - return 1; + return EDGE; if (strcmp(dimension, "face") == 0) - return 2; + return FACE; if (strcmp(dimension, "solid") == 0) - return 3; + return SOLID; throw SALOME_Exception("Bad dimension"); } diff --git a/src/XAO/XaoUtils.hxx b/src/XAO/XaoUtils.hxx index aac50817a..319cf30ba 100644 --- a/src/XAO/XaoUtils.hxx +++ b/src/XAO/XaoUtils.hxx @@ -21,14 +21,39 @@ #ifndef __XAO_UTILS_HXX__ #define __XAO_UTILS_HXX__ +#include "Xao.hxx" + namespace XAO { + /** + * \class XaoUtils + * Utilities class to convert types. + */ class XaoUtils { public: + /** + * Converts an integer into a string. + * \param value the integer to convert. + * \return the string. + */ static const char* intToString(const int value); - static const char* dimensionToString(const int dimension); - static const int stringToDimension(const char* dimension); + + /** + * Converts a Dimension to string. + * \param dimension the Dimension to convert. + * \return the dimension as a string. + * \throw SALOME_Exception + */ + static const char* dimensionToString(const Dimension dimension); + + /** + * Converts a string into a Dimension. + * \param dimension the dimension as a string. + * \return the converted Dimension. + * \throw SALOME_Exception if + */ + static const Dimension stringToDimension(const char* dimension); }; } diff --git a/src/XAO/tests/ImportExportTest.cxx b/src/XAO/tests/ImportExportTest.cxx index 30ef338d5..28fe95ce5 100644 --- a/src/XAO/tests/ImportExportTest.cxx +++ b/src/XAO/tests/ImportExportTest.cxx @@ -50,7 +50,7 @@ void ImportExportTest::testExportNoGeometry() { Xao xao("me", "1.0"); - bool res = xao.exportToFile("empty.xao"); + bool res = xao.exportXAO("empty.xao"); CPPUNIT_ASSERT(res); } @@ -82,18 +82,18 @@ void ImportExportTest::testExportGeometry() Group* group = new Group(); xao.addGroup(group); group->setName("boite1"); - group->setDimension(3); + group->setDimension(XAO::SOLID); group->addElement(1); group = new Group(); xao.addGroup(group); group->setName("faces"); - group->setDimension(2); + group->setDimension(XAO::FACE); group->addElement(5); group->addElement(8); group->addElement(9); - bool res = xao.exportToFile("mygeom.xao"); + bool res = xao.exportXAO("mygeom.xao"); CPPUNIT_ASSERT(res); const char* xml = xao.getXML(); @@ -115,7 +115,12 @@ void ImportExportTest::testImportXao() { //std::cout << std::endl; Xao xao; - xao.importFromFile(getTestFile("test.xao").c_str()); + xao.importXAO(getTestFile("test.xao").c_str()); + checkImport(xao); +} + +void ImportExportTest::checkImport(Xao& xao) +{ CPPUNIT_ASSERT(strcmp(xao.getAuthor(), "me") == 0); CPPUNIT_ASSERT(strcmp(xao.getVersion(), "1.0") == 0); @@ -155,13 +160,30 @@ void ImportExportTest::testImportXao() Group* group = xao.getGroup(0); CPPUNIT_ASSERT(group->getCount() == 1); CPPUNIT_ASSERT(strcmp(group->getName(), "boite_1") == 0); - CPPUNIT_ASSERT(group->getDimension() == 3); + CPPUNIT_ASSERT(group->getDimension() == XAO::SOLID); CPPUNIT_ASSERT(group->getElement(0) == 1); group = xao.getGroup(1); CPPUNIT_ASSERT(group->getCount() == 3); CPPUNIT_ASSERT(strcmp(group->getName(), "") == 0); - CPPUNIT_ASSERT(group->getDimension() == 2); + CPPUNIT_ASSERT(group->getDimension() == XAO::FACE); CPPUNIT_ASSERT(group->getElement(0) == 5); CPPUNIT_ASSERT(group->getElement(1) == 8); CPPUNIT_ASSERT(group->getElement(2) == 9); } + +void ImportExportTest::testImportXaoFromText() +{ + std::ifstream rstr; + int length; + rstr.open(getTestFile("test.xao").c_str()); + rstr.seekg(0, rstr.end); // go to the end + length = rstr.tellg(); // report location (this is the length) + rstr.seekg(0, rstr.beg); // go back to the beginning + char* txt = new char[length]; // allocate memory for a buffer of appropriate dimension + rstr.read(txt, length); // read the whole file into the buffer + rstr.close(); + + Xao xao; + xao.setXML(txt); + checkImport(xao); +} diff --git a/src/XAO/tests/ImportExportTest.hxx b/src/XAO/tests/ImportExportTest.hxx index a2be0f415..6f7926808 100644 --- a/src/XAO/tests/ImportExportTest.hxx +++ b/src/XAO/tests/ImportExportTest.hxx @@ -14,6 +14,7 @@ namespace XAO CPPUNIT_TEST(testExportGeometry); CPPUNIT_TEST(testGeometryError); CPPUNIT_TEST(testImportXao); + CPPUNIT_TEST(testImportXaoFromText); CPPUNIT_TEST_SUITE_END(); public: @@ -25,6 +26,9 @@ namespace XAO void testExportGeometry(); void testGeometryError(); void testImportXao(); + void testImportXaoFromText(); + + void checkImport(Xao& xao); }; } diff --git a/src/XAO/tests/Makefile.am b/src/XAO/tests/Makefile.am index 1efe609a0..4533db12a 100755 --- a/src/XAO/tests/Makefile.am +++ b/src/XAO/tests/Makefile.am @@ -1,3 +1,22 @@ +# Copyright (C) 2013 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# Author : Nathalie Gore (OpenCascade) include $(top_srcdir)/adm_local/unix/make_common_starter.am -- 2.39.2