Salome HOME
DCQ:prepare 2.0.0
[modules/smesh.git] / src / SMDS / SMDS_Tria3OfNodes.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 "SMDS_Tria3OfNodes.hxx"
23 #include "SMDS_IteratorOfElements.hxx"
24 #include "SMDS_MeshNode.hxx"
25 #include "utilities.h"
26
27 //=======================================================================
28 //function : NbEdges
29 //purpose  : 
30 //=======================================================================
31
32 int SMDS_Tria3OfNodes::NbEdges() const
33 {
34         return 3;
35 }
36
37 int SMDS_Tria3OfNodes::NbFaces() const
38 {
39         return 3;
40 }
41
42 int SMDS_Tria3OfNodes::NbNodes() const
43 {
44         return 3;
45 }
46 //=======================================================================
47 //function : Print
48 //purpose  : 
49 //=======================================================================
50
51 void SMDS_Tria3OfNodes::Print(ostream & OS) const
52 {
53         OS << "face <" << GetID() << " > : ";
54         int i;
55         for (i = 0; i < NbNodes() - 1; i++) OS << myNodes[i] << ",";
56         OS << myNodes[i] << ") " << endl;
57 }
58
59 class SMDS_Tria3OfNodes_MyIterator:public SMDS_ElemIterator
60 {
61   const SMDS_MeshNode * const* mySet;
62   int index;
63  public:
64   SMDS_Tria3OfNodes_MyIterator(const SMDS_MeshNode * const* s):
65     mySet(s),index(0) {}
66
67   bool more()
68   {
69     return index<3;
70   }
71
72   const SMDS_MeshElement* next()
73   {
74     index++;
75     return mySet[index-1];
76   }
77 };
78
79 SMDS_ElemIteratorPtr SMDS_Tria3OfNodes::
80         elementsIterator(SMDSAbs_ElementType type) const
81 {
82   switch(type)
83   {
84   case SMDSAbs_Face:
85     return SMDS_MeshElement::elementsIterator(SMDSAbs_Face);
86   case SMDSAbs_Node:
87     return SMDS_ElemIteratorPtr(new SMDS_Tria3OfNodes_MyIterator(myNodes));
88   case SMDSAbs_Edge:
89     MESSAGE("Error : edge iterator for SMDS_FaceOfNodes not implemented");
90     break;
91   default:
92     return SMDS_ElemIteratorPtr
93       (new SMDS_IteratorOfElements
94        (this,type,SMDS_ElemIteratorPtr(new SMDS_Tria3OfNodes_MyIterator(myNodes))));
95   }
96 }
97
98 SMDS_Tria3OfNodes::SMDS_Tria3OfNodes(const SMDS_MeshNode* node1,
99                                      const SMDS_MeshNode* node2,
100                                      const SMDS_MeshNode* node3)
101 {
102         myNodes[0]=node1;
103         myNodes[1]=node2;
104         myNodes[2]=node3;
105 }
106
107