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.hxx>
17 #include <Adaptor3d_IsoCurve.hxx>
18 #include <Draw_Color.hxx>
19 #include <Draw_Display.hxx>
20 #include <DrawTrSurf.hxx>
21 #include <DrawTrSurf_Params.hxx>
22 #include <Geom_Surface.hxx>
23 #include <GeomAdaptor_Surface.hxx>
24 #include <GeomTools_SurfaceSet.hxx>
25 #include <Precision.hxx>
27 IMPLEMENT_STANDARD_RTTIEXT(DrawTrSurf_Surface, DrawTrSurf_Drawable)
29 Standard_Real DrawTrSurf_SurfaceLimit = 400;
31 //=======================================================================
32 //function : DrawTrSurf_Surface
34 //=======================================================================
35 DrawTrSurf_Surface::DrawTrSurf_Surface (const Handle(Geom_Surface)& S)
36 : DrawTrSurf_Drawable (16, 0.01, 1)
39 boundsLook = Draw_jaune;
45 //=======================================================================
46 //function : DrawTrSurf_Surface
48 //=======================================================================
49 DrawTrSurf_Surface::DrawTrSurf_Surface
50 (const Handle(Geom_Surface)& S, const Standard_Integer Nu,
51 const Standard_Integer Nv,
52 const Draw_Color& BoundsColor, const Draw_Color& IsosColor,
53 const Standard_Integer Discret, const Standard_Real Deflection,
54 const Standard_Integer DrawMode)
55 : DrawTrSurf_Drawable (Discret, Deflection, DrawMode)
58 boundsLook = BoundsColor;
64 //=======================================================================
67 //=======================================================================
68 void DrawTrSurf_Surface::DrawOn (Draw_Display& dis) const
70 DrawOn(dis,Standard_True);
73 //=======================================================================
76 //=======================================================================
77 void DrawTrSurf_Surface::DrawOn (Draw_Display& dis, const Standard_Boolean Iso) const
79 Standard_Real UFirst, ULast, VFirst, VLast;
80 surf->Bounds (UFirst, ULast, VFirst, VLast);
82 Standard_Boolean UfirstInf = Precision::IsNegativeInfinite(UFirst);
83 Standard_Boolean UlastInf = Precision::IsPositiveInfinite(ULast);
84 Standard_Boolean VfirstInf = Precision::IsNegativeInfinite(VFirst);
85 Standard_Boolean VlastInf = Precision::IsPositiveInfinite(VLast);
87 if (UfirstInf || UlastInf) {
90 if (VfirstInf && VlastInf)
97 v = (VFirst + VLast) / 2;
99 Standard_Real delta = 1.;
101 if (UfirstInf && UlastInf) {
106 surf->D0(UFirst,v,P1);
107 surf->D0(ULast,v,P2);
108 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
110 else if (UfirstInf) {
111 surf->D0(ULast,v,P2);
114 UFirst = ULast - delta;
115 surf->D0(UFirst,v,P1);
116 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
119 surf->D0(UFirst,v,P1);
122 ULast = UFirst + delta;
123 surf->D0(ULast,v,P2);
124 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
128 if (VfirstInf || VlastInf) {
130 Standard_Real u = (UFirst + ULast) /2 ;
132 Standard_Real delta = 1.;
134 if (VfirstInf && VlastInf) {
139 surf->D0(u,VFirst,P1);
140 surf->D0(u,VLast,P2);
141 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
143 else if (VfirstInf) {
144 surf->D0(u,VLast,P2);
147 VFirst = VLast - delta;
148 surf->D0(u,VFirst,P1);
149 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
152 surf->D0(u,VFirst,P1);
155 VLast = VFirst + delta;
156 surf->D0(u,VLast,P2);
157 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
162 Handle(GeomAdaptor_Surface) HS = new GeomAdaptor_Surface();
163 HS->Load(surf,UFirst,ULast,VFirst,VLast);
165 Adaptor3d_IsoCurve C(HS);
168 dis.SetColor(isosLook);
169 Standard_Integer i, j;
171 Standard_Real Du = (ULast - UFirst) / (nbUIsos + 1);
172 Standard_Real U = UFirst;
173 for (i = 1; i <= nbUIsos; i++) {
175 DrawIsoCurveOn(C,GeomAbs_IsoU,U,VFirst,VLast,dis);
178 Standard_Real Dv = (VLast - VFirst) / (nbVIsos + 1);
179 Standard_Real V = VFirst;
180 for (j = 1; j <= nbVIsos; j++) {
182 DrawIsoCurveOn(C,GeomAbs_IsoV,V,UFirst,ULast,dis);
187 dis.SetColor(boundsLook);
188 if (!UfirstInf) DrawIsoCurveOn(C,GeomAbs_IsoU,UFirst,VFirst,VLast,dis);
189 if (!UlastInf) DrawIsoCurveOn(C,GeomAbs_IsoU,ULast ,VFirst,VLast,dis);
190 if (!VfirstInf) DrawIsoCurveOn(C,GeomAbs_IsoV,VFirst,UFirst,ULast,dis);
191 if (!VlastInf) DrawIsoCurveOn(C,GeomAbs_IsoV,VLast ,UFirst,ULast,dis);
194 DrawIsoCurveOn(C,GeomAbs_IsoU,
195 UFirst+(ULast-UFirst)/10.,
196 VFirst, VFirst + (VLast-VFirst)/10.,
200 //=======================================================================
201 //function : ClearIsos
203 //=======================================================================
204 void DrawTrSurf_Surface::ClearIsos ()
210 //=======================================================================
213 //=======================================================================
214 Handle(Draw_Drawable3D) DrawTrSurf_Surface::Copy() const
216 Handle(DrawTrSurf_Surface) DS = new DrawTrSurf_Surface
217 (Handle(Geom_Surface)::DownCast(surf->Copy()),
218 nbUIsos,nbVIsos,boundsLook,isosLook,
219 GetDiscretisation(),GetDeflection(),GetDrawMode());
224 //=======================================================================
227 //=======================================================================
228 void DrawTrSurf_Surface::Dump (Standard_OStream& S) const
230 GeomTools_SurfaceSet::PrintSurface(surf,S);
233 //=======================================================================
236 //=======================================================================
237 void DrawTrSurf_Surface::Save (Standard_OStream& theStream) const
239 GeomTools_SurfaceSet::PrintSurface (surf, theStream, true);
242 //=======================================================================
245 //=======================================================================
246 Handle(Draw_Drawable3D) DrawTrSurf_Surface::Restore (std::istream& theStream)
248 const DrawTrSurf_Params& aParams = DrawTrSurf::Parameters();
249 Handle(Geom_Surface) aGeomSurface = GeomTools_SurfaceSet::ReadSurface (theStream);
250 Handle(DrawTrSurf_Surface) aDrawSurface = new DrawTrSurf_Surface (aGeomSurface,
251 aParams.NbUIsos, aParams.NbVIsos,
252 aParams.BoundsColor, aParams.IsosColor,
253 aParams.Discret, aParams.Deflection, aParams.DrawMode);
257 //=======================================================================
260 //=======================================================================
261 void DrawTrSurf_Surface::Whatis (Draw_Interpretor& S) const