0028799: Coding Rules - elimilate confusing Quantity aliases of Standard_Real type
[occt.git] / src / VrmlConverter / VrmlConverter_WFDeflectionRestrictedFace.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
42cf5bc1 14
7fd59977 15#include <Adaptor2d_Curve2d.hxx>
7fd59977 16#include <Adaptor3d_IsoCurve.hxx>
42cf5bc1 17#include <Bnd_Box.hxx>
7fd59977 18#include <Bnd_Box2d.hxx>
19#include <BndLib_Add2dCurve.hxx>
42cf5bc1 20#include <BndLib_AddSurface.hxx>
21#include <BRepAdaptor_HSurface.hxx>
22#include <GCPnts_QuasiUniformDeflection.hxx>
23#include <gp_Pnt.hxx>
24#include <gp_Pnt2d.hxx>
25#include <Hatch_Hatcher.hxx>
7fd59977 26#include <Precision.hxx>
42cf5bc1 27#include <StdPrs_ToolRFace.hxx>
7fd59977 28#include <Vrml_Material.hxx>
42cf5bc1 29#include <Vrml_Separator.hxx>
30#include <VrmlConverter_DeflectionCurve.hxx>
31#include <VrmlConverter_Drawer.hxx>
32#include <VrmlConverter_IsoAspect.hxx>
33#include <VrmlConverter_WFDeflectionRestrictedFace.hxx>
7fd59977 34
35//==================================================================
36// function: GetDeflection
37// purpose:
38//==================================================================
39static Standard_Real GetDeflection(const Handle(BRepAdaptor_HSurface)& aFace,
40 const Handle (VrmlConverter_Drawer)& aDrawer) {
41
42 Standard_Real theRequestedDeflection;
43 if(aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE) // TOD_RELATIVE, TOD_ABSOLUTE
44 {
45 Bnd_Box box;
46 BndLib_AddSurface::Add(aFace->Surface(), Precision::Confusion(), box);
47
48 Standard_Real Xmin, Xmax, Ymin, Ymax, Zmin, Zmax, diagonal;
49 box.Get( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax );
50 if (!(box.IsOpenXmin() || box.IsOpenXmax() ||
51 box.IsOpenYmin() || box.IsOpenYmax() ||
52 box.IsOpenZmin() || box.IsOpenZmax()))
53 {
54 diagonal = Sqrt ((Xmax - Xmin)*( Xmax - Xmin) + ( Ymax - Ymin)*( Ymax - Ymin) + ( Zmax - Zmin)*( Zmax - Zmin));
55 diagonal = Max(diagonal, Precision::Confusion());
56 theRequestedDeflection = aDrawer->DeviationCoefficient() * diagonal;
57 }
58 else
59 {
60 diagonal =1000000.;
61 theRequestedDeflection = aDrawer->DeviationCoefficient() * diagonal;
62 }
63// cout << "diagonal = " << diagonal << endl;
64// cout << "theRequestedDeflection = " << theRequestedDeflection << endl;
65 }
66 else
67 {
68 theRequestedDeflection = aDrawer->MaximalChordialDeviation();
69 }
70 return theRequestedDeflection;
71}
72
73//=========================================================================
74// function: Add 1
75// purpose
76//=========================================================================
77void VrmlConverter_WFDeflectionRestrictedFace::Add
78 (Standard_OStream& anOStream,
79 const Handle(BRepAdaptor_HSurface)& aFace,
80 const Standard_Boolean DrawUIso,
81 const Standard_Boolean DrawVIso,
09324e85 82 const Standard_Real Deflection,
7fd59977 83 const Standard_Integer NBUiso,
84 const Standard_Integer NBViso,
85 const Handle(VrmlConverter_Drawer)& aDrawer)
86{
87
88 StdPrs_ToolRFace ToolRst (aFace);
89 Standard_Real UF, UL, VF, VL;
90 UF = aFace->FirstUParameter();
91 UL = aFace->LastUParameter();
92 VF = aFace->FirstVParameter();
93 VL = aFace->LastVParameter();
94
95 Standard_Real aLimit = aDrawer->MaximalParameterValue();
96
97 // compute bounds of the restriction
98 Standard_Real UMin,UMax,VMin,VMax;
99 Standard_Integer i;
100
101 UMin = UF;
102 UMax = UL;
103 VMin = VF;
104 VMax = VL;
105
106 // load the isos
107 Hatch_Hatcher isobuild(1.e-5,ToolRst.IsOriented());
108 Standard_Boolean UClosed = aFace->IsUClosed();
109 Standard_Boolean VClosed = aFace->IsVClosed();
110
111 if ( ! UClosed ) {
112 UMin = UMin + ( UMax - UMin) /1000.;
113 UMax = UMax - ( UMax - UMin) /1000.;
114 }
115
116 if ( ! VClosed ) {
117 VMin = VMin + ( VMax - VMin) /1000.;
118 VMax = VMax - ( VMax - VMin) /1000.;
119 }
120
121 if (DrawUIso){
122 if (NBUiso > 0) {
123 UClosed = Standard_False;
124 Standard_Real du= UClosed ? (UMax-UMin)/NBUiso : (UMax-UMin)/(1+NBUiso);
125 for (i=1; i<=NBUiso;i++){
126 isobuild.AddXLine(UMin+du*i);
127 }
128 }
129 }
130 if (DrawVIso){
131 if ( NBViso > 0) {
132 VClosed = Standard_False;
133 Standard_Real dv= VClosed ?(VMax-VMin)/NBViso : (VMax-VMin)/(1+NBViso);
134 for (i=1; i<=NBViso;i++){
135 isobuild.AddYLine(VMin+dv*i);
136 }
137 }
138 }
139
140
141 // trim the isos
142 gp_Pnt2d P1,P2;
143 Standard_Real U1, U2;
144 gp_Pnt dummypnt;
145 for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
146 TopAbs_Orientation Orient = ToolRst.Orientation();
147 if ( Orient == TopAbs_FORWARD || Orient == TopAbs_REVERSED ) {
148 Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
149 if (TheRCurve->GetType() != GeomAbs_Line) {
150 GCPnts_QuasiUniformDeflection UDP(*TheRCurve, Deflection);
151 if (UDP.IsDone()) {
152 Standard_Integer NumberOfPoints = UDP.NbPoints();
153 if ( NumberOfPoints >= 2 ) {
154 dummypnt = UDP.Value(1);
155 P2.SetCoord(dummypnt.X(), dummypnt.Y());
156 for (i = 2; i <= NumberOfPoints; i++) {
157 P1 = P2;
158 dummypnt = UDP.Value(i);
159 P2.SetCoord(dummypnt.X(), dummypnt.Y());
160 if(Orient == TopAbs_FORWARD )
161 isobuild.Trim(P1,P2);
162 else
163 isobuild.Trim(P2,P1);
164 }
165 }
166 }
167 else {
168 cout << "Cannot evaluate curve on surface"<<endl;
169 }
170 }
171 else {
172 U1 = TheRCurve->FirstParameter();
173 U2 = TheRCurve->LastParameter();
174 P1 = TheRCurve->Value(U1);
175 P2 = TheRCurve->Value(U2);
176 if(Orient == TopAbs_FORWARD )
177 isobuild.Trim(P1,P2);
178 else
179 isobuild.Trim(P2,P1);
180 }
181 }
182 }
183
184 // draw the isos
185
186 Adaptor3d_IsoCurve anIso;
187 anIso.Load(aFace);
188 Standard_Integer NumberOfLines = isobuild.NbLines();
189
190 Handle(VrmlConverter_LineAspect) latmp = new VrmlConverter_LineAspect;
191 latmp->SetMaterial(aDrawer->LineAspect()->Material());
192 latmp->SetHasMaterial(aDrawer->LineAspect()->HasMaterial());
193
194 Handle(VrmlConverter_IsoAspect) iautmp = new VrmlConverter_IsoAspect;
195 iautmp->SetMaterial(aDrawer->UIsoAspect()->Material());
196 iautmp->SetHasMaterial(aDrawer->UIsoAspect()->HasMaterial());
197 iautmp->SetNumber(aDrawer->UIsoAspect()->Number());
198
199 Handle(VrmlConverter_IsoAspect) iavtmp = new VrmlConverter_IsoAspect;
200 iavtmp->SetMaterial(aDrawer->VIsoAspect()->Material());
201 iavtmp->SetHasMaterial(aDrawer->VIsoAspect()->HasMaterial());
202 iavtmp->SetNumber(aDrawer->VIsoAspect()->Number());
203
204 Handle(VrmlConverter_LineAspect) laU = new VrmlConverter_LineAspect;
205 Handle(VrmlConverter_LineAspect) laV = new VrmlConverter_LineAspect;
206
207 laU = aDrawer->UIsoAspect();
208 laV = aDrawer->VIsoAspect();
209
210 Vrml_Separator SE1;
211 Vrml_Separator SE2;
212 Vrml_Separator SE3;
213
214 Standard_Boolean flag = Standard_False; // to check a call of Vrml_Separator.Print(anOStream)
215
216 SE1.Print(anOStream);
217
218 if (DrawUIso) {
219 if (NBUiso > 0) {
220
221 if (laU->HasMaterial()){
222
223 Handle(Vrml_Material) MU;
224 MU = laU->Material();
225
226 MU->Print(anOStream);
227 laU->SetHasMaterial(Standard_False);
228
229 flag = Standard_True;
230 // Separator 2 {
231 SE2.Print(anOStream);
232 }
233 aDrawer->SetLineAspect(laU);
234
235 for (i = 1; i <= NumberOfLines; i++) {
236 if (isobuild.IsXLine(i))
237 {
238 Standard_Integer NumberOfIntervals = isobuild.NbIntervals(i);
239 Standard_Real Coord = isobuild.Coordinate(i);
240 for (Standard_Integer j = 1; j <= NumberOfIntervals; j++) {
241 Standard_Real b1=isobuild.Start(i,j),b2=isobuild.End(i,j);
242
243 b1 = b1 == RealFirst() ? - aLimit : b1;
244 b2 = b2 == RealLast() ? aLimit : b2;
245
246 anIso.Load(GeomAbs_IsoU,Coord,b1,b2);
247
248 VrmlConverter_DeflectionCurve::Add(anOStream, anIso, Deflection, aDrawer);
249 }
250 }
251 }
252 if (flag){
253 // Separator 2 }
254 SE2.Print(anOStream);
255 flag = Standard_False;
256 }
257 }
258 }
259
260 if (DrawVIso) {
261 if ( NBViso > 0) {
262 if (laV->HasMaterial()){
263
264 Handle(Vrml_Material) MV;
265 MV = laV->Material();
266
267 MV->Print(anOStream);
268 laV->SetHasMaterial(Standard_False);
269 flag = Standard_True;
270
271 // Separator 3 {
272 SE3.Print(anOStream);
273 }
274
275 aDrawer->SetLineAspect(laV);
276
277 for (i = 1; i <= NumberOfLines; i++) {
278 if (isobuild.IsYLine(i))
279 {
280 Standard_Integer NumberOfIntervals = isobuild.NbIntervals(i);
281 Standard_Real Coord = isobuild.Coordinate(i);
282 for (Standard_Integer j = 1; j <= NumberOfIntervals; j++) {
283 Standard_Real b1=isobuild.Start(i,j),b2=isobuild.End(i,j);
284
285 b1 = b1 == RealFirst() ? - aLimit : b1;
286 b2 = b2 == RealLast() ? aLimit : b2;
287
288 anIso.Load(GeomAbs_IsoV,Coord,b1,b2);
289
290 VrmlConverter_DeflectionCurve::Add(anOStream, anIso, Deflection, aDrawer);
291 }
292 }
293 }
294
295 if (flag){
296 // Separator 3 }
297 SE3.Print(anOStream);
298 flag = Standard_False;
299 }
300 }
301 }
302
303 // Separator 1 }
304 SE1.Print(anOStream);
305
306 aDrawer->SetLineAspect(latmp);
307 aDrawer->SetUIsoAspect(iautmp);
308 aDrawer->SetVIsoAspect(iavtmp);
309}
310
311//=========================================================================
312// function: Add 2
313// purpose
314//=========================================================================
315void VrmlConverter_WFDeflectionRestrictedFace::Add
316 (Standard_OStream& anOStream,
317 const Handle(BRepAdaptor_HSurface)& aFace,
318 const Handle (VrmlConverter_Drawer)& aDrawer){
319
09324e85 320 Standard_Real Deflection = GetDeflection(aFace, aDrawer);
7fd59977 321
322 Standard_Integer finu = aDrawer->UIsoAspect()->Number();
323 Standard_Integer finv = aDrawer->VIsoAspect()->Number();
324
325 VrmlConverter_WFDeflectionRestrictedFace::Add (
326 anOStream,
327 aFace,
328 Standard_True,
329 Standard_True,
330 Deflection,
331 finu,
332 finv,
333 aDrawer);
334
335}
336
337
338//=========================================================================
339// function: AddUIso
340// purpose
341//=========================================================================
342void VrmlConverter_WFDeflectionRestrictedFace::AddUIso
343 (Standard_OStream& anOStream,
344 const Handle(BRepAdaptor_HSurface)& aFace,
345 const Handle (VrmlConverter_Drawer)& aDrawer) {
346
09324e85 347 Standard_Real Deflection = GetDeflection(aFace, aDrawer);
7fd59977 348
349 Standard_Integer finu = aDrawer->UIsoAspect()->Number();
350 Standard_Integer finv = aDrawer->VIsoAspect()->Number();
351 VrmlConverter_WFDeflectionRestrictedFace::Add (
352 anOStream,
353 aFace,
354 Standard_True,
355 Standard_False,
356 Deflection,
357 finu,
358 finv,
359 aDrawer);
360}
361
362
363//=========================================================================
364// function: AddVIso
365// purpose
366//=========================================================================
367void VrmlConverter_WFDeflectionRestrictedFace::AddVIso
368 (Standard_OStream& anOStream,
369 const Handle(BRepAdaptor_HSurface)& aFace,
370 const Handle (VrmlConverter_Drawer)& aDrawer) {
371
09324e85 372 Standard_Real Deflection = GetDeflection(aFace, aDrawer);
7fd59977 373
374 Standard_Integer finu = aDrawer->UIsoAspect()->Number();
375 Standard_Integer finv = aDrawer->VIsoAspect()->Number();
376 VrmlConverter_WFDeflectionRestrictedFace::Add (
377 anOStream,
378 aFace,
379 Standard_False,
380 Standard_True,
381 Deflection,
382 finu,
383 finv,
384 aDrawer);
385}