Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/smesh.git] / src / SMDS / SMDS_FaceOfEdges.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_FaceOfEdges.hxx"
23 #include "SMDS_IteratorOfElements.hxx"
24 #include "SMDS_MeshNode.hxx"
25
26 using namespace std;
27
28 //=======================================================================
29 //function : NbEdges
30 //purpose  : 
31 //=======================================================================
32
33 int SMDS_FaceOfEdges::NbEdges() const
34 {
35         return myEdges.size();
36 }
37
38 int SMDS_FaceOfEdges::NbFaces() const
39 {
40         return 1;
41 }
42 //=======================================================================
43 //function : Print
44 //purpose  : 
45 //=======================================================================
46
47 void SMDS_FaceOfEdges::Print(ostream & OS) const
48 {
49         OS << "face <" << GetID() << " > : ";
50         int i;
51         for (i = 0; i < NbEdges() - 1; i++) OS << myEdges[i] << ",";
52         OS << myEdges[i] << ") " << endl;
53 }
54
55 SMDSAbs_ElementType SMDS_FaceOfEdges::GetType() const
56 {
57         return SMDSAbs_Face;
58 }
59
60 class SMDS_FaceOfEdges_MyIterator:public SMDS_ElemIterator
61 {
62   const vector<const SMDS_MeshEdge*>& mySet;
63   int index;
64  public:
65   SMDS_FaceOfEdges_MyIterator(const vector<const SMDS_MeshEdge*>& s):
66     mySet(s),index(0) {}
67
68   bool more()
69   {
70     return index<mySet.size();
71   }
72
73   const SMDS_MeshElement* next()
74   {
75     index++;
76     return mySet[index-1];
77   }     
78 };
79 SMDS_ElemIteratorPtr SMDS_FaceOfEdges::
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_Edge:
87           return SMDS_ElemIteratorPtr(new SMDS_FaceOfEdges_MyIterator(myEdges));
88         default:
89           return SMDS_ElemIteratorPtr
90             (new SMDS_IteratorOfElements
91              (this,type, SMDS_ElemIteratorPtr(new SMDS_FaceOfEdges_MyIterator(myEdges))));
92         }
93 }
94
95 SMDS_FaceOfEdges::SMDS_FaceOfEdges(const SMDS_MeshEdge* edge1,
96                                    const SMDS_MeshEdge* edge2,
97                                    const SMDS_MeshEdge* edge3)
98 {
99         myEdges.resize(3);
100         myEdges[0]=edge1;
101         myEdges[1]=edge2;
102         myEdges[2]=edge3;
103 }
104
105 SMDS_FaceOfEdges::SMDS_FaceOfEdges(const SMDS_MeshEdge* edge1,
106                                    const SMDS_MeshEdge* edge2,
107                                    const SMDS_MeshEdge* edge3,
108                                    const SMDS_MeshEdge* edge4)
109 {
110         myEdges.resize(4);
111         myEdges[0]=edge1;
112         myEdges[1]=edge2;
113         myEdges[2]=edge3;
114         myEdges[3]=edge4;       
115 }
116
117 /*bool operator<(const SMDS_FaceOfEdges& f1, const SMDS_FaceOfEdges& f2)
118 {
119         set<SMDS_MeshNode> set1,set2;
120         SMDS_ElemIteratorPtr it;
121         const SMDS_MeshNode * n;
122
123         it=f1.nodesIterator();
124
125         while(it->more())
126         {
127                 n=static_cast<const SMDS_MeshNode *>(it->next());
128                 set1.insert(*n);
129         }
130
131         delete it;
132         it=f2.nodesIterator();
133         
134         while(it->more())
135         {       
136                 n=static_cast<const SMDS_MeshNode *>(it->next());
137                 set2.insert(*n);
138         }
139
140         delete it;
141         return set1<set2;       
142
143 }*/
144