add read only property to geometry

This commit is contained in:
fps 2013-09-13 09:41:06 +00:00
parent 8a3dd9b891
commit b90ae66f7d
20 changed files with 225 additions and 89 deletions

View File

@ -23,7 +23,7 @@
#include <string>
#include "XAO_Xao.hxx"
#include "XAO_XaoUtils.hxx"
#include "XAO_Field.hxx"
#include "XAO_BooleanStep.hxx"

View File

@ -18,13 +18,12 @@
//
// Author : Frederic Pons (OpenCascade)
#ifndef __XAO_BOOLEANSTEP_HXX__
#define __XAO_BOOLEANSTEP_HXX__
#include <vector>
#include "XAO_Xao.hxx"
#include "XAO_XaoUtils.hxx"
#include "XAO_Step.hxx"
namespace XAO

View File

@ -26,7 +26,7 @@
#include <TopoDS_Shape.hxx>
#include "XAO_Xao.hxx"
#include "XAO_XaoUtils.hxx"
#include "XAO_Geometry.hxx"
namespace XAO

View File

@ -23,7 +23,7 @@
#include <string>
#include "XAO_Xao.hxx"
#include "XAO_XaoUtils.hxx"
#include "XAO_Field.hxx"
#include "XAO_DoubleStep.hxx"

View File

@ -18,13 +18,12 @@
//
// Author : Frederic Pons (OpenCascade)
#ifndef __XAO_DOUBLESTEP_HXX__
#define __XAO_DOUBLESTEP_HXX__
#include <vector>
#include "XAO_Xao.hxx"
#include "XAO_XaoUtils.hxx"
#include "XAO_Step.hxx"
namespace XAO

View File

