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 | |
42 | static const Standard_Integer num[6] = {0,1,2,3,4,5}; |
43 | static const Standard_Integer val[6] = {0,4,0,2,0,1}; |
44 | static 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 |
56 | static 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 |
64 | static 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); |
7fd59977 |
70 | if ( i1/2 == i2/2 ) Standard_DomainError::Raise(); |
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 |
79 | static 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 ) || |
89 | ( i3/2 == i1/2 )) Standard_DomainError::Raise(); |
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 |
98 | static 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++) |
105 | if (V[i]) Standard_DomainError::Raise(); |
106 | for (i = 0; i < NBEDGES; i++) |
107 | if (E[i]) Standard_DomainError::Raise(); |
108 | for (i = 0; i < NBWIRES; i++) |
109 | if (W[i]) Standard_DomainError::Raise(); |
110 | for (i = 0; i < NBFACES; i++) |
111 | if (F[i]) Standard_DomainError::Raise(); |
112 | } |
113 | |
114 | //======================================================================= |
a104bb8f |
115 | //function : BRepPrim_Wedge_Init |
7fd59977 |
116 | //purpose : Set arrays to Standard_False |
117 | //======================================================================= |
118 | |
a104bb8f |
119 | static 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 |
142 | BRepPrim_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() ) ) |
164 | Standard_DomainError::Raise(); |
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 |
174 | BRepPrim_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 ) ) |
198 | Standard_DomainError::Raise(); |
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 |
208 | BRepPrim_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 ) ) |
239 | Standard_DomainError::Raise(); |
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 |
251 | gp_Ax2 BRepPrim_GWedge::Axes () const { return myAxes; } |
252 | Standard_Real BRepPrim_GWedge::GetXMin () const { return XMin; } |
253 | Standard_Real BRepPrim_GWedge::GetYMin () const { return YMin; } |
254 | Standard_Real BRepPrim_GWedge::GetZMin () const { return ZMin; } |
255 | Standard_Real BRepPrim_GWedge::GetZ2Min () const { return Z2Min; } |
256 | Standard_Real BRepPrim_GWedge::GetX2Min () const { return X2Min; } |
257 | Standard_Real BRepPrim_GWedge::GetXMax () const { return XMax; } |
258 | Standard_Real BRepPrim_GWedge::GetYMax () const { return YMax; } |
259 | Standard_Real BRepPrim_GWedge::GetZMax () const { return ZMax; } |
260 | Standard_Real BRepPrim_GWedge::GetZ2Max () const { return Z2Max; } |
261 | Standard_Real BRepPrim_GWedge::GetX2Max () const { return X2Max; } |
7fd59977 |
262 | |
263 | //======================================================================= |
264 | //function : Open |
265 | //purpose : trivial |
266 | //======================================================================= |
267 | |
a104bb8f |
268 | void 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 |
279 | void 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 |
290 | Standard_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 |
298 | const 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 |
327 | Standard_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 |
340 | gp_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 |
430 | const 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 |
532 | Standard_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 |
579 | const 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 |
641 | Standard_Boolean BRepPrim_GWedge::HasEdge (const BRepPrim_Direction d1, |
642 | const BRepPrim_Direction d2) const |
7fd59977 |
643 | { |
a104bb8f |
644 | Standard_Boolean state = !(myInfinite[BRepPrim_Wedge_NumDir1(d1)] || |
645 | myInfinite[BRepPrim_Wedge_NumDir1(d2)]); |
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 |
657 | gp_Lin BRepPrim_GWedge::Line |
658 | (const BRepPrim_Direction d1, |
659 | const BRepPrim_Direction d2) |
7fd59977 |
660 | { |
661 | if (!HasEdge(d1,d2)) Standard_DomainError::Raise(); |
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(); |
7fd59977 |
671 | |
672 | switch (i/4) { |
673 | |
674 | case 0 : |
675 | D = myAxes.Direction(); |
7fd59977 |
676 | break; |
677 | |
678 | case 1 : |
679 | D = myAxes.XDirection(); |
7fd59977 |
680 | break; |
681 | |
682 | case 2 : |
683 | D = myAxes.YDirection(); |
7fd59977 |
684 | break; |
685 | |
686 | }; |
687 | |
688 | switch (i) { |
689 | |
690 | case 0 : |
691 | // XMin YMin |
692 | X = XMin; |
693 | Y = YMin; |
694 | Z = ZMin; |
695 | break; |
696 | |
697 | case 1 : |
698 | // XMin YMax |
699 | X = X2Min; |
700 | Y = YMax; |
701 | Z = Z2Min; |
702 | break; |
703 | |
704 | case 2 : |
705 | // XMax YMin |
706 | X = XMax; |
707 | Y = YMin; |
708 | Z = ZMin; |
709 | break; |
710 | |
711 | case 3 : |
712 | // XMax YMax |
713 | X = X2Max; |
714 | Y = YMax; |
715 | Z = Z2Min; |
716 | break; |
717 | |
718 | case 4 : |
719 | // YMin ZMin |
720 | X = XMin; |
721 | Y = YMin; |
722 | Z = ZMin; |
723 | break; |
724 | |
725 | case 5 : |
726 | // YMin ZMax |
727 | X = XMin; |
728 | Y = YMin; |
729 | Z = ZMax; |
730 | break; |
731 | |
732 | case 6 : |
733 | // YMax ZMin |
734 | X = X2Min; |
735 | Y = YMax; |
736 | Z = Z2Min; |
737 | break; |
738 | |
739 | case 7 : |
740 | // YMax ZMax |
741 | X = X2Min; |
742 | Y = YMax; |
743 | Z = Z2Max; |
744 | break; |
745 | |
746 | case 8 : |
747 | // ZMin XMin |
748 | X = XMin; |
749 | Y = YMin; |
750 | Z = ZMin; |
751 | if ( (XMin != X2Min) || (ZMin != Z2Min) ) |
b70bbe58 |
752 | D = gp_Vec( (X2Min-XMin)*VX + (YMax-YMin)*VY + (Z2Min-ZMin)*VZ); |
7fd59977 |
753 | break; |
754 | |
755 | case 9 : |
756 | // ZMax XMin |
757 | X = XMin; |
758 | Y = YMin; |
759 | Z = ZMax; |
760 | if ( (XMin != X2Min) || (ZMax != Z2Max) ) |
761 | D = gp_Vec( (X2Min-XMin)*VX + (YMax-YMin)*VY + (Z2Max-ZMax)*VZ); |
762 | break; |
763 | |
764 | case 10 : |
765 | // ZMin XMax |
766 | X = XMax; |
767 | Y = YMin; |
768 | Z = ZMin; |
769 | if ( (XMax != X2Max) || (ZMin != Z2Min) ) |
770 | D = gp_Vec( (X2Max-XMax)*VX + (YMax-YMin)*VY + (Z2Min-ZMin)*VZ); |
771 | break; |
772 | |
773 | case 11 : |
774 | // ZMax XMax |
775 | X = XMax; |
776 | Y = YMin; |
777 | Z = ZMax; |
778 | if ( (XMax != X2Max) || (ZMax != Z2Max) ) |
779 | D = gp_Vec(gp_Pnt(XMax,YMin,ZMax),gp_Pnt(X2Max,YMax,Z2Max)); |
780 | D = gp_Vec( (X2Max-XMax)*VX + (YMax-YMin)*VY + (Z2Max-ZMax)*VZ); |
781 | break; |
782 | |
783 | } |
784 | |
785 | gp_Pnt P = myAxes.Location(); |
786 | P.Translate(X*gp_Vec(myAxes.XDirection())); |
787 | P.Translate(Y*gp_Vec(myAxes.YDirection())); |
788 | P.Translate(Z*gp_Vec(myAxes.Direction ())); |
789 | return gp_Lin(gp_Ax1(P,D)); |
790 | |
791 | } |
792 | |
793 | //======================================================================= |
794 | //function : Edge |
795 | //purpose : trivial |
796 | //======================================================================= |
797 | |
a104bb8f |
798 | const TopoDS_Edge& BRepPrim_GWedge::Edge |
799 | (const BRepPrim_Direction d1, |
800 | const BRepPrim_Direction d2) |
7fd59977 |
801 | { |
802 | if (!HasEdge(d1,d2)) Standard_DomainError::Raise(); |
803 | |
a104bb8f |
804 | Standard_Integer i = BRepPrim_Wedge_NumDir2(d1,d2); |
7fd59977 |
805 | |
806 | if (!EdgesBuilt[i]) { |
1d47d8d0 |
807 | |
a104bb8f |
808 | BRepPrim_Direction dd1 = BRepPrim_XMin ,dd2 = BRepPrim_XMax; |
1d47d8d0 |
809 | |
7fd59977 |
810 | switch (i/4) { |
811 | |
812 | case 0 : |
a104bb8f |
813 | dd1 = BRepPrim_ZMin; |
814 | dd2 = BRepPrim_ZMax; |
7fd59977 |
815 | break; |
816 | |
817 | case 1 : |
a104bb8f |
818 | dd1 = BRepPrim_XMin; |
819 | dd2 = BRepPrim_XMax; |
7fd59977 |
820 | break; |
821 | |
822 | case 2 : |
a104bb8f |
823 | dd1 = BRepPrim_YMin; |
824 | dd2 = BRepPrim_YMax; |
7fd59977 |
825 | break; |
96a95605 |
826 | |
7fd59977 |
827 | default: |
828 | break; |
7fd59977 |
829 | }; |
830 | |
831 | gp_Lin L = Line(d1,d2); |
832 | myBuilder.MakeEdge(myEdges[i],L); |
833 | |
834 | if (HasVertex(d1,d2,dd2)) { |
835 | myBuilder.AddEdgeVertex(myEdges[i],Vertex(d1,d2,dd2), |
836 | ElCLib::Parameter(L,Point(d1,d2,dd2)), |
837 | Standard_False); |
838 | } |
839 | if (HasVertex(d1,d2,dd1)) { |
840 | myBuilder.AddEdgeVertex(myEdges[i],Vertex(d1,d2,dd1), |
841 | ElCLib::Parameter(L,Point(d1,d2,dd1)), |
842 | Standard_True ); |
843 | } |
844 | |
845 | if ( Z2Max == Z2Min ) { |
846 | if ( i == 6 ) { |
847 | myEdges[7] = myEdges[6]; |
848 | EdgesBuilt[7] = Standard_True; |
849 | } |
850 | else if ( i == 7 ) { |
851 | myEdges[6] = myEdges[7]; |
852 | EdgesBuilt[6] = Standard_True; |
853 | } |
854 | } |
855 | if ( X2Max == X2Min ) { |
856 | if ( i == 1 ) { |
857 | myEdges[3] = myEdges[1]; |
858 | EdgesBuilt[3] = Standard_True; |
859 | } |
860 | else if ( i == 3 ) { |
861 | myEdges[1] = myEdges[3]; |
862 | EdgesBuilt[1] = Standard_True; |
863 | } |
864 | } |
865 | |
866 | myBuilder.CompleteEdge(myEdges[i]); |
867 | EdgesBuilt[i] = Standard_True; |
868 | } |
869 | |
870 | return myEdges[i]; |
871 | |
872 | } |
873 | |
874 | //======================================================================= |
875 | //function : HasVertex |
876 | //purpose : trivial |
877 | //======================================================================= |
878 | |
a104bb8f |
879 | Standard_Boolean BRepPrim_GWedge::HasVertex |
880 | (const BRepPrim_Direction d1, |
881 | const BRepPrim_Direction d2, |
882 | const BRepPrim_Direction d3) const |
883 | { return !(myInfinite[BRepPrim_Wedge_NumDir1(d1)] || |
884 | myInfinite[BRepPrim_Wedge_NumDir1(d2)] || |
885 | myInfinite[BRepPrim_Wedge_NumDir1(d3)]); } |
7fd59977 |
886 | |
887 | //======================================================================= |
888 | //function : Point |
889 | //purpose : trivial |
890 | //======================================================================= |
891 | |
a104bb8f |
892 | gp_Pnt BRepPrim_GWedge::Point |
893 | (const BRepPrim_Direction d1, |
894 | const BRepPrim_Direction d2, |
895 | const BRepPrim_Direction d3) |
7fd59977 |
896 | { |
897 | if (!HasVertex(d1,d2,d3)) Standard_DomainError::Raise(); |
898 | |
a104bb8f |
899 | Standard_Integer i = BRepPrim_Wedge_NumDir3(d1,d2,d3); |
1d47d8d0 |
900 | |
7fd59977 |
901 | Standard_Real X =0., Y =0., Z =0.; |
1d47d8d0 |
902 | |
7fd59977 |
903 | switch (i) { |
904 | |
905 | case 0 : |
906 | X = XMin; |
907 | Y = YMin; |
908 | Z = ZMin; |
909 | break; |
910 | |
911 | case 1 : |
912 | X = XMin; |
913 | Y = YMin; |
914 | Z = ZMax; |
915 | break; |
916 | |
917 | case 2 : |
918 | X = X2Min; |
919 | Y = YMax; |
920 | Z = Z2Min; |
921 | break; |
922 | |
923 | case 3 : |
924 | X = X2Min; |
925 | Y = YMax; |
926 | Z = Z2Max; |
927 | break; |
928 | |
929 | case 4 : |
930 | X = XMax; |
931 | Y = YMin; |
932 | Z = ZMin; |
933 | break; |
934 | |
935 | case 5 : |
936 | X = XMax; |
937 | Y = YMin; |
938 | Z = ZMax; |
939 | break; |
940 | |
941 | case 6 : |
942 | X = X2Max; |
943 | Y = YMax; |
944 | Z = Z2Min; |
945 | break; |
946 | |
947 | case 7 : |
948 | X = X2Max; |
949 | Y = YMax; |
950 | Z = Z2Max; |
951 | break; |
952 | |
953 | }; |
954 | |
955 | gp_Pnt P = myAxes.Location(); |
956 | P.Translate(X*gp_Vec(myAxes.XDirection())); |
957 | P.Translate(Y*gp_Vec(myAxes.YDirection())); |
958 | P.Translate(Z*gp_Vec(myAxes.Direction ())); |
959 | return P; |
960 | } |
961 | |
962 | //======================================================================= |
963 | //function : Vertex |
964 | //purpose : trivial |
965 | //======================================================================= |
966 | |
a104bb8f |
967 | const TopoDS_Vertex& BRepPrim_GWedge::Vertex |
968 | (const BRepPrim_Direction d1, |
969 | const BRepPrim_Direction d2, |
970 | const BRepPrim_Direction d3) |
7fd59977 |
971 | { |
972 | if (!HasVertex(d1,d2,d3)) Standard_DomainError::Raise(); |
973 | |
a104bb8f |
974 | Standard_Integer i = BRepPrim_Wedge_NumDir3(d1,d2,d3); |
7fd59977 |
975 | |
976 | if (!VerticesBuilt[i]) { |
977 | |
978 | myBuilder.MakeVertex(myVertices[i],Point(d1,d2,d3)); |
979 | |
980 | if ( Z2Max == Z2Min ) { |
981 | if ( i == 2 || i == 6 ) { |
982 | myVertices[3] = myVertices[2]; |
983 | myVertices[7] = myVertices[6]; |
984 | VerticesBuilt[3] = Standard_True; |
985 | VerticesBuilt[7] = Standard_True; |
986 | } |
987 | else if ( i == 3 || i == 7 ) { |
988 | myVertices[2] = myVertices[3]; |
989 | myVertices[6] = myVertices[7]; |
990 | VerticesBuilt[2] = Standard_True; |
991 | VerticesBuilt[6] = Standard_True; |
992 | } |
993 | } |
994 | if ( X2Max == X2Min ) { |
995 | if ( i == 2 || i == 3 ) { |
996 | myVertices[6] = myVertices[2]; |
997 | myVertices[7] = myVertices[3]; |
998 | VerticesBuilt[6] = Standard_True; |
999 | VerticesBuilt[7] = Standard_True; |
1000 | } |
1001 | else if ( i == 6 || i == 7 ) { |
1002 | myVertices[2] = myVertices[6]; |
1003 | myVertices[3] = myVertices[7]; |
1004 | VerticesBuilt[2] = Standard_True; |
1005 | VerticesBuilt[3] = Standard_True; |
1006 | } |
1007 | } |
1008 | |
1009 | VerticesBuilt[i] = Standard_True; |
1010 | } |
1011 | |
1012 | return myVertices[i]; |
1013 | |
1014 | } |
1015 | |