improve exception messages

add more tests
This commit is contained in:
fps 2013-09-03 15:56:58 +00:00
parent 54030bc86c
commit 29d01572ac
34 changed files with 1158 additions and 242 deletions

View File

@ -25,26 +25,26 @@
using namespace XAO; using namespace XAO;
BooleanField::BooleanField(const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents) BooleanField::BooleanField(const XAO::Dimension& dimension,
const int& nbElements, const int& nbComponents)
: Field("", dimension, nbElements, nbComponents) : Field("", dimension, nbElements, nbComponents)
{ {
} }
BooleanField::BooleanField(const std::string& name, const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents) BooleanField::BooleanField(const std::string& name, const XAO::Dimension& dimension,
const int& nbElements, const int& nbComponents)
: Field(name, dimension, nbElements, nbComponents) : Field(name, dimension, nbElements, nbComponents)
{ {
} }
Step* BooleanField::addNewStep(const int& step) Step* BooleanField::addNewStep(const int& step)
{ {
return addStep(step); return addStep(step, 0);
} }
BooleanStep* BooleanField::addStep(const int& step) BooleanStep* BooleanField::addStep(const int& step)
{ {
BooleanStep* bstep = new BooleanStep(step, m_nbElements, m_nbComponents); return addStep(step, 0);
m_steps.push_back(bstep);
return bstep;
} }
BooleanStep* BooleanField::addStep(const int& step, const int& stamp) BooleanStep* BooleanField::addStep(const int& step, const int& stamp)
@ -56,7 +56,6 @@ BooleanStep* BooleanField::addStep(const int& step, const int& stamp)
BooleanStep* BooleanField::getStep(const int& index) BooleanStep* BooleanField::getStep(const int& index)
{ {
if (index < m_steps.size()) checkStepIndex(index);
return (BooleanStep*)m_steps[index]; return (BooleanStep*)m_steps[index];
throw SALOME_Exception("IndexOutOfRange");
} }

View File

