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