0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[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-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <DsgPrs_FilletRadiusPresentation.hxx>
18
19 #include <DsgPrs.hxx>
20 #include <ElCLib.hxx>
21 #include <Geom_Circle.hxx>
22 #include <Geom_Line.hxx>
23 #include <Geom_TrimmedCurve.hxx>
24 #include <GeomAPI_ExtremaCurveCurve.hxx>
25 #include <gp_Dir.hxx>
26 #include <gp_Lin.hxx>
27 #include <gp_Pnt.hxx>
28 #include <Graphic3d_ArrayOfPolylines.hxx>
29 #include <Graphic3d_ArrayOfSegments.hxx>
30 #include <Graphic3d_AspectLine3d.hxx>
31 #include <Graphic3d_AspectMarker3d.hxx>
32 #include <Graphic3d_Group.hxx>
33 #include <Precision.hxx>
34 #include <Prs3d_Arrow.hxx>
35 #include <Prs3d_ArrowAspect.hxx>
36 #include <Prs3d_DimensionAspect.hxx>
37 #include <Prs3d_LineAspect.hxx>
38 #include <Prs3d_Presentation.hxx>
39 #include <Prs3d_Text.hxx>
40 #include <TCollection_AsciiString.hxx>
41 #include <TCollection_ExtendedString.hxx>
42
43 #include <stdio.h>
44 //=======================================================================
45 //function : Add
46 //purpose  : 
47 //=======================================================================
48 void DsgPrs_FilletRadiusPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
49                                            const Handle(Prs3d_Drawer)& aDrawer,
50                                            const Standard_Real theval,
51                                            const TCollection_ExtendedString & aText,
52                                            const gp_Pnt & aPosition,
53                                            const gp_Dir & aNormalDir,
54                                            const gp_Pnt & aBasePnt,
55                                            const gp_Pnt & aFirstPoint,
56                                            const gp_Pnt & aSecondPoint,
57                                            const gp_Pnt & aCenter,
58                                            const DsgPrs_ArrowSide ArrowPrs,
59                                            const Standard_Boolean drawRevers,
60                                                  gp_Pnt & DrawPosition,
61                                                  gp_Pnt & EndOfArrow,
62                                                  Handle(Geom_TrimmedCurve)& TrimCurve,
63                                                  Standard_Boolean & HasCircle )
64 {
65   char valcar[80];
66   sprintf(valcar,"%5.2f",theval);
67
68   Standard_Real FirstParCirc, LastParCirc;
69   Standard_Boolean SpecCase;
70   gp_Dir DirOfArrow;
71   gp_Circ FilletCirc;
72   //  gp_Pnt NewPosition, EndOfArrow;
73   Handle( Prs3d_DimensionAspect ) LA = aDrawer->DimensionAspect();
74   Prs3d_Root::CurrentGroup( aPresentation )->SetPrimitivesAspect( LA->LineAspect()->Aspect() );
75
76   Standard_Real ArrowLength = LA->ArrowAspect()->Length();
77   DsgPrs::ComputeFilletRadiusPresentation( ArrowLength,
78                                            theval,
79                                            aPosition,
80                                            aNormalDir,
81                                            aFirstPoint,
82                                            aSecondPoint,
83                                            aCenter,
84                                            aBasePnt,
85                                            drawRevers,
86                                            SpecCase,
87                                            FilletCirc,
88                                            FirstParCirc,
89                                            LastParCirc,
90                                            EndOfArrow,
91                                            DirOfArrow,
92                                            DrawPosition //NewPosition
93                                            );
94   // Creating the fillet's arc                                
95   if( !SpecCase )
96   {
97     const Standard_Real Alpha = Abs(LastParCirc - FirstParCirc);
98     const Standard_Integer NodeNumber = Max (4 , Standard_Integer (50. * Alpha / M_PI));
99     const Standard_Real delta = Alpha / ( NodeNumber - 1 );
100
101     Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(NodeNumber);
102     for (Standard_Integer i = 0 ; i < NodeNumber; i++, FirstParCirc += delta)
103           aPrims->AddVertex(ElCLib::Value( FirstParCirc, FilletCirc ));
104     Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
105
106     HasCircle = Standard_True;
107     Handle(Geom_Circle) Circle = new Geom_Circle( FilletCirc );
108     TrimCurve = new Geom_TrimmedCurve( Circle,  FirstParCirc, LastParCirc );
109   }
110   else // null or PI anle or Radius = 0
111   {
112     HasCircle = Standard_False;
113   }
114   
115   // Line from position to intersection point on fillet's circle (EndOfArrow)
116   Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
117   aPrims->AddVertex(DrawPosition);
118   aPrims->AddVertex(EndOfArrow);
119   Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
120
121   // Drawing the text
122   Prs3d_Text::Draw (Prs3d_Root::CurrentGroup (aPresentation), LA->TextAspect(), aText, DrawPosition);
123    
124   // Add presentation of arrows
125   DsgPrs::ComputeSymbol( aPresentation, LA, EndOfArrow, EndOfArrow, DirOfArrow, DirOfArrow, ArrowPrs );
126 }