442f004855fc7520cf27f3ba4839cfe8e970d6bf
[occt.git] / src / DsgPrs / DsgPrs_FilletRadiusPresentation.cxx
1 // Created on: 1997-12-08
2 // Created by: Serguei ZARITCHNY
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22
23 #include <DsgPrs_FilletRadiusPresentation.ixx>
24
25 #include <gp_Lin.hxx>
26 #include <gp_Dir.hxx>
27 #include <ElCLib.hxx>
28 #include <Graphic3d_Group.hxx>
29 #include <Graphic3d_Array1OfVertex.hxx>
30 #include <Prs3d_LengthAspect.hxx>
31 #include <Prs3d_Arrow.hxx>
32 #include <Prs3d_ArrowAspect.hxx>
33 #include <Prs3d_LineAspect.hxx>
34 #include <Prs3d_Text.hxx>
35 #include <TCollection_AsciiString.hxx>
36 #include <TCollection_ExtendedString.hxx>
37
38 #include <ElCLib.hxx>
39
40 #include <Graphic3d_Vertex.hxx>
41 #include <Graphic3d_AspectMarker3d.hxx>
42 #include <Graphic3d_AspectLine3d.hxx>
43 #include <Aspect_TypeOfLine.hxx>
44 #include <Aspect_TypeOfMarker.hxx>
45 #include <Aspect_AspectMarker.hxx>
46 #include <Quantity_Color.hxx>
47 #include <DsgPrs.hxx>
48 #include <Precision.hxx>
49
50 #include <Geom_Circle.hxx>
51 #include <Geom_Line.hxx>
52 #include <GeomAPI_ExtremaCurveCurve.hxx>
53
54 //pop pour NT
55 //#if WNT
56 #include <stdio.h>
57 //#endif
58 //=======================================================================
59 //function : Add
60 //purpose  : 
61 //=======================================================================
62
63 void DsgPrs_FilletRadiusPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
64                                            const Handle(Prs3d_Drawer)& aDrawer,
65                                            const Standard_Real theval,
66                                            const TCollection_ExtendedString & aText,
67                                            const gp_Pnt & aPosition,
68                                            const gp_Dir & aNormalDir,
69                                            const gp_Pnt & aBasePnt,
70                                            const gp_Pnt & aFirstPoint,
71                                            const gp_Pnt & aSecondPoint,
72                                            const gp_Pnt & aCenter,
73                                            const DsgPrs_ArrowSide ArrowPrs,
74                                            const Standard_Boolean drawRevers,
75                                                  gp_Pnt & DrawPosition,
76                                                  gp_Pnt & EndOfArrow,
77                                                  Handle(Geom_TrimmedCurve)& TrimCurve,
78                                                  Standard_Boolean & HasCircle )
79 {
80   char valcar[80];
81   sprintf(valcar,"%5.2f",theval);
82   Standard_Real FirstParCirc, LastParCirc;
83   Standard_Boolean SpecCase;
84   gp_Dir DirOfArrow;
85   gp_Circ FilletCirc;
86   //  gp_Pnt NewPosition, EndOfArrow;
87   Handle( Prs3d_LengthAspect ) LA = aDrawer->LengthAspect();
88   Prs3d_Root::CurrentGroup( aPresentation )->SetPrimitivesAspect( LA->LineAspect()->Aspect() );
89   Standard_Real ArrowLength = LA->Arrow1Aspect()->Length();
90   DsgPrs::ComputeFilletRadiusPresentation( ArrowLength,
91                                            theval,
92                                            aPosition,
93                                            aNormalDir,
94                                            aFirstPoint,
95                                            aSecondPoint,
96                                            aCenter,
97                                            aBasePnt,
98                                            drawRevers,
99                                            SpecCase,
100                                            FilletCirc,
101                                            FirstParCirc,
102                                            LastParCirc,
103                                            EndOfArrow,
104                                            DirOfArrow,
105                                            DrawPosition //NewPosition
106                                            );
107   // Creating the fillet's arc                                
108   if( !SpecCase )
109     {
110       Standard_Real Alpha = Abs(LastParCirc - FirstParCirc);
111       Standard_Integer NodeNumber = Max (4 , Standard_Integer (50. * Alpha / M_PI));
112       Graphic3d_Array1OfVertex ApproxArc( 0, NodeNumber-1 );
113       Standard_Real delta = Alpha / ( NodeNumber - 1 );
114       gp_Pnt CurPnt;
115       for (Standard_Integer i = 0 ; i < NodeNumber; i++)
116         {
117           CurPnt =  ElCLib::Value( FirstParCirc, FilletCirc );
118           ApproxArc(i).SetCoord( CurPnt.X(), CurPnt.Y(), CurPnt.Z() );
119           FirstParCirc += delta ;
120         }
121       Prs3d_Root::CurrentGroup( aPresentation )->Polyline( ApproxArc );
122       HasCircle = Standard_True;
123       Handle(Geom_Circle) Circle = new Geom_Circle( FilletCirc );
124       TrimCurve = new Geom_TrimmedCurve( Circle,  FirstParCirc, LastParCirc );
125     }
126   else // null or PI anle or Radius = 0
127     {
128       HasCircle = Standard_False;
129     }
130   
131   // Line from position to intersection point on fillet's circle (EndOfArrow)
132   Graphic3d_Array1OfVertex Vrap(1,2);
133   Vrap(1).SetCoord(DrawPosition.X(),
134                    DrawPosition.Y(),
135                    DrawPosition.Z());
136   Vrap(2).SetCoord( EndOfArrow.X(), EndOfArrow.Y(), EndOfArrow.Z() );
137   Prs3d_Root::CurrentGroup( aPresentation )->Polyline( Vrap );
138   // Drawing the text
139   Prs3d_Text::Draw(aPresentation, LA->TextAspect(), aText, DrawPosition);
140    
141   // Add presentation of arrows
142   DsgPrs::ComputeSymbol( aPresentation, LA, EndOfArrow, EndOfArrow, DirOfArrow, DirOfArrow, ArrowPrs );
143   
144 }
145