1 // Created on: 1995-02-07
2 // Copyright (c) 1995-1999 Matra Datavision
3 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
22 #include <DsgPrs_AnglePresentation.ixx>
26 #include <Graphic3d_Group.hxx>
27 #include <Graphic3d_Array1OfVertex.hxx>
28 #include <Prs3d_AngleAspect.hxx>
29 #include <Prs3d_Arrow.hxx>
30 #include <Prs3d_ArrowAspect.hxx>
31 #include <Prs3d_LineAspect.hxx>
32 #include <Prs3d_LengthAspect.hxx>
33 #include <Prs3d_Text.hxx>
34 #include <TCollection_AsciiString.hxx>
35 #include <TCollection_ExtendedString.hxx>
39 #include <Graphic3d_Vertex.hxx>
40 #include <Graphic3d_AspectMarker3d.hxx>
41 #include <Graphic3d_AspectLine3d.hxx>
42 #include <Aspect_TypeOfLine.hxx>
43 #include <Aspect_TypeOfMarker.hxx>
44 #include <Aspect_AspectMarker.hxx>
45 #include <Quantity_Color.hxx>
47 #include <Precision.hxx>
49 #include <Geom_Circle.hxx>
50 #include <Geom_Line.hxx>
51 #include <GeomAPI_ExtremaCurveCurve.hxx>
52 #include <GC_MakeCircle.hxx>
53 #include <gce_MakePln.hxx>
55 #include <UnitsAPI.hxx>
63 static Standard_Integer AboveInBelowCone(gp_Circ CMax, gp_Circ CMin, gp_Circ C);
66 //==========================================================================
67 // function : DsgPrs_AnglePresentation::Add
68 // purpose : draws the presentation of the cone's angle;
69 //==========================================================================
70 void DsgPrs_AnglePresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
71 const Handle(Prs3d_Drawer)& aDrawer,
72 const Standard_Real aVal,
73 const TCollection_ExtendedString& aText,
74 const gp_Circ& aCircle,
75 const gp_Pnt& aPosition,
77 const gp_Circ& VminCircle,
78 const gp_Circ& VmaxCircle,
79 const Standard_Real aArrowSize)
84 Handle(Prs3d_AngleAspect) anAngleAspect = aDrawer->AngleAspect();
85 Handle(Prs3d_LengthAspect) aLengthAspect = aDrawer->LengthAspect();
86 Standard_Real myArrowSize;
88 TCollection_ExtendedString txt = aText;
89 if( aArrowSize == 0.0 ) myArrowSize = aCircle.Radius()/ 10.;
90 else myArrowSize = aArrowSize;
92 anAngleAspect->ArrowAspect()->SetLength(myArrowSize);
93 aDrawer->ArrowAspect()->SetLength(myArrowSize);
95 Standard_Boolean IsArrowOut = Standard_True; //Is arrows inside or outside of the cone
96 Standard_Boolean IsConeTrimmed = Standard_False;
97 gp_Circ myCircle = aCircle;
100 if( VminCircle.Radius() > 0.01 ) {
101 IsConeTrimmed = Standard_True;
102 if( AboveInBelowCone( VmaxCircle, VminCircle, myCircle ) == 1 ) myCircle = VminCircle;
105 gp_Pnt AttachmentPnt;
110 Quantity_Length X,Y,Z;
112 Standard_Real param = 0.; //ElCLib::Parameter(myCircle, aPosition);
115 gp_Pnt P1 = ElCLib::Value(0., myCircle);
116 gp_Pnt P2 = ElCLib::Value(M_PI, myCircle);
118 gce_MakePln mkPln(P1, P2, aPnt); // create a plane whitch defines plane for projection aPosition on it
120 gp_Vec aVector( mkPln.Value().Location(), aPosition ); //project aPosition on a plane
121 gp_Vec Normal = mkPln.Value().Axis().Direction();
122 Normal = (aVector * Normal) * Normal;
125 aPnt = aPnt.Translated( -Normal );
129 if( aPnt.Distance(P1) < aPnt.Distance(P2) ){
138 aPnt = AttachmentPnt ; // Creating of circle whitch defines a plane for a dimension arc
139 gp_Vec Vec(AttachmentPnt, Apex); // Dimension arc is a part of the circle
142 GC_MakeCircle mkCirc(AttachmentPnt, OppositePnt, aPnt);
143 gp_Circ aCircle2 = mkCirc.Value()->Circ();
146 Standard_Real AttParam = ElCLib::Parameter(aCircle2, AttachmentPnt); //must be equal to zero (look circle construction)
147 Standard_Real OppParam = ElCLib::Parameter(aCircle2, OppositePnt);
150 while ( AttParam >= 2 * M_PI ) AttParam -= 2 * M_PI;
151 while ( OppParam >= 2 * M_PI ) OppParam -= 2 * M_PI;
153 //-------------------------- Compute angle ------------------------
154 if( txt.Length() == 0 ) {
155 Standard_Real angle = UnitsAPI::CurrentFromLS( Abs( OppParam ),"PLANE ANGLE");
157 sprintf(res, "%g", angle );
158 txt = TCollection_ExtendedString(res);
160 //-----------------------------------------------------------------
164 if( ElCLib::Parameter(aCircle2, tmpPnt) < OppParam )
165 // if( aPosition.Distance( myCircle.Location() ) <= myCircle.Radius() )
166 if( 2 * myCircle.Radius() > 4 * myArrowSize ) IsArrowOut = Standard_False; //four times more than an arrow size
169 Graphic3d_Array1OfVertex V(1, 12);
172 // param = ElCLib::Parameter(aCircle2, tmpPnt);
173 angle = OppParam - AttParam;
177 aDir = gp_Dir( ( gp_Vec( ElCLib::Value( AttParam - M_PI / 12, aCircle2 ), AttachmentPnt) ) );
178 aDir2 = gp_Dir( ( gp_Vec( ElCLib::Value( OppParam + M_PI / 12, aCircle2 ), OppositePnt) ) );
181 aDir = gp_Dir( ( gp_Vec( ElCLib::Value( AttParam + M_PI / 12, aCircle2 ), AttachmentPnt ) ) );
182 aDir2 = gp_Dir( ( gp_Vec( ElCLib::Value( OppParam - M_PI / 12, aCircle2 ), OppositePnt ) ) );
185 while ( angle > 2 * M_PI ) angle -= 2 * M_PI;
186 for( i = 0; i <= 11; i++ ) { //calculating of arc
187 ( ElCLib::Value(param + angle/11 * i, aCircle2) ).Coord(X, Y, Z);
188 V(i+1).SetCoord(X, Y, Z);
191 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V); //add the arc
193 DsgPrs::ComputeSymbol(aPresentation, anAngleAspect, AttachmentPnt,
194 AttachmentPnt, aDir, aDir, DsgPrs_AS_LASTAR);
195 DsgPrs::ComputeSymbol(aPresentation, anAngleAspect, OppositePnt,
196 OppositePnt, aDir2, aDir2, DsgPrs_AS_LASTAR);
198 param = ElCLib::Parameter(aCircle2, tmpPnt);
199 tmpPnt = ElCLib::Value(param, aCircle2);
200 tmpPnt = tmpPnt.Translated(gp_Vec(0, 0, -1)*2);
201 Prs3d_Text::Draw(aPresentation,aLengthAspect->TextAspect(), txt, tmpPnt); //add the TCollection_ExtendedString
203 angle = 2 * M_PI - param ;
204 if( param > OppParam ) {
205 while ( angle > 2 * M_PI ) angle -= 2 * M_PI;
206 for( i = 11; i >= 0; i-- ) { //calculating of arc
207 ( ElCLib::Value(-angle/11 * i, aCircle2) ).Coord(X, Y, Z);
208 V(i+1).SetCoord(X, Y, Z);
211 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V); //add additional line
214 if( AboveInBelowCone( VmaxCircle, VminCircle, myCircle ) == 1 && !IsConeTrimmed ) { //above
215 Graphic3d_Array1OfVertex V2(1,3);
216 AttachmentPnt.Coord(X, Y, Z);
217 V2(1).SetCoord(X, Y, Z);
219 V2(2).SetCoord(X, Y, Z);
220 OppositePnt.Coord(X, Y, Z);
221 V2(3).SetCoord(X, Y, Z);
223 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V2); //add the additional lines
227 if ( AboveInBelowCone( VmaxCircle, VminCircle, myCircle ) == 0 ) return;
228 Graphic3d_Array1OfVertex V3(1,2);
229 gp_Pnt P11 = ElCLib::Value( 0., VmaxCircle );
230 gp_Pnt P12 = ElCLib::Value( M_PI, VmaxCircle );
232 AttachmentPnt.Coord(X, Y, Z);
233 V3(1).SetCoord(X, Y, Z);
234 if( aPnt.Distance(P1) < aPnt.Distance(P2) ) P12.Coord(X, Y, Z);
235 else P11.Coord(X, Y, Z);
236 V3(2).SetCoord(X, Y, Z);
238 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V3);
240 OppositePnt.Coord(X, Y, Z);
241 V3(1).SetCoord(X, Y, Z);
242 if( aPnt.Distance(P1) < aPnt.Distance(P2) ) P11.Coord(X, Y, Z);
243 else P12.Coord(X, Y, Z);
244 V3(2).SetCoord(X, Y, Z);
246 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V3);
250 //------------------------------------------------------------------------------------------------------------------
251 // Returns 1 if C is above of CMin; 0 if C is bitween CMin and CMax; -1 if C is Below CMax
252 //-----------------------------------------------------------------------------------------------------------------
253 static Standard_Integer AboveInBelowCone(gp_Circ CMax, gp_Circ CMin, gp_Circ C)
255 Standard_Real D, D1, D2;
257 D = CMax.Location().Distance( CMin.Location() );
258 D1 = CMax.Location().Distance( C.Location() );
259 D2 = CMin.Location().Distance( C.Location() );
262 if ( D >= D1 && D >= D2 ) return 0;
263 if ( D < D2 && D1 < D2 ) return -1;
264 if ( D < D1 && D2 < D1 ) return 1;
270 //==========================================================================
271 // function : DsgPrs_AnglePresentation::Add
274 //==========================================================================
276 void DsgPrs_AnglePresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
277 const Handle(Prs3d_Drawer)& aDrawer,
278 const Standard_Real theval,
279 const TCollection_ExtendedString& aText,
280 const gp_Pnt& CenterPoint,
281 const gp_Pnt& AttachmentPoint1,
282 const gp_Pnt& AttachmentPoint2,
285 const gp_Dir& axisdir,
286 const gp_Pnt& OffsetPoint) {
288 sprintf(valcar,"%5.2f",theval);
290 Handle(Prs3d_AngleAspect) LA = aDrawer->AngleAspect();
291 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
293 gp_Ax2 ax(CenterPoint,axisdir,dir1);
294 gp_Circ cer(ax,CenterPoint.Distance(OffsetPoint));
296 vec1 *= cer.Radius();
300 CenterPoint.Translated(vec1);
302 vec2 *= cer.Radius();
303 gp_Pnt p2 = CenterPoint.Translated(vec2);
305 Standard_Real uc1 = 0.;
306 Standard_Real uc2 = ElCLib::Parameter(cer,p2);
307 Standard_Real uco = ElCLib::Parameter(cer,OffsetPoint);
309 Standard_Real udeb = uc1;
310 Standard_Real ufin = uc2;
313 if (Abs(theval)<M_PI) {
314 // test if uco is in the opposite sector
315 if (uco > udeb+M_PI && uco < ufin+M_PI){
325 if ((uco-uc2) < (uc1-uco+(2*M_PI))) {
333 Standard_Real alpha = Abs(ufin-udeb);
334 Standard_Integer nbp = Max (4 , Standard_Integer (50. * alpha / M_PI));
335 Graphic3d_Array1OfVertex V(1,nbp);
336 Standard_Real dteta = alpha/(nbp-1);
338 for (Standard_Integer i = 1; i<=nbp; i++) {
339 ptcur = ElCLib::Value(udeb+ dteta*(i-1),cer);
340 V(i).SetCoord(ptcur.X(),ptcur.Y(),ptcur.Z());
342 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
344 Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,OffsetPoint);
348 ElCLib::D1(uc1,cer,ptarr,vecarr);
349 gp_Ax1 ax1(ptarr, axisdir);
350 gp_Dir dirarr(-vecarr);
351 //calculate angle of rotation
352 Standard_Real beta(0.);
353 Standard_Real length = LA->ArrowAspect()->Length();
354 if (length < Precision::Confusion()) length = 1.e-04;
355 gp_Pnt ptarr2(ptarr.XYZ() + length*dirarr.XYZ());
356 Standard_Real parcir = ElCLib::Parameter(cer, ptarr2);
357 gp_Pnt ptarr3 = ElCLib::Value(parcir, cer);
358 gp_Vec v1(ptarr,ptarr2 );
359 gp_Vec v2(ptarr, ptarr3);
361 dirarr.Rotate(ax1, beta);
362 Prs3d_Arrow::Draw(aPresentation,
365 LA->ArrowAspect()->Angle(),
368 Graphic3d_Array1OfVertex Vrap(1,2);
369 Vrap(1).SetCoord(AttachmentPoint1.X(),
370 AttachmentPoint1.Y(),
371 AttachmentPoint1.Z());
372 Vrap(2).SetCoord(ptarr.X(),ptarr.Y(),ptarr.Z());
373 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(Vrap);
375 ElCLib::D1(uc2,cer,ptarr,vecarr);
376 ax1.SetLocation(ptarr);
377 gp_Dir dirarr2(vecarr);
378 dirarr2.Rotate(ax1,-beta);
379 Prs3d_Arrow::Draw(aPresentation,
382 LA->ArrowAspect()->Angle(),
385 Vrap(1).SetCoord(AttachmentPoint2.X(),
386 AttachmentPoint2.Y(),
387 AttachmentPoint2.Z());
388 Vrap(2).SetCoord(ptarr.X(),ptarr.Y(),ptarr.Z());
389 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(Vrap);
393 //==========================================================================
394 // function : DsgPrs_AnglePresentation::Add
395 // purpose : Adds prezentation of angle between two faces
396 //==========================================================================
398 void DsgPrs_AnglePresentation::Add( const Handle(Prs3d_Presentation)& aPresentation,
399 const Handle(Prs3d_Drawer)& aDrawer,
400 const Standard_Real theval,
401 const TCollection_ExtendedString& aText,
402 const gp_Pnt& CenterPoint,
403 const gp_Pnt& AttachmentPoint1,
404 const gp_Pnt& AttachmentPoint2,
407 const gp_Dir& axisdir,
408 const Standard_Boolean isPlane,
409 const gp_Ax1& AxisOfSurf,
410 const gp_Pnt& OffsetPoint,
411 const DsgPrs_ArrowSide ArrowPrs )
414 sprintf( valcar, "%5.2f", theval );
416 Handle( Prs3d_AngleAspect ) LA = aDrawer->AngleAspect();
417 Prs3d_Root::CurrentGroup( aPresentation )->SetPrimitivesAspect( LA->LineAspect()->Aspect() );
419 gp_Circ AngleCirc, AttachCirc;
420 Standard_Real FirstParAngleCirc, LastParAngleCirc, FirstParAttachCirc, LastParAttachCirc;
421 gp_Pnt EndOfArrow1, EndOfArrow2, ProjAttachPoint2;
422 gp_Dir DirOfArrow1, DirOfArrow2;
423 DsgPrs::ComputeFacesAnglePresentation( LA->ArrowAspect()->Length(),
446 Graphic3d_Array1OfVertex Vrap(1,2);
448 // Creating the angle's arc or line if null angle
449 if (theval > Precision::Angular() && Abs( M_PI-theval ) > Precision::Angular())
451 Standard_Real Alpha = Abs( LastParAngleCirc - FirstParAngleCirc );
452 Standard_Integer NodeNumber = Max (4 , Standard_Integer (50. * Alpha / M_PI));
453 Graphic3d_Array1OfVertex ApproxArc( 0, NodeNumber-1 );
454 Standard_Real delta = Alpha / (Standard_Real)( NodeNumber - 1 );
456 for (Standard_Integer i = 0 ; i < NodeNumber; i++)
458 CurPnt = ElCLib::Value( FirstParAngleCirc, AngleCirc );
459 ApproxArc(i).SetCoord( CurPnt.X(), CurPnt.Y(), CurPnt.Z() );
460 FirstParAngleCirc += delta ;
462 Prs3d_Root::CurrentGroup( aPresentation )->Polyline( ApproxArc );
466 Vrap(1).SetCoord( OffsetPoint.X(),
469 Vrap(2).SetCoord( EndOfArrow1.X(), EndOfArrow1.Y(), EndOfArrow1.Z() );
470 Prs3d_Root::CurrentGroup( aPresentation )->Polyline( Vrap );
473 // Add presentation of arrows
474 DsgPrs::ComputeSymbol( aPresentation, LA, EndOfArrow1, EndOfArrow2, DirOfArrow1, DirOfArrow2, ArrowPrs );
477 Prs3d_Text::Draw( aPresentation, LA->TextAspect(), aText, OffsetPoint );
479 // Line from AttachmentPoint1 to end of Arrow1
480 Vrap(1).SetCoord(AttachmentPoint1.X(),
481 AttachmentPoint1.Y(),
482 AttachmentPoint1.Z());
483 Vrap(2).SetCoord( EndOfArrow1.X(), EndOfArrow1.Y(), EndOfArrow1.Z() );
484 Prs3d_Root::CurrentGroup( aPresentation )->Polyline( Vrap );
486 // Line or arc from AttachmentPoint2 to its "projection"
487 if (AttachmentPoint2.Distance( ProjAttachPoint2 ) > Precision::Confusion())
491 // Creating the line from AttachmentPoint2 to its projection
492 Vrap(1).SetCoord( AttachmentPoint2.X(),
493 AttachmentPoint2.Y(),
494 AttachmentPoint2.Z() );
495 Vrap(2).SetCoord( ProjAttachPoint2.X(),
496 ProjAttachPoint2.Y(),
497 ProjAttachPoint2.Z() );
498 Prs3d_Root::CurrentGroup( aPresentation )->Polyline( Vrap );
502 // Creating the arc from AttachmentPoint2 to its projection
503 Standard_Real Alpha = Abs( LastParAttachCirc - FirstParAttachCirc );
504 Standard_Integer NodeNumber = Max (4 , Standard_Integer (50. * Alpha / M_PI));
505 Graphic3d_Array1OfVertex ApproxArc( 0, NodeNumber-1 );
506 Standard_Real delta = Alpha / (Standard_Real)( NodeNumber - 1 );
508 for (Standard_Integer i = 0 ; i < NodeNumber; i++)
510 CurPnt = ElCLib::Value( FirstParAttachCirc, AttachCirc );
511 ApproxArc(i).SetCoord( CurPnt.X(), CurPnt.Y(), CurPnt.Z() );
512 FirstParAttachCirc += delta ;
514 Prs3d_Root::CurrentGroup( aPresentation )->Polyline( ApproxArc );
517 // Line from "projection" of AttachmentPoint2 to end of Arrow2
518 Vrap(1).SetCoord( ProjAttachPoint2.X(),
519 ProjAttachPoint2.Y(),
520 ProjAttachPoint2.Z() );
521 Vrap(2).SetCoord( EndOfArrow2.X(), EndOfArrow2.Y(), EndOfArrow2.Z());
522 Prs3d_Root::CurrentGroup( aPresentation )->Polyline( Vrap );
526 //==========================================================================
527 // function : DsgPrs_AnglePresentation::Add
530 //==========================================================================
532 void DsgPrs_AnglePresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
533 const Handle(Prs3d_Drawer)& aDrawer,
534 const Standard_Real theval,
535 const TCollection_ExtendedString& aText,
536 const gp_Pnt& CenterPoint,
537 const gp_Pnt& AttachmentPoint1,
538 const gp_Pnt& AttachmentPoint2,
541 const gp_Pnt& OffsetPoint) {
543 sprintf(valcar,"%5.2f",theval);
545 Handle(Prs3d_AngleAspect) LA = aDrawer->AngleAspect();
546 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
548 if (!dir1.IsParallel(dir2, Precision::Angular())) {
549 Norm = dir1.Crossed(dir2);
552 gp_Dir dir2B = gp_Dir(gp_Vec(CenterPoint, OffsetPoint));
553 Norm = dir1.Crossed(dir2B);
556 if (Abs(theval) > M_PI) Norm.Reverse();
558 gp_Ax2 ax(CenterPoint,Norm,dir1);
559 gp_Circ cer(ax,CenterPoint.Distance(OffsetPoint));
561 vec1 *= cer.Radius();
565 CenterPoint.Translated(vec1);
567 vec2 *= cer.Radius();
568 gp_Pnt p2 = CenterPoint.Translated(vec2);
570 Standard_Real uc1 = 0.;
571 Standard_Real uc2 = ElCLib::Parameter(cer,p2);
572 Standard_Real uco = ElCLib::Parameter(cer,OffsetPoint);
574 Standard_Real udeb = uc1;
575 Standard_Real ufin = uc2;
578 if (Abs(theval)<M_PI) {
579 // test if uco is in the opposite sector
580 if (uco > udeb+M_PI && uco < ufin+M_PI){
590 if ((uco-uc2) < (uc1-uco+(2*M_PI))) {
598 Standard_Real alpha = Abs(ufin-udeb);
599 Standard_Integer nbp = Max (4 , Standard_Integer (50. * alpha / M_PI));
600 Graphic3d_Array1OfVertex V(1,nbp);
601 Standard_Real dteta = alpha/(nbp-1);
603 for (Standard_Integer i = 1; i<=nbp; i++) {
604 ptcur = ElCLib::Value(udeb+ dteta*(i-1),cer);
605 V(i).SetCoord(ptcur.X(),ptcur.Y(),ptcur.Z());
607 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
609 Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,OffsetPoint);
613 ElCLib::D1(uc1,cer,ptarr,vecarr);
614 gp_Ax1 ax1(ptarr, Norm);
615 gp_Dir dirarr(-vecarr);
616 //calculate the angle of rotation
618 Standard_Real length = LA->ArrowAspect()->Length();
619 if (length < Precision::Confusion()) length = 1.e-04;
620 gp_Pnt ptarr2(ptarr.XYZ() + length*dirarr.XYZ());
621 Standard_Real parcir = ElCLib::Parameter(cer, ptarr2);
622 gp_Pnt ptarr3 = ElCLib::Value(parcir, cer);
623 gp_Vec v1(ptarr,ptarr2 );
624 gp_Vec v2(ptarr, ptarr3);
626 dirarr.Rotate(ax1, beta);
627 Prs3d_Arrow::Draw(aPresentation,
630 LA->ArrowAspect()->Angle(),
632 Graphic3d_Array1OfVertex Vrap(1,2);
633 Vrap(1).SetCoord(AttachmentPoint1.X(),
634 AttachmentPoint1.Y(),
635 AttachmentPoint1.Z());
636 Vrap(2).SetCoord(ptarr.X(),ptarr.Y(),ptarr.Z());
637 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(Vrap);
639 ElCLib::D1(uc2,cer,ptarr,vecarr);
640 ax1.SetLocation(ptarr);
641 gp_Dir dirarr2(vecarr);
642 dirarr2.Rotate(ax1, - beta);
643 Prs3d_Arrow::Draw(aPresentation,
646 LA->ArrowAspect()->Angle(),
649 Vrap(1).SetCoord(AttachmentPoint2.X(),
650 AttachmentPoint2.Y(),
651 AttachmentPoint2.Z());
652 Vrap(2).SetCoord(ptarr.X(),ptarr.Y(),ptarr.Z());
653 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(Vrap);
656 //==========================================================================
657 // function : DsgPrs_AnglePresentation::Add
658 // purpose : It is possible to choose the symbol of extremities of the face (arrow, point...)
659 //==========================================================================
661 void DsgPrs_AnglePresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
662 const Handle(Prs3d_Drawer)& aDrawer,
663 const Standard_Real theval,
664 const TCollection_ExtendedString& aText,
665 const gp_Pnt& CenterPoint,
666 const gp_Pnt& AttachmentPoint1,
667 const gp_Pnt& AttachmentPoint2,
670 const gp_Pnt& OffsetPoint,
671 const DsgPrs_ArrowSide ArrowPrs)
674 sprintf(valcar,"%5.2f",theval);
676 Handle(Prs3d_AngleAspect) LA = aDrawer->AngleAspect();
677 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
678 gp_Dir Norm = dir1.Crossed(dir2);
680 if (Abs(theval) > M_PI) Norm.Reverse();
682 gp_Ax2 ax(CenterPoint,Norm,dir1);
683 gp_Circ cer(ax,CenterPoint.Distance(OffsetPoint));
685 vec1 *= cer.Radius();
689 CenterPoint.Translated(vec1);
691 vec2 *= cer.Radius();
692 gp_Pnt p2 = CenterPoint.Translated(vec2);
694 Standard_Real uc1 = 0.;
695 Standard_Real uc2 = ElCLib::Parameter(cer,p2);
696 Standard_Real uco = ElCLib::Parameter(cer,OffsetPoint);
698 Standard_Real udeb = uc1;
699 Standard_Real ufin = uc2;
702 if (Abs(theval)<M_PI) {
703 // test if uco is in the opposite sector
704 if (uco > udeb+M_PI && uco < ufin+M_PI){
714 if ((uco-uc2) < (uc1-uco+(2*M_PI))) {
722 Standard_Real alpha = Abs(ufin-udeb);
723 Standard_Integer nbp = Max (4 , Standard_Integer (50. * alpha / M_PI));
724 Graphic3d_Array1OfVertex V(1,nbp);
725 Standard_Real dteta = alpha/(nbp-1);
727 for (Standard_Integer i = 1; i<=nbp; i++) {
728 ptcur = ElCLib::Value(udeb+ dteta*(i-1),cer);
729 V(i).SetCoord(ptcur.X(),ptcur.Y(),ptcur.Z());
731 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
733 Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,OffsetPoint);
738 ElCLib::D1(uc1,cer,ptarr,vecarr);
739 gp_Ax1 ax1(ptarr, Norm);
740 gp_Dir dirarr(-vecarr);
741 //calculate angle of rotation
742 Standard_Real beta(0.);
743 Standard_Real length = LA->ArrowAspect()->Length();
744 if (length < Precision::Confusion()) length = 1.e-04;
745 gp_Pnt ptarr2(ptarr.XYZ() + length*dirarr.XYZ());
746 Standard_Real parcir = ElCLib::Parameter(cer, ptarr2);
747 gp_Pnt ptarr3 = ElCLib::Value(parcir, cer);
748 gp_Vec v1(ptarr,ptarr2 );
749 gp_Vec v2(ptarr, ptarr3);
751 dirarr.Rotate(ax1, beta);
753 Graphic3d_Array1OfVertex Vrap(1,2);
754 Vrap(1).SetCoord(AttachmentPoint1.X(),
755 AttachmentPoint1.Y(),
756 AttachmentPoint1.Z());
757 Vrap(2).SetCoord(ptarr.X(),ptarr.Y(),ptarr.Z());
758 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(Vrap);
762 ElCLib::D1(uc2,cer,ptarr1,vecarr1);
763 ax1.SetLocation(ptarr1);
764 gp_Dir dirarr2(vecarr1);
765 dirarr2.Rotate(ax1, - beta);
768 Vrap(1).SetCoord(AttachmentPoint2.X(),
769 AttachmentPoint2.Y(),
770 AttachmentPoint2.Z());
771 Vrap(2).SetCoord(ptarr1.X(),ptarr1.Y(),ptarr1.Z());
772 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(Vrap);
775 // One traces the arrows
776 DsgPrs::ComputeSymbol(aPresentation,LA,ptarr,ptarr1,dirarr,dirarr2,ArrowPrs);
782 //==========================================================================
783 // function : DsgPrs_AnglePresentation::Add
786 //==========================================================================
788 void DsgPrs_AnglePresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
789 const Handle(Prs3d_Drawer)& aDrawer,
790 const Standard_Real theval,
791 const gp_Pnt& CenterPoint,
792 const gp_Pnt& AttachmentPoint1,
793 const gp_Pnt& AttachmentPoint2,
796 const gp_Pnt& OffsetPoint) {
800 sprintf(valcar,"%5.2f",theval);
801 TCollection_AsciiString valas(valcar);
802 TCollection_ExtendedString aText(valas);
804 Handle(Prs3d_AngleAspect) LA = aDrawer->AngleAspect();
805 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
806 gp_Dir Norm = dir1.Crossed(dir2);
808 if (Abs(theval) > M_PI) Norm.Reverse();
810 gp_Ax2 ax(CenterPoint,Norm,dir1);
811 gp_Circ cer(ax,CenterPoint.Distance(OffsetPoint));
813 vec1 *= cer.Radius();
817 CenterPoint.Translated(vec1);
819 vec2 *= cer.Radius();
820 gp_Pnt p2 = CenterPoint.Translated(vec2);
822 Standard_Real uc1 = 0.;
823 Standard_Real uc2 = ElCLib::Parameter(cer,p2);
824 Standard_Real uco = ElCLib::Parameter(cer,OffsetPoint);
826 Standard_Real udeb = uc1;
827 Standard_Real ufin = uc2;
830 if (Abs(theval)<M_PI) {
831 // test if uco is in the opposite sector
832 if (uco > udeb+M_PI && uco < ufin+M_PI){
842 if ((uco-uc2) < (uc1-uco+(2*M_PI))) {
850 Standard_Real alpha = Abs(ufin-udeb);
851 Standard_Integer nbp = Max (4 , Standard_Integer (50. * alpha / M_PI));
852 Graphic3d_Array1OfVertex V(1,nbp);
853 Standard_Real dteta = alpha/(nbp-1);
855 for (Standard_Integer i = 1; i<=nbp; i++) {
856 ptcur = ElCLib::Value(udeb+ dteta*(i-1),cer);
857 V(i).SetCoord(ptcur.X(),ptcur.Y(),ptcur.Z());
859 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
861 Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,OffsetPoint);
865 ElCLib::D1(uc1,cer,ptarr,vecarr);
866 gp_Ax1 ax1(ptarr, Norm);
867 gp_Dir dirarr(-vecarr);
868 //calculate the angle of rotation
870 Standard_Real length = LA->ArrowAspect()->Length();
871 if (length < Precision::Confusion()) length = 1.e-04;
872 gp_Pnt ptarr2(ptarr.XYZ() + length*dirarr.XYZ());
873 Standard_Real parcir = ElCLib::Parameter(cer, ptarr2);
874 gp_Pnt ptarr3 = ElCLib::Value(parcir, cer);
875 gp_Vec v1(ptarr,ptarr2 );
876 gp_Vec v2(ptarr, ptarr3);
878 dirarr.Rotate(ax1, beta);
879 Prs3d_Arrow::Draw(aPresentation,
882 LA->ArrowAspect()->Angle(),
885 Graphic3d_Array1OfVertex Vrap(1,2);
886 Vrap(1).SetCoord(AttachmentPoint1.X(),
887 AttachmentPoint1.Y(),
888 AttachmentPoint1.Z());
889 Vrap(2).SetCoord(ptarr.X(),ptarr.Y(),ptarr.Z());
890 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(Vrap);
892 ElCLib::D1(uc2,cer,ptarr,vecarr);
893 ax1.SetLocation(ptarr);
894 gp_Dir dirarr2(vecarr);
895 dirarr2.Rotate(ax1, - beta);
896 Prs3d_Arrow::Draw(aPresentation,
899 LA->ArrowAspect()->Angle(),
902 Vrap(1).SetCoord(AttachmentPoint2.X(),
903 AttachmentPoint2.Y(),
904 AttachmentPoint2.Z());
905 Vrap(2).SetCoord(ptarr.X(),ptarr.Y(),ptarr.Z());
906 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(Vrap);
909 void DsgPrs_AnglePresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
910 const Handle(Prs3d_Drawer)& aDrawer,
911 const Standard_Real theval,
912 const gp_Pnt& CenterPoint,
913 const gp_Pnt& AttachmentPoint1,
914 const gp_Ax1& theAxe,
915 const DsgPrs_ArrowSide ArrowSide)
917 Handle(Prs3d_AngleAspect) LA = aDrawer->AngleAspect();
918 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
920 gp_Dir dir1(gp_Vec(CenterPoint, AttachmentPoint1));
921 gp_Ax2 ax(CenterPoint,theAxe.Direction(),dir1);
922 gp_Circ cer(ax,CenterPoint.Distance(AttachmentPoint1));
924 Standard_Integer nbp = Max (4 , Standard_Integer (50. * theval / M_PI));
925 Graphic3d_Array1OfVertex V(1,nbp);
926 Standard_Real dteta = theval/(nbp-1);
928 for (Standard_Integer i = 1; i<=nbp; i++) {
929 ptcur = ElCLib::Value(dteta*(i-1),cer);
930 V(i).SetCoord(ptcur.X(),ptcur.Y(),ptcur.Z());
932 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
934 Standard_Real uc1 = 0.;
935 Standard_Real uc2 = ElCLib::Parameter(cer,AttachmentPoint1.Rotated(theAxe,theval));
939 Standard_Real length = LA->ArrowAspect()->Length();
940 if (length < Precision::Confusion()) length = 1.e-04;
947 case DsgPrs_AS_FIRSTAR:
949 ElCLib::D1(uc1,cer,ptarr,vecarr);
950 Prs3d_Arrow::Draw(aPresentation,
953 LA->ArrowAspect()->Angle(),
957 case DsgPrs_AS_LASTAR:
959 ElCLib::D1(uc2,cer,ptarr,vecarr);
960 Prs3d_Arrow::Draw(aPresentation,
963 LA->ArrowAspect()->Angle(),
967 case DsgPrs_AS_BOTHAR:
969 ElCLib::D1(uc1,cer,ptarr,vecarr);
970 Prs3d_Arrow::Draw(aPresentation,
973 LA->ArrowAspect()->Angle(),
975 ElCLib::D1(uc2,cer,ptarr,vecarr);
976 Prs3d_Arrow::Draw(aPresentation,
979 LA->ArrowAspect()->Angle(),