Salome HOME
New DS implementation
[modules/smesh.git] / src / SMDS / SMDS_VolumeOfNodes.cxx
1 //  SMESH SMDS : implementaion of Salome mesh data structure
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21
22 #include "utilities.h"
23 #include "SMDS_VolumeOfNodes.hxx"
24 #include "SMDS_MeshNode.hxx"
25
26 ///////////////////////////////////////////////////////////////////////////////
27 /// Create an hexahedron. node 1,2,3,4 and 5,6,7,8 are quadrangle and
28 /// 5,1 and 7,3 are an edges.
29 ///////////////////////////////////////////////////////////////////////////////
30 SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
31                 SMDS_MeshNode * node1,
32                 SMDS_MeshNode * node2,
33                 SMDS_MeshNode * node3,
34                 SMDS_MeshNode * node4,
35                 SMDS_MeshNode * node5,
36                 SMDS_MeshNode * node6,
37                 SMDS_MeshNode * node7,
38                 SMDS_MeshNode * node8)
39 {
40         myNodes[0]=node1;
41         myNodes[1]=node2;
42         myNodes[2]=node3;
43         myNodes[3]=node4;
44         myNodes[4]=node5;
45         myNodes[5]=node6;
46         myNodes[6]=node7;
47         myNodes[7]=node8;
48 }
49
50 //=======================================================================
51 //function : Print
52 //purpose  : 
53 //=======================================================================
54
55 void SMDS_VolumeOfNodes::Print(ostream & OS) const
56 {
57         OS << "volume <" << GetID() << "> : ";
58         int i;
59         for (i = 0; i < 7; ++i) OS << myNodes[i] << ",";
60         OS << myNodes[7]<< ") " << endl;
61 }
62
63 int SMDS_VolumeOfNodes::NbFaces() const
64 {
65         return 6;
66 }
67
68 int SMDS_VolumeOfNodes::NbNodes() const
69 {
70         return 8;
71 }
72
73 int SMDS_VolumeOfNodes::NbEdges() const
74 {
75         return 12;
76 }
77
78 SMDS_Iterator<const SMDS_MeshElement *> * SMDS_VolumeOfNodes::
79         elementsIterator(SMDSAbs_ElementType type) const
80 {
81         class MyIterator:public SMDS_Iterator<const SMDS_MeshElement*>
82         {
83                 const SMDS_MeshNode * const* mySet;
84                 int index;
85           public:
86                 MyIterator(const SMDS_MeshNode * const* s):mySet(s),index(0)
87                 {}
88
89                 bool more()
90                 {
91                         return index<8;
92                 }
93
94                 const SMDS_MeshElement* next()
95                 {
96                         index++;
97                         return mySet[index-1];
98                 }       
99         };
100
101         switch(type)
102         {
103         case SMDSAbs_Volume:return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume);
104         case SMDSAbs_Node:return new MyIterator(myNodes);
105         default: MESSAGE("ERROR : Iterator not implemented");
106         }
107 }
108
109 SMDSAbs_ElementType SMDS_VolumeOfNodes::GetType() const
110 {
111         return SMDSAbs_Volume;
112 }