0030675: Visualization - remove redundant proxy classes in hierarchy of PrsMgr_Presen...
[occt.git] / src / DsgPrs / DsgPrs.cxx
CommitLineData
b311480e 1// Copyright (c) 1998-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
7dd7c146 15#include <DsgPrs.hxx>
16
7fd59977 17#include <Aspect_TypeOfLine.hxx>
18#include <Aspect_TypeOfMarker.hxx>
7fd59977 19#include <ElCLib.hxx>
42cf5bc1 20#include <gce_MakeLin.hxx>
7fd59977 21#include <Geom_Circle.hxx>
42cf5bc1 22#include <Geom_Curve.hxx>
23#include <Geom_Line.hxx>
24#include <Geom_Surface.hxx>
7fd59977 25#include <GeomAPI_ExtremaCurveCurve.hxx>
7fd59977 26#include <GeomAPI_ProjectPointOnCurve.hxx>
42cf5bc1 27#include <GeomAPI_ProjectPointOnSurf.hxx>
28#include <gp_Ax1.hxx>
29#include <gp_Circ.hxx>
30#include <gp_Dir.hxx>
31#include <gp_Elips.hxx>
32#include <gp_Pln.hxx>
33#include <gp_Pnt.hxx>
34#include <gp_Vec.hxx>
35#include <Graphic3d_ArrayOfPoints.hxx>
36#include <Graphic3d_AspectLine3d.hxx>
37#include <Graphic3d_AspectMarker3d.hxx>
38#include <Graphic3d_Group.hxx>
42cf5bc1 39#include <Precision.hxx>
40#include <Prs3d_Arrow.hxx>
41#include <Prs3d_ArrowAspect.hxx>
42#include <Prs3d_DimensionAspect.hxx>
43#include <Prs3d_LineAspect.hxx>
44#include <Prs3d_Presentation.hxx>
45#include <Prs3d_Root.hxx>
46#include <Quantity_Color.hxx>
47#include <TCollection_AsciiString.hxx>
48#include <TCollection_ExtendedString.hxx>
7fd59977 49
7fd59977 50void DsgPrs::ComputeSymbol (const Handle(Prs3d_Presentation)& aPresentation,
a6eb515f 51 const Handle(Prs3d_DimensionAspect)& LA,
7fd59977 52 const gp_Pnt& pt1,
53 const gp_Pnt& pt2,
54 const gp_Dir& dir1,
55 const gp_Dir& dir2,
a6eb515f 56 const DsgPrs_ArrowSide ArrowSide,
57 const Standard_Boolean drawFromCenter)
7fd59977 58{
bf5f0ca2 59 Handle(Graphic3d_Group) aGroup = aPresentation->NewGroup();
a577aaab 60
b6472664 61 Quantity_Color aColor = LA->LineAspect()->Aspect()->Color();
a577aaab 62 Handle(Graphic3d_AspectMarker3d) aMarkerAsp = new Graphic3d_AspectMarker3d (Aspect_TOM_O, aColor, 1.0);
bf5f0ca2 63 aGroup->SetGroupPrimitivesAspect (LA->LineAspect()->Aspect());
7fd59977 64
65 switch(ArrowSide) {
66 case DsgPrs_AS_NONE:
67 {
68 break;
69 }
70 case DsgPrs_AS_FIRSTAR:
71 {
bf5f0ca2 72 Prs3d_Arrow::Draw (aGroup,
7fd59977 73 pt1,
74 dir1,
75 LA->ArrowAspect()->Angle(),
76 LA->ArrowAspect()->Length());
77 break;
78 }
79 case DsgPrs_AS_LASTAR:
80 {
81
bf5f0ca2 82 Prs3d_Arrow::Draw (aGroup,
7fd59977 83 pt2,
84 dir2,
85 LA->ArrowAspect()->Angle(),
86 LA->ArrowAspect()->Length());
87 break;
88 }
89
90 case DsgPrs_AS_BOTHAR:
91 {
bf5f0ca2 92 Prs3d_Arrow::Draw (aGroup,
7fd59977 93 pt1,
94 dir1,
95 LA->ArrowAspect()->Angle(),
96 LA->ArrowAspect()->Length());
bf5f0ca2 97 Prs3d_Arrow::Draw (aGroup,
7fd59977 98 pt2,
99 dir2,
100 LA->ArrowAspect()->Angle(),
101 LA->ArrowAspect()->Length());
102
103 break;
104 }
105
106 case DsgPrs_AS_FIRSTPT:
107 {
a6eb515f 108 if(drawFromCenter)
a577aaab 109 {
110 Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
111 anArrayOfPoints->AddVertex (pt1.X(), pt1.Y(), pt1.Z());
112 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints);
113 }
7fd59977 114 break;
115 }
116
117 case DsgPrs_AS_LASTPT:
118 {
119 // On dessine un rond
a577aaab 120 Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
121 anArrayOfPoints->AddVertex (pt2.X(), pt2.Y(), pt2.Z());
122 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints);
7fd59977 123 break;
124 }
125
126 case DsgPrs_AS_BOTHPT:
127 {
a6eb515f 128 if(drawFromCenter)
a577aaab 129 {
bf5f0ca2 130 Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints1 = new Graphic3d_ArrayOfPoints (2);
a577aaab 131 anArrayOfPoints1->AddVertex (pt1.X(), pt1.Y(), pt1.Z());
bf5f0ca2 132 anArrayOfPoints1->AddVertex (pt2.X(), pt2.Y(), pt2.Z());
133 aGroup->SetGroupPrimitivesAspect (aMarkerAsp);
134 aGroup->AddPrimitiveArray (anArrayOfPoints1);
a6eb515f 135 }
7fd59977 136 break;
137 }
138
139 case DsgPrs_AS_FIRSTAR_LASTPT:
140 {
141 // an Arrow
bf5f0ca2 142 Prs3d_Arrow::Draw (aGroup,
a6eb515f 143 pt1,
144 dir1,
145 LA->ArrowAspect()->Angle(),
146 LA->ArrowAspect()->Length());
7fd59977 147 // a Round
a577aaab 148 Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
149 anArrayOfPoints->AddVertex (pt2.X(), pt2.Y(), pt2.Z());
bf5f0ca2 150 aGroup->SetPrimitivesAspect (aMarkerAsp);
151 aGroup->AddPrimitiveArray (anArrayOfPoints);
7fd59977 152 break;
153 }
154
155 case DsgPrs_AS_FIRSTPT_LASTAR:
156 {
7fd59977 157 // an Arrow
bf5f0ca2 158 Prs3d_Arrow::Draw (aGroup,
a6eb515f 159 pt2,
160 dir2,
161 LA->ArrowAspect()->Angle(),
162 LA->ArrowAspect()->Length());
bf5f0ca2 163
164 // a Round
165 if (drawFromCenter)
166 {
167 Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
168 anArrayOfPoints->AddVertex (pt1.X(), pt1.Y(), pt1.Z());
169 aGroup->SetPrimitivesAspect (aMarkerAsp);
170 aGroup->AddPrimitiveArray (anArrayOfPoints);
171 }
7fd59977 172 break;
173 }
174 }
175}
176
177
178//=======================================================================
179//function : ComputePlanarFacesLengthPresentation
180//purpose :
181//=======================================================================
182
183void DsgPrs::ComputePlanarFacesLengthPresentation( const Standard_Real FirstArrowLength,
184 const Standard_Real SecondArrowLength,
185 const gp_Pnt& AttachmentPoint1,
186 const gp_Pnt& AttachmentPoint2,
187 const gp_Dir& DirAttach,
188 const gp_Pnt& OffsetPoint,
189 const gp_Pln& PlaneOfFaces,
190 gp_Pnt & EndOfArrow1,
191 gp_Pnt & EndOfArrow2,
192 gp_Dir & DirOfArrow1 )
193{
194 gp_Lin FirstLin( AttachmentPoint1, DirAttach );
195 gp_Lin SecondLin( AttachmentPoint2, DirAttach );
196
197 EndOfArrow1 = ElCLib::Value( ElCLib::Parameter( FirstLin, OffsetPoint ), FirstLin );
198 EndOfArrow2 = ElCLib::Value( ElCLib::Parameter( SecondLin, OffsetPoint ), SecondLin );
199
08cd2f6b 200 if (EndOfArrow1.SquareDistance( EndOfArrow2 ) > Precision::SquareConfusion()) // not null length
7fd59977 201 {
202 gp_Dir LengthDir( gp_Vec( EndOfArrow1, EndOfArrow2 ) );
203 if ((FirstArrowLength + SecondArrowLength)*(FirstArrowLength + SecondArrowLength) <
204 EndOfArrow1.SquareDistance( EndOfArrow2 ))
205 DirOfArrow1 = -LengthDir;
206 else
207 DirOfArrow1 = LengthDir;
208 }
209 else // null length
210 DirOfArrow1 = PlaneOfFaces.Axis().Direction();
211}
212
213//=======================================================================
214//function : ComputeCurvilinearFacesLengthPresentation
215//purpose :
216//=======================================================================
217
218void DsgPrs::ComputeCurvilinearFacesLengthPresentation( const Standard_Real FirstArrowLength,
219 const Standard_Real SecondArrowLength,
220 const Handle( Geom_Surface )& SecondSurf,
221 const gp_Pnt& AttachmentPoint1,
222 const gp_Pnt& AttachmentPoint2,
223 const gp_Dir& DirAttach,
224 gp_Pnt & EndOfArrow2,
225 gp_Dir & DirOfArrow1,
226 Handle( Geom_Curve )& VCurve,
227 Handle( Geom_Curve )& UCurve,
228 Standard_Real & FirstU,
229 Standard_Real & deltaU,
230 Standard_Real & FirstV,
231 Standard_Real & deltaV )
232{
233 GeomAPI_ProjectPointOnSurf ProjectorOnSurface;
234 GeomAPI_ProjectPointOnCurve ProjectorOnCurve;
ee2be2a8 235 Standard_Real U1, V1, U2, V2;
7fd59977 236 Standard_Real LastU, LastV;
08cd2f6b 237 Standard_Real SquareTolerance = Precision::SquareConfusion();
7fd59977 238
239 ProjectorOnSurface.Init( AttachmentPoint1, SecondSurf );
240 Standard_Integer Index(1);
ee2be2a8 241 Standard_Real MinDist = RealLast();
242 Standard_Real LocalU, LocalV;
7fd59977 243 gp_Vec D1U, D1V;
244 gp_Dir LocalDir;
245 for (Standard_Integer i = 1; i <= ProjectorOnSurface.NbPoints(); i++)
246 {
247 ProjectorOnSurface.Parameters( i, LocalU, LocalV );
248
249 SecondSurf->D1( LocalU, LocalV, EndOfArrow2, D1U, D1V );
250 if (D1U.SquareMagnitude() <= SquareTolerance || D1V.SquareMagnitude() <= SquareTolerance)
251 LocalDir = gp_Dir( gp_Vec( AttachmentPoint1, ProjectorOnSurface.Point( i ) ) );
252 else
253 LocalDir = gp_Dir( D1U ^ D1V );
254 if (DirAttach.IsParallel( LocalDir, Precision::Angular() ) && ProjectorOnSurface.Distance( i ) < MinDist)
255 {
256 Index = i;
257 MinDist = ProjectorOnSurface.Distance( i );
258 }
259 }
260 EndOfArrow2 = ProjectorOnSurface.Point( Index );
261 ProjectorOnSurface.Parameters( Index, U1, V1 );
262
263 if ((FirstArrowLength + SecondArrowLength)*(FirstArrowLength + SecondArrowLength) <
264 AttachmentPoint1.SquareDistance( EndOfArrow2 ))
265 DirOfArrow1 = -DirAttach;
266 else
267 DirOfArrow1 = DirAttach;
268
08cd2f6b 269 if (EndOfArrow2.SquareDistance( AttachmentPoint2 ) > Precision::SquareConfusion())
7fd59977 270 {
271 VCurve = SecondSurf->VIso( V1 );
272 ProjectorOnCurve.Init( EndOfArrow2, VCurve );
273 FirstU = ProjectorOnCurve.LowerDistanceParameter();
274
275 ProjectorOnSurface.Init( AttachmentPoint2, SecondSurf );
276 ProjectorOnSurface.LowerDistanceParameters( U2, V2 );
277 UCurve = SecondSurf->UIso( U2 );
278
279 ProjectorOnCurve.Init( AttachmentPoint2, UCurve );
280 LastV = ProjectorOnCurve.LowerDistanceParameter();
281
282 gp_Pnt Intersection = SecondSurf->Value( U2, V1 );
283 ProjectorOnCurve.Init( Intersection, VCurve );
284 LastU = ProjectorOnCurve.LowerDistanceParameter();
285 ProjectorOnCurve.Init( Intersection, UCurve );
286 FirstV = ProjectorOnCurve.LowerDistanceParameter();
287
288 deltaU = LastU - FirstU;
289 deltaV = LastV - FirstV;
290
291 if (VCurve->IsPeriodic() && Abs( deltaU ) > VCurve->Period()/2)
292 {
293 Standard_Real Sign = (deltaU > 0.0)? -1.0 : 1.0;
294 deltaU = VCurve->Period() - Abs( deltaU );
295 deltaU *= Sign;
296 }
297 if (UCurve->IsPeriodic() && Abs( deltaV ) > UCurve->Period()/2)
298 {
299 Standard_Real Sign = (deltaV > 0.0)? -1.0 : 1.0;
300 deltaV = UCurve->Period() - Abs( deltaV );
301 deltaV *= Sign;
302 }
303 }
304}
305
306
307//=======================================================================
308//function : ComputeFacesAnglePresentation
309//purpose :
310//=======================================================================
311
312void DsgPrs::ComputeFacesAnglePresentation( const Standard_Real ArrowLength,
313 const Standard_Real Value,
314 const gp_Pnt& CenterPoint,
315 const gp_Pnt& AttachmentPoint1,
316 const gp_Pnt& AttachmentPoint2,
317 const gp_Dir& dir1,
318 const gp_Dir& dir2,
319 const gp_Dir& axisdir,
320 const Standard_Boolean isPlane,
321 const gp_Ax1& AxisOfSurf,
322 const gp_Pnt& OffsetPoint,
323 gp_Circ & AngleCirc,
324 Standard_Real & FirstParAngleCirc,
325 Standard_Real & LastParAngleCirc,
326 gp_Pnt & EndOfArrow1,
327 gp_Pnt & EndOfArrow2,
328 gp_Dir & DirOfArrow1,
329 gp_Dir & DirOfArrow2,
330 gp_Pnt & ProjAttachPoint2,
331 gp_Circ & AttachCirc,
332 Standard_Real & FirstParAttachCirc,
333 Standard_Real & LastParAttachCirc )
334{
c6541a0c 335 if (Value > Precision::Angular() && Abs( M_PI-Value ) > Precision::Angular())
7fd59977 336 {
337 // Computing presentation of angle's arc
338 gp_Ax2 ax( CenterPoint, axisdir, dir1 );
339 AngleCirc.SetPosition( ax );
340 AngleCirc.SetRadius( CenterPoint.Distance( OffsetPoint ) );
341 gp_Vec vec1( dir1 );
342 vec1 *= AngleCirc.Radius();
343 gp_Pnt p1 = CenterPoint.Translated( vec1 );
344 gp_Vec vec2( dir2 );
345 vec2 *= AngleCirc.Radius();
346 gp_Pnt p2 = CenterPoint.Translated( vec2 );
347
348 Standard_Real Par1 = 0.;
349 Standard_Real Par2 = ElCLib::Parameter( AngleCirc, p2 );
350 Standard_Real Par0 = ElCLib::Parameter( AngleCirc, OffsetPoint );
351
352 gp_Vec PosVec( CenterPoint, OffsetPoint );
353 gp_Vec NormalOfPlane = vec1 ^ vec2;
354
355 gp_Vec Normal1 = NormalOfPlane ^ vec1;
356 gp_Vec Normal2 = NormalOfPlane ^ vec2;
357 Standard_Integer Sign1 = (PosVec * Normal1 >= 0)? 1 : -1;
358 Standard_Integer Sign2 = (PosVec * Normal2 >= 0)? 1 : -1;
359 if (Sign1 == 1 && Sign2 == -1)
360 {
361 FirstParAngleCirc = Par1;
362 LastParAngleCirc = Par2;
363 }
364 else if (Sign1 == 1 && Sign2 == 1)
365 {
366 FirstParAngleCirc = Par1;
367 LastParAngleCirc = Par0;
368 }
369 else if (Sign1 == -1 && Sign2 == 1)
370 {
c6541a0c
D
371 Par1 += M_PI;
372 Par2 += M_PI;
7fd59977 373 FirstParAngleCirc = Par1;
374 LastParAngleCirc = Par2;
375 }
376 else //Sign1 == -1 && Sign2 == -1
377 {
378 AngleCirc.SetPosition( gp_Ax2( CenterPoint, axisdir, gp_Dir( PosVec ) ) );
379 Par0 = 0.;
380 Par1 = ElCLib::Parameter( AngleCirc, p1 );
381 Par2 = ElCLib::Parameter( AngleCirc, p2 );
382 FirstParAngleCirc = Par0;
383 LastParAngleCirc = Par2;
384 }
385
386 // Computing presentation of arrows
387 EndOfArrow1 = ElCLib::Value( Par1, AngleCirc );
388 EndOfArrow2 = ElCLib::Value( Par2, AngleCirc );
389 Standard_Real beta = 0.;
390 if (AngleCirc.Radius() > Precision::Confusion())
391 beta = ArrowLength / AngleCirc.Radius();
392 gp_Pnt OriginOfArrow1 = ElCLib::Value( Par1 + beta, AngleCirc );
393 gp_Pnt OriginOfArrow2 = ElCLib::Value( Par2 - beta, AngleCirc );
394 DirOfArrow1 = gp_Dir( gp_Vec( OriginOfArrow1, EndOfArrow1 ) );
395 DirOfArrow2 = gp_Dir( gp_Vec( OriginOfArrow2, EndOfArrow2 ) );
396 if (EndOfArrow1.SquareDistance( EndOfArrow2 ) <= (ArrowLength + ArrowLength)*(ArrowLength + ArrowLength))
397 {
398 DirOfArrow1.Reverse();
399 DirOfArrow2.Reverse();
400 }
401 }
402 else // dir1 and dir2 are parallel
403 {
404 gp_Dir ArrowDir = axisdir ^ dir1;
405 DirOfArrow1 = ArrowDir;
406 DirOfArrow2 = -ArrowDir;
407 gp_Lin DirLine( AttachmentPoint1, dir1 );
408 EndOfArrow1 = ElCLib::Value( ElCLib::Parameter( DirLine, OffsetPoint ), DirLine );
409 EndOfArrow2 = EndOfArrow1;
410 }
411
412 // Line or arc from AttachmentPoint2 to its "projection"
413 gp_Lin SecondLin( CenterPoint, dir2 );
414 if (SecondLin.Contains( AttachmentPoint2, Precision::Confusion() ))
415 ProjAttachPoint2 = AttachmentPoint2;
416 else
417 {
418 if (isPlane)
419 ProjAttachPoint2 = ElCLib::Value( ElCLib::Parameter( SecondLin, AttachmentPoint2 ), SecondLin );
420 else
421 {
422 gp_Lin LineOfAxis( AxisOfSurf );
423 gp_Pnt CenterOfArc = ElCLib::Value( ElCLib::Parameter( LineOfAxis, AttachmentPoint2 ),
424 LineOfAxis );
425
426 gp_Ax2 Ax2( CenterOfArc,
427 AxisOfSurf.Direction(),
428 gp_Dir( gp_Vec( CenterOfArc, AttachmentPoint2 ) ) );
429 AttachCirc.SetPosition( Ax2 );
430 AttachCirc.SetRadius( CenterOfArc.Distance( AttachmentPoint2 ) );
431
432 GeomAPI_ExtremaCurveCurve Intersection( new Geom_Circle( AttachCirc ),
433 new Geom_Line( SecondLin ) );
434 Intersection.NearestPoints( ProjAttachPoint2, ProjAttachPoint2 );
435
436 Standard_Real U2 = ElCLib::Parameter( AttachCirc, ProjAttachPoint2 );
c6541a0c 437 if (U2 <= M_PI)
7fd59977 438 {
439 FirstParAttachCirc = 0;
440 LastParAttachCirc = U2;
441 }
442 else
443 {
444 FirstParAttachCirc = U2;
c6541a0c 445 LastParAttachCirc = 2*M_PI;
7fd59977 446 }
447 }
448 }
449}
450
451
452
35e08fe8 453void DsgPrs::ComputeFilletRadiusPresentation( const Standard_Real /*ArrowLength*/,
7fd59977 454 const Standard_Real Value,
455 const gp_Pnt & Position,
456 const gp_Dir & NormalDir,
457 const gp_Pnt & FirstPoint,
458 const gp_Pnt & SecondPoint,
459 const gp_Pnt & Center,
460 const gp_Pnt & BasePnt,
461 const Standard_Boolean drawRevers,
462 Standard_Boolean & SpecCase,
463 gp_Circ & FilletCirc,
464 Standard_Real & FirstParCirc,
465 Standard_Real & LastParCirc,
466 gp_Pnt & EndOfArrow,
467 gp_Dir & DirOfArrow,
468 gp_Pnt & DrawPosition)
469{
470 gp_Dir dir1(gp_Vec(Center, FirstPoint));
471 gp_Dir dir2(gp_Vec(Center, SecondPoint));
472 Standard_Real Angle = dir1.Angle(dir2);
c6541a0c 473 if(Angle <= Precision::Angular() || ( M_PI - Angle ) <= Precision::Angular() ||
7fd59977 474 Value <= Precision::Confusion()) SpecCase = Standard_True;
475 else SpecCase = Standard_False;
476 if ( !SpecCase )
477 {
478 // Computing presentation of fillet's arc
479 gp_Ax2 ax( Center, NormalDir, dir1 );
480 FilletCirc.SetPosition( ax );
481 FilletCirc.SetRadius( Center.Distance( FirstPoint ) ); //***
482 gp_Vec vec1( dir1 );
483 vec1 *= FilletCirc.Radius();
7fd59977 484 gp_Vec vec2( dir2 );
485 vec2 *= FilletCirc.Radius();
7fd59977 486 gp_Vec PosVec;
487 if(! Center.IsEqual( Position, Precision::Confusion() ))
488 PosVec.SetXYZ( gp_Vec(Center, Position).XYZ() );
489 else
490 PosVec.SetXYZ( (vec1.Added(vec2)).XYZ() );
491 gp_Vec NormalOfPlane = vec1 ^ vec2;
492 gp_Vec Normal1 = NormalOfPlane ^ vec1;
493 gp_Vec Normal2 = NormalOfPlane ^ vec2;
494 Standard_Integer Sign1 = (PosVec * Normal1 >= 0)? 1 : -1;
495 Standard_Integer Sign2 = (PosVec * Normal2 >= 0)? 1 : -1;
496 gp_Lin L1( Center, dir1 );
497 gp_Lin L2( Center, dir2 );
498 if ( Sign1 != Sign2 )
499 {
500 DrawPosition = Position; //***
501 gp_Dir direction(PosVec) ;
502 Standard_Real angle = dir1.Angle(direction) ;
503 if (( dir1 ^ direction) * NormalDir < 0.0e0) angle = -angle ;
c6541a0c 504 if(Sign1 == -1) angle += M_PI;
7fd59977 505 EndOfArrow = ElCLib::Value(angle, FilletCirc); //***
506
507 }
508 else
509 {
510 if(L1.Distance(Position) < L2.Distance(Position))
511 {
512 EndOfArrow = FirstPoint; //***
513 DrawPosition = ElCLib::Value(ElCLib::Parameter(L1, Position), L1);
514 }
515 else
516 {
517 EndOfArrow = SecondPoint; //***
518 DrawPosition = ElCLib::Value(ElCLib::Parameter(L2, Position), L2);
519 }
520 }
521 if((dir1^dir2).IsOpposite(NormalDir, Precision::Angular()))
522 {
523 gp_Dir newdir = NormalDir.Reversed() ;
524 gp_Ax2 axnew( Center, newdir, dir1 );
525 FilletCirc.SetPosition( axnew );
526 }
527 FirstParCirc = ElCLib::Parameter( FilletCirc, FirstPoint );
528 LastParCirc = ElCLib::Parameter( FilletCirc, SecondPoint );
7fd59977 529 }
530 else //Angle equal 0 or PI or R = 0
531 {
532 DrawPosition = Position;
533 EndOfArrow = BasePnt;
534 }
535
7fd59977 536 if(drawRevers)
537 {
538 gp_Vec Vd(DrawPosition, EndOfArrow);
539 DrawPosition.Translate(Vd *2);
540 }
541 DirOfArrow.SetXYZ(gp_Dir(gp_Vec(DrawPosition, EndOfArrow)).XYZ());
542}
543
544//=======================================================================
545//function : ComputeRadiusLine
546//purpose :
547//=======================================================================
548
549void DsgPrs::ComputeRadiusLine(const gp_Pnt & aCenter,
550 const gp_Pnt & anEndOfArrow,
551 const gp_Pnt & aPosition,
552 const Standard_Boolean drawFromCenter,
553 gp_Pnt & aRadLineOrign,
554 gp_Pnt & aRadLineEnd)
555{
556 if(drawFromCenter)
557 {
558 gp_Lin RadiusLine = gce_MakeLin( aCenter, anEndOfArrow );
559 Standard_Real PosParOnLine = ElCLib::Parameter( RadiusLine, aPosition );
560 Standard_Real EndOfArrowPar = ElCLib::Parameter( RadiusLine, anEndOfArrow );
561 if (PosParOnLine < 0.0)
562 {
563 aRadLineOrign = aPosition;
564 aRadLineEnd = anEndOfArrow;
565 }
566 else if (PosParOnLine > EndOfArrowPar)
567 {
568 aRadLineOrign = aPosition;
569 aRadLineEnd = aCenter;
570 }
571 else
572 {
573 aRadLineOrign = aCenter;
574 aRadLineEnd = anEndOfArrow;
575 }
576 }
577 else
578 {
579 aRadLineOrign = aPosition;
580 aRadLineEnd = anEndOfArrow;
581 }
582}
583
584
585//=======================================================================
586//function : DistanceFromApex
587//purpose :
588//=======================================================================
589
590Standard_Real DsgPrs::DistanceFromApex(const gp_Elips & elips,
591 const gp_Pnt & Apex,
592 const Standard_Real par)
593{
594 Standard_Real dist;
595 Standard_Real parApex = ElCLib::Parameter ( elips, Apex );
c6541a0c 596 if(parApex == 0.0 || parApex == M_PI)
7fd59977 597 {//Major case
598 if(parApex == 0.0) //pos Apex
c6541a0c 599 dist = (par < M_PI) ? par : (2*M_PI - par);
7fd59977 600 else //neg Apex
c6541a0c 601 dist = (par < M_PI) ? ( M_PI - par) : ( par - M_PI );
7fd59977 602 }
603 else
604 {// Minor case
c6541a0c 605 if(parApex == M_PI / 2) //pos Apex
7fd59977 606 {
c6541a0c 607 if(par <= parApex + M_PI && par > parApex )
7fd59977 608 dist = par - parApex;
609 else
610 {
c6541a0c
D
611 if(par > parApex + M_PI)
612 dist = 2*M_PI - par + parApex;
7fd59977 613 else
c6541a0c 614 dist = parApex - par; // 0 < par < M_PI/2
7fd59977 615 }
616 }
617 else //neg Apex == 3/2 PI
618 {
c6541a0c 619 if(par <= parApex && par >= M_PI/2)
7fd59977 620 dist = parApex - par;
621 else
622 {
623 if(par > parApex)
624 dist = par - parApex;
625 else
c6541a0c 626 dist = par + M_PI/2; // 0 < par < PI/2
7fd59977 627 }
628 }
629 }
630 return dist;
631}