Salome HOME
Merge branch V7_3_1_BR
[modules/smesh.git] / src / SMDS / SMDS_QuadraticEdge.cxx
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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 #include "utilities.h"
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_LinearEdge(node1,node2)
46 {
47   //MESSAGE("******************************************************* SMDS_QuadraticEdge");
48   myNodes[2]=node12;
49 }
50
51
52 //=======================================================================
53 //function : Print
54 //purpose  : 
55 //=======================================================================
56
57 void SMDS_QuadraticEdge::Print(ostream & OS) const
58 {
59   OS << "quadratic edge <" << GetID() << "> : ( first-" << myNodes[0]
60      << " , last-" << myNodes[1] << " , medium-" << myNodes[2] << ") " << endl;
61 }
62
63
64 //=======================================================================
65 //function : NbNodes
66 //purpose  : 
67 //=======================================================================
68
69 int SMDS_QuadraticEdge::NbNodes() const
70 {
71   return 3;
72 }
73
74 //=======================================================================
75 //function : ChangeNodes
76 //purpose  : 
77 //=======================================================================
78
79 bool SMDS_QuadraticEdge::ChangeNodes(const SMDS_MeshNode * node1,
80                                      const SMDS_MeshNode * node2,
81                                      const SMDS_MeshNode * node12)
82 {
83   myNodes[0]=node1;
84   myNodes[1]=node2;
85   myNodes[2]=node12;
86   return true;
87 }
88
89 //=======================================================================
90 //function : IsMediumNode
91 //purpose  : 
92 //=======================================================================
93
94 bool SMDS_QuadraticEdge::IsMediumNode(const SMDS_MeshNode * node) const
95 {
96   return (myNodes[2]==node);
97 }
98
99 namespace
100 {
101   //=======================================================================
102   //class : _MyInterlacedNodeIterator
103   //purpose  : 
104   //=======================================================================
105
106   class _MyInterlacedNodeIterator: public SMDS_NodeArrayIterator
107   {
108     const SMDS_MeshNode * myNodes[3];
109   public:
110     _MyInterlacedNodeIterator(const SMDS_MeshNode * const * nodes):
111       SMDS_NodeArrayIterator( myNodes, & myNodes[3] )
112     {
113       myNodes[0] = nodes[0];
114       myNodes[1] = nodes[2];
115       myNodes[2] = nodes[1];
116     }
117   };
118
119   //=======================================================================
120   //class : _MyNodeIterator
121   //purpose  : 
122   //=======================================================================
123
124   class _MyNodeIterator:public SMDS_NodeArrayElemIterator
125   {
126   public:
127     _MyNodeIterator(const SMDS_MeshNode * const * nodes):
128       SMDS_NodeArrayElemIterator( nodes, & nodes[3] ) {}
129   };
130 }
131
132 //=======================================================================
133 //function : interlacedNodesIterator
134 //purpose  : 
135 //=======================================================================
136
137 SMDS_NodeIteratorPtr SMDS_QuadraticEdge::interlacedNodesIterator() const
138 {
139   return SMDS_NodeIteratorPtr (new _MyInterlacedNodeIterator (myNodes));
140 }
141
142 //=======================================================================
143 //function : elementsIterator
144 //purpose  : 
145 //=======================================================================
146
147 SMDS_ElemIteratorPtr SMDS_QuadraticEdge::elementsIterator(SMDSAbs_ElementType type) const
148 {
149   switch(type)
150   {
151   case SMDSAbs_Edge:
152     return SMDS_MeshElement::elementsIterator(SMDSAbs_Edge); 
153   case SMDSAbs_Node:
154     return SMDS_ElemIteratorPtr(new _MyNodeIterator(myNodes));
155   default:
156     return SMDS_ElemIteratorPtr
157       (new SMDS_IteratorOfElements
158        (this,type, SMDS_ElemIteratorPtr(new _MyNodeIterator(myNodes))));
159   }
160 }