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 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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BRep_Tool.hxx>
19 #include <BRepAdaptor_Surface.hxx>
20 #include <DBRep_DrawableShape.hxx>
22 #include <Draw_Display.hxx>
23 #include <Draw_MarkerShape.hxx>
24 #include <DrawDim.hxx>
25 #include <DrawDim_PlanarAngle.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>
41 #include <gp_Dir2d.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>
52 #include <TopoDS_Edge.hxx>
53 #include <TopoDS_Face.hxx>
54 #include <TopoDS_Shape.hxx>
56 IMPLEMENT_STANDARD_RTTIEXT(DrawDim_PlanarAngle,DrawDim_PlanarDimension)
58 //=======================================================================
59 //function : DrawDim_PlanarAngle
61 //=======================================================================
62 DrawDim_PlanarAngle::DrawDim_PlanarAngle (const TopoDS_Face& face,
63 const TopoDS_Shape& line1,
64 const TopoDS_Shape& line2)
72 //=======================================================================
73 //function : DrawDim_PlanarAngle
75 //=======================================================================
77 DrawDim_PlanarAngle::DrawDim_PlanarAngle (const TopoDS_Shape& line1,
78 const TopoDS_Shape& line2)
85 //=======================================================================
88 //=======================================================================
90 void DrawDim_PlanarAngle::Sector (const Standard_Boolean reversed, const Standard_Boolean inverted)
92 myIsReversed = reversed;
93 myIsInverted = inverted;
96 //=======================================================================
99 //=======================================================================
101 void DrawDim_PlanarAngle::Position (const Standard_Real value)
107 //=======================================================================
109 //purpose : line1^line2 suppose positifs
110 //=======================================================================
112 void DrawDim_PlanarAngle::DrawOn(Draw_Display& dis) const
114 Standard_Boolean clockwise = myIsReversed;
115 Standard_Boolean parallel = !myIsInverted;
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();
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();
134 gp_Lin2d l2 = Handle(Geom2d_Line)::DownCast (L2)->Lin2d();
136 IntAna2d_AnaIntersection inter;
137 inter.Perform(l1,l2);
138 if (!inter.IsDone() || !inter.NbPoints()) return;
139 gp_Pnt2d pinter = inter.Point(1).Value();
142 angle = Abs(l1.Direction().Angle(l2.Direction()));
143 gp_Circ2d c (gp_Ax2d (pinter,l1.Direction()),myPosition);
146 Handle(Geom_Curve) C = GeomAPI::To3d (new Geom2d_Circle(c),plane);
147 gp_Circ circle = Handle(Geom_Circle)::DownCast (C)->Circ();
149 Standard_Real p1=0., p2=0.;
151 if (parallel && !clockwise) {
154 dis.Draw(circle,0.0,angle);
156 if (!parallel && !clockwise) {
160 if (parallel && clockwise) {
164 if (!parallel && clockwise) {
169 dis.Draw(circle,p1,p2);
170 Standard_Real ptext = (p1+p2)/2;
171 gp_Pnt pnttext = ElCLib::Value(ptext,circle);
173 DrawText(pnttext,dis);