Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/smesh.git] / src / SMDS / SMDS_QuadraticEdge.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  SMESH SMDS : implementaion of Salome mesh data structure
23 // File:      SMDS_QuadraticEdge.cxx
24 // Created:   16.01.06 16:25:42
25 // Author:    Sergey KUUL
26 //
27 #include "SMDS_QuadraticEdge.hxx"
28
29 #include "SMDS_SetIterator.hxx"
30 #include "SMDS_IteratorOfElements.hxx"
31 #include "SMDS_MeshNode.hxx"
32
33 using namespace std;
34
35 //=======================================================================
36 //function : SMDS_QuadraticEdge
37 //purpose  : 
38 //=======================================================================
39
40 SMDS_QuadraticEdge::SMDS_QuadraticEdge(const SMDS_MeshNode * node1,
41                                        const SMDS_MeshNode * node2,
42                                        const SMDS_MeshNode * node12)
43      :SMDS_MeshEdge(node1,node2)
44 {       
45   myNodes[2]=node12;
46 }
47
48
49 //=======================================================================
50 //function : Print
51 //purpose  : 
52 //=======================================================================
53
54 void SMDS_QuadraticEdge::Print(ostream & OS) const
55 {
56   OS << "quadratic edge <" << GetID() << "> : ( first-" << myNodes[0]
57      << " , last-" << myNodes[1] << " , medium-" << myNodes[2] << ") " << endl;
58 }
59
60
61 //=======================================================================
62 //function : NbNodes
63 //purpose  : 
64 //=======================================================================
65
66 int SMDS_QuadraticEdge::NbNodes() const
67 {
68   return 3;
69 }
70
71 //=======================================================================
72 //function : ChangeNodes
73 //purpose  : 
74 //=======================================================================
75
76 bool SMDS_QuadraticEdge::ChangeNodes(const SMDS_MeshNode * node1,
77                                      const SMDS_MeshNode * node2,
78                                      const SMDS_MeshNode * node12)
79 {
80   myNodes[0]=node1;
81   myNodes[1]=node2;
82   myNodes[2]=node12;
83   return true;
84 }
85
86 //=======================================================================
87 //function : IsMediumNode
88 //purpose  : 
89 //=======================================================================
90
91 bool SMDS_QuadraticEdge::IsMediumNode(const SMDS_MeshNode * node) const
92 {
93   return (myNodes[2]==node);
94 }
95
96 namespace
97 {
98   //=======================================================================
99   //class : _MyInterlacedNodeIterator
100   //purpose  : 
101   //=======================================================================
102
103   class _MyInterlacedNodeIterator: public SMDS_NodeArrayIterator
104   {
105     const SMDS_MeshNode * myNodes[3];
106   public:
107     _MyInterlacedNodeIterator(const SMDS_MeshNode * const * nodes):
108       SMDS_NodeArrayIterator( myNodes, & myNodes[3] )
109     {
110       myNodes[0] = nodes[0];
111       myNodes[1] = nodes[2];
112       myNodes[2] = nodes[1];
113     }
114   };
115
116   //=======================================================================
117   //class : _MyInterlacedNodeElemIterator
118   //purpose  : 
119   //=======================================================================
120
121   class _MyInterlacedNodeElemIterator : public SMDS_ElemIterator
122   {
123     SMDS_NodeIteratorPtr myItr;
124   public:
125     _MyInterlacedNodeElemIterator(SMDS_NodeIteratorPtr interlacedNodeItr):
126       myItr( interlacedNodeItr ) {}
127     bool more()                    { return myItr->more(); }
128     const SMDS_MeshElement* next() { return myItr->next(); }
129   };
130
131   //=======================================================================
132   //class : _MyNodeIterator
133   //purpose  : 
134   //=======================================================================
135
136   class _MyNodeIterator:public SMDS_NodeArrayElemIterator
137   {
138   public:
139     _MyNodeIterator(const SMDS_MeshNode * const * nodes):
140       SMDS_NodeArrayElemIterator( nodes, & nodes[3] ) {}
141   };
142 }
143
144 //=======================================================================
145 //function : interlacedNodesIterator
146 //purpose  : 
147 //=======================================================================
148
149 SMDS_NodeIteratorPtr SMDS_QuadraticEdge::interlacedNodesIterator() const
150 {
151   return SMDS_NodeIteratorPtr (new _MyInterlacedNodeIterator (myNodes));
152 }
153
154
155 //=======================================================================
156 //function : interlacedNodesElemIterator
157 //purpose  : 
158 //=======================================================================
159
160 SMDS_ElemIteratorPtr SMDS_QuadraticEdge::interlacedNodesElemIterator() const
161 {
162   return SMDS_ElemIteratorPtr
163     (new _MyInterlacedNodeElemIterator ( interlacedNodesIterator() ));
164 }
165
166 //=======================================================================
167 //function : elementsIterator
168 //purpose  : 
169 //=======================================================================
170
171 SMDS_ElemIteratorPtr SMDS_QuadraticEdge::elementsIterator(SMDSAbs_ElementType type) const
172 {
173   switch(type)
174   {
175   case SMDSAbs_Edge:
176     return SMDS_MeshElement::elementsIterator(SMDSAbs_Edge); 
177   case SMDSAbs_Node:
178     return SMDS_ElemIteratorPtr(new _MyNodeIterator(myNodes));
179   default:
180     return SMDS_ElemIteratorPtr
181       (new SMDS_IteratorOfElements
182        (this,type, SMDS_ElemIteratorPtr(new _MyNodeIterator(myNodes))));
183   }
184 }
185