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