mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2025-01-28 06:50:33 +05:00
add generic method to get element by type
use enum instead of integer
This commit is contained in:
parent
f74d6b98cb
commit
e2e1c99ebc
@ -18,31 +18,32 @@
|
||||
//
|
||||
// Author : Nathalie Gore (OpenCascade)
|
||||
|
||||
#include "Xao.hxx"
|
||||
#include "Field.hxx"
|
||||
|
||||
using namespace XAO;
|
||||
|
||||
Field::Field()
|
||||
template<typename T>
|
||||
Field<T>::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<typename T>
|
||||
Field<T>::Field(const char* name, const FieldDimension dim, const int nbComponents)
|
||||
: m_name(name), m_dimension(dim)
|
||||
{
|
||||
m_components.reserve(nbComponents);
|
||||
}
|
||||
|
||||
Field *Field::New()
|
||||
template<typename T>
|
||||
void Field<T>::setComponentName(const int index, const char* name)
|
||||
{
|
||||
return new Field;
|
||||
if (index < m_components.size())
|
||||
{
|
||||
m_components[index] = name;
|
||||
}
|
||||
|
||||
// TODO: throw
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "Xao.hxx"
|
||||
|
||||
namespace XAO
|
||||
{
|
||||
typedef enum
|
||||
{
|
||||
VERTEX = 0,
|
||||
EDGE = 1,
|
||||
FACE = 2,
|
||||
SOLID = 3
|
||||
} FieldDimension;
|
||||
enum FieldType
|
||||
{
|
||||
FIELD_BOOLEAN = 0,
|
||||
FIELD_INTEGER = 1,
|
||||
FIELD_DOUBLE = 2,
|
||||
FIELD_STRING = 3
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BOOLEAN = 0,
|
||||
INTEGER = 1,
|
||||
DOUBLE = 2,
|
||||
STRING = 3
|
||||
} FieldType;
|
||||
enum FieldDimension
|
||||
{
|
||||
FIELD_VERTEX = 0,
|
||||
FIELD_EDGE = 1,
|
||||
FIELD_FACE = 2,
|
||||
FIELD_SOLID = 3,
|
||||
FIELD_WHOLE = -1
|
||||
};
|
||||
|
||||
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; }
|
||||
template <typename T>
|
||||
class Step
|
||||
{
|
||||
public:
|
||||
private:
|
||||
int m_number;
|
||||
int m_stamp;
|
||||
std::map<int, T> m_values;
|
||||
|
||||
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;
|
||||
};
|
||||
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 <typename T>
|
||||
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<std::string> m_components;
|
||||
std::list< Step<T>* > m_steps;
|
||||
};
|
||||
|
||||
class BooleanField : Field<bool>
|
||||
{
|
||||
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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -24,32 +24,59 @@
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
|
||||
|
||||
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:
|
||||
|
@ -43,6 +43,8 @@
|
||||
#include <TColStd_HArray1OfInteger.hxx>
|
||||
#include <TColStd_HSequenceOfInteger.hxx>
|
||||
|
||||
#include <Utils_SALOME_Exception.hxx>
|
||||
|
||||
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<int> 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<int>::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");
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,8 @@
|
||||
#include <SALOMEconfig.h>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
|
||||
# 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);
|
||||
|
@ -19,12 +19,13 @@
|
||||
// Author : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade)
|
||||
|
||||
#include "Group.hxx"
|
||||
#include <Utils_SALOME_Exception.hxx>
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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<int> m_elements;
|
||||
};
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
bool Xao::exportToFile(const char* fileName)
|
||||
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<IField*>::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::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
|
||||
|
147
src/XAO/Xao.hxx
147
src/XAO/Xao.hxx
@ -27,72 +27,113 @@
|
||||
|
||||
namespace XAO
|
||||
{
|
||||
enum Kind
|
||||
{
|
||||
VERTEX,
|
||||
EDGE,
|
||||
FACE,
|
||||
SOLID
|
||||
};
|
||||
/**
|
||||
* @enum Dimension
|
||||
*/
|
||||
enum Dimension
|
||||
{
|
||||
VERTEX = 0,//!< VERTEX
|
||||
EDGE = 1, //!< EDGE
|
||||
FACE = 2, //!< FACE
|
||||
SOLID = 3 //!< SOLID
|
||||
};
|
||||
|
||||
class Geometry;
|
||||
class Group;
|
||||
class Field;
|
||||
class Geometry;
|
||||
class Group;
|
||||
class IField;
|
||||
|
||||
class Xao
|
||||
{
|
||||
public:
|
||||
Xao();
|
||||
Xao(const char* author, const char* version);
|
||||
~Xao();
|
||||
/**
|
||||
* @class Xao
|
||||
* The Xao class describes the XAO format.
|
||||
*/
|
||||
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(); }
|
||||
const char* getAuthor()
|
||||
{
|
||||
return m_author.c_str();
|
||||
}
|
||||
void setAuthor(const char* author)
|
||||
{
|
||||
m_author = author;
|
||||
}
|
||||
|
||||
void setVersion(const char* version) { m_version = version; }
|
||||
const char* getVersion() { return m_version.c_str(); }
|
||||
const char* getVersion()
|
||||
{
|
||||
return m_version.c_str();
|
||||
}
|
||||
void setVersion(const char* version)
|
||||
{
|
||||
m_version = version;
|
||||
}
|
||||
|
||||
void setGeometry(Geometry* geometry) { m_geometry = geometry; }
|
||||
Geometry* getGeometry() { return m_geometry; }
|
||||
//
|
||||
// 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); }
|
||||
Geometry* getGeometry()
|
||||
{
|
||||
return m_geometry;
|
||||
}
|
||||
void setGeometry(Geometry* geometry)
|
||||
{
|
||||
m_geometry = geometry;
|
||||
}
|
||||
|
||||
bool exportToFile(const char* fileName);
|
||||
const char* getXML();
|
||||
//
|
||||
// Groups
|
||||
//
|
||||
|
||||
bool importFromFile(const char* fileName);
|
||||
bool setXML(const char* xml);
|
||||
int countGroups();
|
||||
Group* getGroup(const int index);
|
||||
void addGroup(Group* group);
|
||||
void removeGroup(Group* group);
|
||||
|
||||
//
|
||||
// Fields
|
||||
//
|
||||
|
||||
private:
|
||||
std::string m_author;
|
||||
std::string m_version;
|
||||
Geometry* m_geometry;
|
||||
int m_nbGroups;
|
||||
std::list<Group*> m_groups;
|
||||
//int m_nbFields;
|
||||
//std::list<Field*> m_fields;
|
||||
int countFields();
|
||||
IField* getField(const int index);
|
||||
void addField(IField* field);
|
||||
void removeField(IField* field);
|
||||
|
||||
xmlDocPtr exportXMLDoc();
|
||||
void exportGeometry(xmlDocPtr doc, xmlNodePtr xao);
|
||||
void exportGroups(xmlNodePtr xao);
|
||||
//
|
||||
// Import / Export
|
||||
//
|
||||
bool exportXAO(const char* fileName);
|
||||
const char* getXML();
|
||||
|
||||
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);
|
||||
bool importXAO(const char* fileName);
|
||||
bool setXML(const char* xml);
|
||||
|
||||
};
|
||||
private:
|
||||
std::string m_author;
|
||||
std::string m_version;
|
||||
Geometry* m_geometry;
|
||||
std::list<Group*> m_groups;
|
||||
std::list<IField*> 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);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include <sstream>
|
||||
#include <iosfwd>
|
||||
#include <Utils_SALOME_Exception.hxx>
|
||||
|
||||
#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");
|
||||
}
|
||||
|
@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user