0023634: Eliminate Polyline and Polygon usage in drawers
[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 #include <DsgPrs_FilletRadiusPresentation.ixx>
22
23 #include <gp_Lin.hxx>
24 #include <gp_Dir.hxx>
25 #include <ElCLib.hxx>
26 #include <Graphic3d_Group.hxx>
27 #include <Graphic3d_ArrayOfSegments.hxx>
28 #include <Graphic3d_ArrayOfPolylines.hxx>
29 #include <Prs3d_LengthAspect.hxx>
30 #include <Prs3d_Arrow.hxx>
31 #include <Prs3d_ArrowAspect.hxx>
32 #include <Prs3d_LineAspect.hxx>
33 #include <Prs3d_Text.hxx>
34 #include <TCollection_AsciiString.hxx>
35 #include <TCollection_ExtendedString.hxx>
36
37 #include <ElCLib.hxx>
38
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>
46 #include <DsgPrs.hxx>
47 #include <Precision.hxx>
48
49 #include <Geom_Circle.hxx>
50 #include <Geom_Line.hxx>
51 #include <GeomAPI_ExtremaCurveCurve.hxx>
52
53 //pop pour NT
54 //#if WNT
55 #include <stdio.h>
56 //#endif
57 //=======================================================================
58 //function : Add
59 //purpose  : 
60 //=======================================================================
61
62 void DsgPrs_FilletRadiusPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
63                                            const Handle(Prs3d_Drawer)& aDrawer,
64                                            const Standard_Real theval,
65                                            const TCollection_ExtendedString & aText,
66                                            const gp_Pnt & aPosition,
67                                            const gp_Dir & aNormalDir,
68                                            const gp_Pnt & aBasePnt,
69                                            const gp_Pnt & aFirstPoint,
70                                            const gp_Pnt & aSecondPoint,
71                                            const gp_Pnt & aCenter,
72                                            const DsgPrs_ArrowSide ArrowPrs,
73                                            const Standard_Boolean drawRevers,
74                                                  gp_Pnt & DrawPosition,
75                                                  gp_Pnt & EndOfArrow,
76                                                  Handle(Geom_TrimmedCurve)& TrimCurve,
77                                                  Standard_Boolean & HasCircle )
78 {
79   char valcar[80];
80   sprintf(valcar,"%5.2f",theval);
81
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
90   Standard_Real ArrowLength = LA->Arrow1Aspect()->Length();
91   DsgPrs::ComputeFilletRadiusPresentation( ArrowLength,
92                                            theval,
93                                            aPosition,
94                                            aNormalDir,
95                                            aFirstPoint,
96                                            aSecondPoint,
97                                            aCenter,
98                                            aBasePnt,
99                                            drawRevers,
100                                            SpecCase,
101                                            FilletCirc,
102                                            FirstParCirc,
103                                            LastParCirc,
104                                            EndOfArrow,
105                                            DirOfArrow,
106                                            DrawPosition //NewPosition
107                                            );
108   // Creating the fillet's arc                                
109   if( !SpecCase )
110   {
111     const Standard_Real Alpha = Abs(LastParCirc - FirstParCirc);
112     const Standard_Integer NodeNumber = Max (4 , Standard_Integer (50. * Alpha / M_PI));
113     const Standard_Real delta = Alpha / ( NodeNumber - 1 );
114
115     Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(NodeNumber);
116     for (Standard_Integer i = 0 ; i < NodeNumber; i++, FirstParCirc += delta)
117           aPrims->AddVertex(ElCLib::Value( FirstParCirc, FilletCirc ));
118     Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
119
120     HasCircle = Standard_True;
121     Handle(Geom_Circle) Circle = new Geom_Circle( FilletCirc );
122     TrimCurve = new Geom_TrimmedCurve( Circle,  FirstParCirc, LastParCirc );
123   }
124   else // null or PI anle or Radius = 0
125   {
126     HasCircle = Standard_False;
127   }
128   
129   // Line from position to intersection point on fillet's circle (EndOfArrow)
130   Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
131   aPrims->AddVertex(DrawPosition);
132   aPrims->AddVertex(EndOfArrow);
133   Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
134
135   // Drawing the text
136   Prs3d_Text::Draw(aPresentation, LA->TextAspect(), aText, DrawPosition);
137    
138   // Add presentation of arrows
139   DsgPrs::ComputeSymbol( aPresentation, LA, EndOfArrow, EndOfArrow, DirOfArrow, DirOfArrow, ArrowPrs );
140 }