Salome HOME
correct previous integration (Porting to Python 2.6)
[modules/smesh.git] / src / SMDS / SMDS_VolumeOfFaces.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  SMESH SMDS : implementaion of Salome mesh data structure
23 //  File   : SMDS_VolumeOfFaces.cxx
24 //  Author : Jean-Michel BOULCOURT
25 //  Module : SMESH
26 //
27 #ifdef _MSC_VER
28 #pragma warning(disable:4786)
29 #endif
30
31 #include "SMDS_VolumeOfFaces.hxx"
32 #include "SMDS_IteratorOfElements.hxx"
33
34 using namespace std;
35
36 //=======================================================================
37 //function : Print
38 //purpose  : 
39 //=======================================================================
40
41 void SMDS_VolumeOfFaces::Print(ostream & OS) const
42 {
43         OS << "volume <" << GetID() << "> : ";
44         int i;
45         for (i = 0; i < NbFaces()-1; ++i) OS << myFaces[i] << ",";
46         OS << myFaces[i]<< ") " << endl;
47 }
48
49
50 int SMDS_VolumeOfFaces::NbFaces() const
51 {
52         return myNbFaces;
53 }
54
55 class SMDS_VolumeOfFaces_MyIterator:public SMDS_ElemIterator
56 {
57   const SMDS_MeshFace* const *mySet;
58   int myLength;
59   int index;
60  public:
61   SMDS_VolumeOfFaces_MyIterator(const SMDS_MeshFace* const *s, int l):
62     mySet(s),myLength(l),index(0) {}
63
64   bool more()
65   {
66     return index<myLength;
67   }
68
69   const SMDS_MeshElement* next()
70   {
71     index++;
72     return mySet[index-1];
73   }
74 };
75
76 SMDS_ElemIteratorPtr SMDS_VolumeOfFaces::
77         elementsIterator(SMDSAbs_ElementType type) const
78 {
79   switch(type)
80   {
81   case SMDSAbs_Volume:
82     return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume);
83   case SMDSAbs_Face:
84     return SMDS_ElemIteratorPtr(new SMDS_VolumeOfFaces_MyIterator(myFaces,myNbFaces));
85   default:
86     return SMDS_ElemIteratorPtr
87       (new SMDS_IteratorOfElements
88        (this,type,SMDS_ElemIteratorPtr
89         (new SMDS_VolumeOfFaces_MyIterator(myFaces,myNbFaces))));
90   }
91 }
92
93 SMDS_VolumeOfFaces::SMDS_VolumeOfFaces(const SMDS_MeshFace * face1,
94                                        const SMDS_MeshFace * face2,
95                                        const SMDS_MeshFace * face3,
96                                        const SMDS_MeshFace * face4)
97 {
98         myNbFaces = 4;
99         myFaces[0]=face1;
100         myFaces[1]=face2;
101         myFaces[2]=face3;
102         myFaces[3]=face4;
103         myFaces[4]=0;
104         myFaces[5]=0;
105 }
106
107 SMDS_VolumeOfFaces::SMDS_VolumeOfFaces(const SMDS_MeshFace * face1,
108                                        const SMDS_MeshFace * face2,
109                                        const SMDS_MeshFace * face3,
110                                        const SMDS_MeshFace * face4,
111                                        const SMDS_MeshFace * face5)
112 {
113         myNbFaces = 5;
114         myFaces[0]=face1;
115         myFaces[1]=face2;
116         myFaces[2]=face3;
117         myFaces[3]=face4;
118         myFaces[4]=face5;
119         myFaces[5]=0;
120 }
121
122 SMDS_VolumeOfFaces::SMDS_VolumeOfFaces(const SMDS_MeshFace * face1,
123                                        const SMDS_MeshFace * face2,
124                                        const SMDS_MeshFace * face3,
125                                        const SMDS_MeshFace * face4,
126                                        const SMDS_MeshFace * face5,
127                                        const SMDS_MeshFace * face6)
128 {
129         myNbFaces = 6;
130         myFaces[0]=face1;
131         myFaces[1]=face2;
132         myFaces[2]=face3;
133         myFaces[3]=face4;
134         myFaces[4]=face5;
135         myFaces[5]=face6;
136 }
137
138 SMDSAbs_EntityType SMDS_VolumeOfFaces::GetEntityType() const
139 {
140   SMDSAbs_EntityType aType = SMDSEntity_Tetra;
141   switch(myNbFaces)
142   {
143   case 4: aType = SMDSEntity_Tetra;   break;
144   case 5: aType = SMDSEntity_Pyramid; break;
145   case 6: aType = SMDSEntity_Penta;   break;
146   case 8:
147   default: aType = SMDSEntity_Hexa;    break;
148   }
149   return aType;
150 }