From b90ae66f7df6c81e8a00050f283dad331d6fdcc0 Mon Sep 17 00:00:00 2001 From: fps Date: Fri, 13 Sep 2013 09:41:06 +0000 Subject: [PATCH] add read only property to geometry --- src/XAO/XAO_BooleanField.hxx | 2 +- src/XAO/XAO_BooleanStep.hxx | 3 +- src/XAO/XAO_BrepGeometry.hxx | 2 +- src/XAO/XAO_DoubleField.hxx | 2 +- src/XAO/XAO_DoubleStep.hxx | 3 +- src/XAO/XAO_Exception.hxx | 26 ++++++++--- src/XAO/XAO_Field.hxx | 2 +- src/XAO/XAO_Geometry.cxx | 71 ++++++++++++++++++++++++++++++ src/XAO/XAO_Geometry.hxx | 50 ++++++++++++++------- src/XAO/XAO_Group.hxx | 2 +- src/XAO/XAO_IntegerField.hxx | 2 +- src/XAO/XAO_IntegerStep.hxx | 3 +- src/XAO/XAO_Step.hxx | 3 +- src/XAO/XAO_StringField.hxx | 2 +- src/XAO/XAO_StringStep.hxx | 3 +- src/XAO/XAO_Xao.hxx | 40 +++-------------- src/XAO/XAO_XaoExporter.cxx | 19 ++++++++ src/XAO/XAO_XaoExporter.hxx | 19 ++++++++ src/XAO/XAO_XaoUtils.hxx | 33 +++++++++++++- src/XAO/tests/ImportExportTest.cxx | 27 ++++++------ 20 files changed, 225 insertions(+), 89 deletions(-) diff --git a/src/XAO/XAO_BooleanField.hxx b/src/XAO/XAO_BooleanField.hxx index 328c6b332..9a971e0aa 100644 --- a/src/XAO/XAO_BooleanField.hxx +++ b/src/XAO/XAO_BooleanField.hxx @@ -23,7 +23,7 @@ #include -#include "XAO_Xao.hxx" +#include "XAO_XaoUtils.hxx" #include "XAO_Field.hxx" #include "XAO_BooleanStep.hxx" diff --git a/src/XAO/XAO_BooleanStep.hxx b/src/XAO/XAO_BooleanStep.hxx index 819161f03..c6ceb3e60 100644 --- a/src/XAO/XAO_BooleanStep.hxx +++ b/src/XAO/XAO_BooleanStep.hxx @@ -18,13 +18,12 @@ // // Author : Frederic Pons (OpenCascade) - #ifndef __XAO_BOOLEANSTEP_HXX__ #define __XAO_BOOLEANSTEP_HXX__ #include -#include "XAO_Xao.hxx" +#include "XAO_XaoUtils.hxx" #include "XAO_Step.hxx" namespace XAO diff --git a/src/XAO/XAO_BrepGeometry.hxx b/src/XAO/XAO_BrepGeometry.hxx index 017d9c2c4..217faf8c7 100644 --- a/src/XAO/XAO_BrepGeometry.hxx +++ b/src/XAO/XAO_BrepGeometry.hxx @@ -26,7 +26,7 @@ #include -#include "XAO_Xao.hxx" +#include "XAO_XaoUtils.hxx" #include "XAO_Geometry.hxx" namespace XAO diff --git a/src/XAO/XAO_DoubleField.hxx b/src/XAO/XAO_DoubleField.hxx index a733aeae3..2ea44cf27 100644 --- a/src/XAO/XAO_DoubleField.hxx +++ b/src/XAO/XAO_DoubleField.hxx @@ -23,7 +23,7 @@ #include -#include "XAO_Xao.hxx" +#include "XAO_XaoUtils.hxx" #include "XAO_Field.hxx" #include "XAO_DoubleStep.hxx" diff --git a/src/XAO/XAO_DoubleStep.hxx b/src/XAO/XAO_DoubleStep.hxx index e652f84fb..72a92c5a5 100644 --- a/src/XAO/XAO_DoubleStep.hxx +++ b/src/XAO/XAO_DoubleStep.hxx @@ -18,13 +18,12 @@ // // Author : Frederic Pons (OpenCascade) - #ifndef __XAO_DOUBLESTEP_HXX__ #define __XAO_DOUBLESTEP_HXX__ #include -#include "XAO_Xao.hxx" +#include "XAO_XaoUtils.hxx" #include "XAO_Step.hxx" namespace XAO diff --git a/src/XAO/XAO_Exception.hxx b/src/XAO/XAO_Exception.hxx index 8c9aea26a..17f2699ab 100644 --- a/src/XAO/XAO_Exception.hxx +++ b/src/XAO/XAO_Exception.hxx @@ -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. diff --git a/src/XAO/XAO_Field.hxx b/src/XAO/XAO_Field.hxx index 3d33e46f6..d36987569 100644 --- a/src/XAO/XAO_Field.hxx +++ b/src/XAO/XAO_Field.hxx @@ -24,7 +24,7 @@ #include #include -#include "XAO_Xao.hxx" +#include "XAO_XaoUtils.hxx" #include "XAO_Step.hxx" namespace XAO diff --git a/src/XAO/XAO_Geometry.cxx b/src/XAO/XAO_Geometry.cxx index 7ef743765..b774b31af 100644 --- a/src/XAO/XAO_Geometry.cxx +++ b/src/XAO/XAO_Geometry.cxx @@ -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); +} diff --git a/src/XAO/XAO_Geometry.hxx b/src/XAO/XAO_Geometry.hxx index acc5adae2..4cfc080ef 100644 --- a/src/XAO/XAO_Geometry.hxx +++ b/src/XAO/XAO_Geometry.hxx @@ -23,7 +23,8 @@ #include -#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; }; } diff --git a/src/XAO/XAO_Group.hxx b/src/XAO/XAO_Group.hxx index a5394252a..0625600d5 100644 --- a/src/XAO/XAO_Group.hxx +++ b/src/XAO/XAO_Group.hxx @@ -24,7 +24,7 @@ #include #include -#include "XAO_Xao.hxx" +#include "XAO_XaoUtils.hxx" namespace XAO { diff --git a/src/XAO/XAO_IntegerField.hxx b/src/XAO/XAO_IntegerField.hxx index 1f8db8f54..e801c25bd 100644 --- a/src/XAO/XAO_IntegerField.hxx +++ b/src/XAO/XAO_IntegerField.hxx @@ -23,7 +23,7 @@ #include -#include "XAO_Xao.hxx" +#include "XAO_XaoUtils.hxx" #include "XAO_Field.hxx" #include "XAO_IntegerStep.hxx" diff --git a/src/XAO/XAO_IntegerStep.hxx b/src/XAO/XAO_IntegerStep.hxx index b2c537261..10d50a5bf 100644 --- a/src/XAO/XAO_IntegerStep.hxx +++ b/src/XAO/XAO_IntegerStep.hxx @@ -18,13 +18,12 @@ // // Author : Frederic Pons (OpenCascade) - #ifndef __XAO_INTEGERSTEP_HXX__ #define __XAO_INTEGERSTEP_HXX__ #include -#include "XAO_Xao.hxx" +#include "XAO_XaoUtils.hxx" #include "XAO_Step.hxx" namespace XAO diff --git a/src/XAO/XAO_Step.hxx b/src/XAO/XAO_Step.hxx index 42ca7def6..6c61020c9 100644 --- a/src/XAO/XAO_Step.hxx +++ b/src/XAO/XAO_Step.hxx @@ -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 { diff --git a/src/XAO/XAO_StringField.hxx b/src/XAO/XAO_StringField.hxx index c939a637d..489f23459 100644 --- a/src/XAO/XAO_StringField.hxx +++ b/src/XAO/XAO_StringField.hxx @@ -23,7 +23,7 @@ #include -#include "XAO_Xao.hxx" +#include "XAO_XaoUtils.hxx" #include "XAO_Field.hxx" #include "XAO_StringStep.hxx" diff --git a/src/XAO/XAO_StringStep.hxx b/src/XAO/XAO_StringStep.hxx index f1ad0d953..a623bb580 100644 --- a/src/XAO/XAO_StringStep.hxx +++ b/src/XAO/XAO_StringStep.hxx @@ -18,14 +18,13 @@ // // Author : Frederic Pons (OpenCascade) - #ifndef __XAO_STRINGSTEP_HXX__ #define __XAO_STRINGSTEP_HXX__ #include #include -#include "XAO_Xao.hxx" +#include "XAO_XaoUtils.hxx" #include "XAO_Step.hxx" namespace XAO diff --git a/src/XAO/XAO_Xao.hxx b/src/XAO/XAO_Xao.hxx index 8bcd11dbd..a6685bc30 100644 --- a/src/XAO/XAO_Xao.hxx +++ b/src/XAO/XAO_Xao.hxx @@ -24,42 +24,11 @@ #include #include #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(); } // diff --git a/src/XAO/XAO_XaoExporter.cxx b/src/XAO/XAO_XaoExporter.cxx index 5ebfef7dc..cd68ec5c9 100644 --- a/src/XAO/XAO_XaoExporter.cxx +++ b/src/XAO/XAO_XaoExporter.cxx @@ -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 diff --git a/src/XAO/XAO_XaoExporter.hxx b/src/XAO/XAO_XaoExporter.hxx index 3dad13d6d..6929b22b8 100644 --- a/src/XAO/XAO_XaoExporter.hxx +++ b/src/XAO/XAO_XaoExporter.hxx @@ -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__ diff --git a/src/XAO/XAO_XaoUtils.hxx b/src/XAO/XAO_XaoUtils.hxx index 41fefb5ec..5718db52b 100644 --- a/src/XAO/XAO_XaoUtils.hxx +++ b/src/XAO/XAO_XaoUtils.hxx @@ -25,12 +25,43 @@ #include #include -#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. diff --git a/src/XAO/tests/ImportExportTest.cxx b/src/XAO/tests/ImportExportTest.cxx index 5d02cb0d9..b84f04eac 100644 --- a/src/XAO/tests/ImportExportTest.cxx +++ b/src/XAO/tests/ImportExportTest.cxx @@ -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); -} -- 2.39.2