mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2025-01-28 07:30:33 +05:00
improve exception messages
add more tests
This commit is contained in:
parent
54030bc86c
commit
29d01572ac
@ -25,26 +25,26 @@
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
Step* BooleanField::addNewStep(const int& step)
|
||||
{
|
||||
return addStep(step);
|
||||
return addStep(step, 0);
|
||||
}
|
||||
|
||||
BooleanStep* BooleanField::addStep(const int& step)
|
||||
{
|
||||
BooleanStep* bstep = new BooleanStep(step, m_nbElements, m_nbComponents);
|
||||
m_steps.push_back(bstep);
|
||||
return bstep;
|
||||
return addStep(step, 0);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (index < m_steps.size())
|
||||
return (BooleanStep*)m_steps[index];
|
||||
throw SALOME_Exception("IndexOutOfRange");
|
||||
checkStepIndex(index);
|
||||
return (BooleanStep*)m_steps[index];
|
||||
}
|
||||
|
@ -18,8 +18,9 @@
|
||||
//
|
||||
// Author : Frederic Pons (OpenCascade)
|
||||
|
||||
#include "BooleanStep.hxx"
|
||||
#include <Utils_SALOME_Exception.hxx>
|
||||
#include "BooleanStep.hxx"
|
||||
#include "XaoUtils.hxx"
|
||||
|
||||
using namespace XAO;
|
||||
|
||||
@ -73,7 +74,7 @@ std::vector<bool> BooleanStep::getValues()
|
||||
|
||||
std::vector<bool> BooleanStep::getElement(const int& element)
|
||||
{
|
||||
checkElement(element);
|
||||
checkElementIndex(element);
|
||||
|
||||
std::vector<bool> result(m_values[element]);
|
||||
return result;
|
||||
@ -81,7 +82,7 @@ std::vector<bool> BooleanStep::getElement(const int& element)
|
||||
|
||||
std::vector<bool> BooleanStep::getComponent(const int& component)
|
||||
{
|
||||
checkComponent(component);
|
||||
checkComponentIndex(component);
|
||||
|
||||
std::vector<bool> result;
|
||||
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)
|
||||
{
|
||||
checkElement(element);
|
||||
checkComponent(component);
|
||||
checkElementIndex(element);
|
||||
checkComponentIndex(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)
|
||||
{
|
||||
if (values.size() != m_nbComponents * m_nbElements)
|
||||
throw SALOME_Exception("bad size"); // TODO
|
||||
checkNbValues((int)values.size());
|
||||
|
||||
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)
|
||||
{
|
||||
checkElement(element);
|
||||
if (elements.size() != m_nbComponents)
|
||||
throw SALOME_Exception("bad size"); // TODO
|
||||
checkElementIndex(element);
|
||||
checkNbElements((int)elements.size());
|
||||
|
||||
for (int i = 0; i < m_nbComponents; ++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)
|
||||
{
|
||||
checkComponent(component);
|
||||
if (components.size() != m_nbElements)
|
||||
throw SALOME_Exception("bad size"); // TODO
|
||||
checkComponentIndex(component);
|
||||
checkNbElements((int)components.size());
|
||||
|
||||
for (int i = 0; i < m_nbElements; ++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)
|
||||
{
|
||||
checkElement(element);
|
||||
checkComponent(component);
|
||||
checkElementIndex(element);
|
||||
checkComponentIndex(component);
|
||||
|
||||
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)
|
||||
{
|
||||
if (value != "true" && value != "false")
|
||||
throw SALOME_Exception("Bad boolean value");
|
||||
throw SALOME_Exception(MsgBuilder() << "Bad boolean value: " << value);
|
||||
|
||||
setValue(element, component, value == "true");
|
||||
}
|
||||
|
@ -18,6 +18,8 @@
|
||||
//
|
||||
// Author : Frederic Pons (OpenCascade)
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <TopTools_MapOfShape.hxx>
|
||||
#include <TopTools_ListOfShape.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)
|
||||
@ -121,10 +123,14 @@ std::vector<int> BrepGeometry::getGeometricalElements(TopoDS_Shape shape, TopAbs
|
||||
return indexList;
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
@ -153,23 +159,21 @@ std::vector<int> BrepGeometry::getSolidShells(const int& solid)
|
||||
|
||||
void BrepGeometry::getVertexXYZ(const int& vertex, double& xCoord, double& yCoord, double& zCoord)
|
||||
{
|
||||
TopoDS_Shape shape = getGeometricalElement(TopAbs_VERTEX, vertex);
|
||||
|
||||
xCoord = 0.;
|
||||
yCoord = 0.;
|
||||
zCoord = 0.;
|
||||
if ( shape.ShapeType() != TopAbs_VERTEX )
|
||||
{
|
||||
throw SALOME_Exception("not a point"); // TODO
|
||||
}
|
||||
|
||||
TopoDS_Vertex aPoint = TopoDS::Vertex( shape );
|
||||
if ( !aPoint.IsNull() )
|
||||
TopoDS_Shape shape = getGeometricalElement(TopAbs_VERTEX, vertex);
|
||||
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 );
|
||||
xCoord = aPnt.X();
|
||||
yCoord = aPnt.Y();
|
||||
zCoord = aPnt.Z();
|
||||
gp_Pnt aPnt = BRep_Tool::Pnt(point);
|
||||
xCoord = aPnt.X();
|
||||
yCoord = aPnt.Y();
|
||||
zCoord = aPnt.Z();
|
||||
}
|
||||
}
|
||||
|
||||
@ -296,4 +300,3 @@ void BrepGeometry::changeSolidName(const int& id, const std::string& name)
|
||||
{
|
||||
setSolidName(findSolid(id), name);
|
||||
}
|
||||
|
||||
|
@ -37,14 +37,12 @@ DoubleField::DoubleField(const std::string& name, const XAO::Dimension& dimensio
|
||||
|
||||
Step* DoubleField::addNewStep(const int& step)
|
||||
{
|
||||
return addStep(step);
|
||||
return addStep(step, 0);
|
||||
}
|
||||
|
||||
DoubleStep* DoubleField::addStep(const int& step)
|
||||
{
|
||||
DoubleStep* bstep = new DoubleStep(step, m_nbElements, m_nbComponents);
|
||||
m_steps.push_back(bstep);
|
||||
return bstep;
|
||||
return addStep(step, 0);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (index < m_steps.size())
|
||||
return (DoubleStep*)m_steps[index];
|
||||
throw SALOME_Exception("IndexOutOfRange");
|
||||
checkStepIndex(index);
|
||||
return (DoubleStep*)m_steps[index];
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ std::vector<double> DoubleStep::getValues()
|
||||
|
||||
std::vector<double> DoubleStep::getElement(const int& element)
|
||||
{
|
||||
checkElement(element);
|
||||
checkElementIndex(element);
|
||||
|
||||
std::vector<double> result(m_values[element]);
|
||||
return result;
|
||||
@ -82,7 +82,7 @@ std::vector<double> DoubleStep::getElement(const int& element)
|
||||
|
||||
std::vector<double> DoubleStep::getComponent(const int& component)
|
||||
{
|
||||
checkComponent(component);
|
||||
checkComponentIndex(component);
|
||||
|
||||
std::vector<double> result;
|
||||
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)
|
||||
{
|
||||
checkElement(element);
|
||||
checkComponent(component);
|
||||
checkElementIndex(element);
|
||||
checkComponentIndex(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)
|
||||
{
|
||||
if (values.size() != m_nbComponents * m_nbElements)
|
||||
throw SALOME_Exception("bad size"); // TODO
|
||||
checkNbValues(values.size());
|
||||
|
||||
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)
|
||||
{
|
||||
checkElement(element);
|
||||
if (elements.size() != m_nbComponents)
|
||||
throw SALOME_Exception("bad size"); // TODO
|
||||
checkElementIndex(element);
|
||||
checkNbComponents(elements.size());
|
||||
|
||||
for (int i = 0; i < m_nbComponents; ++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)
|
||||
{
|
||||
checkElement(component);
|
||||
if (components.size() != m_nbElements)
|
||||
throw SALOME_Exception("bad size"); // TODO
|
||||
checkElementIndex(component);
|
||||
checkNbElements(components.size());
|
||||
|
||||
for (int i = 0; i < m_nbElements; ++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)
|
||||
{
|
||||
checkElement(element);
|
||||
checkComponent(component);
|
||||
checkElementIndex(element);
|
||||
checkComponentIndex(component);
|
||||
|
||||
m_values[element][component] = value;
|
||||
}
|
||||
|
@ -19,16 +19,16 @@
|
||||
// Author : Frederic Pons (OpenCascade)
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <Utils_SALOME_Exception.hxx>
|
||||
|
||||
#include "Xao.hxx"
|
||||
#include "Field.hxx"
|
||||
#include "BooleanField.hxx"
|
||||
#include "IntegerField.hxx"
|
||||
#include "DoubleField.hxx"
|
||||
#include "StringField.hxx"
|
||||
|
||||
#include <Utils_SALOME_Exception.hxx>
|
||||
#include "XaoUtils.hxx"
|
||||
|
||||
using namespace XAO;
|
||||
|
||||
@ -67,26 +67,19 @@ Field* Field::createField(const XAO::Type& type, const std::string& name, const
|
||||
if (type == XAO::STRING)
|
||||
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)
|
||||
{
|
||||
if (index < m_components.size())
|
||||
return m_components[index];
|
||||
|
||||
throw SALOME_Exception("IndexOutOfRange component");
|
||||
checkComponent(index);
|
||||
return m_components[index];
|
||||
}
|
||||
|
||||
void Field::setComponentName(const int& index, const std::string& name)
|
||||
{
|
||||
if (index < m_components.size())
|
||||
{
|
||||
m_components[index] = name;
|
||||
return;
|
||||
}
|
||||
|
||||
throw SALOME_Exception("IndexOutOfRange component");
|
||||
checkComponent(index);
|
||||
m_components[index] = name;
|
||||
}
|
||||
|
||||
bool Field::removeStep(Step* step)
|
||||
@ -105,12 +98,20 @@ bool Field::removeStep(Step* step)
|
||||
return false;
|
||||
}
|
||||
|
||||
void Field::checkStep(const int& step)
|
||||
void Field::checkComponent(const int& component)
|
||||
{
|
||||
if (step >= m_steps.size() || step < 0)
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << "Step index is out of range [0, " << m_steps.size() << "] : " << step;
|
||||
throw SALOME_Exception(str.str().c_str());
|
||||
}
|
||||
if (component < m_nbComponents && component >= 0)
|
||||
return;
|
||||
|
||||
throw SALOME_Exception(MsgBuilder() << "Step index is out of range [0, "
|
||||
<< 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);
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ namespace XAO
|
||||
* Gets the name of the Field.
|
||||
* @return the name of the Field.
|
||||
*/
|
||||
const std::string getName()
|
||||
const std::string getName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
@ -108,7 +108,7 @@ namespace XAO
|
||||
* Gets the Dimension of the Field.
|
||||
* @return the Dimension of the Field.
|
||||
*/
|
||||
const XAO::Dimension getDimension()
|
||||
const XAO::Dimension getDimension() const
|
||||
{
|
||||
return m_dimension;
|
||||
}
|
||||
@ -117,7 +117,7 @@ namespace XAO
|
||||
* Gets 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;
|
||||
}
|
||||
@ -126,7 +126,7 @@ namespace XAO
|
||||
* Gets the number of components.
|
||||
* @return the number of components.
|
||||
*/
|
||||
const int countComponents()
|
||||
const int countComponents() const
|
||||
{
|
||||
return m_nbComponents;
|
||||
}
|
||||
@ -135,7 +135,7 @@ namespace XAO
|
||||
* Gets 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;
|
||||
}
|
||||
@ -144,7 +144,7 @@ namespace XAO
|
||||
* Gets the number of the 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.
|
||||
@ -186,10 +186,10 @@ namespace XAO
|
||||
*/
|
||||
stepIterator end() { return m_steps.end(); }
|
||||
|
||||
private:
|
||||
protected:
|
||||
/** Ensures that component is valid (< m_nbComponents). */
|
||||
void checkComponent(const int& component);
|
||||
void checkStep(const int& step);
|
||||
void checkStepIndex(const int& step);
|
||||
|
||||
protected:
|
||||
/** The name of the Field. */
|
||||
|
@ -41,7 +41,7 @@ GeometricElement::~GeometricElement()
|
||||
{
|
||||
}
|
||||
|
||||
bool GeometricElement::hasName()
|
||||
const bool GeometricElement::hasName()
|
||||
{
|
||||
return !m_name.empty();
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ namespace XAO
|
||||
* Checks if the element has a name.
|
||||
* @return true if the element has a name, false otherwise.
|
||||
*/
|
||||
bool hasName();
|
||||
const bool hasName();
|
||||
|
||||
/**
|
||||
* Gets the reference of the element.
|
||||
@ -122,7 +122,7 @@ namespace XAO
|
||||
* Gets 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.
|
||||
|
@ -56,14 +56,15 @@ Geometry::Geometry(const std::string& name)
|
||||
|
||||
Geometry* Geometry::createGeometry(const XAO::Format& format)
|
||||
{
|
||||
return createGeometry(format,"");
|
||||
return createGeometry(format, "");
|
||||
}
|
||||
|
||||
Geometry* Geometry::createGeometry(const XAO::Format& format, const std::string& name)
|
||||
{
|
||||
if (format == XAO::BREP)
|
||||
return new BrepGeometry(name);
|
||||
throw SALOME_Exception("Geometry format not supported.");
|
||||
|
||||
throw SALOME_Exception(MsgBuilder() << "Geometry format not supported: " << format);
|
||||
}
|
||||
|
||||
Geometry::~Geometry()
|
||||
@ -175,7 +176,7 @@ const int Geometry::countElements(const XAO::Dimension& dim)
|
||||
if (dim == XAO::SOLID)
|
||||
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)
|
||||
@ -189,7 +190,7 @@ const std::string Geometry::getElementReference(const XAO::Dimension& dim, const
|
||||
if (dim == XAO::SOLID)
|
||||
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)
|
||||
@ -203,7 +204,7 @@ const int Geometry::getElementIndexByReference(const XAO::Dimension& dim, const
|
||||
if (dim == XAO::SOLID)
|
||||
return getSolidIndexByReference(reference);
|
||||
|
||||
throw SALOME_Exception("Unknown dimension"); // TODO
|
||||
throw SALOME_Exception(MsgBuilder() << "Unknown 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)
|
||||
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)
|
||||
@ -231,5 +232,5 @@ GeometricElementList::iterator Geometry::end(const XAO::Dimension& dim)
|
||||
if (dim == XAO::SOLID)
|
||||
return m_solids.end();
|
||||
|
||||
throw SALOME_Exception("Unknown dimension"); // TODO
|
||||
throw SALOME_Exception(MsgBuilder() << "Unknown dimension:" << dim);
|
||||
}
|
||||
|
@ -18,10 +18,11 @@
|
||||
//
|
||||
// Author : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade)
|
||||
|
||||
#include <sstream>
|
||||
#include "Group.hxx"
|
||||
#include <Utils_SALOME_Exception.hxx>
|
||||
|
||||
#include "XaoUtils.hxx"
|
||||
#include "Group.hxx"
|
||||
|
||||
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)
|
||||
{
|
||||
if (dim == XAO::WHOLE)
|
||||
throw SALOME_Exception("Dimension WHOLE is not valid for group.");
|
||||
|
||||
m_name = name;
|
||||
m_dimension = dim;
|
||||
m_count = 0;
|
||||
@ -49,12 +53,11 @@ Group::~Group()
|
||||
|
||||
void Group::checkIndex(const int& element)
|
||||
{
|
||||
if (element >= m_elements.size() || element < 0)
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << "Index of element is out of range [0, " << m_elements.size()-1 << "]: " << element;
|
||||
throw SALOME_Exception(str.str().c_str());
|
||||
}
|
||||
if (element < m_elements.size() && element >= 0)
|
||||
return;
|
||||
|
||||
throw SALOME_Exception(MsgBuilder() << "Index of element is out of range [0, "
|
||||
<< m_elements.size()-1 << "]: " << element);
|
||||
}
|
||||
|
||||
void Group::add(const int& value)
|
||||
|
@ -60,7 +60,7 @@ namespace XAO
|
||||
* Gets the name of the group.
|
||||
* \return the name of the group.
|
||||
*/
|
||||
const std::string getName() const
|
||||
const std::string getName()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
@ -95,7 +95,7 @@ namespace XAO
|
||||
* Gets the number of elements in the group.
|
||||
* \return the number of elements.
|
||||
*/
|
||||
const int count()
|
||||
const int count() const
|
||||
{
|
||||
return m_elements.size();
|
||||
}
|
||||
|
@ -37,14 +37,12 @@ IntegerField::IntegerField(const std::string& name, const XAO::Dimension& dimens
|
||||
|
||||
Step* IntegerField::addNewStep(const int& step)
|
||||
{
|
||||
return addStep(step);
|
||||
return addStep(step, 0);
|
||||
}
|
||||
|
||||
IntegerStep* IntegerField::addStep(const int& step)
|
||||
{
|
||||
IntegerStep* bstep = new IntegerStep(step, m_nbElements, m_nbComponents);
|
||||
m_steps.push_back(bstep);
|
||||
return bstep;
|
||||
return addStep(step, 0);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (index < m_steps.size())
|
||||
return (IntegerStep*)m_steps[index];
|
||||
throw SALOME_Exception("IndexOutOfRange");
|
||||
checkStepIndex(index);
|
||||
return (IntegerStep*)m_steps[index];
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ std::vector<int> IntegerStep::getValues()
|
||||
|
||||
std::vector<int> IntegerStep::getElement(const int& element)
|
||||
{
|
||||
checkElement(element);
|
||||
checkElementIndex(element);
|
||||
|
||||
std::vector<int> result(m_values[element]);
|
||||
return result;
|
||||
@ -82,7 +82,7 @@ std::vector<int> IntegerStep::getElement(const int& element)
|
||||
|
||||
std::vector<int> IntegerStep::getComponent(const int& component)
|
||||
{
|
||||
checkComponent(component);
|
||||
checkComponentIndex(component);
|
||||
|
||||
std::vector<int> result;
|
||||
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)
|
||||
{
|
||||
checkElement(element);
|
||||
checkComponent(component);
|
||||
checkElementIndex(element);
|
||||
checkComponentIndex(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)
|
||||
{
|
||||
if (values.size() != m_nbComponents * m_nbElements)
|
||||
throw SALOME_Exception("bad size"); // TODO
|
||||
checkNbValues(values.size());
|
||||
|
||||
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)
|
||||
{
|
||||
checkElement(element);
|
||||
if (elements.size() != m_nbComponents)
|
||||
throw SALOME_Exception("bad size"); // TODO
|
||||
checkElementIndex(element);
|
||||
checkNbComponents(elements.size());
|
||||
|
||||
for (int i = 0; i < m_nbComponents; ++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)
|
||||
{
|
||||
checkElement(component);
|
||||
if (components.size() != m_nbElements)
|
||||
throw SALOME_Exception("bad size"); // TODO
|
||||
checkElementIndex(component);
|
||||
checkNbElements(components.size());
|
||||
|
||||
for (int i = 0; i < m_nbElements; ++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)
|
||||
{
|
||||
checkElement(element);
|
||||
checkComponent(component);
|
||||
checkElementIndex(element);
|
||||
checkComponentIndex(component);
|
||||
|
||||
m_values[element][component] = value;
|
||||
}
|
||||
|
@ -18,17 +18,16 @@
|
||||
//
|
||||
// Author : Frederic Pons (OpenCascade)
|
||||
|
||||
#include <sstream>
|
||||
#include <Utils_SALOME_Exception.hxx>
|
||||
|
||||
#include "Xao.hxx"
|
||||
#include "XaoUtils.hxx"
|
||||
#include "Step.hxx"
|
||||
#include "BooleanStep.hxx"
|
||||
#include "IntegerStep.hxx"
|
||||
#include "DoubleStep.hxx"
|
||||
#include "StringStep.hxx"
|
||||
|
||||
|
||||
using namespace XAO;
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
void Step::checkElement(const int& element)
|
||||
void Step::checkElementIndex(const int& element)
|
||||
{
|
||||
if (element >= m_nbElements || element < 0)
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << "Element index is out of range [0, " << m_nbElements-1 << "] : " << element;
|
||||
throw SALOME_Exception(str.str().c_str());
|
||||
}
|
||||
if (element < m_nbElements && element >= 0)
|
||||
return;
|
||||
|
||||
throw SALOME_Exception(MsgBuilder() << "Element index is out of range [0, "
|
||||
<< m_nbElements-1 << "] : " << element);
|
||||
}
|
||||
|
||||
void Step::checkComponent(const int& component)
|
||||
void Step::checkComponentIndex(const int& component)
|
||||
{
|
||||
if (component >= m_nbComponents || component < 0)
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << "Component index is out of range [0, " << m_nbComponents-1 << "] : " << component;
|
||||
throw SALOME_Exception(str.str().c_str());
|
||||
}
|
||||
if (component < m_nbComponents && component >= 0)
|
||||
return;
|
||||
|
||||
throw SALOME_Exception(MsgBuilder() << "Component index is out of range [0, "
|
||||
<< 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);
|
||||
}
|
||||
|
@ -115,8 +115,12 @@ namespace XAO
|
||||
virtual void setStringValue(const int& element, const int& component, const std::string& value) = 0;
|
||||
|
||||
protected:
|
||||
void checkElement(const int& element);
|
||||
void checkComponent(const int& component);
|
||||
void checkElementIndex(const int& element);
|
||||
void checkComponentIndex(const int& component);
|
||||
|
||||
void checkNbElements(const int& nbElements);
|
||||
void checkNbComponents(const int& nbComponents);
|
||||
void checkNbValues(const int& nbValues);
|
||||
|
||||
protected:
|
||||
/** the index of the step. */
|
||||
|
@ -37,14 +37,12 @@ StringField::StringField(const std::string& name, const XAO::Dimension& dimensio
|
||||
|
||||
Step* StringField::addNewStep(const int& step)
|
||||
{
|
||||
return addStep(step);
|
||||
return addStep(step, 0);
|
||||
}
|
||||
|
||||
StringStep* StringField::addStep(const int& step)
|
||||
{
|
||||
StringStep* bstep = new StringStep(step, m_nbElements, m_nbComponents);
|
||||
m_steps.push_back(bstep);
|
||||
return bstep;
|
||||
return addStep(step, 0);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (index < m_steps.size())
|
||||
return (StringStep*)m_steps[index];
|
||||
throw SALOME_Exception("IndexOutOfRange");
|
||||
checkStepIndex(index);
|
||||
return (StringStep*)m_steps[index];
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ std::vector<std::string> StringStep::getValues()
|
||||
|
||||
std::vector<std::string> StringStep::getElement(const int& element)
|
||||
{
|
||||
checkElement(element);
|
||||
checkElementIndex(element);
|
||||
|
||||
std::vector<std::string> result(m_values[element]);
|
||||
return result;
|
||||
@ -81,7 +81,7 @@ std::vector<std::string> StringStep::getElement(const int& element)
|
||||
|
||||
std::vector<std::string> StringStep::getComponent(const int& component)
|
||||
{
|
||||
checkComponent(component);
|
||||
checkComponentIndex(component);
|
||||
|
||||
std::vector<std::string> result;
|
||||
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)
|
||||
{
|
||||
checkElement(element);
|
||||
checkComponent(component);
|
||||
checkElementIndex(element);
|
||||
checkComponentIndex(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)
|
||||
{
|
||||
if (values.size() != m_nbComponents * m_nbElements)
|
||||
throw SALOME_Exception("bad size"); // TODO
|
||||
checkNbValues(values.size());
|
||||
|
||||
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)
|
||||
{
|
||||
checkElement(element);
|
||||
if (elements.size() != m_nbComponents)
|
||||
throw SALOME_Exception("bad size"); // TODO
|
||||
checkElementIndex(element);
|
||||
checkNbComponents(elements.size());
|
||||
|
||||
for (int i = 0; i < m_nbComponents; ++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)
|
||||
{
|
||||
checkElement(component);
|
||||
if (components.size() != m_nbElements)
|
||||
throw SALOME_Exception("bad size"); // TODO
|
||||
checkElementIndex(component);
|
||||
checkNbElements(components.size());
|
||||
|
||||
for (int i = 0; i < m_nbElements; ++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)
|
||||
{
|
||||
checkElement(element);
|
||||
checkComponent(component);
|
||||
checkElementIndex(element);
|
||||
checkComponentIndex(component);
|
||||
|
||||
m_values[element][component] = value;
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ Xao::~Xao()
|
||||
}
|
||||
}
|
||||
|
||||
const int Xao::countGroups()
|
||||
const int Xao::countGroups() const
|
||||
{
|
||||
return m_groups.size();
|
||||
}
|
||||
@ -100,7 +100,7 @@ void Xao::removeGroup(Group* group)
|
||||
m_groups.remove(group);
|
||||
}
|
||||
|
||||
const int Xao::countFields()
|
||||
const int Xao::countFields() const
|
||||
{
|
||||
return m_fields.size();
|
||||
}
|
||||
@ -138,25 +138,11 @@ void Xao::removeField(Field* field)
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -170,8 +156,8 @@ const bool Xao::setXML(const std::string& xml)
|
||||
return XaoExporter::setXML(xml, this);
|
||||
}
|
||||
|
||||
void Xao::checkGeometry()
|
||||
void Xao::checkGeometry() const
|
||||
{
|
||||
if (m_geometry == NULL)
|
||||
throw SALOME_Exception("Geometry is null"); // TODO
|
||||
throw SALOME_Exception("Geometry is null");
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ namespace XAO
|
||||
* Gets the author of the file.
|
||||
* \return the author of the file.
|
||||
*/
|
||||
const std::string getAuthor()
|
||||
const std::string getAuthor() const
|
||||
{
|
||||
return m_author;
|
||||
}
|
||||
@ -106,7 +106,7 @@ namespace XAO
|
||||
* Gets the version of the file.
|
||||
* \return the version of the file.
|
||||
*/
|
||||
const std::string getVersion()
|
||||
const std::string getVersion() const
|
||||
{
|
||||
return m_version;
|
||||
}
|
||||
@ -127,7 +127,7 @@ namespace XAO
|
||||
* Gets the geometry.
|
||||
* \return the geometry.
|
||||
*/
|
||||
Geometry* getGeometry()
|
||||
Geometry* getGeometry() const
|
||||
{
|
||||
return m_geometry;
|
||||
}
|
||||
@ -148,7 +148,7 @@ namespace XAO
|
||||
* Gets the number of groups.
|
||||
* \return the number of groups.
|
||||
*/
|
||||
const int countGroups();
|
||||
const int countGroups() const;
|
||||
/**
|
||||
* Gets a group.
|
||||
* \param index the index of the wanted group.
|
||||
@ -182,7 +182,7 @@ namespace XAO
|
||||
* Gets the number of fields.
|
||||
* \return the number of fields.
|
||||
*/
|
||||
const int countFields();
|
||||
const int countFields() const;
|
||||
/**
|
||||
* Gets a field.
|
||||
* \param index the index of the wanted field.
|
||||
@ -241,7 +241,7 @@ namespace XAO
|
||||
const bool setXML(const std::string& xml);
|
||||
|
||||
private:
|
||||
void checkGeometry();
|
||||
void checkGeometry() const;
|
||||
|
||||
private:
|
||||
/** The author of the file. */
|
||||
|
@ -1,5 +1,4 @@
|
||||
|
||||
#include <sstream>
|
||||
#include <libxml/parser.h>
|
||||
#include <Utils_SALOME_Exception.hxx>
|
||||
|
||||
@ -81,10 +80,8 @@ std::string XaoExporter::readStringProp(xmlNodePtr node, const xmlChar* attribut
|
||||
if (exception.size() > 0)
|
||||
throw SALOME_Exception(exception.c_str());
|
||||
|
||||
std::ostringstream str;
|
||||
str << "Line " << node->line << ": ";
|
||||
str << "Property " << (char*)attribute << " is required.";
|
||||
throw SALOME_Exception(str.str().c_str());
|
||||
throw SALOME_Exception(MsgBuilder() << "Line " << node->line << ": "
|
||||
<< "Property " << (char*)attribute << " is required.");
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
@ -107,9 +104,8 @@ int XaoExporter::readIntegerProp(xmlNodePtr node, const xmlChar* attribute,
|
||||
if (exception.size() > 0)
|
||||
throw SALOME_Exception(exception.c_str());
|
||||
|
||||
std::ostringstream str;
|
||||
str << "Property " << (char*)attribute << " is required.";
|
||||
throw SALOME_Exception(str.str().c_str());
|
||||
throw SALOME_Exception(MsgBuilder() << "Line " << node->line << ": "
|
||||
<< "Property " << (char*)attribute << " is required.");
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
@ -205,7 +201,6 @@ void XaoExporter::exportGroups(Xao* xaoObject, xmlNodePtr xao)
|
||||
xmlNodePtr groups = xmlNewChild(xao, 0, C_TAG_GROUPS, 0);
|
||||
xmlNewProp(groups, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoObject->countGroups()).c_str());
|
||||
|
||||
//for (std::list<Group*>::iterator it = m_groups.begin(); it != m_groups.end(); ++it)
|
||||
for (int i = 0; i < xaoObject->countGroups(); i++)
|
||||
{
|
||||
//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_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)
|
||||
{
|
||||
int grpElt = (*it);
|
||||
@ -379,9 +373,8 @@ void XaoExporter::parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode, Geometry*
|
||||
}
|
||||
else
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << "Shape format not supported: " << XaoUtils::shapeFormatToString(geometry->getFormat());
|
||||
throw SALOME_Exception(str.str().c_str());
|
||||
throw SALOME_Exception(MsgBuilder() << "Shape format not supported: "
|
||||
<< XaoUtils::shapeFormatToString(geometry->getFormat()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -535,7 +528,10 @@ void XaoExporter::parseFieldNode(xmlNodePtr fieldNode, Xao* xaoObject)
|
||||
|
||||
// ensure that the components node is defined
|
||||
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
|
||||
int nbComponents = readIntegerProp(componentsNode, C_ATTR_COUNT, true, -1);
|
||||
@ -602,9 +598,7 @@ void XaoExporter::parseStepElementNode(xmlNodePtr eltNode, Step* step)
|
||||
|
||||
if (data == NULL)
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << "Line " << valNode->line << ": no content for value.";
|
||||
throw SALOME_Exception(str.str().c_str());
|
||||
throw SALOME_Exception(MsgBuilder() << "Line " << valNode->line << ": no content for value.");
|
||||
}
|
||||
|
||||
std::string value = (char*)data;
|
||||
|
@ -24,10 +24,8 @@
|
||||
#include <Utils_SALOME_Exception.hxx>
|
||||
|
||||
#include "Xao.hxx"
|
||||
#include "Field.hxx"
|
||||
#include "XaoUtils.hxx"
|
||||
|
||||
|
||||
using namespace XAO;
|
||||
|
||||
|
||||
@ -75,7 +73,8 @@ const std::string XaoUtils::dimensionToString(const XAO::Dimension& dimension)
|
||||
return "solid";
|
||||
if (dimension == XAO::WHOLE)
|
||||
return "whole";
|
||||
throw SALOME_Exception("Bad dimension");
|
||||
|
||||
throw SALOME_Exception(MsgBuilder() << "Bad dimension: " << 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;
|
||||
if (dimension == "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)
|
||||
@ -103,7 +103,8 @@ const std::string XaoUtils::fieldTypeToString(const XAO::Type& type)
|
||||
return "double";
|
||||
if (type == XAO::STRING)
|
||||
return "string";
|
||||
throw SALOME_Exception("Bad type");
|
||||
|
||||
throw SALOME_Exception(MsgBuilder() << "Bad type: " << 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;
|
||||
if (type == "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)
|
||||
@ -125,7 +127,8 @@ const std::string XaoUtils::shapeFormatToString(const XAO::Format& format)
|
||||
return "BREP";
|
||||
if (format == XAO::STEP)
|
||||
return "STEP";
|
||||
throw SALOME_Exception("Bad format");
|
||||
|
||||
throw SALOME_Exception(MsgBuilder() << "Bad format: " << 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;
|
||||
if (format == "STEP")
|
||||
return XAO::STEP;
|
||||
throw SALOME_Exception("Bad format");
|
||||
|
||||
throw SALOME_Exception(MsgBuilder() << "Bad format: " << format);
|
||||
}
|
||||
|
@ -21,6 +21,9 @@
|
||||
#ifndef __XAO_UTILS_HXX__
|
||||
#define __XAO_UTILS_HXX__
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "Xao.hxx"
|
||||
#include "Field.hxx"
|
||||
|
||||
@ -91,7 +94,26 @@ namespace XAO
|
||||
* \throw SALOME_Exception
|
||||
*/
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -48,7 +48,21 @@ void BrepGeometryTest::testGetIDs()
|
||||
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");
|
||||
readBrep(geom, "Box_2.brep");
|
||||
@ -61,7 +75,21 @@ void BrepGeometryTest::testGeometricalElements()
|
||||
CPPUNIT_ASSERT_EQUAL(2, wires[0]);
|
||||
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;
|
||||
}
|
||||
|
@ -11,7 +11,9 @@ namespace XAO
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(BrepGeometryTest);
|
||||
CPPUNIT_TEST(testGetIDs);
|
||||
CPPUNIT_TEST(testGeometricalElements);
|
||||
CPPUNIT_TEST(testGetEdgeVertices);
|
||||
CPPUNIT_TEST(testGetFaceWires);
|
||||
CPPUNIT_TEST(testSolidShells);
|
||||
CPPUNIT_TEST(testGetVertex);
|
||||
CPPUNIT_TEST(testGetEdgeLength);
|
||||
CPPUNIT_TEST(testGetFaceArea);
|
||||
@ -24,7 +26,9 @@ namespace XAO
|
||||
void cleanUp();
|
||||
|
||||
void testGetIDs();
|
||||
void testGeometricalElements();
|
||||
void testGetEdgeVertices();
|
||||
void testGetFaceWires();
|
||||
void testSolidShells();
|
||||
|
||||
void testGetVertex();
|
||||
void testGetEdgeLength();
|
||||
|
36
src/XAO/tests/GeometryTest.cxx
Normal file
36
src/XAO/tests/GeometryTest.cxx
Normal 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);
|
||||
}
|
27
src/XAO/tests/GeometryTest.hxx
Normal file
27
src/XAO/tests/GeometryTest.hxx
Normal 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__
|
@ -52,9 +52,7 @@ void GroupTest::testGroup()
|
||||
delete group;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void GroupTest::testGroupErrors()
|
||||
{
|
||||
CPPUNIT_ASSERT_THROW(new Group(XAO::WHOLE, 20), SALOME_Exception);
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ namespace XAO
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(GroupTest);
|
||||
CPPUNIT_TEST(testGroup);
|
||||
CPPUNIT_TEST(testGroupErrors);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
@ -19,6 +20,7 @@ namespace XAO
|
||||
void cleanUp();
|
||||
|
||||
void testGroup();
|
||||
void testGroupErrors();
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -179,15 +179,6 @@ void ImportExportTest::checkImport(Xao& xao)
|
||||
|
||||
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"));
|
||||
|
||||
Xao xao;
|
||||
|
@ -62,7 +62,7 @@ Arguments parseArguments(int argc, char* argv[])
|
||||
{
|
||||
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)
|
||||
res.Test = argv[++i];
|
||||
|
@ -41,6 +41,7 @@ TestXAO_LDFLAGS = \
|
||||
dist_TestXAO_SOURCES = \
|
||||
GroupTest.cxx \
|
||||
FieldTest.cxx \
|
||||
GeometryTest.cxx \
|
||||
ImportExportTest.cxx \
|
||||
BrepGeometryTest.cxx \
|
||||
XAOTests.cxx
|
||||
|
@ -1,10 +1,12 @@
|
||||
#include "GroupTest.hxx"
|
||||
#include "FieldTest.hxx"
|
||||
#include "GeometryTest.hxx"
|
||||
#include "ImportExportTest.hxx"
|
||||
#include "BrepGeometryTest.hxx"
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::GroupTest);
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::FieldTest);
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::GeometryTest);
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::ImportExportTest);
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::BrepGeometryTest);
|
||||
|
||||
|
806
src/XAO/tests/data/Cut_2.brep
Normal file
806
src/XAO/tests/data/Cut_2.brep
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user