Back to index

salome-smesh  6.5.0
SMESHDS_GroupOnGeom.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SMESH SMESHDS : idl implementation based on 'SMESH' unit's classes
00024 //  File   : SMESHDS_GroupOnGeom.cxx
00025 //  Module : SMESH
00026 //
00027 #include "SMESHDS_GroupOnGeom.hxx"
00028 #include "SMESHDS_Mesh.hxx"
00029 #include "utilities.h"
00030 
00031 using namespace std;
00032 
00033 //=============================================================================
00037 //=============================================================================
00038 
00039 SMESHDS_GroupOnGeom::SMESHDS_GroupOnGeom (const int                 theID,
00040                                           const SMESHDS_Mesh*       theMesh,
00041                                           const SMDSAbs_ElementType theType,
00042                                           const TopoDS_Shape&       theShape)
00043      : SMESHDS_GroupBase(theID,theMesh,theType)
00044 {
00045   SetShape( theShape );
00046 }
00047 
00048 void SMESHDS_GroupOnGeom::SetShape( const TopoDS_Shape& theShape)
00049 {
00050   SMESHDS_Mesh* aMesh = const_cast<SMESHDS_Mesh*>( GetMesh() );
00051   mySubMesh = aMesh->MeshElements( aMesh->AddCompoundSubmesh( theShape ));
00052   myShape   = theShape;
00053 }
00054 
00055 // =====================
00056 // class MyGroupIterator
00057 // =====================
00058 
00059 class MyIterator: public SMDS_ElemIterator
00060 {
00061   SMDSAbs_ElementType     myType;
00062   SMDS_ElemIteratorPtr    myElemIt;
00063   SMDS_NodeIteratorPtr    myNodeIt;
00064   const SMDS_MeshElement* myElem;
00065  public:
00066   MyIterator(SMDSAbs_ElementType type, const SMESHDS_SubMesh* subMesh)
00067     : myType(type), myElem(0)
00068   {
00069     if ( subMesh ) {
00070       if ( myType == SMDSAbs_Node )
00071         myNodeIt = subMesh->GetNodes();
00072       else {
00073         myElemIt = subMesh->GetElements();
00074         next();
00075       }
00076     }
00077   }
00078   bool more()
00079   {
00080     if ( myType == SMDSAbs_Node && myNodeIt )
00081       return myNodeIt->more();
00082     return ( myElem != 0 );
00083   }
00084   const SMDS_MeshElement* next()
00085   {
00086     if ( myType == SMDSAbs_Node && myNodeIt )
00087       return myNodeIt->next();
00088     const SMDS_MeshElement* res = myElem;
00089     myElem = 0;
00090     while ( myElemIt && myElemIt->more() ) {
00091       myElem = myElemIt->next();
00092       if ( myElem && myElem->GetType() == myType )
00093         break;
00094       else
00095         myElem = 0;
00096     }
00097     return res;
00098   }
00099 };
00100 
00101 //=======================================================================
00102 //function : GetElements
00103 //purpose  : 
00104 //=======================================================================
00105 
00106 SMDS_ElemIteratorPtr SMESHDS_GroupOnGeom::GetElements() const
00107 {
00108   return SMDS_ElemIteratorPtr( new MyIterator ( GetType(), mySubMesh ));
00109 }
00110 
00111 //=======================================================================
00112 //function : Contains
00113 //purpose  : 
00114 //=======================================================================
00115 
00116 bool SMESHDS_GroupOnGeom::Contains (const int theID)
00117 {
00118   return mySubMesh->Contains( findInMesh( theID ));
00119 }
00120 
00121 //=======================================================================
00122 //function : Contains
00123 //purpose  : 
00124 //=======================================================================
00125 
00126 bool SMESHDS_GroupOnGeom::Contains (const SMDS_MeshElement* elem)
00127 {
00128   return mySubMesh->Contains( elem );
00129 }
00130 
00131 //================================================================================
00135 //================================================================================
00136 
00137 int SMESHDS_GroupOnGeom::GetTic() const
00138 {
00139   return GetMesh()->GetMTime();
00140 }
00141