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