Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1994-03-07 |
2 | // Created by: Bruno DUMORTIER | |
3 | // Copyright (c) 1994-1999 Matra Datavision | |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS | |
5 | // | |
6 | // The content of this file is subject to the Open CASCADE Technology Public | |
7 | // License Version 6.5 (the "License"). You may not use the content of this file | |
8 | // except in compliance with the License. Please obtain a copy of the License | |
9 | // at http://www.opencascade.org and read it completely before using this file. | |
10 | // | |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
13 | // | |
14 | // The Original Code and all software distributed under the License is | |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
16 | // Initial Developer hereby disclaims all such warranties, including without | |
17 | // limitation, any warranties of merchantability, fitness for a particular | |
18 | // purpose or non-infringement. Please see the License for the specific terms | |
19 | // and conditions governing the rights and limitations under the License. | |
20 | ||
7fd59977 | 21 | |
22 | #include <BRepFill_Generator.ixx> | |
23 | ||
24 | #include <TopoDS_Face.hxx> | |
25 | #include <TopoDS_Wire.hxx> | |
26 | #include <TopoDS_Edge.hxx> | |
27 | #include <TopoDS_Vertex.hxx> | |
28 | #include <BRep_Builder.hxx> | |
29 | #include <TopLoc_Location.hxx> | |
30 | #include <TopExp_Explorer.hxx> | |
31 | #include <gp_Pnt2d.hxx> | |
32 | #include <gp_Dir2d.hxx> | |
33 | #include <gp_Ax1.hxx> | |
34 | #include <gp_Ax3.hxx> | |
35 | #include <gp_Circ.hxx> | |
36 | #include <gp_Lin.hxx> | |
37 | #include <GeomAbs_Shape.hxx> | |
38 | #include <GeomAdaptor_Curve.hxx> | |
39 | #include <Geom_Circle.hxx> | |
40 | #include <Geom_Line.hxx> | |
41 | #include <Geom_Curve.hxx> | |
42 | #include <Geom_BezierCurve.hxx> | |
43 | #include <Geom_TrimmedCurve.hxx> | |
44 | #include <Geom_Surface.hxx> | |
45 | #include <Geom_Plane.hxx> | |
46 | #include <Geom_CylindricalSurface.hxx> | |
47 | #include <Geom_ConicalSurface.hxx> | |
48 | #include <Geom_RectangularTrimmedSurface.hxx> | |
49 | #include <Geom2d_Line.hxx> | |
50 | #include <Geom2d_BezierCurve.hxx> | |
51 | #include <GeomFill_Generator.hxx> | |
52 | ||
53 | #include <TopTools_DataMapOfShapeShape.hxx> | |
54 | #include <GeomFill.hxx> | |
55 | #include <BRep_Tool.hxx> | |
56 | #include <TopoDS.hxx> | |
57 | #include <TopExp.hxx> | |
58 | #include <Precision.hxx> | |
59 | #include <BRepLib.hxx> | |
60 | ||
61 | #include <TColgp_Array1OfPnt.hxx> | |
62 | #include <TColgp_Array1OfPnt2d.hxx> | |
63 | #include <Geom_BSplineCurve.hxx> | |
64 | #include <gp_Vec.hxx> | |
65 | #include <GeomConvert.hxx> | |
66 | ||
67 | #include <BRepTools_WireExplorer.hxx> | |
68 | #include <BRepTools.hxx> | |
69 | ||
70 | ||
71 | ||
72 | //======================================================================= | |
73 | //function : DetectKPart | |
74 | //purpose : | |
75 | //======================================================================= | |
76 | ||
77 | Standard_Integer DetectKPart(const TopoDS_Edge& Edge1, | |
78 | const TopoDS_Edge& Edge2) | |
79 | { | |
0d969553 | 80 | // initializations |
7fd59977 | 81 | Standard_Integer IType = 0; |
82 | ||
0d969553 | 83 | // characteristics of the first edge |
7fd59977 | 84 | Standard_Real first1, last1, first2, last2, ff, ll; |
85 | TopLoc_Location loc; | |
86 | TopoDS_Vertex V1, V2; | |
87 | Handle(Geom_Curve) curv1, curv; | |
88 | GeomAdaptor_Curve AdC1; | |
89 | Standard_Boolean degen1 = BRep_Tool::Degenerated(Edge1); | |
90 | ||
0d969553 | 91 | // find the particular case |
7fd59977 | 92 | gp_Pnt pos1, pos; |
93 | Standard_Real dist; | |
7fd59977 | 94 | Standard_Real dist1 =0.; |
7fd59977 | 95 | gp_Ax1 axe1, axe; |
96 | ||
97 | if (degen1) { | |
98 | IType = -2; | |
99 | TopExp::Vertices(Edge1,V1,V2); | |
100 | pos1 = BRep_Tool::Pnt(V1); | |
101 | } | |
102 | else { | |
103 | curv1 = BRep_Tool::Curve(Edge1, loc, first1, last1); | |
104 | curv1 = | |
105 | Handle(Geom_Curve)::DownCast(curv1->Transformed(loc.Transformation())); | |
106 | ff = first1; | |
107 | ll = last1; | |
108 | if (Edge1.Orientation() == TopAbs_REVERSED) { | |
109 | curv1->Reverse(); | |
110 | first1 = curv1->ReversedParameter(ll); | |
111 | last1 = curv1->ReversedParameter(ff); | |
112 | } | |
113 | AdC1.Load(curv1); | |
114 | if (AdC1.GetType() == GeomAbs_Circle) { | |
0d969553 | 115 | // first circular section |
7fd59977 | 116 | IType = 1; |
117 | pos1 = AdC1.Circle().Location(); | |
118 | dist1 = AdC1.Circle().Radius(); | |
119 | axe1 = AdC1.Circle().Axis(); | |
120 | } | |
121 | else if (AdC1.GetType() == GeomAbs_Line) { | |
0d969553 | 122 | // first straight line section |
7fd59977 | 123 | IType = 4; |
124 | pos1 = AdC1.Line().Location(); | |
125 | dist1 = AdC1.Value(first1).Distance(AdC1.Value(last1)); | |
126 | gp_Vec vec(AdC1.Value(first1),AdC1.Value(last1)); | |
127 | gp_Dir dir(vec); | |
128 | axe1 = gp_Ax1(AdC1.Value(first1),dir); | |
129 | } | |
130 | else { | |
0d969553 | 131 | // first section of any type |
7fd59977 | 132 | IType = 0; |
133 | } | |
134 | } | |
135 | ||
136 | if (IType!=0) { | |
137 | ||
138 | Standard_Boolean degen2 = BRep_Tool::Degenerated(Edge2); | |
139 | if (degen2) { | |
140 | TopExp::Vertices(Edge2,V1,V2); | |
141 | pos = BRep_Tool::Pnt(V1); | |
142 | if (IType==1) { | |
0d969553 | 143 | // the only particular case with degenerated edge at end : the cone |
7fd59977 | 144 | if (pos.IsEqual(pos1,Precision::Confusion())) { |
0d969553 | 145 | // the top is mixed with the center of the circle |
7fd59977 | 146 | IType = 0; |
147 | } | |
148 | else { | |
149 | gp_Vec vec(pos1,pos); | |
150 | gp_Dir dir(vec); | |
151 | axe = gp_Ax1(pos1,dir); | |
152 | if (axe.IsParallel(axe1,Precision::Angular())) { | |
0d969553 | 153 | // the top is on the axis of the circle |
7fd59977 | 154 | IType = 2; |
155 | } | |
156 | else { | |
0d969553 | 157 | // incorrect top --> no particular case |
7fd59977 | 158 | IType = 0; |
159 | } | |
160 | } | |
161 | } | |
0d969553 Y |
162 | else if (IType != 4) { //not a plane |
163 | // no particular case | |
7fd59977 | 164 | IType = 0; |
165 | } | |
166 | } | |
167 | else { | |
168 | curv = BRep_Tool::Curve(Edge2, loc, first2, last2); | |
169 | curv = | |
170 | Handle(Geom_Curve)::DownCast(curv->Transformed(loc.Transformation())); | |
171 | ff = first2; | |
172 | ll = last2; | |
173 | if (Edge2.Orientation() == TopAbs_REVERSED) { | |
174 | curv->Reverse(); | |
175 | first2 = curv->ReversedParameter(ll); | |
176 | last2 = curv->ReversedParameter(ff); | |
177 | } | |
178 | GeomAdaptor_Curve AdC(curv); | |
179 | ||
180 | if (IType>0 && IType<4) { | |
181 | if (AdC.GetType() != GeomAbs_Circle) { | |
0d969553 | 182 | // section not circular --> no particular case |
7fd59977 | 183 | IType = 0; |
184 | } | |
185 | else { | |
186 | if (AdC.Circle().Axis() | |
187 | .IsCoaxial(axe1,Precision::Angular(),Precision::Confusion())) { | |
0d969553 | 188 | // same axis |
7fd59977 | 189 | if (Abs(AdC.Circle().Radius()-dist1)< Precision::Confusion()) { |
0d969553 | 190 | // possibility of cylinder or a piece of cylinder |
7fd59977 | 191 | Standard_Real h1 = Abs(last1-first1), h2 = Abs(last2-first2); |
192 | Standard_Boolean Same, | |
193 | SameParametricLength = ( Abs(h1-h2) < Precision::PConfusion() ); | |
194 | Standard_Real m1=(first1+last1)/2., m2=(first2+last2)/2.; | |
195 | gp_Pnt P1,P2; | |
196 | gp_Vec DU; | |
197 | AdC1.D1(m1,P1,DU); | |
198 | AdC.D0(m2,P2); | |
199 | Same = SameParametricLength | |
200 | && ( gp_Vec(P1,P2).IsNormal(DU,Precision::Angular()) ) ; | |
201 | if (Same) { | |
0d969553 | 202 | // cylinder or piece of cylinder |
7fd59977 | 203 | IType = 1; |
204 | } | |
205 | else { | |
0d969553 | 206 | // the interval of definition is not correct |
7fd59977 | 207 | IType = 0; |
208 | } | |
209 | } | |
210 | else { | |
0d969553 | 211 | // possibility of cone truncation |
7fd59977 | 212 | Standard_Real h1 = Abs(last1-first1), h2 = Abs(last2-first2); |
213 | Standard_Boolean Same, | |
214 | SameParametricLength = ( Abs(h1-h2) < Precision::PConfusion() ); | |
215 | Standard_Real m1=(first1+last1)/2., m2=(first2+last2)/2.; | |
216 | gp_Pnt P1,P2; | |
217 | gp_Vec DU; | |
218 | AdC1.D1(m1,P1,DU); | |
219 | AdC.D0(m2,P2); | |
220 | Same = SameParametricLength | |
221 | && ( gp_Vec(P1,P2).IsNormal(DU,Precision::Angular()) ) ; | |
222 | if (Same) { | |
0d969553 | 223 | // truncation of cone |
7fd59977 | 224 | IType = 2; |
225 | } | |
226 | else { | |
0d969553 | 227 | // the interval of definition is not correct |
7fd59977 | 228 | IType = 0; |
229 | } | |
230 | } | |
231 | if (AdC.Circle().Location().IsEqual(pos1,Precision::Confusion())) { | |
0d969553 | 232 | // the centers are mixed |
7fd59977 | 233 | IType = 0; |
234 | } | |
235 | } | |
236 | else { | |
0d969553 | 237 | // different axis |
7fd59977 | 238 | if (AdC.Circle().Radius()==dist1) { |
0d969553 | 239 | // torus ? |
7fd59977 | 240 | IType = 3; |
241 | } | |
242 | else { | |
0d969553 | 243 | // different radius --> no particular case |
7fd59977 | 244 | IType = 0; |
245 | } | |
246 | } | |
247 | } | |
248 | } | |
249 | else if (IType>=4) { | |
250 | if (AdC.GetType() != GeomAbs_Line) { | |
0d969553 | 251 | // not a straight line section --> no particular case |
7fd59977 | 252 | IType = 0; |
253 | } | |
254 | else { | |
255 | pos = AdC.Line().Location(); | |
256 | dist = AdC.Value(first2).Distance(AdC.Value(last2)); | |
257 | gp_Vec vec(AdC.Value(first2),AdC.Value(last2)); | |
258 | gp_Dir dir(vec); | |
259 | axe = gp_Ax1(AdC.Value(first2),dir); | |
260 | if (axe.IsParallel(axe1,Precision::Angular())) { | |
0d969553 | 261 | // parallel straight line |
7fd59977 | 262 | if (Abs(dist-dist1)<Precision::Confusion()) { |
263 | gp_Dir dir(gp_Vec(AdC1.Value(first1),AdC.Value(first2))); | |
264 | if (dir.IsNormal(gp_Dir(vec),Precision::Angular())) { | |
0d969553 | 265 | // plane |
7fd59977 | 266 | IType = 4; |
267 | } | |
268 | else { | |
269 | // extrusion ? | |
270 | IType = 5; | |
271 | } | |
272 | } | |
273 | else { | |
0d969553 | 274 | // different length --> no particular case |
7fd59977 | 275 | IType = 0; |
276 | } | |
277 | } | |
278 | else { | |
0d969553 | 279 | // not parallel straight line --> no particular case |
7fd59977 | 280 | IType = 0; |
281 | } | |
282 | } | |
283 | } | |
284 | else if (IType==-2) { | |
285 | if (AdC.GetType() == GeomAbs_Line) | |
286 | IType = 4; //plane | |
287 | else if (AdC.GetType() == GeomAbs_Circle) | |
288 | { | |
0d969553 | 289 | // the only particular case with degenerated edge at the beginning the cone |
7fd59977 | 290 | pos = AdC.Circle().Location(); |
291 | axe = AdC.Circle().Axis(); | |
292 | if (pos1.IsEqual(pos,Precision::Confusion())) { | |
0d969553 | 293 | // the top is mixed with the center of the circle |
7fd59977 | 294 | IType = 0; |
295 | } | |
296 | else { | |
297 | gp_Vec vec(pos1,pos); | |
298 | gp_Dir dir(vec); | |
299 | axe1 = gp_Ax1(pos1,dir); | |
300 | if (axe.IsParallel(axe1,Precision::Angular())) { | |
0d969553 | 301 | // the top is on the axis of the circle |
7fd59977 | 302 | IType = -2; |
303 | } | |
304 | else { | |
0d969553 | 305 | // incorrect top --> no particular case |
7fd59977 | 306 | IType = 0; |
307 | } | |
308 | } | |
309 | } | |
310 | else | |
311 | IType = 0; | |
312 | } | |
313 | } | |
314 | ||
315 | } | |
0d969553 | 316 | // torus and extrusion are not particular cases. |
7fd59977 | 317 | if (IType == 3 || IType == 5) IType = 0; |
318 | return IType; | |
319 | } | |
320 | ||
321 | ||
322 | //======================================================================= | |
323 | //function : CreateKPart | |
324 | //purpose : | |
325 | //======================================================================= | |
326 | ||
327 | void CreateKPart(const TopoDS_Edge& Edge1,const TopoDS_Edge& Edge2, | |
328 | const Standard_Integer IType, | |
329 | Handle(Geom_Surface)& Surf) | |
330 | { | |
331 | // find the dimension | |
332 | TopoDS_Vertex V1, V2; | |
333 | ||
334 | TopLoc_Location loc; | |
335 | Standard_Real a1, b1, aa =0., bb =0.; | |
336 | TopoDS_Vertex v1f,v1l,v2f,v2l; | |
337 | ||
338 | // find characteristics of the first edge | |
339 | Handle(Geom_Curve) C1; | |
340 | Standard_Boolean degen1 = BRep_Tool::Degenerated(Edge1); | |
341 | if(degen1) { | |
0d969553 | 342 | // cone with degenerated edge at the top |
7fd59977 | 343 | TopExp::Vertices(Edge1,v1f,v1l); |
344 | } | |
345 | else { | |
346 | C1 = BRep_Tool::Curve(Edge1, loc, a1, b1); | |
347 | C1 = Handle(Geom_Curve)::DownCast(C1->Transformed(loc.Transformation())); | |
348 | aa = a1; | |
349 | bb = b1; | |
350 | if (Edge1.Orientation() == TopAbs_REVERSED) { | |
351 | C1->Reverse(); | |
352 | aa = C1->ReversedParameter(b1); | |
353 | bb = C1->ReversedParameter(a1); | |
354 | TopExp::Vertices(Edge1,v1l,v1f); | |
355 | } | |
356 | else { | |
357 | TopExp::Vertices(Edge1,v1f,v1l); | |
358 | } | |
359 | } | |
360 | ||
361 | // find characteristics of the second edge | |
362 | Handle(Geom_Curve) C2; | |
363 | Standard_Boolean degen2 = BRep_Tool::Degenerated(Edge2); | |
364 | if(degen2) { | |
0d969553 | 365 | // cone with degenerated edge at the top |
7fd59977 | 366 | TopExp::Vertices(Edge2,v2f,v2l); |
367 | } | |
368 | else { | |
369 | C2 = BRep_Tool::Curve(Edge2, loc, a1, b1); | |
370 | C2 = Handle(Geom_Curve)::DownCast(C2->Transformed(loc.Transformation())); | |
371 | if (Edge2.Orientation() == TopAbs_REVERSED) { | |
372 | C2->Reverse(); | |
373 | if (degen1) { | |
374 | aa = a1; | |
375 | bb = b1; | |
376 | } | |
377 | TopExp::Vertices(Edge2,v2l,v2f); | |
378 | } | |
379 | else { | |
380 | if (degen1) { | |
381 | aa = a1; //C2->ReversedParameter(b1); | |
382 | bb = b1; //C2->ReversedParameter(a1); | |
383 | } | |
384 | TopExp::Vertices(Edge2,v2f,v2l); | |
385 | } | |
386 | } | |
387 | ||
388 | // create the new surface | |
389 | TopoDS_Shell shell; | |
390 | TopoDS_Face face; | |
391 | TopoDS_Wire W; | |
392 | TopoDS_Edge edge1, edge2, edge3, edge4, couture; | |
393 | ||
394 | BRep_Builder B; | |
395 | B.MakeShell(shell); | |
396 | ||
397 | TopoDS_Wire newW1, newW2; | |
398 | BRep_Builder BW1, BW2; | |
399 | BW1.MakeWire(newW1); | |
400 | BW2.MakeWire(newW2); | |
401 | ||
402 | ||
403 | // calculate the surface | |
404 | Handle(Geom_Surface) surface; | |
405 | Standard_Real V, Rad; | |
406 | if (IType==1) { | |
0d969553 | 407 | // cylindrical surface |
7fd59977 | 408 | gp_Circ c1 = (Handle(Geom_Circle)::DownCast(C1))->Circ(); |
409 | gp_Circ c2 = (Handle(Geom_Circle)::DownCast(C2))->Circ(); | |
410 | gp_Ax3 Ac1 = c1.Position(); | |
411 | V = gp_Vec( c1.Location(),c2.Location()).Dot(gp_Vec(Ac1.Direction())); | |
412 | if ( V < 0.) { | |
413 | Ac1.ZReverse(); | |
414 | V = -V; | |
415 | } | |
416 | Handle(Geom_CylindricalSurface) Cyl = | |
417 | new Geom_CylindricalSurface( Ac1, c1.Radius()); | |
418 | surface = new Geom_RectangularTrimmedSurface | |
419 | ( Cyl, aa, bb, Min(0.,V), Max(0.,V) ); | |
420 | } | |
421 | else if (IType==2) { | |
0d969553 | 422 | // conical surface |
7fd59977 | 423 | gp_Circ k1 = (Handle(Geom_Circle)::DownCast(C1))->Circ(); |
424 | gp_Ax3 Ak1 = k1.Position(); | |
425 | if (degen2) { | |
426 | V = gp_Vec( k1.Location(),BRep_Tool::Pnt(v2f)) | |
427 | .Dot(gp_Vec(Ak1.Direction())); | |
428 | Rad = - k1.Radius(); | |
429 | } | |
430 | else { | |
431 | gp_Circ k2 = (Handle(Geom_Circle)::DownCast(C2))->Circ(); | |
432 | V = gp_Vec( k1.Location(),k2.Location()).Dot(gp_Vec(Ak1.Direction())); | |
433 | Rad = k2.Radius() - k1.Radius(); | |
434 | } | |
435 | ||
436 | if ( V < 0.) { | |
437 | Ak1.ZReverse(); | |
438 | V = -V; | |
439 | } | |
440 | Standard_Real Ang = ATan( Rad / V); | |
441 | Handle(Geom_ConicalSurface) Cone = | |
442 | new Geom_ConicalSurface( Ak1, Ang, k1.Radius()); | |
443 | V /= Cos(Ang); | |
444 | surface = new Geom_RectangularTrimmedSurface | |
445 | ( Cone, aa, bb, Min(0.,V), Max(0.,V) ); | |
446 | } | |
447 | else if (IType==-2) { | |
0d969553 | 448 | // conical surface with the top at the beginning (degen1 is true) |
7fd59977 | 449 | gp_Circ k2 = (Handle(Geom_Circle)::DownCast(C2))->Circ(); |
450 | gp_Ax3 Ak2 = k2.Position(); | |
451 | Ak2.SetLocation(BRep_Tool::Pnt(v1f)); | |
452 | V = gp_Vec(BRep_Tool::Pnt(v1f),k2.Location()) | |
453 | .Dot(gp_Vec(Ak2.Direction())); | |
454 | Rad = k2.Radius(); // - k2.Radius(); | |
455 | if ( V < 0.) { | |
456 | Ak2.ZReverse(); | |
457 | V = -V; | |
458 | } | |
459 | Standard_Real Ang = ATan( Rad / V); | |
460 | Handle(Geom_ConicalSurface) Cone = | |
461 | new Geom_ConicalSurface( Ak2, Ang, 0.); | |
462 | V /= Cos(Ang); | |
463 | surface = new Geom_RectangularTrimmedSurface | |
464 | ( Cone, aa, bb, Min(0.,V), Max(0.,V) ); | |
465 | } | |
466 | else if (IType==3) { | |
0d969553 | 467 | // torus surface ? |
7fd59977 | 468 | } |
469 | else if (IType==4) { | |
470 | // surface plane | |
471 | gp_Lin L1, L2, aLine; | |
472 | if (!degen1) | |
473 | { | |
474 | L1 = (Handle(Geom_Line)::DownCast(C1))->Lin(); | |
475 | aLine = L1; | |
476 | } | |
477 | if (!degen2) | |
478 | { | |
479 | L2 = (Handle(Geom_Line)::DownCast(C2))->Lin(); | |
480 | aLine = L2; | |
481 | } | |
482 | ||
483 | gp_Pnt P1 = (degen1)? BRep_Tool::Pnt(v1f) : L1.Location(); | |
484 | gp_Pnt P2 = (degen2)? BRep_Tool::Pnt(v2f) : L2.Location(); | |
485 | ||
486 | gp_Vec P1P2( P1, P2 ); | |
487 | gp_Dir D1 = aLine.Direction(); | |
488 | gp_Ax3 Ax( aLine.Location(), gp_Dir(D1.Crossed(P1P2)), D1 ); | |
489 | Handle(Geom_Plane) Plan = new Geom_Plane(Ax); | |
490 | V = P1P2.Dot( Ax.YDirection()); | |
491 | surface = Plan; | |
492 | //surface = new Geom_RectangularTrimmedSurface | |
493 | //( Plan, aa, bb, Min(0.,V), Max(0.,V) ); | |
494 | } | |
495 | else if (IType==5) { | |
0d969553 | 496 | // surface of extrusion ? |
7fd59977 | 497 | } |
498 | else { | |
499 | // IType incorrect | |
500 | } | |
501 | Surf = surface; | |
502 | } | |
503 | ||
504 | ||
505 | //======================================================================= | |
506 | //function : BRepFill_Generator | |
507 | //purpose : | |
508 | //======================================================================= | |
509 | ||
510 | BRepFill_Generator::BRepFill_Generator() | |
511 | { | |
512 | } | |
513 | ||
514 | ||
515 | //======================================================================= | |
516 | //function : AddWire | |
517 | //purpose : | |
518 | //======================================================================= | |
519 | ||
520 | void BRepFill_Generator::AddWire(const TopoDS_Wire& Wire) | |
521 | { | |
522 | myWires.Append( Wire); | |
523 | } | |
524 | ||
525 | ||
526 | //======================================================================= | |
527 | //function : Perform | |
528 | //purpose : | |
529 | //======================================================================= | |
530 | ||
531 | void BRepFill_Generator::Perform() | |
532 | { | |
533 | TopoDS_Shell Shell; | |
534 | TopoDS_Face Face; | |
535 | TopoDS_Shape S1, S2; | |
536 | TopoDS_Edge Edge1, Edge2, Edge3, Edge4, Couture; | |
537 | ||
538 | BRep_Builder B; | |
539 | B.MakeShell(myShell); | |
540 | ||
541 | Standard_Integer Nb = myWires.Length(); | |
542 | ||
543 | BRepTools_WireExplorer ex1,ex2; | |
544 | ||
545 | Standard_Boolean wPoint1, wPoint2, uClosed, DegenFirst, DegenLast; | |
546 | ||
547 | for ( Standard_Integer i = 1; i <= Nb-1; i++) { | |
548 | ||
549 | TopoDS_Wire Wire1 = TopoDS::Wire(myWires( i )); | |
550 | TopoDS_Wire Wire2 = TopoDS::Wire(myWires(i+1)); | |
551 | ||
552 | wPoint1 = Standard_False; | |
553 | if (i==1) { | |
554 | wPoint1 = Standard_True; | |
555 | for(ex1.Init(Wire1); ex1.More(); ex1.Next()) { | |
556 | wPoint1 = wPoint1 && (BRep_Tool::Degenerated(ex1.Current())); | |
557 | } | |
558 | DegenFirst = wPoint1; | |
559 | ||
560 | TopoDS_Vertex V1, V2; | |
561 | TopExp::Vertices(Wire1, V1, V2); | |
562 | uClosed = V1.IsSame(V2); | |
563 | } | |
564 | ||
565 | wPoint2 = Standard_False; | |
566 | if (i==Nb-1) { | |
567 | wPoint2 = Standard_True; | |
568 | for(ex2.Init(Wire2); ex2.More(); ex2.Next()) { | |
569 | wPoint2 = wPoint2 && (BRep_Tool::Degenerated(ex2.Current())); | |
570 | } | |
571 | DegenLast = wPoint2; | |
572 | } | |
573 | ||
574 | ex1.Init(Wire1); | |
575 | ex2.Init(Wire2); | |
576 | ||
577 | TopTools_DataMapOfShapeShape Map; | |
578 | ||
579 | Standard_Boolean tantque = ex1.More() && ex2.More(); | |
580 | ||
581 | while ( tantque ) { | |
582 | ||
583 | TopoDS_Vertex V1f,V1l,V2f,V2l, Vf_toMap, Vl_toMap; | |
584 | ||
585 | Standard_Boolean degen1 | |
586 | = BRep_Tool::Degenerated(TopoDS::Edge(ex1.Current())); | |
587 | Standard_Boolean degen2 | |
588 | = BRep_Tool::Degenerated(TopoDS::Edge(ex2.Current())); | |
589 | ||
590 | if ( degen1 ) { | |
591 | TopoDS_Shape aLocalShape = ex1.Current().EmptyCopied(); | |
592 | Edge1 = TopoDS::Edge(aLocalShape); | |
593 | // Edge1 = TopoDS::Edge(ex1.Current().EmptyCopied()); | |
594 | // aLocalShape = ex1.Current(); | |
595 | // TopExp::Vertices(TopoDS::Edge(aLocalShape),V1f,V1l); | |
596 | TopExp::Vertices(TopoDS::Edge(ex1.Current()),V1f,V1l); | |
597 | V1f.Orientation(TopAbs_FORWARD); | |
598 | B.Add(Edge1,V1f); | |
599 | V1l.Orientation(TopAbs_REVERSED); | |
600 | B.Add(Edge1,V1l); | |
601 | B.Range(Edge1,0,1); | |
602 | } | |
603 | else { | |
604 | TopoDS_Shape aLocalShape = ex1.Current(); | |
605 | Edge1 = TopoDS::Edge(aLocalShape); | |
606 | // Edge1 = TopoDS::Edge(ex1.Current()); | |
607 | } | |
608 | ||
609 | if ( degen2 ) { | |
610 | TopoDS_Shape aLocalShape = ex2.Current().EmptyCopied(); | |
611 | Edge2 = TopoDS::Edge(aLocalShape); | |
612 | // Edge2 = TopoDS::Edge(ex2.Current().EmptyCopied()); | |
613 | TopExp::Vertices(TopoDS::Edge(ex2.Current()),V2f,V2l); | |
614 | V2f.Orientation(TopAbs_FORWARD); | |
615 | B.Add(Edge2,V2f); | |
616 | V2l.Orientation(TopAbs_REVERSED); | |
617 | B.Add(Edge2,V2l); | |
618 | B.Range(Edge2,0,1); | |
619 | } | |
620 | else { | |
621 | Edge2 = TopoDS::Edge(ex2.Current()); | |
622 | } | |
623 | ||
624 | Standard_Boolean Periodic | |
625 | = (Edge1.Closed() || degen1) && (Edge2.Closed() || degen2); | |
0d969553 Y |
626 | // ATTENTION : a non-punctual wire should not |
627 | // contain a punctual edge | |
7fd59977 | 628 | if (!wPoint1) ex1.Next(); |
629 | if (!wPoint2) ex2.Next(); | |
630 | ||
0d969553 | 631 | // initialization of vertices |
7fd59977 | 632 | Handle(Geom_Surface) Surf; |
633 | Standard_Real f1=0, l1=1, f2=0, l2=1; | |
634 | if (Edge1.Orientation() == TopAbs_REVERSED) | |
635 | TopExp::Vertices(Edge1,V1l,V1f); | |
636 | else | |
637 | TopExp::Vertices(Edge1,V1f,V1l); | |
638 | if (Edge2.Orientation() == TopAbs_REVERSED) | |
639 | TopExp::Vertices(Edge2,V2l,V2f); | |
640 | else | |
641 | TopExp::Vertices(Edge2,V2f,V2l); | |
642 | if (degen1) | |
643 | { | |
644 | Vf_toMap = V2f; | |
645 | Vl_toMap = V2l; | |
646 | } | |
647 | else | |
648 | { | |
649 | Vf_toMap = V1f; | |
650 | Vl_toMap = V1l; | |
651 | } | |
652 | ||
653 | if(Periodic) { | |
654 | Standard_Boolean E1IsReallyClosed = BRepTools::Compare(V1f,V1l); | |
655 | Standard_Boolean E2IsReallyClosed = BRepTools::Compare(V2f,V2l); | |
656 | Periodic | |
657 | = (E1IsReallyClosed || degen1) && (E2IsReallyClosed || degen2); | |
658 | } | |
0d969553 | 659 | // processing of KPart |
7fd59977 | 660 | Standard_Integer IType = DetectKPart(Edge1,Edge2); |
661 | if (IType==0) { | |
0d969553 | 662 | // no part cases |
7fd59977 | 663 | TopLoc_Location L,L1,L2; |
664 | ||
665 | Handle(Geom_Curve) C1, C2; | |
666 | TColgp_Array1OfPnt Extremities(1,2); | |
667 | ||
668 | if (degen1) { | |
669 | Extremities(1) = BRep_Tool::Pnt(V1f); | |
670 | Extremities(2) = BRep_Tool::Pnt(V1l); | |
671 | C1 = new Geom_BezierCurve(Extremities); | |
672 | } | |
673 | else { | |
674 | C1 = BRep_Tool::Curve(Edge1,L1,f1,l1); | |
675 | } | |
676 | if (degen2) { | |
677 | Extremities(1) = BRep_Tool::Pnt(V2l); | |
678 | Extremities(2) = BRep_Tool::Pnt(V2f); | |
679 | C2 = new Geom_BezierCurve(Extremities); | |
680 | } | |
681 | else { | |
682 | C2 = BRep_Tool::Curve(Edge2,L2,f2,l2); | |
683 | } | |
684 | ||
685 | // compute the location | |
686 | Standard_Boolean SameLoc = Standard_False; | |
687 | ||
688 | // transform and trim the curves | |
689 | ||
690 | if (Abs(f1 - C1->FirstParameter()) > Precision::PConfusion() || | |
691 | Abs(l1 - C1->LastParameter()) > Precision::PConfusion() ) { | |
692 | C1 = new Geom_TrimmedCurve(C1,f1,l1); | |
693 | } | |
694 | else { | |
695 | C1 = Handle(Geom_Curve)::DownCast(C1->Copy()); | |
696 | } | |
697 | if (!SameLoc) C1->Transform(L1.Transformation()); | |
698 | if (Edge1.Orientation() == TopAbs_REVERSED) { | |
699 | C1->Reverse(); | |
700 | } | |
701 | ||
702 | if (Abs(f2 - C2->FirstParameter()) > Precision::PConfusion() || | |
703 | Abs(l2 - C2->LastParameter()) > Precision::PConfusion() ) { | |
704 | C2 = new Geom_TrimmedCurve(C2,f2,l2); | |
705 | } | |
706 | else { | |
707 | C2 = Handle(Geom_Curve)::DownCast(C2->Copy()); | |
708 | } | |
709 | if (!SameLoc) C2->Transform(L2.Transformation()); | |
710 | if (Edge2.Orientation() == TopAbs_REVERSED) { | |
711 | C2->Reverse(); | |
712 | } | |
713 | ||
714 | GeomFill_Generator Generator; | |
715 | Generator.AddCurve( C1); | |
716 | Generator.AddCurve( C2); | |
717 | Generator.Perform( Precision::PConfusion()); | |
718 | ||
719 | Surf = Generator.Surface(); | |
720 | B.MakeFace(Face,Surf,Precision::Confusion()); | |
721 | } | |
722 | else { | |
0d969553 | 723 | // particular case |
7fd59977 | 724 | CreateKPart(Edge1,Edge2,IType,Surf); |
725 | B.MakeFace(Face,Surf,Precision::Confusion()); | |
726 | } | |
727 | ||
728 | // make the missing edges | |
729 | Standard_Real first,last; | |
730 | Surf->Bounds(f1,l1,f2,l2); | |
731 | ||
732 | if ( Map.IsBound(Vf_toMap)) { | |
733 | TopoDS_Shape aLocalShape = Map(Vf_toMap).Reversed(); | |
734 | Edge3 = TopoDS::Edge(aLocalShape); | |
735 | // Edge3 = TopoDS::Edge(Map(V1f).Reversed()); | |
736 | } | |
737 | else { | |
738 | Handle(Geom_Curve) CC; | |
739 | TColgp_Array1OfPnt Extremities(1,2); | |
740 | if (IType==0) { | |
0d969553 | 741 | // general case : Edge3 corresponds to iso U=f1 |
7fd59977 | 742 | CC = Surf->UIso(f1); |
743 | first=f2; | |
744 | last=l2; | |
745 | } | |
746 | else { | |
0d969553 | 747 | // particular case : it is required to calculate the curve 3d |
7fd59977 | 748 | Extremities(1) = BRep_Tool::Pnt(V1f); |
749 | Extremities(2) = BRep_Tool::Pnt(V2f); | |
750 | CC = new Geom_BezierCurve(Extremities); | |
751 | first=0.; | |
752 | last=1.; | |
753 | } | |
754 | B.MakeEdge(Edge3,CC,Precision::Confusion()); | |
755 | V1f.Orientation(TopAbs_FORWARD); | |
756 | B.Add(Edge3,V1f); | |
757 | V2f.Orientation(TopAbs_REVERSED); | |
758 | B.Add(Edge3,V2f); | |
759 | B.Range(Edge3,first,last); | |
760 | Edge3.Reverse(); | |
761 | Map.Bind(Vf_toMap, Edge3); | |
762 | } | |
763 | ||
764 | Standard_Boolean CommonEdge = Standard_False; | |
765 | if ( Map.IsBound(Vl_toMap) ) { | |
766 | TopoDS_Shape aLocalShape = Map(Vl_toMap).Reversed(); | |
767 | const TopoDS_Edge CommonE = TopoDS::Edge(aLocalShape); | |
768 | // const TopoDS_Edge CommonE = TopoDS::Edge(Map(V1l).Reversed()); | |
769 | TopoDS_Vertex V1, V2; | |
770 | TopExp::Vertices(CommonE,V1,V2); | |
771 | CommonEdge = V1.IsSame(V1l) && V2.IsSame(V2l); | |
772 | } | |
773 | if ( CommonEdge ) { | |
774 | TopoDS_Shape aLocalShape = Map(Vl_toMap).Reversed(); | |
775 | Edge4 = TopoDS::Edge(aLocalShape); | |
776 | // Edge4 = TopoDS::Edge(Map(V1l).Reversed()); | |
777 | } | |
778 | else { | |
779 | Handle(Geom_Curve) CC; | |
780 | TColgp_Array1OfPnt Extremities(1,2); | |
781 | if (IType==0) { | |
0d969553 | 782 | // general case : Edge4 corresponds to iso U=l1 |
7fd59977 | 783 | CC = Surf->UIso(l1); |
784 | first=f2; | |
785 | last=l2; | |
786 | } | |
787 | else { | |
0d969553 | 788 | // particular case : it is required to calculate the curve 3d |
7fd59977 | 789 | Extremities(1) = BRep_Tool::Pnt(V1l); |
790 | Extremities(2) = BRep_Tool::Pnt(V2l); | |
791 | CC = new Geom_BezierCurve(Extremities); | |
792 | first=0.; | |
793 | last=1.; | |
794 | } | |
795 | B.MakeEdge(Edge4,CC,Precision::Confusion()); | |
796 | V1l.Orientation(TopAbs_FORWARD); | |
797 | B.Add(Edge4,V1l); | |
798 | V2l.Orientation(TopAbs_REVERSED); | |
799 | B.Add(Edge4,V2l); | |
800 | B.Range(Edge4,first,last); | |
801 | Map.Bind(Vl_toMap, Edge4); | |
802 | } | |
803 | ||
804 | // make the wire | |
805 | ||
806 | TopoDS_Wire W; | |
807 | B.MakeWire(W); | |
808 | ||
809 | if (! (degen1 && IType == 4)) | |
810 | B.Add(W,Edge1); | |
811 | B.Add(W,Edge4); | |
812 | if (! (degen2 && IType == 4)) | |
813 | B.Add(W,Edge2.Reversed()); | |
814 | B.Add(W,Edge3); | |
815 | ||
816 | B.Add(Face,W); | |
817 | ||
818 | B.Add(myShell,Face); | |
819 | ||
820 | // complete myMap for edge1 | |
821 | if (! (degen1 && IType == 4)) | |
822 | { | |
823 | TopTools_ListOfShape Empty; | |
824 | if (!myMap.IsBound(Edge1)) myMap.Bind(Edge1,Empty); | |
825 | myMap(Edge1).Append(Face); | |
826 | } | |
827 | ||
828 | // set the pcurves | |
829 | ||
830 | Standard_Real T = Precision::Confusion(); | |
831 | ||
832 | if (IType != 4) //not plane | |
833 | { | |
834 | if ( Edge1.Orientation() == TopAbs_REVERSED ) { | |
835 | B.UpdateEdge(Edge1, | |
836 | new Geom2d_Line(gp_Pnt2d(0,f2),gp_Dir2d(-1,0)), | |
837 | Face,T); | |
838 | B.Range(Edge1,Face,-l1,-f1); | |
839 | } | |
840 | else { | |
841 | B.UpdateEdge(Edge1, | |
842 | new Geom2d_Line(gp_Pnt2d(0,f2),gp_Dir2d(1,0)), | |
843 | Face,T); | |
844 | B.Range(Edge1,Face,f1,l1); | |
845 | } | |
846 | ||
847 | if ( Edge2.Orientation() == TopAbs_REVERSED ) { | |
848 | B.UpdateEdge(Edge2, | |
849 | new Geom2d_Line(gp_Pnt2d(0,l2),gp_Dir2d(-1,0)), | |
850 | Face,T); | |
851 | B.Range(Edge2,Face,-l1,-f1); | |
852 | } | |
853 | else { | |
854 | B.UpdateEdge(Edge2, | |
855 | new Geom2d_Line(gp_Pnt2d(0,l2),gp_Dir2d(1,0)), | |
856 | Face,T); | |
857 | B.Range(Edge2,Face,f1,l1); | |
858 | } | |
859 | } | |
860 | ||
861 | if (IType==0) { | |
862 | if ( Periodic) { | |
863 | B.UpdateEdge(Edge3, | |
864 | new Geom2d_Line(gp_Pnt2d(l1,0),gp_Dir2d(0,1)), | |
865 | new Geom2d_Line(gp_Pnt2d(f1,0),gp_Dir2d(0,1)), | |
866 | Face,T); | |
867 | } | |
868 | else { | |
869 | B.UpdateEdge(Edge3, | |
870 | new Geom2d_Line(gp_Pnt2d(f1,0),gp_Dir2d(0,1)), | |
871 | Face,T); | |
872 | B.UpdateEdge(Edge4, | |
873 | new Geom2d_Line(gp_Pnt2d(l1,0),gp_Dir2d(0,1)), | |
874 | Face,T); | |
875 | } | |
876 | } | |
877 | else { | |
878 | // KPart | |
879 | if ( Periodic) { | |
880 | TColgp_Array1OfPnt2d Extrem1(1,2); | |
881 | Extrem1(1).SetCoord(l1,f2); | |
882 | Extrem1(2).SetCoord(l1,l2); | |
883 | TColgp_Array1OfPnt2d Extrem2(1,2); | |
884 | Extrem2(1).SetCoord(f1,f2); | |
885 | Extrem2(2).SetCoord(f1,l2); | |
886 | B.UpdateEdge(Edge3, | |
887 | new Geom2d_BezierCurve(Extrem1), | |
888 | new Geom2d_BezierCurve(Extrem2), | |
889 | Face,T); | |
890 | } | |
891 | else if (IType != 4) { //not plane | |
892 | TColgp_Array1OfPnt2d Extrem2(1,2); | |
893 | Extrem2(1).SetCoord(f1,f2); | |
894 | Extrem2(2).SetCoord(f1,l2); | |
895 | B.UpdateEdge(Edge3, | |
896 | new Geom2d_BezierCurve(Extrem2), | |
897 | Face,T); | |
898 | TColgp_Array1OfPnt2d Extrem1(1,2); | |
899 | Extrem1(1).SetCoord(l1,f2); | |
900 | Extrem1(2).SetCoord(l1,l2); | |
901 | B.UpdateEdge(Edge4, | |
902 | new Geom2d_BezierCurve(Extrem1), | |
903 | Face,T); | |
904 | } | |
905 | } | |
906 | // Set the non parameter flag; | |
907 | B.SameParameter(Edge1,Standard_False); | |
908 | B.SameParameter(Edge2,Standard_False); | |
909 | B.SameParameter(Edge3,Standard_False); | |
910 | B.SameParameter(Edge4,Standard_False); | |
911 | B.SameRange(Edge1,Standard_False); | |
912 | B.SameRange(Edge2,Standard_False); | |
913 | B.SameRange(Edge3,Standard_False); | |
914 | B.SameRange(Edge4,Standard_False); | |
915 | ||
916 | tantque = ex1.More() && ex2.More(); | |
917 | if (wPoint1) tantque = ex2.More(); | |
918 | if (wPoint2) tantque = ex1.More(); | |
919 | } | |
920 | } | |
921 | BRepLib::SameParameter(myShell); | |
922 | ||
923 | if (uClosed && DegenFirst && DegenLast) | |
924 | myShell.Closed(Standard_True); | |
925 | } | |
926 | ||
927 | ||
928 | //======================================================================= | |
929 | //function : GeneratedShapes | |
930 | //purpose : | |
931 | //======================================================================= | |
932 | ||
933 | const TopTools_ListOfShape& | |
934 | BRepFill_Generator::GeneratedShapes (const TopoDS_Shape& SSection) const | |
935 | { | |
936 | if (myMap.IsBound(SSection)) { | |
937 | return myMap(SSection); | |
938 | } | |
939 | else { | |
940 | static TopTools_ListOfShape Empty; | |
941 | return Empty; | |
942 | } | |
943 | } | |
944 | ||
945 | //======================================================================= | |
946 | //function : Generated | |
947 | //purpose : | |
948 | //=================================================================== ==== | |
949 | ||
950 | const TopTools_DataMapOfShapeListOfShape& BRepFill_Generator::Generated() const | |
951 | { | |
952 | return myMap; | |
953 | } | |
954 | ||
955 |