@ -1,16 +1,28 @@
/*
* XAO_Exception.hxx
*
* Created on: 12 sept. 2013
* Author: salome
*/
// Copyright (C) 2013 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// Author : Frederic Pons (OpenCascade)
#ifndef __XAO_EXCEPTION_HXX__
#define __XAO_EXCEPTION_HXX__
namespace XAO
{
/**
* \class XAO_Exception
* Exception for XAO operations.

View File

@ -24,7 +24,7 @@
#include <string>
#include <vector>
#include "XAO_Xao.hxx"
#include "XAO_XaoUtils.hxx"
#include "XAO_Step.hxx"
namespace XAO

View File

@ -27,6 +27,7 @@ using namespace XAO;
Geometry::Geometry(const std::string& name)
: m_name(name)
{
m_readOnly = false;
}
Geometry* Geometry::createGeometry(const XAO::Format& format)
@ -48,6 +49,13 @@ Geometry::~Geometry()
{
}
void Geometry::checkReadOnly()
throw (XAO_Exception)
{
if (m_readOnly)
throw XAO_Exception("Geometry is read only.");
}
const int Geometry::countElements(const XAO::Dimension& dim) const
throw (XAO_Exception)
{
@ -122,3 +130,66 @@ throw (XAO_Exception)
throw XAO_Exception(MsgBuilder() << "Unknown dimension:" << dim);
}
void Geometry::setCountVertices(const int& nb) throw (XAO_Exception)
{
checkReadOnly();
m_vertices.setSize(nb);
}
void Geometry::setCountEdges(const int& nb) throw (XAO_Exception)
{
checkReadOnly();
m_edges.setSize(nb);
}
void Geometry::setCountFaces(const int& nb) throw (XAO_Exception)
{
checkReadOnly();
m_faces.setSize(nb);
}
void Geometry::setCountSolids(const int& nb) throw (XAO_Exception)
{
checkReadOnly();
m_solids.setSize(nb);
}
void Geometry::setVertexReference(const int& index, const std::string& reference) throw (XAO_Exception)
{
checkReadOnly();
m_vertices.setReference(index, reference);
}
void Geometry::setEdgeReference(const int& index, const std::string& reference) throw (XAO_Exception)
{
checkReadOnly();
m_edges.setReference(index, reference);
}
void Geometry::setFaceReference(const int& index, const std::string& reference) throw (XAO_Exception)
{
checkReadOnly();
m_faces.setReference(index, reference);
}
void Geometry::setSolidReference(const int& index, const std::string& reference) throw (XAO_Exception)
{
checkReadOnly();
m_solids.setReference(index, reference);
}
void Geometry::setVertex(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception)
{
checkReadOnly();
m_vertices.setElement(index, name, reference);
}
void Geometry::setEdge(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception)
{
checkReadOnly();
m_edges.setElement(index, name, reference);
}
void Geometry::setFace(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception)
{
checkReadOnly();
m_faces.setElement(index, name, reference);
}
void Geometry::setSolid(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception)
{
checkReadOnly();
m_solids.setElement(index, name, reference);
}

View File

@ -23,7 +23,8 @@
#include <string>
#include "XAO_Xao.hxx"
#include "XAO_XaoUtils.hxx"
#include "XAO_Exception.hxx"
#include "XAO_GeometricElement.hxx"
namespace XAO
@ -93,10 +94,10 @@ namespace XAO
const int countFaces() const { return m_faces.getSize(); }
const int countSolids() const { return m_solids.getSize(); }
void setCountVertices(const int& nb) { m_vertices.setSize(nb); }
void setCountEdges(const int& nb) { m_edges.setSize(nb); }
void setCountFaces(const int& nb) { m_faces.setSize(nb); }
void setCountSolids(const int& nb) { m_solids.setSize(nb); }
void setCountVertices(const int& nb) throw (XAO_Exception);
void setCountEdges(const int& nb) throw (XAO_Exception);
void setCountFaces(const int& nb) throw (XAO_Exception);
void setCountSolids(const int& nb) throw (XAO_Exception);
const std::string getVertexName(const int& index) throw (XAO_Exception) { return m_vertices.getName(index); }
const std::string getEdgeName(const int& index) throw (XAO_Exception) { return m_edges.getName(index); }
@ -113,21 +114,21 @@ namespace XAO
const bool hasFaceName(const int& index) throw (XAO_Exception) { return m_faces.hasName(index); }
const bool hasSolidName(const int& index) throw (XAO_Exception) { return m_solids.hasName(index); }
const std::string getVertexReference(const int& index) { return m_vertices.getReference(index); }
const std::string getEdgeReference(const int& index) { return m_edges.getReference(index); }
const std::string getFaceReference(const int& index) { return m_faces.getReference(index); }
const std::string getSolidReference(const int& index) { return m_solids.getReference(index); }
const std::string getVertexReference(const int& index) throw (XAO_Exception) { return m_vertices.getReference(index); }
const std::string getEdgeReference(const int& index) throw (XAO_Exception) { return m_edges.getReference(index); }
const std::string getFaceReference(const int& index) throw (XAO_Exception) { return m_faces.getReference(index); }
const std::string getSolidReference(const int& index) throw (XAO_Exception) { return m_solids.getReference(index); }
const std::string getElementReference(const XAO::Dimension& dim, const int& index) throw (XAO_Exception);
void setVertexReference(const int& index, const std::string& reference) { m_vertices.setReference(index, reference); }
void setEdgeReference(const int& index, const std::string& reference) { m_edges.setReference(index, reference); }
void setFaceReference(const int& index, const std::string& reference) { m_faces.setReference(index, reference); }
void setSolidReference(const int& index, const std::string& reference) { m_solids.setReference(index, reference); }
void setVertexReference(const int& index, const std::string& reference) throw (XAO_Exception);
void setEdgeReference(const int& index, const std::string& reference) throw (XAO_Exception);
void setFaceReference(const int& index, const std::string& reference) throw (XAO_Exception);
void setSolidReference(const int& index, const std::string& reference) throw (XAO_Exception);
void setVertex(const int& index, const std::string& name, const std::string& reference) { m_vertices.setElement(index, name, reference); }
void setEdge(const int& index, const std::string& name, const std::string& reference) { m_edges.setElement(index, name, reference); }
void setFace(const int& index, const std::string& name, const std::string& reference) { m_faces.setElement(index, name, reference); }
void setSolid(const int& index, const std::string& name, const std::string& reference) { m_solids.setElement(index, name, reference); }
void setVertex(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception);
void setEdge(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception);
void setFace(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception);
void setSolid(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception);
const int getVertexIndexByReference(const std::string& reference) { return m_vertices.getIndexByReference(reference); }
const int getEdgeIndexByReference(const std::string& reference) { return m_edges.getIndexByReference(reference); }
@ -138,12 +139,27 @@ namespace XAO
GeometricElementList::iterator begin(const XAO::Dimension& dim) throw (XAO_Exception);
GeometricElementList::iterator end(const XAO::Dimension& dim) throw (XAO_Exception);
/**
* Verifies if the geometry is read only.
* @return true if the geometry is read only.
*/
bool isReadOnly() { return m_readOnly; }
/**
* Sets the geometry read only.
*/
void setReadOnly() { m_readOnly = true; }
protected:
void checkReadOnly() throw (XAO_Exception);
protected:
std::string m_name;
GeometricElementList m_vertices;
GeometricElementList m_edges;
GeometricElementList m_faces;
GeometricElementList m_solids;
bool m_readOnly;
};
}

