X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESHDS%2FSMESHDS_Document.cxx;h=4513302d3767bc5e5210122c58d16156ef8d13eb;hp=81949891f6bac520158c5f9cbf7f6be89c3dfb81;hb=7eda9ca931ed2a11cb5e4637e4ffe19f5c061115;hpb=789d7f7415a1e465aee36232e7633eea548ff1fb diff --git a/src/SMESHDS/SMESHDS_Document.cxx b/src/SMESHDS/SMESHDS_Document.cxx index 81949891f..4513302d3 100644 --- a/src/SMESHDS/SMESHDS_Document.cxx +++ b/src/SMESHDS/SMESHDS_Document.cxx @@ -1,192 +1,205 @@ -// SMESH SMESHDS : management of mesh data and SMESH document +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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, or (at your option) any later version. // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// 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 // + +// SMESH SMESHDS : management of mesh data and SMESH document // File : SMESHDS_Document.cxx // Author : Yves FRICAUD, OCC // Module : SMESH // $Header: +// +#include "SMESHDS_Document.hxx" +#include "utilities.h" using namespace std; -#include "SMESHDS_Document.ixx" -#include "SMESHDS_Hypothesis.hxx" - -#include //======================================================================= //function : Create //purpose : //======================================================================= -SMESHDS_Document::SMESHDS_Document(const Standard_Integer UserID): myUserID(UserID) -{} +SMESHDS_Document::SMESHDS_Document(int UserID):myUserID(UserID) +{ +} + +//======================================================================= +//function : Destructor +//purpose : +//======================================================================= + +SMESHDS_Document::~SMESHDS_Document() +{ + InitMeshesIterator(); + while ( MoreMesh() ) + delete NextMesh(); +} //======================================================================= //function : NewMesh //purpose : //======================================================================= -Standard_Integer SMESHDS_Document::NewMesh() +SMESHDS_Mesh * SMESHDS_Document::NewMesh(bool theIsEmbeddedMode, int MeshID) { - static Standard_Integer NewMeshID = 0; - NewMeshID++; - Handle (SMESHDS_Mesh) aNewMesh = new SMESHDS_Mesh (NewMeshID); - myMeshes.Bind(NewMeshID ,aNewMesh); - return NewMeshID; + std::map::iterator i_m = + myMeshes.insert( make_pair( MeshID, (SMESHDS_Mesh*)0 )).first; + if ( i_m->second ) + throw SALOME_Exception("SMESHDS_Document::NewMesh(): ID of existing mesh given"); + SMESHDS_Mesh *aNewMesh = new SMESHDS_Mesh(MeshID,theIsEmbeddedMode); + i_m->second = aNewMesh; + return aNewMesh; } //======================================================================= //function : GetMesh -//purpose : +//purpose : //======================================================================= -Handle(SMESHDS_Mesh) SMESHDS_Document::GetMesh(const Standard_Integer MeshID) +SMESHDS_Mesh *SMESHDS_Document::GetMesh(int MeshID) { - if (!myMeshes.IsBound(MeshID)) - Standard_OutOfRange::Raise("SMESHDS_Document::RemoveMesh"); - return myMeshes.Find(MeshID); + map::iterator it=myMeshes.find(MeshID); + if (it==myMeshes.end()) + { + MESSAGE("SMESHDS_Document::GetMesh : ID not found"); + return NULL; + } + else return (*it).second; } //======================================================================= //function : RemoveMesh -//purpose : +//purpose : //======================================================================= -void SMESHDS_Document::RemoveMesh(const Standard_Integer MeshID) +void SMESHDS_Document::RemoveMesh(int MeshID) { - if (!myMeshes.IsBound(MeshID)) - Standard_OutOfRange::Raise("SMESHDS_Document::RemoveMesh"); - myMeshes.UnBind(MeshID); + map::iterator it=myMeshes.find(MeshID); + if (it!=myMeshes.end()) + myMeshes.erase(it); } //======================================================================= //function : AddHypothesis //purpose : //======================================================================= -void SMESHDS_Document::AddHypothesis(const SMESHDS_PtrHypothesis& H) +void SMESHDS_Document::AddHypothesis(SMESHDS_Hypothesis * H) { - myHypothesis.Bind (H->GetID(), H); + myHypothesis[H->GetID()]=H; } //======================================================================= //function : GetHypothesis //purpose : //======================================================================= -SMESHDS_PtrHypothesis SMESHDS_Document::GetHypothesis(const Standard_Integer HypID) +SMESHDS_Hypothesis * SMESHDS_Document::GetHypothesis(int HypID) { - if (!myHypothesis.IsBound(HypID)) - Standard_OutOfRange::Raise("SMESHDS_Document::GetHypothesis"); - return myHypothesis.Find(HypID); + map::iterator it=myHypothesis.find(HypID); + if (it==myHypothesis.end()) + { + MESSAGE("SMESHDS_Document::GetHypothesis : ID not found"); + return NULL; + } + else return (*it).second; } //======================================================================= //function : RemoveHypothesis -//purpose : +//purpose : //======================================================================= -void SMESHDS_Document::RemoveHypothesis(const Standard_Integer HypID) +void SMESHDS_Document::RemoveHypothesis(int HypID) { - if (!myHypothesis.IsBound(HypID)) - Standard_OutOfRange::Raise("SMESHDS_Document::RemoveHypothesis"); - myMeshes.UnBind(HypID); + map::iterator it=myHypothesis.find(HypID); + if (it==myHypothesis.end()) + MESSAGE("SMESHDS_Document::RemoveHypothesis : ID not found"); + myHypothesis.erase(it); } //======================================================================= //function : NbMeshes -//purpose : +//purpose : //======================================================================= -Standard_Integer SMESHDS_Document::NbMeshes() +int SMESHDS_Document::NbMeshes() { - return myMeshes.Extent(); + return myMeshes.size(); } //======================================================================= //function : NbHypothesis -//purpose : +//purpose : //======================================================================= -Standard_Integer SMESHDS_Document::NbHypothesis() +int SMESHDS_Document::NbHypothesis() { - return myHypothesis.Extent(); + return myHypothesis.size(); } //======================================================================= //function : InitMeshesIterator -//purpose : +//purpose : //======================================================================= -void SMESHDS_Document::InitMeshesIterator() +void SMESHDS_Document::InitMeshesIterator() { - myMeshesIt.Initialize(myMeshes); + myMeshesIt=myMeshes.begin(); } + //======================================================================= //function : NextMesh -//purpose : +//purpose : //======================================================================= -void SMESHDS_Document::NextMesh() +SMESHDS_Mesh * SMESHDS_Document::NextMesh() { - myMeshesIt.Next(); + SMESHDS_Mesh * toReturn=(*myMeshesIt).second; + myMeshesIt++; + return toReturn; } + //======================================================================= //function : MoreMesh -//purpose : +//purpose : //======================================================================= -Standard_Boolean SMESHDS_Document::MoreMesh() +bool SMESHDS_Document::MoreMesh() { - return myMeshesIt.More(); -} -//======================================================================= -//function : CurrentMesh -//purpose : -//======================================================================= -Handle_SMESHDS_Mesh SMESHDS_Document::CurrentMesh() -{ - return myMeshesIt.Value(); + return myMeshesIt!=myMeshes.end(); } //======================================================================= //function : InitHypothesisIterator -//purpose : +//purpose : //======================================================================= -void SMESHDS_Document::InitHypothesisIterator() +void SMESHDS_Document::InitHypothesisIterator() { - myHypothesisIt.Initialize(myHypothesis); + myHypothesisIt=myHypothesis.begin(); } + //======================================================================= //function : NextMesh -//purpose : +//purpose : //======================================================================= -void SMESHDS_Document::NextHypothesis() +SMESHDS_Hypothesis * SMESHDS_Document::NextHypothesis() { - myHypothesisIt.Next(); + SMESHDS_Hypothesis * toReturn=(*myHypothesisIt).second; + myHypothesisIt++; + return toReturn; } + //======================================================================= //function : MoreMesh -//purpose : -//======================================================================= -Standard_Boolean SMESHDS_Document::MoreHypothesis() -{ - return myHypothesisIt.More(); -} -//======================================================================= -//function : CurrentMesh -//purpose : +//purpose : //======================================================================= -SMESHDS_PtrHypothesis SMESHDS_Document::CurrentHypothesis() +bool SMESHDS_Document::MoreHypothesis() { - return myHypothesisIt.Value(); + return myHypothesisIt!=myHypothesis.end(); } - -