Salome HOME
Merge branch merge_1_2_d
[modules/smesh.git] / src / SMDS / SMDS_FaceOfNodes.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_FaceOfNodes.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_FaceOfNodes::NbEdges() const
33 {
34         return NbNodes();
35 }
36
37 int SMDS_FaceOfNodes::NbFaces() const
38 {
39         return 1;
40 }
41
42 int SMDS_FaceOfNodes::NbNodes() const
43 {
44         return myNodes.size();
45 }
46 //=======================================================================
47 //function : Print
48 //purpose  : 
49 //=======================================================================
50
51 void SMDS_FaceOfNodes::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 SMDS_Iterator<const SMDS_MeshElement *> * SMDS_FaceOfNodes::
60         elementsIterator(SMDSAbs_ElementType type) const
61 {
62         class MyIterator:public SMDS_Iterator<const SMDS_MeshElement*>
63         {
64                 const vector<const SMDS_MeshNode*>& mySet;
65                 int index;
66           public:
67                 MyIterator(const vector<const SMDS_MeshNode*>& s):mySet(s),index(0)
68                 {}
69
70                 bool more()
71                 {
72                         return index<mySet.size();
73                 }
74
75                 const SMDS_MeshElement* next()
76                 {
77                         index++;
78                         return mySet[index-1];
79                 }       
80         };
81
82         switch(type)
83         {
84         case SMDSAbs_Face:return SMDS_MeshElement::elementsIterator(SMDSAbs_Face);
85         case SMDSAbs_Node:return new MyIterator(myNodes);
86         case SMDSAbs_Edge:
87                 MESSAGE("Error : edge iterator for SMDS_FaceOfNodes not implemented");
88                 break;
89         default:return new SMDS_IteratorOfElements(this,type,new MyIterator(myNodes));
90         }
91 }
92
93 SMDS_FaceOfNodes::SMDS_FaceOfNodes(SMDS_MeshNode* node1, SMDS_MeshNode* node2,
94         SMDS_MeshNode* node3)
95 {
96         myNodes.resize(3);
97         myNodes[0]=node1;
98         myNodes[1]=node2;
99         myNodes[2]=node3;
100 }
101
102 SMDS_FaceOfNodes::SMDS_FaceOfNodes(SMDS_MeshNode* node1, SMDS_MeshNode* node2,
103         SMDS_MeshNode* node3, SMDS_MeshNode* node4)
104 {
105         myNodes.resize(4);
106         myNodes[0]=node1;
107         myNodes[1]=node2;
108         myNodes[2]=node3;
109         myNodes[3]=node4;       
110 }
111
112 /*bool operator<(const SMDS_FaceOfNodes& f1, const SMDS_FaceOfNodes& f2)
113 {
114         set<SMDS_MeshNode> set1,set2;
115         SMDS_Iterator<const SMDS_MeshElement*> * it;
116         const SMDS_MeshNode * n;
117
118         it=f1.nodesIterator();
119
120         while(it->more())
121         {
122                 n=static_cast<const SMDS_MeshNode *>(it->next());
123                 set1.insert(*n);
124         }
125
126         delete it;
127         it=f2.nodesIterator();
128         
129         while(it->more())
130         {       
131                 n=static_cast<const SMDS_MeshNode *>(it->next());
132                 set2.insert(*n);
133         }
134
135         delete it;
136         return set1<set2;       
137
138 }*/
139