View File

@ -24,7 +24,7 @@
#include <string>
#include <set>
#include "XAO_Xao.hxx"
#include "XAO_XaoUtils.hxx"
namespace XAO
{

View File

@ -23,7 +23,7 @@
#include <string>
#include "XAO_Xao.hxx"
#include "XAO_XaoUtils.hxx"
#include "XAO_Field.hxx"
#include "XAO_IntegerStep.hxx"

View File

@ -18,13 +18,12 @@
//
// Author : Frederic Pons (OpenCascade)
#ifndef __XAO_INTEGERSTEP_HXX__
#define __XAO_INTEGERSTEP_HXX__
#include <vector>
#include "XAO_Xao.hxx"
#include "XAO_XaoUtils.hxx"
#include "XAO_Step.hxx"
namespace XAO

View File

@ -18,11 +18,10 @@
//
// Author : Frederic Pons (OpenCascade)
#ifndef __XAO_STEP_HXX__
#define __XAO_STEP_HXX__
#include "XAO_Xao.hxx"
#include "XAO_XaoUtils.hxx"
namespace XAO
{

View File

@ -23,7 +23,7 @@
#include <string>
#include "XAO_Xao.hxx"
#include "XAO_XaoUtils.hxx"
#include "XAO_Field.hxx"
#include "XAO_StringStep.hxx"

View File

@ -18,14 +18,13 @@
//
// Author : Frederic Pons (OpenCascade)
#ifndef __XAO_STRINGSTEP_HXX__
#define __XAO_STRINGSTEP_HXX__
#include <string>
#include <vector>
#include "XAO_Xao.hxx"
#include "XAO_XaoUtils.hxx"
#include "XAO_Step.hxx"
namespace XAO

View File

@ -24,42 +24,11 @@
#include <string>
#include <list>
#include "XAO_Exception.hxx"
#include "XAO_XaoUtils.hxx"
#include "XAO_Geometry.hxx"
namespace XAO
{
/**
* @enum Format
*/
enum Format
{
BREP,
STEP
};
/**
* @enum Dimension
*/
enum Dimension
{
VERTEX = 0,//!< VERTEX
EDGE = 1, //!< EDGE
FACE = 2, //!< FACE
SOLID = 3, //!< SOLID
WHOLE = -1 //!< WHOLE
};
/**
* @enum Type
*/
enum Type
{
BOOLEAN = 0,//!< BOOLEAN
INTEGER = 1,//!< INTEGER
DOUBLE = 2, //!< DOUBLE
STRING = 3 //!< STRING
};
class Geometry;
class Group;
class Field;
@ -135,9 +104,12 @@ namespace XAO
* Sets the geometry.
* \param geometry the geometry to set.
*/
void setGeometry(Geometry* geometry)
void setGeometry(Geometry* geometry) throw (XAO_Exception)
{
if (m_geometry != NULL)
throw XAO_Exception("Geometry already set.");
m_geometry = geometry;
m_geometry->setReadOnly();
}
//

View File

@ -1,3 +1,22 @@
// Copyright (C) 2013 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// Author : Frederic Pons (OpenCascade)
#include <libxml/parser.h>

View File

@ -1,3 +1,22 @@
// Copyright (C) 2013 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// Author : Frederic Pons (OpenCascade)
#ifndef __XAO_XAOEXPORTER_HXX__
#define __XAO_XAOEXPORTER_HXX__

View File

@ -25,12 +25,43 @@
#include <string>
#include <exception>
#include "XAO_Xao.hxx"
#include "XAO_Exception.hxx"
namespace XAO
{
/**
* @enum Format
*/
enum Format
{
BREP,
STEP
};
/**
* @enum Dimension
*/
enum Dimension
{
VERTEX = 0,//!< VERTEX
EDGE = 1, //!< EDGE
FACE = 2, //!< FACE
SOLID = 3, //!< SOLID
WHOLE = -1 //!< WHOLE
};
/**
* @enum Type
*/
enum Type
{
BOOLEAN = 0,//!< BOOLEAN
INTEGER = 1,//!< INTEGER
DOUBLE = 2, //!< DOUBLE
STRING = 3 //!< STRING
};
/**
* \class XaoUtils
* Utilities class to convert types.

View File

@ -55,7 +55,7 @@ void ImportExportTest::testExportGeometry()
Xao xao("me", "1.0");
Geometry* geom = Geometry::createGeometry(XAO::BREP);
geom->setName("mygeom");
xao.setGeometry(geom);
CPPUNIT_ASSERT_EQUAL(false, geom->isReadOnly());
// add elements
geom->setCountVertices(4);
@ -76,6 +76,9 @@ void ImportExportTest::testExportGeometry()
geom->setCountSolids(1);
geom->setSolid(0, "s1", "10");
xao.setGeometry(geom);
CPPUNIT_ASSERT_EQUAL(true, geom->isReadOnly());
// groups
Group* group = xao.addGroup(XAO::SOLID);
group->setName("boite1");
@ -109,13 +112,11 @@ void ImportExportTest::testExportGeometry()
void ImportExportTest::testGeometryError()
{
Xao xao("me", "1.0");
Geometry* geom = Geometry::createGeometry(XAO::BREP);
geom->setName("mygeom");
xao.setGeometry(geom);
geom->setCountVertices(2);
CPPUNIT_ASSERT_THROW(geom->setVertex(3, "v4", "4"), XAO_Exception);
delete geom;
}
void ImportExportTest::testImportXao()
@ -125,6 +126,15 @@ void ImportExportTest::testImportXao()
checkImport(xao);
}
void ImportExportTest::testImportXaoFromText()
{
char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath("test.xao"));
Xao xao;
xao.setXML(txt);
checkImport(xao);
}
void ImportExportTest::checkImport(Xao& xao)
{
CPPUNIT_ASSERT_EQUAL(std::string("me"), xao.getAuthor());
@ -175,12 +185,3 @@ void ImportExportTest::checkImport(Xao& xao)
CPPUNIT_ASSERT_EQUAL(0, group->get(0));
CPPUNIT_ASSERT_EQUAL(1, group->get(1));
}
void ImportExportTest::testImportXaoFromText()
{
char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath("test.xao"));
Xao xao;
xao.setXML(txt);
checkImport(xao);
}