0028643: Coding rules - eliminate GCC compiler warnings -Wmisleading-indentation
[occt.git] / src / BRepPrim / BRepPrim_GWedge.cxx
CommitLineData
b311480e 1// Created on: 1991-09-27
2// Created by: Christophe MARION
3// Copyright (c) 1991-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
a104bb8f 17
a104bb8f 18#include <BRepPrim_Builder.hxx>
19#include <BRepPrim_Direction.hxx>
42cf5bc1 20#include <BRepPrim_GWedge.hxx>
21#include <ElCLib.hxx>
22#include <ElSLib.hxx>
23#include <gp_Ax2.hxx>
24#include <gp_Lin.hxx>
25#include <gp_Pln.hxx>
26#include <gp_Pnt.hxx>
27#include <gp_Vec.hxx>
28#include <Precision.hxx>
7fd59977 29#include <Standard_DomainError.hxx>
30#include <Standard_OutOfRange.hxx>
42cf5bc1 31#include <TopoDS_Edge.hxx>
32#include <TopoDS_Face.hxx>
33#include <TopoDS_Shell.hxx>
34#include <TopoDS_Vertex.hxx>
35#include <TopoDS_Wire.hxx>
7fd59977 36
7fd59977 37#define NBFACES 6
38#define NBWIRES 6
39#define NBEDGES 12
40#define NBVERTICES 8
41
42static const Standard_Integer num[6] = {0,1,2,3,4,5};
43static const Standard_Integer val[6] = {0,4,0,2,0,1};
44static const Standard_Integer tab[6][6] = {{-1,-1, 0, 1, 8, 9},
45 {-1,-1, 2, 3,10,11},
46 { 0, 2,-1,-1, 4, 5},
47 { 1, 3,-1,-1, 6, 7},
48 { 8,10, 4, 6,-1,-1},
49 { 9,11, 5, 7,-1,-1}};
50
51//=======================================================================
a104bb8f 52//function : BRepPrim_Wedge_NumDir1
7fd59977 53//purpose : when giving a direction return the range of the face
54//=======================================================================
55
a104bb8f 56static Standard_Integer BRepPrim_Wedge_NumDir1
57 (const BRepPrim_Direction d1) { return num[d1]; }
7fd59977 58
59//=======================================================================
a104bb8f 60//function : BRepPrim_Wedge_NumDir2
7fd59977 61//purpose : when giving two directions return the range of the edge
62//=======================================================================
63
a104bb8f 64static Standard_Integer BRepPrim_Wedge_NumDir2
65 (const BRepPrim_Direction d1,
66 const BRepPrim_Direction d2)
7fd59977 67{
a104bb8f 68 Standard_Integer i1 = BRepPrim_Wedge_NumDir1(d1);
69 Standard_Integer i2 = BRepPrim_Wedge_NumDir1(d2);
9775fa61 70 if ( i1/2 == i2/2 ) throw Standard_DomainError();
7fd59977 71 return tab[i1][i2];
72}
73
74//=======================================================================
a104bb8f 75//function : BRepPrim_Wedge_NumDir3
7fd59977 76//purpose : when giving three directions return the range of the vertex
77//=======================================================================
78
a104bb8f 79static Standard_Integer BRepPrim_Wedge_NumDir3
80 (const BRepPrim_Direction d1,
81 const BRepPrim_Direction d2,
82 const BRepPrim_Direction d3)
7fd59977 83{
a104bb8f 84 Standard_Integer i1 = BRepPrim_Wedge_NumDir1(d1);
85 Standard_Integer i2 = BRepPrim_Wedge_NumDir1(d2);
86 Standard_Integer i3 = BRepPrim_Wedge_NumDir1(d3);
7fd59977 87 if (( i1/2 == i2/2 ) ||
88 ( i2/2 == i3/2 ) ||
9775fa61 89 ( i3/2 == i1/2 )) throw Standard_DomainError();
7fd59977 90 return val[i1]+val[i2]+val[i3];
91}
92
93//=======================================================================
a104bb8f 94//function : BRepPrim_Wedge_Check
7fd59977 95//purpose : raise Standard_DomainError if something was built
96//=======================================================================
97
a104bb8f 98static void BRepPrim_Wedge_Check(const Standard_Boolean V[],
7fd59977 99 const Standard_Boolean E[],
100 const Standard_Boolean W[],
101 const Standard_Boolean F[])
102{
103 Standard_Integer i;
104 for (i = 0; i < NBVERTICES; i++)
9775fa61 105 if (V[i]) throw Standard_DomainError();
7fd59977 106 for (i = 0; i < NBEDGES; i++)
9775fa61 107 if (E[i]) throw Standard_DomainError();
7fd59977 108 for (i = 0; i < NBWIRES; i++)
9775fa61 109 if (W[i]) throw Standard_DomainError();
7fd59977 110 for (i = 0; i < NBFACES; i++)
9775fa61 111 if (F[i]) throw Standard_DomainError();
7fd59977 112}
113
114//=======================================================================
a104bb8f 115//function : BRepPrim_Wedge_Init
7fd59977 116//purpose : Set arrays to Standard_False
117//=======================================================================
118
a104bb8f 119static void BRepPrim_Wedge_Init(Standard_Boolean& S,
7fd59977 120 Standard_Boolean V[],
121 Standard_Boolean E[],
122 Standard_Boolean W[],
123 Standard_Boolean F[])
124{
125 Standard_Integer i;
126 S = Standard_False;
127 for (i = 0; i < NBVERTICES; i++)
128 V[i] = Standard_False;
129 for (i = 0; i < NBEDGES; i++)
130 E[i] = Standard_False;
131 for (i = 0; i < NBWIRES; i++)
132 W[i] = Standard_False;
133 for (i = 0; i < NBFACES; i++)
134 F[i] = Standard_False;
135}
136
137//=======================================================================
a104bb8f 138//function : BRepPrim_GWedge
7fd59977 139//purpose : build a box
140//=======================================================================
141
a104bb8f 142BRepPrim_GWedge::BRepPrim_GWedge (const BRepPrim_Builder& B,
7fd59977 143 const gp_Ax2& Axes,
144 const Standard_Real dx,
145 const Standard_Real dy,
146 const Standard_Real dz) :
147 myBuilder(B),
148 myAxes(Axes),
149 XMin(0),
150 XMax(dx),
151 YMin(0),
152 YMax(dy),
153 ZMin(0),
154 ZMax(dz),
155 Z2Min(0),
156 Z2Max(dz),
157 X2Min(0),
158 X2Max(dx)
159{
160 for (Standard_Integer i = 0; i < NBFACES; i++) { myInfinite[i]=Standard_False; }
161 if ( ( dx <= Precision::Confusion() ) ||
162 ( dy <= Precision::Confusion() ) ||
163 ( dz <= Precision::Confusion() ) )
9775fa61 164 throw Standard_DomainError();
a104bb8f 165 BRepPrim_Wedge_Init(ShellBuilt,VerticesBuilt,EdgesBuilt,
7fd59977 166 WiresBuilt,FacesBuilt);
167}
168
169//=======================================================================
a104bb8f 170//function : BRepPrim_GWedge
7fd59977 171//purpose : build a STEP wedge
172//=======================================================================
173
a104bb8f 174BRepPrim_GWedge::BRepPrim_GWedge (const BRepPrim_Builder& B,
7fd59977 175 const gp_Ax2& Axes,
176 const Standard_Real dx,
177 const Standard_Real dy,
178 const Standard_Real dz,
179 const Standard_Real ltx) :
180 myBuilder(B),
181 myAxes(Axes),
182 XMin(0),
183 XMax(dx),
184 YMin(0),
185 YMax(dy),
186 ZMin(0),
187 ZMax(dz),
188 Z2Min(0),
189 Z2Max(dz),
190 X2Min(0),
191 X2Max(ltx)
192{
193 for (Standard_Integer i = 0; i < NBFACES; i++) { myInfinite[i]=Standard_False; }
194 if ( ( dx <= Precision::Confusion() ) ||
195 ( dy <= Precision::Confusion() ) ||
196 ( dz <= Precision::Confusion() ) ||
197 ( ltx < 0 ) )
9775fa61 198 throw Standard_DomainError();
a104bb8f 199 BRepPrim_Wedge_Init(ShellBuilt,VerticesBuilt,EdgesBuilt,
7fd59977 200 WiresBuilt,FacesBuilt);
201}
202
203//=======================================================================
a104bb8f 204//function : BRepPrim_GWedge
7fd59977 205//purpose : build a wedge by giving all the fields
206//=======================================================================
207
a104bb8f 208BRepPrim_GWedge::BRepPrim_GWedge (const BRepPrim_Builder& B,
7fd59977 209 const gp_Ax2& Axes,
210 const Standard_Real xmin,
211 const Standard_Real ymin,
212 const Standard_Real zmin,
213 const Standard_Real z2min,
214 const Standard_Real x2min,
215 const Standard_Real xmax,
216 const Standard_Real ymax,
217 const Standard_Real zmax,
218 const Standard_Real z2max,
219 const Standard_Real x2max) :
220 myBuilder(B),
221 myAxes(Axes),
222 XMin(xmin),
223 XMax(xmax),
224 YMin(ymin),
225 YMax(ymax),
226 ZMin(zmin),
227 ZMax(zmax),
228 Z2Min(z2min),
229 Z2Max(z2max),
230 X2Min(x2min),
231 X2Max(x2max)
232{
233 for (Standard_Integer i = 0; i < NBFACES; i++) { myInfinite[i]=Standard_False; }
234 if ( ( XMax-XMin <= Precision::Confusion() ) ||
235 ( YMax-YMin <= Precision::Confusion() ) ||
236 ( ZMax-ZMin <= Precision::Confusion() ) ||
237 ( Z2Max-Z2Min < 0 ) ||
238 ( X2Max-X2Min < 0 ) )
9775fa61 239 throw Standard_DomainError();
a104bb8f 240 BRepPrim_Wedge_Init(ShellBuilt,VerticesBuilt,EdgesBuilt,
7fd59977 241 WiresBuilt,FacesBuilt);
242}
243
244//=======================================================================
245//function : Axes,
246// GetXMin, GetYMin, GetZMin, GetZ2Min, GetX2Min
247// GetXMax, GetYMax, GetZMax, GetZ2Max, GetX2Max
248//purpose : trivial
249//=======================================================================
250
a104bb8f 251gp_Ax2 BRepPrim_GWedge::Axes () const { return myAxes; }
252Standard_Real BRepPrim_GWedge::GetXMin () const { return XMin; }
253Standard_Real BRepPrim_GWedge::GetYMin () const { return YMin; }
254Standard_Real BRepPrim_GWedge::GetZMin () const { return ZMin; }
255Standard_Real BRepPrim_GWedge::GetZ2Min () const { return Z2Min; }
256Standard_Real BRepPrim_GWedge::GetX2Min () const { return X2Min; }
257Standard_Real BRepPrim_GWedge::GetXMax () const { return XMax; }
258Standard_Real BRepPrim_GWedge::GetYMax () const { return YMax; }
259Standard_Real BRepPrim_GWedge::GetZMax () const { return ZMax; }
260Standard_Real BRepPrim_GWedge::GetZ2Max () const { return Z2Max; }
261Standard_Real BRepPrim_GWedge::GetX2Max () const { return X2Max; }
7fd59977 262
263//=======================================================================
264//function : Open
265//purpose : trivial
266//=======================================================================
267
a104bb8f 268void BRepPrim_GWedge::Open (const BRepPrim_Direction d1)
7fd59977 269{
a104bb8f 270 BRepPrim_Wedge_Check(VerticesBuilt,EdgesBuilt,WiresBuilt,FacesBuilt);
271 myInfinite[BRepPrim_Wedge_NumDir1(d1)] = Standard_True;
7fd59977 272}
273
274//=======================================================================
275//function : Close
276//purpose : trivial
277//=======================================================================
278
a104bb8f 279void BRepPrim_GWedge::Close (const BRepPrim_Direction d1)
7fd59977 280{
a104bb8f 281 BRepPrim_Wedge_Check(VerticesBuilt,EdgesBuilt,WiresBuilt,FacesBuilt);
282 myInfinite[BRepPrim_Wedge_NumDir1(d1)] = Standard_False;
7fd59977 283}
284
285//=======================================================================
286//function : IsInfinite
287//purpose : true if it is open in the given direction
288//=======================================================================
289
a104bb8f 290Standard_Boolean BRepPrim_GWedge::IsInfinite (const BRepPrim_Direction d1) const
291{ return myInfinite[BRepPrim_Wedge_NumDir1(d1)]; }
7fd59977 292
293//=======================================================================
294//function : Shell
295//purpose :
296//=======================================================================
297
a104bb8f 298const TopoDS_Shell& BRepPrim_GWedge::Shell() {
7fd59977 299 if (!ShellBuilt) {
300 myBuilder.MakeShell(myShell);
301
a104bb8f 302 if (HasFace(BRepPrim_XMin))
303 myBuilder.AddShellFace(myShell,Face(BRepPrim_XMin));
304 if (HasFace(BRepPrim_XMax))
305 myBuilder.AddShellFace(myShell,Face(BRepPrim_XMax));
306 if (HasFace(BRepPrim_YMin))
307 myBuilder.AddShellFace(myShell,Face(BRepPrim_YMin));
308 if (HasFace(BRepPrim_YMax))
309 myBuilder.AddShellFace(myShell,Face(BRepPrim_YMax));
310 if (HasFace(BRepPrim_ZMin))
311 myBuilder.AddShellFace(myShell,Face(BRepPrim_ZMin));
312 if (HasFace(BRepPrim_ZMax))
313 myBuilder.AddShellFace(myShell,Face(BRepPrim_ZMax));
7fd59977 314
ab860031 315 myShell.Closed (BRep_Tool::IsClosed (myShell));
7fd59977 316 myBuilder.CompleteShell(myShell);
317 ShellBuilt = Standard_True;
318 }
319 return myShell;
320}
321
322//=======================================================================
323//function : HasFace
324//purpose : true if the face exist in one direction
325//=======================================================================
326
a104bb8f 327Standard_Boolean BRepPrim_GWedge::HasFace (const BRepPrim_Direction d1) const
7fd59977 328{
a104bb8f 329 Standard_Boolean state = !myInfinite[BRepPrim_Wedge_NumDir1(d1)];
330 if ( d1 == BRepPrim_YMax ) state = state && ( Z2Max != Z2Min )
7fd59977 331 && ( X2Max != X2Min );
332 return state;
333}
334
335//=======================================================================
336//function : Plane
337//purpose :
338//=======================================================================
339
a104bb8f 340gp_Pln BRepPrim_GWedge::Plane(const BRepPrim_Direction d1)
7fd59977 341{
342
a104bb8f 343 Standard_Integer i = BRepPrim_Wedge_NumDir1(d1);
7fd59977 344
345 gp_Dir D;
346 gp_Vec VX = myAxes.XDirection();
347 gp_Vec VY = myAxes.YDirection();
348 gp_Vec VZ = myAxes.Direction();
349
350 switch (i/2) {
351
352 case 0 :
353 D = myAxes.XDirection();
354 break;
355
356 case 1 :
357 D = myAxes.YDirection();
358 break;
359
360 case 2 :
361 D = myAxes.Direction();
362 break;
363
364 };
1d47d8d0 365 Standard_Real X = 0., Y = 0., Z = 0.;
7fd59977 366
367 switch (i) {
368
369 case 0 :
370 // XMin
371 X = XMin;
372 Y = YMin;
373 Z = ZMin;
374 if ( X2Min != XMin ) D = gp_Dir((YMax-YMin)*VX+(XMin-X2Min)*VY);
375 break;
376
377 case 1 :
378 // XMax
379 X = XMax;
380 Y = YMin;
381 Z = ZMin;
382 if ( X2Max != XMax ) D = gp_Dir((YMax-YMin)*VX+(XMax-X2Max)*VY);
383 break;
384
385 case 2 :
386 // YMin
387 X = XMin;
388 Y = YMin;
389 Z = ZMin;
390 break;
391
392 case 3 :
393 // YMax
394 X = XMin;
395 Y = YMax;
396 Z = ZMin;
397 break;
398
399 case 4 :
400 // ZMin
401 X = XMin;
402 Y = YMin;
403 Z = ZMin;
404 if ( Z2Min != ZMin ) D = gp_Dir((YMax-YMin)*VZ+(ZMin-Z2Min)*VY);
405 break;
406
407 case 5 :
408 // ZMax
409 X = XMin;
410 Y = YMin;
411 Z = ZMax;
412 if ( Z2Max != ZMax ) D = gp_Dir((YMax-YMin)*VZ+(ZMax-Z2Max)*VY);
413 break;
414
415 };
416
417 gp_Pnt P = myAxes.Location();
418 P.Translate(X*gp_Vec(myAxes.XDirection()));
419 P.Translate(Y*gp_Vec(myAxes.YDirection()));
420 P.Translate(Z*gp_Vec(myAxes.Direction ()));
421 gp_Pln plane(P,D);
422 return plane;
423}
424
425//=======================================================================
426//function : Face
427//purpose : the face in one direction
428//=======================================================================
429
a104bb8f 430const TopoDS_Face& BRepPrim_GWedge::Face
431 (const BRepPrim_Direction d1)
7fd59977 432{
433
a104bb8f 434 Standard_Integer i = BRepPrim_Wedge_NumDir1(d1);
7fd59977 435
436 if (!FacesBuilt[i]) {
437 gp_Pln P = Plane(d1);
438 myBuilder.MakeFace(myFaces[i],P);
439 if (HasWire(d1)) myBuilder.AddFaceWire(myFaces[i],Wire(d1));
440 if ( i%2 == 0 ) myBuilder.ReverseFace(myFaces[i]);
441
442 // pcurves
1d47d8d0 443
a104bb8f 444 BRepPrim_Direction dd1 = BRepPrim_ZMin, dd2 = BRepPrim_YMax,
445 dd3 = BRepPrim_ZMax,dd4 = BRepPrim_YMin;
1d47d8d0 446
7fd59977 447 switch (i/2) {
448
449 case 0 :
450 // XMin XMax
a104bb8f 451 dd1 = BRepPrim_ZMin;
452 dd2 = BRepPrim_YMax;
453 dd3 = BRepPrim_ZMax;
454 dd4 = BRepPrim_YMin;
7fd59977 455 break;
456
457 case 1 :
458 // YMin YMax
a104bb8f 459 dd1 = BRepPrim_XMin;
460 dd2 = BRepPrim_ZMax;
461 dd3 = BRepPrim_XMax;
462 dd4 = BRepPrim_ZMin;
7fd59977 463 break;
464
465 case 2 :
466 // ZMin ZMax
a104bb8f 467 dd1 = BRepPrim_YMin;
468 dd2 = BRepPrim_XMax;
469 dd3 = BRepPrim_YMax;
470 dd4 = BRepPrim_XMin;
7fd59977 471 break;
472
473 };
474
475 gp_Lin L;
476 gp_Dir DX = P.XAxis().Direction();
477 gp_Dir DY = P.YAxis().Direction();
478 Standard_Real U,V,DU,DV;
479 if (HasEdge(d1,dd4)) {
480 L = Line(d1,dd4);
481 ElSLib::Parameters(P,L.Location(),U,V);
482 DU = L.Direction() * DX;
483 DV = L.Direction() * DY;
a104bb8f 484 myBuilder.SetPCurve(myEdges[BRepPrim_Wedge_NumDir2(d1,dd4)],
7fd59977 485 myFaces[i],
486 gp_Lin2d(gp_Pnt2d(U,V),gp_Dir2d(DU,DV)));
487 }
488 if (HasEdge(d1,dd3)) {
489 L = Line(d1,dd3);
490 ElSLib::Parameters(P,L.Location(),U,V);
491 DU = L.Direction() * DX;
492 DV = L.Direction() * DY;
a104bb8f 493 myBuilder.SetPCurve(myEdges[BRepPrim_Wedge_NumDir2(d1,dd3)],
7fd59977 494 myFaces[i],
495 gp_Lin2d(gp_Pnt2d(U,V),gp_Dir2d(DU,DV)));
496 }
497
498 if (HasEdge(d1,dd2)) {
499 L = Line(d1,dd2);
500 ElSLib::Parameters(P,L.Location(),U,V);
501 DU = L.Direction() * DX;
502 DV = L.Direction() * DY;
a104bb8f 503 myBuilder.SetPCurve(myEdges[BRepPrim_Wedge_NumDir2(d1,dd2)],
7fd59977 504 myFaces[i],
505 gp_Lin2d(gp_Pnt2d(U,V),gp_Dir2d(DU,DV)));
506 }
507
508 if (HasEdge(d1,dd1)) {
509 L = Line(d1,dd1);
510 ElSLib::Parameters(P,L.Location(),U,V);
511 DU = L.Direction() * DX;
512 DV = L.Direction() * DY;
a104bb8f 513 myBuilder.SetPCurve(myEdges[BRepPrim_Wedge_NumDir2(d1,dd1)],
7fd59977 514 myFaces[i],
515 gp_Lin2d(gp_Pnt2d(U,V),gp_Dir2d(DU,DV)));
516 }
517
518
519 myBuilder.CompleteFace(myFaces[i]);
520 FacesBuilt[i] = Standard_True;
521 }
522
523 return myFaces[i];
524
525}
526
527//=======================================================================
528//function : HasWire
529//purpose : trivial
530//=======================================================================
531
a104bb8f 532Standard_Boolean BRepPrim_GWedge::HasWire (const BRepPrim_Direction d1) const
7fd59977 533{
a104bb8f 534 Standard_Integer i = BRepPrim_Wedge_NumDir1(d1);
7fd59977 535
536 if (myInfinite[i]) return Standard_False;
a104bb8f 537 BRepPrim_Direction dd1 = BRepPrim_XMin,dd2 = BRepPrim_YMax,dd3 = BRepPrim_XMax ,dd4 = BRepPrim_ZMin;
1d47d8d0 538
7fd59977 539 switch (i/2) {
540
541 case 0 :
542 // XMin XMax
a104bb8f 543 dd1 = BRepPrim_ZMin;
544 dd2 = BRepPrim_YMax;
545 dd3 = BRepPrim_ZMax;
546 dd4 = BRepPrim_YMin;
7fd59977 547 break;
548
549 case 1 :
550 // YMin YMax
a104bb8f 551 dd1 = BRepPrim_XMin;
552 dd2 = BRepPrim_ZMax;
553 dd3 = BRepPrim_XMax;
554 dd4 = BRepPrim_ZMin;
7fd59977 555 break;
556
557 case 2 :
558 // ZMin ZMax
a104bb8f 559 dd1 = BRepPrim_YMin;
560 dd2 = BRepPrim_XMax;
561 dd3 = BRepPrim_YMax;
562 dd4 = BRepPrim_XMin;
7fd59977 563 break;
0797d9d3 564#ifndef OCCT_DEBUG
7fd59977 565 default:
566 break;
567#endif
568 };
569
570 return HasEdge(d1,dd1)||HasEdge(d1,dd2)||HasEdge(d1,dd3)||HasEdge(d1,dd4);
571
572}
573
574//=======================================================================
575//function : Wire
576//purpose : trivial
577//=======================================================================
578
a104bb8f 579const TopoDS_Wire& BRepPrim_GWedge::Wire
580 (const BRepPrim_Direction d1)
7fd59977 581{
a104bb8f 582 Standard_Integer i = BRepPrim_Wedge_NumDir1(d1);
7fd59977 583
a104bb8f 584 BRepPrim_Direction dd1 = BRepPrim_XMin,dd2 = BRepPrim_YMax,dd3 = BRepPrim_XMax ,dd4 = BRepPrim_ZMin;
1d47d8d0 585
7fd59977 586 if (!WiresBuilt[i]) {
587
588 switch (i/2) {
589
590 case 0 :
591 // XMin XMax
a104bb8f 592 dd1 = BRepPrim_ZMin;
593 dd2 = BRepPrim_YMax;
594 dd3 = BRepPrim_ZMax;
595 dd4 = BRepPrim_YMin;
7fd59977 596 break;
597
598 case 1 :
599 // YMin YMax
a104bb8f 600 dd1 = BRepPrim_XMin;
601 dd2 = BRepPrim_ZMax;
602 dd3 = BRepPrim_XMax;
603 dd4 = BRepPrim_ZMin;
7fd59977 604 break;
605
606 case 2 :
607 // ZMin ZMax
a104bb8f 608 dd1 = BRepPrim_YMin;
609 dd2 = BRepPrim_XMax;
610 dd3 = BRepPrim_YMax;
611 dd4 = BRepPrim_XMin;
7fd59977 612 break;
7fd59977 613 default:
614 break;
7fd59977 615 };
616
617 myBuilder.MakeWire(myWires[i]);
618
619 if (HasEdge(d1,dd4))
620 myBuilder.AddWireEdge(myWires[i],Edge(d1,dd4),Standard_False);
621 if (HasEdge(d1,dd3))
622 myBuilder.AddWireEdge(myWires[i],Edge(d1,dd3),Standard_False);
623 if (HasEdge(d1,dd2))
624 myBuilder.AddWireEdge(myWires[i],Edge(d1,dd2),Standard_True );
625 if (HasEdge(d1,dd1))
626 myBuilder.AddWireEdge(myWires[i],Edge(d1,dd1),Standard_True );
627
628 myBuilder.CompleteWire(myWires[i]);
629 WiresBuilt[i] = Standard_True;
630 }
631
632 return myWires[i];
633
634}
635
636//=======================================================================
637//function : HasEdge
638//purpose : trivial
639//=======================================================================
640
a104bb8f 641Standard_Boolean BRepPrim_GWedge::HasEdge (const BRepPrim_Direction d1,
642 const BRepPrim_Direction d2) const
c48e2889 643{
a104bb8f 644 Standard_Boolean state = !(myInfinite[BRepPrim_Wedge_NumDir1(d1)] ||
c48e2889 645 myInfinite[BRepPrim_Wedge_NumDir1(d2)]);
a104bb8f 646 Standard_Integer i = BRepPrim_Wedge_NumDir2(d1,d2);
7fd59977 647 if ( i == 6 || i == 7 ) state = state && ( X2Max != X2Min );
648 else if ( i == 1 || i == 3 ) state = state && ( Z2Max != Z2Min );
649 return state;
650}
651
652//=======================================================================
653//function : Line
654//purpose : trivial
655//=======================================================================
656
a104bb8f 657gp_Lin BRepPrim_GWedge::Line
658 (const BRepPrim_Direction d1,
659 const BRepPrim_Direction d2)
7fd59977 660{
9775fa61 661 if (!HasEdge(d1,d2)) throw Standard_DomainError();
7fd59977 662
a104bb8f 663 Standard_Integer i = BRepPrim_Wedge_NumDir2(d1,d2);
1d47d8d0 664
7fd59977 665 Standard_Real X =0., Y =0., Z =0.;
1d47d8d0 666
7fd59977 667 gp_Dir D;
668 gp_Vec VX = myAxes.XDirection();
669 gp_Vec VY = myAxes.YDirection();
670 gp_Vec VZ = myAxes.Direction();
c48e2889 671
7fd59977 672 switch (i/4) {
c48e2889 673
7fd59977 674 case 0 :
675 D = myAxes.Direction();
7fd59977 676 break;
c48e2889 677
7fd59977 678 case 1 :
679 D = myAxes.XDirection();
7fd59977 680 break;
c48e2889 681
7fd59977 682 case 2 :
683 D = myAxes.YDirection();
7fd59977 684 break;
c48e2889 685
7fd59977 686 };
c48e2889 687
7fd59977 688 switch (i) {
c48e2889 689
7fd59977 690 case 0 :
691 // XMin YMin
692 X = XMin;
693 Y = YMin;
694 Z = ZMin;
695 break;
c48e2889 696
7fd59977 697 case 1 :
698 // XMin YMax
699 X = X2Min;
700 Y = YMax;
701 Z = Z2Min;
702 break;
c48e2889 703
7fd59977 704 case 2 :
705 // XMax YMin
706 X = XMax;
707 Y = YMin;
708 Z = ZMin;
709 break;
c48e2889 710
7fd59977 711 case 3 :
712 // XMax YMax
713 X = X2Max;
714 Y = YMax;
715 Z = Z2Min;
716 break;
c48e2889 717
7fd59977 718 case 4 :
719 // YMin ZMin
720 X = XMin;
721 Y = YMin;
722 Z = ZMin;
723 break;
c48e2889 724
7fd59977 725 case 5 :
726 // YMin ZMax
727 X = XMin;
728 Y = YMin;
729 Z = ZMax;
730 break;
c48e2889 731
7fd59977 732 case 6 :
733 // YMax ZMin
734 X = X2Min;
735 Y = YMax;
736 Z = Z2Min;
737 break;
c48e2889 738
7fd59977 739 case 7 :
740 // YMax ZMax
741 X = X2Min;
742 Y = YMax;
743 Z = Z2Max;
744 break;
c48e2889 745
7fd59977 746 case 8 :
747 // ZMin XMin
748 X = XMin;
749 Y = YMin;
750 Z = ZMin;
c48e2889 751 if ( (XMin != X2Min) || (ZMin != Z2Min) )
752 {
b70bbe58 753 D = gp_Vec( (X2Min-XMin)*VX + (YMax-YMin)*VY + (Z2Min-ZMin)*VZ);
c48e2889 754 }
7fd59977 755 break;
c48e2889 756
7fd59977 757 case 9 :
758 // ZMax XMin
759 X = XMin;
760 Y = YMin;
761 Z = ZMax;
c48e2889 762 if ( (XMin != X2Min) || (ZMax != Z2Max) )
763 {
7fd59977 764 D = gp_Vec( (X2Min-XMin)*VX + (YMax-YMin)*VY + (Z2Max-ZMax)*VZ);
c48e2889 765 }
7fd59977 766 break;
c48e2889 767
7fd59977 768 case 10 :
769 // ZMin XMax
770 X = XMax;
771 Y = YMin;
772 Z = ZMin;
c48e2889 773 if ( (XMax != X2Max) || (ZMin != Z2Min) )
774 {
7fd59977 775 D = gp_Vec( (X2Max-XMax)*VX + (YMax-YMin)*VY + (Z2Min-ZMin)*VZ);
c48e2889 776 }
7fd59977 777 break;
c48e2889 778
7fd59977 779 case 11 :
780 // ZMax XMax
781 X = XMax;
782 Y = YMin;
783 Z = ZMax;
c48e2889 784 if ( (XMax != X2Max) || (ZMax != Z2Max) )
785 {
7fd59977 786 D = gp_Vec( (X2Max-XMax)*VX + (YMax-YMin)*VY + (Z2Max-ZMax)*VZ);
c48e2889 787 }
7fd59977 788 break;
c48e2889 789
7fd59977 790 }
791
792 gp_Pnt P = myAxes.Location();
793 P.Translate(X*gp_Vec(myAxes.XDirection()));
794 P.Translate(Y*gp_Vec(myAxes.YDirection()));
795 P.Translate(Z*gp_Vec(myAxes.Direction ()));
796 return gp_Lin(gp_Ax1(P,D));
c48e2889 797
7fd59977 798}
799
800//=======================================================================
801//function : Edge
802//purpose : trivial
803//=======================================================================
804
a104bb8f 805const TopoDS_Edge& BRepPrim_GWedge::Edge
806 (const BRepPrim_Direction d1,
807 const BRepPrim_Direction d2)
7fd59977 808{
9775fa61 809 if (!HasEdge(d1,d2)) throw Standard_DomainError();
7fd59977 810
a104bb8f 811 Standard_Integer i = BRepPrim_Wedge_NumDir2(d1,d2);
7fd59977 812
813 if (!EdgesBuilt[i]) {
1d47d8d0 814
a104bb8f 815 BRepPrim_Direction dd1 = BRepPrim_XMin ,dd2 = BRepPrim_XMax;
1d47d8d0 816
7fd59977 817 switch (i/4) {
818
819 case 0 :
a104bb8f 820 dd1 = BRepPrim_ZMin;
821 dd2 = BRepPrim_ZMax;
7fd59977 822 break;
823
824 case 1 :
a104bb8f 825 dd1 = BRepPrim_XMin;
826 dd2 = BRepPrim_XMax;
7fd59977 827 break;
828
829 case 2 :
a104bb8f 830 dd1 = BRepPrim_YMin;
831 dd2 = BRepPrim_YMax;
7fd59977 832 break;
96a95605 833
7fd59977 834 default:
835 break;
7fd59977 836 };
837
838 gp_Lin L = Line(d1,d2);
839 myBuilder.MakeEdge(myEdges[i],L);
840
841 if (HasVertex(d1,d2,dd2)) {
842 myBuilder.AddEdgeVertex(myEdges[i],Vertex(d1,d2,dd2),
843 ElCLib::Parameter(L,Point(d1,d2,dd2)),
844 Standard_False);
845 }
846 if (HasVertex(d1,d2,dd1)) {
847 myBuilder.AddEdgeVertex(myEdges[i],Vertex(d1,d2,dd1),
848 ElCLib::Parameter(L,Point(d1,d2,dd1)),
849 Standard_True );
850 }
851
852 if ( Z2Max == Z2Min ) {
853 if ( i == 6 ) {
854 myEdges[7] = myEdges[6];
855 EdgesBuilt[7] = Standard_True;
856 }
857 else if ( i == 7 ) {
858 myEdges[6] = myEdges[7];
859 EdgesBuilt[6] = Standard_True;
860 }
861 }
862 if ( X2Max == X2Min ) {
863 if ( i == 1 ) {
864 myEdges[3] = myEdges[1];
865 EdgesBuilt[3] = Standard_True;
866 }
867 else if ( i == 3 ) {
868 myEdges[1] = myEdges[3];
869 EdgesBuilt[1] = Standard_True;
870 }
871 }
872
873 myBuilder.CompleteEdge(myEdges[i]);
874 EdgesBuilt[i] = Standard_True;
875 }
876
877 return myEdges[i];
878
879}
880
881//=======================================================================
882//function : HasVertex
883//purpose : trivial
884//=======================================================================
885
a104bb8f 886Standard_Boolean BRepPrim_GWedge::HasVertex
887 (const BRepPrim_Direction d1,
888 const BRepPrim_Direction d2,
889 const BRepPrim_Direction d3) const
890{ return !(myInfinite[BRepPrim_Wedge_NumDir1(d1)] ||
891 myInfinite[BRepPrim_Wedge_NumDir1(d2)] ||
892 myInfinite[BRepPrim_Wedge_NumDir1(d3)]); }
7fd59977 893
894//=======================================================================
895//function : Point
896//purpose : trivial
897//=======================================================================
898
a104bb8f 899gp_Pnt BRepPrim_GWedge::Point
900 (const BRepPrim_Direction d1,
901 const BRepPrim_Direction d2,
902 const BRepPrim_Direction d3)
7fd59977 903{
9775fa61 904 if (!HasVertex(d1,d2,d3)) throw Standard_DomainError();
7fd59977 905
a104bb8f 906 Standard_Integer i = BRepPrim_Wedge_NumDir3(d1,d2,d3);
1d47d8d0 907
7fd59977 908 Standard_Real X =0., Y =0., Z =0.;
1d47d8d0 909
7fd59977 910 switch (i) {
911
912 case 0 :
913 X = XMin;
914 Y = YMin;
915 Z = ZMin;
916 break;
917
918 case 1 :
919 X = XMin;
920 Y = YMin;
921 Z = ZMax;
922 break;
923
924 case 2 :
925 X = X2Min;
926 Y = YMax;
927 Z = Z2Min;
928 break;
929
930 case 3 :
931 X = X2Min;
932 Y = YMax;
933 Z = Z2Max;
934 break;
935
936 case 4 :
937 X = XMax;
938 Y = YMin;
939 Z = ZMin;
940 break;
941
942 case 5 :
943 X = XMax;
944 Y = YMin;
945 Z = ZMax;
946 break;
947
948 case 6 :
949 X = X2Max;
950 Y = YMax;
951 Z = Z2Min;
952 break;
953
954 case 7 :
955 X = X2Max;
956 Y = YMax;
957 Z = Z2Max;
958 break;
959
960 };
961
962 gp_Pnt P = myAxes.Location();
963 P.Translate(X*gp_Vec(myAxes.XDirection()));
964 P.Translate(Y*gp_Vec(myAxes.YDirection()));
965 P.Translate(Z*gp_Vec(myAxes.Direction ()));
966 return P;
967}
968
969//=======================================================================
970//function : Vertex
971//purpose : trivial
972//=======================================================================
973
a104bb8f 974const TopoDS_Vertex& BRepPrim_GWedge::Vertex
975 (const BRepPrim_Direction d1,
976 const BRepPrim_Direction d2,
977 const BRepPrim_Direction d3)
7fd59977 978{
9775fa61 979 if (!HasVertex(d1,d2,d3)) throw Standard_DomainError();
7fd59977 980
a104bb8f 981 Standard_Integer i = BRepPrim_Wedge_NumDir3(d1,d2,d3);
7fd59977 982
983 if (!VerticesBuilt[i]) {
984
985 myBuilder.MakeVertex(myVertices[i],Point(d1,d2,d3));
986
987 if ( Z2Max == Z2Min ) {
988 if ( i == 2 || i == 6 ) {
989 myVertices[3] = myVertices[2];
990 myVertices[7] = myVertices[6];
991 VerticesBuilt[3] = Standard_True;
992 VerticesBuilt[7] = Standard_True;
993 }
994 else if ( i == 3 || i == 7 ) {
995 myVertices[2] = myVertices[3];
996 myVertices[6] = myVertices[7];
997 VerticesBuilt[2] = Standard_True;
998 VerticesBuilt[6] = Standard_True;
999 }
1000 }
1001 if ( X2Max == X2Min ) {
1002 if ( i == 2 || i == 3 ) {
1003 myVertices[6] = myVertices[2];
1004 myVertices[7] = myVertices[3];
1005 VerticesBuilt[6] = Standard_True;
1006 VerticesBuilt[7] = Standard_True;
1007 }
1008 else if ( i == 6 || i == 7 ) {
1009 myVertices[2] = myVertices[6];
1010 myVertices[3] = myVertices[7];
1011 VerticesBuilt[2] = Standard_True;
1012 VerticesBuilt[3] = Standard_True;
1013 }
1014 }
1015
1016 VerticesBuilt[i] = Standard_True;
1017 }
1018
1019 return myVertices[i];
1020
1021}
1022