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