0023706: Cannot project point on curve
[occt.git] / src / DrawTrSurf / DrawTrSurf_Surface.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
2// Copyright (c) 1999-2012 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
7fd59977 19#include <DrawTrSurf_Surface.ixx>
20#include <GeomTools_SurfaceSet.hxx>
21#include <GeomAdaptor_HSurface.hxx>
22#include <Adaptor3d_IsoCurve.hxx>
23#include <Precision.hxx>
24
25Standard_Real DrawTrSurf_SurfaceLimit = 400;
26
27
28//=======================================================================
29//function : DrawTrSurf_Surface
30//purpose :
31//=======================================================================
32
33DrawTrSurf_Surface::DrawTrSurf_Surface (const Handle(Geom_Surface)& S)
34: DrawTrSurf_Drawable (16, 0.01, 1)
35{
36 surf = S;
37 boundsLook = Draw_jaune;
38 isosLook = Draw_bleu;
39 nbUIsos = 1;
40 nbVIsos = 1;
41}
42
43
44
45
46//=======================================================================
47//function : DrawTrSurf_Surface
48//purpose :
49//=======================================================================
50
51DrawTrSurf_Surface::DrawTrSurf_Surface
52 (const Handle(Geom_Surface)& S, const Standard_Integer Nu,
53 const Standard_Integer Nv,
54 const Draw_Color& BoundsColor, const Draw_Color& IsosColor,
55 const Standard_Integer Discret, const Standard_Real Deflection,
56 const Standard_Integer DrawMode)
57: DrawTrSurf_Drawable (Discret, Deflection, DrawMode)
58{
59 surf = S;
60 boundsLook = BoundsColor;
61 isosLook = IsosColor;
62 nbUIsos = Abs(Nu);
63 nbVIsos = Abs(Nv);
64}
65
66
67
68//=======================================================================
69//function : DrawOn
70//purpose :
71//=======================================================================
72
73void DrawTrSurf_Surface::DrawOn (Draw_Display& dis) const
74{
75 DrawOn(dis,Standard_True);
76}
77
78//=======================================================================
79//function : DrawOn
80//purpose :
81//=======================================================================
82
83void DrawTrSurf_Surface::DrawOn (Draw_Display& dis,
84 const Standard_Boolean Iso) const
85{
86 Standard_Real UFirst, ULast, VFirst, VLast;
87 surf->Bounds (UFirst, ULast, VFirst, VLast);
88
89 Standard_Boolean UfirstInf = Precision::IsNegativeInfinite(UFirst);
90 Standard_Boolean UlastInf = Precision::IsPositiveInfinite(ULast);
91 Standard_Boolean VfirstInf = Precision::IsNegativeInfinite(VFirst);
92 Standard_Boolean VlastInf = Precision::IsPositiveInfinite(VLast);
93
94 if (UfirstInf || UlastInf) {
95 gp_Pnt P1,P2;
96 Standard_Real v;
97 if (VfirstInf && VlastInf)
98 v = 0;
99 else if (VfirstInf)
100 v = VLast;
101 else if (VlastInf)
102 v = VFirst;
103 else
104 v = (VFirst + VLast) / 2;
105
106 Standard_Real delta = 1.;
107
108 if (UfirstInf && UlastInf) {
109 do {
110 delta *= 2;
111 UFirst = - delta;
112 ULast = delta;
113 surf->D0(UFirst,v,P1);
114 surf->D0(ULast,v,P2);
115 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
116 }
117 else if (UfirstInf) {
118 surf->D0(ULast,v,P2);
119 do {
120 delta *= 2;
121 UFirst = ULast - delta;
122 surf->D0(UFirst,v,P1);
123 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
124 }
125 else if (UlastInf) {
126 surf->D0(UFirst,v,P1);
127 do {
128 delta *= 2;
129 ULast = UFirst + delta;
130 surf->D0(ULast,v,P2);
131 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
132 }
133 }
134
135 if (VfirstInf || VlastInf) {
136 gp_Pnt P1,P2;
137 Standard_Real u = (UFirst + ULast) /2 ;
138
139 Standard_Real delta = 1.;
140
141 if (VfirstInf && VlastInf) {
142 do {
143 delta *= 2;
144 VFirst = - delta;
145 VLast = delta;
146 surf->D0(u,VFirst,P1);
147 surf->D0(u,VLast,P2);
148 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
149 }
150 else if (VfirstInf) {
151 surf->D0(u,VLast,P2);
152 do {
153 delta *= 2;
154 VFirst = VLast - delta;
155 surf->D0(u,VFirst,P1);
156 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
157 }
158 else if (VlastInf) {
159 surf->D0(u,VFirst,P1);
160 do {
161 delta *= 2;
162 VLast = VFirst + delta;
163 surf->D0(u,VLast,P2);
164 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
165 }
166 }
167
168
169 Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface();
170 HS->ChangeSurface().Load(surf,UFirst,ULast,VFirst,VLast);
171
172 Adaptor3d_IsoCurve C(HS);
173
174 if (Iso) {
175 dis.SetColor(isosLook);
176 Standard_Integer i, j;
177
178 Standard_Real Du = (ULast - UFirst) / (nbUIsos + 1);
179 Standard_Real U = UFirst;
180 for (i = 1; i <= nbUIsos; i++) {
181 U += Du;
182 DrawIsoCurveOn(C,GeomAbs_IsoU,U,VFirst,VLast,dis);
183 }
184
185 Standard_Real Dv = (VLast - VFirst) / (nbVIsos + 1);
186 Standard_Real V = VFirst;
187 for (j = 1; j <= nbVIsos; j++) {
188 V += Dv;
189 DrawIsoCurveOn(C,GeomAbs_IsoV,V,UFirst,ULast,dis);
190 }
191 }
192
193 // draw bounds
194 dis.SetColor(boundsLook);
195 if (!UfirstInf) DrawIsoCurveOn(C,GeomAbs_IsoU,UFirst,VFirst,VLast,dis);
196 if (!UlastInf) DrawIsoCurveOn(C,GeomAbs_IsoU,ULast ,VFirst,VLast,dis);
197 if (!VfirstInf) DrawIsoCurveOn(C,GeomAbs_IsoV,VFirst,UFirst,ULast,dis);
198 if (!VlastInf) DrawIsoCurveOn(C,GeomAbs_IsoV,VLast ,UFirst,ULast,dis);
199
200 // draw marker
201 DrawIsoCurveOn(C,GeomAbs_IsoU,
202 UFirst+(ULast-UFirst)/10.,
203 VFirst, VFirst + (VLast-VFirst)/10.,
204 dis);
205}
206
207
208
209//=======================================================================
210//function : ShowIsos
211//purpose :
212//=======================================================================
213
214void DrawTrSurf_Surface::ShowIsos ( const Standard_Integer Nu,
215 const Standard_Integer Nv)
216{
217 nbUIsos = Abs(Nu);
218 nbVIsos = Abs(Nv);
219}
220
221
222//=======================================================================
223//function : ClearIsos
224//purpose :
225//=======================================================================
226
227void DrawTrSurf_Surface::ClearIsos ()
228{
229 nbUIsos = 0;
230 nbVIsos = 0;
231}
232
233
234//=======================================================================
235//function : Copy
236//purpose :
237//=======================================================================
238
239Handle(Draw_Drawable3D) DrawTrSurf_Surface::Copy() const
240{
241 Handle(DrawTrSurf_Surface) DS = new DrawTrSurf_Surface
242 (Handle(Geom_Surface)::DownCast(surf->Copy()),
243 nbUIsos,nbVIsos,boundsLook,isosLook,
244 GetDiscretisation(),GetDeflection(),GetDrawMode());
245
246 return DS;
247}
248
249
250//=======================================================================
251//function : Dump
252//purpose :
253//=======================================================================
254
255void DrawTrSurf_Surface::Dump(Standard_OStream& S)const
256{
257 GeomTools_SurfaceSet::PrintSurface(surf,S);
258}
259
260
261//=======================================================================
262//function : Whatis
263//purpose :
264//=======================================================================
265
266void DrawTrSurf_Surface::Whatis(Draw_Interpretor& S)const
267{
268 S << "a surface";
269}