0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / DrawDim / DrawDim_PlanarAngle.cxx
1 // Created on: 1996-01-12
2 // Created by: Denis PASCAL
3 // Copyright (c) 1996-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
18 #include <BRep_Tool.hxx>
19 #include <BRepAdaptor_Surface.hxx>
20 #include <DBRep_DrawableShape.hxx>
21 #include <Draw.hxx>
22 #include <Draw_Display.hxx>
23 #include <Draw_MarkerShape.hxx>
24 #include <DrawDim.hxx>
25 #include <DrawDim_PlanarAngle.hxx>
26 #include <ElCLib.hxx>
27 #include <ElSLib.hxx>
28 #include <Geom2d_CartesianPoint.hxx>
29 #include <Geom2d_Circle.hxx>
30 #include <Geom2d_Curve.hxx>
31 #include <Geom2d_Line.hxx>
32 #include <Geom2d_TrimmedCurve.hxx>
33 #include <Geom2dAPI_InterCurveCurve.hxx>
34 #include <Geom_Circle.hxx>
35 #include <Geom_Curve.hxx>
36 #include <Geom_Line.hxx>
37 #include <Geom_Plane.hxx>
38 #include <GeomAPI.hxx>
39 #include <gp.hxx>
40 #include <gp_Ax1.hxx>
41 #include <gp_Dir2d.hxx>
42 #include <gp_Pln.hxx>
43 #include <gp_Pnt.hxx>
44 #include <gp_Pnt2d.hxx>
45 #include <IntAna2d_AnaIntersection.hxx>
46 #include <Precision.hxx>
47 #include <Standard_Type.hxx>
48 #include <TCollection_AsciiString.hxx>
49 #include <TColStd_Array1OfReal.hxx>
50 #include <TopExp.hxx>
51 #include <TopoDS.hxx>
52 #include <TopoDS_Edge.hxx>
53 #include <TopoDS_Face.hxx>
54 #include <TopoDS_Shape.hxx>
55
56 IMPLEMENT_STANDARD_RTTIEXT(DrawDim_PlanarAngle,DrawDim_PlanarDimension)
57
58 //=======================================================================
59 //function : DrawDim_PlanarAngle
60 //purpose  : 
61 //=======================================================================
62 DrawDim_PlanarAngle::DrawDim_PlanarAngle (const TopoDS_Face& face, 
63                                           const TopoDS_Shape& line1,
64                                           const TopoDS_Shape& line2)
65 {
66   myPlane = face;
67   myLine1 = line1;
68   myLine2 = line2;
69   myPosition = 100;
70 }
71
72 //=======================================================================
73 //function : DrawDim_PlanarAngle
74 //purpose  : 
75 //=======================================================================
76
77 DrawDim_PlanarAngle::DrawDim_PlanarAngle (const TopoDS_Shape& line1,
78                                           const TopoDS_Shape& line2)
79 {
80   myLine1 = line1;
81   myLine2 = line2;  
82   myPosition = 100;
83 }
84
85 //=======================================================================
86 //function : Sector
87 //purpose  : 
88 //=======================================================================
89
90 void DrawDim_PlanarAngle::Sector (const Standard_Boolean reversed, const Standard_Boolean inverted)
91 {   
92   myIsReversed = reversed;
93   myIsInverted = inverted;
94 }
95
96 //=======================================================================
97 //function : Position
98 //purpose  : 
99 //=======================================================================
100
101 void DrawDim_PlanarAngle::Position (const Standard_Real value)
102 {   
103   myPosition = value;
104 }
105
106
107 //=======================================================================
108 //function : DrawOn
109 //purpose  : line1^line2 suppose positifs
110 //=======================================================================
111
112 void DrawDim_PlanarAngle::DrawOn(Draw_Display& dis) const 
113 {      
114   Standard_Boolean clockwise = myIsReversed;
115   Standard_Boolean parallel  = !myIsInverted;
116   // geometrie
117   gp_Pln plane = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(myPlane))->Pln();
118   //if (plane.IsNull()) return;  
119   if (!(myLine1.ShapeType() == TopAbs_EDGE)) return;
120   if (!(myLine2.ShapeType() == TopAbs_EDGE)) return;
121   Standard_Real s1,e1,s2,e2;
122   Handle(Geom_Curve) curve1 = BRep_Tool::Curve(TopoDS::Edge(myLine1),s1,e1);  
123   Handle(Geom_Curve) curve2 = BRep_Tool::Curve(TopoDS::Edge(myLine2),s2,e2);
124   if (!curve1->IsKind(STANDARD_TYPE(Geom_Line)) || !curve2->IsKind(STANDARD_TYPE(Geom_Line))) return;
125   Handle(Geom2d_Geometry) L1 = GeomAPI::To2d (curve1,plane);
126   if (L1->IsInstance(STANDARD_TYPE(Geom2d_TrimmedCurve))) {
127     L1 = Handle(Geom2d_TrimmedCurve)::DownCast (L1)->BasisCurve();
128   }
129   gp_Lin2d l1 = Handle(Geom2d_Line)::DownCast (L1)->Lin2d();   
130   Handle(Geom2d_Geometry) L2 = GeomAPI::To2d (curve2,plane);
131   if (L2->IsInstance(STANDARD_TYPE(Geom2d_TrimmedCurve))) {
132     L2 = Handle(Geom2d_TrimmedCurve)::DownCast (L2)->BasisCurve();
133   }
134   gp_Lin2d l2 = Handle(Geom2d_Line)::DownCast (L2)->Lin2d(); 
135   //
136   IntAna2d_AnaIntersection inter;
137   inter.Perform(l1,l2);  
138   if (!inter.IsDone() || !inter.NbPoints()) return;
139   gp_Pnt2d pinter = inter.Point(1).Value();
140   //  
141   Standard_Real angle;
142   angle =  Abs(l1.Direction().Angle(l2.Direction()));
143   gp_Circ2d c (gp_Ax2d (pinter,l1.Direction()),myPosition);
144
145   // retour au plan
146   Handle(Geom_Curve) C = GeomAPI::To3d (new Geom2d_Circle(c),plane); 
147   gp_Circ circle = Handle(Geom_Circle)::DownCast (C)->Circ(); 
148   //
149   Standard_Real p1=0., p2=0.;   
150   angle =  Abs(angle);
151   if (parallel && !clockwise)  {
152     p1 = 0.0;
153     p2 = angle;
154     dis.Draw(circle,0.0,angle);
155   }
156   if (!parallel && !clockwise) {
157     p1 = angle;
158     p2 = M_PI;
159   }
160   if (parallel && clockwise) {
161     p1 = M_PI;
162     p2 = M_PI+angle;
163   }
164   if (!parallel && clockwise) {
165     p1 = M_PI+angle;
166     p2 = 2*M_PI;
167   }
168   // affichage
169   dis.Draw(circle,p1,p2);
170   Standard_Real ptext = (p1+p2)/2;
171   gp_Pnt pnttext = ElCLib::Value(ptext,circle);
172   //
173   DrawText(pnttext,dis);
174 }