1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
19 #include <DrawTrSurf_Surface.ixx>
20 #include <GeomTools_SurfaceSet.hxx>
21 #include <GeomAdaptor_HSurface.hxx>
22 #include <Adaptor3d_IsoCurve.hxx>
23 #include <Precision.hxx>
25 Standard_Real DrawTrSurf_SurfaceLimit = 400;
28 //=======================================================================
29 //function : DrawTrSurf_Surface
31 //=======================================================================
33 DrawTrSurf_Surface::DrawTrSurf_Surface (const Handle(Geom_Surface)& S)
34 : DrawTrSurf_Drawable (16, 0.01, 1)
37 boundsLook = Draw_jaune;
46 //=======================================================================
47 //function : DrawTrSurf_Surface
49 //=======================================================================
51 DrawTrSurf_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)
60 boundsLook = BoundsColor;
68 //=======================================================================
71 //=======================================================================
73 void DrawTrSurf_Surface::DrawOn (Draw_Display& dis) const
75 DrawOn(dis,Standard_True);
78 //=======================================================================
81 //=======================================================================
83 void DrawTrSurf_Surface::DrawOn (Draw_Display& dis,
84 const Standard_Boolean Iso) const
86 Standard_Real UFirst, ULast, VFirst, VLast;
87 surf->Bounds (UFirst, ULast, VFirst, VLast);
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);
94 if (UfirstInf || UlastInf) {
97 if (VfirstInf && VlastInf)
104 v = (VFirst + VLast) / 2;
106 Standard_Real delta = 1.;
108 if (UfirstInf && UlastInf) {
113 surf->D0(UFirst,v,P1);
114 surf->D0(ULast,v,P2);
115 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
117 else if (UfirstInf) {
118 surf->D0(ULast,v,P2);
121 UFirst = ULast - delta;
122 surf->D0(UFirst,v,P1);
123 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
126 surf->D0(UFirst,v,P1);
129 ULast = UFirst + delta;
130 surf->D0(ULast,v,P2);
131 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
135 if (VfirstInf || VlastInf) {
137 Standard_Real u = (UFirst + ULast) /2 ;
139 Standard_Real delta = 1.;
141 if (VfirstInf && VlastInf) {
146 surf->D0(u,VFirst,P1);
147 surf->D0(u,VLast,P2);
148 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
150 else if (VfirstInf) {
151 surf->D0(u,VLast,P2);
154 VFirst = VLast - delta;
155 surf->D0(u,VFirst,P1);
156 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
159 surf->D0(u,VFirst,P1);
162 VLast = VFirst + delta;
163 surf->D0(u,VLast,P2);
164 } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit);
169 Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface();
170 HS->ChangeSurface().Load(surf,UFirst,ULast,VFirst,VLast);
172 Adaptor3d_IsoCurve C(HS);
175 dis.SetColor(isosLook);
176 Standard_Integer i, j;
178 Standard_Real Du = (ULast - UFirst) / (nbUIsos + 1);
179 Standard_Real U = UFirst;
180 for (i = 1; i <= nbUIsos; i++) {
182 DrawIsoCurveOn(C,GeomAbs_IsoU,U,VFirst,VLast,dis);
185 Standard_Real Dv = (VLast - VFirst) / (nbVIsos + 1);
186 Standard_Real V = VFirst;
187 for (j = 1; j <= nbVIsos; j++) {
189 DrawIsoCurveOn(C,GeomAbs_IsoV,V,UFirst,ULast,dis);
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);
201 DrawIsoCurveOn(C,GeomAbs_IsoU,
202 UFirst+(ULast-UFirst)/10.,
203 VFirst, VFirst + (VLast-VFirst)/10.,
209 //=======================================================================
210 //function : ShowIsos
212 //=======================================================================
214 void DrawTrSurf_Surface::ShowIsos ( const Standard_Integer Nu,
215 const Standard_Integer Nv)
222 //=======================================================================
223 //function : ClearIsos
225 //=======================================================================
227 void DrawTrSurf_Surface::ClearIsos ()
234 //=======================================================================
237 //=======================================================================
239 Handle(Draw_Drawable3D) DrawTrSurf_Surface::Copy() const
241 Handle(DrawTrSurf_Surface) DS = new DrawTrSurf_Surface
242 (Handle(Geom_Surface)::DownCast(surf->Copy()),
243 nbUIsos,nbVIsos,boundsLook,isosLook,
244 GetDiscretisation(),GetDeflection(),GetDrawMode());
250 //=======================================================================
253 //=======================================================================
255 void DrawTrSurf_Surface::Dump(Standard_OStream& S)const
257 GeomTools_SurfaceSet::PrintSurface(surf,S);
261 //=======================================================================
264 //=======================================================================
266 void DrawTrSurf_Surface::Whatis(Draw_Interpretor& S)const