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