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