1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <DrawTrSurf_Surface.ixx>
16 #include <GeomTools_SurfaceSet.hxx>
17 #include <GeomAdaptor_HSurface.hxx>
18 #include <Adaptor3d_IsoCurve.hxx>
19 #include <Precision.hxx>
21 Standard_Real DrawTrSurf_SurfaceLimit = 400;
24 //=======================================================================
25 //function : DrawTrSurf_Surface
27 //=======================================================================
29 DrawTrSurf_Surface::DrawTrSurf_Surface (const Handle(Geom_Surface)& S)
30 : DrawTrSurf_Drawable (16, 0.01, 1)
33 boundsLook = Draw_jaune;
42 //=======================================================================
43 //function : DrawTrSurf_Surface
45 //=======================================================================
47 DrawTrSurf_Surface::DrawTrSurf_Surface
48 (const Handle(Geom_Surface)& S, const Standard_Integer Nu,
49 const Standard_Integer Nv,
50 const Draw_Color& BoundsColor, const Draw_Color& IsosColor,
51 const Standard_Integer Discret, const Standard_Real Deflection,
52 const Standard_Integer DrawMode)
53 : DrawTrSurf_Drawable (Discret, Deflection, DrawMode)
56 boundsLook = BoundsColor;
64 //=======================================================================
67 //=======================================================================
69 void DrawTrSurf_Surface::DrawOn (Draw_Display& dis) const
71 DrawOn(dis,Standard_True);
74 //=======================================================================
77 //=======================================================================
79 void DrawTrSurf_Surface::DrawOn (Draw_Display& dis,
80 const Standard_Boolean Iso) const
82 Standard_Real UFirst, ULast, VFirst, VLast;
83 surf->Bounds (UFirst, ULast, VFirst, VLast);
85 Standard_Boolean UfirstInf = Precision::IsNegativeInfinite(UFirst);
86 Standard_Boolean UlastInf = Precision::IsPositiveInfinite(ULast);
87 Standard_Boolean VfirstInf = Precision::IsNegativeInfinite(VFirst);
88 Standard_Boolean VlastInf = Precision::IsPositiveInfinite(VLast);
90 if (UfirstInf || UlastInf) {
93 if (VfirstInf && VlastInf)
100 v = (VFirst + VLast) / 2;
102 Standard_Real delta = 1.;
104 if (UfirstInf && UlastInf) {
109 surf->D0(UFirst,v,P1);
110 surf->D0(ULast,v,P2);
111 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
113 else if (UfirstInf) {
114 surf->D0(ULast,v,P2);
117 UFirst = ULast - delta;
118 surf->D0(UFirst,v,P1);
119 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
122 surf->D0(UFirst,v,P1);
125 ULast = UFirst + delta;
126 surf->D0(ULast,v,P2);
127 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
131 if (VfirstInf || VlastInf) {
133 Standard_Real u = (UFirst + ULast) /2 ;
135 Standard_Real delta = 1.;
137 if (VfirstInf && VlastInf) {
142 surf->D0(u,VFirst,P1);
143 surf->D0(u,VLast,P2);
144 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
146 else if (VfirstInf) {
147 surf->D0(u,VLast,P2);
150 VFirst = VLast - delta;
151 surf->D0(u,VFirst,P1);
152 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
155 surf->D0(u,VFirst,P1);
158 VLast = VFirst + delta;
159 surf->D0(u,VLast,P2);
160 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
165 Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface();
166 HS->ChangeSurface().Load(surf,UFirst,ULast,VFirst,VLast);
168 Adaptor3d_IsoCurve C(HS);
171 dis.SetColor(isosLook);
172 Standard_Integer i, j;
174 Standard_Real Du = (ULast - UFirst) / (nbUIsos + 1);
175 Standard_Real U = UFirst;
176 for (i = 1; i <= nbUIsos; i++) {
178 DrawIsoCurveOn(C,GeomAbs_IsoU,U,VFirst,VLast,dis);
181 Standard_Real Dv = (VLast - VFirst) / (nbVIsos + 1);
182 Standard_Real V = VFirst;
183 for (j = 1; j <= nbVIsos; j++) {
185 DrawIsoCurveOn(C,GeomAbs_IsoV,V,UFirst,ULast,dis);
190 dis.SetColor(boundsLook);
191 if (!UfirstInf) DrawIsoCurveOn(C,GeomAbs_IsoU,UFirst,VFirst,VLast,dis);
192 if (!UlastInf) DrawIsoCurveOn(C,GeomAbs_IsoU,ULast ,VFirst,VLast,dis);
193 if (!VfirstInf) DrawIsoCurveOn(C,GeomAbs_IsoV,VFirst,UFirst,ULast,dis);
194 if (!VlastInf) DrawIsoCurveOn(C,GeomAbs_IsoV,VLast ,UFirst,ULast,dis);
197 DrawIsoCurveOn(C,GeomAbs_IsoU,
198 UFirst+(ULast-UFirst)/10.,
199 VFirst, VFirst + (VLast-VFirst)/10.,
205 //=======================================================================
206 //function : ShowIsos
208 //=======================================================================
210 void DrawTrSurf_Surface::ShowIsos ( const Standard_Integer Nu,
211 const Standard_Integer Nv)
218 //=======================================================================
219 //function : ClearIsos
221 //=======================================================================
223 void DrawTrSurf_Surface::ClearIsos ()
230 //=======================================================================
233 //=======================================================================
235 Handle(Draw_Drawable3D) DrawTrSurf_Surface::Copy() const
237 Handle(DrawTrSurf_Surface) DS = new DrawTrSurf_Surface
238 (Handle(Geom_Surface)::DownCast(surf->Copy()),
239 nbUIsos,nbVIsos,boundsLook,isosLook,
240 GetDiscretisation(),GetDeflection(),GetDrawMode());
246 //=======================================================================
249 //=======================================================================
251 void DrawTrSurf_Surface::Dump(Standard_OStream& S)const
253 GeomTools_SurfaceSet::PrintSurface(surf,S);
257 //=======================================================================
260 //=======================================================================
262 void DrawTrSurf_Surface::Whatis(Draw_Interpretor& S)const