@ -18,8 +18,9 @@
// //
// Author : Frederic Pons (OpenCascade) // Author : Frederic Pons (OpenCascade)
#include "BooleanStep.hxx"
#include <Utils_SALOME_Exception.hxx> #include <Utils_SALOME_Exception.hxx>
#include "BooleanStep.hxx"
#include "XaoUtils.hxx"
using namespace XAO; using namespace XAO;
@ -73,7 +74,7 @@ std::vector<bool> BooleanStep::getValues()
std::vector<bool> BooleanStep::getElement(const int& element) std::vector<bool> BooleanStep::getElement(const int& element)
{ {
checkElement(element); checkElementIndex(element);
std::vector<bool> result(m_values[element]); std::vector<bool> result(m_values[element]);
return result; return result;
@ -81,7 +82,7 @@ std::vector<bool> BooleanStep::getElement(const int& element)
std::vector<bool> BooleanStep::getComponent(const int& component) std::vector<bool> BooleanStep::getComponent(const int& component)
{ {
checkComponent(component); checkComponentIndex(component);
std::vector<bool> result; std::vector<bool> result;
result.reserve(m_nbElements); result.reserve(m_nbElements);
@ -98,8 +99,8 @@ std::vector<bool> BooleanStep::getComponent(const int& component)
const bool BooleanStep::getValue(const int& element, const int& component) const bool BooleanStep::getValue(const int& element, const int& component)
{ {
checkElement(element); checkElementIndex(element);
checkComponent(component); checkComponentIndex(component);
return m_values[element][component]; return m_values[element][component];
} }
@ -111,8 +112,7 @@ const std::string BooleanStep::getStringValue(const int& element, const int& com
void BooleanStep::setValues(const std::vector<bool>& values) void BooleanStep::setValues(const std::vector<bool>& values)
{ {
if (values.size() != m_nbComponents * m_nbElements) checkNbValues((int)values.size());
throw SALOME_Exception("bad size"); // TODO
for (int i = 0; i < m_nbElements; ++i) for (int i = 0; i < m_nbElements; ++i)
{ {
@ -125,9 +125,8 @@ void BooleanStep::setValues(const std::vector<bool>& values)
void BooleanStep::setElements(const int& element, const std::vector<bool>& elements) void BooleanStep::setElements(const int& element, const std::vector<bool>& elements)
{ {
checkElement(element); checkElementIndex(element);
if (elements.size() != m_nbComponents) checkNbElements((int)elements.size());
throw SALOME_Exception("bad size"); // TODO
for (int i = 0; i < m_nbComponents; ++i) for (int i = 0; i < m_nbComponents; ++i)
m_values[element][i] = elements[i]; m_values[element][i] = elements[i];
@ -135,9 +134,8 @@ void BooleanStep::setElements(const int& element, const std::vector<bool>& eleme
void BooleanStep::setComponents(const int& component, const std::vector<bool>& components) void BooleanStep::setComponents(const int& component, const std::vector<bool>& components)
{ {
checkComponent(component); checkComponentIndex(component);
if (components.size() != m_nbElements) checkNbElements((int)components.size());
throw SALOME_Exception("bad size"); // TODO
for (int i = 0; i < m_nbElements; ++i) for (int i = 0; i < m_nbElements; ++i)
m_values[i][component] = components[i]; m_values[i][component] = components[i];
@ -145,8 +143,8 @@ void BooleanStep::setComponents(const int& component, const std::vector<bool>& c
void BooleanStep::setValue(const int& element, const int& component, const bool& value) void BooleanStep::setValue(const int& element, const int& component, const bool& value)
{ {
checkElement(element); checkElementIndex(element);
checkComponent(component); checkComponentIndex(component);
m_values[element][component] = value; m_values[element][component] = value;
} }
@ -154,7 +152,7 @@ void BooleanStep::setValue(const int& element, const int& component, const bool&
void BooleanStep::setStringValue(const int& element, const int& component, const std::string& value) void BooleanStep::setStringValue(const int& element, const int& component, const std::string& value)
{ {
if (value != "true" && value != "false") if (value != "true" && value != "false")
throw SALOME_Exception("Bad boolean value"); throw SALOME_Exception(MsgBuilder() << "Bad boolean value: " << value);
setValue(element, component, value == "true"); setValue(element, component, value == "true");
} }

View File

@ -18,6 +18,8 @@
// //
// Author : Frederic Pons (OpenCascade) // Author : Frederic Pons (OpenCascade)
#include <cassert>
#include <TopTools_MapOfShape.hxx> #include <TopTools_MapOfShape.hxx>
#include <TopTools_ListOfShape.hxx> #include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx> #include <TopTools_ListIteratorOfListOfShape.hxx>
@ -74,7 +76,7 @@ TopoDS_Shape BrepGeometry::getGeometricalElement(TopAbs_ShapeEnum shapeType, con
} }
} }
throw SALOME_Exception("Shape not found"); // TODO throw SALOME_Exception(MsgBuilder() << "Shape not found: " << shapeIndex);
} }
const int BrepGeometry::countGeometricalElements(TopoDS_Shape shape, TopAbs_ShapeEnum shapeType) const int BrepGeometry::countGeometricalElements(TopoDS_Shape shape, TopAbs_ShapeEnum shapeType)
@ -121,10 +123,14 @@ std::vector<int> BrepGeometry::getGeometricalElements(TopoDS_Shape shape, TopAbs
return indexList; return indexList;
} }
void BrepGeometry::getEdgeVertices(const int& edge, int& vertexA, int& vertexB) void BrepGeometry::getEdgeVertices(const int& edge, int& vertexA, int& vertexB)
{ {
throw SALOME_Exception("Not implemented"); TopoDS_Shape shape = getGeometricalElement(TopAbs_EDGE, edge);
std::vector<int> vertices = getGeometricalElements(shape, TopAbs_VERTEX);
assert(vertices.size() == 2);
vertexA = vertices[0];
vertexB = vertices[1];
} }
const int BrepGeometry::countFaceWires(const int& face) const int BrepGeometry::countFaceWires(const int& face)
@ -153,23 +159,21 @@ std::vector<int> BrepGeometry::getSolidShells(const int& solid)
void BrepGeometry::getVertexXYZ(const int& vertex, double& xCoord, double& yCoord, double& zCoord) void BrepGeometry::getVertexXYZ(const int& vertex, double& xCoord, double& yCoord, double& zCoord)
{ {
TopoDS_Shape shape = getGeometricalElement(TopAbs_VERTEX, vertex);
xCoord = 0.; xCoord = 0.;
yCoord = 0.; yCoord = 0.;
zCoord = 0.; zCoord = 0.;
if ( shape.ShapeType() != TopAbs_VERTEX )
{
throw SALOME_Exception("not a point"); // TODO
}
TopoDS_Vertex aPoint = TopoDS::Vertex( shape ); TopoDS_Shape shape = getGeometricalElement(TopAbs_VERTEX, vertex);
if ( !aPoint.IsNull() ) if (shape.ShapeType() != TopAbs_VERTEX)
throw SALOME_Exception(MsgBuilder() << "Shape " << vertex << " is not a point.");
TopoDS_Vertex point = TopoDS::Vertex(shape);
if (!point.IsNull())
{ {
gp_Pnt aPnt = BRep_Tool::Pnt( aPoint ); gp_Pnt aPnt = BRep_Tool::Pnt(point);
xCoord = aPnt.X(); xCoord = aPnt.X();
yCoord = aPnt.Y(); yCoord = aPnt.Y();
zCoord = aPnt.Z(); zCoord = aPnt.Z();
} }
} }
@ -296,4 +300,3 @@ void BrepGeometry::changeSolidName(const int& id, const std::string& name)
{ {
setSolidName(findSolid(id), name); setSolidName(findSolid(id), name);
} }

View File

@ -37,14 +37,12 @@ DoubleField::DoubleField(const std::string& name, const XAO::Dimension& dimensio
Step* DoubleField::addNewStep(const int& step) Step* DoubleField::addNewStep(const int& step)
{ {
return addStep(step); return addStep(step, 0);
} }
DoubleStep* DoubleField::addStep(const int& step) DoubleStep* DoubleField::addStep(const int& step)
{ {
DoubleStep* bstep = new DoubleStep(step, m_nbElements, m_nbComponents); return addStep(step, 0);
m_steps.push_back(bstep);
return bstep;
} }
DoubleStep* DoubleField::addStep(const int& step, const int& stamp) DoubleStep* DoubleField::addStep(const int& step, const int& stamp)
@ -56,7 +54,6 @@ DoubleStep* DoubleField::addStep(const int& step, const int& stamp)
DoubleStep* DoubleField::getStep(const int& index) DoubleStep* DoubleField::getStep(const int& index)
{ {
if (index < m_steps.size()) checkStepIndex(index);
return (DoubleStep*)m_steps[index]; return (DoubleStep*)m_steps[index];
throw SALOME_Exception("IndexOutOfRange");
} }

View File

@ -74,7 +74,7 @@ std::vector<double> DoubleStep::getValues()
std::vector<double> DoubleStep::getElement(const int& element) std::vector<double> DoubleStep::getElement(const int& element)
{ {
checkElement(element); checkElementIndex(element);
std::vector<double> result(m_values[element]); std::vector<double> result(m_values[element]);
return result; return result;
@ -82,7 +82,7 @@ std::vector<double> DoubleStep::getElement(const int& element)
std::vector<double> DoubleStep::getComponent(const int& component) std::vector<double> DoubleStep::getComponent(const int& component)
{ {
checkComponent(component); checkComponentIndex(component);
std::vector<double> result; std::vector<double> result;
result.reserve(m_nbElements); result.reserve(m_nbElements);
@ -99,8 +99,8 @@ std::vector<double> DoubleStep::getComponent(const int& component)
const double DoubleStep::getValue(const int& element, const int& component) const double DoubleStep::getValue(const int& element, const int& component)
{ {
checkElement(element); checkElementIndex(element);
checkComponent(component); checkComponentIndex(component);
return m_values[element][component]; return m_values[element][component];
} }
@ -112,8 +112,7 @@ const std::string DoubleStep::getStringValue(const int& element, const int& comp
void DoubleStep::setValues(const std::vector<double>& values) void DoubleStep::setValues(const std::vector<double>& values)
{ {
if (values.size() != m_nbComponents * m_nbElements) checkNbValues(values.size());
throw SALOME_Exception("bad size"); // TODO
for (int i = 0; i < m_nbElements; ++i) for (int i = 0; i < m_nbElements; ++i)
{ {
@ -126,9 +125,8 @@ void DoubleStep::setValues(const std::vector<double>& values)
void DoubleStep::setElements(const int& element, const std::vector<double>& elements) void DoubleStep::setElements(const int& element, const std::vector<double>& elements)
{ {
checkElement(element); checkElementIndex(element);
if (elements.size() != m_nbComponents) checkNbComponents(elements.size());
throw SALOME_Exception("bad size"); // TODO
for (int i = 0; i < m_nbComponents; ++i) for (int i = 0; i < m_nbComponents; ++i)
m_values[element][i] = elements[i]; m_values[element][i] = elements[i];
@ -136,9 +134,8 @@ void DoubleStep::setElements(const int& element, const std::vector<double>& elem
void DoubleStep::setComponents(const int& component, const std::vector<double>& components) void DoubleStep::setComponents(const int& component, const std::vector<double>& components)
{ {
checkElement(component); checkElementIndex(component);
if (components.size() != m_nbElements) checkNbElements(components.size());
throw SALOME_Exception("bad size"); // TODO
for (int i = 0; i < m_nbElements; ++i) for (int i = 0; i < m_nbElements; ++i)
m_values[i][component] = components[i]; m_values[i][component] = components[i];
@ -146,8 +143,8 @@ void DoubleStep::setComponents(const int& component, const std::vector<double>&
void DoubleStep::setValue(const int& element, const int& component, const double& value) void DoubleStep::setValue(const int& element, const int& component, const double& value)
{ {
checkElement(element); checkElementIndex(element);
checkComponent(component); checkComponentIndex(component);
m_values[element][component] = value; m_values[element][component] = value;
} }

View File

@ -19,16 +19,16 @@
// Author : Frederic Pons (OpenCascade) // Author : Frederic Pons (OpenCascade)
#include <string> #include <string>
#include <sstream>
#include <iostream> #include <iostream>
#include <Utils_SALOME_Exception.hxx>
#include "Xao.hxx" #include "Xao.hxx"
#include "Field.hxx" #include "Field.hxx"
#include "BooleanField.hxx" #include "BooleanField.hxx"
#include "IntegerField.hxx" #include "IntegerField.hxx"
#include "DoubleField.hxx" #include "DoubleField.hxx"
#include "StringField.hxx" #include "StringField.hxx"
#include "XaoUtils.hxx"
#include <Utils_SALOME_Exception.hxx>
using namespace XAO; using namespace XAO;
@ -67,26 +67,19 @@ Field* Field::createField(const XAO::Type& type, const std::string& name, const
if (type == XAO::STRING) if (type == XAO::STRING)
return new StringField(name, dimension, nbElements, nbComponents); return new StringField(name, dimension, nbElements, nbComponents);
throw SALOME_Exception("Bad Type"); throw SALOME_Exception(MsgBuilder() << "Bad Type:" << type);
} }
const std::string Field::getComponentName(const int& index) const std::string Field::getComponentName(const int& index)
{ {
if (index < m_components.size()) checkComponent(index);
return m_components[index]; return m_components[index];
throw SALOME_Exception("IndexOutOfRange component");
} }
void Field::setComponentName(const int& index, const std::string& name) void Field::setComponentName(const int& index, const std::string& name)
{ {
if (index < m_components.size()) checkComponent(index);
{ m_components[index] = name;
m_components[index] = name;
return;
}
throw SALOME_Exception("IndexOutOfRange component");
} }
bool Field::removeStep(Step* step) bool Field::removeStep(Step* step)
@ -105,12 +98,20 @@ bool Field::removeStep(Step* step)
return false; return false;
} }
void Field::checkStep(const int& step) void Field::checkComponent(const int& component)
{ {
if (step >= m_steps.size() || step < 0) if (component < m_nbComponents && component >= 0)
{ return;
std::ostringstream str;
str << "Step index is out of range [0, " << m_steps.size() << "] : " << step; throw SALOME_Exception(MsgBuilder() << "Step index is out of range [0, "
throw SALOME_Exception(str.str().c_str()); << m_nbComponents << "] : " << component);
} }
void Field::checkStepIndex(const int& step)
{
if (step < m_steps.size() && step >= 0)
return;
throw SALOME_Exception(MsgBuilder() << "Step index is out of range [0, "
<< m_steps.size() << "] : " << step);
} }

View File

@ -90,7 +90,7 @@ namespace XAO
* Gets the name of the Field. * Gets the name of the Field.
* @return the name of the Field. * @return the name of the Field.
*/ */
const std::string getName() const std::string getName() const
{ {
return m_name; return m_name;
} }
@ -108,7 +108,7 @@ namespace XAO
* Gets the Dimension of the Field. * Gets the Dimension of the Field.
* @return the Dimension of the Field. * @return the Dimension of the Field.
*/ */
const XAO::Dimension getDimension() const XAO::Dimension getDimension() const
{ {
return m_dimension; return m_dimension;
} }
@ -117,7 +117,7 @@ namespace XAO
* Gets the number of elements of each step. * Gets the number of elements of each step.
* @return the number of elements of each step. * @return the number of elements of each step.
*/ */
const int countElements() const int countElements() const
{ {
return m_nbElements; return m_nbElements;
} }
@ -126,7 +126,7 @@ namespace XAO
* Gets the number of components. * Gets the number of components.
* @return the number of components. * @return the number of components.
*/ */
const int countComponents() const int countComponents() const
{ {
return m_nbComponents; return m_nbComponents;
} }
@ -135,7 +135,7 @@ namespace XAO
* Gets the number of values for each step. * Gets the number of values for each step.
* @return the number of values for each step. * @return the number of values for each step.
*/ */
const int countValues() const int countValues() const
{ {
return m_nbElements * m_nbComponents; return m_nbElements * m_nbComponents;
} }
@ -144,7 +144,7 @@ namespace XAO
* Gets the number of the steps. * Gets the number of the steps.
* @return the number of steps. * @return the number of steps.
*/ */
const int countSteps() { return m_steps.size(); } const int countSteps() const { return m_steps.size(); }
/** /**
* Gets the name of a component. * Gets the name of a component.
@ -186,10 +186,10 @@ namespace XAO
*/ */
stepIterator end() { return m_steps.end(); } stepIterator end() { return m_steps.end(); }
private: protected:
/** Ensures that component is valid (< m_nbComponents). */ /** Ensures that component is valid (< m_nbComponents). */
void checkComponent(const int& component); void checkComponent(const int& component);
void checkStep(const int& step); void checkStepIndex(const int& step);
protected: protected:
/** The name of the Field. */ /** The name of the Field. */

View File

@ -41,7 +41,7 @@ GeometricElement::~GeometricElement()
{ {
} }
bool GeometricElement::hasName() const bool GeometricElement::hasName()
{ {
return !m_name.empty(); return !m_name.empty();
} }

View File

@ -69,7 +69,7 @@ namespace XAO
* Checks if the element has a name. * Checks if the element has a name.
* @return true if the element has a name, false otherwise. * @return true if the element has a name, false otherwise.
*/ */
bool hasName(); const bool hasName();
/** /**
* Gets the reference of the element. * Gets the reference of the element.
@ -122,7 +122,7 @@ namespace XAO
* Gets the size of the list. * Gets the size of the list.
* \return the size of the list. * \return the size of the list.
*/ */
const int getSize() { return m_count; } const int getSize() const { return m_count; }
/** /**
* Sets the size of the list. * Sets the size of the list.

View File

@ -56,14 +56,15 @@ Geometry::Geometry(const std::string& name)
Geometry* Geometry::createGeometry(const XAO::Format& format) Geometry* Geometry::createGeometry(const XAO::Format& format)
{ {
return createGeometry(format,""); return createGeometry(format, "");
} }
Geometry* Geometry::createGeometry(const XAO::Format& format, const std::string& name) Geometry* Geometry::createGeometry(const XAO::Format& format, const std::string& name)
{ {
if (format == XAO::BREP) if (format == XAO::BREP)
return new BrepGeometry(name); return new BrepGeometry(name);
throw SALOME_Exception("Geometry format not supported.");
throw SALOME_Exception(MsgBuilder() << "Geometry format not supported: " << format);
} }
Geometry::~Geometry() Geometry::~Geometry()
@ -175,7 +176,7 @@ const int Geometry::countElements(const XAO::Dimension& dim)
if (dim == XAO::SOLID) if (dim == XAO::SOLID)
return countSolids(); return countSolids();
throw SALOME_Exception("Unknown dimension"); // TODO throw SALOME_Exception(MsgBuilder() << "Unknown dimension:" << dim);
} }
const std::string Geometry::getElementReference(const XAO::Dimension& dim, const int& index) const std::string Geometry::getElementReference(const XAO::Dimension& dim, const int& index)
@ -189,7 +190,7 @@ const std::string Geometry::getElementReference(const XAO::Dimension& dim, const
if (dim == XAO::SOLID) if (dim == XAO::SOLID)
return getSolidReference(index); return getSolidReference(index);
throw SALOME_Exception("Unknown dimension"); // TODO throw SALOME_Exception(MsgBuilder() << "Unknown dimension:" << dim);
} }
const int Geometry::getElementIndexByReference(const XAO::Dimension& dim, const std::string& reference) const int Geometry::getElementIndexByReference(const XAO::Dimension& dim, const std::string& reference)
@ -203,7 +204,7 @@ const int Geometry::getElementIndexByReference(const XAO::Dimension& dim, const
if (dim == XAO::SOLID) if (dim == XAO::SOLID)
return getSolidIndexByReference(reference); return getSolidIndexByReference(reference);
throw SALOME_Exception("Unknown dimension"); // TODO throw SALOME_Exception(MsgBuilder() << "Unknown dimension:" << dim);
} }
GeometricElementList::iterator Geometry::begin(const XAO::Dimension& dim) GeometricElementList::iterator Geometry::begin(const XAO::Dimension& dim)
@ -217,7 +218,7 @@ GeometricElementList::iterator Geometry::begin(const XAO::Dimension& dim)
if (dim == XAO::SOLID) if (dim == XAO::SOLID)
return m_solids.begin(); return m_solids.begin();
throw SALOME_Exception("Unknown dimension"); // TODO throw SALOME_Exception(MsgBuilder() << "Unknown dimension:" << dim);
} }
GeometricElementList::iterator Geometry::end(const XAO::Dimension& dim) GeometricElementList::iterator Geometry::end(const XAO::Dimension& dim)
@ -231,5 +232,5 @@ GeometricElementList::iterator Geometry::end(const XAO::Dimension& dim)
if (dim == XAO::SOLID) if (dim == XAO::SOLID)
return m_solids.end(); return m_solids.end();
throw SALOME_Exception("Unknown dimension"); // TODO throw SALOME_Exception(MsgBuilder() << "Unknown dimension:" << dim);
} }

View File

@ -18,10 +18,11 @@
// //
// Author : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade) // Author : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade)
#include <sstream>
#include "Group.hxx"
#include <Utils_SALOME_Exception.hxx> #include <Utils_SALOME_Exception.hxx>
#include "XaoUtils.hxx"
#include "Group.hxx"
using namespace XAO; using namespace XAO;
@ -37,6 +38,9 @@ Group::Group(const std::string& name, const XAO::Dimension& dim, const int& nbEl
void Group::initGroup(const std::string& name, const XAO::Dimension& dim, const int& nbElements) void Group::initGroup(const std::string& name, const XAO::Dimension& dim, const int& nbElements)
{ {
if (dim == XAO::WHOLE)
throw SALOME_Exception("Dimension WHOLE is not valid for group.");
m_name = name; m_name = name;
m_dimension = dim; m_dimension = dim;
m_count = 0; m_count = 0;
@ -49,12 +53,11 @@ Group::~Group()
void Group::checkIndex(const int& element) void Group::checkIndex(const int& element)
{ {
if (element >= m_elements.size() || element < 0) if (element < m_elements.size() && element >= 0)
{ return;
std::ostringstream str;
str << "Index of element is out of range [0, " << m_elements.size()-1 << "]: " << element; throw SALOME_Exception(MsgBuilder() << "Index of element is out of range [0, "
throw SALOME_Exception(str.str().c_str()); << m_elements.size()-1 << "]: " << element);
}
} }
void Group::add(const int& value) void Group::add(const int& value)

View File

@ -60,7 +60,7 @@ namespace XAO
* Gets the name of the group. * Gets the name of the group.
* \return the name of the group. * \return the name of the group.
*/ */
const std::string getName() const const std::string getName()
{ {
return m_name; return m_name;
} }
@ -95,7 +95,7 @@ namespace XAO
* Gets the number of elements in the group. * Gets the number of elements in the group.
* \return the number of elements. * \return the number of elements.
*/ */
const int count() const int count() const
{ {
return m_elements.size(); return m_elements.size();
} }

View File

@ -37,14 +37,12 @@ IntegerField::IntegerField(const std::string& name, const XAO::Dimension& dimens
Step* IntegerField::addNewStep(const int& step) Step* IntegerField::addNewStep(const int& step)
{ {
return addStep(step); return addStep(step, 0);
} }
IntegerStep* IntegerField::addStep(const int& step) IntegerStep* IntegerField::addStep(const int& step)
{ {
IntegerStep* bstep = new IntegerStep(step, m_nbElements, m_nbComponents); return addStep(step, 0);
m_steps.push_back(bstep);
return bstep;
} }
IntegerStep* IntegerField::addStep(const int& step, const int& stamp) IntegerStep* IntegerField::addStep(const int& step, const int& stamp)
@ -56,7 +54,6 @@ IntegerStep* IntegerField::addStep(const int& step, const int& stamp)
IntegerStep* IntegerField::getStep(const int& index) IntegerStep* IntegerField::getStep(const int& index)
{ {
if (index < m_steps.size()) checkStepIndex(index);
return (IntegerStep*)m_steps[index]; return (IntegerStep*)m_steps[index];
throw SALOME_Exception("IndexOutOfRange");
} }

View File

@ -74,7 +74,7 @@ std::vector<int> IntegerStep::getValues()
std::vector<int> IntegerStep::getElement(const int& element) std::vector<int> IntegerStep::getElement(const int& element)
{ {
checkElement(element); checkElementIndex(element);
std::vector<int> result(m_values[element]); std::vector<int> result(m_values[element]);
return result; return result;
@ -82,7 +82,7 @@ std::vector<int> IntegerStep::getElement(const int& element)
std::vector<int> IntegerStep::getComponent(const int& component) std::vector<int> IntegerStep::getComponent(const int& component)
{ {
checkComponent(component); checkComponentIndex(component);
std::vector<int> result; std::vector<int> result;
result.reserve(m_nbElements); result.reserve(m_nbElements);
@ -99,8 +99,8 @@ std::vector<int> IntegerStep::getComponent(const int& component)
const int IntegerStep::getValue(const int& element, const int& component) const int IntegerStep::getValue(const int& element, const int& component)
{ {
checkElement(element); checkElementIndex(element);
checkComponent(component); checkComponentIndex(component);
return m_values[element][component]; return m_values[element][component];
} }
@ -112,8 +112,7 @@ const std::string IntegerStep::getStringValue(const int& element, const int& com
void IntegerStep::setValues(const std::vector<int>& values) void IntegerStep::setValues(const std::vector<int>& values)
{ {
if (values.size() != m_nbComponents * m_nbElements) checkNbValues(values.size());
throw SALOME_Exception("bad size"); // TODO
for (int i = 0; i < m_nbElements; ++i) for (int i = 0; i < m_nbElements; ++i)
{ {
@ -126,9 +125,8 @@ void IntegerStep::setValues(const std::vector<int>& values)
void IntegerStep::setElements(const int& element, const std::vector<int>& elements) void IntegerStep::setElements(const int& element, const std::vector<int>& elements)
{ {
checkElement(element); checkElementIndex(element);
if (elements.size() != m_nbComponents) checkNbComponents(elements.size());
throw SALOME_Exception("bad size"); // TODO
for (int i = 0; i < m_nbComponents; ++i) for (int i = 0; i < m_nbComponents; ++i)
m_values[element][i] = elements[i]; m_values[element][i] = elements[i];
@ -136,9 +134,8 @@ void IntegerStep::setElements(const int& element, const std::vector<int>& elemen
void IntegerStep::setComponents(const int& component, const std::vector<int>& components) void IntegerStep::setComponents(const int& component, const std::vector<int>& components)
{ {
checkElement(component); checkElementIndex(component);
if (components.size() != m_nbElements) checkNbElements(components.size());
throw SALOME_Exception("bad size"); // TODO
for (int i = 0; i < m_nbElements; ++i) for (int i = 0; i < m_nbElements; ++i)
m_values[i][component] = components[i]; m_values[i][component] = components[i];
@ -146,8 +143,8 @@ void IntegerStep::setComponents(const int& component, const std::vector<int>& co
void IntegerStep::setValue(const int& element, const int& component, const int& value) void IntegerStep::setValue(const int& element, const int& component, const int& value)
{ {
checkElement(element); checkElementIndex(element);
checkComponent(component); checkComponentIndex(component);
m_values[element][component] = value; m_values[element][component] = value;
} }

View File

@ -18,17 +18,16 @@
// //
// Author : Frederic Pons (OpenCascade) // Author : Frederic Pons (OpenCascade)
#include <sstream>
#include <Utils_SALOME_Exception.hxx> #include <Utils_SALOME_Exception.hxx>
#include "Xao.hxx" #include "Xao.hxx"
#include "XaoUtils.hxx"
#include "Step.hxx" #include "Step.hxx"
#include "BooleanStep.hxx" #include "BooleanStep.hxx"
#include "IntegerStep.hxx" #include "IntegerStep.hxx"
#include "DoubleStep.hxx" #include "DoubleStep.hxx"
#include "StringStep.hxx" #include "StringStep.hxx"
using namespace XAO; using namespace XAO;
Step* Step::createStep(const XAO::Type& type, const int& step, const int& stamp, const int& nbElements, const int& nbComponents) Step* Step::createStep(const XAO::Type& type, const int& step, const int& stamp, const int& nbElements, const int& nbComponents)
@ -45,22 +44,47 @@ Step* Step::createStep(const XAO::Type& type, const int& step, const int& stamp,
throw SALOME_Exception("Unknown Type"); throw SALOME_Exception("Unknown Type");
} }
void Step::checkElement(const int& element) void Step::checkElementIndex(const int& element)
{ {
if (element >= m_nbElements || element < 0) if (element < m_nbElements && element >= 0)
{ return;
std::ostringstream str;
str << "Element index is out of range [0, " << m_nbElements-1 << "] : " << element; throw SALOME_Exception(MsgBuilder() << "Element index is out of range [0, "
throw SALOME_Exception(str.str().c_str()); << m_nbElements-1 << "] : " << element);
}
} }
void Step::checkComponent(const int& component) void Step::checkComponentIndex(const int& component)
{ {
if (component >= m_nbComponents || component < 0) if (component < m_nbComponents && component >= 0)
{ return;
std::ostringstream str;
str << "Component index is out of range [0, " << m_nbComponents-1 << "] : " << component; throw SALOME_Exception(MsgBuilder() << "Component index is out of range [0, "
throw SALOME_Exception(str.str().c_str()); << m_nbComponents-1 << "] : " << component);
} }
void Step::checkNbElements(const int& nbElements)
{
if (nbElements == m_nbElements)
return;
throw SALOME_Exception(MsgBuilder() << "Invalid number of elements:" << nbElements
<< ", expected " << m_nbElements);
}
void Step::checkNbComponents(const int& nbComponents)
{
if (nbComponents == m_nbComponents)
return;
throw SALOME_Exception(MsgBuilder() << "Invalid number of components:" << nbComponents
<< ", expected " << m_nbComponents);
}
void Step::checkNbValues(const int& nbValues)
{
if (nbValues == m_nbElements * m_nbComponents)
return;
throw SALOME_Exception(MsgBuilder() << "Invalid number of values:" << nbValues
<< ", expected " << m_nbElements * m_nbComponents);
} }

View File

@ -115,8 +115,12 @@ namespace XAO
virtual void setStringValue(const int& element, const int& component, const std::string& value) = 0; virtual void setStringValue(const int& element, const int& component, const std::string& value) = 0;
protected: protected:
void checkElement(const int& element); void checkElementIndex(const int& element);
void checkComponent(const int& component); void checkComponentIndex(const int& component);
void checkNbElements(const int& nbElements);
void checkNbComponents(const int& nbComponents);
void checkNbValues(const int& nbValues);
protected: protected:
/** the index of the step. */ /** the index of the step. */

View File

@ -37,14 +37,12 @@ StringField::StringField(const std::string& name, const XAO::Dimension& dimensio
Step* StringField::addNewStep(const int& step) Step* StringField::addNewStep(const int& step)
{ {
return addStep(step); return addStep(step, 0);
} }
StringStep* StringField::addStep(const int& step) StringStep* StringField::addStep(const int& step)
{ {
StringStep* bstep = new StringStep(step, m_nbElements, m_nbComponents); return addStep(step, 0);
m_steps.push_back(bstep);
return bstep;
} }
StringStep* StringField::addStep(const int& step, const int& stamp) StringStep* StringField::addStep(const int& step, const int& stamp)
@ -56,7 +54,6 @@ StringStep* StringField::addStep(const int& step, const int& stamp)
StringStep* StringField::getStep(const int& index) StringStep* StringField::getStep(const int& index)
{ {
if (index < m_steps.size()) checkStepIndex(index);
return (StringStep*)m_steps[index]; return (StringStep*)m_steps[index];
throw SALOME_Exception("IndexOutOfRange");
} }

View File

@ -73,7 +73,7 @@ std::vector<std::string> StringStep::getValues()
std::vector<std::string> StringStep::getElement(const int& element) std::vector<std::string> StringStep::getElement(const int& element)
{ {
checkElement(element); checkElementIndex(element);
std::vector<std::string> result(m_values[element]); std::vector<std::string> result(m_values[element]);
return result; return result;
@ -81,7 +81,7 @@ std::vector<std::string> StringStep::getElement(const int& element)
std::vector<std::string> StringStep::getComponent(const int& component) std::vector<std::string> StringStep::getComponent(const int& component)
{ {
checkComponent(component); checkComponentIndex(component);
std::vector<std::string> result; std::vector<std::string> result;
result.reserve(m_nbElements); result.reserve(m_nbElements);
@ -98,8 +98,8 @@ std::vector<std::string> StringStep::getComponent(const int& component)
const std::string StringStep::getValue(const int& element, const int& component) const std::string StringStep::getValue(const int& element, const int& component)
{ {
checkElement(element); checkElementIndex(element);
checkComponent(component); checkComponentIndex(component);
return m_values[element][component]; return m_values[element][component];
} }
@ -111,8 +111,7 @@ const std::string StringStep::getStringValue(const int& element, const int& comp
void StringStep::setValues(const std::vector<std::string>& values) void StringStep::setValues(const std::vector<std::string>& values)
{ {
if (values.size() != m_nbComponents * m_nbElements) checkNbValues(values.size());
throw SALOME_Exception("bad size"); // TODO
for (int i = 0; i < m_nbElements; ++i) for (int i = 0; i < m_nbElements; ++i)
{ {
@ -125,9 +124,8 @@ void StringStep::setValues(const std::vector<std::string>& values)
void StringStep::setElements(const int& element, const std::vector<std::string>& elements) void StringStep::setElements(const int& element, const std::vector<std::string>& elements)
{ {
checkElement(element); checkElementIndex(element);
if (elements.size() != m_nbComponents) checkNbComponents(elements.size());
throw SALOME_Exception("bad size"); // TODO
for (int i = 0; i < m_nbComponents; ++i) for (int i = 0; i < m_nbComponents; ++i)
m_values[element][i] = elements[i]; m_values[element][i] = elements[i];
@ -135,9 +133,8 @@ void StringStep::setElements(const int& element, const std::vector<std::string>&
void StringStep::setComponents(const int& component, const std::vector<std::string>& components) void StringStep::setComponents(const int& component, const std::vector<std::string>& components)
{ {
checkElement(component); checkElementIndex(component);
if (components.size() != m_nbElements) checkNbElements(components.size());
throw SALOME_Exception("bad size"); // TODO
for (int i = 0; i < m_nbElements; ++i) for (int i = 0; i < m_nbElements; ++i)
m_values[i][component] = components[i]; m_values[i][component] = components[i];
@ -145,8 +142,8 @@ void StringStep::setComponents(const int& component, const std::vector<std::stri
void StringStep::setValue(const int& element, const int& component, const std::string& value) void StringStep::setValue(const int& element, const int& component, const std::string& value)
{ {
checkElement(element); checkElementIndex(element);
checkComponent(component); checkComponentIndex(component);
m_values[element][component] = value; m_values[element][component] = value;
} }

View File

@ -65,7 +65,7 @@ Xao::~Xao()
} }
} }
const int Xao::countGroups() const int Xao::countGroups() const
{ {
return m_groups.size(); return m_groups.size();
} }
@ -100,7 +100,7 @@ void Xao::removeGroup(Group* group)
m_groups.remove(group); m_groups.remove(group);
} }
const int Xao::countFields() const int Xao::countFields() const
{ {
return m_fields.size(); return m_fields.size();
} }
@ -138,25 +138,11 @@ void Xao::removeField(Field* field)
const bool Xao::exportXAO(const std::string& fileName) const bool Xao::exportXAO(const std::string& fileName)
{ {
// xmlDocPtr doc = exportXMLDoc();
// xmlSaveFormatFileEnc(fileName, doc, "UTF-8", 2);
// xmlFreeDoc(doc);
//
// return true;
return XaoExporter::saveToFile(this, fileName); return XaoExporter::saveToFile(this, fileName);
} }
const std::string Xao::getXML() const std::string Xao::getXML()
{ {
// xmlDocPtr doc = exportXMLDoc();
//
// xmlChar *xmlbuff;
// int buffersize;
// xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
// xmlFreeDoc(doc);
// xmlCleanupGlobals();
//
// return (char*)xmlbuff;
return XaoExporter::saveToXml(this); return XaoExporter::saveToXml(this);
} }
@ -170,8 +156,8 @@ const bool Xao::setXML(const std::string& xml)
return XaoExporter::setXML(xml, this); return XaoExporter::setXML(xml, this);
} }
void Xao::checkGeometry() void Xao::checkGeometry() const
{ {
if (m_geometry == NULL) if (m_geometry == NULL)
throw SALOME_Exception("Geometry is null"); // TODO throw SALOME_Exception("Geometry is null");
} }

View File

@ -89,7 +89,7 @@ namespace XAO
* Gets the author of the file. * Gets the author of the file.
* \return the author of the file. * \return the author of the file.
*/ */
const std::string getAuthor() const std::string getAuthor() const
{ {
return m_author; return m_author;
} }
@ -106,7 +106,7 @@ namespace XAO
* Gets the version of the file. * Gets the version of the file.
* \return the version of the file. * \return the version of the file.
*/ */
const std::string getVersion() const std::string getVersion() const
{ {
return m_version; return m_version;
} }
@ -127,7 +127,7 @@ namespace XAO
* Gets the geometry. * Gets the geometry.
* \return the geometry. * \return the geometry.
*/ */
Geometry* getGeometry() Geometry* getGeometry() const
{ {
return m_geometry; return m_geometry;
} }
@ -148,7 +148,7 @@ namespace XAO
* Gets the number of groups. * Gets the number of groups.
* \return the number of groups. * \return the number of groups.
*/ */
const int countGroups(); const int countGroups() const;
/** /**
* Gets a group. * Gets a group.
* \param index the index of the wanted group. * \param index the index of the wanted group.
@ -182,7 +182,7 @@ namespace XAO
* Gets the number of fields. * Gets the number of fields.
* \return the number of fields. * \return the number of fields.
*/ */
const int countFields(); const int countFields() const;
/** /**
* Gets a field. * Gets a field.
* \param index the index of the wanted field. * \param index the index of the wanted field.
@ -241,7 +241,7 @@ namespace XAO
const bool setXML(const std::string& xml); const bool setXML(const std::string& xml);
private: private:
void checkGeometry(); void checkGeometry() const;
private: private:
/** The author of the file. */ /** The author of the file. */

View File

@ -1,5 +1,4 @@
#include <sstream>
#include <libxml/parser.h> #include <libxml/parser.h>
#include <Utils_SALOME_Exception.hxx> #include <Utils_SALOME_Exception.hxx>
@ -81,10 +80,8 @@ std::string XaoExporter::readStringProp(xmlNodePtr node, const xmlChar* attribut
if (exception.size() > 0) if (exception.size() > 0)
throw SALOME_Exception(exception.c_str()); throw SALOME_Exception(exception.c_str());
std::ostringstream str; throw SALOME_Exception(MsgBuilder() << "Line " << node->line << ": "
str << "Line " << node->line << ": "; << "Property " << (char*)attribute << " is required.");
str << "Property " << (char*)attribute << " is required.";
throw SALOME_Exception(str.str().c_str());
} }
return defaultValue; return defaultValue;
@ -107,9 +104,8 @@ int XaoExporter::readIntegerProp(xmlNodePtr node, const xmlChar* attribute,
if (exception.size() > 0) if (exception.size() > 0)
throw SALOME_Exception(exception.c_str()); throw SALOME_Exception(exception.c_str());
std::ostringstream str; throw SALOME_Exception(MsgBuilder() << "Line " << node->line << ": "
str << "Property " << (char*)attribute << " is required."; << "Property " << (char*)attribute << " is required.");
throw SALOME_Exception(str.str().c_str());
} }
return defaultValue; return defaultValue;
@ -205,7 +201,6 @@ void XaoExporter::exportGroups(Xao* xaoObject, xmlNodePtr xao)
xmlNodePtr groups = xmlNewChild(xao, 0, C_TAG_GROUPS, 0); xmlNodePtr groups = xmlNewChild(xao, 0, C_TAG_GROUPS, 0);
xmlNewProp(groups, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoObject->countGroups()).c_str()); xmlNewProp(groups, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoObject->countGroups()).c_str());
//for (std::list<Group*>::iterator it = m_groups.begin(); it != m_groups.end(); ++it)
for (int i = 0; i < xaoObject->countGroups(); i++) for (int i = 0; i < xaoObject->countGroups(); i++)
{ {
//Group* grp = (*it); //Group* grp = (*it);
@ -215,7 +210,6 @@ void XaoExporter::exportGroups(Xao* xaoObject, xmlNodePtr xao)
xmlNewProp(group, C_ATTR_GROUP_DIM, BAD_CAST XaoUtils::dimensionToString(grp->getDimension()).c_str()); xmlNewProp(group, C_ATTR_GROUP_DIM, BAD_CAST XaoUtils::dimensionToString(grp->getDimension()).c_str());
xmlNewProp(group, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(grp->count()).c_str()); xmlNewProp(group, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(grp->count()).c_str());
//for (int j = 0; j < grp->count(); j++)
for (std::set<int>::iterator it = grp->begin(); it != grp->end(); ++it) for (std::set<int>::iterator it = grp->begin(); it != grp->end(); ++it)
{ {
int grpElt = (*it); int grpElt = (*it);
@ -379,9 +373,8 @@ void XaoExporter::parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode, Geometry*
} }
else else
{ {
std::ostringstream str; throw SALOME_Exception(MsgBuilder() << "Shape format not supported: "
str << "Shape format not supported: " << XaoUtils::shapeFormatToString(geometry->getFormat()); << XaoUtils::shapeFormatToString(geometry->getFormat()));
throw SALOME_Exception(str.str().c_str());
} }
} }
@ -535,7 +528,10 @@ void XaoExporter::parseFieldNode(xmlNodePtr fieldNode, Xao* xaoObject)
// ensure that the components node is defined // ensure that the components node is defined
if (componentsNode == NULL) if (componentsNode == NULL)
throw SALOME_Exception("No components defined for field"); // TODO {
throw SALOME_Exception(MsgBuilder() << "Line " << fieldNode->line << ": "
<< "No components defined for field.");
}
// create the field // create the field
int nbComponents = readIntegerProp(componentsNode, C_ATTR_COUNT, true, -1); int nbComponents = readIntegerProp(componentsNode, C_ATTR_COUNT, true, -1);
@ -602,9 +598,7 @@ void XaoExporter::parseStepElementNode(xmlNodePtr eltNode, Step* step)
if (data == NULL) if (data == NULL)
{ {
std::ostringstream str; throw SALOME_Exception(MsgBuilder() << "Line " << valNode->line << ": no content for value.");
str << "Line " << valNode->line << ": no content for value.";
throw SALOME_Exception(str.str().c_str());
} }
std::string value = (char*)data; std::string value = (char*)data;

View File

@ -24,10 +24,8 @@
#include <Utils_SALOME_Exception.hxx> #include <Utils_SALOME_Exception.hxx>
#include "Xao.hxx" #include "Xao.hxx"
#include "Field.hxx"
#include "XaoUtils.hxx" #include "XaoUtils.hxx"
using namespace XAO; using namespace XAO;
@ -75,7 +73,8 @@ const std::string XaoUtils::dimensionToString(const XAO::Dimension& dimension)
return "solid"; return "solid";
if (dimension == XAO::WHOLE) if (dimension == XAO::WHOLE)
return "whole"; return "whole";
throw SALOME_Exception("Bad dimension");
throw SALOME_Exception(MsgBuilder() << "Bad dimension: " << dimension);
} }
const XAO::Dimension XaoUtils::stringToDimension(const std::string& dimension) const XAO::Dimension XaoUtils::stringToDimension(const std::string& dimension)
@ -90,7 +89,8 @@ const XAO::Dimension XaoUtils::stringToDimension(const std::string& dimension)
return XAO::SOLID; return XAO::SOLID;
if (dimension == "whole") if (dimension == "whole")
return XAO::WHOLE; return XAO::WHOLE;
throw SALOME_Exception("Bad dimension");
throw SALOME_Exception(MsgBuilder() << "Bad dimension: " << dimension);
} }
const std::string XaoUtils::fieldTypeToString(const XAO::Type& type) const std::string XaoUtils::fieldTypeToString(const XAO::Type& type)
@ -103,7 +103,8 @@ const std::string XaoUtils::fieldTypeToString(const XAO::Type& type)
return "double"; return "double";
if (type == XAO::STRING) if (type == XAO::STRING)
return "string"; return "string";
throw SALOME_Exception("Bad type");
throw SALOME_Exception(MsgBuilder() << "Bad type: " << type);
} }
const XAO::Type XaoUtils::stringToFieldType(const std::string& type) const XAO::Type XaoUtils::stringToFieldType(const std::string& type)
@ -116,7 +117,8 @@ const XAO::Type XaoUtils::stringToFieldType(const std::string& type)
return XAO::DOUBLE; return XAO::DOUBLE;
if (type == "string") if (type == "string")
return XAO::STRING; return XAO::STRING;
throw SALOME_Exception("Bad type");
throw SALOME_Exception(MsgBuilder() << "Bad type: " << type);
} }
const std::string XaoUtils::shapeFormatToString(const XAO::Format& format) const std::string XaoUtils::shapeFormatToString(const XAO::Format& format)
@ -125,7 +127,8 @@ const std::string XaoUtils::shapeFormatToString(const XAO::Format& format)
return "BREP"; return "BREP";
if (format == XAO::STEP) if (format == XAO::STEP)
return "STEP"; return "STEP";
throw SALOME_Exception("Bad format");
throw SALOME_Exception(MsgBuilder() << "Bad format: " << format);
} }
const XAO::Format XaoUtils::stringToShapeFormat(const std::string& format) const XAO::Format XaoUtils::stringToShapeFormat(const std::string& format)
@ -134,5 +137,6 @@ const XAO::Format XaoUtils::stringToShapeFormat(const std::string& format)
return XAO::BREP; return XAO::BREP;
if (format == "STEP") if (format == "STEP")
return XAO::STEP; return XAO::STEP;
throw SALOME_Exception("Bad format");
throw SALOME_Exception(MsgBuilder() << "Bad format: " << format);
} }

View File

@ -21,6 +21,9 @@
#ifndef __XAO_UTILS_HXX__ #ifndef __XAO_UTILS_HXX__
#define __XAO_UTILS_HXX__ #define __XAO_UTILS_HXX__
#include <sstream>
#include <string>
#include "Xao.hxx" #include "Xao.hxx"
#include "Field.hxx" #include "Field.hxx"
@ -91,7 +94,26 @@ namespace XAO
* \throw SALOME_Exception * \throw SALOME_Exception
*/ */
static const XAO::Format stringToShapeFormat(const std::string& format); static const XAO::Format stringToShapeFormat(const std::string& format);
}; };
class MsgBuilder
{
public:
MsgBuilder() {};
template <typename T>
MsgBuilder& operator <<(const T& t)
{
m_stream << t;
return *this;
}
operator const char*() const { return m_stream.str().c_str(); }
private :
std::stringstream m_stream;
};
} }

View File

@ -48,7 +48,21 @@ void BrepGeometryTest::testGetIDs()
delete geom; delete geom;
} }
void BrepGeometryTest::testGeometricalElements() void BrepGeometryTest::testGetEdgeVertices()
{
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_2.brep");
int v1, v2;
geom->getEdgeVertices(63, v1, v2);
std::cout << "# " << v1 << ", " << v2 << std::endl;
CPPUNIT_ASSERT_EQUAL(47, v1);
CPPUNIT_ASSERT_EQUAL(59, v2);
delete geom;
}
void BrepGeometryTest::testGetFaceWires()
{ {
BrepGeometry* geom = new BrepGeometry("box"); BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_2.brep"); readBrep(geom, "Box_2.brep");
@ -61,7 +75,21 @@ void BrepGeometryTest::testGeometricalElements()
CPPUNIT_ASSERT_EQUAL(2, wires[0]); CPPUNIT_ASSERT_EQUAL(2, wires[0]);
CPPUNIT_ASSERT_EQUAL(11, wires[1]); CPPUNIT_ASSERT_EQUAL(11, wires[1]);
CPPUNIT_ASSERT_EQUAL(1, geom->countSolidShells(1)); delete geom;
}
void BrepGeometryTest::testSolidShells()
{
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Cut_2.brep");
CPPUNIT_ASSERT_EQUAL(5, geom->countSolidShells(1));
std::vector<int> shells = geom->getSolidShells(1);
CPPUNIT_ASSERT_EQUAL(5, (int)shells.size());
int ids[5] = { 2, 35, 68, 76, 84 };
for (int i = 0; i < 5; ++i)
CPPUNIT_ASSERT_EQUAL(ids[i], shells[i]);
delete geom; delete geom;
} }

View File

@ -11,7 +11,9 @@ namespace XAO
{ {
CPPUNIT_TEST_SUITE(BrepGeometryTest); CPPUNIT_TEST_SUITE(BrepGeometryTest);
CPPUNIT_TEST(testGetIDs); CPPUNIT_TEST(testGetIDs);
CPPUNIT_TEST(testGeometricalElements); CPPUNIT_TEST(testGetEdgeVertices);
CPPUNIT_TEST(testGetFaceWires);
CPPUNIT_TEST(testSolidShells);
CPPUNIT_TEST(testGetVertex); CPPUNIT_TEST(testGetVertex);
CPPUNIT_TEST(testGetEdgeLength); CPPUNIT_TEST(testGetEdgeLength);
CPPUNIT_TEST(testGetFaceArea); CPPUNIT_TEST(testGetFaceArea);
@ -24,7 +26,9 @@ namespace XAO
void cleanUp(); void cleanUp();
void testGetIDs(); void testGetIDs();
void testGeometricalElements(); void testGetEdgeVertices();
void testGetFaceWires();
void testSolidShells();
void testGetVertex(); void testGetVertex();
void testGetEdgeLength(); void testGetEdgeLength();

View File

@ -0,0 +1,36 @@
#include <vector>
#include <Utils_SALOME_Exception.hxx>
#include "TestUtils.hxx"
#include "GeometryTest.hxx"
#include "../Geometry.hxx"
using namespace XAO;
void GeometryTest::setUp()
{
}
void GeometryTest::tearDown()
{
}
void GeometryTest::cleanUp()
{
}
void GeometryTest::testGeometry()
{
Geometry* geom = Geometry::createGeometry(XAO::BREP, "cube");
CPPUNIT_ASSERT_EQUAL(std::string("cube"), geom->getName());
CPPUNIT_ASSERT_EQUAL(XAO::BREP, geom->getFormat());
geom->setName("sphere");
CPPUNIT_ASSERT_EQUAL(std::string("sphere"), geom->getName());
}
void GeometryTest::testGeometryErrors()
{
CPPUNIT_ASSERT_THROW(Geometry::createGeometry(XAO::STEP), SALOME_Exception);
}

View File

@ -0,0 +1,27 @@
#ifndef __XAO_GEOMETRY_TEST_HXX__
#define __XAO_GEOMETRY_TEST_HXX__
#include <cppunit/extensions/HelperMacros.h>
#include "../Xao.hxx"
namespace XAO
{
class GeometryTest: public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(GeometryTest);
CPPUNIT_TEST(testGeometry);
CPPUNIT_TEST(testGeometryErrors);
CPPUNIT_TEST_SUITE_END();
public:
void setUp();
void tearDown();
void cleanUp();
void testGeometry();
void testGeometryErrors();
};
}
#endif // __XAO_GEOMETRY_TEST_HXX__

View File

@ -52,9 +52,7 @@ void GroupTest::testGroup()
delete group; delete group;
} }
void GroupTest::testGroupErrors()
{
CPPUNIT_ASSERT_THROW(new Group(XAO::WHOLE, 20), SALOME_Exception);
}

View File

@ -11,6 +11,7 @@ namespace XAO
{ {
CPPUNIT_TEST_SUITE(GroupTest); CPPUNIT_TEST_SUITE(GroupTest);
CPPUNIT_TEST(testGroup); CPPUNIT_TEST(testGroup);
CPPUNIT_TEST(testGroupErrors);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
public: public:
@ -19,6 +20,7 @@ namespace XAO
void cleanUp(); void cleanUp();
void testGroup(); void testGroup();
void testGroupErrors();
}; };
} }

View File

@ -179,15 +179,6 @@ void ImportExportTest::checkImport(Xao& xao)
void ImportExportTest::testImportXaoFromText() void ImportExportTest::testImportXaoFromText()
{ {
// std::ifstream rstr;
// int length;
// rstr.open(TestUtils::getTestFilePath("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();
char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath("test.xao")); char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath("test.xao"));
Xao xao; Xao xao;

View File

@ -62,7 +62,7 @@ Arguments parseArguments(int argc, char* argv[])
{ {
res.Err = true; res.Err = true;
} }
if (strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--test") == 0) else if (strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--test") == 0)
{ {
if (i+1 < argc) if (i+1 < argc)
res.Test = argv[++i]; res.Test = argv[++i];

View File

@ -41,6 +41,7 @@ TestXAO_LDFLAGS = \
dist_TestXAO_SOURCES = \ dist_TestXAO_SOURCES = \
GroupTest.cxx \ GroupTest.cxx \
FieldTest.cxx \ FieldTest.cxx \
GeometryTest.cxx \
ImportExportTest.cxx \ ImportExportTest.cxx \
BrepGeometryTest.cxx \ BrepGeometryTest.cxx \
XAOTests.cxx XAOTests.cxx

View File

@ -1,10 +1,12 @@
#include "GroupTest.hxx" #include "GroupTest.hxx"
#include "FieldTest.hxx" #include "FieldTest.hxx"
#include "GeometryTest.hxx"
#include "ImportExportTest.hxx" #include "ImportExportTest.hxx"
#include "BrepGeometryTest.hxx" #include "BrepGeometryTest.hxx"
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::GroupTest); CPPUNIT_TEST_SUITE_REGISTRATION(XAO::GroupTest);
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::FieldTest); CPPUNIT_TEST_SUITE_REGISTRATION(XAO::FieldTest);
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::GeometryTest);
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::ImportExportTest); CPPUNIT_TEST_SUITE_REGISTRATION(XAO::ImportExportTest);
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::BrepGeometryTest); CPPUNIT_TEST_SUITE_REGISTRATION(XAO::BrepGeometryTest);

File diff suppressed because one or more lines are too long