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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <DrawDim_PlanarAngle.ixx>
18 #include <TCollection_AsciiString.hxx>
19 #include <DrawDim.hxx>
21 #include <Draw_MarkerShape.hxx>
24 #include <Geom_Curve.hxx>
25 #include <Geom_Line.hxx>
27 #include <BRep_Tool.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>
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>
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;
60 //=======================================================================
61 //function : DrawDim_PlanarAngle
63 //=======================================================================
65 DrawDim_PlanarAngle::DrawDim_PlanarAngle (const TopoDS_Face& face,
66 const TopoDS_Shape& line1,
67 const TopoDS_Shape& line2)
75 //=======================================================================
76 //function : DrawDim_PlanarAngle
78 //=======================================================================
80 DrawDim_PlanarAngle::DrawDim_PlanarAngle (const TopoDS_Shape& line1,
81 const TopoDS_Shape& line2)
88 //=======================================================================
91 //=======================================================================
93 void DrawDim_PlanarAngle::Sector (const Standard_Boolean reversed, const Standard_Boolean inverted)
95 myIsReversed = reversed;
96 myIsInverted = inverted;
99 //=======================================================================
100 //function : Position
102 //=======================================================================
104 void DrawDim_PlanarAngle::Position (const Standard_Real value)
110 //=======================================================================
112 //purpose : line1^line2 suppose positifs
113 //=======================================================================
115 void DrawDim_PlanarAngle::DrawOn(Draw_Display& dis) const
117 Standard_Boolean clockwise = myIsReversed;
118 Standard_Boolean parallel = !myIsInverted;
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();
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();
137 gp_Lin2d l2 = ((Handle(Geom2d_Line)&) L2)->Lin2d();
139 IntAna2d_AnaIntersection inter;
140 inter.Perform(l1,l2);
141 if (!inter.IsDone() || !inter.NbPoints()) return;
142 gp_Pnt2d pinter = inter.Point(1).Value();
145 angle = Abs(l1.Direction().Angle(l2.Direction()));
146 gp_Circ2d c (gp_Ax2d (pinter,l1.Direction()),myPosition);
149 Handle(Geom_Curve) C = GeomAPI::To3d (new Geom2d_Circle(c),plane);
150 gp_Circ circle = ((Handle(Geom_Circle)&) C)->Circ();
152 Standard_Real p1=0., p2=0.;
154 if (parallel && !clockwise) {
157 dis.Draw(circle,0.0,angle);
159 if (!parallel && !clockwise) {
163 if (parallel && clockwise) {
167 if (!parallel && clockwise) {
172 dis.Draw(circle,p1,p2);
173 Standard_Real ptext = (p1+p2)/2;
174 gp_Pnt pnttext = ElCLib::Value(ptext,circle);
176 DrawText(pnttext,dis);