0022922: Clean up warnings on uninitialized / unused variables
[occt.git] / src / MAT2d / MAT2d_Tool2d.cxx
CommitLineData
7fd59977 1// File: MAT2d_Tool2d.cxx
2// Created: Mon Jul 12 18:10:23 1993
3// Author: Yves FRICAUD
4// <yfr@phylox>
5
6
7#define Debug(expr) cout<<" MAT2d_Tool2d.cxx : expr :"<<expr<<endl;
8
9#ifdef DRAW
10#include <DBRep.hxx>
11#include <DrawTrSurf.hxx>
12#include <stdio.h>
13#endif
14
15#ifdef DRAW
16#include <Draw_Appli.hxx>
17#include <DrawTrSurf_Curve2d.hxx>
18#include <GCE2d_MakeSegment.hxx>
19#include <DrawTrSurf.hxx>
20#endif
21
22#include <MAT2d_Tool2d.ixx>
23#include <MAT2d_MiniPath.hxx>
24#include <MAT2d_Connexion.hxx>
25#include <MAT2d_SequenceOfSequenceOfGeometry.hxx>
26#include <MAT_Edge.hxx>
27#include <Bisector_Curve.hxx>
28#include <Bisector_BisecAna.hxx>
29#include <Bisector_BisecCC.hxx>
30#include <Bisector_Bisec.hxx>
31#include <Bisector_Inter.hxx>
32#include <IntRes2d_Domain.hxx>
33#include <Extrema_ExtPC2d.hxx>
34#include <Geom2dInt_GInter.hxx>
35#include <IntRes2d_IntersectionPoint.hxx>
36#include <IntRes2d_IntersectionSegment.hxx>
37#include <Geom2d_Geometry.hxx>
38#include <Geom2d_Point.hxx>
39#include <Geom2d_Line.hxx>
40#include <Geom2d_Circle.hxx>
41#include <Geom2d_Curve.hxx>
42#include <Geom2d_Parabola.hxx>
43#include <Geom2d_Hyperbola.hxx>
44#include <Geom2d_Ellipse.hxx>
45#include <Geom2d_CartesianPoint.hxx>
46#include <Geom2d_TrimmedCurve.hxx>
47#include <Geom2dAdaptor_Curve.hxx>
48#include <gp_Lin2d.hxx>
49#include <gp_Hypr2d.hxx>
50#include <gp_Parab2d.hxx>
51#include <gp_Elips2d.hxx>
52#include <gp_Circ2d.hxx>
53#include <gp_Vec2d.hxx>
54#include <TColStd_Array1OfReal.hxx>
55#include <ElCLib.hxx>
56#include <StdFail_NotDone.hxx>
57#include <Standard_NotImplemented.hxx>
58#include <Precision.hxx>
59
60#ifdef DRAW
61 static Handle(DrawTrSurf_Curve2d) draw;
62#endif
63#ifdef DEB
64 static void MAT2d_DrawCurve(const Handle(Geom2d_Curve)& aCurve,
65 const Standard_Integer Indice);
66 static Standard_Boolean Store = Standard_False;
67#endif
68
69//=====================================================================
70// static functions
71//=====================================================================
72static IntRes2d_Domain Domain
73 (const Handle(Geom2d_TrimmedCurve)& Bisector1,
74 const Standard_Real Tolerance);
75
76static Handle(Standard_Type) Type (const Handle(Geom2d_Geometry)& acurve);
77
78static Standard_Boolean AreNeighbours(const Standard_Integer IEdge1,
79 const Standard_Integer IEdge2,
80 const Standard_Integer NbEdge);
81
82static void SetTrim(Bisector_Bisec& Bis , Handle(Geom2d_Curve)& Line1);
83
84static Standard_Real MAT2d_TOLCONF = 1.e-7;
85
86//============================================================================
87//function :
88//purpose :
89//============================================================================
90MAT2d_Tool2d::MAT2d_Tool2d()
91{
92 theDirection = 1.;
93 theNumberOfBisectors = 0;
94 theNumberOfVecs = 0;
95 theNumberOfPnts = 0;
96}
97
98//=============================================================================
99//function : InitItems
100//purpose :
101//=============================================================================
102void MAT2d_Tool2d::InitItems(const Handle(MAT2d_Circuit)& EquiCircuit)
103{
104 theGeomBisectors.Clear();
105 theGeomPnts.Clear();
106 theGeomVecs.Clear();
107 theLinesLength.Clear();
108 theNumberOfBisectors = 0;
109 theNumberOfVecs = 0;
110 theNumberOfPnts = 0;
111
112 theCircuit = EquiCircuit;
113}
114
115//=============================================================================
116//function : Sense
117//purpose :
118//=============================================================================
119void MAT2d_Tool2d::Sense(const MAT_Side aside)
120{
121 if(aside == MAT_Left) theDirection = 1.;
122 else theDirection = -1.;
123}
124
125//=============================================================================
126//function : NumberOfItems
127//purpose :
128//=============================================================================
129Standard_Integer MAT2d_Tool2d::NumberOfItems() const
130{
131 return theCircuit->NumberOfItems();
132}
133
134//=============================================================================
135//function : ToleranceOfConfusion
136//purpose :
137//=============================================================================
138Standard_Real MAT2d_Tool2d::ToleranceOfConfusion() const
139{
140 return 2*MAT2d_TOLCONF;
141}
142
143//=============================================================================
144//function : FirstPoint
145//purpose :
146//=============================================================================
147Standard_Integer MAT2d_Tool2d::FirstPoint(const Standard_Integer anitem,
148 Standard_Real& dist )
149{
150 Handle(Geom2d_Curve) curve;
151 Handle(Geom2d_Point) point;
152 theNumberOfPnts++;
153
154 if (theCircuit->ConnexionOn(anitem)){
155 gp_Pnt2d P1 = theCircuit->Connexion(anitem)->PointOnFirst();
156 gp_Pnt2d P2 = theCircuit->Connexion(anitem)->PointOnSecond();
157 theGeomPnts.Bind(theNumberOfPnts,gp_Pnt2d((P1.X() + P2.X())*0.5,
158 (P1.Y() + P2.Y())*0.5));
159 dist = P1.Distance(P2)*0.5;
160 return theNumberOfPnts;
161 }
162
163 Handle(Standard_Type) type;
164 type = theCircuit->Value(anitem)->DynamicType();
165 dist = 0.;
166
167 if ( type != STANDARD_TYPE(Geom2d_CartesianPoint)){
168 curve = Handle(Geom2d_Curve)::DownCast(theCircuit->Value(anitem));
169 theGeomPnts.Bind(theNumberOfPnts,curve->Value(curve->FirstParameter()));
170 }
171 else{
172 point = Handle(Geom2d_Point)::DownCast(theCircuit->Value(anitem));
173 theGeomPnts.Bind(theNumberOfPnts,point->Pnt2d());
174 }
175 return theNumberOfPnts;
176}
177
178//=============================================================================
179//function : TangentBefore
180//purpose :
181//=============================================================================
182Standard_Integer MAT2d_Tool2d::TangentBefore(const Standard_Integer anitem)
183{
184 Standard_Integer item;
185 Handle(Geom2d_Curve) curve;
186 theNumberOfVecs++;
187
188 item = (anitem == theCircuit->NumberOfItems()) ? 1 : (anitem + 1);
189 if (theCircuit->ConnexionOn(item)){
190 Standard_Real x1,y1,x2,y2;
191 theCircuit->Connexion(item)->PointOnFirst().Coord(x1,y1);
192 theCircuit->Connexion(item)->PointOnSecond().Coord(x2,y2);
193 theGeomVecs.Bind(theNumberOfVecs,gp_Vec2d((x2-x1),(y2-y1)));
194 return theNumberOfVecs;
195 }
196
197 Handle(Standard_Type) type;
198 type = theCircuit->Value(anitem)->DynamicType();
199 if ( type != STANDARD_TYPE(Geom2d_CartesianPoint)){
200 curve = Handle(Geom2d_Curve)::DownCast(theCircuit->Value(anitem));
201 theGeomVecs.Bind(theNumberOfVecs,curve->DN(curve->LastParameter(),1));
202 }
203 else {
204 curve = Handle(Geom2d_Curve)::DownCast(theCircuit->Value(item));
205 theGeomVecs.Bind(theNumberOfVecs,curve->DN(curve->FirstParameter(),1));
206 }
207
208 return theNumberOfVecs;
209}
210
211//=============================================================================
212//function : TangentAfter
213//purpose :
214//=============================================================================
215Standard_Integer MAT2d_Tool2d::TangentAfter(const Standard_Integer anitem)
216{
217 Standard_Integer item;
218 Handle(Geom2d_Curve) curve;
219 gp_Vec2d thevector;
220 theNumberOfVecs++;
221
222 if (theCircuit->ConnexionOn(anitem)){
223 Standard_Real x1,y1,x2,y2;
224 theCircuit->Connexion(anitem)->PointOnFirst().Coord(x1,y1);
225 theCircuit->Connexion(anitem)->PointOnSecond().Coord(x2,y2);
226 theGeomVecs.Bind(theNumberOfVecs,gp_Vec2d((x1-x2),(y1-y2)));
227 return theNumberOfVecs;
228 }
229
230 Handle(Standard_Type) type;
231 type = theCircuit->Value(anitem)->DynamicType();
232 if ( type != STANDARD_TYPE(Geom2d_CartesianPoint)){
233 curve = Handle(Geom2d_Curve)::DownCast(theCircuit->Value(anitem));
234 thevector = curve->DN(curve->FirstParameter(),1);
235 }
236 else {
237 item = (anitem == 1) ? theCircuit->NumberOfItems() : (anitem - 1);
238 curve = Handle(Geom2d_Curve)::DownCast(theCircuit->Value(item));
239 thevector = curve->DN(curve->LastParameter(),1);
240 }
241 theGeomVecs.Bind(theNumberOfVecs,thevector.Reversed());
242 return theNumberOfVecs;
243}
244
245//=============================================================================
246//function : Tangent
247//purpose :
248//=============================================================================
249Standard_Integer MAT2d_Tool2d::Tangent(const Standard_Integer bisector)
250{
251 theNumberOfVecs++;
252 theGeomVecs.Bind(theNumberOfVecs,GeomBis(bisector).Value()
253 ->DN(GeomBis(bisector).Value()
254 ->LastParameter(),1));
255 return theNumberOfVecs;
256}
257
258//=============================================================================
259//function : CreateBisector
260//purpose :
261//=============================================================================
262void MAT2d_Tool2d::CreateBisector(const Handle(MAT_Bisector)& abisector)
263{
264 Handle(Geom2d_Point) point1,point2;
265 Handle(Geom2d_Geometry) elt1,elt2;
266 Bisector_Bisec bisector;
267 Standard_Real tolerance = MAT2d_TOLCONF ;
268
269 Standard_Integer edge1number = abisector->FirstEdge()->EdgeNumber();
270 Standard_Integer edge2number = abisector->SecondEdge()->EdgeNumber();
271 Standard_Boolean ontheline = AreNeighbours(edge1number,
272 edge2number,
273 NumberOfItems());
274 Standard_Boolean InitialNeighbour = ontheline;
275
276 if(theCircuit->ConnexionOn(edge2number)) ontheline = Standard_False;
277
278 elt1 = theCircuit->Value(edge1number);
279 elt2 = theCircuit->Value(edge2number);
280
281 Handle(Standard_Type) type1;
282 type1 = theCircuit->Value(edge1number)->DynamicType();
283 Handle(Standard_Type) type2;
284 type2 = theCircuit->Value(edge2number)->DynamicType();
285 Handle(Geom2d_Curve) item1;
286 Handle(Geom2d_Curve) item2;
287
288 if ( type1 != STANDARD_TYPE(Geom2d_CartesianPoint)){
289 item1 = Handle(Geom2d_Curve)::DownCast(elt1);
290 }
291
292 if ( type2 != STANDARD_TYPE(Geom2d_CartesianPoint)){
293 item2 = Handle(Geom2d_Curve)::DownCast(elt2);
294 }
295
296#ifdef DEB
297 Standard_Boolean Affich = Standard_False;
298 if (Affich) {
299 cout<<endl;
300 cout<<"BISECTOR number : "<<theNumberOfBisectors+1<<endl;
301 cout<<" Item 1 : "<<endl;
302 cout<<edge1number<<endl;
303 cout<<endl;
304// elt1->Dump(1,1);
305 cout<<endl;
306 cout<<" Item 2 : "<<endl;
307 cout<<edge2number<<endl;
308 cout<<endl;
309// elt2->Dump(1,1);
310 cout<<endl;
311 }
312#endif
313
314 if(type1 != STANDARD_TYPE(Geom2d_CartesianPoint) &&
315 type2 != STANDARD_TYPE(Geom2d_CartesianPoint)) {
316 bisector.Perform(item1,item2,
317 GeomPnt (abisector->IssuePoint()),
318 GeomVec (abisector->FirstVector()),
319 GeomVec (abisector->SecondVector()),
320 theDirection,tolerance,ontheline);
321 }
322 else if(type1 == STANDARD_TYPE(Geom2d_CartesianPoint) &&
323 type2 == STANDARD_TYPE(Geom2d_CartesianPoint)) {
324 point1 = Handle(Geom2d_Point)::DownCast(elt1);
325 point2 = Handle(Geom2d_Point)::DownCast(elt2);
326 bisector.Perform(point1,point2,
327 GeomPnt (abisector->IssuePoint()),
328 GeomVec (abisector->FirstVector()),
329 GeomVec (abisector->SecondVector()),
330 theDirection,tolerance,ontheline);
331 }
332 else if(type1 == STANDARD_TYPE(Geom2d_CartesianPoint)) {
333 point1 = Handle(Geom2d_Point)::DownCast(elt1);
334 bisector.Perform(point1,item2,
335 GeomPnt (abisector->IssuePoint()),
336 GeomVec (abisector->FirstVector()),
337 GeomVec (abisector->SecondVector()),
338 theDirection,tolerance,ontheline);
339 }
340 else {
341 point2 = Handle(Geom2d_Point)::DownCast(elt2);
342 bisector.Perform(item1,point2,
343 GeomPnt (abisector->IssuePoint()),
344 GeomVec (abisector->FirstVector()),
345 GeomVec (abisector->SecondVector()),
346 theDirection,tolerance,ontheline);
347 }
348
349 //------------------------------
350 // Restriction de la bisectrice.
351 //-----------------------------
352 TrimBisec(bisector,edge1number,InitialNeighbour,1);
353 TrimBisec(bisector,edge2number,InitialNeighbour,2);
354
355 theNumberOfBisectors++;
356 theGeomBisectors.Bind(theNumberOfBisectors,bisector);
357
358 abisector->BisectorNumber(theNumberOfBisectors);
359 abisector->Sense(1);
360
361#ifdef DEB
362 Standard_Boolean AffichDraw = Standard_False;
363 if (AffichDraw) Dump(abisector->BisectorNumber(),1);
364 if (Store) {
365 Handle(Standard_Type) Type1 = Type(bisector.Value()->BasisCurve());
366 Handle(Geom2d_Curve) BasisCurve;
367 if (Type1 == STANDARD_TYPE(Bisector_BisecAna)) {
368 BasisCurve = Handle(Bisector_BisecAna)
369 ::DownCast(bisector.Value()->BasisCurve())->Geom2dCurve();
370#ifdef DRAW
371 char *name = new char[100];
372 sprintf(name,"BISSEC_%d",abisector->BisectorNumber());
373 DrawTrSurf::Set(name,BasisCurve);
374 delete [] name;
375#endif
376 }
377 }
378#endif
379}
380
381//=============================================================================
382//function : TrimBisec
383//purpose : Restriction de la bisectrice.
384// Restriction des bissectrice separant deux elements lies par une
385// connexion ou l un au moins des elements est un cercle.
386// Cette restriction est necessaire a la logique de l algorithme.
387//=============================================================================
388void MAT2d_Tool2d::TrimBisec ( Bisector_Bisec& B1,
389 const Standard_Integer IndexEdge,
390 const Standard_Boolean InitialNeighbour,
391 const Standard_Integer StartOrEnd ) const
392{
393 Handle(Geom2d_Curve) Curve;
394 Handle(Geom2d_TrimmedCurve) LineSupportDomain,Line;
395 Handle(Geom2d_Line) Line1,Line2;
396
397 //gp_Vec2d Tan1,Tan2;
398 gp_Pnt2d Ori; //PEdge;
399 Standard_Integer IPrec,INext;
7fd59977 400 IPrec = (IndexEdge == 1) ? theCircuit->NumberOfItems() : (IndexEdge - 1);
401 INext = (IndexEdge == theCircuit->NumberOfItems()) ? 1 : (IndexEdge + 1);
402
403 Handle(Standard_Type) EdgeType = theCircuit->Value(IndexEdge)->DynamicType();
404
405 if (EdgeType != STANDARD_TYPE(Geom2d_CartesianPoint)) {
406 if(!InitialNeighbour) {
407 Curve = Handle(Geom2d_TrimmedCurve)
408 ::DownCast(theCircuit->Value(IndexEdge))->BasisCurve();
409 EdgeType = Curve->DynamicType();
410 //-------------------------------------------------------------------
411 // si l edge est liee a sa voisine precedente par une connexion.
412 //-------------------------------------------------------------------
413 if (theCircuit->ConnexionOn(IndexEdge) && StartOrEnd == 1){
414 if (EdgeType == STANDARD_TYPE(Geom2d_Circle)) {
415 Ori = Handle(Geom2d_Circle)::DownCast(Curve)->Location();
416 gp_Pnt2d P2 = theCircuit->Connexion(IndexEdge)->PointOnFirst();
417 Line1 = new Geom2d_Line (Ori,gp_Dir2d(P2.X() - Ori.X(),
418 P2.Y() - Ori.Y()));
419 }
420 }
421 //-----------------------------------------------------------------------
422 // Si l edge est liee a sa voisine suivante par une connexion.
423 //-----------------------------------------------------------------------
424 if (theCircuit->ConnexionOn(INext) && StartOrEnd == 2){
425 if (EdgeType == STANDARD_TYPE(Geom2d_Circle)) {
426 Ori = Handle(Geom2d_Circle)::DownCast(Curve)->Location();
427 gp_Pnt2d P2 = theCircuit->Connexion(INext)->PointOnSecond();
428 Line2 = new Geom2d_Line (Ori,gp_Dir2d(P2.X() - Ori.X(),
429 P2.Y() - Ori.Y()));
430 }
431 }
432 if (Line1.IsNull() && Line2.IsNull()) return;
433
434 //-----------------------------------------------------------------------
435 // Restriction de la bisectrice par les demi-droites liees aux connexions
436 // si elles existent.
437 //-----------------------------------------------------------------------
438 if (!Line1.IsNull()) {
439 Line = new Geom2d_TrimmedCurve(Line1,0.,Precision::Infinite());
440 SetTrim(B1,Line);
441 }
442 if (!Line2.IsNull()) {
443 Line = new Geom2d_TrimmedCurve(Line2,0.,Precision::Infinite());
444 SetTrim(B1,Line);
445 }
446 }
447 }
448}
449
450//=============================================================================
451//function : TrimBisector
452//purpose :
453//=============================================================================
454Standard_Boolean MAT2d_Tool2d::TrimBisector
455 (const Handle(MAT_Bisector)& abisector)
456{
457 Standard_Real param = abisector->FirstParameter();
458
459#ifdef DEB
460 Standard_Boolean Affich = Standard_False;
461 if (Affich) cout<<"TRIM de "<<abisector->BisectorNumber()<<endl;
462#endif
463
464 Handle(Geom2d_TrimmedCurve)
465 bisector = Handle(Geom2d_TrimmedCurve)
466 ::DownCast(ChangeGeomBis(abisector->BisectorNumber()).ChangeValue());
467
468 if(bisector->BasisCurve()->IsPeriodic() && param == Precision::Infinite()) {
c6541a0c 469 param = bisector->FirstParameter() + 2*M_PI;
7fd59977 470 }
471 if (param > bisector->BasisCurve()->LastParameter()) {
472 param = bisector->BasisCurve()->LastParameter();
473 }
474 if(bisector->FirstParameter() == param) return Standard_False;
475
476 bisector->SetTrim(bisector->FirstParameter(),param);
477 return Standard_True;
478}
479
480//=============================================================================
481//function : TrimBisector
482//purpose :
483//=============================================================================
484Standard_Boolean MAT2d_Tool2d::TrimBisector
485 (const Handle(MAT_Bisector)& abisector,
486 const Standard_Integer apoint)
487{
488 Standard_Real Param;
489 Handle(Geom2d_TrimmedCurve)
490 Bisector = Handle(Geom2d_TrimmedCurve)::
491 DownCast(ChangeGeomBis(abisector->BisectorNumber()).ChangeValue());
492
493 Handle(Bisector_Curve) Bis = Handle(Bisector_Curve)::
494 DownCast(Bisector->BasisCurve());
495
496// Param = ParameterOnCurve(Bisector,theGeomPnts.Value(apoint));
497 Param = Bis->Parameter(GeomPnt (apoint));
498
499 if (Bisector->BasisCurve()->IsPeriodic()) {
c6541a0c 500 if (Bisector->FirstParameter() > Param) Param = Param + 2*M_PI;
7fd59977 501 }
502 if(Bisector->FirstParameter() >= Param)return Standard_False;
503 if(Bisector->LastParameter() < Param)return Standard_False;
504 Bisector->SetTrim(Bisector->FirstParameter(),Param);
505
506#ifdef DEB
507 Standard_Boolean Affich = Standard_False;
508 if (Affich) MAT2d_DrawCurve(Bisector,2);
509#endif
510
511 return Standard_True;
512}
513
514//=============================================================================
515//function : Projection
516//purpose :
517//=============================================================================
518Standard_Boolean MAT2d_Tool2d::Projection (const Standard_Integer IEdge ,
519 const gp_Pnt2d& PCom ,
520 Standard_Real& Distance)
521 const
522{
523 gp_Pnt2d PEdge;
524 Handle(Geom2d_Geometry) Elt = theCircuit->Value(IEdge);
525 Handle(Standard_Type) Type = Elt->DynamicType();
526 Handle(Geom2d_TrimmedCurve) Curve;
527 Standard_Integer INext;
528 Standard_Real ParameterOnC;
529 Standard_Real Eps = MAT2d_TOLCONF;//*10.;
530
531 if (Type == STANDARD_TYPE(Geom2d_CartesianPoint)) {
532 PEdge = Handle(Geom2d_Point)::DownCast(Elt)->Pnt2d();
533 Distance = PCom.Distance(PEdge);
534 }
535 else {
536 Distance = Precision::Infinite();
537 Curve = Handle(Geom2d_TrimmedCurve)::DownCast(Elt);
538 //-----------------------------------------------------------------------
539 // Calcul des parametres MinMax sur l edge si celui ci est lies a ses
540 // voisins par des connexions la courbe de calcul est limitee par
541 // celles_ci.
542 //-----------------------------------------------------------------------
543 Standard_Real ParamMin = Curve->FirstParameter();
544 Standard_Real ParamMax = Curve->LastParameter();
545 if (theCircuit->ConnexionOn(IEdge)) {
546 ParamMin = theCircuit->Connexion(IEdge)->ParameterOnSecond();
547 }
548 INext = (IEdge == theCircuit->NumberOfItems()) ? 1 : (IEdge + 1);
549 if (theCircuit->ConnexionOn(INext)) {
550 ParamMax = theCircuit->Connexion(INext)->ParameterOnFirst();
551 if (Curve->BasisCurve()->IsPeriodic()){
c6541a0c 552 ElCLib::AdjustPeriodic(0.,2*M_PI,Eps,ParamMin,ParamMax);
7fd59977 553 }
554 }
555 //---------------------------------------------------------------------
556 // Constuction de la courbe pour les extremas et ajustement des bornes.
557 //---------------------------------------------------------------------
558 Geom2dAdaptor_Curve C1(Curve);
559 GeomAbs_CurveType TypeC1 = C1.GetType();
560 if (TypeC1 == GeomAbs_Circle) {
561 Standard_Real R = C1.Circle().Radius();
562 Standard_Real EpsCirc = Eps;
563 if ( R < 1.) EpsCirc = Eps/R;
c6541a0c 564 if (!((ParamMax - ParamMin + 2*EpsCirc) < 2*M_PI)) {
7fd59977 565 ParamMax = ParamMax + EpsCirc; ParamMin = ParamMin - EpsCirc;
566 }
567 }
568 else {
569 ParamMax = ParamMax + Eps; ParamMin = ParamMin - Eps;
570 }
571 //-----------------------------------------------------
572 // Calcul des extremas et stockage minimum de distance.
573 //-----------------------------------------------------
574 Extrema_ExtPC2d Extremas(PCom,C1,ParamMin,ParamMax);
575 if (Extremas.IsDone()){
576 if (Extremas.NbExt() == 0 ) return Standard_False; // Pas de solution!
577 for (Standard_Integer i = 1; i <= Extremas.NbExt(); i++) {
578 if (Extremas.SquareDistance(i) < Distance * Distance) {
579 ParameterOnC = Extremas.Point(i).Parameter();
580 Distance = sqrt (Extremas.SquareDistance(i));
581 }
582 }
583 }
584 else {
585 if (TypeC1 == GeomAbs_Circle) {
586 Distance = C1.Circle().Radius();
587 }
588 }
589 }
590 return Standard_True;
591}
592
593//=============================================================================
594//function : IsSameDistance
595// purpose :
596//=============================================================================
597Standard_Boolean MAT2d_Tool2d::IsSameDistance (
598 const Handle(MAT_Bisector)& BisectorOne,
599 const Handle(MAT_Bisector)& BisectorTwo,
600 const gp_Pnt2d& PCom,
601 Standard_Real& Distance) const
602{
603 TColStd_Array1OfReal Dist(1,4);
604 Standard_Integer IEdge1,IEdge2,IEdge3,IEdge4;
605
606 IEdge1 = BisectorOne->FirstEdge() ->EdgeNumber();
607 IEdge2 = BisectorOne->SecondEdge()->EdgeNumber();
608 IEdge3 = BisectorTwo->FirstEdge() ->EdgeNumber();
609 IEdge4 = BisectorTwo->SecondEdge()->EdgeNumber();
610
611 Projection(IEdge1,PCom,Dist(1));
612 Projection(IEdge2,PCom,Dist(2));
613
614 if (IEdge3 == IEdge1) Dist(3) = Dist(1);
615 else if (IEdge3 == IEdge2) Dist(3) = Dist(2);
616 else Projection(IEdge3,PCom,Dist(3));
617
618 if (IEdge4 == IEdge1) Dist(4) = Dist(1);
619 else if (IEdge4 == IEdge2) Dist(4) = Dist(2);
620 else Projection(IEdge4,PCom,Dist(4));
621
622#ifdef DEB
623 Standard_Boolean Affich = Standard_False;
624 if (Affich)
625 for (Standard_Integer j = 1; j <= 4;j++){
626 cout <<"Distance number : "<<j<<" is :"<< Dist(j)<<endl;
627 }
628#endif
629
630 Standard_Real EpsDist = MAT2d_TOLCONF*100. ;
631 Distance = Dist(1);
632 for (Standard_Integer i = 1; i <= 4; i++){
633 if (Abs(Dist(i) - Distance) > EpsDist) {
634 Distance = Precision::Infinite();
635 return Standard_False;
636 }
637 }
638 return Standard_True;
639}
640
641//=============================================================================
642//function : IntersectBisector
643//purpose :
644//=============================================================================
645Standard_Real MAT2d_Tool2d::IntersectBisector (
646 const Handle(MAT_Bisector)& BisectorOne,
647 const Handle(MAT_Bisector)& BisectorTwo,
648 Standard_Integer& IntPnt)
649{
650 Standard_Real Tolerance = MAT2d_TOLCONF;
651 Standard_Real Param1,Param2;
652 Standard_Real Parama,Paramb;
653 Standard_Real Distance,DistanceMini;
654 Standard_Boolean SolutionValide;
655 gp_Pnt2d PointSolution;
656
657 Handle(Geom2d_TrimmedCurve)
658 Bisector1 = Handle(Geom2d_TrimmedCurve)
659 ::DownCast(ChangeGeomBis(BisectorOne->BisectorNumber()).ChangeValue());
660
661 Handle(Geom2d_TrimmedCurve)
662 Bisector2 = Handle(Geom2d_TrimmedCurve)
663 ::DownCast(ChangeGeomBis(BisectorTwo->BisectorNumber()).ChangeValue());
664
665 if(Bisector1.IsNull() || Bisector2.IsNull()) return Precision::Infinite();
666
667 //-------------------------------------------------------------------------
668 // Si les deux bissectrices separent des elements consecutifs et qu elles
669 // sont issues des connexions C1 et C2.
670 // Si C1 est la reverse de C2 ,alors les deux bissectrices sont issues
671 // du meme point. Dans ce cas l intersection n est pas validee.
672 //-------------------------------------------------------------------------
673 Standard_Integer IS1 = BisectorOne->SecondEdge()->EdgeNumber();
674 Standard_Integer IS2 = BisectorTwo->SecondEdge()->EdgeNumber();
675 Standard_Integer IF1 = BisectorOne->FirstEdge() ->EdgeNumber();
676 Standard_Integer IF2 = BisectorTwo->FirstEdge() ->EdgeNumber();
677
678 if (AreNeighbours(IF1,IS1,NumberOfItems()) &&
679 AreNeighbours(IF2,IS2,NumberOfItems()) &&
680 theCircuit->ConnexionOn(IS2) &&
681 theCircuit->ConnexionOn(IS1) ) {
682 Handle(MAT2d_Connexion) C1,C2;
683 C1 = theCircuit->Connexion(IS1);
684 C2 = theCircuit->Connexion(IS2);
685 if (C2->IndexFirstLine() == C1->IndexSecondLine() &&
686 C1->IndexFirstLine() == C2->IndexSecondLine() )
687 return Precision::Infinite();
688 }
689
690 // -----------------------------------------
691 // Construction des domaines d intersection.
692 // -----------------------------------------
693 IntRes2d_Domain Domain1 = Domain(Bisector1,Tolerance);
694 IntRes2d_Domain Domain2 = Domain(Bisector2,Tolerance);
695
696 if (Domain1.LastParameter() - Domain1.FirstParameter() < Tolerance)
697 return Precision::Infinite();
698 if (Domain2.LastParameter() - Domain2.FirstParameter() < Tolerance)
699 return Precision::Infinite();
700
701#ifdef DEB
702 Standard_Boolean Affich = Standard_False;
703 if (Affich) {
704 cout<<endl;
705 cout<<"INTERSECTION de "<<BisectorOne->BisectorNumber()<<
706 " et de "<<BisectorTwo->BisectorNumber()<<endl;
707 cout<<" Bisector 1 : "<<endl;
708// (Bisector1->BasisCurve())->Dump(-1,1);
709 cout<<endl;
710 Debug(Domain1.FirstParameter());
711 Debug(Domain1.LastParameter());
712 cout<<"-----------------"<<endl;
713 cout<<" Bisector 2 : "<<endl;
714// (Bisector2->BasisCurve())->Dump(-1,1);
715 cout<<endl;
716 Debug(Domain2.FirstParameter());
717 Debug(Domain2.LastParameter());
718 cout<<"-----------------"<<endl;
719 }
720#endif
721
722// -------------------------
723// Calcul de l intersection.
724// -------------------------
725
726 Bisector_Inter Intersect;
727 Intersect.Perform (GeomBis(BisectorOne->BisectorNumber()),Domain1,
728 GeomBis(BisectorTwo->BisectorNumber()),Domain2,
729 Tolerance,Tolerance,Standard_True);
730
731// Geom2dInt_GInter Intersect;
732// Intersect.Perform(Bisector1,Domain1,Bisector2,Domain2,Tolerance,Tolerance);
733
734// -------------------------------------------------------------------------
735// Exploitation du resultat de l intersection et selection du point solution
736// equidistant des deux edges et le plus proche en parametre de l origine
737// des bissectrices.
738// -------------------------------------------------------------------------
739
740 if(!Intersect.IsDone()) return Precision::Infinite();
741
742 if(Intersect.IsEmpty()) return Precision::Infinite();
743
744 DistanceMini = Precision::Infinite();
745 Param1 = Precision::Infinite();
746 Param2 = Precision::Infinite();
747 SolutionValide = Standard_False;
748
749 if(Intersect.NbSegments() >= 1) {
750 Standard_Real MaxSegmentLength = 10.*Tolerance;
751 for (Standard_Integer i=1;i<=Intersect.NbSegments();i++) {
752 IntRes2d_IntersectionSegment Segment = Intersect.Segment(i);
753 Standard_Boolean PointRetenu = Standard_False;
754 gp_Pnt2d PointOnSegment;
755 // ----------------------------------------------------------------
756 // Si les segments sont petits, recherche des points sur le segment
757 // equidistants des edges.
758 // ----------------------------------------------------------------
759 if ((Segment.HasFirstPoint() && Segment.HasLastPoint())) {
760 gp_Pnt2d P1,P2;
761 Standard_Real SegmentLength;
762 P1 = Segment.FirstPoint().Value();
763 P2 = Segment.LastPoint().Value();
764 SegmentLength = P1.Distance(P2);
765 if (SegmentLength <= Tolerance) {
766 PointOnSegment = P1;
767 if(IsSameDistance(BisectorOne,BisectorTwo,
768 PointOnSegment,Distance))
769 PointRetenu = Standard_True;
770 }
771 else if (SegmentLength <= MaxSegmentLength) {
772 gp_Dir2d Dir(P2.X()-P1.X(),P2.Y()-P1.Y());
773 Standard_Real Dist = 0.;
774 while (Dist <= SegmentLength + Tolerance){
775 PointOnSegment = P1.Translated(Dist*Dir);
776 if(IsSameDistance(BisectorOne,BisectorTwo,
777 PointOnSegment,Distance)) {
778 PointRetenu = Standard_True;
779 break;
780 }
781 Dist = Dist + Tolerance;
782 }
783 }
784 }
785
786 // ----------------------------------------------------------------
787 // Sauvegarde du point equidistant des edges de plus petit
788 // parametre sur les bissectrices.
789 // ----------------------------------------------------------------
790 if(PointRetenu) {
791 Parama = Handle(Bisector_Curve)::DownCast(Bisector1->BasisCurve())
792 ->Parameter(PointOnSegment);
793 Paramb = Handle(Bisector_Curve)::DownCast(Bisector2->BasisCurve())
794 ->Parameter(PointOnSegment);
795 if(Parama < Param1 && Paramb < Param2) {
796 Param1 = Parama;
797 Param2 = Paramb;
798 DistanceMini = Distance;
799 PointSolution = PointOnSegment;
800 SolutionValide = Standard_True;
801 }
802 }
803 }
804 }
805
806 if(Intersect.NbPoints() != 1) {
807 for(Standard_Integer i=1; i<=Intersect.NbPoints(); i++) {
808 if(IsSameDistance(BisectorOne,BisectorTwo,
809 Intersect.Point(i).Value(),Distance) &&
810 Distance > Tolerance ) {
811 Parama = Intersect.Point(i).ParamOnFirst();
812 Paramb = Intersect.Point(i).ParamOnSecond();
813 if (Parama < Param1 && Paramb < Param2) {
814 Param1 = Parama;
815 Param2 = Paramb;
816 DistanceMini = Distance;
817 PointSolution = Intersect.Point(i).Value();
818 SolutionValide = Standard_True;
819 }
820 }
821 }
822 }
823 else {
824 PointSolution = Intersect.Point(1).Value();
825 Param1 = Intersect.Point(1).ParamOnFirst();
826 Param2 = Intersect.Point(1).ParamOnSecond();
827 SolutionValide = IsSameDistance(BisectorOne,BisectorTwo,
828 PointSolution,DistanceMini);
829 }
830
831 if (!SolutionValide) return Precision::Infinite();
832 theNumberOfPnts++;
833 theGeomPnts.Bind(theNumberOfPnts,PointSolution);
834 IntPnt = theNumberOfPnts;
835
836 //-----------------------------------------------------------------------
837 // Si le point d intersection est quasi confondue avec une des extremites
838 // de l une ou l autre des bisectrices, l intersection n est pas validee.
839 //
840 // SAUF si une des bisectrices est issue d une connexion et que les
841 // edges separes par les bissectrices sont des voisines sur le contour
842 // initiales.
843 // en effet le milieu de la connexion P qui est l origine d une des
844 // bissectrices peut etre sur l autre bissectrice.
845 // P est donc point d intersection
846 // et la bissectrice issue de la connexion est de longueur nulle.
847 // (ex : un rectangle dans un rectangle ou la connexion est entre un coin
848 // et un cote).
849 //-----------------------------------------------------------------------
850
851 Standard_Integer IndexEdge1,IndexEdge2,IndexEdge3,IndexEdge4;
852 Standard_Boolean ExtremiteControle = Standard_True;
853
854 IndexEdge1 = BisectorOne->FirstEdge() ->EdgeNumber();
855 IndexEdge2 = BisectorOne->SecondEdge()->EdgeNumber();
856 IndexEdge3 = BisectorTwo->FirstEdge() ->EdgeNumber();
857 IndexEdge4 = BisectorTwo->SecondEdge()->EdgeNumber();
858
859 if (theCircuit->ConnexionOn(IndexEdge2)){
860 // --------------------------------------
861 // BisectorOne est issue d une connexion.
862 // --------------------------------------
863 if (AreNeighbours(IndexEdge1,IndexEdge2,NumberOfItems()) &&
864 AreNeighbours(IndexEdge3,IndexEdge4,NumberOfItems()) &&
865 IndexEdge2 == IndexEdge3 ){
866 ExtremiteControle = Standard_False;
867 Param1 = Param1 + Tolerance;
868 }
869 }
870
871 if (theCircuit->ConnexionOn(IndexEdge4)){
872 // --------------------------------------
873 // BisectorTwo est issue d une connexion.
874 // --------------------------------------
875 if (AreNeighbours(IndexEdge1,IndexEdge2,NumberOfItems()) &&
876 AreNeighbours(IndexEdge3,IndexEdge4,NumberOfItems()) &&
877 IndexEdge2 == IndexEdge3 ){
878 ExtremiteControle = Standard_False;
879 Param2 = Param2 + Tolerance;
880 }
881 }
882
883 if (ExtremiteControle) {
884 if(Bisector1->StartPoint().Distance(PointSolution) < Tolerance ||
885 Bisector2->StartPoint().Distance(PointSolution) < Tolerance )
886 return Precision::Infinite();
887 }
888
889 if(BisectorOne->SecondParameter() < Precision::Infinite() &&
890 BisectorOne->SecondParameter() < Param1*(1. - Tolerance ))
891 return Precision::Infinite();
892
893 if(BisectorTwo->FirstParameter() < Precision::Infinite() &&
894 BisectorTwo->FirstParameter() < Param2*(1.- Tolerance))
895 return Precision::Infinite();
896
897 BisectorOne->SecondParameter(Param1);
898 BisectorTwo->FirstParameter (Param2);
899
900#ifdef DEB
901 if (Affich) {
902 cout<<" coordonnees : "<<GeomPnt (IntPnt).X()<<" "
903 <<GeomPnt (IntPnt).Y()<<endl;
904 cout<<" parametres : "<<Param1<<" "<<Param2<<endl;
905 cout<<" distancemini : "<<DistanceMini<<endl;
906 }
907#endif
908
909 return DistanceMini;
910}
911
912//=============================================================================
913//function : Distance
914//purpose :
915//=============================================================================
916Standard_Real MAT2d_Tool2d::Distance(const Handle(MAT_Bisector)& Bis,
917 const Standard_Real Param1,
918 const Standard_Real Param2) const
919{
920 Standard_Real Dist = Precision::Infinite();
921
922 if (Param1 != Precision::Infinite() && Param2 != Precision::Infinite()) {
923 gp_Pnt2d P1 = GeomBis(Bis->BisectorNumber()).Value()->Value(Param1);
924 gp_Pnt2d P2 = GeomBis(Bis->BisectorNumber()).Value()->Value(Param2);
925 Dist = P1.Distance(P2);
926 }
927 return Dist;
928}
929
930//=============================================================================
931//function : Dump
932//purpose :
933//=============================================================================
934#ifndef DEB
935void MAT2d_Tool2d::Dump(const Standard_Integer ,
936 const Standard_Integer ) const
937{
938 Standard_NotImplemented::Raise();
939#else
940void MAT2d_Tool2d::Dump(const Standard_Integer bisector,
941 const Standard_Integer) const
942{
943 if(bisector == -1) return;
944 if(bisector > theNumberOfBisectors) return;
945
946 Handle(Geom2d_Curve) thebisector = GeomBis(bisector).Value();
947
948 MAT2d_DrawCurve(thebisector,3);
949
950#endif
951}
952
953
954//=============================================================================
955//function : GeomBis
956//purpose :
957//=============================================================================
958const Bisector_Bisec& MAT2d_Tool2d::GeomBis (const Standard_Integer Index)
959 const
960{
961 return theGeomBisectors.Find(Index);
962}
963
964//=============================================================================
965//function : ChangeGeomBis
966//purpose :
967//=============================================================================
968Bisector_Bisec& MAT2d_Tool2d::ChangeGeomBis(const Standard_Integer Index)
969{
970 return theGeomBisectors.ChangeFind(Index);
971}
972
973
974//=============================================================================
975//function : GeomElt
976//purpose :
977//=============================================================================
978Handle(Geom2d_Geometry) MAT2d_Tool2d::GeomElt(const Standard_Integer Index)
979 const
980{
981 return theCircuit->Value(Index);
982}
983
984
985//=============================================================================
986//function : GeomPnt
987//purpose :
988//=============================================================================
989const gp_Pnt2d& MAT2d_Tool2d::GeomPnt(const Standard_Integer Index) const
990{
991 return theGeomPnts.Find(Index);
992}
993
994//=============================================================================
995//function : GeomVec
996//purpose :
997//=============================================================================
998const gp_Vec2d& MAT2d_Tool2d::GeomVec(const Standard_Integer Index)const
999{
1000 return theGeomVecs.Find(Index);
1001}
1002
1003//=============================================================================
1004//function : Circuit
1005//purpose :
1006//=============================================================================
1007Handle(MAT2d_Circuit) MAT2d_Tool2d::Circuit()const
1008{
1009 return theCircuit;
1010}
1011
1012//=============================================================================
1013//function : BisecFusion
1014//purpose :
1015//=============================================================================
1016void MAT2d_Tool2d::BisecFusion(const Standard_Integer I1,
1017 const Standard_Integer I2)
1018{
1019 Standard_Real DU,UL1,UF1;
1020 Handle(Geom2d_TrimmedCurve) Bisector1;
1021 Handle(Geom2d_TrimmedCurve) Bisector2;
1022
1023 Bisector1 = Handle(Geom2d_TrimmedCurve)::DownCast(GeomBis(I1).Value());
1024 Bisector2 = Handle(Geom2d_TrimmedCurve)::DownCast(GeomBis(I2).Value());
1025 UF1 = Bisector1->FirstParameter();
1026 UL1 = Bisector1->LastParameter();
1027
1028 Handle(Standard_Type) Type1 = Bisector1->BasisCurve()->DynamicType();
1029 if (Type1 == STANDARD_TYPE(Bisector_BisecCC)) {
1030 //------------------------------------------------------------------------------------
1031 // les bissectrice courbe/courbe sont construites avec un point de depart
1032 // elles ne peuvent pas etre trimes par un point se trouvant de l autre cote du
1033 // point de depart.
1034 // pour faire la fusion des deux bissectrices on reconstruit la bissectrice entre les
1035 // deux courbes avec comme point de depart le dernier point de la Bisector2.
1036 // on trime ensuite la courbe par le dernier point de Bisector1.
1037 //------------------------------------------------------------------------------------
1038 Standard_Real Tolerance = MAT2d_TOLCONF;
1039 Bisector_Bisec Bis;
1040 gp_Vec2d VBid(1,0);
1041 gp_Pnt2d P2 = Bisector2->Value(Bisector2->LastParameter());
1042 gp_Pnt2d P1 = Bisector1->Value(Bisector1->LastParameter());
1043 Handle(Bisector_BisecCC) BCC1 = Handle(Bisector_BisecCC)::DownCast(Bisector1->BasisCurve());
1044
1045 Bis.Perform(BCC1->Curve(2), BCC1->Curve(1), P2, VBid, VBid,
1046 theDirection, Tolerance, Standard_False);
1047
1048 Bisector1 = Handle(Geom2d_TrimmedCurve)::DownCast(Bis.Value());
1049 BCC1 = Handle(Bisector_BisecCC) ::DownCast(Bisector1->BasisCurve());
1050 UF1 = BCC1->FirstParameter();
1051 UL1 = BCC1->Parameter(P1);
1052 Bisector1->SetTrim(UF1,UL1);
1053 theGeomBisectors.Bind(I1,Bis);
1054 }
1055 else {
1056 DU = Bisector2->LastParameter() - Bisector2->FirstParameter();
1057 UF1 = UF1 - DU;
1058
1059 Handle(Bisector_BisecAna) BAna = Handle(Bisector_BisecAna)::DownCast(Bisector1->BasisCurve());
1060//---------------------------- uncomment if new method Bisector_BisecAna::SetTrim(f,l) is not used
1061// Handle(Geom2d_Curve) C2d = BAna->Geom2dCurve();
1062// Handle(Geom2d_TrimmedCurve) trimC2d = new Geom2d_TrimmedCurve(C2d, UF1, UL1);
1063// BAna->Init(trimC2d);
1064//--------------------------- end
1065 BAna->SetTrim(UF1,UL1); // put comment if SetTrim(f,l) is not used
1066
1067 Bisector1->SetTrim(UF1,UL1);
1068 }
1069}
1070
1071//=============================================================================
1072//function : Type
1073//purpose :
1074//=============================================================================
1075static Handle(Standard_Type) Type(const Handle(Geom2d_Geometry)& aGeom)
1076{
1077 Handle(Standard_Type) type = aGeom->DynamicType();
1078 Handle(Geom2d_Curve) curve;
1079
1080 if (type == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
1081 curve = Handle(Geom2d_TrimmedCurve)::DownCast(aGeom)->BasisCurve();
1082 type = curve->DynamicType();
1083 }
1084 return type;
1085}
1086
1087//==========================================================================
1088//function : AreNeighbours
1089//purpose : Return TRUE si IEdge1 et IEdge2 correspondent a des elements
1090// consecutifs sur un contour ferme de NbEdge elements.
1091//==========================================================================
1092Standard_Boolean AreNeighbours(const Standard_Integer IEdge1,
1093 const Standard_Integer IEdge2,
1094 const Standard_Integer NbEdge)
1095{
1096 if (Abs(IEdge1 - IEdge2) == 1) return Standard_True;
1097 else if (Abs(IEdge1 - IEdge2) == NbEdge -1) return Standard_True;
1098 else return Standard_False;
1099}
1100
1101//==========================================================================
1102//function : SetTrim
1103//purpose :
1104//==========================================================================
1105void SetTrim(Bisector_Bisec& Bis, Handle(Geom2d_Curve)& Line1)
1106{
1107 Geom2dInt_GInter Intersect;
1108 Standard_Real Distance;
1109 Standard_Real Tolerance = MAT2d_TOLCONF;
1110 Handle(Geom2d_TrimmedCurve) Bisector =
1111 Handle(Geom2d_TrimmedCurve)::DownCast(Bis.ChangeValue());
1112
1113 IntRes2d_Domain Domain1 = Domain(Bisector,Tolerance);
1114 Standard_Real UB1 = Bisector->FirstParameter();
1115 Standard_Real UB2 = Bisector->LastParameter();
1116
1117 gp_Pnt2d FirstPointBisector = Bisector->Value(UB1);
1118 Standard_Real UTrim = Precision::Infinite();
1119
1120 Geom2dAdaptor_Curve AdapBisector(Bisector);
1121 Geom2dAdaptor_Curve AdapLine1 (Line1);
1122 Intersect.Perform(AdapBisector, Domain1,
1123 AdapLine1, Tolerance, Tolerance);
1124
1125 if (Intersect.IsDone() && !Intersect.IsEmpty()) {
1126 for (Standard_Integer i = 1; i <= Intersect.NbPoints(); i++) {
1127 gp_Pnt2d PInt = Intersect.Point(i).Value();
1128 Distance = FirstPointBisector.Distance(PInt);
1129 if (Distance > 10.*Tolerance &&
1130 Intersect.Point(i).ParamOnFirst() < UTrim ) {
1131 UTrim = Intersect.Point(i).ParamOnFirst();
1132 }
1133 }
1134 }
1135 // ------------------------------------------------------------------------
1136 // Restriction de la Bissectrice par le point d intersection de plus petit
1137 // parametre.
1138 // ------------------------------------------------------------------------
1139 if (UTrim < UB2 && UTrim > UB1) Bisector->SetTrim(UB1,UTrim);
1140}
1141
1142//==========================================================================
1143//function : Domain
1144//purpose :
1145//==========================================================================
1146IntRes2d_Domain Domain(const Handle(Geom2d_TrimmedCurve)& Bisector1,
1147 const Standard_Real Tolerance)
1148{
1149 Standard_Real Param1 = Bisector1->FirstParameter();
1150 Standard_Real Param2 = Bisector1->LastParameter();
1151 if(Param2 > 10000.) {
1152 Param2 = 10000.;
1153 Handle(Standard_Type) Type1 = Type(Bisector1->BasisCurve());
1154 Handle(Geom2d_Curve) BasisCurve;
1155 if (Type1 == STANDARD_TYPE(Bisector_BisecAna)) {
1156 BasisCurve = Handle(Bisector_BisecAna)
1157 ::DownCast(Bisector1->BasisCurve())->Geom2dCurve();
1158 Type1 = BasisCurve->DynamicType();
1159 }
1160 gp_Parab2d gpParabola;
1161 gp_Hypr2d gpHyperbola;
1162 Standard_Real Focus;
1163 Standard_Real Limit = 50000.;
1164 if (Type1 == STANDARD_TYPE(Geom2d_Parabola)) {
1165 gpParabola = Handle(Geom2d_Parabola)::DownCast(BasisCurve)->Parab2d();
1166 Focus = gpParabola.Focal();
1167 Standard_Real Val1 = Sqrt(Limit*Focus);
1168 Standard_Real Val2 = Sqrt(Limit*Limit);
1169 Param2 = (Val1 <= Val2 ? Val1:Val2);
1170 }
1171 else if (Type1 == STANDARD_TYPE(Geom2d_Hyperbola)) {
1172 gpHyperbola = Handle(Geom2d_Hyperbola)::DownCast(BasisCurve)->Hypr2d();
1173 Standard_Real Majr = gpHyperbola.MajorRadius();
1174 Standard_Real Minr = gpHyperbola.MinorRadius();
1175 Standard_Real Valu1 = Limit/Majr;
1176 Standard_Real Valu2 = Limit/Minr;
1177 Standard_Real Val1 = Log(Valu1+Sqrt(Valu1*Valu1-1));
1178 Standard_Real Val2 = Log(Valu2+Sqrt(Valu2*Valu2+1));
1179 Param2 = (Val1 <= Val2 ? Val1:Val2);
1180 }
1181 }
1182
1183 IntRes2d_Domain Domain1(Bisector1->Value(Param1),Param1,Tolerance,
1184 Bisector1->Value(Param2),Param2,Tolerance);
1185 if(Bisector1->BasisCurve()->IsPeriodic()) {
c6541a0c 1186 Domain1.SetEquivalentParameters(0.,2.*M_PI);
7fd59977 1187 }
1188 return Domain1;
1189}
1190
1191#ifdef DEB
1192//==========================================================================
1193//function : MAT2d_DrawCurve
1194//purpose : Affichage d une courbe <aCurve> de Geom2d. dans une couleur
1195// definie par <Indice>.
1196// Indice = 1 jaune,
1197// Indice = 2 bleu,
1198// Indice = 3 rouge,
1199// Indice = 4 vert.
1200//==========================================================================
1201void MAT2d_DrawCurve(const Handle(Geom2d_Curve)& aCurve,
1202 const Standard_Integer Indice)
1203{
1204 Handle(Standard_Type) type = aCurve->DynamicType();
1205 Handle(Geom2d_Curve) curve,CurveDraw;
1206#ifdef DRAW
1207 Handle(DrawTrSurf_Curve2d) dr;
1208 Draw_Color Couleur;
1209#endif
1210
1211 if (type == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
1212 curve = Handle(Geom2d_TrimmedCurve)::DownCast(aCurve)->BasisCurve();
1213 type = curve->DynamicType();
1214 // PB de representation des courbes semi_infinies.
1215 gp_Parab2d gpParabola;
1216 gp_Hypr2d gpHyperbola;
1217 Standard_Real Focus;
1218 Standard_Real Limit = 50000.;
1219 Standard_Real delta = 400;
1220
1221 // PB de representation des courbes semi_infinies.
1222 if (aCurve->LastParameter() == Precision::Infinite()) {
1223
1224 if (type == STANDARD_TYPE(Geom2d_Parabola)) {
1225 gpParabola = Handle(Geom2d_Parabola)::DownCast(curve)->Parab2d();
1226 Focus = gpParabola.Focal();
1227 Standard_Real Val1 = Sqrt(Limit*Focus);
1228 Standard_Real Val2 = Sqrt(Limit*Limit);
1229 delta= (Val1 <= Val2 ? Val1:Val2);
1230 }
1231 else if (type == STANDARD_TYPE(Geom2d_Hyperbola)) {
1232 gpHyperbola = Handle(Geom2d_Hyperbola)::DownCast(curve)->Hypr2d();
1233 Standard_Real Majr = gpHyperbola.MajorRadius();
1234 Standard_Real Minr = gpHyperbola.MinorRadius();
1235 Standard_Real Valu1 = Limit/Majr;
1236 Standard_Real Valu2 = Limit/Minr;
1237 Standard_Real Val1 = Log(Valu1+Sqrt(Valu1*Valu1-1));
1238 Standard_Real Val2 = Log(Valu2+Sqrt(Valu2*Valu2+1));
1239 delta = (Val1 <= Val2 ? Val1:Val2);
1240 }
1241 CurveDraw = new Geom2d_TrimmedCurve(aCurve,
1242 aCurve->FirstParameter(),
1243 aCurve->FirstParameter() + delta);
1244 }
1245 else {
1246 CurveDraw = aCurve;
1247 }
1248 // fin PB.
1249 }
1250 else {
1251 CurveDraw = aCurve;
1252 }
1253
1254#ifdef DRAW
1255 if (Indice == 1) Couleur = Draw_jaune;
1256 else if (Indice == 2) Couleur = Draw_bleu;
1257 else if (Indice == 3) Couleur = Draw_rouge;
1258 else if (Indice == 4) Couleur = Draw_vert;
1259
1260 if (type == STANDARD_TYPE(Geom2d_Circle))
1261 dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,30);
1262 else if (type == STANDARD_TYPE(Geom2d_Line))
1263 dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,2);
1264 else
1265 dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,500);
1266
1267 dout << dr;
1268 dout.Flush();
1269#endif
1270}
1271
1272#endif
1273