b311480e |
1 | // Created on: 1991-07-16 |
2 | // Created by: Christophe MARION |
3 | // Copyright (c) 1991-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 | // |
d5f74e42 |
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 |
973c2be1 |
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 | |
42cf5bc1 |
17 | |
18 | #include <Adaptor2d_Curve2d.hxx> |
42cf5bc1 |
19 | #include <Adaptor3d_IsoCurve.hxx> |
20 | #include <Draw_Display.hxx> |
21 | #include <DrawTrSurf_Drawable.hxx> |
7fd59977 |
22 | #include <GCPnts_UniformDeflection.hxx> |
7fd59977 |
23 | #include <Geom_BSplineCurve.hxx> |
7109a4ae |
24 | #include <Geom_BezierCurve.hxx> |
42cf5bc1 |
25 | #include <GeomAdaptor_Curve.hxx> |
26 | #include <gp_Pnt.hxx> |
27 | #include <gp_Pnt2d.hxx> |
7fd59977 |
28 | #include <Precision.hxx> |
42cf5bc1 |
29 | #include <Standard_Type.hxx> |
30 | #include <TColStd_Array1OfReal.hxx> |
7fd59977 |
31 | |
92efcf78 |
32 | IMPLEMENT_STANDARD_RTTIEXT(DrawTrSurf_Drawable,Draw_Drawable3D) |
33 | |
7fd59977 |
34 | //======================================================================= |
35 | //function : DrawTrSurf_Drawable |
36 | //purpose : initialise the discretisation |
37 | //======================================================================= |
7fd59977 |
38 | DrawTrSurf_Drawable::DrawTrSurf_Drawable ( |
39 | |
40 | const Standard_Integer discret, |
41 | const Standard_Real deflection, |
42 | const Standard_Integer DrawMode ) : |
43 | myDrawMode (DrawMode), |
44 | myDiscret(discret), |
45 | myDeflection(deflection) |
46 | { |
47 | } |
48 | |
49 | //======================================================================= |
50 | //function : DrawCurve2dOn |
51 | //purpose : draw a 2D curve |
52 | //======================================================================= |
53 | |
54 | void DrawTrSurf_Drawable::DrawCurve2dOn (Adaptor2d_Curve2d& C, |
55 | Draw_Display& aDisplay) const |
56 | { |
57 | gp_Pnt P; |
58 | |
59 | gp_Pnt2d aPoint2d, |
60 | *aPoint2dPtr ; |
61 | if (myDrawMode == 1) { |
62 | Standard_Real Fleche = myDeflection/aDisplay.Zoom(); |
63 | GCPnts_UniformDeflection LineVu(C,Fleche); |
64 | if (LineVu.IsDone()) { |
65 | P = LineVu.Value(1) ; |
66 | aPoint2dPtr = (gp_Pnt2d *) &P ; |
67 | aDisplay.MoveTo(*aPoint2dPtr); |
68 | for (Standard_Integer i = 2; i <= LineVu.NbPoints(); i++) { |
69 | P = LineVu.Value(i) ; |
70 | aPoint2dPtr = (gp_Pnt2d *) &P ; |
71 | aDisplay.DrawTo(*aPoint2dPtr); |
72 | } |
73 | } |
74 | } |
75 | else { |
76 | Standard_Integer intrv, nbintv = C.NbIntervals(GeomAbs_CN); |
77 | TColStd_Array1OfReal TI(1,nbintv+1); |
78 | C.Intervals(TI,GeomAbs_CN); |
79 | C.D0(C.FirstParameter(),aPoint2d); |
80 | aDisplay.MoveTo(aPoint2d); |
81 | for (intrv = 1; intrv <= nbintv; intrv++) { |
82 | if (C.GetType() != GeomAbs_Line) { |
83 | Standard_Real t = TI(intrv); |
84 | Standard_Real step = (TI(intrv+1) - t) / myDiscret; |
85 | for (Standard_Integer i = 1; i < myDiscret; i++) { |
86 | t += step; |
87 | C.D0(t,aPoint2d); |
88 | aDisplay.DrawTo(aPoint2d); |
89 | } |
90 | } |
91 | C.D0(TI(intrv+1),aPoint2d); |
92 | aDisplay.DrawTo(aPoint2d); |
93 | } |
94 | } |
95 | } |
96 | |
97 | //======================================================================= |
98 | //static function : PlotCurve |
99 | //purpose : draw a 3D curve |
100 | //======================================================================= |
101 | static void PlotCurve (Draw_Display& aDisplay, |
102 | const Adaptor3d_Curve& C, |
103 | Standard_Real& theFirstParam, |
104 | Standard_Real theHalfStep, |
105 | const gp_Pnt& theFirstPnt, |
106 | const gp_Pnt& theLastPnt) |
107 | { |
108 | Standard_Real IsoRatio = 1.001; |
109 | gp_Pnt Pm; |
110 | |
111 | C.D0 (theFirstParam + theHalfStep, Pm); |
112 | |
113 | Standard_Real dfLength = theFirstPnt.Distance(theLastPnt); |
114 | if (dfLength < Precision::Confusion() || |
115 | Pm.Distance(theFirstPnt) + Pm.Distance(theLastPnt) <= IsoRatio*dfLength) { |
116 | aDisplay.DrawTo (theLastPnt); |
117 | } else { |
118 | PlotCurve (aDisplay, C, theFirstParam, theHalfStep/2., theFirstPnt, Pm); |
119 | Standard_Real aLocalF = theFirstParam + theHalfStep; |
120 | PlotCurve (aDisplay, C, aLocalF, theHalfStep/2., Pm, theLastPnt); |
121 | } |
122 | } |
123 | //======================================================================= |
124 | //function : DrawCurveOn |
125 | //purpose : draw a 3D curve |
126 | //======================================================================= |
127 | |
128 | void DrawTrSurf_Drawable::DrawCurveOn (Adaptor3d_Curve& C, |
32ca7a51 |
129 | Draw_Display& aDisplay) const |
7fd59977 |
130 | { |
131 | gp_Pnt P; |
32ca7a51 |
132 | if (myDrawMode == 1) |
133 | { |
7fd59977 |
134 | Standard_Real Fleche = myDeflection/aDisplay.Zoom(); |
135 | GCPnts_UniformDeflection LineVu(C,Fleche); |
32ca7a51 |
136 | if (LineVu.IsDone()) |
137 | { |
7fd59977 |
138 | aDisplay.MoveTo(LineVu.Value(1)); |
32ca7a51 |
139 | for (Standard_Integer i = 2; i <= LineVu.NbPoints(); i++) |
140 | { |
141 | aDisplay.DrawTo(LineVu.Value(i)); |
7fd59977 |
142 | } |
32ca7a51 |
143 | } |
7fd59977 |
144 | } |
32ca7a51 |
145 | else |
146 | { |
147 | Standard_Integer j; |
7fd59977 |
148 | Standard_Integer intrv, nbintv = C.NbIntervals(GeomAbs_CN); |
149 | TColStd_Array1OfReal TI(1,nbintv+1); |
150 | C.Intervals(TI,GeomAbs_CN); |
151 | C.D0(C.FirstParameter(),P); |
152 | aDisplay.MoveTo(P); |
153 | GeomAbs_CurveType CurvType = C.GetType(); |
154 | gp_Pnt aPPnt=P, aNPnt; |
155 | |
32ca7a51 |
156 | for (intrv = 1; intrv <= nbintv; intrv++) |
157 | { |
7fd59977 |
158 | Standard_Real t = TI(intrv); |
159 | Standard_Real step = (TI(intrv+1) - t) / myDiscret; |
160 | |
32ca7a51 |
161 | switch (CurvType) |
162 | { |
163 | case GeomAbs_Line: |
164 | break; |
165 | case GeomAbs_Circle: |
166 | case GeomAbs_Ellipse: |
167 | for (j = 1; j < myDiscret; j++) |
168 | { |
169 | t += step; |
170 | C.D0(t,P); |
171 | aDisplay.DrawTo(P); |
172 | } |
173 | break; |
174 | case GeomAbs_Parabola: |
175 | case GeomAbs_Hyperbola: |
176 | case GeomAbs_BezierCurve: |
177 | case GeomAbs_BSplineCurve: |
1aec3320 |
178 | case GeomAbs_OffsetCurve: |
32ca7a51 |
179 | case GeomAbs_OtherCurve: |
180 | const Standard_Integer nIter = myDiscret/2; |
181 | for (j = 1; j < nIter; j++) |
182 | { |
183 | const Standard_Real t1 = t+step*2.; |
184 | C.D0 (t1, aNPnt); |
7fd59977 |
185 | PlotCurve (aDisplay, C, t, step, aPPnt, aNPnt); |
32ca7a51 |
186 | aPPnt = aNPnt; |
187 | t = t1; |
188 | } |
189 | |
190 | break; |
7fd59977 |
191 | } |
192 | |
193 | C.D0(TI(intrv+1),P); |
32ca7a51 |
194 | PlotCurve (aDisplay, C, t, step, aPPnt, P); |
7fd59977 |
195 | aDisplay.DrawTo(P); |
196 | } |
197 | } |
198 | } |
199 | |
200 | |
201 | //======================================================================= |
202 | //function : DrawIsoCurveOn |
203 | //purpose : |
204 | //======================================================================= |
205 | |
206 | void DrawTrSurf_Drawable::DrawIsoCurveOn(Adaptor3d_IsoCurve& C, |
207 | const GeomAbs_IsoType T, |
208 | const Standard_Real P, |
209 | const Standard_Real F, |
210 | const Standard_Real L, |
211 | Draw_Display& dis) const |
212 | { |
213 | C.Load(T,P,F,L); |
214 | if ((C.GetType() == GeomAbs_BezierCurve) || |
215 | (C.GetType() == GeomAbs_BSplineCurve)) { |
216 | GeomAdaptor_Curve GC; |
217 | if (C.GetType() == GeomAbs_BezierCurve) |
218 | GC.Load(C.Bezier(),F,L); |
219 | else |
220 | GC.Load(C.BSpline(),F,L); |
221 | |
222 | DrawCurveOn(GC,dis); |
223 | } |
224 | else |
225 | DrawCurveOn(C,dis); |
226 | |
227 | } |