Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1994-06-07 |
2 | // Created by: Bruno DUMORTIER | |
3 | // Copyright (c) 1994-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 | |
17 | #include <BRepFill_Pipe.ixx> | |
18 | ||
19 | #include <Standard_ErrorHandler.hxx> | |
20 | ||
21 | #include <BRep_Tool.hxx> | |
22 | #include <BRep_Builder.hxx> | |
23 | #include <BRepClass3d_SolidClassifier.hxx> | |
24 | #include <BRepLib_MakeVertex.hxx> | |
46e68e02 | 25 | #include <BRepTools_Substitution.hxx> |
7fd59977 | 26 | |
27 | #include <GeomFill_CorrectedFrenet.hxx> | |
a31abc03 | 28 | #include <GeomFill_Frenet.hxx> |
29 | #include <GeomFill_DiscreteTrihedron.hxx> | |
7fd59977 | 30 | #include <GeomFill_CurveAndTrihedron.hxx> |
31 | ||
32 | #include <BRepFill_SectionPlacement.hxx> | |
33 | #include <BRepFill_ShapeLaw.hxx> | |
34 | #include <BRepFill_Edge3DLaw.hxx> | |
35 | #include <BRepFill_Sweep.hxx> | |
36 | ||
37 | #include <GeomAbs_Shape.hxx> | |
38 | #include <TopExp.hxx> | |
39 | #include <TopAbs_ShapeEnum.hxx> | |
40 | #include <TopoDS.hxx> | |
41 | #include <TopoDS_Shell.hxx> | |
42 | #include <TopoDS_Solid.hxx> | |
43 | #include <TopoDS_Compound.hxx> | |
44 | #include <TopoDS_Iterator.hxx> | |
46e68e02 | 45 | #include <TopTools_DataMapOfShapeInteger.hxx> |
46 | #include <TColStd_DataMapOfIntegerInteger.hxx> | |
47 | #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx> | |
7fd59977 | 48 | |
49 | #include <Precision.hxx> | |
50 | #include <Standard_NotImplemented.hxx> | |
51 | ||
52 | #include <Geom_TrimmedCurve.hxx> | |
53 | #include <Geom_OffsetCurve.hxx> | |
54 | #include <Geom_BSplineCurve.hxx> | |
c8ea5b8e | 55 | #include <BRepBuilderAPI_Transform.hxx> |
f52d1b53 | 56 | #include <BRepBuilderAPI_Copy.hxx> |
c8ea5b8e | 57 | #include <TopTools_SequenceOfShape.hxx> |
475604b4 | 58 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
c8ea5b8e | 59 | #include <BRepLib.hxx> |
60 | ||
61 | #include <Geom2dAdaptor_HCurve.hxx> | |
62 | #include <GeomAdaptor_HSurface.hxx> | |
63 | #include <Adaptor3d_CurveOnSurface.hxx> | |
7fd59977 | 64 | |
f52d1b53 | 65 | #include <ShapeUpgrade_RemoveLocations.hxx> |
66 | ||
7fd59977 | 67 | #ifdef DRAW |
68 | #include <DBRep.hxx> | |
69 | static Standard_Boolean Affich = 0; | |
70 | #endif | |
71 | ||
f52d1b53 | 72 | static void ReverseModifiedEdges(TopoDS_Shape& aShape, |
73 | TopTools_MapOfShape& Emap) | |
74 | { | |
75 | TopExp_Explorer Explo(aShape, TopAbs_FACE); | |
76 | BRep_Builder BB; | |
475604b4 | 77 | |
f52d1b53 | 78 | for (; Explo.More(); Explo.Next()) |
79 | { | |
80 | TopoDS_Shape aFace = Explo.Current(); | |
81 | TopoDS_Iterator itf(aFace); | |
82 | for (; itf.More(); itf.Next()) | |
83 | { | |
84 | TopoDS_Shape aWire = itf.Value(); | |
475604b4 | 85 | TopTools_ListOfShape Ledges; |
f52d1b53 | 86 | TopoDS_Iterator itw(aWire); |
87 | for (; itw.More(); itw.Next()) | |
475604b4 | 88 | Ledges.Append(itw.Value()); |
89 | ||
f52d1b53 | 90 | aWire.Free(Standard_True); |
475604b4 | 91 | TopTools_ListIteratorOfListOfShape itl(Ledges); |
92 | for (; itl.More(); itl.Next()) | |
93 | BB.Remove(aWire, itl.Value()); | |
94 | ||
95 | for (itl.Initialize(Ledges); itl.More(); itl.Next()) | |
f52d1b53 | 96 | { |
475604b4 | 97 | TopoDS_Shape anEdge = itl.Value(); |
98 | if (Emap.Contains(anEdge)) | |
99 | anEdge.Reverse(); | |
100 | BB.Add(aWire, anEdge); | |
f52d1b53 | 101 | } |
102 | } | |
103 | } | |
104 | } | |
c8ea5b8e | 105 | |
106 | static void UpdateTolFromTopOrBottomPCurve(const TopoDS_Face& aFace, | |
107 | TopoDS_Edge& anEdge) | |
108 | { | |
109 | Standard_Real fpar, lpar; | |
110 | Handle(Geom2d_Curve) aPCurve = BRep_Tool::CurveOnSurface(anEdge, aFace, fpar, lpar); | |
111 | if (aPCurve.IsNull()) | |
112 | return; | |
113 | ||
114 | Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, fpar, lpar); | |
115 | if (aCurve.IsNull()) | |
116 | return; | |
117 | ||
118 | Handle(Geom2dAdaptor_HCurve) GAHC2d = new Geom2dAdaptor_HCurve(aPCurve, fpar, lpar); | |
119 | Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace); | |
120 | Handle(GeomAdaptor_HSurface) GAHS = new GeomAdaptor_HSurface(aSurf); | |
121 | Adaptor3d_CurveOnSurface ConS(GAHC2d, GAHS); | |
122 | ||
123 | Standard_Real Tol = BRep_Tool::Tolerance(anEdge); | |
124 | Standard_Real InitTol = Tol; | |
125 | Standard_Real TolTol = Tol*Tol; | |
126 | const Standard_Integer NCONTROL = 22; | |
127 | Standard_Real delta = (lpar - fpar)/NCONTROL; | |
128 | for (Standard_Integer i = 0; i <= NCONTROL; i++) | |
129 | { | |
130 | Standard_Real par = fpar + i*delta; | |
131 | gp_Pnt pnt = aCurve->Value(par); | |
132 | gp_Pnt prj = ConS.Value(par); | |
133 | Standard_Real sqdist = pnt.SquareDistance(prj); | |
134 | if (sqdist > TolTol) | |
135 | TolTol = sqdist; | |
136 | } | |
137 | Tol = 1.00005 * Sqrt(TolTol); | |
138 | if (Tol >= InitTol) | |
139 | { | |
140 | BRep_Builder BB; | |
141 | BB.UpdateEdge(anEdge, Tol); | |
142 | TopoDS_Iterator itv(anEdge); | |
143 | for (; itv.More(); itv.Next()) | |
144 | { | |
145 | TopoDS_Vertex aVertex = TopoDS::Vertex(itv.Value()); | |
146 | BB.UpdateVertex(aVertex, Tol); | |
147 | } | |
148 | } | |
149 | } | |
150 | ||
7fd59977 | 151 | //======================================================================= |
152 | //function : BRepFill_Pipe | |
153 | //purpose : | |
154 | //======================================================================= | |
155 | ||
156 | BRepFill_Pipe::BRepFill_Pipe() | |
157 | { | |
471ce736 | 158 | myDegmax = 11; |
7fd59977 | 159 | mySegmax = 100; |
471ce736 | 160 | myContinuity = GeomAbs_C2; |
a31abc03 | 161 | myMode = GeomFill_IsCorrectedFrenet; |
162 | myForceApproxC1 = Standard_False; | |
c8ea5b8e | 163 | |
164 | myCurIndexOfSectionEdge = 1; | |
7fd59977 | 165 | } |
166 | ||
167 | ||
168 | //======================================================================= | |
169 | //function : BRepFill_Pipe | |
170 | //purpose : | |
171 | //======================================================================= | |
172 | ||
173 | BRepFill_Pipe::BRepFill_Pipe(const TopoDS_Wire& Spine, | |
174 | const TopoDS_Shape& Profile, | |
471ce736 | 175 | const GeomFill_Trihedron aMode, |
176 | const Standard_Boolean ForceApproxC1, | |
7fd59977 | 177 | const Standard_Boolean KPart) |
471ce736 | 178 | |
7fd59977 | 179 | { |
471ce736 | 180 | myDegmax = 11; |
7fd59977 | 181 | mySegmax = 100; |
471ce736 | 182 | |
a31abc03 | 183 | myMode = GeomFill_IsCorrectedFrenet; |
a31abc03 | 184 | if (aMode == GeomFill_IsFrenet || |
185 | aMode == GeomFill_IsCorrectedFrenet || | |
186 | aMode == GeomFill_IsDiscreteTrihedron) | |
187 | myMode = aMode; | |
a31abc03 | 188 | |
471ce736 | 189 | myContinuity = GeomAbs_C2; |
190 | if (myMode == GeomFill_IsDiscreteTrihedron) | |
191 | myContinuity = GeomAbs_C0; | |
192 | ||
a31abc03 | 193 | myForceApproxC1 = ForceApproxC1; |
c8ea5b8e | 194 | |
195 | myCurIndexOfSectionEdge = 1; | |
196 | ||
471ce736 | 197 | Perform(Spine, Profile, KPart); |
a31abc03 | 198 | } |
7fd59977 | 199 | |
200 | ||
201 | //======================================================================= | |
202 | //function : Perform | |
203 | //purpose : | |
204 | //======================================================================= | |
205 | ||
206 | void BRepFill_Pipe::Perform(const TopoDS_Wire& Spine, | |
207 | const TopoDS_Shape& Profile, | |
35e08fe8 | 208 | const Standard_Boolean /*KPart*/) |
7fd59977 | 209 | |
210 | { | |
211 | mySections.Nullify(); | |
212 | myFaces.Nullify(); | |
213 | myEdges.Nullify(); | |
214 | ||
215 | mySpine = Spine; | |
216 | myProfile = Profile; | |
217 | ||
218 | DefineRealSegmax(); | |
219 | ||
220 | BRepTools_WireExplorer wexp; | |
221 | TopoDS_Shape TheProf; | |
222 | ||
a31abc03 | 223 | Handle(GeomFill_TrihedronLaw) TLaw; |
224 | switch (myMode) | |
225 | { | |
226 | case GeomFill_IsFrenet: | |
227 | TLaw = new GeomFill_Frenet(); | |
228 | break; | |
229 | case GeomFill_IsCorrectedFrenet: | |
230 | TLaw = new GeomFill_CorrectedFrenet(); | |
231 | break; | |
232 | case GeomFill_IsDiscreteTrihedron: | |
233 | TLaw = new GeomFill_DiscreteTrihedron(); | |
234 | break; | |
566f8441 | 235 | default: |
236 | break; | |
a31abc03 | 237 | } |
7fd59977 | 238 | Handle(GeomFill_CurveAndTrihedron) Loc = |
239 | new (GeomFill_CurveAndTrihedron) (TLaw); | |
240 | myLoc = new (BRepFill_Edge3DLaw) (mySpine, Loc); | |
241 | if (myLoc->NbLaw() == 0) { | |
0d969553 | 242 | return; // Degenerated case |
7fd59977 | 243 | } |
0d969553 | 244 | myLoc->TransformInG0Law(); // Set into continuity |
7fd59977 | 245 | |
246 | BRepFill_SectionPlacement Place(myLoc, Profile); | |
247 | myTrsf = Place.Transformation(); | |
248 | ||
249 | TopLoc_Location Loc2(myTrsf), Loc1; | |
250 | Loc1 = Profile.Location(); | |
251 | TopoDS_Shape aux; | |
252 | TheProf = myProfile; | |
253 | TheProf.Location(Loc2.Multiplied(Loc1)); | |
254 | ||
0d969553 | 255 | // Construct First && Last Shape |
7fd59977 | 256 | Handle(GeomFill_LocationLaw) law; |
257 | ||
258 | gp_Mat M; | |
259 | gp_Vec V; | |
260 | gp_Trsf fila; | |
261 | Standard_Real first, last; | |
262 | myLoc->Law(1)->GetDomain(first, last); | |
263 | myLoc->Law(1)->D0(first, M, V); | |
264 | fila.SetValues(M(1,1), M(1,2), M(1,3), V.X(), | |
265 | M(2,1), M(2,2), M(2,3), V.Y(), | |
7a8c6a36 | 266 | M(3,1), M(3,2), M(3,3), V.Z()); |
7fd59977 | 267 | |
268 | fila.Multiply(myTrsf); | |
269 | TopLoc_Location LocFirst(fila); | |
270 | myFirst = myProfile; | |
271 | if ( ! LocFirst.IsIdentity()) { | |
c8ea5b8e | 272 | //myFirst.Location( LocFirst.Multiplied(myProfile.Location()) ); |
273 | myFirst = BRepBuilderAPI_Transform(myProfile, fila, Standard_True); //copy | |
7fd59977 | 274 | } |
275 | ||
f52d1b53 | 276 | ShapeUpgrade_RemoveLocations RemLoc; |
277 | RemLoc.Remove(myFirst); | |
278 | myFirst = RemLoc.GetResult(); | |
279 | TopLoc_Location theLoc = myFirst.Location(); | |
280 | if (!theLoc.IsIdentity()) | |
281 | { | |
282 | TopoDS_Shape NewMyFirst = BRepBuilderAPI_Copy(myFirst); | |
475604b4 | 283 | RemLoc.Remove(NewMyFirst); |
284 | NewMyFirst = RemLoc.GetResult(); | |
f52d1b53 | 285 | TopLoc_Location theIdentity; |
286 | NewMyFirst.Location(theIdentity); | |
475604b4 | 287 | myFirst = BRepBuilderAPI_Transform(NewMyFirst, theLoc.Transformation(), Standard_True); |
f52d1b53 | 288 | } |
289 | ||
7fd59977 | 290 | myLoc->Law(myLoc->NbLaw())->GetDomain(first, last); |
291 | myLoc->Law(myLoc->NbLaw())->D0(last,M, V); | |
0d969553 | 292 | // try { // Not good, but there are no other means to test SetValues |
7fd59977 | 293 | fila.SetValues(M(1,1), M(1,2), M(1,3), V.X(), |
294 | M(2,1), M(2,2), M(2,3), V.Y(), | |
7a8c6a36 | 295 | M(3,1), M(3,2), M(3,3), V.Z()); |
7fd59977 | 296 | fila.Multiply(myTrsf); |
297 | TopLoc_Location LocLast(fila); | |
298 | if (! myLoc->IsClosed() || LocFirst != LocLast) { | |
299 | myLast = myProfile; | |
300 | if ( ! LocLast.IsIdentity()) { | |
c8ea5b8e | 301 | //myLast.Location(LocLast.Multiplied(myProfile.Location()) ); |
302 | myLast = BRepBuilderAPI_Transform(myProfile, fila, Standard_True); //copy | |
7fd59977 | 303 | } |
304 | } | |
305 | else { | |
306 | myLast = myFirst; | |
307 | } | |
f52d1b53 | 308 | |
309 | RemLoc.Remove(myLast); | |
310 | myLast = RemLoc.GetResult(); | |
311 | theLoc = myLast.Location(); | |
312 | if (!theLoc.IsIdentity()) | |
313 | { | |
314 | TopoDS_Shape NewMyLast = BRepBuilderAPI_Copy(myLast); | |
475604b4 | 315 | RemLoc.Remove(NewMyLast); |
316 | NewMyLast = RemLoc.GetResult(); | |
f52d1b53 | 317 | TopLoc_Location theIdentity; |
318 | NewMyLast.Location(theIdentity); | |
475604b4 | 319 | myLast = BRepBuilderAPI_Transform(NewMyLast, theLoc.Transformation(), Standard_True); |
f52d1b53 | 320 | } |
321 | ||
7fd59977 | 322 | #if DRAW |
323 | if (Affich) { | |
324 | DBRep::Set("theprof", TheProf); | |
325 | DBRep::Set("thefirst", myFirst); | |
326 | DBRep::Set("thelast" , myLast); | |
327 | } | |
328 | #endif | |
329 | ||
330 | myShape = MakeShape(TheProf, myFirst, myLast); | |
331 | } | |
332 | ||
333 | ||
334 | //======================================================================= | |
335 | //function : Spine | |
336 | //purpose : | |
337 | //======================================================================= | |
338 | ||
339 | const TopoDS_Shape& BRepFill_Pipe::Spine() const | |
340 | { | |
341 | return mySpine; | |
342 | } | |
343 | ||
344 | //======================================================================= | |
345 | //function : Profile | |
346 | //purpose : | |
347 | //======================================================================= | |
348 | ||
349 | const TopoDS_Shape& BRepFill_Pipe::Profile() const | |
350 | { | |
351 | return myProfile; | |
352 | } | |
353 | ||
354 | //======================================================================= | |
355 | //function : Shape | |
356 | //purpose : | |
357 | //======================================================================= | |
358 | ||
359 | const TopoDS_Shape& BRepFill_Pipe::Shape() const | |
360 | { | |
361 | return myShape; | |
362 | } | |
363 | ||
73920cd4 | 364 | //======================================================================= |
365 | //function : ErrorOnSurface | |
366 | //purpose : | |
367 | //======================================================================= | |
368 | ||
369 | Standard_Real BRepFill_Pipe::ErrorOnSurface() const | |
370 | { | |
371 | return myErrorOnSurf; | |
372 | } | |
373 | ||
7fd59977 | 374 | |
375 | //======================================================================= | |
376 | //function : FirstShape | |
377 | //purpose : | |
378 | //======================================================================= | |
379 | ||
380 | const TopoDS_Shape& BRepFill_Pipe::FirstShape() const | |
381 | { | |
382 | return myFirst; | |
383 | } | |
384 | ||
385 | ||
386 | //======================================================================= | |
387 | //function : LastShape | |
388 | //purpose : | |
389 | //======================================================================= | |
390 | ||
391 | const TopoDS_Shape& BRepFill_Pipe::LastShape() const | |
392 | { | |
393 | return myLast; | |
394 | } | |
395 | ||
396 | ||
397 | //======================================================================= | |
398 | //function : Face | |
399 | //purpose : | |
400 | //======================================================================= | |
401 | ||
402 | TopoDS_Face BRepFill_Pipe::Face(const TopoDS_Edge& ESpine, | |
403 | const TopoDS_Edge& EProfile) | |
404 | { | |
405 | TopoDS_Face theFace; | |
406 | ||
407 | if ( BRep_Tool::Degenerated(EProfile)) | |
408 | return theFace; | |
409 | ||
410 | Standard_Integer ii, ispin = 0, iprof = 0, count = 0; | |
411 | ||
412 | // ************************************************* | |
413 | // Search if EProfile is an edge of myProfile | |
414 | // ************************************************* | |
415 | iprof = FindEdge(myProfile, EProfile, count); | |
416 | ||
417 | if (!iprof) Standard_DomainError::Raise( | |
418 | "BRepFill_Pipe::Face : Edge not in the Profile"); | |
419 | ||
420 | ||
421 | // ************************************************* | |
422 | // Search if ESpine is an edge of mySpine and find | |
423 | // the index of the corresponding Filler | |
424 | // ************************************************* | |
425 | for (ii=1; ii<=myLoc->NbLaw() && (!ispin); ii++) | |
426 | if (ESpine.IsSame(myLoc->Edge(ii))) ispin = ii; | |
427 | ||
428 | if (!ispin) Standard_DomainError::Raise( | |
429 | "BRepFill_Pipe::Edge : Edge not in the Spine"); | |
430 | ||
431 | theFace = TopoDS::Face(myFaces->Value(iprof, ispin)); | |
432 | return theFace; | |
433 | ||
434 | } | |
435 | ||
436 | //======================================================================= | |
437 | //function : Edge | |
438 | //purpose : | |
439 | //======================================================================= | |
440 | TopoDS_Edge BRepFill_Pipe::Edge(const TopoDS_Edge& ESpine, | |
441 | const TopoDS_Vertex& VProfile) | |
442 | { | |
443 | Standard_Integer ii, ispin = 0, iprof = 0, count = 0;; | |
444 | ||
445 | // ************************************************* | |
446 | // Search if VProfile is a Vertex of myProfile | |
447 | // ************************************************* | |
448 | iprof = FindVertex(myProfile, VProfile, count); | |
449 | if (!iprof) Standard_DomainError::Raise( | |
450 | "BRepFill_Pipe::Edge : Vertex not in the Profile"); | |
451 | ||
452 | ||
453 | // ************************************************* | |
454 | // Search if ESpine is an edge of mySpine and find | |
455 | // the index of the corresponding Filler | |
456 | // ************************************************* | |
457 | ||
458 | for (ii=1; ii<=myLoc->NbLaw() && (!ispin); ii++) | |
459 | if (ESpine.IsSame(myLoc->Edge(ii))) ispin = ii; | |
460 | ||
461 | if (!ispin) Standard_DomainError::Raise( | |
462 | "BRepFill_Pipe::Edge : Edge not in the Spine"); | |
463 | ||
464 | ||
465 | // ************************************************* | |
466 | // Generate the corresponding Shape | |
467 | // ************************************************* | |
468 | TopoDS_Edge theEdge; | |
469 | theEdge = TopoDS::Edge(myEdges->Value(iprof, ispin)); | |
470 | ||
471 | return theEdge; | |
472 | ||
473 | } | |
474 | ||
475 | ||
476 | //======================================================================= | |
477 | //function : Section | |
478 | //purpose : | |
479 | //======================================================================= | |
480 | ||
481 | TopoDS_Shape BRepFill_Pipe::Section(const TopoDS_Vertex& VSpine) const | |
482 | { | |
483 | TopoDS_Iterator it, itv; | |
484 | ||
485 | Standard_Integer ii, ispin = 0; | |
486 | ||
487 | TopoDS_Shape curSect = myProfile; | |
488 | ||
489 | // ************************************************* | |
490 | // Search if ESpine is an edge of mySpine and find | |
491 | // the index of the corresponding Filler | |
492 | // ************************************************* | |
493 | ||
494 | // iterate on all the edges of mySpine | |
495 | for (ii=1; ii<=myLoc->NbLaw()+1 && (!ispin); ii++) | |
496 | if (VSpine.IsSame(myLoc->Vertex(ii))) ispin = ii; | |
497 | ||
498 | if (!ispin) Standard_DomainError::Raise( | |
499 | "BRepFill_Pipe::Section : Vertex not in the Spine"); | |
500 | ||
501 | BRep_Builder B; | |
502 | TopoDS_Compound Comp; | |
503 | B.MakeCompound(Comp); | |
504 | for (ii=1; ii<=mySections->ColLength(); ii++) | |
505 | B.Add(Comp, mySections->Value(ii, ispin)); | |
506 | ||
507 | return Comp; | |
508 | } | |
509 | ||
510 | //======================================================================= | |
511 | //function : PipeLine | |
0d969553 | 512 | //purpose : Construct a wire by sweeping of a point |
7fd59977 | 513 | //======================================================================= |
514 | ||
c8ea5b8e | 515 | TopoDS_Wire BRepFill_Pipe::PipeLine(const gp_Pnt& Point) |
7fd59977 | 516 | { |
0d969553 | 517 | // Postioning |
7fd59977 | 518 | gp_Pnt P; |
519 | P = Point; | |
520 | P.Transform(myTrsf); | |
521 | ||
522 | BRepLib_MakeVertex MkV(P); | |
523 | Handle(BRepFill_ShapeLaw) Section = | |
524 | new (BRepFill_ShapeLaw) (MkV.Vertex()); | |
525 | ||
0d969553 | 526 | // Sweeping |
7fd59977 | 527 | BRepFill_Sweep MkSw(Section, myLoc, Standard_True); |
a31abc03 | 528 | MkSw.SetForceApproxC1(myForceApproxC1); |
8e817497 | 529 | MkSw.Build( myReversedEdges, myTapes, myRails, |
c8ea5b8e | 530 | BRepFill_Modified, myContinuity, GeomFill_Location, myDegmax, mySegmax ); |
7fd59977 | 531 | TopoDS_Shape aLocalShape = MkSw.Shape(); |
73920cd4 | 532 | myErrorOnSurf = MkSw.ErrorOnSurface(); |
7fd59977 | 533 | return TopoDS::Wire(aLocalShape); |
534 | // return TopoDS::Wire(MkSw.Shape()); | |
535 | } | |
536 | ||
537 | //======================================================================= | |
538 | //function : MakeShape | |
539 | //purpose : | |
540 | //======================================================================= | |
541 | ||
542 | TopoDS_Shape BRepFill_Pipe::MakeShape(const TopoDS_Shape& S, | |
543 | const TopoDS_Shape& FirstShape, | |
544 | const TopoDS_Shape& LastShape) | |
545 | { | |
546 | TopoDS_Shape result; | |
547 | BRep_Builder B; | |
548 | Standard_Boolean explode = Standard_False; | |
549 | TopoDS_Shape TheS, TheFirst, TheLast; | |
550 | Standard_Integer InitialLength = 0; | |
551 | TheS = S; | |
552 | TheFirst = FirstShape; | |
553 | TheLast = LastShape; | |
554 | if (! myFaces.IsNull()) InitialLength = myFaces->ColLength(); | |
555 | ||
556 | // there are two kinds of generation | |
557 | // 1. generate with S from each Filler (Vertex, Edge) | |
558 | // 2. call MakeShape recursively on the subshapes of S | |
559 | // | |
560 | // explode is True in the second case | |
561 | ||
562 | // create the result empty | |
563 | ||
564 | switch (S.ShapeType()) { | |
565 | ||
566 | case TopAbs_VERTEX : | |
567 | { | |
568 | B.MakeWire(TopoDS::Wire(result)); | |
569 | break; | |
570 | } | |
571 | ||
572 | case TopAbs_EDGE : | |
573 | { | |
574 | TopoDS_Wire W; | |
575 | B.MakeShell(TopoDS::Shell(result)); | |
576 | B.MakeWire(W); | |
577 | B.Add(W, S); | |
578 | W.Closed(S.Closed()); | |
579 | TheS = W; | |
580 | if (!FirstShape.IsNull()) { | |
581 | B.MakeWire(W); | |
582 | B.Add(W, FirstShape); | |
583 | W.Closed(FirstShape.Closed()); | |
584 | TheFirst = W; | |
585 | } | |
586 | if (!LastShape.IsNull()) { | |
587 | B.MakeWire(W); | |
588 | B.Add(W, LastShape); | |
589 | W.Closed(LastShape.Closed()); | |
590 | TheLast = W; | |
591 | } | |
592 | break; | |
593 | } | |
594 | ||
595 | case TopAbs_WIRE : | |
596 | B.MakeShell(TopoDS::Shell(result)); | |
597 | break; | |
598 | ||
599 | case TopAbs_FACE : | |
600 | { | |
601 | B.MakeShell(TopoDS::Shell(result)); | |
602 | explode = Standard_True; | |
603 | if ( !mySpine.Closed() && !TheFirst.IsNull()) { | |
604 | B.Add(result, TheFirst.Reversed()); | |
605 | } | |
606 | break; | |
607 | } | |
608 | ||
609 | case TopAbs_SHELL : | |
610 | { | |
611 | B.MakeCompSolid(TopoDS::CompSolid(result)); | |
612 | explode = Standard_True; | |
613 | break; | |
614 | } | |
615 | ||
616 | case TopAbs_SOLID : | |
617 | case TopAbs_COMPSOLID : | |
c8ea5b8e | 618 | Standard_DomainError::Raise("BRepFill_Pipe::profile contains solids"); |
7fd59977 | 619 | break; |
620 | ||
621 | case TopAbs_COMPOUND : | |
622 | { | |
623 | B.MakeCompound(TopoDS::Compound(result)); | |
624 | explode = Standard_True; | |
625 | break; | |
626 | } | |
7fd59977 | 627 | default: |
628 | break; | |
7fd59977 | 629 | } |
630 | ||
631 | if (explode) { | |
632 | // add the subshapes | |
633 | TopoDS_Iterator itFirst, itLast; | |
634 | TopoDS_Shape first, last; | |
635 | if (!TheFirst.IsNull()) itFirst.Initialize(TheFirst); | |
636 | if (!TheLast.IsNull()) itLast.Initialize(TheLast); | |
637 | ||
638 | for (TopoDS_Iterator it(S); it.More(); it.Next()) { | |
639 | if (!TheFirst.IsNull()) first = itFirst.Value(); | |
640 | if (!TheLast.IsNull()) last = itLast.Value(); | |
641 | if (TheS.ShapeType() == TopAbs_FACE ) | |
642 | MakeShape(it.Value(), first, last); | |
643 | else | |
644 | B.Add(result,MakeShape(it.Value(), first, last)); | |
645 | ||
646 | if (!TheFirst.IsNull()) itFirst.Next(); | |
647 | if (!TheLast.IsNull()) itLast.Next(); | |
648 | } | |
649 | } | |
650 | ||
651 | else { | |
652 | if (TheS.ShapeType() == TopAbs_VERTEX ) { | |
653 | Handle(BRepFill_ShapeLaw) Section = | |
654 | new (BRepFill_ShapeLaw) (TopoDS::Vertex(TheS)); | |
655 | BRepFill_Sweep MkSw(Section, myLoc, Standard_True); | |
a31abc03 | 656 | MkSw.SetForceApproxC1(myForceApproxC1); |
8e817497 | 657 | MkSw.Build( myReversedEdges, myTapes, myRails, |
c8ea5b8e | 658 | BRepFill_Modified, myContinuity, GeomFill_Location, myDegmax, mySegmax ); |
7fd59977 | 659 | result = MkSw.Shape(); |
73920cd4 | 660 | myErrorOnSurf = MkSw.ErrorOnSurface(); |
2cd138b8 | 661 | |
662 | Handle(TopTools_HArray2OfShape) aSections = MkSw.Sections(); | |
663 | ||
664 | if (aSections.IsNull() == Standard_False) { | |
665 | const Standard_Integer aVLast = aSections->UpperCol(); | |
666 | ||
667 | myFirst = aSections->Value(1, 1); | |
668 | myLast = aSections->Value(1, aVLast); | |
669 | } | |
7fd59977 | 670 | } |
671 | ||
672 | if (TheS.ShapeType() == TopAbs_WIRE ) { | |
673 | Handle(BRepFill_ShapeLaw) Section = | |
674 | new (BRepFill_ShapeLaw) (TopoDS::Wire(TheS)); | |
675 | BRepFill_Sweep MkSw(Section, myLoc, Standard_True); | |
676 | MkSw.SetBounds(TopoDS::Wire(TheFirst), | |
677 | TopoDS::Wire(TheLast)); | |
a31abc03 | 678 | MkSw.SetForceApproxC1(myForceApproxC1); |
8e817497 | 679 | MkSw.Build( myReversedEdges, myTapes, myRails, |
c8ea5b8e | 680 | BRepFill_Modified, myContinuity, GeomFill_Location, myDegmax, mySegmax ); |
7fd59977 | 681 | result = MkSw.Shape(); |
73920cd4 | 682 | myErrorOnSurf = MkSw.ErrorOnSurface(); |
f52d1b53 | 683 | //Correct <myFirst> and <myLast> |
684 | ReverseModifiedEdges(myFirst, myReversedEdges); | |
685 | ReverseModifiedEdges(myLast, myReversedEdges); | |
7fd59977 | 686 | |
0d969553 | 687 | // Labeling of elements |
7fd59977 | 688 | if (mySections.IsNull()) { |
689 | myFaces = MkSw.SubShape(); | |
690 | mySections = MkSw.Sections(); | |
691 | myEdges = MkSw.InterFaces(); | |
692 | } | |
693 | else { | |
694 | Handle(TopTools_HArray2OfShape) Aux, Somme; | |
695 | Standard_Integer length; | |
696 | Standard_Integer ii, jj, kk; | |
697 | ||
698 | Aux = MkSw.SubShape(); | |
699 | length = Aux->ColLength() + myFaces->ColLength(); | |
700 | Somme = new (TopTools_HArray2OfShape) (1, length, 1, | |
701 | Aux->RowLength()); | |
702 | for (jj=1; jj<=myFaces->RowLength(); jj++) { | |
703 | for (ii=1; ii<=myFaces->ColLength(); ii++) | |
704 | Somme->SetValue(ii, jj, myFaces->Value(ii, jj)); | |
705 | ||
706 | for (kk=1, ii=myFaces->ColLength()+1; | |
707 | kk <=Aux->ColLength(); kk++, ii++) | |
708 | Somme->SetValue(ii, jj, Aux->Value(kk, jj)); | |
709 | } | |
710 | myFaces = Somme; | |
7fd59977 | 711 | |
712 | Aux = MkSw.Sections(); | |
713 | length = Aux->ColLength() + mySections->ColLength(); | |
714 | Somme = new (TopTools_HArray2OfShape) (1, length, 1, | |
715 | Aux->RowLength()); | |
716 | for (jj=1; jj<=mySections->RowLength(); jj++) { | |
717 | for (ii=1; ii<=mySections->ColLength(); ii++) | |
718 | Somme->SetValue(ii, jj, mySections->Value(ii, jj)); | |
c8ea5b8e | 719 | |
720 | myCurIndexOfSectionEdge = mySections->ColLength()+1; | |
721 | ||
7fd59977 | 722 | for (kk=1, ii=mySections->ColLength()+1; |
723 | kk <=Aux->ColLength(); kk++, ii++) | |
724 | Somme->SetValue(ii, jj, Aux->Value(kk, jj)); | |
725 | } | |
726 | mySections = Somme; | |
727 | ||
728 | Aux = MkSw.InterFaces(); | |
729 | length = Aux->ColLength() + myEdges->ColLength(); | |
730 | Somme = new (TopTools_HArray2OfShape) (1, length, 1, | |
731 | Aux->RowLength()); | |
732 | for (jj=1; jj<=myEdges->RowLength(); jj++) { | |
733 | for (ii=1; ii<=myEdges->ColLength(); ii++) | |
734 | Somme->SetValue(ii, jj, myEdges->Value(ii, jj)); | |
735 | ||
736 | for (kk=1, ii=myEdges->ColLength()+1; | |
737 | kk <=Aux->ColLength(); kk++, ii++) | |
738 | Somme->SetValue(ii, jj, Aux->Value(kk, jj)); | |
739 | } | |
46e68e02 | 740 | |
741 | myEdges = Somme; | |
7fd59977 | 742 | } |
743 | } | |
744 | } | |
745 | ||
746 | if ( TheS.ShapeType() == TopAbs_FACE ) { | |
747 | Standard_Integer ii, jj; | |
c8ea5b8e | 748 | //jgv |
749 | TopExp_Explorer Explo(result, TopAbs_FACE); | |
750 | for (; Explo.More(); Explo.Next()) | |
751 | { | |
752 | TopoDS_Shape aFace = Explo.Current(); | |
753 | RebuildTopOrBottomFace(aFace.Reversed(), Standard_True); //top face was reversed | |
754 | } | |
755 | ///// | |
7fd59977 | 756 | TopoDS_Face F; |
757 | for (ii=InitialLength+1; ii<=myFaces->ColLength(); ii++) { | |
758 | for (jj=1; jj<=myFaces->RowLength(); jj++) { | |
759 | F = TopoDS::Face(myFaces->Value(ii, jj)); | |
760 | if (!F.IsNull()) B.Add(result, F); | |
761 | } | |
762 | } | |
763 | ||
764 | if ( !mySpine.Closed()) { | |
765 | // if Spine is not closed | |
766 | // add the last face of the solid | |
c8ea5b8e | 767 | |
768 | //jgv | |
769 | RebuildTopOrBottomFace(TheLast, Standard_False); //bottom face | |
770 | ///// | |
7fd59977 | 771 | B.Add(result, TopoDS::Face(TheLast)); |
772 | } | |
773 | ||
774 | TopoDS_Solid solid; | |
775 | BRep_Builder BS; | |
776 | BS.MakeSolid(solid); | |
777 | ||
778 | result.Closed(Standard_True); | |
779 | BS.Add(solid,TopoDS::Shell(result)); | |
780 | ||
781 | BRepClass3d_SolidClassifier SC(solid); | |
782 | SC.PerformInfinitePoint(Precision::Confusion()); | |
783 | if ( SC.State() == TopAbs_IN) { | |
784 | BS.MakeSolid(solid); | |
785 | TopoDS_Shape aLocalShape = result.Reversed(); | |
786 | BS.Add(solid,TopoDS::Shell(aLocalShape)); | |
787 | // BS.Add(solid,TopoDS::Shell(result.Reversed())); | |
788 | } | |
789 | return solid; | |
790 | } | |
791 | else { | |
792 | return result; | |
793 | } | |
7fd59977 | 794 | } |
795 | ||
0d969553 | 796 | //============================================================================ |
7fd59977 | 797 | //function : FindEdge |
0d969553 Y |
798 | //purpose : Find the number of edge corresponding to the edge of the profile. |
799 | //============================================================================ | |
7fd59977 | 800 | |
801 | Standard_Integer BRepFill_Pipe::FindEdge(const TopoDS_Shape& S, | |
802 | const TopoDS_Edge& E, | |
803 | Standard_Integer& InitialLength) const | |
804 | { | |
805 | Standard_Integer result = 0; | |
806 | ||
807 | switch (S.ShapeType()) { | |
808 | ||
809 | case TopAbs_EDGE : | |
810 | { | |
811 | InitialLength++; | |
812 | if (S.IsSame(E)) result = InitialLength; | |
813 | break; | |
814 | } | |
815 | ||
816 | case TopAbs_WIRE : | |
817 | { | |
818 | Standard_Integer ii = InitialLength+1; | |
819 | Handle(BRepFill_ShapeLaw) Section = | |
820 | new (BRepFill_ShapeLaw) (TopoDS::Wire(S), Standard_False); | |
821 | InitialLength += Section->NbLaw(); | |
822 | ||
823 | for (; (ii<=InitialLength) && (!result); ii++) { | |
824 | if (E.IsSame(Section->Edge(ii)) ) result = ii; | |
825 | } | |
826 | break; | |
827 | } | |
828 | ||
829 | case TopAbs_FACE : | |
830 | case TopAbs_SHELL : | |
831 | case TopAbs_COMPOUND : | |
832 | { | |
833 | for (TopoDS_Iterator it(S); it.More() && (!result); it.Next()) | |
834 | result = FindEdge(it.Value(), E, InitialLength ); | |
835 | break; | |
836 | } | |
837 | ||
838 | case TopAbs_SOLID : | |
839 | case TopAbs_COMPSOLID : | |
840 | Standard_DomainError::Raise("BRepFill_Pipe::SOLID or COMPSOLID"); | |
841 | break; | |
7fd59977 | 842 | default: |
843 | break; | |
7fd59977 | 844 | } |
845 | ||
846 | return result; | |
847 | } | |
848 | ||
849 | //======================================================================= | |
850 | //function : FindVertex | |
0d969553 | 851 | //purpose : Find the number of edge corresponding to an edge of the profile. |
7fd59977 | 852 | //======================================================================= |
853 | ||
854 | Standard_Integer BRepFill_Pipe::FindVertex(const TopoDS_Shape& S, | |
855 | const TopoDS_Vertex& V, | |
856 | Standard_Integer& InitialLength) const | |
857 | { | |
858 | Standard_Integer result = 0; | |
859 | ||
860 | switch (S.ShapeType()) { | |
861 | case TopAbs_VERTEX : | |
862 | { | |
863 | InitialLength++; | |
864 | if (S.IsSame(V)) result = InitialLength; | |
865 | break; | |
866 | } | |
867 | ||
868 | case TopAbs_EDGE : | |
869 | { | |
870 | TopoDS_Vertex VF, VL; | |
871 | TopExp::Vertices(TopoDS::Edge(S), VF, VL); | |
872 | if (S.Orientation() == TopAbs_REVERSED) { | |
873 | TopoDS_Vertex aux; | |
874 | aux = VF; VF = VL; VL = aux; | |
875 | } | |
876 | if (VF.IsSame(V)) result = InitialLength+1; | |
877 | else if (VL.IsSame(V)) result = InitialLength+2; | |
878 | InitialLength += 2; | |
879 | break; | |
880 | } | |
881 | ||
882 | case TopAbs_WIRE : | |
883 | { | |
884 | Standard_Integer ii = InitialLength+1; | |
885 | Handle(BRepFill_ShapeLaw) Section = | |
886 | new (BRepFill_ShapeLaw) (TopoDS::Wire(S), Standard_False); | |
887 | InitialLength += Section->NbLaw()+1; | |
888 | ||
889 | for (; (ii<=InitialLength) && (!result); ii++) { | |
890 | if (V.IsSame(Section->Vertex(ii, 0.)) ) result = ii; | |
891 | } | |
892 | break; | |
893 | } | |
894 | ||
895 | case TopAbs_FACE : | |
896 | case TopAbs_SHELL : | |
897 | case TopAbs_COMPOUND : | |
898 | { | |
899 | for (TopoDS_Iterator it(S); it.More() && (!result); it.Next()) | |
900 | result = FindVertex(it.Value(), V, InitialLength); | |
901 | break; | |
902 | } | |
903 | ||
904 | case TopAbs_SOLID : | |
905 | case TopAbs_COMPSOLID : | |
906 | Standard_DomainError::Raise("BRepFill_Pipe::SOLID or COMPSOLID"); | |
907 | break; | |
7fd59977 | 908 | default: |
909 | break; | |
7fd59977 | 910 | } |
911 | ||
912 | return result; | |
913 | } | |
914 | ||
915 | //======================================================================= | |
916 | //function : DefineRealSegmax | |
917 | //purpose : Defines the real number of segments | |
918 | // required in the case of bspline spine | |
919 | //======================================================================= | |
920 | ||
921 | void BRepFill_Pipe::DefineRealSegmax() | |
922 | { | |
923 | Standard_Integer RealSegmax = 0; | |
924 | ||
925 | TopoDS_Iterator iter(mySpine); | |
926 | for (; iter.More(); iter.Next()) | |
927 | { | |
928 | TopoDS_Edge E = TopoDS::Edge(iter.Value()); | |
929 | Standard_Real first, last; | |
930 | Handle(Geom_Curve) C = BRep_Tool::Curve( E, first, last ); | |
931 | if (C.IsNull()) | |
932 | continue; | |
933 | while (C->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve) || | |
934 | C->DynamicType() == STANDARD_TYPE(Geom_OffsetCurve)) | |
935 | { | |
936 | if (C->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) | |
937 | C = (*((Handle(Geom_TrimmedCurve)*)&C))->BasisCurve(); | |
938 | if (C->DynamicType() == STANDARD_TYPE(Geom_OffsetCurve)) | |
939 | C = (*((Handle(Geom_OffsetCurve)*)&C))->BasisCurve(); | |
940 | } | |
941 | if (C->DynamicType() == STANDARD_TYPE(Geom_BSplineCurve)) | |
942 | { | |
943 | const Handle(Geom_BSplineCurve)& BC = *((Handle(Geom_BSplineCurve)*)&C); | |
944 | Standard_Integer NbKnots = BC->NbKnots(); | |
945 | Standard_Integer RealNbKnots = NbKnots; | |
946 | if (first > BC->FirstParameter()) | |
947 | { | |
948 | Standard_Integer I1, I2; | |
949 | BC->LocateU( first, Precision::PConfusion(), I1, I2 ); | |
950 | RealNbKnots -= I1-1; | |
951 | } | |
952 | if (last < BC->LastParameter()) | |
953 | { | |
954 | Standard_Integer I1, I2; | |
955 | BC->LocateU( last, Precision::PConfusion(), I1, I2 ); | |
956 | RealNbKnots -= NbKnots-I2; | |
957 | } | |
958 | RealSegmax += RealNbKnots-1; | |
959 | } | |
960 | } | |
961 | ||
962 | if (mySegmax < RealSegmax) | |
963 | mySegmax = RealSegmax; | |
964 | } | |
46e68e02 | 965 | |
966 | //======================================================================= | |
c8ea5b8e | 967 | //function : RebuildTopOrBottomFace |
968 | //purpose : Correct orientation of v-iso edges | |
969 | // according to new 3d and 2d curves taken from swept surfaces | |
46e68e02 | 970 | //======================================================================= |
971 | ||
c8ea5b8e | 972 | void BRepFill_Pipe::RebuildTopOrBottomFace(const TopoDS_Shape& aFace, |
973 | const Standard_Boolean IsTop) const | |
46e68e02 | 974 | { |
c8ea5b8e | 975 | Standard_Integer IndexOfSection = |
976 | (IsTop)? 1 : mySections->RowLength(); | |
46e68e02 | 977 | |
c8ea5b8e | 978 | Standard_Integer ii; |
979 | BRep_Builder BB; | |
980 | TopoDS_Iterator itf(aFace); | |
981 | for (; itf.More(); itf.Next()) | |
982 | { | |
983 | TopoDS_Shape aWire = itf.Value(); | |
984 | TopTools_SequenceOfShape InitEdges; | |
985 | TopTools_SequenceOfShape ResEdges; | |
986 | TopoDS_Iterator itw(aWire); | |
987 | for (; itw.More(); itw.Next()) | |
988 | { | |
989 | TopoDS_Shape anEdge = itw.Value(); | |
990 | for (ii = myCurIndexOfSectionEdge; ii <= mySections->ColLength(); ii++) | |
991 | { | |
992 | TopoDS_Shape aVisoEdge = mySections->Value(ii, IndexOfSection); | |
993 | if (anEdge.IsSame(aVisoEdge)) | |
994 | { | |
995 | InitEdges.Append(anEdge); | |
996 | ResEdges.Append(aVisoEdge); | |
46e68e02 | 997 | break; |
998 | } | |
999 | } | |
1000 | } | |
c8ea5b8e | 1001 | aWire.Free(Standard_True); |
1002 | for (ii = 1; ii <= InitEdges.Length(); ii++) | |
1003 | { | |
1004 | BB.Remove(aWire, InitEdges(ii)); | |
1005 | UpdateTolFromTopOrBottomPCurve(TopoDS::Face(aFace), TopoDS::Edge(ResEdges(ii))); | |
1006 | BB.Add(aWire, ResEdges(ii)); | |
46e68e02 | 1007 | } |
1008 | } | |
46e68e02 | 1009 | } |