d0cb8fff85c5b674b111542c4775508c7aab7140
[occt.git] / src / MAT2d / MAT2d_Connexion.cxx
1 // Created on: 1993-10-11
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <gp_Pnt2d.hxx>
19 #include <gp_Vec2d.hxx>
20 #include <MAT2d_Connexion.hxx>
21 #include <Standard_Type.hxx>
22
23 IMPLEMENT_STANDARD_RTTIEXT(MAT2d_Connexion,Standard_Transient)
24
25 //=============================================================================
26 //function :
27 //purpose  :
28 //=============================================================================
29 MAT2d_Connexion::MAT2d_Connexion()
30 {
31 }
32
33 //=============================================================================
34 //function :
35 //purpose  :
36 //=============================================================================
37 MAT2d_Connexion::MAT2d_Connexion(const Standard_Integer LineA, 
38                                  const Standard_Integer LineB, 
39                                  const Standard_Integer ItemA, 
40                                  const Standard_Integer ItemB, 
41                                  const Standard_Real    Distance, 
42                                  const Standard_Real    ParameterOnA, 
43                                  const Standard_Real    ParameterOnB, 
44                                  const gp_Pnt2d&        PointA, 
45                                  const gp_Pnt2d&        PointB):
46        lineA(LineA), lineB(LineB),itemA(ItemA),itemB(ItemB), 
47        distance(Distance),
48        parameterOnA(ParameterOnA),parameterOnB(ParameterOnB),
49        pointA(PointA),pointB(PointB)
50 {
51 }
52
53 //=============================================================================
54 //function : IndexFirstLine
55 //purpose  :
56 //=============================================================================
57 Standard_Integer MAT2d_Connexion::IndexFirstLine() const
58 {
59   return lineA;
60 }
61
62 //=============================================================================
63 //function : IndexSecondLine
64 //purpose  :
65 //=============================================================================
66 Standard_Integer  MAT2d_Connexion::IndexSecondLine() const 
67 {
68   return lineB;
69 }
70
71 //=============================================================================
72 //function : IndexItemOnFirst
73 //purpose  :
74 //=============================================================================
75 Standard_Integer  MAT2d_Connexion::IndexItemOnFirst()const 
76 {
77   return itemA;
78 }
79
80 //=============================================================================
81 //function : IndexItemOnSecond
82 // purpose :
83 //=============================================================================
84 Standard_Integer  MAT2d_Connexion::IndexItemOnSecond() const
85 {
86   return itemB;
87 }
88
89 //=============================================================================
90 //function : ParameterOnFirst
91 //purpose  :
92 //=============================================================================
93 Standard_Real  MAT2d_Connexion::ParameterOnFirst() const
94 {
95   return parameterOnA;
96 }
97
98 //=============================================================================
99 //function : ParameterOnSecond
100 // purpose :
101 //=============================================================================
102 Standard_Real  MAT2d_Connexion::ParameterOnSecond() const
103 {
104   return parameterOnB;
105 }
106
107 //=============================================================================
108 //function : PointOnFirst
109 //purpose  :
110 //=============================================================================
111 gp_Pnt2d  MAT2d_Connexion::PointOnFirst() const
112 {
113   return pointA;
114 }
115
116 //=============================================================================
117 //function : PointOnSecond
118 //purpose  :
119 //=============================================================================
120 gp_Pnt2d  MAT2d_Connexion::PointOnSecond() const 
121 {
122   return pointB;
123 }
124
125 //=============================================================================
126 //function : Distance
127 //purpose  :
128 //=============================================================================
129 Standard_Real  MAT2d_Connexion::Distance() const
130 {
131   return distance;
132 }
133
134 //=============================================================================
135 //function : IndexFirstLine
136 //purpose  :
137 //=============================================================================
138 void  MAT2d_Connexion::IndexFirstLine(const Standard_Integer anIndex)
139 {
140   lineA = anIndex;
141 }
142
143 //=============================================================================
144 //function : IndexSecondLine
145 //purpose  :
146 //=============================================================================
147 void  MAT2d_Connexion::IndexSecondLine(const Standard_Integer anIndex)
148 {
149   lineB = anIndex;
150 }
151
152 //=============================================================================
153 //function : IndexItemOnFirst
154 //purpose  :
155 //=============================================================================
156 void  MAT2d_Connexion::IndexItemOnFirst(const Standard_Integer anIndex)
157 {
158   itemA = anIndex;
159 }
160
161 //=============================================================================
162 //function : IndexItemOnSecond
163 //purpose  :
164 //=============================================================================
165 void  MAT2d_Connexion::IndexItemOnSecond(const Standard_Integer anIndex)
166 {
167   itemB = anIndex;
168 }
169
170 //=============================================================================
171 //function : ParameterOnFirst
172 //purpose  :
173 //=============================================================================
174 void  MAT2d_Connexion::ParameterOnFirst(const Standard_Real aParameter)
175 {
176   parameterOnA = aParameter;
177 }
178
179 //=============================================================================
180 //function : ParameterOnSecond
181 //purpose  :
182 //=============================================================================
183 void  MAT2d_Connexion::ParameterOnSecond(const Standard_Real aParameter)
184 {
185   parameterOnB = aParameter;
186 }
187
188 //=============================================================================
189 //function : PointOnFirst
190 //purpose  :
191 //=============================================================================
192 void  MAT2d_Connexion::PointOnFirst(const gp_Pnt2d& aPoint)
193 {
194   pointA = aPoint;
195 }
196
197 //=============================================================================
198 //function : PointOnSecond
199 //purpose  :
200 //=============================================================================
201 void  MAT2d_Connexion::PointOnSecond(const gp_Pnt2d& aPoint)
202 {
203   pointB = aPoint;
204 }
205
206 //=============================================================================
207 //function : Distance
208 //purpose  :
209 //=============================================================================
210 void  MAT2d_Connexion::Distance(const Standard_Real d)
211 {
212   distance = d;
213 }
214
215 //=============================================================================
216 //function : Reverse
217 //purpose  :
218 //=============================================================================
219 Handle(MAT2d_Connexion) MAT2d_Connexion::Reverse() const
220 {
221   return new MAT2d_Connexion(lineB,lineA,itemB,itemA,distance,
222                              parameterOnB,parameterOnA,pointB,pointA);
223 }
224
225 //=============================================================================
226 //function : IsAfter
227 //purpose  :
228 //=============================================================================
229 Standard_Boolean MAT2d_Connexion::IsAfter(const Handle(MAT2d_Connexion)& C2,
230                                           const Standard_Real    Sense) const
231 {
232   if (lineA != C2->IndexFirstLine()) {
233     return Standard_False;
234   }
235   
236   if (itemA > C2->IndexItemOnFirst()) {
237     return Standard_True;
238   }
239   else if (itemA == C2->IndexItemOnFirst()){
240     if ( parameterOnA > C2->ParameterOnFirst()) {
241       return Standard_True;
242     }
243     else if ( parameterOnA == C2->ParameterOnFirst()) {
244       gp_Vec2d Vect1(C2->PointOnFirst(),C2->PointOnSecond());
245       gp_Vec2d Vect2(pointA,pointB);
246       if ((Vect1^Vect2)*Sense > 0) {
247         return Standard_True;
248       }
249     }
250   }
251   return Standard_False;
252 }
253
254 static void Indent(const Standard_Integer Offset) {
255   if (Offset > 0) {
256     for (Standard_Integer i = 0; i <Offset; i++) {std::cout <<" ";}
257   }
258 }
259
260 //=============================================================================
261 //function : Dump
262 //purpose  :
263 //=============================================================================
264 void MAT2d_Connexion::Dump (const Standard_Integer ,
265                             const Standard_Integer Offset) const
266 {
267   Standard_Integer MyOffset = Offset;
268   Indent (Offset);
269   std::cout<<"MAT2d_Connexion :"<<std::endl;
270   MyOffset++;
271   Indent (MyOffset);
272   std::cout <<"IndexFirstLine    :"<<lineA<<std::endl;
273   Indent (MyOffset);
274   std::cout <<"IndexSecondLine   :"<<lineB<<std::endl;
275   Indent (MyOffset);
276   std::cout <<"IndexItemOnFirst  :"<<itemA<<std::endl;
277   Indent (MyOffset);
278   std::cout <<"IndexItemOnSecond :"<<itemB<<std::endl;
279   Indent (MyOffset);
280   std::cout <<"ParameterOnFirst  :"<<parameterOnA<<std::endl;
281   Indent (MyOffset);
282   std::cout <<"ParameterOnSecond :"<<parameterOnB<<std::endl;
283   Indent (MyOffset);
284   std::cout <<"PointOnFirst      :"<<std::endl;
285   std::cout <<"  X = "<<pointA.X()<<std::endl;
286   std::cout <<"  Y = "<<pointA.Y()<<std::endl;
287   Indent (MyOffset);
288   std::cout <<"PointOnSecond     :"<<std::endl;
289   std::cout <<"  X = "<<pointB.X()<<std::endl;
290   std::cout <<"  Y = "<<pointB.Y()<<std::endl;
291   Indent (MyOffset);
292   std::cout <<"Distance          :"<<distance<<std::endl;
293 }