0024510: Remove unused local variables
[occt.git] / src / DrawDim / DrawDim_PlanarAngle.cxx
CommitLineData
b311480e 1// Created on: 1996-01-12
2// Created by: Denis PASCAL
3// Copyright (c) 1996-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 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
7fd59977 52//=======================================================================
53//function : DrawDim_PlanarAngle
54//purpose :
55//=======================================================================
56
57DrawDim_PlanarAngle::DrawDim_PlanarAngle (const TopoDS_Face& face,
58 const TopoDS_Shape& line1,
59 const TopoDS_Shape& line2)
60{
61 myPlane = face;
62 myLine1 = line1;
63 myLine2 = line2;
64 myPosition = 100;
65}
66
67//=======================================================================
68//function : DrawDim_PlanarAngle
69//purpose :
70//=======================================================================
71
72DrawDim_PlanarAngle::DrawDim_PlanarAngle (const TopoDS_Shape& line1,
73 const TopoDS_Shape& line2)
74{
75 myLine1 = line1;
76 myLine2 = line2;
77 myPosition = 100;
78}
79
80//=======================================================================
81//function : Sector
82//purpose :
83//=======================================================================
84
85void DrawDim_PlanarAngle::Sector (const Standard_Boolean reversed, const Standard_Boolean inverted)
86{
87 myIsReversed = reversed;
88 myIsInverted = inverted;
89}
90
91//=======================================================================
92//function : Position
93//purpose :
94//=======================================================================
95
96void DrawDim_PlanarAngle::Position (const Standard_Real value)
97{
98 myPosition = value;
99}
100
101
102//=======================================================================
103//function : DrawOn
104//purpose : line1^line2 suppose positifs
105//=======================================================================
106
107void DrawDim_PlanarAngle::DrawOn(Draw_Display& dis) const
108{
109 Standard_Boolean clockwise = myIsReversed;
110 Standard_Boolean parallel = !myIsInverted;
111 // geometrie
112 gp_Pln plane = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(myPlane))->Pln();
113 //if (plane.IsNull()) return;
114 if (!(myLine1.ShapeType() == TopAbs_EDGE)) return;
115 if (!(myLine2.ShapeType() == TopAbs_EDGE)) return;
116 Standard_Real s1,e1,s2,e2;
117 Handle(Geom_Curve) curve1 = BRep_Tool::Curve(TopoDS::Edge(myLine1),s1,e1);
118 Handle(Geom_Curve) curve2 = BRep_Tool::Curve(TopoDS::Edge(myLine2),s2,e2);
119 if (!curve1->IsKind(STANDARD_TYPE(Geom_Line)) || !curve2->IsKind(STANDARD_TYPE(Geom_Line))) return;
120 Handle(Geom2d_Geometry) L1 = GeomAPI::To2d (curve1,plane);
121 if (L1->IsInstance(STANDARD_TYPE(Geom2d_TrimmedCurve))) {
122 L1 = ((Handle(Geom2d_TrimmedCurve)&) L1)->BasisCurve();
123 }
124 gp_Lin2d l1 = ((Handle(Geom2d_Line)&) L1)->Lin2d();
125 Handle(Geom2d_Geometry) L2 = GeomAPI::To2d (curve2,plane);
126 if (L2->IsInstance(STANDARD_TYPE(Geom2d_TrimmedCurve))) {
127 L2 = ((Handle(Geom2d_TrimmedCurve)&) L2)->BasisCurve();
128 }
129 gp_Lin2d l2 = ((Handle(Geom2d_Line)&) L2)->Lin2d();
130 //
131 IntAna2d_AnaIntersection inter;
132 inter.Perform(l1,l2);
133 if (!inter.IsDone() || !inter.NbPoints()) return;
134 gp_Pnt2d pinter = inter.Point(1).Value();
135 //
136 Standard_Real angle;
137 angle = Abs(l1.Direction().Angle(l2.Direction()));
138 gp_Circ2d c (gp_Ax2d (pinter,l1.Direction()),myPosition);
139
140 // retour au plan
141 Handle(Geom_Curve) C = GeomAPI::To3d (new Geom2d_Circle(c),plane);
142 gp_Circ circle = ((Handle(Geom_Circle)&) C)->Circ();
143 //
144 Standard_Real p1=0., p2=0.;
145 angle = Abs(angle);
146 if (parallel && !clockwise) {
147 p1 = 0.0;
148 p2 = angle;
149 dis.Draw(circle,0.0,angle);
150 }
151 if (!parallel && !clockwise) {
152 p1 = angle;
c6541a0c 153 p2 = M_PI;
7fd59977 154 }
155 if (parallel && clockwise) {
c6541a0c
D
156 p1 = M_PI;
157 p2 = M_PI+angle;
7fd59977 158 }
159 if (!parallel && clockwise) {
c6541a0c
D
160 p1 = M_PI+angle;
161 p2 = 2*M_PI;
7fd59977 162 }
163 // affichage
164 dis.Draw(circle,p1,p2);
165 Standard_Real ptext = (p1+p2)/2;
166 gp_Pnt pnttext = ElCLib::Value(ptext,circle);
167 //
168 DrawText(pnttext,dis);
169}