Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1995-10-27 |
2 | // Created by: Yves FRICAUD | |
3 | // Copyright (c) 1995-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 | // Modified by skv - Tue Mar 15 16:20:43 2005 | |
18 | // Add methods for supporting history. | |
7fd59977 | 19 | // Modified by skv - Mon Jan 12 11:50:02 2004 OCC4455 |
20 | ||
42cf5bc1 | 21 | #include <Adaptor3d_CurveOnSurface.hxx> |
22 | #include <BRep_Builder.hxx> | |
23 | #include <BRep_ListIteratorOfListOfPointRepresentation.hxx> | |
24 | #include <BRep_PointRepresentation.hxx> | |
25 | #include <BRep_TEdge.hxx> | |
26 | #include <BRep_Tool.hxx> | |
27 | #include <BRep_TVertex.hxx> | |
28 | #include <BRepAdaptor_Curve.hxx> | |
29 | #include <BRepAdaptor_Curve2d.hxx> | |
30 | #include <BRepAdaptor_Surface.hxx> | |
31 | #include <BRepAlgo_AsDes.hxx> | |
32 | #include <BRepAlgo_Image.hxx> | |
33 | #include <BRepCheck_Analyzer.hxx> | |
34 | #include <BRepCheck_Edge.hxx> | |
35 | #include <BRepCheck_Vertex.hxx> | |
36 | #include <BRepClass3d_SolidClassifier.hxx> | |
37 | #include <BRepGProp.hxx> | |
38 | #include <BRepLib.hxx> | |
39 | #include <BRepLib_FindSurface.hxx> | |
40 | #include <BRepLib_MakeEdge.hxx> | |
41 | #include <BRepLib_MakeFace.hxx> | |
42 | #include <BRepLib_MakeVertex.hxx> | |
7fd59977 | 43 | #include <BRepOffset_Analyse.hxx> |
7fd59977 | 44 | #include <BRepOffset_DataMapIteratorOfDataMapOfShapeOffset.hxx> |
42cf5bc1 | 45 | #include <BRepOffset_DataMapOfShapeMapOfShape.hxx> |
46 | #include <BRepOffset_DataMapOfShapeOffset.hxx> | |
47 | #include <BRepOffset_Inter2d.hxx> | |
48 | #include <BRepOffset_Inter3d.hxx> | |
7fd59977 | 49 | #include <BRepOffset_Interval.hxx> |
50 | #include <BRepOffset_ListOfInterval.hxx> | |
42cf5bc1 | 51 | #include <BRepOffset_MakeLoops.hxx> |
52 | #include <BRepOffset_MakeOffset.hxx> | |
7fd59977 | 53 | #include <BRepOffset_Offset.hxx> |
54 | #include <BRepOffset_Tool.hxx> | |
7fd59977 | 55 | #include <BRepTools.hxx> |
42cf5bc1 | 56 | #include <BRepTools_Quilt.hxx> |
57 | #include <BRepTools_Substitution.hxx> | |
58 | #include <BRepTools_WireExplorer.hxx> | |
7fd59977 | 59 | #include <ElCLib.hxx> |
42cf5bc1 | 60 | #include <ElSLib.hxx> |
61 | #include <GC_MakeCylindricalSurface.hxx> | |
7fd59977 | 62 | #include <GCE2d_MakeLine.hxx> |
42cf5bc1 | 63 | #include <gce_MakeCone.hxx> |
64 | #include <gce_MakeDir.hxx> | |
7fd59977 | 65 | #include <Geom2d_Line.hxx> |
42cf5bc1 | 66 | #include <Geom2d_TrimmedCurve.hxx> |
c22b52d6 | 67 | #include <Geom2dAdaptor_Curve.hxx> |
7fd59977 | 68 | #include <Geom_Circle.hxx> |
42cf5bc1 | 69 | #include <Geom_ConicalSurface.hxx> |
c04c30b3 | 70 | #include <Geom_CylindricalSurface.hxx> |
42cf5bc1 | 71 | #include <Geom_OffsetSurface.hxx> |
72 | #include <Geom_Plane.hxx> | |
73 | #include <Geom_SphericalSurface.hxx> | |
7fd59977 | 74 | #include <Geom_SurfaceOfLinearExtrusion.hxx> |
42cf5bc1 | 75 | #include <Geom_TrimmedCurve.hxx> |
c22b52d6 | 76 | #include <GeomAdaptor_Surface.hxx> |
42cf5bc1 | 77 | #include <GeomAPI_ProjectPointOnCurve.hxx> |
7fd59977 | 78 | #include <GeomFill_Generator.hxx> |
42cf5bc1 | 79 | #include <GeomLib.hxx> |
99c9a820 | 80 | #include <GeomLib_IsPlanarSurface.hxx> |
42cf5bc1 | 81 | #include <gp_Cone.hxx> |
82 | #include <gp_Lin2d.hxx> | |
83 | #include <gp_Pnt.hxx> | |
84 | #include <GProp_GProps.hxx> | |
bb310307 | 85 | #include <IntTools_FClass2d.hxx> |
db2f1498 | 86 | #include <NCollection_List.hxx> |
42cf5bc1 | 87 | #include <Precision.hxx> |
88 | #include <Standard_ConstructionError.hxx> | |
89 | #include <Standard_NotImplemented.hxx> | |
90 | #include <TColStd_ListIteratorOfListOfInteger.hxx> | |
91 | #include <TopExp.hxx> | |
92 | #include <TopExp_Explorer.hxx> | |
93 | #include <TopoDS.hxx> | |
94 | #include <TopoDS_Compound.hxx> | |
95 | #include <TopoDS_Edge.hxx> | |
96 | #include <TopoDS_Face.hxx> | |
97 | #include <TopoDS_Iterator.hxx> | |
98 | #include <TopoDS_Shape.hxx> | |
99 | #include <TopoDS_Shell.hxx> | |
100 | #include <TopoDS_Solid.hxx> | |
101 | #include <TopoDS_Vertex.hxx> | |
102 | #include <TopoDS_Wire.hxx> | |
103 | #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx> | |
104 | #include <TopTools_DataMapIteratorOfDataMapOfShapeReal.hxx> | |
105 | #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx> | |
106 | #include <TopTools_DataMapOfShapeShape.hxx> | |
107 | #include <TopTools_IndexedMapOfShape.hxx> | |
108 | #include <TopTools_ListIteratorOfListOfShape.hxx> | |
109 | #include <TopTools_ListOfShape.hxx> | |
110 | #include <TopTools_MapIteratorOfMapOfShape.hxx> | |
111 | #include <TopTools_MapOfShape.hxx> | |
112 | #include <TopTools_SequenceOfShape.hxx> | |
a8704c36 | 113 | #include <BRepBuilderAPI_Sewing.hxx> |
114 | #include <Geom_Line.hxx> | |
e1ed38e0 | 115 | #include <NCollection_Vector.hxx> |
e7384fd4 | 116 | #include <NCollection_IncAllocator.hxx> |
9b7f3f83 | 117 | // |
9b7f3f83 | 118 | #include <BOPAlgo_MakerVolume.hxx> |
9b7f3f83 | 119 | #include <BOPTools_AlgoTools.hxx> |
7fd59977 | 120 | |
42cf5bc1 | 121 | #include <stdio.h> |
122 | // POP for NT | |
7fd59977 | 123 | #ifdef DRAW |
124 | ||
125 | #include <DBRep.hxx> | |
126 | #endif | |
0797d9d3 | 127 | #ifdef OCCT_DEBUG |
7fd59977 | 128 | #include <OSD_Chronometer.hxx> |
498ce76b | 129 | //#define DEB_VERB |
7fd59977 | 130 | Standard_Boolean AffichInt2d = Standard_False; |
131 | Standard_Boolean AffichOffC = Standard_False; | |
132 | Standard_Boolean ChronBuild = Standard_False; | |
133 | Standard_Integer NbAE = 0; | |
134 | Standard_Integer NbAF = 0; | |
b0091bc9 | 135 | Standard_Integer NVP = 0; |
136 | Standard_Integer NVM = 0; | |
137 | Standard_Integer NVN = 0; | |
7fd59977 | 138 | static OSD_Chronometer Clock; |
139 | char name[100]; | |
140 | ||
141 | ||
142 | ||
143 | ||
144 | //======================================================================= | |
145 | //function : DEBVerticesControl | |
146 | //purpose : | |
147 | //======================================================================= | |
148 | ||
975ec82a | 149 | static void DEBVerticesControl (const TopTools_IndexedMapOfShape& NewEdges, |
9b7f3f83 | 150 | Handle(BRepAlgo_AsDes) AsDes) |
7fd59977 | 151 | { |
7fd59977 | 152 | TopTools_ListOfShape LVP; |
7fd59977 | 153 | TopTools_ListIteratorOfListOfShape it1LE ; |
154 | TopTools_ListIteratorOfListOfShape it2LE ; | |
155 | ||
975ec82a J |
156 | Standard_Integer i; |
157 | for (i = 1; i <= NewEdges.Extent(); i++) { | |
158 | const TopoDS_Edge& NE = TopoDS::Edge(NewEdges(i)); | |
7fd59977 | 159 | if (AsDes->HasDescendant(NE)) { |
160 | for (it1LE.Initialize(AsDes->Descendant(NE)); it1LE.More(); it1LE.Next()) { | |
9b7f3f83 | 161 | if (AsDes->Ascendant(it1LE.Value()).Extent() < 3) { |
162 | LVP.Append(it1LE.Value()); | |
04232180 | 163 | std::cout <<"Vertex on at least 3 edges."<<std::endl; |
7fd59977 | 164 | #ifdef DRAW |
9b7f3f83 | 165 | if (AffichInt2d) { |
166 | sprintf (name,"VP_%d",NVP++); | |
167 | DBRep::Set(name,it1LE.Value()); | |
168 | } | |
7fd59977 | 169 | #endif |
9b7f3f83 | 170 | } |
171 | else if (AsDes->Ascendant(it1LE.Value()).Extent() > 3) { | |
04232180 | 172 | std::cout <<"Vertex on more than 3 edges."<<std::endl; |
7fd59977 | 173 | #ifdef DRAW |
9b7f3f83 | 174 | if (AffichInt2d) { |
175 | sprintf (name,"VM_%d",NVM++); | |
176 | DBRep::Set(name,it1LE.Value()); | |
177 | } | |
7fd59977 | 178 | #endif |
9b7f3f83 | 179 | |
180 | } | |
181 | else { | |
7fd59977 | 182 | #ifdef DRAW |
9b7f3f83 | 183 | if (AffichInt2d) { |
184 | sprintf (name,"VN_%d",NVN++); | |
185 | DBRep::Set(name,it1LE.Value()); | |
186 | } | |
7fd59977 | 187 | #endif |
9b7f3f83 | 188 | } |
7fd59977 | 189 | } |
190 | } | |
191 | } | |
192 | //------------------------------------------------ | |
0d969553 | 193 | // Try to mix spoiled vertices. |
7fd59977 | 194 | //------------------------------------------------ |
195 | BRep_Builder B; | |
196 | TopTools_ListIteratorOfListOfShape it1(LVP); | |
197 | Standard_Real TolConf = 1.e-5; | |
198 | Standard_Real Tol = Precision::Confusion(); | |
975ec82a J |
199 | //Standard_Integer i = 1; |
200 | ||
201 | i = 1; | |
7fd59977 | 202 | for ( ; it1.More(); it1.Next()) { |
203 | TopoDS_Shape V1 = it1.Value(); | |
204 | gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(V1)); | |
205 | Standard_Real distmin = Precision::Infinite(); | |
206 | TopTools_ListIteratorOfListOfShape it2(LVP); | |
207 | Standard_Integer j = 1; | |
208 | ||
209 | for ( ; it2.More(); it2.Next()) { | |
210 | if (j > i) { | |
9b7f3f83 | 211 | TopoDS_Shape V2 = it2.Value(); |
212 | gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(V2)); | |
213 | if (!V1.IsSame(V2)) { | |
214 | Standard_Real dist = P1.Distance(P2); | |
215 | if (dist < distmin) distmin = dist; | |
216 | if (dist < TolConf) { | |
217 | Standard_Real UV2; | |
218 | TopoDS_Edge EWE2; | |
219 | const TopTools_ListOfShape& EdgeWithV2 = AsDes->Ascendant(V2); | |
220 | TopTools_ListIteratorOfListOfShape itAsDes; | |
221 | for (itAsDes.Initialize(EdgeWithV2); itAsDes.More(); itAsDes.Next()) { | |
222 | EWE2 = TopoDS::Edge(itAsDes.Value()); | |
223 | TopoDS_Shape aLocalShape = V2.Oriented(TopAbs_INTERNAL); | |
224 | UV2 = BRep_Tool::Parameter(TopoDS::Vertex(aLocalShape),EWE2); | |
225 | aLocalShape = V1.Oriented(TopAbs_INTERNAL) ; | |
226 | B.UpdateVertex(TopoDS::Vertex(aLocalShape),UV2,EWE2,Tol); | |
227 | // UV2 = | |
228 | // BRep_Tool::Parameter(TopoDS::Vertex(),EWE2); | |
229 | // B.UpdateVertex(TopoDS::Vertex(V1.Oriented(TopAbs_INTERNAL)), | |
230 | // UV2,EWE2,Tol); | |
231 | } | |
232 | AsDes->Replace(V2,V1); | |
233 | } | |
234 | } | |
7fd59977 | 235 | } |
236 | j++; | |
237 | } | |
238 | i++; | |
04232180 | 239 | std::cout <<" distmin between VP : "<<distmin<<std::endl; |
7fd59977 | 240 | } |
241 | } | |
242 | #endif | |
243 | ||
9b7f3f83 | 244 | |
245 | //======================================================================= | |
246 | // static methods | |
247 | //======================================================================= | |
ecf4f17c | 248 | static |
420b38fd | 249 | void GetEnlargedFaces(const TopTools_ListOfShape& theFaces, |
ecf4f17c | 250 | const BRepOffset_DataMapOfShapeOffset& theMapSF, |
251 | const TopTools_DataMapOfShapeShape& theMES, | |
252 | TopTools_DataMapOfShapeShape& theFacesOrigins, | |
253 | BRepAlgo_Image& theImage, | |
254 | TopTools_ListOfShape& theLSF); | |
9b7f3f83 | 255 | |
ecf4f17c | 256 | static |
1155d05a | 257 | Standard_Boolean BuildShellsCompleteInter(const TopTools_ListOfShape& theLF, |
ecf4f17c | 258 | BRepAlgo_Image& theImage, |
259 | TopoDS_Shape& theShells); | |
9b7f3f83 | 260 | |
ecf4f17c | 261 | static |
262 | Standard_Boolean GetSubShapes(const TopoDS_Shape& theShape, | |
263 | const TopAbs_ShapeEnum theSSType, | |
264 | TopoDS_Shape& theResult); | |
9b7f3f83 | 265 | |
9b7f3f83 | 266 | static |
267 | void UpdateInitOffset(BRepAlgo_Image& myInitOffset, | |
268 | BRepAlgo_Image& myImageOffset, | |
269 | const TopoDS_Shape& myOffsetShape, | |
270 | const TopAbs_ShapeEnum &theShapeType); | |
271 | ||
272 | static | |
273 | void RemoveShapes(TopoDS_Shape& theS, | |
274 | const TopTools_ListOfShape& theLS); | |
275 | ||
276 | static | |
277 | Standard_Boolean IsSolid(const TopoDS_Shape& theS); | |
278 | ||
279 | static | |
280 | void UpdateHistory(const TopTools_ListOfShape& theLF, | |
281 | BOPAlgo_Builder& theGF, | |
282 | BRepAlgo_Image& theImage); | |
283 | ||
284 | static | |
99c9a820 | 285 | void RemoveSeamAndDegeneratedEdges(const TopoDS_Face& theFace, |
286 | const TopoDS_Face& theOldFace); | |
9b7f3f83 | 287 | |
ecf4f17c | 288 | static |
3e85dfc5 | 289 | Standard_Boolean TrimEdge(TopoDS_Edge& NE, |
290 | const Handle(BRepAlgo_AsDes)& AsDes2d, | |
291 | Handle(BRepAlgo_AsDes)& AsDes, | |
292 | TopTools_DataMapOfShapeShape& theETrimEInf); | |
ecf4f17c | 293 | |
294 | static | |
3e85dfc5 | 295 | Standard_Boolean TrimEdges(const TopoDS_Shape& theShape, |
296 | const Standard_Real theOffset, | |
297 | const BRepOffset_Analyse& Analyse, | |
298 | BRepOffset_DataMapOfShapeOffset& theMapSF, | |
299 | TopTools_DataMapOfShapeShape& theMES, | |
300 | TopTools_DataMapOfShapeShape& theBuild, | |
301 | Handle(BRepAlgo_AsDes)& theAsDes, | |
302 | Handle(BRepAlgo_AsDes)& theAsDes2d, | |
303 | TopTools_IndexedMapOfShape& theNewEdges, | |
304 | TopTools_DataMapOfShapeShape& theETrimEInf, | |
305 | TopTools_DataMapOfShapeListOfShape& theEdgesOrigins); | |
ecf4f17c | 306 | |
307 | static | |
308 | void AppendToList(TopTools_ListOfShape& theL, | |
309 | const TopoDS_Shape& theS); | |
310 | ||
e1ed38e0 | 311 | static BRepOffset_Error checkSinglePoint(const Standard_Real theUParam, |
312 | const Standard_Real theVParam, | |
313 | const Handle(Geom_Surface)& theSurf, | |
314 | const NCollection_Vector<gp_Pnt>& theBadPoints); | |
315 | ||
db2f1498 | 316 | //--------------------------------------------------------------------- |
975ec82a | 317 | static void UpdateTolerance ( TopoDS_Shape& myShape, |
9b7f3f83 | 318 | const TopTools_IndexedMapOfShape& myFaces); |
4560c054 | 319 | static Standard_Real ComputeMaxDist(const gp_Pln& thePlane, |
320 | const Handle(Geom_Curve)& theCrv, | |
321 | const Standard_Real theFirst, | |
322 | const Standard_Real theLast); | |
7fd59977 | 323 | |
db2f1498 | 324 | static void CorrectSolid(TopoDS_Solid& theSol, TopTools_ListOfShape& theSolList); |
325 | //--------------------------------------------------------------------- | |
bad76cfc | 326 | |
327 | static TopAbs_Orientation OrientationOfEdgeInFace(const TopoDS_Edge& theEdge, | |
328 | const TopoDS_Face& theFace) | |
329 | { | |
330 | TopAbs_Orientation anOr = TopAbs_EXTERNAL; | |
331 | ||
332 | TopExp_Explorer Explo(theFace, TopAbs_EDGE); | |
333 | for (; Explo.More(); Explo.Next()) | |
334 | { | |
335 | const TopoDS_Shape& anEdge = Explo.Current(); | |
336 | if (anEdge.IsSame(theEdge)) | |
337 | { | |
338 | anOr = anEdge.Orientation(); | |
339 | break; | |
340 | } | |
341 | } | |
342 | ||
343 | return anOr; | |
344 | } | |
345 | ||
db2f1498 | 346 | // |
7fd59977 | 347 | static Standard_Boolean FindParameter(const TopoDS_Vertex& V, |
9b7f3f83 | 348 | const TopoDS_Edge& E, |
349 | Standard_Real& U) | |
7fd59977 | 350 | { |
351 | // Search the vertex in the edge | |
352 | ||
353 | Standard_Boolean rev = Standard_False; | |
354 | TopoDS_Shape VF; | |
355 | TopAbs_Orientation orient = TopAbs_INTERNAL; | |
356 | ||
357 | TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD)); | |
358 | ||
359 | // if the edge has no vertices | |
360 | // and is degenerated use the vertex orientation | |
361 | // RLE, june 94 | |
362 | ||
363 | if (!itv.More() && BRep_Tool::Degenerated(E)) { | |
364 | orient = V.Orientation(); | |
365 | } | |
366 | ||
367 | while (itv.More()) { | |
368 | const TopoDS_Shape& Vcur = itv.Value(); | |
369 | if (V.IsSame(Vcur)) { | |
370 | if (VF.IsNull()) { | |
9b7f3f83 | 371 | VF = Vcur; |
7fd59977 | 372 | } |
373 | else { | |
9b7f3f83 | 374 | rev = E.Orientation() == TopAbs_REVERSED; |
375 | if (Vcur.Orientation() == V.Orientation()) { | |
376 | VF = Vcur; | |
377 | } | |
7fd59977 | 378 | } |
379 | } | |
380 | itv.Next(); | |
381 | } | |
382 | ||
383 | if (!VF.IsNull()) orient = VF.Orientation(); | |
384 | ||
385 | Standard_Real f,l; | |
386 | ||
387 | if (orient == TopAbs_FORWARD) { | |
388 | BRep_Tool::Range(E,f,l); | |
389 | //return (rev) ? l : f; | |
390 | U = (rev) ? l : f; | |
391 | return Standard_True; | |
392 | } | |
393 | ||
394 | else if (orient == TopAbs_REVERSED) { | |
395 | BRep_Tool::Range(E,f,l); | |
396 | //return (rev) ? f : l; | |
397 | U = (rev) ? f : l; | |
398 | return Standard_True; | |
399 | } | |
400 | ||
401 | else { | |
402 | TopLoc_Location L; | |
403 | const Handle(Geom_Curve)& C = BRep_Tool::Curve(E,L,f,l); | |
404 | L = L.Predivided(V.Location()); | |
405 | if (!C.IsNull() || BRep_Tool::Degenerated(E)) { | |
406 | BRep_ListIteratorOfListOfPointRepresentation itpr | |
9b7f3f83 | 407 | ((*((Handle(BRep_TVertex)*) &V.TShape()))->Points()); |
7fd59977 | 408 | |
409 | while (itpr.More()) { | |
9b7f3f83 | 410 | const Handle(BRep_PointRepresentation)& pr = itpr.Value(); |
411 | if (pr->IsPointOnCurve(C,L)) { | |
412 | Standard_Real p = pr->Parameter(); | |
413 | Standard_Real res = p;// SVV 4 nov 99 - to avoid warnings on Linux | |
414 | if (!C.IsNull()) { | |
415 | // Closed curves RLE 16 june 94 | |
416 | if (Precision::IsNegativeInfinite(f)) | |
417 | { | |
418 | //return pr->Parameter();//p; | |
419 | U = pr->Parameter(); | |
420 | return Standard_True; | |
421 | } | |
422 | if (Precision::IsPositiveInfinite(l)) | |
423 | { | |
424 | //return pr->Parameter();//p; | |
425 | U = pr->Parameter(); | |
426 | return Standard_True; | |
427 | } | |
428 | gp_Pnt Pf = C->Value(f).Transformed(L.Transformation()); | |
429 | gp_Pnt Pl = C->Value(l).Transformed(L.Transformation()); | |
430 | Standard_Real tol = BRep_Tool::Tolerance(V); | |
431 | if (Pf.Distance(Pl) < tol) { | |
432 | if (Pf.Distance(BRep_Tool::Pnt(V)) < tol) { | |
433 | if (V.Orientation() == TopAbs_FORWARD) res = f;//p = f; | |
434 | else res = l;//p = l; | |
435 | } | |
436 | } | |
437 | } | |
438 | //return res;//p; | |
439 | U = res; | |
440 | return Standard_True; | |
441 | } | |
442 | itpr.Next(); | |
7fd59977 | 443 | } |
444 | } | |
445 | else { | |
446 | // no 3d curve !! | |
447 | // let us try with the first pcurve | |
448 | Handle(Geom2d_Curve) PC; | |
449 | Handle(Geom_Surface) S; | |
450 | BRep_Tool::CurveOnSurface(E,PC,S,L,f,l); | |
451 | L = L.Predivided(V.Location()); | |
452 | BRep_ListIteratorOfListOfPointRepresentation itpr | |
9b7f3f83 | 453 | ((*((Handle(BRep_TVertex)*) &V.TShape()))->Points()); |
7fd59977 | 454 | |
455 | while (itpr.More()) { | |
9b7f3f83 | 456 | const Handle(BRep_PointRepresentation)& pr = itpr.Value(); |
457 | if (pr->IsPointOnCurveOnSurface(PC,S,L)) { | |
458 | Standard_Real p = pr->Parameter(); | |
459 | // Closed curves RLE 16 june 94 | |
460 | if (PC->IsClosed()) { | |
461 | if ((p == PC->FirstParameter()) || | |
462 | (p == PC->LastParameter())) { | |
463 | if (V.Orientation() == TopAbs_FORWARD) p = PC->FirstParameter(); | |
464 | else p = PC->LastParameter(); | |
465 | } | |
466 | } | |
467 | //return p; | |
468 | U = p; | |
469 | return Standard_True; | |
470 | } | |
471 | itpr.Next(); | |
7fd59977 | 472 | } |
473 | } | |
474 | } | |
475 | ||
9775fa61 | 476 | //throw Standard_NoSuchObject("BRep_Tool:: no parameter on edge"); |
7fd59977 | 477 | return Standard_False; |
478 | } | |
479 | ||
480 | //======================================================================= | |
481 | //function : GetEdgePoints | |
482 | //purpose : gets the first, last and middle points of the edge | |
483 | //======================================================================= | |
484 | static void GetEdgePoints(const TopoDS_Edge& anEdge, | |
485 | const TopoDS_Face& aFace, | |
486 | gp_Pnt& fPnt, gp_Pnt& mPnt, | |
487 | gp_Pnt& lPnt) | |
488 | { | |
489 | Standard_Real f, l; | |
490 | Handle(Geom2d_Curve) theCurve = BRep_Tool::CurveOnSurface( anEdge, aFace, f, l ); | |
491 | gp_Pnt2d fPnt2d = theCurve->Value(f); | |
492 | gp_Pnt2d lPnt2d = theCurve->Value(l); | |
493 | gp_Pnt2d mPnt2d = theCurve->Value(0.5*(f + l)); | |
494 | Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace); | |
495 | fPnt = aSurf->Value(fPnt2d.X(),fPnt2d.Y()); | |
496 | lPnt = aSurf->Value(lPnt2d.X(),lPnt2d.Y()); | |
497 | mPnt = aSurf->Value(mPnt2d.X(), mPnt2d.Y()); | |
498 | } | |
499 | ||
500 | //======================================================================= | |
501 | //function : FillContours | |
502 | //purpose : fills free boundary contours and faces connected (MapEF) | |
503 | //======================================================================= | |
504 | static void FillContours(const TopoDS_Shape& aShape, | |
9b7f3f83 | 505 | const BRepOffset_Analyse& Analyser, |
bad76cfc | 506 | TopTools_IndexedDataMapOfShapeListOfShape& Contours, |
9b7f3f83 | 507 | TopTools_DataMapOfShapeShape& MapEF) |
7fd59977 | 508 | { |
509 | TopTools_ListOfShape Edges; | |
510 | ||
511 | TopExp_Explorer Explo(aShape, TopAbs_FACE); | |
512 | BRepTools_WireExplorer Wexp; | |
513 | ||
514 | for (; Explo.More(); Explo.Next()) | |
eff3eff9 | 515 | { |
516 | TopoDS_Face aFace = TopoDS::Face(Explo.Current()); | |
517 | TopoDS_Iterator itf(aFace); | |
518 | for (; itf.More(); itf.Next()) | |
7fd59977 | 519 | { |
eff3eff9 | 520 | TopoDS_Wire aWire = TopoDS::Wire(itf.Value()); |
521 | for (Wexp.Init(aWire, aFace); Wexp.More(); Wexp.Next()) | |
522 | { | |
523 | TopoDS_Edge anEdge = Wexp.Current(); | |
524 | if (BRep_Tool::Degenerated(anEdge)) | |
525 | continue; | |
526 | const BRepOffset_ListOfInterval& Lint = Analyser.Type(anEdge); | |
527 | if (!Lint.IsEmpty() && Lint.First().Type() == ChFiDS_FreeBound) | |
9b7f3f83 | 528 | { |
eff3eff9 | 529 | MapEF.Bind(anEdge, aFace); |
530 | Edges.Append(anEdge); | |
9b7f3f83 | 531 | } |
eff3eff9 | 532 | } |
7fd59977 | 533 | } |
eff3eff9 | 534 | } |
7fd59977 | 535 | |
536 | TopTools_ListIteratorOfListOfShape itl; | |
537 | while (!Edges.IsEmpty()) | |
538 | { | |
539 | TopoDS_Edge StartEdge = TopoDS::Edge(Edges.First()); | |
540 | Edges.RemoveFirst(); | |
541 | TopoDS_Vertex StartVertex, CurVertex; | |
542 | TopExp::Vertices(StartEdge, StartVertex, CurVertex, Standard_True); | |
543 | TopTools_ListOfShape aContour; | |
544 | aContour.Append(StartEdge); | |
545 | while (!CurVertex.IsSame(StartVertex)) | |
9b7f3f83 | 546 | for (itl.Initialize(Edges); itl.More(); itl.Next()) |
547 | { | |
548 | TopoDS_Edge anEdge = TopoDS::Edge(itl.Value()); | |
549 | TopoDS_Vertex V1, V2; | |
550 | TopExp::Vertices(anEdge, V1, V2); | |
551 | if (V1.IsSame(CurVertex) || V2.IsSame(CurVertex)) | |
552 | { | |
553 | aContour.Append(anEdge); | |
554 | CurVertex = (V1.IsSame(CurVertex))? V2 : V1; | |
555 | Edges.Remove(itl); | |
556 | break; | |
557 | } | |
558 | } | |
bad76cfc | 559 | Contours.Add(StartVertex, aContour); |
7fd59977 | 560 | } |
561 | } | |
562 | ||
db2f1498 | 563 | // |
564 | //----------------------------------------------------------------------- | |
565 | // | |
7fd59977 | 566 | //======================================================================= |
567 | //function : BRepOffset_MakeOffset | |
568 | //purpose : | |
569 | //======================================================================= | |
570 | ||
571 | BRepOffset_MakeOffset::BRepOffset_MakeOffset() | |
572 | { | |
573 | myAsDes = new BRepAlgo_AsDes(); | |
574 | } | |
575 | ||
576 | ||
577 | //======================================================================= | |
578 | //function : BRepOffset_MakeOffset | |
579 | //purpose : | |
580 | //======================================================================= | |
581 | ||
582 | BRepOffset_MakeOffset::BRepOffset_MakeOffset(const TopoDS_Shape& S, | |
9b7f3f83 | 583 | const Standard_Real Offset, |
584 | const Standard_Real Tol, | |
585 | const BRepOffset_Mode Mode, | |
586 | const Standard_Boolean Inter, | |
587 | const Standard_Boolean SelfInter, | |
588 | const GeomAbs_JoinType Join, | |
589 | const Standard_Boolean Thickening, | |
ecf4f17c | 590 | const Standard_Boolean RemoveIntEdges) |
7fd59977 | 591 | : |
592 | myOffset (Offset), | |
593 | myTol (Tol), | |
8948e18d | 594 | myInitialShape (S), |
7fd59977 | 595 | myShape (S), |
596 | myMode (Mode), | |
597 | myInter (Inter), | |
598 | mySelfInter (SelfInter), | |
599 | myJoin (Join), | |
9b7f3f83 | 600 | myThickening (Thickening), |
601 | myRemoveIntEdges(RemoveIntEdges), | |
7fd59977 | 602 | myDone (Standard_False) |
7fd59977 | 603 | { |
604 | myAsDes = new BRepAlgo_AsDes(); | |
99c9a820 | 605 | myIsLinearizationAllowed = Standard_True; |
606 | ||
7fd59977 | 607 | MakeOffsetShape(); |
608 | } | |
609 | ||
610 | ||
611 | //======================================================================= | |
612 | //function : Initialize | |
613 | //purpose : | |
614 | //======================================================================= | |
615 | ||
616 | void BRepOffset_MakeOffset::Initialize(const TopoDS_Shape& S, | |
9b7f3f83 | 617 | const Standard_Real Offset, |
618 | const Standard_Real Tol, | |
619 | const BRepOffset_Mode Mode, | |
620 | const Standard_Boolean Inter, | |
621 | const Standard_Boolean SelfInter, | |
622 | const GeomAbs_JoinType Join, | |
623 | const Standard_Boolean Thickening, | |
ecf4f17c | 624 | const Standard_Boolean RemoveIntEdges) |
7fd59977 | 625 | { |
626 | myOffset = Offset; | |
8948e18d | 627 | myInitialShape = S; |
7fd59977 | 628 | myShape = S; |
629 | myTol = Tol; | |
630 | myMode = Mode; | |
631 | myInter = Inter; | |
632 | mySelfInter = SelfInter; | |
633 | myJoin = Join; | |
9b7f3f83 | 634 | myThickening = Thickening; |
635 | myRemoveIntEdges = RemoveIntEdges; | |
99c9a820 | 636 | myIsLinearizationAllowed = Standard_True; |
7fd59977 | 637 | myDone = Standard_False; |
a8704c36 | 638 | myIsPerformSewing = Standard_False; |
9b7f3f83 | 639 | myIsPlanar = Standard_False; |
7fd59977 | 640 | Clear(); |
641 | } | |
642 | ||
643 | ||
644 | //======================================================================= | |
645 | //function : Clear | |
646 | //purpose : | |
647 | //======================================================================= | |
648 | ||
649 | void BRepOffset_MakeOffset::Clear() | |
650 | { | |
651 | myOffsetShape.Nullify(); | |
652 | myInitOffsetFace .Clear(); | |
653 | myInitOffsetEdge .Clear(); | |
654 | myImageOffset .Clear(); | |
8948e18d | 655 | myImageVV .Clear(); |
7fd59977 | 656 | myFaces .Clear(); |
99c9a820 | 657 | myOriginalFaces .Clear(); |
7fd59977 | 658 | myFaceOffset .Clear(); |
8948e18d | 659 | myEdgeIntEdges .Clear(); |
7fd59977 | 660 | myAsDes ->Clear(); |
661 | myDone = Standard_False; | |
420b38fd | 662 | myGenerated.Clear(); |
663 | myResMap.Clear(); | |
7fd59977 | 664 | } |
665 | ||
99c9a820 | 666 | //======================================================================= |
667 | //function : AllowLinearization | |
668 | //purpose : | |
669 | //======================================================================= | |
670 | ||
671 | void BRepOffset_MakeOffset::AllowLinearization(const Standard_Boolean theIsAllowed) | |
672 | { | |
673 | myIsLinearizationAllowed = theIsAllowed; | |
674 | } | |
675 | ||
7fd59977 | 676 | //======================================================================= |
677 | //function : AddFace | |
678 | //purpose : | |
679 | //======================================================================= | |
680 | ||
681 | void BRepOffset_MakeOffset::AddFace(const TopoDS_Face& F) { | |
99c9a820 | 682 | |
683 | myOriginalFaces.Add(F); | |
7fd59977 | 684 | } |
685 | ||
686 | //======================================================================= | |
687 | //function : SetOffsetOnFace | |
688 | //purpose : | |
689 | //======================================================================= | |
690 | ||
691 | void BRepOffset_MakeOffset::SetOffsetOnFace(const TopoDS_Face& F, | |
9b7f3f83 | 692 | const Standard_Real Off) |
7fd59977 | 693 | { |
99c9a820 | 694 | myFaceOffset.Bind(F, Off); |
7fd59977 | 695 | } |
696 | ||
697 | //======================================================================= | |
698 | //function : RemoveCorks | |
699 | //purpose : | |
700 | //======================================================================= | |
701 | ||
975ec82a | 702 | static void RemoveCorks (TopoDS_Shape& S, |
9b7f3f83 | 703 | TopTools_IndexedMapOfShape& Faces) |
7fd59977 | 704 | { |
705 | TopoDS_Compound SS; | |
706 | BRep_Builder B; | |
707 | B.MakeCompound (SS); | |
708 | //----------------------------------------------------- | |
0d969553 Y |
709 | // Construction of a shape without caps. |
710 | // and Orientation of caps as in shape S. | |
7fd59977 | 711 | //----------------------------------------------------- |
712 | TopExp_Explorer exp(S,TopAbs_FACE); | |
713 | for (; exp.More(); exp.Next()) { | |
714 | const TopoDS_Shape& Cork = exp.Current(); | |
715 | if (!Faces.Contains(Cork)) { | |
716 | B.Add(SS,Cork); | |
717 | } | |
718 | else { | |
3f5aa017 | 719 | Faces.RemoveKey(Cork); |
975ec82a | 720 | Faces.Add(Cork); // to reset it with proper orientation. |
7fd59977 | 721 | } |
722 | } | |
723 | S = SS; | |
724 | #ifdef DRAW | |
725 | if ( AffichOffC) | |
726 | DBRep::Set("myInit", SS); | |
727 | #endif | |
728 | ||
729 | } | |
730 | ||
9b7f3f83 | 731 | //======================================================================= |
732 | //function : IsConnectedShell | |
733 | //purpose : | |
734 | //======================================================================= | |
7fd59977 | 735 | static Standard_Boolean IsConnectedShell( const TopoDS_Shape& S ) |
736 | { | |
737 | BRepTools_Quilt Glue; | |
738 | Glue.Add( S ); | |
739 | ||
740 | TopoDS_Shape SS = Glue.Shells(); | |
741 | TopExp_Explorer Explo( SS, TopAbs_SHELL ); | |
742 | Explo.Next(); | |
743 | if (Explo.More()) | |
744 | return Standard_False; | |
745 | ||
746 | return Standard_True; | |
747 | } | |
748 | ||
749 | ||
750 | //======================================================================= | |
751 | //function : MakeList | |
752 | //purpose : | |
753 | //======================================================================= | |
754 | ||
975ec82a | 755 | static void MakeList (TopTools_ListOfShape& OffsetFaces, |
9b7f3f83 | 756 | const BRepAlgo_Image& myInitOffsetFace, |
757 | const TopTools_IndexedMapOfShape& myFaces) | |
7fd59977 | 758 | { |
759 | TopTools_ListIteratorOfListOfShape itLOF(myInitOffsetFace.Roots()); | |
760 | for ( ; itLOF.More(); itLOF.Next()) { | |
761 | const TopoDS_Shape& Root = itLOF.Value(); | |
9b7f3f83 | 762 | if (!myFaces.Contains(Root)) { |
763 | if (myInitOffsetFace.HasImage(Root)) { | |
edfa30de | 764 | TopTools_ListIteratorOfListOfShape aItLS(myInitOffsetFace.Image(Root)); |
765 | for (; aItLS.More(); aItLS.Next()) { | |
766 | OffsetFaces.Append(aItLS.Value()); | |
767 | } | |
9b7f3f83 | 768 | } |
769 | } | |
7fd59977 | 770 | } |
771 | } | |
772 | ||
773 | //======================================================================= | |
774 | //function : EvalMax | |
775 | //purpose : | |
776 | //======================================================================= | |
777 | ||
778 | static void EvalMax(const TopoDS_Shape& S, Standard_Real& Tol) | |
779 | { | |
780 | TopExp_Explorer exp; | |
781 | for (exp.Init(S,TopAbs_VERTEX); exp.More(); exp.Next()) { | |
782 | const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current()); | |
783 | Standard_Real TolV = BRep_Tool::Tolerance(V); | |
784 | if (TolV > Tol) Tol = TolV; | |
785 | } | |
7fd59977 | 786 | } |
787 | ||
99c9a820 | 788 | //======================================================================= |
789 | //function : SetFaces | |
790 | //purpose : | |
791 | //======================================================================= | |
792 | ||
793 | void BRepOffset_MakeOffset::SetFaces() | |
794 | { | |
795 | for (Standard_Integer ii = 1; ii <= myOriginalFaces.Extent(); ii++) | |
796 | { | |
797 | TopoDS_Face aFace = TopoDS::Face(myOriginalFaces(ii)); | |
798 | const TopoDS_Shape* aPlanface = myFacePlanfaceMap.Seek(aFace); | |
799 | if (aPlanface) | |
800 | aFace = TopoDS::Face(*aPlanface); | |
801 | ||
802 | myFaces.Add(aFace); | |
803 | //------------- | |
804 | // MAJ SD. | |
805 | //------------- | |
806 | myInitOffsetFace.SetRoot (aFace) ; | |
807 | myInitOffsetFace.Bind (aFace, aFace); | |
808 | myImageOffset.SetRoot (aFace) ; | |
809 | } | |
810 | } | |
811 | ||
812 | //======================================================================= | |
813 | //function : SetFacesWithOffset | |
814 | //purpose : | |
815 | //======================================================================= | |
816 | ||
817 | void BRepOffset_MakeOffset::SetFacesWithOffset() | |
818 | { | |
819 | TopTools_DataMapIteratorOfDataMapOfShapeShape anItmap(myFacePlanfaceMap); | |
820 | for (; anItmap.More(); anItmap.Next()) | |
821 | { | |
822 | TopoDS_Face aFace = TopoDS::Face(anItmap.Key()); | |
823 | TopoDS_Face aPlanface = TopoDS::Face(anItmap.Value()); | |
824 | if (myFaceOffset.IsBound(aFace)) | |
825 | { | |
826 | Standard_Real anOffset = myFaceOffset(aFace); | |
827 | myFaceOffset.UnBind(aFace); | |
828 | myFaceOffset.Bind(aPlanface, anOffset); | |
829 | } | |
830 | } | |
831 | } | |
a8704c36 | 832 | |
7fd59977 | 833 | //======================================================================= |
834 | //function : MakeOffsetShape | |
835 | //purpose : | |
836 | //======================================================================= | |
837 | ||
838 | void BRepOffset_MakeOffset::MakeOffsetShape() | |
839 | { | |
03383c97 | 840 | myDone = Standard_False; |
9b7f3f83 | 841 | // |
99c9a820 | 842 | |
9b7f3f83 | 843 | // check if shape consists of only planar faces |
99c9a820 | 844 | myIsPlanar = IsPlanar(); |
845 | ||
846 | SetFaces(); | |
847 | SetFacesWithOffset(); | |
848 | ||
849 | BuildFaceComp(); | |
850 | ||
7fd59977 | 851 | //------------------------------------------ |
0d969553 | 852 | // Construction of myShape without caps. |
7fd59977 | 853 | //------------------------------------------ |
db2f1498 | 854 | if(!myFaces.IsEmpty()) |
855 | { | |
99c9a820 | 856 | RemoveCorks (myShape, myOriginalFaces); |
857 | RemoveCorks (myFaceComp, myFaces); | |
db2f1498 | 858 | } |
03383c97 | 859 | |
e1ed38e0 | 860 | if (!CheckInputData()) |
03383c97 | 861 | { |
e1ed38e0 | 862 | // There is error in input data. |
863 | // Check Error() method. | |
864 | return; | |
03383c97 | 865 | } |
3e85dfc5 | 866 | myError = BRepOffset_NoError; |
7fd59977 | 867 | TopAbs_State Side = TopAbs_IN; |
868 | if (myOffset < 0.) Side = TopAbs_OUT; | |
03383c97 | 869 | |
7fd59977 | 870 | // ------------ |
871 | // Preanalyse. | |
872 | // ------------ | |
873 | EvalMax(myShape,myTol); | |
a07a0416 | 874 | // There are possible second variant: analytical continuation of arcsin. |
03383c97 | 875 | Standard_Real TolAngleCoeff = Min(myTol / (Abs(myOffset * 0.5) + Precision::Confusion()), 1.0); |
a07a0416 | 876 | Standard_Real TolAngle = 4*ASin(TolAngleCoeff); |
420b38fd | 877 | if ((myJoin == GeomAbs_Intersection) && myInter && myIsPlanar) |
878 | { | |
879 | myAnalyse.SetOffsetValue (myOffset); | |
880 | myAnalyse.SetFaceOffsetMap (myFaceOffset); | |
881 | } | |
99c9a820 | 882 | myAnalyse.Perform(myFaceComp,TolAngle); |
7fd59977 | 883 | //--------------------------------------------------- |
0d969553 | 884 | // Construction of Offset from preanalysis. |
7fd59977 | 885 | //--------------------------------------------------- |
886 | //---------------------------- | |
0d969553 | 887 | // MaJ of SD Face - Offset |
7fd59977 | 888 | //---------------------------- |
889 | UpdateFaceOffset(); | |
890 | ||
891 | if (myJoin == GeomAbs_Arc) | |
892 | BuildOffsetByArc(); | |
893 | else if (myJoin == GeomAbs_Intersection) | |
894 | BuildOffsetByInter(); | |
3e85dfc5 | 895 | if (myError != BRepOffset_NoError) |
896 | { | |
897 | return; | |
898 | } | |
7fd59977 | 899 | //----------------- |
0d969553 | 900 | // Auto unwinding. |
7fd59977 | 901 | //----------------- |
902 | // if (mySelfInter) SelfInter(Modif); | |
903 | //----------------- | |
904 | // Intersection 3d . | |
905 | //----------------- | |
906 | BRepOffset_Inter3d Inter(myAsDes,Side,myTol); | |
907 | Intersection3D (Inter); | |
908 | //----------------- | |
909 | // Intersection2D | |
910 | //----------------- | |
975ec82a J |
911 | TopTools_IndexedMapOfShape& Modif = Inter.TouchedFaces(); |
912 | TopTools_IndexedMapOfShape& NewEdges = Inter.NewEdges(); | |
7fd59977 | 913 | |
914 | if (!Modif.IsEmpty()) Intersection2D (Modif,NewEdges); | |
915 | //------------------------------------------------------- | |
0d969553 | 916 | // Unwinding 2D and reconstruction of modified faces |
7fd59977 | 917 | //---------------------------------------------------- |
918 | MakeLoops (Modif); | |
919 | //----------------------------------------------------- | |
0d969553 Y |
920 | // Reconstruction of non modified faces sharing |
921 | // reconstructed edges | |
7fd59977 | 922 | //------------------------------------------------------ |
923 | if (!Modif.IsEmpty()) MakeFaces (Modif); | |
924 | ||
925 | if (myThickening) | |
926 | MakeMissingWalls(); | |
927 | ||
928 | //------------------------- | |
0d969553 | 929 | // Construction of shells. |
7fd59977 | 930 | //------------------------- |
931 | MakeShells (); | |
ecf4f17c | 932 | if (myOffsetShape.IsNull()) { |
933 | // not done | |
934 | myDone = Standard_False; | |
935 | return; | |
936 | } | |
7fd59977 | 937 | //-------------- |
0d969553 | 938 | // Unwinding 3D. |
7fd59977 | 939 | //-------------- |
940 | SelectShells (); | |
941 | //---------------------------------- | |
9b7f3f83 | 942 | // Remove INTERNAL edges if necessary |
943 | //---------------------------------- | |
944 | if (myRemoveIntEdges) { | |
945 | RemoveInternalEdges(); | |
946 | } | |
947 | //---------------------------------- | |
0d969553 | 948 | // Coding of regularities. |
7fd59977 | 949 | //---------------------------------- |
950 | EncodeRegularity(); | |
420b38fd | 951 | //---------------------------------- |
952 | // Replace roots in history maps | |
953 | //---------------------------------- | |
954 | ReplaceRoots(); | |
7fd59977 | 955 | //---------------------- |
0d969553 | 956 | // Creation of solids. |
7fd59977 | 957 | //---------------------- |
958 | MakeSolid (); | |
959 | ||
960 | //----------------------------- | |
0d969553 | 961 | // MAJ Tolerance edge and Vertex |
7fd59977 | 962 | // ---------------------------- |
963 | if (!myOffsetShape.IsNull()) { | |
964 | UpdateTolerance (myOffsetShape,myFaces); | |
965 | BRepLib::UpdateTolerances( myOffsetShape ); | |
966 | } | |
967 | ||
968 | CorrectConicalFaces(); | |
969 | ||
a8704c36 | 970 | // Result solid should be computed in MakeOffset scope. |
971 | if (myThickening && | |
972 | myIsPerformSewing) | |
973 | { | |
974 | BRepBuilderAPI_Sewing aSew(myTol); | |
975 | aSew.Add(myOffsetShape); | |
976 | aSew.Perform(); | |
977 | myOffsetShape = aSew.SewedShape(); | |
978 | ||
979 | // Rebuild solid. | |
980 | // Offset shape expected to be really closed after sewing. | |
981 | myOffsetShape.Closed(Standard_True); | |
982 | MakeSolid(); | |
983 | } | |
984 | ||
7fd59977 | 985 | myDone = Standard_True; |
986 | } | |
987 | ||
988 | ||
989 | ||
990 | //======================================================================= | |
991 | //function : MakeThickSolid | |
992 | //purpose : | |
993 | //======================================================================= | |
994 | ||
995 | void BRepOffset_MakeOffset::MakeThickSolid() | |
996 | { | |
997 | //-------------------------------------------------------------- | |
0d969553 | 998 | // Construction of shell parallel to shell (initial without cap). |
7fd59977 | 999 | //-------------------------------------------------------------- |
1000 | MakeOffsetShape (); | |
1001 | ||
e1ed38e0 | 1002 | if (!myDone) |
1003 | { | |
1004 | // Save return code and myDone state. | |
1005 | return; | |
1006 | } | |
1007 | ||
7fd59977 | 1008 | //-------------------------------------------------------------------- |
0d969553 Y |
1009 | // Construction of a solid with the initial shell, parallel shell |
1010 | // limited by caps. | |
7fd59977 | 1011 | //-------------------------------------------------------------------- |
e1ed38e0 | 1012 | if (!myFaces.IsEmpty()) |
1013 | { | |
7fd59977 | 1014 | TopoDS_Solid Res; |
1015 | TopExp_Explorer exp; | |
1016 | BRep_Builder B; | |
1017 | Standard_Integer NbF = myFaces.Extent(); | |
1018 | ||
1019 | B.MakeSolid(Res); | |
1020 | ||
1021 | BRepTools_Quilt Glue; | |
e1ed38e0 | 1022 | for (exp.Init(myShape,TopAbs_FACE); exp.More(); exp.Next()) |
1023 | { | |
7fd59977 | 1024 | NbF++; |
1025 | Glue.Add (exp.Current()); | |
1026 | } | |
1027 | Standard_Boolean YaResult = 0; | |
ab87e6fc | 1028 | if (!myOffsetShape.IsNull()) |
1029 | { | |
1030 | for (exp.Init(myOffsetShape,TopAbs_FACE);exp.More(); exp.Next()) | |
1031 | { | |
1032 | YaResult = 1; | |
1033 | Glue.Add (exp.Current().Reversed()); | |
1034 | } | |
0797d9d3 | 1035 | #ifdef OCCT_DEBUG |
ab87e6fc | 1036 | if(YaResult == 0) |
1037 | { | |
04232180 | 1038 | std::cout << "OffsetShape does not contain a FACES." << std::endl; |
ab87e6fc | 1039 | } |
1040 | #endif | |
7fd59977 | 1041 | } |
0797d9d3 | 1042 | #ifdef OCCT_DEBUG |
ab87e6fc | 1043 | else |
1044 | { | |
04232180 | 1045 | std::cout << "OffsetShape is null!" << std::endl; |
ab87e6fc | 1046 | } |
1047 | #endif | |
1048 | ||
1049 | if (YaResult == 0) | |
1050 | { | |
7fd59977 | 1051 | myDone = Standard_False; |
e1ed38e0 | 1052 | myError = BRepOffset_UnknownError; |
7fd59977 | 1053 | return; |
ab87e6fc | 1054 | } |
1055 | ||
7fd59977 | 1056 | myOffsetShape = Glue.Shells(); |
e1ed38e0 | 1057 | for (exp.Init(myOffsetShape,TopAbs_SHELL); exp.More(); exp.Next()) |
1058 | { | |
7fd59977 | 1059 | B.Add(Res,exp.Current()); |
1060 | } | |
1061 | Res.Closed(Standard_True); | |
1062 | myOffsetShape = Res; | |
1063 | ||
0d969553 Y |
1064 | // Test of Validity of the result of thick Solid |
1065 | // more face than the initial solid. | |
7fd59977 | 1066 | Standard_Integer NbOF = 0; |
e1ed38e0 | 1067 | for (exp.Init(myOffsetShape,TopAbs_FACE);exp.More(); exp.Next()) |
1068 | { | |
7fd59977 | 1069 | NbOF++; |
1070 | } | |
e1ed38e0 | 1071 | if (NbOF <= NbF) |
1072 | { | |
7fd59977 | 1073 | myDone = Standard_False; |
e1ed38e0 | 1074 | myError = BRepOffset_UnknownError; |
7fd59977 | 1075 | return; |
1076 | } | |
1077 | } | |
1078 | ||
e1ed38e0 | 1079 | if (myOffset > 0 ) myOffsetShape.Reverse(); |
7fd59977 | 1080 | |
1081 | myDone = Standard_True; | |
1082 | } | |
1083 | ||
1084 | //======================================================================= | |
1085 | //function : IsDone | |
1086 | //purpose : | |
1087 | //======================================================================= | |
1088 | ||
1089 | Standard_Boolean BRepOffset_MakeOffset::IsDone() const | |
1090 | { | |
1091 | return myDone; | |
1092 | } | |
1093 | ||
1094 | //======================================================================= | |
1095 | //function : Error | |
1096 | //purpose : | |
1097 | //======================================================================= | |
1098 | ||
1099 | BRepOffset_Error BRepOffset_MakeOffset::Error() const | |
1100 | { | |
1101 | return myError; | |
1102 | } | |
1103 | ||
1104 | //======================================================================= | |
1105 | //function : Shape | |
1106 | //purpose : | |
1107 | //======================================================================= | |
1108 | ||
1109 | const TopoDS_Shape& BRepOffset_MakeOffset::Shape() const | |
1110 | { | |
1111 | return myOffsetShape; | |
1112 | } | |
1113 | ||
1114 | //======================================================================= | |
ecf4f17c | 1115 | //function : MakeOffsetFaces |
1116 | //purpose : | |
7fd59977 | 1117 | //======================================================================= |
ecf4f17c | 1118 | void BRepOffset_MakeOffset::MakeOffsetFaces(BRepOffset_DataMapOfShapeOffset& theMapSF) |
7fd59977 | 1119 | { |
ecf4f17c | 1120 | Standard_Real aCurOffset; |
1121 | TopTools_ListOfShape aLF; | |
1122 | TopTools_DataMapOfShapeShape ShapeTgt; | |
1123 | TopTools_ListIteratorOfListOfShape aItLF; | |
9b7f3f83 | 1124 | // |
ecf4f17c | 1125 | Standard_Boolean OffsetOutside = (myOffset > 0.); |
9b7f3f83 | 1126 | // |
99c9a820 | 1127 | BRepLib::SortFaces(myFaceComp, aLF); |
9b7f3f83 | 1128 | // |
ecf4f17c | 1129 | aItLF.Initialize(aLF); |
1130 | for (; aItLF.More(); aItLF.Next()) { | |
1131 | const TopoDS_Face& aF = TopoDS::Face(aItLF.Value()); | |
1132 | aCurOffset = myFaceOffset.IsBound(aF) ? myFaceOffset(aF) : myOffset; | |
1133 | BRepOffset_Offset OF(aF, aCurOffset, ShapeTgt, OffsetOutside, myJoin); | |
7fd59977 | 1134 | TopTools_ListOfShape Let; |
eff3eff9 | 1135 | myAnalyse.Edges(aF,ChFiDS_Tangential,Let); |
ecf4f17c | 1136 | TopTools_ListIteratorOfListOfShape itl(Let); |
1137 | for (; itl.More(); itl.Next()) { | |
7fd59977 | 1138 | const TopoDS_Edge& Cur = TopoDS::Edge(itl.Value()); |
420b38fd | 1139 | if ( !ShapeTgt.IsBound(Cur) && !myAnalyse.HasGenerated (Cur)) { |
9b7f3f83 | 1140 | TopoDS_Shape aLocalShape = OF.Generated(Cur); |
1141 | const TopoDS_Edge& OTE = TopoDS::Edge(aLocalShape); | |
9b7f3f83 | 1142 | ShapeTgt.Bind(Cur,OF.Generated(Cur)); |
1143 | TopoDS_Vertex V1,V2,OV1,OV2; | |
1144 | TopExp::Vertices (Cur,V1,V2); | |
1145 | TopExp::Vertices (OTE,OV1,OV2); | |
1146 | TopTools_ListOfShape LE; | |
1147 | if (!ShapeTgt.IsBound(V1)) { | |
eff3eff9 | 1148 | myAnalyse.Edges(V1,ChFiDS_Tangential,LE); |
9b7f3f83 | 1149 | const TopTools_ListOfShape& LA =myAnalyse.Ancestors(V1); |
1150 | if (LE.Extent() == LA.Extent()) | |
1151 | ShapeTgt.Bind(V1,OV1); | |
1152 | } | |
1153 | if (!ShapeTgt.IsBound(V2)) { | |
1154 | LE.Clear(); | |
eff3eff9 | 1155 | myAnalyse.Edges(V2,ChFiDS_Tangential,LE); |
9b7f3f83 | 1156 | const TopTools_ListOfShape& LA =myAnalyse.Ancestors(V2); |
1157 | if (LE.Extent() == LA.Extent()) | |
1158 | ShapeTgt.Bind(V2,OV2); | |
1159 | } | |
7fd59977 | 1160 | } |
1161 | } | |
ecf4f17c | 1162 | theMapSF.Bind(aF,OF); |
1163 | } | |
420b38fd | 1164 | // |
1165 | const TopTools_ListOfShape& aNewFaces = myAnalyse.NewFaces(); | |
1166 | for (TopTools_ListOfShape::Iterator it (aNewFaces); it.More(); it.Next()) | |
1167 | { | |
1168 | const TopoDS_Face& aF = TopoDS::Face (it.Value()); | |
1169 | BRepOffset_Offset OF(aF, 0.0, ShapeTgt, OffsetOutside, myJoin); | |
1170 | theMapSF.Bind (aF, OF); | |
1171 | } | |
ecf4f17c | 1172 | } |
1173 | ||
1174 | //======================================================================= | |
1175 | //function : BuildOffsetByInter | |
1176 | //purpose : | |
1177 | //======================================================================= | |
1178 | void BRepOffset_MakeOffset::BuildOffsetByInter() | |
1179 | { | |
1180 | #ifdef OCCT_DEBUG | |
1181 | if ( ChronBuild) { | |
04232180 | 1182 | std::cout << " CONSTRUCTION OF OFFSETS :" << std::endl; |
ecf4f17c | 1183 | Clock.Reset(); |
1184 | Clock.Start(); | |
7fd59977 | 1185 | } |
ecf4f17c | 1186 | #endif |
1187 | ||
1188 | TopExp_Explorer Exp, Exp2, ExpC; | |
1189 | TopTools_ListIteratorOfListOfShape itLF; | |
1190 | ||
1191 | //-------------------------------------------------------- | |
1192 | // Construction of faces parallel to initial faces | |
1193 | //-------------------------------------------------------- | |
1194 | BRepOffset_DataMapOfShapeOffset MapSF; | |
1195 | MakeOffsetFaces(MapSF); | |
7fd59977 | 1196 | //-------------------------------------------------------------------- |
1197 | // MES : Map of OffsetShape -> Extended Shapes. | |
1198 | // Build : Map of Initial SS -> OffsetShape build by Inter. | |
1199 | // can be an edge or a compound of edges | |
1200 | //--------------------------------------------------------------------- | |
1201 | TopTools_DataMapOfShapeShape MES; | |
1202 | TopTools_DataMapOfShapeShape Build; | |
1203 | TopTools_ListOfShape Failed; | |
1204 | TopAbs_State Side = TopAbs_IN; | |
1205 | Handle(BRepAlgo_AsDes) AsDes = new BRepAlgo_AsDes(); | |
1206 | ||
1207 | //------------------------------------------------------------------- | |
0d969553 | 1208 | // Extension of faces and calculation of new edges of intersection. |
7fd59977 | 1209 | //------------------------------------------------------------------- |
1210 | Standard_Boolean ExtentContext = 0; | |
1211 | if (myOffset > 0) ExtentContext = 1; | |
1212 | ||
1213 | BRepOffset_Inter3d Inter3 (AsDes,Side,myTol); | |
0d969553 | 1214 | // Intersection between parallel faces |
99c9a820 | 1215 | Inter3.ConnexIntByInt(myFaceComp,MapSF,myAnalyse,MES,Build,Failed,myIsPlanar); |
0d969553 | 1216 | // Intersection with caps. |
9b7f3f83 | 1217 | Inter3.ContextIntByInt(myFaces,ExtentContext,MapSF,myAnalyse,MES,Build,Failed,myIsPlanar); |
7fd59977 | 1218 | |
420b38fd | 1219 | TopTools_ListOfShape aLFaces; |
99c9a820 | 1220 | for (Exp.Init(myFaceComp,TopAbs_FACE) ; Exp.More(); Exp.Next()) |
420b38fd | 1221 | aLFaces.Append (Exp.Current()); |
420b38fd | 1222 | for (TopTools_ListOfShape::Iterator it (myAnalyse.NewFaces()); it.More(); it.Next()) |
1223 | aLFaces.Append (it.Value()); | |
7fd59977 | 1224 | //--------------------------------------------------------------------------------- |
0d969553 | 1225 | // Extension of neighbor edges of new edges and intersection between neighbors. |
7fd59977 | 1226 | //-------------------------------------------------------------------------------- |
1227 | Handle(BRepAlgo_AsDes) AsDes2d = new BRepAlgo_AsDes(); | |
420b38fd | 1228 | IntersectEdges(aLFaces, MapSF, MES, Build, AsDes, AsDes2d); |
3e85dfc5 | 1229 | if (myError != BRepOffset_NoError) |
1230 | { | |
1231 | return; | |
1232 | } | |
7fd59977 | 1233 | //----------------------------------------------------------- |
0d969553 | 1234 | // Great restriction of new edges and update of AsDes. |
7fd59977 | 1235 | //------------------------------------------ ---------------- |
ecf4f17c | 1236 | TopTools_DataMapOfShapeListOfShape anEdgesOrigins; // offset edge - initial edges |
975ec82a | 1237 | TopTools_IndexedMapOfShape NewEdges; |
ecf4f17c | 1238 | TopTools_DataMapOfShapeShape aETrimEInf; // trimmed - not trimmed edges |
1239 | // | |
1240 | //Map of edges obtained after FACE-FACE (offsetted) intersection. | |
1241 | //Key1 is edge trimmed by intersection points with other edges; | |
1242 | //Item is not-trimmed edge. | |
99c9a820 | 1243 | if (!TrimEdges(myFaceComp, myOffset, myAnalyse, MapSF, MES, Build, AsDes, AsDes2d, NewEdges, aETrimEInf, anEdgesOrigins)) |
3e85dfc5 | 1244 | { |
1245 | myError = BRepOffset_CannotTrimEdges; | |
1246 | return; | |
1247 | } | |
ecf4f17c | 1248 | // |
7fd59977 | 1249 | //--------------------------------- |
0d969553 | 1250 | // Intersection 2D on // |
7fd59977 | 1251 | //--------------------------------- |
ecf4f17c | 1252 | TopTools_IndexedDataMapOfShapeListOfShape aDMVV; |
1253 | TopTools_DataMapOfShapeShape aFacesOrigins; // offset face - initial face | |
7fd59977 | 1254 | TopTools_ListOfShape LFE; |
1255 | BRepAlgo_Image IMOE; | |
420b38fd | 1256 | GetEnlargedFaces(aLFaces, MapSF, MES, aFacesOrigins, IMOE, LFE); |
ecf4f17c | 1257 | // |
7fd59977 | 1258 | TopTools_ListIteratorOfListOfShape itLFE(LFE); |
03383c97 | 1259 | for (; itLFE.More(); itLFE.Next()) |
1260 | { | |
7fd59977 | 1261 | const TopoDS_Face& NEF = TopoDS::Face(itLFE.Value()); |
03383c97 | 1262 | Standard_Real aCurrFaceTol = BRep_Tool::Tolerance(NEF); |
8948e18d | 1263 | BRepOffset_Inter2d::Compute(AsDes, NEF, NewEdges, aCurrFaceTol, myEdgeIntEdges, aDMVV); |
7fd59977 | 1264 | } |
1265 | //---------------------------------------------- | |
0d969553 | 1266 | // Intersections 2d on caps. |
7fd59977 | 1267 | //---------------------------------------------- |
975ec82a | 1268 | Standard_Integer i; |
03383c97 | 1269 | for (i = 1; i <= myFaces.Extent(); i++) |
1270 | { | |
975ec82a | 1271 | const TopoDS_Face& Cork = TopoDS::Face(myFaces(i)); |
03383c97 | 1272 | Standard_Real aCurrFaceTol = BRep_Tool::Tolerance(Cork); |
8948e18d | 1273 | BRepOffset_Inter2d::Compute(AsDes, Cork, NewEdges, aCurrFaceTol, myEdgeIntEdges, aDMVV); |
7fd59977 | 1274 | } |
b0fbc579 | 1275 | // |
8948e18d | 1276 | BRepOffset_Inter2d::FuseVertices(aDMVV, AsDes, myImageVV); |
7fd59977 | 1277 | //------------------------------- |
0d969553 | 1278 | // Unwinding of extended Faces. |
7fd59977 | 1279 | //------------------------------- |
9b7f3f83 | 1280 | // |
1281 | TopTools_MapOfShape aMFDone; | |
1282 | // | |
ecf4f17c | 1283 | if ((myJoin == GeomAbs_Intersection) && myInter && myIsPlanar) { |
420b38fd | 1284 | BuildSplitsOfExtendedFaces(LFE, myAnalyse, AsDes, anEdgesOrigins, aFacesOrigins, aETrimEInf, IMOE); |
9b7f3f83 | 1285 | // |
ecf4f17c | 1286 | TopTools_ListIteratorOfListOfShape aItLF(LFE); |
1287 | for (; aItLF.More(); aItLF.Next()) { | |
1288 | const TopoDS_Shape& aS = aItLF.Value(); | |
1289 | aMFDone.Add(aS); | |
9b7f3f83 | 1290 | } |
1291 | } | |
1292 | else { | |
8948e18d | 1293 | myMakeLoops.Build(LFE, AsDes, IMOE, myImageVV); |
9b7f3f83 | 1294 | } |
1295 | // | |
0797d9d3 | 1296 | #ifdef OCCT_DEBUG |
975ec82a | 1297 | TopTools_IndexedMapOfShape COES; |
7fd59977 | 1298 | #endif |
1299 | //--------------------------- | |
0d969553 | 1300 | // MAJ SD. for faces // |
7fd59977 | 1301 | //--------------------------- |
420b38fd | 1302 | for (TopTools_ListOfShape::Iterator it (aLFaces); it.More(); it.Next()) |
1303 | { | |
1304 | const TopoDS_Shape& FI = it.Value(); | |
7fd59977 | 1305 | myInitOffsetFace.SetRoot(FI); |
1306 | TopoDS_Face OF = MapSF(FI).Face(); | |
1307 | if (MES.IsBound(OF)) { | |
1308 | OF = TopoDS::Face(MES(OF)); | |
1309 | if (IMOE.HasImage(OF)) { | |
9b7f3f83 | 1310 | const TopTools_ListOfShape& LOFE = IMOE.Image(OF); |
1311 | myInitOffsetFace.Bind(FI,LOFE); | |
1312 | for (itLF.Initialize(LOFE); itLF.More(); itLF.Next()) { | |
1313 | const TopoDS_Shape& OFE = itLF.Value(); | |
1314 | myImageOffset.SetRoot(OFE); | |
7fd59977 | 1315 | #ifdef DRAW |
9b7f3f83 | 1316 | if (AffichInt2d) { |
1317 | sprintf(name,"AF_%d",NbAF++); | |
1318 | DBRep::Set(name,OFE); | |
1319 | } | |
7fd59977 | 1320 | #endif |
9b7f3f83 | 1321 | TopTools_MapOfShape View; |
1322 | for (Exp2.Init(OFE.Oriented(TopAbs_FORWARD),TopAbs_EDGE); | |
1323 | Exp2.More(); Exp2.Next()) { | |
1324 | const TopoDS_Edge& COE = TopoDS::Edge(Exp2.Current()); | |
1325 | ||
1326 | myAsDes->Add (OFE,COE); | |
7fd59977 | 1327 | #ifdef DRAW |
9b7f3f83 | 1328 | if (AffichInt2d) { |
1329 | sprintf(name,"AE_%d",NbAE++); | |
1330 | DBRep::Set(name,COE); | |
1331 | COES.Add(COE); | |
1332 | } | |
7fd59977 | 1333 | #endif |
9b7f3f83 | 1334 | if (View.Add(COE)){ |
1335 | if (!myAsDes->HasDescendant(COE)) { | |
1336 | TopoDS_Vertex CV1,CV2; | |
1337 | TopExp::Vertices(COE,CV1,CV2); | |
1338 | if (!CV1.IsNull()) myAsDes->Add(COE,CV1.Oriented(TopAbs_FORWARD)); | |
1339 | if (!CV2.IsNull()) myAsDes->Add(COE,CV2.Oriented(TopAbs_REVERSED)); | |
1340 | } | |
1341 | } | |
1342 | } | |
1343 | } | |
7fd59977 | 1344 | } |
1345 | else { | |
9b7f3f83 | 1346 | if (aMFDone.Contains(OF)) { |
1347 | continue; | |
1348 | } | |
1349 | // | |
1350 | myInitOffsetFace.Bind(FI,OF); | |
1351 | myImageOffset.SetRoot(OF); | |
7fd59977 | 1352 | #ifdef DRAW |
9b7f3f83 | 1353 | if (AffichInt2d) { |
1354 | sprintf(name,"AF_%d",NbAF++); | |
1355 | DBRep::Set(name,OF); | |
1356 | } | |
7fd59977 | 1357 | #endif |
9b7f3f83 | 1358 | const TopTools_ListOfShape& LE = AsDes->Descendant(OF); |
1359 | for (itLF.Initialize(LE) ; itLF.More(); itLF.Next()) { | |
1360 | const TopoDS_Edge& OE = TopoDS::Edge(itLF.Value()); | |
1361 | if (IMOE.HasImage(OE)) { | |
1362 | const TopTools_ListOfShape& LOE = IMOE.Image(OE); | |
1363 | TopTools_ListIteratorOfListOfShape itLOE(LOE); | |
1364 | for (; itLOE.More(); itLOE.Next()) { | |
1365 | TopoDS_Shape aLocalShape = itLOE.Value().Oriented(OE.Orientation()); | |
1366 | const TopoDS_Edge& COE = TopoDS::Edge(aLocalShape); | |
1367 | // const TopoDS_Edge& COE = TopoDS::Edge(itLOE.Value().Oriented(OE.Orientation())); | |
1368 | myAsDes->Add(OF,COE); | |
7fd59977 | 1369 | #ifdef DRAW |
9b7f3f83 | 1370 | if (AffichInt2d) { |
1371 | sprintf(name,"AE_%d",NbAE++); | |
1372 | DBRep::Set(name,COE); | |
1373 | COES.Add(COE); | |
1374 | } | |
7fd59977 | 1375 | #endif |
9b7f3f83 | 1376 | |
1377 | if (!myAsDes->HasDescendant(COE)) { | |
1378 | TopoDS_Vertex CV1,CV2; | |
1379 | TopExp::Vertices(COE,CV1,CV2); | |
1380 | if (!CV1.IsNull()) myAsDes->Add(COE,CV1.Oriented(TopAbs_FORWARD)); | |
1381 | if (!CV2.IsNull()) myAsDes->Add(COE,CV2.Oriented(TopAbs_REVERSED)); | |
1382 | } | |
1383 | } | |
1384 | } | |
1385 | else { | |
1386 | myAsDes->Add(OF,OE); | |
7fd59977 | 1387 | #ifdef DRAW |
9b7f3f83 | 1388 | if (AffichInt2d) { |
1389 | sprintf(name,"AE_%d",NbAE++); | |
1390 | DBRep::Set(name,OE); | |
1391 | COES.Add(OE); | |
1392 | } | |
7fd59977 | 1393 | #endif |
1394 | ||
9b7f3f83 | 1395 | const TopTools_ListOfShape& LV = AsDes->Descendant(OE); |
1396 | myAsDes->Add(OE,LV); | |
1397 | } | |
1398 | } | |
7fd59977 | 1399 | } |
1400 | } | |
1401 | else { | |
1402 | myInitOffsetFace.Bind(FI,OF); | |
1403 | myImageOffset.SetRoot(OF); | |
1404 | TopTools_MapOfShape View; | |
1405 | for (Exp2.Init(OF.Oriented(TopAbs_FORWARD),TopAbs_EDGE); | |
9b7f3f83 | 1406 | Exp2.More(); Exp2.Next()) { |
7fd59977 | 1407 | |
9b7f3f83 | 1408 | const TopoDS_Edge& COE = TopoDS::Edge(Exp2.Current()); |
1409 | myAsDes->Add (OF,COE); | |
7fd59977 | 1410 | #ifdef DRAW |
9b7f3f83 | 1411 | if (AffichInt2d) { |
1412 | sprintf(name,"AE_%d",NbAE++); | |
1413 | DBRep::Set(name,COE); | |
1414 | COES.Add(COE); | |
1415 | } | |
7fd59977 | 1416 | #endif |
9b7f3f83 | 1417 | |
1418 | if (View.Add(Exp2.Current())) { | |
1419 | if (!myAsDes->HasDescendant(COE)) { | |
1420 | TopoDS_Vertex CV1,CV2; | |
1421 | TopExp::Vertices(COE,CV1,CV2); | |
1422 | if (!CV1.IsNull()) myAsDes->Add(COE,CV1.Oriented(TopAbs_FORWARD)); | |
1423 | if (!CV2.IsNull()) myAsDes->Add(COE,CV2.Oriented(TopAbs_REVERSED)); | |
1424 | } | |
1425 | } | |
7fd59977 | 1426 | } |
1427 | } | |
1428 | } | |
1429 | // Modified by skv - Tue Mar 15 16:20:43 2005 | |
1430 | // Add methods for supporting history. | |
1431 | TopTools_MapOfShape aMapEdges; | |
1432 | ||
420b38fd | 1433 | for (TopTools_ListOfShape::Iterator it (aLFaces); it.More(); it.Next()) |
1434 | { | |
1435 | const TopoDS_Shape& aFaceRef = it.Value(); | |
7fd59977 | 1436 | Exp2.Init(aFaceRef.Oriented(TopAbs_FORWARD), TopAbs_EDGE); |
1437 | ||
1438 | for (; Exp2.More(); Exp2.Next()) { | |
1439 | const TopoDS_Shape& anEdgeRef = Exp2.Current(); | |
1440 | ||
1441 | if (aMapEdges.Add(anEdgeRef)) { | |
9b7f3f83 | 1442 | myInitOffsetEdge.SetRoot(anEdgeRef); |
1443 | if (Build.IsBound(anEdgeRef)) { | |
1444 | TopoDS_Shape aNewShape = Build(anEdgeRef); | |
1445 | ||
1446 | if (aNewShape.ShapeType() == TopAbs_EDGE) { | |
1447 | if (IMOE.HasImage(aNewShape)) { | |
1448 | const TopTools_ListOfShape& aListNewE = IMOE.Image(aNewShape); | |
1449 | ||
1450 | myInitOffsetEdge.Bind (anEdgeRef, aListNewE); | |
1451 | } else | |
1452 | myInitOffsetEdge.Bind (anEdgeRef, aNewShape); | |
1453 | } else { // aNewShape != TopAbs_EDGE | |
1454 | TopTools_ListOfShape aListNewEdge; | |
1455 | ||
1456 | for (ExpC.Init(aNewShape, TopAbs_EDGE); ExpC.More(); ExpC.Next()) { | |
1457 | const TopoDS_Shape &aResEdge = ExpC.Current(); | |
1458 | ||
1459 | if (IMOE.HasImage(aResEdge)) { | |
1460 | const TopTools_ListOfShape& aListNewE = IMOE.Image(aResEdge); | |
1461 | TopTools_ListIteratorOfListOfShape aNewEIter(aListNewE); | |
1462 | ||
1463 | for (; aNewEIter.More(); aNewEIter.Next()) | |
1464 | aListNewEdge.Append(aNewEIter.Value()); | |
1465 | } else | |
1466 | aListNewEdge.Append(aResEdge); | |
1467 | } | |
1468 | ||
1469 | myInitOffsetEdge.Bind (anEdgeRef, aListNewEdge); | |
1470 | } | |
1471 | } | |
1472 | else { // Free boundary. | |
1473 | TopoDS_Shape aNewEdge = MapSF(aFaceRef).Generated(anEdgeRef); | |
1474 | ||
1475 | if (MES.IsBound(aNewEdge)) | |
1476 | aNewEdge = MES(aNewEdge); | |
1477 | ||
1478 | if (IMOE.HasImage(aNewEdge)) { | |
1479 | const TopTools_ListOfShape& aListNewE = IMOE.Image(aNewEdge); | |
1480 | ||
1481 | myInitOffsetEdge.Bind (anEdgeRef, aListNewE); | |
1482 | } else | |
1483 | myInitOffsetEdge.Bind (anEdgeRef, aNewEdge); | |
1484 | } | |
7fd59977 | 1485 | } |
1486 | } | |
1487 | } | |
1488 | // Modified by skv - Tue Mar 15 16:20:43 2005 | |
1489 | ||
1490 | //--------------------------- | |
ecf4f17c | 1491 | // MAJ SD. for caps |
7fd59977 | 1492 | //--------------------------- |
975ec82a J |
1493 | //TopTools_MapOfShape View; |
1494 | for (i = 1; i <= myFaces.Extent(); i++) { | |
1495 | const TopoDS_Shape& Cork = myFaces(i); | |
7fd59977 | 1496 | const TopTools_ListOfShape& LE = AsDes->Descendant(Cork); |
1497 | for (itLF.Initialize(LE) ; itLF.More(); itLF.Next()) { | |
1498 | const TopoDS_Edge& OE = TopoDS::Edge(itLF.Value()); | |
1499 | if (IMOE.HasImage(OE)) { | |
9b7f3f83 | 1500 | const TopTools_ListOfShape& LOE = IMOE.Image(OE); |
1501 | TopTools_ListIteratorOfListOfShape itLOE(LOE); | |
1502 | for (; itLOE.More(); itLOE.Next()) { | |
1503 | const TopoDS_Edge& COE = TopoDS::Edge(itLOE.Value()); | |
1504 | myAsDes->Add(Cork,COE.Oriented(OE.Orientation())) ; | |
7fd59977 | 1505 | #ifdef DRAW |
9b7f3f83 | 1506 | if (AffichInt2d) { |
1507 | sprintf(name,"AE_%d",NbAE++); | |
1508 | DBRep::Set(name,COE); | |
1509 | COES.Add(COE); | |
1510 | } | |
7fd59977 | 1511 | #endif |
9b7f3f83 | 1512 | |
1513 | if (!myAsDes->HasDescendant(COE)) { | |
1514 | TopoDS_Vertex CV1,CV2; | |
1515 | TopExp::Vertices(COE,CV1,CV2); | |
1516 | if (!CV1.IsNull()) myAsDes->Add(COE,CV1.Oriented(TopAbs_FORWARD)); | |
1517 | if (!CV2.IsNull()) myAsDes->Add(COE,CV2.Oriented(TopAbs_REVERSED)); | |
1518 | } | |
1519 | } | |
7fd59977 | 1520 | } |
1521 | else { | |
9b7f3f83 | 1522 | myAsDes->Add(Cork,OE); |
1523 | if (AsDes->HasDescendant(OE)) { | |
1524 | myAsDes->Add(OE,AsDes->Descendant(OE)); | |
1525 | } | |
7fd59977 | 1526 | #ifdef DRAW |
9b7f3f83 | 1527 | if (AffichInt2d) { |
1528 | sprintf(name,"AE_%d",NbAE++); | |
1529 | DBRep::Set(name,OE); | |
1530 | COES.Add(OE); | |
1531 | } | |
7fd59977 | 1532 | #endif |
1533 | } | |
1534 | } | |
1535 | } | |
1536 | ||
0797d9d3 | 1537 | #ifdef OCCT_DEBUG |
7fd59977 | 1538 | DEBVerticesControl (COES,myAsDes); |
1539 | if ( ChronBuild) Clock.Show(); | |
1540 | #endif | |
420b38fd | 1541 | |
1542 | } | |
1543 | ||
1544 | //======================================================================= | |
1545 | //function : ReplaceRoots | |
1546 | //purpose : | |
1547 | //======================================================================= | |
1548 | void BRepOffset_MakeOffset::ReplaceRoots() | |
1549 | { | |
1550 | // Replace the artificial faces and edges in InitOffset maps with the original ones. | |
1551 | TopTools_MapOfShape View; | |
99c9a820 | 1552 | for (TopExp_Explorer anExpF (myFaceComp, TopAbs_EDGE); anExpF.More(); anExpF.Next()) |
420b38fd | 1553 | { |
1554 | const TopoDS_Shape& aF = anExpF.Current(); | |
1555 | for (TopExp_Explorer anExpE (aF, TopAbs_EDGE); anExpE.More(); anExpE.Next()) | |
1556 | { | |
1557 | const TopoDS_Shape& aE = anExpE.Current(); | |
1558 | if (!View.Add (aE)) | |
1559 | continue; | |
1560 | ||
1561 | TopoDS_Shape aFGen = myAnalyse.Generated (aE); | |
1562 | if (aFGen.IsNull()) | |
1563 | continue; | |
1564 | ||
1565 | myInitOffsetFace.ReplaceRoot (aFGen, aE); | |
1566 | ||
1567 | for (TopoDS_Iterator itV (aE); itV.More(); itV.Next()) | |
1568 | { | |
1569 | const TopoDS_Shape& aV = itV.Value(); | |
1570 | if (!View.Add (aV)) | |
1571 | continue; | |
1572 | ||
1573 | TopoDS_Shape aEGen = myAnalyse.Generated (aV); | |
1574 | if (aEGen.IsNull()) | |
1575 | continue; | |
1576 | ||
1577 | myInitOffsetEdge.ReplaceRoot (aEGen, aV); | |
1578 | } | |
1579 | } | |
1580 | } | |
7fd59977 | 1581 | } |
1582 | ||
99c9a820 | 1583 | //======================================================================= |
1584 | //function : BuildFaceComp | |
1585 | //purpose : Make a compound containing actual faces (including planar faces instead of their originals) | |
1586 | //======================================================================= | |
1587 | void BRepOffset_MakeOffset::BuildFaceComp() | |
1588 | { | |
1589 | BRep_Builder aBB; | |
1590 | aBB.MakeCompound(myFaceComp); | |
1591 | TopExp_Explorer anExplo(myShape, TopAbs_FACE); | |
1592 | for (; anExplo.More(); anExplo.Next()) | |
1593 | { | |
1594 | TopoDS_Shape aFace = anExplo.Current(); | |
1595 | TopAbs_Orientation anOr = aFace.Orientation(); | |
1596 | const TopoDS_Shape* aPlanface = myFacePlanfaceMap.Seek(aFace); | |
1597 | if (aPlanface) | |
1598 | aFace = *aPlanface; | |
1599 | aBB.Add(myFaceComp, aFace.Oriented(anOr)); | |
1600 | } | |
1601 | } | |
1602 | ||
9b7f3f83 | 1603 | //======================================================================= |
ecf4f17c | 1604 | //function : BuildOffsetByArc |
9b7f3f83 | 1605 | //purpose : |
1606 | //======================================================================= | |
ecf4f17c | 1607 | void BRepOffset_MakeOffset::BuildOffsetByArc() |
9b7f3f83 | 1608 | { |
ecf4f17c | 1609 | #ifdef OCCT_DEBUG |
1610 | if ( ChronBuild) { | |
04232180 | 1611 | std::cout << " CONSTRUCTION OF OFFSETS :" << std::endl; |
ecf4f17c | 1612 | Clock.Reset(); |
1613 | Clock.Start(); | |
7fd59977 | 1614 | } |
1615 | #endif | |
1616 | ||
ecf4f17c | 1617 | TopExp_Explorer Exp; |
1618 | TopTools_ListIteratorOfListOfShape itLF; | |
1619 | TopTools_MapOfShape Done; | |
1620 | ||
7fd59977 | 1621 | //-------------------------------------------------------- |
0d969553 | 1622 | // Construction of faces parallel to initial faces |
7fd59977 | 1623 | //-------------------------------------------------------- |
ecf4f17c | 1624 | BRepOffset_DataMapOfShapeOffset MapSF; |
1625 | MakeOffsetFaces(MapSF); | |
7fd59977 | 1626 | //-------------------------------------------------------- |
0d969553 | 1627 | // Construction of tubes on edge. |
7fd59977 | 1628 | //-------------------------------------------------------- |
eff3eff9 | 1629 | ChFiDS_TypeOfConcavity OT = ChFiDS_Convex; |
1630 | if (myOffset < 0.) OT = ChFiDS_Concave; | |
7fd59977 | 1631 | |
99c9a820 | 1632 | for (Exp.Init(myFaceComp,TopAbs_EDGE); Exp.More(); Exp.Next()) { |
7fd59977 | 1633 | const TopoDS_Edge& E = TopoDS::Edge(Exp.Current()); |
1634 | if (Done.Add(E)) { | |
1635 | const TopTools_ListOfShape& Anc = myAnalyse.Ancestors(E); | |
1636 | if (Anc.Extent() == 2) { | |
9b7f3f83 | 1637 | const BRepOffset_ListOfInterval& L = myAnalyse.Type(E); |
1638 | if (!L.IsEmpty() && L.First().Type() == OT) { | |
1639 | Standard_Real CurOffset = myOffset; | |
1640 | if ( myFaceOffset.IsBound(Anc.First())) | |
1641 | CurOffset = myFaceOffset(Anc.First()); | |
1642 | TopoDS_Shape aLocalShapeGen = MapSF(Anc.First()).Generated(E); | |
1643 | TopoDS_Edge EOn1 = TopoDS::Edge(aLocalShapeGen); | |
1644 | aLocalShapeGen = MapSF(Anc.Last()).Generated(E); | |
1645 | TopoDS_Edge EOn2 = TopoDS::Edge(aLocalShapeGen); | |
1646 | // TopoDS_Edge EOn1 = TopoDS::Edge(MapSF(Anc.First()).Generated(E)); | |
1647 | // TopoDS_Edge EOn2 = TopoDS::Edge(MapSF(Anc.Last()) .Generated(E)); | |
1648 | // find if exits tangent edges in the original shape | |
1649 | TopoDS_Edge E1f, E1l; | |
1650 | TopoDS_Vertex V1f, V1l; | |
1651 | TopExp::Vertices(E,V1f,V1l); | |
1652 | TopTools_ListOfShape TangE; | |
1653 | myAnalyse.TangentEdges(E,V1f,TangE); | |
1654 | // find if the pipe on the tangent edges are soon created. | |
1655 | TopTools_ListIteratorOfListOfShape itl(TangE); | |
1656 | Standard_Boolean Find = Standard_False; | |
1657 | for ( ; itl.More() && !Find; itl.Next()) { | |
1658 | if ( MapSF.IsBound(itl.Value())) { | |
1659 | TopoDS_Shape aLocalShape = MapSF(itl.Value()).Generated(V1f); | |
1660 | E1f = TopoDS::Edge(aLocalShape); | |
1661 | // E1f = TopoDS::Edge(MapSF(itl.Value()).Generated(V1f)); | |
1662 | Find = Standard_True; | |
1663 | } | |
1664 | } | |
1665 | TangE.Clear(); | |
1666 | myAnalyse.TangentEdges(E,V1l,TangE); | |
1667 | // find if the pipe on the tangent edges are soon created. | |
1668 | itl.Initialize(TangE); | |
1669 | Find = Standard_False; | |
1670 | for ( ; itl.More() && !Find; itl.Next()) { | |
1671 | if ( MapSF.IsBound(itl.Value())) { | |
1672 | TopoDS_Shape aLocalShape = MapSF(itl.Value()).Generated(V1l); | |
1673 | E1l = TopoDS::Edge(aLocalShape); | |
1674 | // E1l = TopoDS::Edge(MapSF(itl.Value()).Generated(V1l)); | |
1675 | Find = Standard_True; | |
1676 | } | |
1677 | } | |
1678 | BRepOffset_Offset OF (E,EOn1,EOn2,CurOffset,E1f, E1l); | |
1679 | MapSF.Bind(E,OF); | |
1680 | } | |
7fd59977 | 1681 | } |
1682 | else { | |
9b7f3f83 | 1683 | // ---------------------- |
1684 | // free border. | |
1685 | // ---------------------- | |
1686 | TopoDS_Shape aLocalShape = MapSF(Anc.First()).Generated(E); | |
1687 | TopoDS_Edge EOn1 = TopoDS::Edge(aLocalShape); | |
1688 | /// TopoDS_Edge EOn1 = TopoDS::Edge(MapSF(Anc.First()).Generated(E)); | |
7fd59977 | 1689 | myInitOffsetEdge.SetRoot(E); // skv: supporting history. |
9b7f3f83 | 1690 | myInitOffsetEdge.Bind (E,EOn1); |
7fd59977 | 1691 | } |
1692 | } | |
1693 | } | |
1694 | ||
1695 | //-------------------------------------------------------- | |
0d969553 | 1696 | // Construction of spheres on vertex. |
7fd59977 | 1697 | //-------------------------------------------------------- |
1698 | Done.Clear(); | |
1699 | TopTools_ListIteratorOfListOfShape it; | |
1700 | ||
99c9a820 | 1701 | for (Exp.Init(myFaceComp,TopAbs_VERTEX); Exp.More(); Exp.Next()) { |
7fd59977 | 1702 | const TopoDS_Vertex& V = TopoDS::Vertex (Exp.Current()); |
1703 | if (Done.Add(V)) { | |
1704 | const TopTools_ListOfShape& LA = myAnalyse.Ancestors(V); | |
1705 | TopTools_ListOfShape LE; | |
1706 | myAnalyse.Edges(V,OT,LE); | |
1707 | ||
1708 | if (LE.Extent() >= 3 && LE.Extent() == LA.Extent()) { | |
9b7f3f83 | 1709 | TopTools_ListOfShape LOE; |
1710 | //-------------------------------------------------------- | |
1711 | // Return connected edges on tubes. | |
1712 | //-------------------------------------------------------- | |
1713 | for (it.Initialize(LE) ; it.More(); it.Next()) { | |
1714 | LOE.Append(MapSF(it.Value()).Generated(V).Reversed()); | |
1715 | } | |
1716 | //---------------------- | |
1717 | // construction sphere. | |
1718 | //----------------------- | |
1719 | const TopTools_ListOfShape& LLA = myAnalyse.Ancestors(LA.First()); | |
1720 | const TopoDS_Shape& FF = LLA.First(); | |
1721 | Standard_Real CurOffset = myOffset; | |
1722 | if ( myFaceOffset.IsBound(FF)) | |
1723 | CurOffset = myFaceOffset(FF); | |
1724 | ||
1725 | BRepOffset_Offset OF(V,LOE,CurOffset); | |
1726 | MapSF.Bind(V,OF); | |
7fd59977 | 1727 | } |
1728 | //-------------------------------------------------------------- | |
0d969553 | 1729 | // Particular processing if V is at least a free border. |
7fd59977 | 1730 | //------------------------------------------------------------- |
1731 | TopTools_ListOfShape LBF; | |
eff3eff9 | 1732 | myAnalyse.Edges(V,ChFiDS_FreeBound,LBF); |
9b7f3f83 | 1733 | if (!LBF.IsEmpty()) { |
1734 | Standard_Boolean First = Standard_True; | |
1735 | for (it.Initialize(LE) ; it.More(); it.Next()) { | |
1736 | if (First) { | |
1737 | myInitOffsetEdge.SetRoot(V); // skv: supporting history. | |
1738 | myInitOffsetEdge.Bind(V,MapSF(it.Value()).Generated(V)); | |
1739 | First = Standard_False; | |
1740 | } | |
1741 | else { | |
1742 | myInitOffsetEdge.Add(V,MapSF(it.Value()).Generated(V)); | |
1743 | } | |
1744 | } | |
7fd59977 | 1745 | } |
1746 | } | |
1747 | } | |
1748 | ||
1749 | //------------------------------------------------------------ | |
0d969553 Y |
1750 | // Extension of parallel faces to the context. |
1751 | // Extended faces are ordered in DS and removed from MapSF. | |
7fd59977 | 1752 | //------------------------------------------------------------ |
1753 | if (!myFaces.IsEmpty()) ToContext (MapSF); | |
1754 | ||
1755 | //------------------------------------------------------ | |
1756 | // MAJ SD. | |
1757 | //------------------------------------------------------ | |
eff3eff9 | 1758 | ChFiDS_TypeOfConcavity RT = ChFiDS_Concave; |
1759 | if (myOffset < 0.) RT = ChFiDS_Convex; | |
7fd59977 | 1760 | BRepOffset_DataMapIteratorOfDataMapOfShapeOffset It(MapSF); |
7fd59977 | 1761 | for ( ; It.More(); It.Next()) { |
1762 | const TopoDS_Shape& SI = It.Key(); | |
1763 | const BRepOffset_Offset& SF = It.Value(); | |
1764 | if (SF.Status() == BRepOffset_Reversed || | |
9b7f3f83 | 1765 | SF.Status() == BRepOffset_Degenerated ) { |
7fd59977 | 1766 | //------------------------------------------------ |
0d969553 | 1767 | // Degenerated or returned faces are not stored. |
7fd59977 | 1768 | //------------------------------------------------ |
1769 | continue; | |
9b7f3f83 | 1770 | } |
7fd59977 | 1771 | |
1772 | const TopoDS_Face& OF = It.Value().Face(); | |
1773 | myInitOffsetFace.Bind (SI,OF); | |
1774 | myInitOffsetFace.SetRoot (SI); // Initial<-> Offset | |
0d969553 | 1775 | myImageOffset.SetRoot (OF); // FaceOffset root of images |
7fd59977 | 1776 | |
1777 | if (SI.ShapeType() == TopAbs_FACE) { | |
1778 | for (Exp.Init(SI.Oriented(TopAbs_FORWARD),TopAbs_EDGE); | |
9b7f3f83 | 1779 | Exp.More(); Exp.Next()) { |
1780 | //-------------------------------------------------------------------- | |
1781 | // To each face are associatedthe edges that restrict that | |
1782 | // The edges that do not generate tubes or are not tangent | |
1783 | // to two faces are removed. | |
1784 | //-------------------------------------------------------------------- | |
1785 | const TopoDS_Edge& E = TopoDS::Edge(Exp.Current()); | |
1786 | const BRepOffset_ListOfInterval& L = myAnalyse.Type(E); | |
1787 | if (!L.IsEmpty() && L.First().Type() != RT) { | |
1788 | TopAbs_Orientation OO = E.Orientation(); | |
1789 | TopoDS_Shape aLocalShape = It.Value().Generated(E); | |
1790 | TopoDS_Edge OE = TopoDS::Edge(aLocalShape); | |
1791 | // TopoDS_Edge OE = TopoDS::Edge(It.Value().Generated(E)); | |
1792 | myAsDes->Add (OF,OE.Oriented(OO)); | |
1793 | } | |
7fd59977 | 1794 | } |
1795 | } | |
1796 | else { | |
1797 | for (Exp.Init(OF.Oriented(TopAbs_FORWARD),TopAbs_EDGE); | |
9b7f3f83 | 1798 | Exp.More(); Exp.Next()) { |
1799 | myAsDes->Add (OF,Exp.Current()); | |
7fd59977 | 1800 | } |
1801 | } | |
1802 | } | |
1803 | ||
0797d9d3 | 1804 | #ifdef OCCT_DEBUG |
7fd59977 | 1805 | if ( ChronBuild) Clock.Show(); |
1806 | #endif | |
1807 | } | |
1808 | ||
1809 | ||
1810 | ||
1811 | //======================================================================= | |
1812 | //function : SelfInter | |
1813 | //purpose : | |
1814 | //======================================================================= | |
1815 | ||
35e08fe8 | 1816 | void BRepOffset_MakeOffset::SelfInter(TopTools_MapOfShape& /*Modif*/) |
7fd59977 | 1817 | { |
0797d9d3 | 1818 | #ifdef OCCT_DEBUG |
7fd59977 | 1819 | if ( ChronBuild) { |
04232180 | 1820 | std::cout << " AUTODEBOUCLAGE:" << std::endl; |
7fd59977 | 1821 | Clock.Reset(); |
1822 | Clock.Start(); | |
1823 | } | |
1824 | #endif | |
1825 | ||
9775fa61 | 1826 | throw Standard_NotImplemented(); |
7fd59977 | 1827 | } |
1828 | ||
1829 | ||
1830 | //======================================================================= | |
1831 | //function : ToContext | |
1832 | //purpose : | |
1833 | //======================================================================= | |
1834 | ||
1835 | void BRepOffset_MakeOffset::ToContext (BRepOffset_DataMapOfShapeOffset& MapSF) | |
1836 | { | |
1837 | TopTools_DataMapOfShapeShape Created; | |
1838 | TopTools_DataMapOfShapeShape MEF; | |
975ec82a | 1839 | TopTools_IndexedMapOfShape FacesToBuild; |
7fd59977 | 1840 | TopTools_ListIteratorOfListOfShape itl; |
1841 | TopExp_Explorer exp; | |
1842 | ||
1843 | // TopAbs_State Side = TopAbs_IN; | |
1844 | // if (myOffset < 0.) Side = TopAbs_OUT; | |
1845 | ||
1846 | TopAbs_State Side = TopAbs_OUT; | |
975ec82a J |
1847 | |
1848 | /* | |
1849 | Standard_Integer i; | |
1850 | for (i = 1; i <= myFaces.Extent(); i++) { | |
1851 | const TopoDS_Face& CF = TopoDS::Face(myFaces(i)); | |
7fd59977 | 1852 | for (exp.Init(CF.Oriented(TopAbs_FORWARD),TopAbs_EDGE); |
9b7f3f83 | 1853 | exp.More(); exp.Next()) { |
7fd59977 | 1854 | const TopoDS_Edge& E = TopoDS::Edge(exp.Current()); |
1855 | if (!myAnalyse.HasAncestor(E)) { | |
9b7f3f83 | 1856 | //---------------------------------------------------------------- |
1857 | // The edges of context faces that are not in the initial shape | |
1858 | // can appear in the result. | |
1859 | //---------------------------------------------------------------- | |
1860 | //myAsDes->Add(CF,E); | |
7fd59977 | 1861 | } |
1862 | } | |
1863 | } | |
975ec82a J |
1864 | */ |
1865 | ||
1866 | //-------------------------------------------------------- | |
0d969553 | 1867 | // Determine the edges and faces reconstructed by |
7fd59977 | 1868 | // intersection. |
1869 | //--------------------------------------------------------- | |
975ec82a J |
1870 | Standard_Integer j; |
1871 | for (j = 1; j <= myFaces.Extent(); j++) { | |
1872 | const TopoDS_Face& CF = TopoDS::Face(myFaces(j)); | |
7fd59977 | 1873 | for (exp.Init(CF.Oriented(TopAbs_FORWARD),TopAbs_EDGE); |
9b7f3f83 | 1874 | exp.More(); exp.Next()) { |
7fd59977 | 1875 | const TopoDS_Edge& E = TopoDS::Edge(exp.Current()); |
1876 | if (myAnalyse.HasAncestor(E)) { | |
9b7f3f83 | 1877 | const TopTools_ListOfShape& LEA = myAnalyse.Ancestors(E); |
1878 | for (itl.Initialize(LEA); itl.More(); itl.Next()) { | |
1879 | const BRepOffset_Offset& OF = MapSF(itl.Value()); | |
1880 | FacesToBuild.Add(itl.Value()); | |
1881 | MEF.Bind(OF.Generated(E),CF); | |
1882 | } | |
1883 | TopoDS_Vertex V[2]; | |
1884 | TopExp::Vertices(E,V[0],V[1]); | |
1885 | for (Standard_Integer i = 0; i < 2; i++) { | |
1886 | const TopTools_ListOfShape& LVA = myAnalyse.Ancestors(V[i]); | |
1887 | for ( itl.Initialize(LVA); itl.More(); itl.Next()) { | |
1888 | const TopoDS_Edge& EV = TopoDS::Edge(itl.Value()); | |
1889 | if (MapSF.IsBound(EV)) { | |
1890 | const BRepOffset_Offset& OF = MapSF(EV); | |
1891 | FacesToBuild.Add(EV); | |
1892 | MEF.Bind(OF.Generated(V[i]),CF); | |
1893 | } | |
1894 | } | |
1895 | } | |
7fd59977 | 1896 | } |
1897 | } | |
1898 | } | |
1899 | //--------------------------- | |
0d969553 | 1900 | // Reconstruction of faces. |
7fd59977 | 1901 | //--------------------------- |
1902 | TopoDS_Face F,NF; | |
eff3eff9 | 1903 | ChFiDS_TypeOfConcavity RT = ChFiDS_Concave; |
1904 | if (myOffset < 0.) RT = ChFiDS_Convex; | |
7fd59977 | 1905 | TopoDS_Shape OE,NE; |
1906 | TopAbs_Orientation Or; | |
1907 | ||
975ec82a J |
1908 | for (j = 1; j <= FacesToBuild.Extent(); j++) { |
1909 | const TopoDS_Shape& S = FacesToBuild(j); | |
7fd59977 | 1910 | BRepOffset_Offset BOF; |
1911 | BOF = MapSF(S); | |
1912 | F = TopoDS::Face(BOF.Face()); | |
1913 | BRepOffset_Tool::ExtentFace(F,Created,MEF,Side,myTol,NF); | |
1914 | MapSF.UnBind(S); | |
1915 | //-------------- | |
1916 | // MAJ SD. | |
1917 | //-------------- | |
1918 | myInitOffsetFace.Bind (S,NF); | |
1919 | myInitOffsetFace.SetRoot (S); // Initial<-> Offset | |
1920 | myImageOffset.SetRoot (NF); | |
1921 | ||
1922 | if (S.ShapeType() == TopAbs_FACE) { | |
1923 | for (exp.Init(S.Oriented(TopAbs_FORWARD),TopAbs_EDGE); | |
9b7f3f83 | 1924 | exp.More(); exp.Next()) { |
1925 | ||
1926 | const TopoDS_Edge& E = TopoDS::Edge(exp.Current()); | |
1927 | const BRepOffset_ListOfInterval& L = myAnalyse.Type(E); | |
1928 | OE = BOF.Generated(E); | |
1929 | Or = E.Orientation(); | |
1930 | OE.Orientation(Or); | |
1931 | if (!L.IsEmpty() && L.First().Type() != RT) { | |
1932 | if (Created.IsBound(OE)) { | |
1933 | NE = Created(OE); | |
1934 | if (NE.Orientation() == TopAbs_REVERSED) | |
1935 | NE.Orientation(TopAbs::Reverse(Or)); | |
1936 | else | |
1937 | NE.Orientation(Or); | |
1938 | myAsDes->Add(NF,NE); | |
1939 | } | |
1940 | else { | |
1941 | myAsDes->Add(NF,OE); | |
1942 | } | |
1943 | } | |
7fd59977 | 1944 | } |
1945 | } | |
1946 | else { | |
1947 | //------------------ | |
0d969553 | 1948 | // Tube |
7fd59977 | 1949 | //--------------------- |
1950 | for (exp.Init(NF.Oriented(TopAbs_FORWARD),TopAbs_EDGE); | |
9b7f3f83 | 1951 | exp.More(); exp.Next()) { |
1952 | myAsDes->Add (NF,exp.Current()); | |
7fd59977 | 1953 | } |
1954 | } | |
1955 | MapSF.UnBind(S); | |
1956 | } | |
1957 | ||
0d969553 Y |
1958 | //------------------ |
1959 | // MAJ free borders | |
1960 | //------------------ | |
7fd59977 | 1961 | TopTools_DataMapIteratorOfDataMapOfShapeShape itc; |
1962 | for (itc.Initialize(Created); itc.More(); itc.Next()) { | |
1963 | OE = itc.Key(); | |
1964 | NE = itc.Value(); | |
1965 | if (myInitOffsetEdge.IsImage(OE)) { | |
1966 | TopoDS_Shape E = myInitOffsetEdge.ImageFrom (OE); | |
1967 | Or = myInitOffsetEdge.Image(E).First().Orientation(); | |
1968 | if (NE.Orientation() == TopAbs_REVERSED) | |
9b7f3f83 | 1969 | NE.Orientation(TopAbs::Reverse(Or)); |
7fd59977 | 1970 | else |
9b7f3f83 | 1971 | NE.Orientation(Or); |
7fd59977 | 1972 | myInitOffsetEdge.Remove(OE); |
1973 | myInitOffsetEdge.Bind(E,NE); | |
1974 | } | |
1975 | } | |
1976 | } | |
1977 | ||
1978 | ||
1979 | //======================================================================= | |
1980 | //function : UpdateFaceOffset | |
1981 | //purpose : | |
1982 | //======================================================================= | |
1983 | ||
1984 | void BRepOffset_MakeOffset::UpdateFaceOffset() | |
1985 | { | |
1986 | TopTools_MapOfShape M; | |
1987 | TopTools_DataMapOfShapeReal CopiedMap; | |
1988 | CopiedMap.Assign(myFaceOffset); | |
1989 | TopTools_DataMapIteratorOfDataMapOfShapeReal it(CopiedMap); | |
1990 | ||
eff3eff9 | 1991 | ChFiDS_TypeOfConcavity RT = ChFiDS_Convex; |
1992 | if (myOffset < 0.) RT = ChFiDS_Concave; | |
7fd59977 | 1993 | |
1994 | for ( ; it.More(); it.Next()) { | |
1995 | const TopoDS_Face& F = TopoDS::Face(it.Key()); | |
1996 | Standard_Real CurOffset = CopiedMap(F); | |
1997 | if ( !M.Add(F)) continue; | |
1998 | TopoDS_Compound Co; | |
1999 | BRep_Builder Build; | |
2000 | Build.MakeCompound(Co); | |
2001 | TopTools_MapOfShape Dummy; | |
2002 | Build.Add(Co,F); | |
2003 | if (myJoin == GeomAbs_Arc) | |
eff3eff9 | 2004 | myAnalyse.AddFaces(F,Co,Dummy,ChFiDS_Tangential,RT); |
7fd59977 | 2005 | else |
eff3eff9 | 2006 | myAnalyse.AddFaces(F,Co,Dummy,ChFiDS_Tangential); |
7fd59977 | 2007 | |
2008 | TopExp_Explorer exp(Co,TopAbs_FACE); | |
2009 | for (; exp.More(); exp.Next()) { | |
2010 | const TopoDS_Face& FF = TopoDS::Face(exp.Current()); | |
2011 | if ( !M.Add(FF)) continue; | |
2012 | if ( myFaceOffset.IsBound(FF)) | |
9b7f3f83 | 2013 | myFaceOffset.UnBind(FF); |
7fd59977 | 2014 | myFaceOffset.Bind(FF,CurOffset); |
2015 | } | |
2016 | } | |
2017 | } | |
2018 | ||
2019 | //======================================================================= | |
2020 | //function : CorrectConicalFaces | |
2021 | //purpose : | |
2022 | //======================================================================= | |
2023 | ||
2024 | void BRepOffset_MakeOffset::CorrectConicalFaces() | |
2025 | { | |
db2f1498 | 2026 | if(myOffsetShape.IsNull()) |
2027 | { | |
2028 | return; | |
2029 | } | |
2030 | // | |
7fd59977 | 2031 | TopTools_SequenceOfShape Cones; |
2032 | TopTools_SequenceOfShape Circs; | |
2033 | TopTools_SequenceOfShape Seams; | |
2034 | Standard_Real TolApex = 1.e-5; | |
2035 | ||
2036 | Standard_Integer i; | |
2037 | ||
2038 | TopTools_DataMapOfShapeListOfShape FacesOfCone; | |
2039 | //TopTools_DataMapOfShapeShape DegEdges; | |
2040 | TopExp_Explorer Explo( myOffsetShape, TopAbs_FACE ); | |
2041 | if (myJoin == GeomAbs_Arc) | |
903f7584 | 2042 | { |
2043 | for (; Explo.More(); Explo.Next()) | |
7fd59977 | 2044 | { |
903f7584 | 2045 | TopoDS_Face aFace = TopoDS::Face( Explo.Current() ); |
2046 | Handle(Geom_Surface) aSurf = BRep_Tool::Surface( aFace ); | |
2047 | //if (aSurf->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface)) | |
2048 | //aSurf = (Handle(Geom_OffsetSurface)::DownCast(aSurf))->BasisSurface(); //??? | |
2049 | ||
2050 | TopTools_IndexedMapOfShape Emap; | |
2051 | TopExp::MapShapes( aFace, TopAbs_EDGE, Emap ); | |
2052 | for (i = 1; i <= Emap.Extent(); i++) | |
2053 | { | |
2054 | TopoDS_Edge anEdge = TopoDS::Edge( Emap(i) ); | |
2055 | //Standard_Real f, l; | |
2056 | //Handle(Geom_Curve) theCurve = BRep_Tool::Curve( anEdge, f, l ); | |
2057 | //Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &anEdge.TShape()); | |
2058 | if (BRep_Tool::Degenerated(anEdge)) | |
2059 | { | |
2060 | //Check if anEdge is a really degenerated edge or not | |
2061 | BRepAdaptor_Curve BACurve(anEdge, aFace); | |
2062 | gp_Pnt Pfirst, Plast, Pmid; | |
2063 | Pfirst = BACurve.Value(BACurve.FirstParameter()); | |
2064 | Plast = BACurve.Value(BACurve.LastParameter()); | |
2065 | Pmid = BACurve.Value((BACurve.FirstParameter()+BACurve.LastParameter())/2.); | |
2066 | if (Pfirst.Distance(Plast) <= TolApex && | |
2067 | Pfirst.Distance(Pmid) <= TolApex) | |
2068 | continue; | |
2069 | //Cones.Append( aFace ); | |
2070 | //Circs.Append( anEdge ); | |
2071 | //TopoDS_Vertex Vdeg = TopExp::FirstVertex( anEdge ); | |
2072 | TopoDS_Edge OrEdge = | |
2073 | TopoDS::Edge( myInitOffsetEdge.Root( anEdge) ); | |
2074 | TopoDS_Vertex VF = TopExp::FirstVertex( OrEdge ); | |
2075 | if ( FacesOfCone.IsBound(VF) ) | |
2076 | { | |
2077 | //add a face to the existing list | |
2078 | TopTools_ListOfShape& aFaces = FacesOfCone.ChangeFind(VF); | |
2079 | aFaces.Append (aFace); | |
2080 | //DegEdges.Bind(aFace, anEdge); | |
2081 | } | |
2082 | else | |
2083 | { | |
2084 | //the vertex is not in the map => create a new key and items | |
2085 | TopTools_ListOfShape aFaces; | |
2086 | aFaces.Append (aFace); | |
2087 | FacesOfCone.Bind(VF, aFaces); | |
2088 | //DegEdges.Bind(aFace, anEdge); | |
2089 | } | |
2090 | } | |
2091 | } //for (i = 1; i <= Emap.Extent(); i++) | |
2092 | } //for (; fexp.More(); fexp.Next()) | |
2093 | } //if (myJoin == GeomAbs_Arc) | |
7fd59977 | 2094 | |
2095 | TopTools_DataMapIteratorOfDataMapOfShapeListOfShape Cone(FacesOfCone); | |
2096 | BRep_Builder BB; | |
2097 | TopLoc_Location L; | |
db2f1498 | 2098 | Standard_Boolean IsModified = Standard_False; |
7fd59977 | 2099 | for (; Cone.More(); Cone.Next() ) { |
2100 | gp_Sphere theSphere; | |
2101 | Handle(Geom_SphericalSurface) aSphSurf; | |
2102 | TopoDS_Wire SphereWire; | |
2103 | BB.MakeWire(SphereWire); | |
2104 | TopoDS_Vertex anApex = TopoDS::Vertex(Cone.Key()); | |
2105 | const TopTools_ListOfShape& Faces = Cone.Value(); //FacesOfCone(anApex); | |
2106 | TopTools_ListIteratorOfListOfShape itFaces(Faces); | |
2107 | Standard_Boolean isFirstFace = Standard_True; | |
2108 | gp_Pnt FirstPoint; | |
2109 | TopoDS_Vertex theFirstVertex, CurFirstVertex; | |
2110 | for (; itFaces.More(); itFaces.Next()) | |
903f7584 | 2111 | { |
2112 | TopoDS_Face aFace = TopoDS::Face(itFaces.Value()); //TopoDS::Face(Faces.First()); | |
2113 | TopoDS_Edge DegEdge; // = TopoDS::Edge(DegEdges(aFace)); | |
2114 | for (Explo.Init(aFace, TopAbs_EDGE); Explo.More(); Explo.Next()) | |
7fd59977 | 2115 | { |
903f7584 | 2116 | DegEdge = TopoDS::Edge(Explo.Current()); |
2117 | if (BRep_Tool::Degenerated(DegEdge)) | |
2118 | { | |
2119 | TopoDS_Edge OrEdge = TopoDS::Edge( myInitOffsetEdge.Root( DegEdge) ); | |
2120 | TopoDS_Vertex VF = TopExp::FirstVertex( OrEdge ); | |
2121 | if (VF.IsSame(anApex)) | |
2122 | break; | |
2123 | } | |
2124 | } | |
2125 | TopoDS_Shape aLocalDegShape = DegEdge.Oriented(TopAbs_FORWARD); | |
2126 | TopoDS_Edge CurEdge = TopoDS::Edge(aLocalDegShape); | |
2127 | BB.Degenerated(CurEdge, Standard_False); | |
2128 | BB.SameRange(CurEdge, Standard_False); | |
2129 | BB.SameParameter(CurEdge, Standard_False); | |
2130 | gp_Pnt fPnt, lPnt, mPnt; | |
2131 | GetEdgePoints(CurEdge, aFace, fPnt, mPnt, lPnt); | |
2132 | Standard_Real f, l; | |
2133 | BRep_Tool::Range(CurEdge, f, l); | |
2134 | if (isFirstFace) | |
2135 | { | |
2136 | gp_Vec aVec1(fPnt, mPnt); | |
2137 | gp_Vec aVec2(fPnt, lPnt); | |
2138 | gp_Vec aNorm = aVec1.Crossed(aVec2); | |
2139 | gp_Pnt theApex = BRep_Tool::Pnt(anApex); | |
2140 | gp_Vec ApexToFpnt(theApex, fPnt); | |
2141 | gp_Vec Ydir = aNorm ^ ApexToFpnt; | |
2142 | gp_Vec Xdir = Ydir ^ aNorm; | |
2143 | //Xdir.Rotate(gp_Ax1(theApex, aNorm), -f); | |
2144 | gp_Ax2 anAx2(theApex, gp_Dir(aNorm), gp_Dir(Xdir)); | |
2145 | theSphere.SetRadius(myOffset); | |
2146 | theSphere.SetPosition(gp_Ax3(anAx2) /*gp_Ax3(theApex, gp_Dir(aNorm))*/); | |
2147 | aSphSurf = new Geom_SphericalSurface(theSphere); | |
2148 | FirstPoint = fPnt; | |
2149 | theFirstVertex = BRepLib_MakeVertex(fPnt); | |
2150 | CurFirstVertex = theFirstVertex; | |
2151 | } | |
2152 | ||
2153 | TopoDS_Vertex v1, v2, FirstVert, EndVert; | |
2154 | TopExp::Vertices(CurEdge, v1, v2); | |
2155 | FirstVert = CurFirstVertex; | |
2156 | if (lPnt.Distance(FirstPoint) <= Precision::Confusion()) | |
2157 | EndVert = theFirstVertex; | |
2158 | else | |
2159 | EndVert = BRepLib_MakeVertex(lPnt); | |
2160 | CurEdge.Free( Standard_True ); | |
2161 | BB.Remove(CurEdge, v1); | |
2162 | BB.Remove(CurEdge, v2); | |
2163 | BB.Add(CurEdge, FirstVert.Oriented(TopAbs_FORWARD)); | |
2164 | BB.Add(CurEdge, EndVert.Oriented(TopAbs_REVERSED)); | |
2165 | //take the curve from sphere an put it to the edge | |
2166 | Standard_Real Uf, Vf, Ul, Vl; | |
2167 | ElSLib::Parameters( theSphere, fPnt, Uf, Vf ); | |
2168 | ElSLib::Parameters( theSphere, lPnt, Ul, Vl ); | |
2169 | if (Abs(Ul) <= Precision::Confusion()) | |
2170 | Ul = 2.*M_PI; | |
2171 | Handle(Geom_Curve) aCurv = aSphSurf->VIso(Vf); | |
2172 | /* | |
9b7f3f83 | 2173 | if (!isFirstFace) |
903f7584 | 2174 | { |
2175 | gp_Circ aCircle = (Handle(Geom_Circle)::DownCast(aCurv))->Circ(); | |
2176 | if (Abs(Uf - f) > Precision::Confusion()) | |
2177 | { | |
2178 | aCircle.Rotate(aCircle.Axis(), f - Uf); | |
2179 | aCurv = new Geom_Circle(aCircle); | |
2180 | } | |
2181 | } | |
2182 | */ | |
2183 | Handle(Geom_TrimmedCurve) aTrimCurv = new Geom_TrimmedCurve(aCurv, Uf, Ul); | |
2184 | BB.UpdateEdge(CurEdge, aTrimCurv, Precision::Confusion()); | |
2185 | BB.Range(CurEdge, Uf, Ul, Standard_True); | |
2186 | Handle(Geom2d_Line) theLin2d = new Geom2d_Line( gp_Pnt2d( 0., Vf ), gp::DX2d() ); | |
2187 | Handle(Geom2d_TrimmedCurve) theTrimLin2d = new Geom2d_TrimmedCurve(theLin2d, Uf, Ul); | |
2188 | BB.UpdateEdge(CurEdge, theTrimLin2d, aSphSurf, L, Precision::Confusion()); | |
2189 | BB.Range(CurEdge, aSphSurf, L, Uf, Ul); | |
2190 | BRepLib::SameParameter(CurEdge); | |
2191 | BB.Add(SphereWire, CurEdge); | |
2192 | //Modifying correspondent edges in aFace: substitute vertices common with CurEdge | |
2193 | BRepAdaptor_Curve2d BAc2d(CurEdge, aFace); | |
2194 | gp_Pnt2d fPnt2d, lPnt2d; | |
2195 | fPnt2d = BAc2d.Value(BAc2d.FirstParameter()); | |
2196 | lPnt2d = BAc2d.Value(BAc2d.LastParameter()); | |
2197 | TopTools_IndexedMapOfShape Emap; | |
2198 | TopExp::MapShapes(aFace, TopAbs_EDGE, Emap); | |
2199 | TopoDS_Edge EE [2]; | |
2200 | Standard_Integer j = 0, k; | |
2201 | for (k = 1; k <= Emap.Extent(); k++) | |
2202 | { | |
2203 | const TopoDS_Edge& anEdge = TopoDS::Edge(Emap(k)); | |
2204 | if (!BRep_Tool::Degenerated(anEdge)) | |
2205 | { | |
2206 | TopoDS_Vertex V1, V2; | |
2207 | TopExp::Vertices(anEdge, V1, V2); | |
2208 | if (V1.IsSame(v1) || V2.IsSame(v1)) | |
2209 | EE[j++] = anEdge; | |
2210 | } | |
2211 | } | |
2212 | for (k = 0; k < j; k++) | |
2213 | { | |
2214 | TopoDS_Shape aLocalShape = EE[k].Oriented(TopAbs_FORWARD); | |
2215 | TopoDS_Edge Eforward = TopoDS::Edge(aLocalShape); | |
2216 | Eforward.Free(Standard_True); | |
2217 | TopoDS_Vertex V1, V2; | |
2218 | TopExp::Vertices( Eforward, V1, V2 ); | |
2219 | BRepAdaptor_Curve2d EEc( Eforward, aFace ); | |
2220 | gp_Pnt2d p2d1, p2d2; | |
2221 | p2d1 = EEc.Value(EEc.FirstParameter()); | |
2222 | p2d2 = EEc.Value(EEc.LastParameter()); | |
2223 | if (V1.IsSame(v1)) | |
2224 | { | |
2225 | TopoDS_Vertex NewV = (p2d1.Distance(fPnt2d) <= Precision::Confusion())? | |
2226 | FirstVert : EndVert; | |
2227 | BB.Remove( Eforward, V1 ); | |
2228 | BB.Add( Eforward, NewV.Oriented(TopAbs_FORWARD) ); | |
2229 | } | |
2230 | else | |
2231 | { | |
2232 | TopoDS_Vertex NewV = (p2d2.Distance(fPnt2d) <= Precision::Confusion())? | |
2233 | FirstVert : EndVert; | |
2234 | BB.Remove( Eforward, V2 ); | |
2235 | BB.Add( Eforward, NewV.Oriented(TopAbs_REVERSED) ); | |
2236 | } | |
7fd59977 | 2237 | } |
903f7584 | 2238 | |
2239 | isFirstFace = Standard_False; | |
2240 | CurFirstVertex = EndVert; | |
2241 | } | |
7fd59977 | 2242 | //Building new spherical face |
2243 | Standard_Real Ufirst = RealLast(), Ulast = RealFirst(); | |
2244 | gp_Pnt2d p2d1, p2d2; | |
2245 | TopTools_ListOfShape EdgesOfWire; | |
2246 | TopoDS_Iterator itw(SphereWire); | |
2247 | for (; itw.More(); itw.Next()) | |
903f7584 | 2248 | { |
2249 | const TopoDS_Edge& anEdge = TopoDS::Edge(itw.Value()); | |
2250 | EdgesOfWire.Append(anEdge); | |
2251 | Standard_Real f, l; | |
2252 | Handle(Geom2d_Curve) aC2d = BRep_Tool::CurveOnSurface(anEdge, aSphSurf, L, f, l); | |
2253 | p2d1 = aC2d->Value(f); | |
2254 | p2d2 = aC2d->Value(l); | |
2255 | if (p2d1.X() < Ufirst) | |
2256 | Ufirst = p2d1.X(); | |
2257 | if (p2d1.X() > Ulast) | |
2258 | Ulast = p2d1.X(); | |
2259 | if (p2d2.X() < Ufirst) | |
2260 | Ufirst = p2d2.X(); | |
2261 | if (p2d2.X() > Ulast) | |
2262 | Ulast = p2d2.X(); | |
2263 | } | |
7fd59977 | 2264 | TopTools_ListOfShape NewEdges; |
2265 | TopoDS_Edge FirstEdge; | |
2266 | TopTools_ListIteratorOfListOfShape itl(EdgesOfWire); | |
2267 | for (; itl.More(); itl.Next()) | |
903f7584 | 2268 | { |
2269 | FirstEdge = TopoDS::Edge(itl.Value()); | |
2270 | Standard_Real f, l; | |
2271 | Handle(Geom2d_Curve) aC2d = BRep_Tool::CurveOnSurface(FirstEdge, aSphSurf, L, f, l); | |
2272 | p2d1 = aC2d->Value(f); | |
2273 | p2d2 = aC2d->Value(l); | |
2274 | if (Abs(p2d1.X() - Ufirst) <= Precision::Confusion()) | |
7fd59977 | 2275 | { |
903f7584 | 2276 | EdgesOfWire.Remove(itl); |
2277 | break; | |
7fd59977 | 2278 | } |
903f7584 | 2279 | } |
cc9f4591 | 2280 | NewEdges.Append(FirstEdge.Oriented(TopAbs_FORWARD)); |
7fd59977 | 2281 | TopoDS_Vertex Vf1, CurVertex; |
2282 | TopExp::Vertices(FirstEdge, Vf1, CurVertex); | |
2283 | itl.Initialize(EdgesOfWire); | |
2284 | while (itl.More()) | |
903f7584 | 2285 | { |
2286 | const TopoDS_Edge& anEdge = TopoDS::Edge(itl.Value()); | |
2287 | TopoDS_Vertex V1, V2; | |
2288 | TopExp::Vertices(anEdge, V1, V2); | |
2289 | if (V1.IsSame(CurVertex) || V2.IsSame(CurVertex)) | |
7fd59977 | 2290 | { |
cc9f4591 | 2291 | NewEdges.Append(anEdge.Oriented(TopAbs_FORWARD)); |
903f7584 | 2292 | CurVertex = (V1.IsSame(CurVertex))? V2 : V1; |
2293 | EdgesOfWire.Remove(itl); | |
7fd59977 | 2294 | } |
903f7584 | 2295 | else |
2296 | itl.Next(); | |
2297 | } | |
2298 | ||
7fd59977 | 2299 | Standard_Real Vfirst, Vlast; |
2300 | if (p2d1.Y() > 0.) | |
903f7584 | 2301 | { |
2302 | Vfirst = p2d1.Y(); Vlast = M_PI/2.; | |
2303 | } | |
7fd59977 | 2304 | else |
903f7584 | 2305 | { |
2306 | Vfirst = -M_PI/2.; Vlast = p2d1.Y(); | |
2307 | } | |
1c72dff6 | 2308 | TopoDS_Face NewSphericalFace = BRepLib_MakeFace(aSphSurf, Ufirst, Ulast, Vfirst, Vlast, Precision::Confusion()); |
cc9f4591 | 2309 | TopoDS_Edge OldEdge, DegEdge; |
2310 | for (Explo.Init(NewSphericalFace, TopAbs_EDGE); Explo.More(); Explo.Next()) | |
2311 | { | |
2312 | DegEdge = TopoDS::Edge(Explo.Current()); | |
2313 | if (BRep_Tool::Degenerated(DegEdge)) | |
2314 | break; | |
2315 | } | |
2316 | TopoDS_Vertex DegVertex = TopExp::FirstVertex(DegEdge); | |
7fd59977 | 2317 | for (Explo.Init(NewSphericalFace, TopAbs_EDGE); Explo.More(); Explo.Next()) |
903f7584 | 2318 | { |
2319 | OldEdge = TopoDS::Edge(Explo.Current()); | |
cc9f4591 | 2320 | TopoDS_Vertex V1, V2; |
2321 | TopExp::Vertices(OldEdge, V1, V2); | |
2322 | if (!V1.IsSame(DegVertex) && !V2.IsSame(DegVertex)) | |
2323 | break; | |
903f7584 | 2324 | } |
7fd59977 | 2325 | TopoDS_Vertex V1, V2; |
2326 | TopExp::Vertices(OldEdge, V1, V2); | |
2327 | TopTools_ListOfShape LV1, LV2; | |
cc9f4591 | 2328 | LV1.Append(Vf1.Oriented(TopAbs_FORWARD)); |
2329 | LV2.Append(CurVertex.Oriented(TopAbs_FORWARD)); | |
7fd59977 | 2330 | BRepTools_Substitution theSubstitutor; |
cc9f4591 | 2331 | theSubstitutor.Substitute(V1.Oriented(TopAbs_FORWARD), LV1); |
7fd59977 | 2332 | if (!V1.IsSame(V2)) |
cc9f4591 | 2333 | theSubstitutor.Substitute(V2.Oriented(TopAbs_FORWARD), LV2); |
2334 | theSubstitutor.Substitute(OldEdge.Oriented(TopAbs_FORWARD), NewEdges); | |
7fd59977 | 2335 | theSubstitutor.Build(NewSphericalFace); |
2336 | if (theSubstitutor.IsCopied(NewSphericalFace)) | |
903f7584 | 2337 | { |
2338 | const TopTools_ListOfShape& listSh = theSubstitutor.Copy(NewSphericalFace); | |
2339 | NewSphericalFace = TopoDS::Face(listSh.First()); | |
2340 | } | |
2341 | ||
7fd59977 | 2342 | //Adding NewSphericalFace to the shell |
2343 | Explo.Init( myOffsetShape, TopAbs_SHELL ); | |
2344 | TopoDS_Shape theShell = Explo.Current(); | |
2345 | theShell.Free( Standard_True ); | |
2346 | BB.Add( theShell, NewSphericalFace ); | |
db2f1498 | 2347 | IsModified = Standard_True; |
2348 | if(!theShell.Closed()) | |
2349 | { | |
2350 | if(BRep_Tool::IsClosed(theShell)) | |
2351 | { | |
2352 | theShell.Closed(Standard_True); | |
2353 | } | |
2354 | } | |
7fd59977 | 2355 | } |
db2f1498 | 2356 | // |
2357 | if(!IsModified) | |
2358 | { | |
2359 | return; | |
2360 | } | |
2361 | // | |
903f7584 | 2362 | if (myShape.ShapeType() == TopAbs_SOLID || myThickening) |
2363 | { | |
db2f1498 | 2364 | //Explo.Init( myOffsetShape, TopAbs_SHELL ); |
2365 | ||
2366 | //if (Explo.More()) { | |
2367 | // TopoDS_Shape theShell = Explo.Current(); | |
2368 | // theShell.Closed( Standard_True ); | |
2369 | //} | |
2370 | ||
903f7584 | 2371 | Standard_Integer NbShell = 0; |
2372 | TopoDS_Compound NC; | |
2373 | TopoDS_Shape S1; | |
2374 | BB.MakeCompound (NC); | |
db2f1498 | 2375 | |
2376 | TopoDS_Solid Sol; | |
2377 | BB.MakeSolid(Sol); | |
2378 | Sol.Closed(Standard_True); | |
903f7584 | 2379 | for (Explo.Init(myOffsetShape,TopAbs_SHELL); Explo.More(); Explo.Next()) { |
db2f1498 | 2380 | TopoDS_Shell Sh = TopoDS::Shell(Explo.Current()); |
2381 | //if (myThickening && myOffset > 0.) | |
2382 | // Sh.Reverse(); | |
903f7584 | 2383 | NbShell++; |
2384 | if (Sh.Closed()) { | |
db2f1498 | 2385 | BB.Add(Sol,Sh); |
903f7584 | 2386 | } |
2387 | else { | |
2388 | BB.Add (NC,Sh); | |
db2f1498 | 2389 | if(NbShell == 1) |
2390 | { | |
2391 | S1 = Sh; | |
2392 | } | |
903f7584 | 2393 | } |
7fd59977 | 2394 | } |
b2d1851c | 2395 | Standard_Integer nbs = Sol.NbChildren(); |
2396 | Standard_Boolean SolIsNull = (nbs == 0); | |
db2f1498 | 2397 | //Checking solid |
b2d1851c | 2398 | if (nbs > 1) |
db2f1498 | 2399 | { |
b2d1851c | 2400 | BRepCheck_Analyzer aCheck (Sol, Standard_False); |
2401 | if (!aCheck.IsValid ()) | |
db2f1498 | 2402 | { |
b2d1851c | 2403 | TopTools_ListOfShape aSolList; |
2404 | CorrectSolid (Sol, aSolList); | |
2405 | if (!aSolList.IsEmpty ()) | |
db2f1498 | 2406 | { |
b2d1851c | 2407 | BB.Add (NC, Sol); |
2408 | TopTools_ListIteratorOfListOfShape aSLIt (aSolList); | |
2409 | for (; aSLIt.More (); aSLIt.Next ()) | |
db2f1498 | 2410 | { |
b2d1851c | 2411 | BB.Add (NC, aSLIt.Value ()); |
db2f1498 | 2412 | } |
b2d1851c | 2413 | SolIsNull = Standard_True; |
db2f1498 | 2414 | } |
2415 | } | |
2416 | } | |
2417 | // | |
b2d1851c | 2418 | Standard_Boolean NCIsNull = (NC.NbChildren() == 0); |
db2f1498 | 2419 | if((!SolIsNull) && (!NCIsNull)) |
2420 | { | |
2421 | BB.Add(NC, Sol); | |
2422 | myOffsetShape = NC; | |
2423 | } | |
2424 | else if(SolIsNull && (!NCIsNull)) | |
2425 | { | |
2426 | if (NbShell == 1) | |
2427 | { | |
2428 | myOffsetShape = S1; | |
2429 | } | |
2430 | else | |
2431 | { | |
2432 | myOffsetShape = NC; | |
2433 | } | |
2434 | } | |
2435 | else if((!SolIsNull) && NCIsNull) | |
2436 | { | |
2437 | myOffsetShape = Sol; | |
2438 | } | |
2439 | else | |
2440 | { | |
2441 | myOffsetShape = NC; | |
2442 | } | |
7fd59977 | 2443 | } |
7fd59977 | 2444 | } |
2445 | ||
2446 | ||
2447 | //======================================================================= | |
2448 | //function : Intersection3D | |
2449 | //purpose : | |
2450 | //======================================================================= | |
2451 | ||
2452 | void BRepOffset_MakeOffset::Intersection3D(BRepOffset_Inter3d& Inter) | |
2453 | { | |
0797d9d3 | 2454 | #ifdef OCCT_DEBUG |
7fd59977 | 2455 | if (ChronBuild) { |
04232180 | 2456 | std::cout << " INTERSECTION 3D:" << std::endl; |
7fd59977 | 2457 | Clock.Reset(); |
2458 | Clock.Start(); | |
2459 | } | |
2460 | #endif | |
e7384fd4 | 2461 | |
2462 | // In the Complete Intersection mode, implemented currently for planar | |
2463 | // solids only, there is no need to intersect the faces here. | |
2464 | // This intersection will be performed in the method BuildShellsCompleteInter | |
2465 | // where the special treatment is applied to produced faces. | |
2466 | // | |
2467 | // Make sure to match the parameters in which the method | |
2468 | // BuildShellsCompleteInter is called. | |
2469 | if (myInter && (myJoin == GeomAbs_Intersection) && myIsPlanar && | |
2470 | !myThickening && myFaces.IsEmpty() && IsSolid(myShape)) | |
2471 | return; | |
2472 | ||
2473 | ||
0d969553 | 2474 | TopTools_ListOfShape OffsetFaces; // list of faces // created. |
7fd59977 | 2475 | MakeList (OffsetFaces,myInitOffsetFace,myFaces); |
2476 | ||
2477 | if (!myFaces.IsEmpty()) { | |
0d969553 Y |
2478 | Standard_Boolean InSide = (myOffset < 0.); // Temporary |
2479 | // it is necessary to calculate Inside taking account of the concavity or convexity of edges | |
2480 | // between the cap and the part. | |
7fd59977 | 2481 | |
2482 | if (myJoin == GeomAbs_Arc) | |
2483 | Inter.ContextIntByArc (myFaces,InSide,myAnalyse,myInitOffsetFace,myInitOffsetEdge); | |
2484 | } | |
2485 | if (myInter) { | |
2486 | //------------- | |
0d969553 | 2487 | //Complete. |
7fd59977 | 2488 | //------------- |
2489 | Inter.CompletInt (OffsetFaces,myInitOffsetFace); | |
975ec82a | 2490 | TopTools_IndexedMapOfShape& NewEdges = Inter.NewEdges(); |
7fd59977 | 2491 | if (myJoin == GeomAbs_Intersection) { |
99c9a820 | 2492 | BRepOffset_Tool::CorrectOrientation (myFaceComp,NewEdges,myAsDes,myInitOffsetFace,myOffset); |
7fd59977 | 2493 | } |
2494 | } | |
2495 | else { | |
2496 | //-------------------------------- | |
0d969553 | 2497 | // Only between neighbor faces. |
7fd59977 | 2498 | //-------------------------------- |
99c9a820 | 2499 | Inter.ConnexIntByArc(OffsetFaces,myFaceComp,myAnalyse,myInitOffsetFace); |
7fd59977 | 2500 | } |
0797d9d3 | 2501 | #ifdef OCCT_DEBUG |
7fd59977 | 2502 | if ( ChronBuild) Clock.Show(); |
2503 | #endif | |
2504 | } | |
2505 | ||
2506 | //======================================================================= | |
2507 | //function : Intersection2D | |
2508 | //purpose : | |
2509 | //======================================================================= | |
2510 | ||
975ec82a | 2511 | void BRepOffset_MakeOffset::Intersection2D(const TopTools_IndexedMapOfShape& Modif, |
9b7f3f83 | 2512 | const TopTools_IndexedMapOfShape& NewEdges) |
7fd59977 | 2513 | { |
0797d9d3 | 2514 | #ifdef OCCT_DEBUG |
7fd59977 | 2515 | if (ChronBuild) { |
04232180 | 2516 | std::cout << " INTERSECTION 2D:" << std::endl; |
7fd59977 | 2517 | Clock.Reset(); |
2518 | Clock.Start(); | |
2519 | } | |
2520 | #endif | |
0d969553 Y |
2521 | //-------------------------------------------------------- |
2522 | // calculate intersections2d on faces concerned by | |
7fd59977 | 2523 | // intersection3d |
975ec82a J |
2524 | //--------------------------------------------------------- |
2525 | //TopTools_MapIteratorOfMapOfShape it(Modif); | |
7fd59977 | 2526 | //----------------------------------------------- |
0d969553 | 2527 | // Intersection of edges 2 by 2. |
7fd59977 | 2528 | //----------------------------------------------- |
b0fbc579 | 2529 | TopTools_IndexedDataMapOfShapeListOfShape aDMVV; |
975ec82a J |
2530 | Standard_Integer i; |
2531 | for (i = 1; i <= Modif.Extent(); i++) { | |
2532 | const TopoDS_Face& F = TopoDS::Face(Modif(i)); | |
8948e18d | 2533 | BRepOffset_Inter2d::Compute(myAsDes, F, NewEdges, myTol, myEdgeIntEdges, aDMVV); |
7fd59977 | 2534 | } |
b0fbc579 | 2535 | // |
8948e18d | 2536 | BRepOffset_Inter2d::FuseVertices(aDMVV, myAsDes, myImageVV); |
b0fbc579 | 2537 | // |
0797d9d3 | 2538 | #ifdef OCCT_DEBUG |
7fd59977 | 2539 | if (AffichInt2d) { |
2540 | DEBVerticesControl (NewEdges,myAsDes); | |
2541 | } | |
2542 | if ( ChronBuild) Clock.Show(); | |
2543 | #endif | |
2544 | } | |
2545 | ||
2546 | ||
2547 | //======================================================================= | |
2548 | //function : MakeLoops | |
2549 | //purpose : | |
2550 | //======================================================================= | |
2551 | ||
975ec82a | 2552 | void BRepOffset_MakeOffset::MakeLoops(TopTools_IndexedMapOfShape& Modif) |
7fd59977 | 2553 | { |
0797d9d3 | 2554 | #ifdef OCCT_DEBUG |
7fd59977 | 2555 | if (ChronBuild) { |
04232180 | 2556 | std::cout << " DEBOUCLAGE 2D:" << std::endl; |
7fd59977 | 2557 | Clock.Reset(); |
2558 | Clock.Start(); | |
2559 | } | |
2560 | #endif | |
975ec82a | 2561 | //TopTools_MapIteratorOfMapOfShape it(Modif); |
7fd59977 | 2562 | TopTools_ListOfShape LF,LC; |
2563 | //----------------------------------------- | |
0d969553 | 2564 | // unwinding of faces // modified. |
7fd59977 | 2565 | //----------------------------------------- |
975ec82a J |
2566 | Standard_Integer i; |
2567 | for (i = 1; i <= Modif.Extent(); i++) { | |
2568 | if (!myFaces.Contains(Modif(i))) | |
2569 | LF.Append(Modif(i)); | |
7fd59977 | 2570 | } |
9b7f3f83 | 2571 | // |
ecf4f17c | 2572 | if ((myJoin == GeomAbs_Intersection) && myInter && myIsPlanar) { |
2573 | BuildSplitsOfTrimmedFaces(LF, myAsDes, myImageOffset); | |
9b7f3f83 | 2574 | } |
2575 | else { | |
8948e18d | 2576 | myMakeLoops.Build(LF,myAsDes,myImageOffset,myImageVV); |
9b7f3f83 | 2577 | } |
7fd59977 | 2578 | |
2579 | //----------------------------------------- | |
0d969553 | 2580 | // unwinding of caps. |
7fd59977 | 2581 | //----------------------------------------- |
975ec82a J |
2582 | for (i = 1; i <= myFaces.Extent(); i++) |
2583 | LC.Append(myFaces(i)); | |
2584 | ||
7fd59977 | 2585 | Standard_Boolean InSide = 1; |
2586 | if (myOffset > 0 ) InSide = 0; | |
2587 | myMakeLoops.BuildOnContext(LC,myAnalyse,myAsDes,myImageOffset,InSide); | |
2588 | ||
0797d9d3 | 2589 | #ifdef OCCT_DEBUG |
7fd59977 | 2590 | if ( ChronBuild) Clock.Show(); |
2591 | #endif | |
2592 | } | |
2593 | ||
2594 | //======================================================================= | |
2595 | //function : MakeFaces | |
0d969553 Y |
2596 | //purpose : Reconstruction of topologically unchanged faces that |
2597 | // share edges that were reconstructed. | |
7fd59977 | 2598 | //======================================================================= |
2599 | ||
35e08fe8 | 2600 | void BRepOffset_MakeOffset::MakeFaces(TopTools_IndexedMapOfShape& /*Modif*/) |
7fd59977 | 2601 | { |
0797d9d3 | 2602 | #ifdef OCCT_DEBUG |
7fd59977 | 2603 | if (ChronBuild) { |
04232180 | 2604 | std::cout << " RECONSTRUCTION OF FACES:" << std::endl; |
7fd59977 | 2605 | Clock.Reset(); |
2606 | Clock.Start(); | |
2607 | } | |
2608 | #endif | |
2609 | TopTools_ListIteratorOfListOfShape itr; | |
2610 | const TopTools_ListOfShape& Roots = myInitOffsetFace.Roots(); | |
2611 | TopTools_ListOfShape LOF; | |
2612 | //---------------------------------- | |
0d969553 | 2613 | // Loop on all faces //. |
7fd59977 | 2614 | //---------------------------------- |
2615 | for (itr.Initialize(Roots); itr.More(); itr.Next()) { | |
2616 | TopoDS_Face F = TopoDS::Face(myInitOffsetFace.Image(itr.Value()).First()); | |
9b7f3f83 | 2617 | if (!myImageOffset.HasImage(F)) { |
2618 | LOF.Append(F); | |
2619 | } | |
2620 | } | |
2621 | // | |
ecf4f17c | 2622 | if ((myJoin == GeomAbs_Intersection) && myInter && myIsPlanar) { |
2623 | BuildSplitsOfTrimmedFaces(LOF, myAsDes, myImageOffset); | |
9b7f3f83 | 2624 | } |
2625 | else { | |
2626 | myMakeLoops.BuildFaces(LOF,myAsDes,myImageOffset); | |
7fd59977 | 2627 | } |
7fd59977 | 2628 | |
0797d9d3 | 2629 | #ifdef OCCT_DEBUG |
7fd59977 | 2630 | if ( ChronBuild) Clock.Show(); |
2631 | #endif | |
2632 | } | |
2633 | ||
2634 | //======================================================================= | |
2635 | //function : UpdateInitOffset | |
0d969553 | 2636 | //purpose : Update and cleaning of myInitOffset |
7fd59977 | 2637 | //======================================================================= |
7fd59977 | 2638 | static void UpdateInitOffset (BRepAlgo_Image& myInitOffset, |
9b7f3f83 | 2639 | BRepAlgo_Image& myImageOffset, |
2640 | const TopoDS_Shape& myOffsetShape, | |
2641 | const TopAbs_ShapeEnum &theShapeType) // skv | |
7fd59977 | 2642 | { |
2643 | BRepAlgo_Image NIOF; | |
2644 | const TopTools_ListOfShape& Roots = myInitOffset.Roots(); | |
2645 | TopTools_ListIteratorOfListOfShape it(Roots); | |
2646 | for (; it.More(); it.Next()) { | |
2647 | NIOF.SetRoot (it.Value()); | |
2648 | } | |
2649 | for (it.Initialize(Roots); it.More(); it.Next()) { | |
2650 | const TopoDS_Shape& SI = it.Value(); | |
2651 | TopTools_ListOfShape LI; | |
2652 | TopTools_ListOfShape L1; | |
2653 | myInitOffset.LastImage(SI,L1); | |
2654 | TopTools_ListIteratorOfListOfShape itL1(L1); | |
2655 | for (; itL1.More(); itL1.Next()) { | |
2656 | const TopoDS_Shape& O1 = itL1.Value(); | |
2657 | TopTools_ListOfShape L2; | |
2658 | myImageOffset.LastImage(O1,L2); | |
2659 | LI.Append(L2); | |
2660 | } | |
2661 | NIOF.Bind(SI,LI); | |
2662 | } | |
2663 | // Modified by skv - Mon Apr 4 18:17:27 2005 Begin | |
2664 | // Supporting history. | |
2665 | // NIOF.Filter(myOffsetShape,TopAbs_FACE); | |
2666 | NIOF.Filter(myOffsetShape, theShapeType); | |
2667 | // Modified by skv - Mon Apr 4 18:17:27 2005 End | |
2668 | myInitOffset = NIOF; | |
2669 | } | |
2670 | ||
2671 | //======================================================================= | |
2672 | //function : MakeMissingWalls | |
2673 | //purpose : | |
2674 | //======================================================================= | |
7fd59977 | 2675 | void BRepOffset_MakeOffset::MakeMissingWalls () |
2676 | { | |
bad76cfc | 2677 | TopTools_IndexedDataMapOfShapeListOfShape Contours; //Start vertex + list of connected edges (free boundary) |
7fd59977 | 2678 | TopTools_DataMapOfShapeShape MapEF; //Edges of contours: edge + face |
2679 | Standard_Real OffsetVal = Abs(myOffset); | |
2680 | ||
99c9a820 | 2681 | FillContours(myFaceComp, myAnalyse, Contours, MapEF); |
7fd59977 | 2682 | |
bad76cfc | 2683 | for (Standard_Integer ic = 1; ic <= Contours.Extent(); ic++) |
a8704c36 | 2684 | { |
bad76cfc | 2685 | TopoDS_Vertex StartVertex = TopoDS::Vertex(Contours.FindKey(ic)); |
a8704c36 | 2686 | TopoDS_Edge StartEdge; |
bad76cfc | 2687 | const TopTools_ListOfShape& aContour = Contours(ic); |
a8704c36 | 2688 | TopTools_ListIteratorOfListOfShape itl(aContour); |
2689 | Standard_Boolean FirstStep = Standard_True; | |
2690 | TopoDS_Edge PrevEdge; | |
2691 | TopoDS_Vertex PrevVertex = StartVertex; | |
2692 | Standard_Boolean isBuildFromScratch = Standard_False; // Problems with edges. | |
2693 | for (; itl.More(); itl.Next()) | |
7fd59977 | 2694 | { |
a8704c36 | 2695 | TopoDS_Edge anEdge = TopoDS::Edge(itl.Value()); |
bad76cfc | 2696 | TopoDS_Face aFaceOfEdge = TopoDS::Face(MapEF(anEdge)); |
a8704c36 | 2697 | |
2698 | // Check for offset existence. | |
2699 | if (!myInitOffsetEdge.HasImage(anEdge)) | |
2700 | continue; | |
2701 | ||
2702 | // Check for existence of two different vertices. | |
2703 | TopTools_ListOfShape LOE, LOE2; | |
2704 | myInitOffsetEdge.LastImage( anEdge, LOE ); | |
2705 | myImageOffset.LastImage( LOE.Last(), LOE2 ); | |
2706 | TopoDS_Edge OE = TopoDS::Edge( LOE2.Last() ); | |
2707 | TopoDS_Vertex V1, V2, V3, V4; | |
2708 | TopExp::Vertices(OE, V4, V3); | |
2709 | TopExp::Vertices(anEdge, V1, V2); | |
2710 | Standard_Real aF, aL; | |
2711 | const Handle(Geom_Curve) aC = BRep_Tool::Curve(anEdge, aF, aL); | |
2712 | if (!aC.IsNull() && | |
2713 | (!aC->IsClosed() && !aC->IsPeriodic())) | |
2714 | { | |
2715 | gp_Pnt aPntF = BRep_Tool::Pnt(V1); | |
2716 | gp_Pnt aPntL = BRep_Tool::Pnt(V2); | |
2717 | Standard_Real aDistE = aPntF.SquareDistance(aPntL); | |
2718 | if ( aDistE < Precision::SquareConfusion()) | |
2719 | { | |
2720 | // Bad case: non closed, but vertexes mapped to same 3d point. | |
2721 | continue; | |
2722 | } | |
2723 | ||
2724 | Standard_Real anEdgeTol = BRep_Tool::Tolerance(anEdge); | |
2725 | if (aDistE < anEdgeTol) | |
2726 | { | |
2727 | // Potential problems not detected via checkshape. | |
2728 | gp_Pnt aPntOF = BRep_Tool::Pnt(V4); | |
2729 | gp_Pnt aPntOL = BRep_Tool::Pnt(V3); | |
2730 | if (aPntOF.SquareDistance(aPntOL) > gp::Resolution()) | |
de878dad | 2731 | { |
a8704c36 | 2732 | // To avoid computation of complex analytical continuation of Sin / ArcSin. |
2733 | Standard_Real aSinValue = Min(2 * anEdgeTol / aPntOF.Distance(aPntOL), 1.0); | |
2734 | Standard_Real aMaxAngle = Min(Abs(ASin(aSinValue)), M_PI_4); // Maximal angle. | |
2735 | Standard_Real aCurrentAngle = gp_Vec(aPntF, aPntL).Angle(gp_Vec(aPntOF, aPntOL)); | |
2736 | if (aC->IsKind(STANDARD_TYPE(Geom_Line)) && | |
2737 | Abs (aCurrentAngle) > aMaxAngle) | |
2738 | { | |
2739 | // anEdge not collinear to offset edge. | |
2740 | isBuildFromScratch = Standard_True; | |
2741 | myIsPerformSewing = Standard_True; | |
2742 | continue; | |
2743 | } | |
2744 | } | |
2745 | } | |
2746 | } | |
2747 | ||
2748 | Standard_Boolean ToReverse = Standard_False; | |
2749 | if (!V1.IsSame(PrevVertex)) | |
2750 | { | |
2751 | TopoDS_Vertex aVtx = V1; V1 = V2; V2 = aVtx; | |
2752 | aVtx = V3; V3 = V4; V4 = aVtx; | |
2753 | ToReverse = Standard_True; | |
2754 | } | |
2755 | ||
2756 | OE.Orientation(TopAbs::Reverse(anEdge.Orientation())); | |
2757 | TopoDS_Edge E3, E4; | |
2758 | Standard_Boolean ArcOnV2 = ((myJoin == GeomAbs_Arc) && (myInitOffsetEdge.HasImage(V2))); | |
2759 | if (FirstStep || isBuildFromScratch) | |
2760 | { | |
2761 | E4 = BRepLib_MakeEdge( V1, V4 ); | |
2762 | if (FirstStep) | |
2763 | StartEdge = E4; | |
2764 | } | |
2765 | else | |
2766 | E4 = PrevEdge; | |
2767 | if (V2.IsSame(StartVertex) && !ArcOnV2) | |
2768 | E3 = StartEdge; | |
2769 | else | |
2770 | E3 = BRepLib_MakeEdge( V2, V3 ); | |
2771 | E4.Reverse(); | |
2772 | ||
2773 | if (isBuildFromScratch) | |
2774 | { | |
2775 | E3.Reverse(); | |
2776 | E4.Reverse(); | |
2777 | } | |
2778 | ||
2779 | TopoDS_Shape localAnEdge = anEdge.Oriented(TopAbs_FORWARD); | |
2780 | const TopoDS_Edge& anEdgeFWD = TopoDS::Edge(localAnEdge); | |
2781 | Standard_Real ParV1 = BRep_Tool::Parameter(V1, anEdgeFWD); | |
2782 | Standard_Real ParV2 = BRep_Tool::Parameter(V2, anEdgeFWD); | |
2783 | BRep_Builder BB; | |
2784 | TopoDS_Wire theWire; | |
2785 | BB.MakeWire(theWire); | |
2786 | if (ToReverse) | |
2787 | { | |
2788 | BB.Add(theWire, anEdge.Reversed()); | |
2789 | BB.Add(theWire, E3.Reversed()); | |
2790 | BB.Add(theWire, OE.Reversed()); | |
2791 | BB.Add(theWire, E4.Reversed()); | |
2792 | } | |
2793 | else | |
2794 | { | |
2795 | BB.Add(theWire, anEdge); | |
2796 | BB.Add(theWire, E3); | |
2797 | BB.Add(theWire, OE); | |
2798 | BB.Add(theWire, E4); | |
2799 | } | |
2800 | ||
2801 | BRepLib::BuildCurves3d( theWire, myTol ); | |
2802 | theWire.Closed(Standard_True); | |
2803 | TopoDS_Face NewFace; | |
2804 | Handle(Geom_Surface) theSurf; | |
2805 | BRepAdaptor_Curve BAcurve(anEdge); | |
2806 | BRepAdaptor_Curve BAcurveOE(OE); | |
2807 | Standard_Real fpar = BAcurve.FirstParameter(); | |
2808 | Standard_Real lpar = BAcurve.LastParameter(); | |
2809 | gp_Pnt PonE = BAcurve.Value(fpar); | |
2810 | gp_Pnt PonOE = BAcurveOE.Value(fpar); | |
2811 | gp_Dir OffsetDir = gce_MakeDir( PonE, PonOE ); | |
2812 | Handle(Geom2d_Line) EdgeLine2d, OELine2d, aLine2d, aLine2d2; | |
2813 | Standard_Boolean IsPlanar = Standard_False; | |
2814 | if (BAcurve.GetType() == GeomAbs_Circle && | |
2815 | BAcurveOE.GetType() == GeomAbs_Circle) | |
2816 | { | |
2817 | gp_Circ aCirc = BAcurve.Circle(); | |
2818 | gp_Circ aCircOE = BAcurveOE.Circle(); | |
2819 | gp_Lin anAxisLine(aCirc.Axis()); | |
2820 | gp_Dir CircAxisDir = aCirc.Axis().Direction(); | |
2821 | if (aCirc.Axis().IsParallel(aCircOE.Axis(), Precision::Confusion()) && | |
2822 | anAxisLine.Contains(aCircOE.Location(), Precision::Confusion())) | |
2823 | { //cylinder, plane or cone | |
2824 | if (Abs(aCirc.Radius() - aCircOE.Radius()) <= Precision::Confusion()) //case of cylinder | |
2825 | theSurf = GC_MakeCylindricalSurface(aCirc).Value(); | |
2826 | else if (aCirc.Location().Distance(aCircOE.Location()) <= Precision::Confusion()) {//case of plane | |
2827 | IsPlanar = Standard_True; | |
2828 | // | |
2829 | gp_Pnt PonEL = BAcurve.Value(lpar); | |
2830 | if (PonEL.Distance(PonE) <= Precision::PConfusion()) { | |
2831 | Standard_Boolean bIsHole; | |
2832 | TopoDS_Edge aE1, aE2; | |
2833 | TopoDS_Wire aW1, aW2; | |
2834 | Handle(Geom_Plane) aPL; | |
2835 | IntTools_FClass2d aClsf; | |
2836 | // | |
2837 | if (aCirc.Radius()>aCircOE.Radius()) { | |
2838 | aE1 = anEdge; | |
2839 | aE2 = OE; | |
2840 | } else { | |
2841 | aE1 = OE; | |
2842 | aE2 = anEdge; | |
2843 | } | |
2844 | // | |
2845 | BB.MakeWire(aW1); | |
2846 | BB.Add(aW1, aE1); | |
2847 | BB.MakeWire(aW2); | |
2848 | BB.Add(aW2, aE2); | |
2849 | // | |
2850 | aPL = new Geom_Plane(aCirc.Location(), CircAxisDir); | |
2851 | for (Standard_Integer i = 0; i < 2; ++i) { | |
2852 | TopoDS_Wire& aW = (i==0) ? aW1 : aW2; | |
2853 | TopoDS_Edge& aE = (i==0) ? aE1 : aE2; | |
bb310307 | 2854 | // |
a8704c36 | 2855 | TopoDS_Face aFace; |
2856 | BB.MakeFace(aFace, aPL, Precision::Confusion()); | |
2857 | BB.Add (aFace, aW); | |
2858 | aClsf.Init(aFace, Precision::Confusion()); | |
2859 | bIsHole=aClsf.IsHole(); | |
2860 | if ((bIsHole && !i) || (!bIsHole && i)) { | |
2861 | aW.Nullify(); | |
2862 | BB.MakeWire(aW); | |
2863 | BB.Add(aW, aE.Reversed()); | |
bb310307 | 2864 | } |
2865 | } | |
a8704c36 | 2866 | // |
2867 | BB.MakeFace(NewFace, aPL, Precision::Confusion()); | |
2868 | BB.Add(NewFace, aW1); | |
2869 | BB.Add(NewFace, aW2); | |
2870 | } | |
2871 | } | |
2872 | else //case of cone | |
2873 | { | |
2874 | gp_Cone theCone = gce_MakeCone(aCirc.Location(), aCircOE.Location(), | |
2875 | aCirc.Radius(), aCircOE.Radius()); | |
2876 | gp_Ax3 theAx3(aCirc.Position()); | |
2877 | if (CircAxisDir * theCone.Axis().Direction() < 0.) | |
2878 | { | |
2879 | theAx3.ZReverse(); | |
2880 | CircAxisDir.Reverse(); | |
2881 | } | |
2882 | theCone.SetPosition(theAx3); | |
2883 | theSurf = new Geom_ConicalSurface(theCone); | |
2884 | } | |
2885 | if (!IsPlanar) { | |
2886 | TopLoc_Location Loc; | |
2887 | EdgeLine2d = new Geom2d_Line(gp_Pnt2d(0., 0.), gp_Dir2d(1., 0.)); | |
2888 | BB.UpdateEdge(anEdge, EdgeLine2d, theSurf, Loc, Precision::Confusion()); | |
2889 | Standard_Real Coeff = (OffsetDir * CircAxisDir > 0.)? 1. : -1.; | |
2890 | OELine2d = new Geom2d_Line(gp_Pnt2d(0., OffsetVal*Coeff), gp_Dir2d(1., 0.)); | |
2891 | BB.UpdateEdge(OE, OELine2d, theSurf, Loc, Precision::Confusion()); | |
2892 | aLine2d = new Geom2d_Line(gp_Pnt2d(ParV2, 0.), gp_Dir2d(0., Coeff)); | |
2893 | aLine2d2 = new Geom2d_Line(gp_Pnt2d(ParV1, 0.), gp_Dir2d(0., Coeff)); | |
2894 | if (E3.IsSame(E4)) | |
2895 | { | |
2896 | if (Coeff > 0.) | |
2897 | BB.UpdateEdge(E3, aLine2d, aLine2d2, theSurf, Loc, Precision::Confusion()); | |
2898 | else | |
de878dad | 2899 | { |
a8704c36 | 2900 | BB.UpdateEdge(E3, aLine2d2, aLine2d, theSurf, Loc, Precision::Confusion()); |
2901 | theWire.Nullify(); | |
2902 | BB.MakeWire(theWire); | |
2903 | BB.Add(theWire, anEdge.Oriented(TopAbs_REVERSED)); | |
2904 | BB.Add(theWire, E4); | |
2905 | BB.Add(theWire, OE.Oriented(TopAbs_FORWARD)); | |
2906 | BB.Add(theWire, E3); | |
2907 | theWire.Closed(Standard_True); | |
de878dad | 2908 | } |
a8704c36 | 2909 | } |
2910 | else | |
2911 | { | |
2912 | BB.SameParameter(E3, Standard_False); | |
2913 | BB.SameRange(E3, Standard_False); | |
2914 | BB.SameParameter(E4, Standard_False); | |
2915 | BB.SameRange(E4, Standard_False); | |
2916 | BB.UpdateEdge(E3, aLine2d, theSurf, Loc, Precision::Confusion()); | |
2917 | BB.Range(E3, theSurf, Loc, 0., OffsetVal); | |
2918 | BB.UpdateEdge(E4, aLine2d2, theSurf, Loc, Precision::Confusion()); | |
2919 | BB.Range(E4, theSurf, Loc, 0., OffsetVal); | |
2920 | } | |
2921 | NewFace = BRepLib_MakeFace(theSurf, theWire); | |
2922 | } | |
2923 | } //cylinder or cone | |
2924 | } //if both edges are arcs of circles | |
2925 | if (NewFace.IsNull()) | |
2926 | { | |
2927 | BRepLib_MakeFace MF(theWire, Standard_True); //Only plane | |
2928 | if (MF.Error() == BRepLib_FaceDone) | |
2929 | { | |
2930 | NewFace = MF.Face(); | |
2931 | IsPlanar = Standard_True; | |
2932 | } | |
2933 | else //Extrusion (by thrusections) | |
2934 | { | |
2935 | Handle(Geom_Curve) EdgeCurve = BRep_Tool::Curve(anEdge, fpar, lpar); | |
2936 | Handle(Geom_TrimmedCurve) TrEdgeCurve = | |
2937 | new Geom_TrimmedCurve( EdgeCurve, fpar, lpar ); | |
2938 | Standard_Real fparOE, lparOE; | |
2939 | Handle(Geom_Curve) OffsetCurve = BRep_Tool::Curve(OE, fparOE, lparOE); | |
2940 | Handle(Geom_TrimmedCurve) TrOffsetCurve = | |
2941 | new Geom_TrimmedCurve( OffsetCurve, fparOE, lparOE ); | |
2942 | GeomFill_Generator ThrusecGenerator; | |
2943 | ThrusecGenerator.AddCurve( TrEdgeCurve ); | |
2944 | ThrusecGenerator.AddCurve( TrOffsetCurve ); | |
2945 | ThrusecGenerator.Perform( Precision::PConfusion() ); | |
2946 | theSurf = ThrusecGenerator.Surface(); | |
2947 | //theSurf = new Geom_SurfaceOfLinearExtrusion( TrOffsetCurve, OffsetDir ); | |
2948 | Standard_Real Uf, Ul, Vf, Vl; | |
2949 | theSurf->Bounds(Uf, Ul, Vf, Vl); | |
2950 | TopLoc_Location Loc; | |
2951 | EdgeLine2d = new Geom2d_Line(gp_Pnt2d(0., Vf), gp_Dir2d(1., 0.)); | |
2952 | BB.UpdateEdge(anEdge, EdgeLine2d, theSurf, Loc, Precision::Confusion()); | |
2953 | OELine2d = new Geom2d_Line(gp_Pnt2d(0., Vl), gp_Dir2d(1., 0.)); | |
2954 | BB.UpdateEdge(OE, OELine2d, theSurf, Loc, Precision::Confusion()); | |
2955 | Standard_Real UonV1 = (ToReverse)? Ul : Uf; | |
2956 | Standard_Real UonV2 = (ToReverse)? Uf : Ul; | |
2957 | aLine2d = new Geom2d_Line(gp_Pnt2d(UonV2, 0.), gp_Dir2d(0., 1.)); | |
2958 | aLine2d2 = new Geom2d_Line(gp_Pnt2d(UonV1, 0.), gp_Dir2d(0., 1.)); | |
2959 | if (E3.IsSame(E4)) | |
2960 | { | |
2961 | BB.UpdateEdge(E3, aLine2d, aLine2d2, theSurf, Loc, Precision::Confusion()); | |
2962 | Handle(Geom_Curve) BSplC34 = theSurf->UIso( Uf ); | |
2963 | BB.UpdateEdge(E3, BSplC34, Precision::Confusion()); | |
2964 | BB.Range(E3, Vf, Vl); | |
2965 | } | |
2966 | else | |
2967 | { | |
2968 | BB.SameParameter(E3, Standard_False); | |
2969 | BB.SameRange(E3, Standard_False); | |
2970 | BB.SameParameter(E4, Standard_False); | |
2971 | BB.SameRange(E4, Standard_False); | |
2972 | BB.UpdateEdge(E3, aLine2d, theSurf, Loc, Precision::Confusion()); | |
2973 | BB.Range(E3, theSurf, Loc, Vf, Vl); | |
2974 | BB.UpdateEdge(E4, aLine2d2, theSurf, Loc, Precision::Confusion()); | |
2975 | BB.Range(E4, theSurf, Loc, Vf, Vl); | |
2976 | Handle(Geom_Curve) BSplC3 = theSurf->UIso( UonV2 ); | |
2977 | BB.UpdateEdge(E3, BSplC3, Precision::Confusion()); | |
2978 | BB.Range(E3, Vf, Vl, Standard_True); //only for 3d curve | |
2979 | Handle(Geom_Curve) BSplC4 = theSurf->UIso( UonV1 ); | |
2980 | BB.UpdateEdge(E4, BSplC4, Precision::Confusion()); | |
2981 | BB.Range(E4, Vf, Vl, Standard_True); //only for 3d curve | |
2982 | } | |
2983 | NewFace = BRepLib_MakeFace(theSurf, theWire); | |
2984 | } | |
2985 | } | |
2986 | if (!IsPlanar) | |
2987 | { | |
2988 | Standard_Real fparOE = BAcurveOE.FirstParameter(); | |
2989 | Standard_Real lparOE = BAcurveOE.LastParameter(); | |
2990 | TopLoc_Location Loc; | |
2991 | if (Abs(fpar - fparOE) > Precision::Confusion()) | |
2992 | { | |
2993 | const TopoDS_Edge& anE4 = (ToReverse)? E3 : E4; | |
2994 | gp_Pnt2d fp2d = EdgeLine2d->Value(fpar); | |
2995 | gp_Pnt2d fp2dOE = OELine2d->Value(fparOE); | |
2996 | aLine2d2 = GCE2d_MakeLine( fp2d, fp2dOE ).Value(); | |
2997 | Handle(Geom_Curve) aCurve; | |
2998 | Standard_Real FirstPar = 0., LastPar = fp2d.Distance(fp2dOE); | |
2999 | Geom2dAdaptor_Curve AC2d( aLine2d2, FirstPar, LastPar ); | |
3000 | GeomAdaptor_Surface GAsurf( theSurf ); | |
c22b52d6 | 3001 | Handle(Geom2dAdaptor_Curve) HC2d = new Geom2dAdaptor_Curve( AC2d ); |
3002 | Handle(GeomAdaptor_Surface) HSurf = new GeomAdaptor_Surface( GAsurf ); | |
a8704c36 | 3003 | Adaptor3d_CurveOnSurface ConS( HC2d, HSurf ); |
3004 | Standard_Real max_deviation = 0., average_deviation; | |
3005 | GeomLib::BuildCurve3d(Precision::Confusion(), | |
3006 | ConS, FirstPar, LastPar, | |
3007 | aCurve, max_deviation, average_deviation); | |
3008 | BB.UpdateEdge( anE4, aCurve, max_deviation ); | |
3009 | BB.UpdateEdge( anE4, aLine2d2, theSurf, Loc, max_deviation ); | |
3010 | BB.Range( anE4, FirstPar, LastPar ); | |
3011 | } | |
3012 | if (Abs(lpar - lparOE) > Precision::Confusion()) | |
3013 | { | |
3014 | const TopoDS_Edge& anE3 = (ToReverse)? E4 : E3; | |
3015 | gp_Pnt2d lp2d = EdgeLine2d->Value(lpar); | |
3016 | gp_Pnt2d lp2dOE = OELine2d->Value(lparOE); | |
3017 | aLine2d = GCE2d_MakeLine( lp2d, lp2dOE ).Value(); | |
3018 | Handle(Geom_Curve) aCurve; | |
3019 | Standard_Real FirstPar = 0., LastPar = lp2d.Distance(lp2dOE); | |
3020 | Geom2dAdaptor_Curve AC2d( aLine2d, FirstPar, LastPar ); | |
3021 | GeomAdaptor_Surface GAsurf( theSurf ); | |
c22b52d6 | 3022 | Handle(Geom2dAdaptor_Curve) HC2d = new Geom2dAdaptor_Curve( AC2d ); |
3023 | Handle(GeomAdaptor_Surface) HSurf = new GeomAdaptor_Surface( GAsurf ); | |
a8704c36 | 3024 | Adaptor3d_CurveOnSurface ConS( HC2d, HSurf ); |
3025 | Standard_Real max_deviation = 0., average_deviation; | |
3026 | GeomLib::BuildCurve3d(Precision::Confusion(), | |
3027 | ConS, FirstPar, LastPar, | |
3028 | aCurve, max_deviation, average_deviation); | |
3029 | BB.UpdateEdge( anE3, aCurve, max_deviation ); | |
3030 | BB.UpdateEdge( anE3, aLine2d, theSurf, Loc, max_deviation ); | |
3031 | BB.Range( anE3, FirstPar, LastPar ); | |
3032 | } | |
3033 | } | |
3034 | BRepLib::SameParameter(NewFace); | |
3035 | BRepTools::Update(NewFace); | |
bad76cfc | 3036 | //Check orientation |
3037 | TopAbs_Orientation anOr = OrientationOfEdgeInFace(anEdge, aFaceOfEdge); | |
3038 | TopAbs_Orientation OrInNewFace = OrientationOfEdgeInFace(anEdge, NewFace); | |
3039 | if (OrInNewFace != TopAbs::Reverse(anOr)) | |
3040 | NewFace.Reverse(); | |
3041 | /////////////////// | |
a8704c36 | 3042 | myWalls.Append(NewFace); |
3043 | if (ArcOnV2) | |
3044 | { | |
3045 | TopoDS_Edge anArc = TopoDS::Edge(myInitOffsetEdge.Image(V2).First()); | |
3046 | TopoDS_Vertex arcV1, arcV2; | |
3047 | TopExp::Vertices(anArc, arcV1, arcV2); | |
3048 | Standard_Boolean ArcReverse = Standard_False; | |
3049 | if (!arcV1.IsSame(V3)) | |
3050 | { | |
3051 | TopoDS_Vertex aVtx = arcV1; arcV1 = arcV2; arcV2 = aVtx; | |
3052 | ArcReverse = Standard_True; | |
3053 | } | |
3054 | TopoDS_Edge EA1, EA2; | |
3055 | //EA1 = (ToReverse)? E3 : TopoDS::Edge(E3.Reversed()); | |
3056 | EA1 = E3; | |
3057 | EA1.Reverse(); | |
3058 | if (ToReverse) | |
3059 | EA1.Reverse(); | |
3060 | ////////////////////////////////////////////////////// | |
3061 | if (V2.IsSame(StartVertex)) | |
3062 | EA2 = StartEdge; | |
3063 | else | |
3064 | EA2 = BRepLib_MakeEdge( V2, arcV2 ); | |
3065 | anArc.Orientation( ((ArcReverse)? TopAbs_REVERSED : TopAbs_FORWARD) ); | |
3066 | if (EA1.Orientation() == TopAbs_REVERSED) | |
3067 | anArc.Reverse(); | |
3068 | EA2.Orientation(TopAbs::Reverse(EA1.Orientation())); | |
3069 | TopoDS_Wire arcWire; | |
3070 | BB.MakeWire(arcWire); | |
3071 | BB.Add(arcWire, EA1); | |
3072 | BB.Add(arcWire, anArc); | |
3073 | BB.Add(arcWire, EA2); | |
3074 | BRepLib::BuildCurves3d( arcWire, myTol ); | |
3075 | arcWire.Closed(Standard_True); | |
3076 | TopoDS_Face arcFace = BRepLib_MakeFace(arcWire, Standard_True); | |
3077 | BRepTools::Update(arcFace); | |
3078 | myWalls.Append(arcFace); | |
3079 | TopoDS_Shape localEA2 = EA2.Oriented(TopAbs_FORWARD); | |
3080 | const TopoDS_Edge& CEA2 = TopoDS::Edge(localEA2); | |
3081 | PrevEdge = CEA2; | |
3082 | PrevVertex = V2; | |
3083 | } | |
3084 | else | |
3085 | { | |
3086 | if (isBuildFromScratch) | |
3087 | { | |
3088 | PrevEdge = TopoDS::Edge(E4); | |
3089 | PrevVertex = V1; | |
3090 | isBuildFromScratch = Standard_False; | |
3091 | } | |
3092 | else | |
3093 | { | |
3094 | PrevEdge = E3; | |
3095 | PrevVertex = V2; | |
3096 | } | |
3097 | } | |
3098 | FirstStep = Standard_False; | |
7fd59977 | 3099 | } |
a8704c36 | 3100 | } |
7fd59977 | 3101 | } |
3102 | ||
3103 | //======================================================================= | |
3104 | //function : MakeShells | |
3105 | //purpose : | |
3106 | //======================================================================= | |
3107 | ||
3108 | void BRepOffset_MakeOffset::MakeShells () | |
3109 | { | |
0797d9d3 | 3110 | #ifdef OCCT_DEBUG |
7fd59977 | 3111 | if (ChronBuild) { |
04232180 | 3112 | std::cout << " RECONSTRUCTION OF SHELLS:" << std::endl; |
7fd59977 | 3113 | Clock.Reset(); |
3114 | Clock.Start(); | |
3115 | } | |
3116 | #endif | |
9b7f3f83 | 3117 | // |
e7384fd4 | 3118 | // Prepare list of splits of the offset faces to make the shells |
1155d05a | 3119 | TopTools_ListOfShape aLSF; |
7fd59977 | 3120 | const TopTools_ListOfShape& R = myImageOffset.Roots(); |
3121 | TopTools_ListIteratorOfListOfShape it(R); | |
9b7f3f83 | 3122 | // |
3123 | for (; it.More(); it.Next()) { | |
bad76cfc | 3124 | TopoDS_Shape aF = it.Value(); |
3125 | if (myThickening) //offsetted faces must change their orientations | |
3126 | aF.Reverse(); | |
ecf4f17c | 3127 | // |
7fd59977 | 3128 | TopTools_ListOfShape Image; |
ecf4f17c | 3129 | myImageOffset.LastImage(aF,Image); |
7fd59977 | 3130 | TopTools_ListIteratorOfListOfShape it2(Image); |
9b7f3f83 | 3131 | for (; it2.More(); it2.Next()) { |
ecf4f17c | 3132 | const TopoDS_Shape& aFIm = it2.Value(); |
3133 | aLSF.Append(aFIm); | |
7fd59977 | 3134 | } |
3135 | } | |
9b7f3f83 | 3136 | // |
3137 | if (myThickening) { | |
db2f1498 | 3138 | TopExp_Explorer Explo(myShape, TopAbs_FACE); |
9b7f3f83 | 3139 | for (; Explo.More(); Explo.Next()) { |
3140 | const TopoDS_Shape& aF = Explo.Current(); | |
3141 | aLSF.Append(aF); | |
3142 | } | |
3143 | // | |
3144 | it.Initialize(myWalls); | |
3145 | for (; it.More(); it.Next()) { | |
3146 | const TopoDS_Shape& aF = it.Value(); | |
3147 | aLSF.Append(aF); | |
3148 | } | |
3149 | } | |
3150 | // | |
ecf4f17c | 3151 | if (aLSF.IsEmpty()) { |
3152 | return; | |
3153 | } | |
3154 | // | |
9b7f3f83 | 3155 | Standard_Boolean bDone = Standard_False; |
3156 | if ((myJoin == GeomAbs_Intersection) && myInter && | |
3157 | !myThickening && myFaces.IsEmpty() && | |
3158 | IsSolid(myShape) && myIsPlanar) { | |
3159 | // | |
ecf4f17c | 3160 | TopoDS_Shape aShells; |
e7384fd4 | 3161 | bDone = BuildShellsCompleteInter(aLSF, myImageOffset, aShells); |
9b7f3f83 | 3162 | if (bDone) { |
ecf4f17c | 3163 | myOffsetShape = aShells; |
9b7f3f83 | 3164 | } |
3165 | } | |
3166 | // | |
3167 | if (!bDone) { | |
3168 | BRepTools_Quilt Glue; | |
1155d05a | 3169 | TopTools_ListIteratorOfListOfShape aItLS(aLSF); |
9b7f3f83 | 3170 | for (; aItLS.More(); aItLS.Next()) { |
ecf4f17c | 3171 | Glue.Add(aItLS.Value()); |
9b7f3f83 | 3172 | } |
3173 | myOffsetShape = Glue.Shells(); | |
db2f1498 | 3174 | } |
db2f1498 | 3175 | // |
3176 | //Set correct value for closed flag | |
3177 | TopExp_Explorer Explo(myOffsetShape, TopAbs_SHELL); | |
3178 | for(; Explo.More(); Explo.Next()) | |
3179 | { | |
3180 | TopoDS_Shape aS = Explo.Current(); | |
3181 | if(!aS.Closed()) | |
3182 | { | |
3183 | if(BRep_Tool::IsClosed(aS)) | |
3184 | { | |
3185 | aS.Closed(Standard_True); | |
3186 | } | |
3187 | } | |
ecf4f17c | 3188 | } |
7fd59977 | 3189 | } |
3190 | ||
3191 | //======================================================================= | |
3192 | //function : MakeSolid | |
3193 | //purpose : | |
3194 | //======================================================================= | |
3195 | ||
3196 | void BRepOffset_MakeOffset::MakeSolid () | |
3197 | { | |
3198 | if (myOffsetShape.IsNull()) return; | |
3199 | ||
3200 | // Modified by skv - Mon Apr 4 18:17:27 2005 Begin | |
3201 | // Supporting history. | |
3202 | UpdateInitOffset (myInitOffsetFace,myImageOffset,myOffsetShape, TopAbs_FACE); | |
3203 | UpdateInitOffset (myInitOffsetEdge,myImageOffset,myOffsetShape, TopAbs_EDGE); | |
3204 | // Modified by skv - Mon Apr 4 18:17:27 2005 End | |
3205 | TopExp_Explorer exp; | |
3206 | BRep_Builder B; | |
3207 | Standard_Integer NbShell = 0; | |
3208 | TopoDS_Compound NC; | |
3209 | TopoDS_Shape S1; | |
3210 | B.MakeCompound (NC); | |
3211 | ||
db2f1498 | 3212 | TopoDS_Solid Sol; |
3213 | B.MakeSolid(Sol); | |
3214 | Sol.Closed(Standard_True); | |
3215 | Standard_Boolean aMakeSolid = (myShape.ShapeType() == TopAbs_SOLID) || myThickening; | |
7fd59977 | 3216 | for (exp.Init(myOffsetShape,TopAbs_SHELL); exp.More(); exp.Next()) { |
3217 | TopoDS_Shell Sh = TopoDS::Shell(exp.Current()); | |
3218 | if (myThickening && myOffset > 0.) | |
3219 | Sh.Reverse(); | |
3220 | NbShell++; | |
db2f1498 | 3221 | if (Sh.Closed() && aMakeSolid) { |
3222 | B.Add(Sol,Sh); | |
7fd59977 | 3223 | } |
3224 | else { | |
3225 | B.Add (NC,Sh); | |
db2f1498 | 3226 | if(NbShell == 1) |
3227 | { | |
3228 | S1 = Sh; | |
3229 | } | |
3230 | } | |
3231 | } | |
b2d1851c | 3232 | Standard_Integer nbs = Sol.NbChildren(); |
3233 | Standard_Boolean SolIsNull = (nbs == 0); | |
db2f1498 | 3234 | //Checking solid |
b2d1851c | 3235 | if (nbs > 1) |
db2f1498 | 3236 | { |
b2d1851c | 3237 | BRepCheck_Analyzer aCheck (Sol, Standard_False); |
3238 | if (!aCheck.IsValid ()) | |
db2f1498 | 3239 | { |
b2d1851c | 3240 | TopTools_ListOfShape aSolList; |
3241 | CorrectSolid (Sol, aSolList); | |
3242 | if (!aSolList.IsEmpty ()) | |
db2f1498 | 3243 | { |
b2d1851c | 3244 | B.Add (NC, Sol); |
3245 | TopTools_ListIteratorOfListOfShape aSLIt (aSolList); | |
3246 | for (; aSLIt.More (); aSLIt.Next ()) | |
db2f1498 | 3247 | { |
b2d1851c | 3248 | B.Add (NC, aSLIt.Value ()); |
db2f1498 | 3249 | } |
b2d1851c | 3250 | SolIsNull = Standard_True; |
db2f1498 | 3251 | } |
7fd59977 | 3252 | } |
3253 | } | |
b2d1851c | 3254 | Standard_Boolean NCIsNull = (NC.NbChildren() == 0); |
db2f1498 | 3255 | if((!SolIsNull) && (!NCIsNull)) |
3256 | { | |
3257 | B.Add(NC, Sol); | |
3258 | myOffsetShape = NC; | |
3259 | } | |
3260 | else if(SolIsNull && (!NCIsNull)) | |
3261 | { | |
3262 | if (NbShell == 1) | |
3263 | { | |
3264 | myOffsetShape = S1; | |
3265 | } | |
3266 | else | |
3267 | { | |
3268 | myOffsetShape = NC; | |
3269 | } | |
3270 | } | |
3271 | else if((!SolIsNull) && NCIsNull) | |
3272 | { | |
3273 | myOffsetShape = Sol; | |
3274 | } | |
3275 | else | |
3276 | { | |
3277 | myOffsetShape = NC; | |
3278 | } | |
7fd59977 | 3279 | } |
3280 | ||
3281 | //======================================================================= | |
3282 | //function : SelectShells | |
3283 | //purpose : | |
3284 | //======================================================================= | |
3285 | ||
3286 | void BRepOffset_MakeOffset::SelectShells () | |
ecf4f17c | 3287 | { |
7fd59977 | 3288 | TopTools_MapOfShape FreeEdges; |
99c9a820 | 3289 | TopExp_Explorer exp(myFaceComp,TopAbs_EDGE); |
7fd59977 | 3290 | //------------------------------------------------------------- |
0d969553 Y |
3291 | // FreeEdges all edges that can have free border in the |
3292 | // parallel shell | |
3293 | // 1 - free borders of myShape . | |
7fd59977 | 3294 | //------------------------------------------------------------- |
3295 | for ( ; exp.More(); exp.Next()) { | |
3296 | const TopoDS_Edge& E = TopoDS::Edge(exp.Current()); | |
3297 | const TopTools_ListOfShape& LA = myAnalyse.Ancestors(E); | |
3298 | if (LA.Extent() < 2) { | |
eff3eff9 | 3299 | if (myAnalyse.Type(E).First().Type() == ChFiDS_FreeBound) { |
9b7f3f83 | 3300 | FreeEdges.Add(E); |
7fd59977 | 3301 | } |
3302 | } | |
3303 | } | |
0d969553 Y |
3304 | // myShape has free borders and there are no caps |
3305 | // no unwinding 3d. | |
7fd59977 | 3306 | if (!FreeEdges.IsEmpty() && myFaces.IsEmpty()) return; |
3307 | ||
3308 | myOffsetShape = BRepOffset_Tool::Deboucle3D(myOffsetShape,FreeEdges); | |
3309 | } | |
3310 | ||
3311 | //======================================================================= | |
3312 | //function : OffsetFacesFromShapes | |
3313 | //purpose : | |
3314 | //======================================================================= | |
3315 | ||
3316 | const BRepAlgo_Image& BRepOffset_MakeOffset::OffsetFacesFromShapes() const | |
3317 | { | |
3318 | return myInitOffsetFace; | |
3319 | } | |
3320 | ||
3321 | // Modified by skv - Tue Mar 15 16:20:43 2005 Begin | |
3322 | ||
3323 | //======================================================================= | |
3324 | //function : GetJoinType | |
3325 | //purpose : Query offset join type. | |
3326 | //======================================================================= | |
3327 | ||
3328 | GeomAbs_JoinType BRepOffset_MakeOffset::GetJoinType() const | |
3329 | { | |
3330 | return myJoin; | |
3331 | } | |
3332 | ||
3333 | //======================================================================= | |
3334 | //function : OffsetEdgesFromShapes | |
3335 | //purpose : | |
3336 | //======================================================================= | |
3337 | ||
3338 | const BRepAlgo_Image& BRepOffset_MakeOffset::OffsetEdgesFromShapes() const | |
3339 | { | |
3340 | return myInitOffsetEdge; | |
3341 | } | |
3342 | ||
3343 | // Modified by skv - Tue Mar 15 16:20:43 2005 End | |
3344 | ||
3345 | //======================================================================= | |
3346 | //function : ClosingFaces | |
3347 | //purpose : | |
3348 | //======================================================================= | |
3349 | ||
975ec82a | 3350 | const TopTools_IndexedMapOfShape& BRepOffset_MakeOffset::ClosingFaces () const |
7fd59977 | 3351 | { |
8948e18d | 3352 | return myOriginalFaces; |
7fd59977 | 3353 | } |
3354 | ||
3355 | ||
3356 | ||
3357 | //======================================================================= | |
3358 | //function : EncodeRegularity | |
3359 | //purpose : | |
3360 | //======================================================================= | |
3361 | ||
3362 | void BRepOffset_MakeOffset::EncodeRegularity () | |
3363 | { | |
0797d9d3 | 3364 | #ifdef OCCT_DEBUG |
7fd59977 | 3365 | if (ChronBuild) { |
04232180 | 3366 | std::cout << " CODING OF REGULARITIES:" << std::endl; |
7fd59977 | 3367 | Clock.Reset(); |
3368 | Clock.Start(); | |
3369 | } | |
3370 | #endif | |
3371 | ||
3372 | if (myOffsetShape.IsNull()) return; | |
0d969553 | 3373 | // find edges G1 in the result |
7fd59977 | 3374 | TopExp_Explorer exp(myOffsetShape,TopAbs_EDGE); |
3375 | ||
3376 | BRep_Builder B; | |
3377 | TopTools_MapOfShape MS; | |
3378 | ||
3379 | for ( ; exp.More(); exp.Next()) { | |
3380 | TopoDS_Edge OE = TopoDS::Edge(exp.Current()); | |
3381 | BRepLib::BuildCurve3d(OE,myTol); | |
3382 | TopoDS_Edge ROE = OE; | |
3383 | ||
3384 | if ( !MS.Add(OE)) continue; | |
3385 | ||
3386 | if ( myImageOffset.IsImage(OE)) | |
3387 | ROE = TopoDS::Edge(myImageOffset.Root(OE)); | |
3388 | ||
3389 | const TopTools_ListOfShape& LofOF = myAsDes->Ascendant(ROE); | |
3390 | ||
3391 | if (LofOF.Extent() != 2) { | |
0797d9d3 | 3392 | #ifdef OCCT_DEBUG_VERB |
04232180 | 3393 | std::cout << " Edge shared by " << LofOF.Extent() << " Faces" << std::endl; |
7fd59977 | 3394 | #endif |
3395 | continue; | |
3396 | } | |
3397 | ||
3398 | const TopoDS_Face& F1 = TopoDS::Face(LofOF.First()); | |
3399 | const TopoDS_Face& F2 = TopoDS::Face(LofOF.Last() ); | |
3400 | ||
3401 | if ( F1.IsNull() || F2.IsNull()) | |
3402 | continue; | |
3403 | ||
3404 | const TopoDS_Shape& Root1 = myInitOffsetFace.Root(F1); | |
3405 | const TopoDS_Shape& Root2 = myInitOffsetFace.Root(F2); | |
3406 | ||
3407 | TopAbs_ShapeEnum Type1 = Root1.ShapeType(); | |
3408 | TopAbs_ShapeEnum Type2 = Root2.ShapeType(); | |
3409 | ||
3410 | if (F1.IsSame(F2)) { | |
3411 | if (BRep_Tool::IsClosed(OE,F1)) { | |
9b7f3f83 | 3412 | // Temporary Debug for the Bench. |
3413 | // Check with YFR. | |
3414 | // In mode intersection, the edges are not coded in myInitOffsetEdge | |
3415 | // so, manage case by case | |
3416 | // Note DUB; for Hidden parts, it is NECESSARY to code CN | |
3417 | // Analytic Surfaces. | |
3418 | if (myJoin == GeomAbs_Intersection) { | |
3419 | BRepAdaptor_Surface BS(F1,Standard_False); | |
3420 | GeomAbs_SurfaceType SType = BS.GetType(); | |
3421 | if (SType == GeomAbs_Cylinder || | |
3422 | SType == GeomAbs_Cone || | |
3423 | SType == GeomAbs_Sphere || | |
3424 | SType == GeomAbs_Torus ) { | |
3425 | B.Continuity(OE,F1,F1,GeomAbs_CN); | |
3426 | } | |
3427 | else { | |
3428 | // See YFR : MaJ of myInitOffsetFace | |
3429 | } | |
3430 | } | |
3431 | else if (myInitOffsetEdge.IsImage(ROE)) { | |
3432 | if ( Type1 == TopAbs_FACE && Type2 == TopAbs_FACE) { | |
3433 | const TopoDS_Face& FRoot = TopoDS::Face(Root1); | |
3434 | const TopoDS_Edge& EI = TopoDS::Edge(myInitOffsetEdge.ImageFrom(ROE)); | |
3435 | GeomAbs_Shape Conti = BRep_Tool::Continuity(EI,FRoot,FRoot); | |
3436 | if (Conti == GeomAbs_CN) { | |
3437 | B.Continuity(OE,F1,F1,GeomAbs_CN); | |
3438 | } | |
3439 | else if ( Conti > GeomAbs_C0) { | |
3440 | B.Continuity(OE,F1,F1,GeomAbs_G1); | |
3441 | } | |
3442 | } | |
3443 | } | |
7fd59977 | 3444 | } |
3445 | continue; | |
3446 | } | |
3447 | ||
3448 | ||
0d969553 Y |
3449 | // code regularities G1 between : |
3450 | // - sphere and tube : one root is a vertex, the other is an edge | |
3451 | // and the vertex is included in the edge | |
3452 | // - face and tube : one root is a face, the other an edge | |
3453 | // and the edge is included in the face | |
3454 | // - face and face : if two root faces are tangent in | |
3455 | // the initial shape, they will be tangent in the offset shape | |
3456 | // - tube and tube : if 2 edges generating tubes are | |
3457 | // tangents, the 2 will be tangent either. | |
7fd59977 | 3458 | if ( Type1 == TopAbs_EDGE && Type2 == TopAbs_VERTEX) { |
3459 | TopoDS_Vertex V1,V2; | |
3460 | TopExp::Vertices(TopoDS::Edge(Root1), V1, V2); | |
3461 | if ( V1.IsSame(Root2) || V2.IsSame(Root2)) { | |
9b7f3f83 | 3462 | B.Continuity(OE,F1,F2,GeomAbs_G1); |
7fd59977 | 3463 | } |
3464 | } | |
3465 | else if ( Type1 == TopAbs_VERTEX && Type2 == TopAbs_EDGE) { | |
3466 | TopoDS_Vertex V1,V2; | |
3467 | TopExp::Vertices(TopoDS::Edge(Root2), V1, V2); | |
3468 | if ( V1.IsSame(Root1) || V2.IsSame(Root1)) { | |
9b7f3f83 | 3469 | B.Continuity(OE,F1,F2,GeomAbs_G1); |
7fd59977 | 3470 | } |
3471 | } | |
3472 | else if ( Type1 == TopAbs_FACE && Type2 == TopAbs_EDGE) { | |
3473 | TopExp_Explorer exp2(Root1,TopAbs_EDGE); | |
3474 | for ( ; exp2.More(); exp2.Next()) { | |
9b7f3f83 | 3475 | if ( exp2.Current().IsSame(Root2)) { |
3476 | B.Continuity(OE,F1,F2,GeomAbs_G1); | |
3477 | break; | |
3478 | } | |
7fd59977 | 3479 | } |
3480 | } | |
3481 | else if ( Type1 == TopAbs_EDGE && Type2 == TopAbs_FACE) { | |
3482 | TopExp_Explorer exp2(Root2,TopAbs_EDGE); | |
3483 | for ( ; exp2.More(); exp2.Next()) { | |
9b7f3f83 | 3484 | if ( exp2.Current().IsSame(Root1)) { |
3485 | B.Continuity(OE,F1,F2,GeomAbs_G1); | |
3486 | break; | |
3487 | } | |
7fd59977 | 3488 | } |
3489 | } | |
3490 | else if ( Type1 == TopAbs_FACE && Type2 == TopAbs_FACE) { | |
0d969553 Y |
3491 | // if two root faces are tangent in |
3492 | // the initial shape, they will be tangent in the offset shape | |
fe1d4d6c | 3493 | TopTools_ListOfShape LE; |
3494 | BRepOffset_Tool::FindCommonShapes(Root1, Root2, TopAbs_EDGE, LE); | |
3495 | if ( LE.Extent() == 1) { | |
9b7f3f83 | 3496 | const TopoDS_Edge& Ed = TopoDS::Edge(LE.First()); |
3497 | if ( myAnalyse.HasAncestor(Ed)) { | |
3498 | const BRepOffset_ListOfInterval& LI = myAnalyse.Type(Ed); | |
3499 | if (LI.Extent() == 1 && | |
eff3eff9 | 3500 | LI.First().Type() == ChFiDS_Tangential) { |
9b7f3f83 | 3501 | B.Continuity(OE,F1,F2,GeomAbs_G1); |
3502 | } | |
3503 | } | |
7fd59977 | 3504 | } |
3505 | } | |
3506 | else if ( Type1 == TopAbs_EDGE && Type2 == TopAbs_EDGE) { | |
3507 | TopTools_ListOfShape LV; | |
fe1d4d6c | 3508 | BRepOffset_Tool::FindCommonShapes(Root1, Root2, TopAbs_VERTEX, LV); |
7fd59977 | 3509 | if ( LV.Extent() == 1) { |
9b7f3f83 | 3510 | TopTools_ListOfShape LEdTg; |
3511 | myAnalyse.TangentEdges(TopoDS::Edge(Root1), | |
3512 | TopoDS::Vertex(LV.First()), | |
3513 | LEdTg); | |
3514 | TopTools_ListIteratorOfListOfShape it(LEdTg); | |
3515 | for (; it.More(); it.Next()) { | |
3516 | if ( it.Value().IsSame(Root2)) { | |
3517 | B.Continuity(OE,F1,F2,GeomAbs_G1); | |
3518 | break; | |
3519 | } | |
3520 | } | |
7fd59977 | 3521 | } |
3522 | } | |
3523 | } | |
3524 | ||
0797d9d3 | 3525 | #ifdef OCCT_DEBUG |
7fd59977 | 3526 | if ( ChronBuild) Clock.Show(); |
3527 | #endif | |
3528 | } | |
3529 | ||
4560c054 | 3530 | //======================================================================= |
3531 | //function : ComputeMaxDist | |
3532 | //purpose : | |
3533 | //======================================================================= | |
3534 | Standard_Real ComputeMaxDist(const gp_Pln& thePlane, | |
3535 | const Handle(Geom_Curve)& theCrv, | |
3536 | const Standard_Real theFirst, | |
3537 | const Standard_Real theLast) | |
3538 | { | |
3539 | Standard_Real aMaxDist = 0.; | |
3540 | Standard_Integer i, NCONTROL = 23; | |
3541 | Standard_Real aPrm, aDist2; | |
3542 | gp_Pnt aP; | |
3543 | for (i = 0; i< NCONTROL; i++) { | |
3544 | aPrm = ((NCONTROL - 1 - i)*theFirst + i*theLast) / (NCONTROL - 1); | |
3545 | aP = theCrv->Value(aPrm); | |
3546 | if (Precision::IsInfinite(aP.X()) || Precision::IsInfinite(aP.Y()) | |
3547 | || Precision::IsInfinite(aP.Z())) | |
3548 | { | |
3549 | return Precision::Infinite(); | |
3550 | } | |
3551 | aDist2 = thePlane.SquareDistance(aP); | |
3552 | if (aDist2 > aMaxDist) aMaxDist = aDist2; | |
3553 | } | |
3554 | return sqrt(aMaxDist)*1.05; | |
3555 | } | |
7fd59977 | 3556 | //======================================================================= |
3557 | //function : UpDateTolerance | |
3558 | //purpose : | |
3559 | //======================================================================= | |
3560 | ||
db2f1498 | 3561 | void UpdateTolerance (TopoDS_Shape& S, |
4560c054 | 3562 | const TopTools_IndexedMapOfShape& Faces) |
7fd59977 | 3563 | { |
3564 | BRep_Builder B; | |
3565 | TopTools_MapOfShape View; | |
3566 | TopoDS_Vertex V[2]; | |
3567 | ||
0d969553 | 3568 | // The edges of caps are not modified. |
975ec82a J |
3569 | Standard_Integer j; |
3570 | for (j = 1; j <= Faces.Extent(); j++) { | |
3571 | const TopoDS_Shape& F = Faces(j); | |
7fd59977 | 3572 | TopExp_Explorer Exp; |
3573 | for (Exp.Init(F,TopAbs_EDGE); Exp.More(); Exp.Next()) { | |
3574 | View.Add(Exp.Current()); | |
3575 | } | |
3576 | } | |
3577 | ||
4560c054 | 3578 | Standard_Real Tol; |
3579 | TopExp_Explorer ExpF; | |
3580 | for (ExpF.Init(S, TopAbs_FACE); ExpF.More(); ExpF.Next()) | |
3581 | { | |
3582 | const TopoDS_Shape& F = ExpF.Current(); | |
3583 | if (Faces.Contains(F)) | |
3584 | { | |
3585 | continue; | |
3586 | } | |
3587 | BRepAdaptor_Surface aBAS(TopoDS::Face(F), Standard_False); | |
3588 | TopExp_Explorer Exp; | |
3589 | for (Exp.Init(F, TopAbs_EDGE); Exp.More(); Exp.Next()) { | |
3590 | TopoDS_Edge E = TopoDS::Edge(Exp.Current()); | |
3591 | Standard_Boolean isUpdated = Standard_False; | |
3592 | if (aBAS.GetType() == GeomAbs_Plane) | |
3593 | { | |
3594 | //Edge does not seem to have pcurve on plane, | |
3595 | //so EdgeCorrector does not include it in tolerance calculation | |
3596 | Standard_Real aFirst, aLast; | |
3597 | Handle(Geom_Curve) aCrv = BRep_Tool::Curve(E, aFirst, aLast); | |
3598 | Standard_Real aMaxDist = ComputeMaxDist(aBAS.Plane(), aCrv, aFirst, aLast); | |
99c9a820 | 3599 | E.Locked (Standard_False); |
4560c054 | 3600 | B.UpdateEdge(E, aMaxDist); |
3601 | isUpdated = Standard_True; | |
3602 | } | |
3603 | if (View.Add(E)) | |
3604 | { | |
3605 | ||
3606 | BRepCheck_Edge EdgeCorrector(E); | |
3607 | Tol = EdgeCorrector.Tolerance(); | |
3608 | B.UpdateEdge(E, Tol); | |
3609 | isUpdated = Standard_True; | |
3610 | } | |
3611 | if (isUpdated) | |
3612 | { | |
3613 | Tol = BRep_Tool::Tolerance(E); | |
3614 | // Update the vertices. | |
3615 | TopExp::Vertices(E, V[0], V[1]); | |
3616 | ||
3617 | for (Standard_Integer i = 0; i <= 1; i++) { | |
3618 | if (View.Add(V[i])) { | |
3619 | Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(V[i].TShape()); | |
3620 | TV->Tolerance(0.); | |
3621 | BRepCheck_Vertex VertexCorrector(V[i]); | |
99c9a820 | 3622 | V[i].Locked (Standard_False); |
4560c054 | 3623 | B.UpdateVertex(V[i], VertexCorrector.Tolerance()); |
3624 | // use the occasion to clean the vertices. | |
3625 | (TV->ChangePoints()).Clear(); | |
3626 | } | |
3627 | B.UpdateVertex(V[i], Tol); | |
9b7f3f83 | 3628 | } |
7fd59977 | 3629 | } |
3630 | } | |
3631 | } | |
3632 | } | |
3633 | ||
db2f1498 | 3634 | //======================================================================= |
3635 | //function : CorrectSolid | |
3636 | //purpose : | |
3637 | //======================================================================= | |
3638 | void CorrectSolid(TopoDS_Solid& theSol, TopTools_ListOfShape& theSolList) | |
3639 | { | |
3640 | BRep_Builder aBB; | |
3641 | TopoDS_Shape anOuterShell; | |
3642 | NCollection_List<Standard_Real> aVols; | |
3643 | Standard_Real aVolMax = 0., anOuterVol = 0.; | |
3644 | ||
3645 | TopoDS_Iterator anIt(theSol); | |
3646 | for(; anIt.More(); anIt.Next()) | |
3647 | { | |
3648 | const TopoDS_Shape& aSh = anIt.Value(); | |
3649 | GProp_GProps aVProps; | |
3650 | BRepGProp::VolumeProperties(aSh, aVProps, Standard_True); | |
3651 | if(Abs(aVProps.Mass()) > aVolMax) | |
3652 | { | |
3653 | anOuterVol = aVProps.Mass(); | |
3654 | aVolMax = Abs(anOuterVol); | |
3655 | anOuterShell = aSh; | |
3656 | } | |
3657 | aVols.Append(aVProps.Mass()); | |
3658 | } | |
3659 | // | |
ecf4f17c | 3660 | if (Abs(anOuterVol) < Precision::Confusion()) { |
3661 | return; | |
3662 | } | |
db2f1498 | 3663 | if(anOuterVol < 0.) |
3664 | { | |
3665 | anOuterShell.Reverse(); | |
3666 | } | |
3667 | TopoDS_Solid aNewSol; | |
3668 | aBB.MakeSolid(aNewSol); | |
3669 | aNewSol.Closed(Standard_True); | |
3670 | aBB.Add(aNewSol, anOuterShell); | |
3671 | BRepClass3d_SolidClassifier aSolClass(aNewSol); | |
3672 | // | |
3673 | anIt.Initialize(theSol); | |
3674 | NCollection_List<Standard_Real>::Iterator aVIt(aVols); | |
3675 | for(; anIt.More(); anIt.Next(), aVIt.Next()) | |
3676 | { | |
3677 | TopoDS_Shell aSh = TopoDS::Shell(anIt.Value()); | |
3678 | if(aSh.IsSame(anOuterShell)) | |
3679 | { | |
3680 | continue; | |
3681 | } | |
3682 | else | |
3683 | { | |
3684 | TopExp_Explorer aVExp(aSh, TopAbs_VERTEX); | |
3685 | const TopoDS_Vertex& aV = TopoDS::Vertex(aVExp.Current()); | |
3686 | gp_Pnt aP = BRep_Tool::Pnt(aV); | |
3687 | aSolClass.Perform(aP, BRep_Tool::Tolerance(aV)); | |
3688 | if(aSolClass.State() == TopAbs_IN) | |
3689 | { | |
3690 | if(aVIt.Value() > 0.) | |
3691 | { | |
3692 | aSh.Reverse(); | |
3693 | } | |
3694 | aBB.Add(aNewSol, aSh); | |
3695 | } | |
3696 | else | |
3697 | { | |
3698 | if(aVIt.Value() < 0.) | |
3699 | { | |
3700 | aSh.Reverse(); | |
3701 | } | |
3702 | TopoDS_Solid aSol; | |
3703 | aBB.MakeSolid(aSol); | |
3704 | aSol.Closed(Standard_True); | |
3705 | aBB.Add(aSol, aSh); | |
3706 | theSolList.Append(aSol); | |
3707 | } | |
3708 | } | |
3709 | } | |
3710 | theSol = aNewSol; | |
3711 | } | |
e1ed38e0 | 3712 | |
3713 | //======================================================================= | |
3714 | //function : CheckInputData | |
21c7c457 | 3715 | //purpose : Check input data for possibility of offset perform. |
e1ed38e0 | 3716 | //======================================================================= |
3717 | Standard_Boolean BRepOffset_MakeOffset::CheckInputData() | |
3718 | { | |
3719 | // Set initial error state. | |
3720 | myError = BRepOffset_NoError; | |
3721 | TopoDS_Shape aTmpShape; | |
3722 | myBadShape = aTmpShape; | |
3723 | ||
3724 | // Non-null offset. | |
3725 | if (Abs(myOffset) <= myTol) | |
3726 | { | |
3727 | Standard_Boolean isFound = Standard_False; | |
3728 | TopTools_DataMapIteratorOfDataMapOfShapeReal anIter(myFaceOffset); | |
3729 | for( ; anIter.More(); anIter.Next()) | |
3730 | { | |
3731 | if (Abs(anIter.Value()) > myTol) | |
3732 | { | |
3733 | isFound = Standard_True; | |
3734 | break; | |
3735 | } | |
3736 | } | |
3737 | ||
3738 | if (!isFound) | |
3739 | { | |
3740 | // No face with non-null offset found. | |
3741 | myError = BRepOffset_NullOffset; | |
3742 | return Standard_False; | |
3743 | } | |
3744 | } | |
3745 | ||
3746 | // Connectivity of input shape. | |
99c9a820 | 3747 | if (!IsConnectedShell(myFaceComp)) |
e1ed38e0 | 3748 | { |
3749 | myError = BRepOffset_NotConnectedShell; | |
3750 | return Standard_False; | |
3751 | } | |
3752 | ||
3753 | // Normals check and continuity check. | |
3754 | const Standard_Integer aPntPerDim = 20; // 21 points on each dimension. | |
3755 | Standard_Real aUmin, aUmax, aVmin, aVmax; | |
99c9a820 | 3756 | TopExp_Explorer anExpSF(myFaceComp, TopAbs_FACE); |
e1ed38e0 | 3757 | NCollection_Map<Handle(TopoDS_TShape)> aPresenceMap; |
3758 | TopLoc_Location L; | |
3759 | gp_Pnt2d aPnt2d; | |
3760 | for( ; anExpSF.More(); anExpSF.Next()) | |
3761 | { | |
3762 | const TopoDS_Face& aF = TopoDS::Face(anExpSF.Current()); | |
3763 | ||
3764 | if (aPresenceMap.Contains(aF.TShape())) | |
3765 | { | |
3766 | // Not perform computations with partner shapes, | |
3767 | // since they are contain same geometry. | |
3768 | continue; | |
3769 | } | |
3770 | aPresenceMap.Add(aF.TShape()); | |
3771 | ||
3772 | const Handle(Geom_Surface)& aSurf = BRep_Tool::Surface(aF, L); | |
3773 | BRepTools::UVBounds(aF, aUmin, aUmax, aVmin, aVmax); | |
3774 | ||
3775 | // Continuity check. | |
3776 | if (aSurf->Continuity() == GeomAbs_C0) | |
3777 | { | |
3778 | myError = BRepOffset_C0Geometry; | |
3779 | return Standard_False; | |
3780 | } | |
3781 | ||
3782 | // Get degenerated points, to avoid check them. | |
3783 | NCollection_Vector<gp_Pnt> aBad3dPnts; | |
3784 | TopExp_Explorer anExpFE(aF, TopAbs_EDGE); | |
3785 | for( ; anExpFE.More(); anExpFE.Next()) | |
3786 | { | |
3787 | const TopoDS_Edge &aE = TopoDS::Edge(anExpFE.Current()); | |
3788 | if (BRep_Tool::Degenerated(aE)) | |
3789 | { | |
3790 | aBad3dPnts.Append(BRep_Tool::Pnt((TopExp::FirstVertex(aE)))); | |
3791 | } | |
3792 | } | |
3793 | ||
3794 | // Geometry grid check. | |
3795 | for(Standard_Integer i = 0; i <= aPntPerDim; i++) | |
3796 | { | |
3797 | Standard_Real aUParam = aUmin + (aUmax - aUmin) * i / aPntPerDim; | |
3798 | for(Standard_Integer j = 0; j <= aPntPerDim; j++) | |
3799 | { | |
3800 | Standard_Real aVParam = aVmin + (aVmax - aVmin) * j / aPntPerDim; | |
3801 | ||
3802 | myError = checkSinglePoint(aUParam, aVParam, aSurf, aBad3dPnts); | |
3803 | if (myError != BRepOffset_NoError) | |
3804 | return Standard_False; | |
3805 | } | |
3806 | } | |
3807 | ||
3808 | // Vertex list check. | |
3809 | TopExp_Explorer anExpFV(aF, TopAbs_VERTEX); | |
3810 | for( ; anExpFV.More(); anExpFV.Next()) | |
3811 | { | |
3812 | const TopoDS_Vertex &aV = TopoDS::Vertex(anExpFV.Current()); | |
3813 | aPnt2d = BRep_Tool::Parameters(aV, aF); | |
3814 | ||
3815 | myError = checkSinglePoint(aPnt2d.X(), aPnt2d.Y(), aSurf, aBad3dPnts); | |
3816 | if (myError != BRepOffset_NoError) | |
3817 | return Standard_False; | |
3818 | } | |
3819 | } | |
3820 | ||
3821 | return Standard_True; | |
3822 | } | |
3823 | ||
3824 | ||
3825 | //======================================================================= | |
3826 | //function : GetBadShape | |
3827 | //purpose : Get shape where problems detected. | |
3828 | //======================================================================= | |
3829 | const TopoDS_Shape& BRepOffset_MakeOffset::GetBadShape() const | |
3830 | { | |
3831 | return myBadShape; | |
3832 | } | |
3833 | ||
9b7f3f83 | 3834 | //======================================================================= |
3835 | //function : RemoveInternalEdges | |
3836 | //purpose : | |
3837 | //======================================================================= | |
3838 | void BRepOffset_MakeOffset::RemoveInternalEdges() | |
3839 | { | |
3840 | Standard_Boolean bRemoveWire, bRemoveEdge; | |
3841 | TopExp_Explorer aExpF, aExpW, aExpE; | |
3842 | TopTools_IndexedDataMapOfShapeListOfShape aDMELF; | |
3843 | // | |
3844 | TopExp::MapShapesAndAncestors(myOffsetShape, TopAbs_EDGE, TopAbs_FACE, aDMELF); | |
3845 | // | |
3846 | aExpF.Init(myOffsetShape, TopAbs_FACE); | |
3847 | for (; aExpF.More(); aExpF.Next()) { | |
3848 | TopoDS_Face& aF = *(TopoDS_Face*)&aExpF.Current(); | |
3849 | // | |
3850 | TopTools_ListOfShape aLIW; | |
3851 | // | |
3852 | aExpW.Init(aF, TopAbs_WIRE); | |
3853 | for (; aExpW.More(); aExpW.Next()) { | |
3854 | TopoDS_Wire& aW = *(TopoDS_Wire*)&aExpW.Current(); | |
3855 | // | |
3856 | bRemoveWire = Standard_True; | |
3857 | TopTools_ListOfShape aLIE; | |
3858 | // | |
3859 | aExpE.Init(aW, TopAbs_EDGE); | |
3860 | for (; aExpE.More(); aExpE.Next()) { | |
3861 | const TopoDS_Edge& aE = *(TopoDS_Edge*)&aExpE.Current(); | |
3862 | if (aE.Orientation() != TopAbs_INTERNAL) { | |
3863 | bRemoveWire = Standard_False; | |
3864 | continue; | |
3865 | } | |
3866 | // | |
3867 | const TopTools_ListOfShape& aLF = aDMELF.FindFromKey(aE); | |
3868 | bRemoveEdge = (aLF.Extent() == 1); | |
3869 | if (bRemoveEdge) { | |
3870 | aLIE.Append(aE); | |
3871 | } | |
3872 | else { | |
3873 | bRemoveWire = Standard_False; | |
3874 | } | |
3875 | } | |
3876 | // | |
3877 | if (bRemoveWire) { | |
3878 | aLIW.Append(aW); | |
3879 | } | |
3880 | else if (aLIE.Extent()) { | |
3881 | RemoveShapes(aW, aLIE); | |
3882 | } | |
3883 | } | |
3884 | // | |
3885 | if (aLIW.Extent()) { | |
3886 | RemoveShapes(aF, aLIW); | |
3887 | } | |
3888 | } | |
3889 | } | |
3890 | ||
3891 | //======================================================================= | |
3892 | // static methods implementation | |
3893 | //======================================================================= | |
e1ed38e0 | 3894 | |
3895 | //======================================================================= | |
3896 | //function : checkSinglePoint | |
3897 | //purpose : Check single point on surface for bad normals | |
3898 | //======================================================================= | |
3899 | BRepOffset_Error checkSinglePoint(const Standard_Real theUParam, | |
3900 | const Standard_Real theVParam, | |
3901 | const Handle(Geom_Surface)& theSurf, | |
3902 | const NCollection_Vector<gp_Pnt>& theBadPoints) | |
3903 | { | |
3904 | gp_Pnt aPnt; | |
3905 | gp_Vec aD1U, aD1V; | |
3906 | theSurf->D1(theUParam, theVParam, aPnt, aD1U, aD1V); | |
3907 | ||
3908 | if (aD1U.SquareMagnitude() < Precision::SquareConfusion() || | |
3909 | aD1V.SquareMagnitude() < Precision::SquareConfusion() ) | |
3910 | { | |
3911 | Standard_Boolean isKnownBadPnt = Standard_False; | |
3912 | for(Standard_Integer anIdx = theBadPoints.Lower(); | |
3913 | anIdx <= theBadPoints.Upper(); | |
3914 | ++anIdx) | |
3915 | { | |
3916 | if (aPnt.SquareDistance(theBadPoints(anIdx)) < Precision::SquareConfusion()) | |
3917 | { | |
3918 | isKnownBadPnt = Standard_True; | |
3919 | break; | |
3920 | } | |
3921 | } // for(Standard_Integer anIdx = theBadPoints.Lower(); | |
3922 | ||
3923 | if (!isKnownBadPnt) | |
3924 | { | |
3925 | return BRepOffset_BadNormalsOnGeometry; | |
3926 | } | |
3927 | else | |
3928 | { | |
3929 | return BRepOffset_NoError; | |
3930 | } | |
3931 | } // if (aD1U.SquareMagnitude() < Precision::SquareConfusion() || | |
3932 | ||
3933 | if (aD1U.IsParallel(aD1V, Precision::Confusion())) | |
3934 | { | |
3935 | // Isolines are collinear. | |
3936 | return BRepOffset_BadNormalsOnGeometry; | |
3937 | } | |
3938 | ||
3939 | return BRepOffset_NoError; | |
3940 | } | |
9b7f3f83 | 3941 | |
3942 | //======================================================================= | |
3943 | //function : RemoveShapes | |
3944 | //purpose : Removes the shapes <theLS> from the shape <theS> | |
3945 | //======================================================================= | |
3946 | void RemoveShapes(TopoDS_Shape& theS, | |
3947 | const TopTools_ListOfShape& theLS) | |
3948 | { | |
3949 | BRep_Builder aBB; | |
3950 | // | |
3951 | Standard_Boolean bFree = theS.Free(); | |
3952 | theS.Free(Standard_True); | |
3953 | // | |
3954 | TopTools_ListIteratorOfListOfShape aIt(theLS); | |
3955 | for (; aIt.More(); aIt.Next()) { | |
3956 | const TopoDS_Shape& aSI = aIt.Value(); | |
3957 | aBB.Remove(theS, aSI); | |
3958 | } | |
3959 | // | |
3960 | theS.Free(bFree); | |
3961 | } | |
3962 | ||
3963 | //======================================================================= | |
ecf4f17c | 3964 | //function : UpdateHistory |
3965 | //purpose : Updates the history information | |
9b7f3f83 | 3966 | //======================================================================= |
ecf4f17c | 3967 | void UpdateHistory(const TopTools_ListOfShape& theLF, |
3968 | BOPAlgo_Builder& theGF, | |
3969 | BRepAlgo_Image& theImage) | |
9b7f3f83 | 3970 | { |
ecf4f17c | 3971 | TopTools_ListIteratorOfListOfShape aIt(theLF); |
3972 | for (; aIt.More(); aIt.Next()) { | |
3973 | const TopoDS_Shape& aF = aIt.Value(); | |
3974 | const TopTools_ListOfShape& aLFIm = theGF.Modified(aF); | |
3975 | if (aLFIm.Extent()) { | |
3976 | if (theImage.HasImage(aF)) { | |
3977 | theImage.Add(aF, aLFIm); | |
9b7f3f83 | 3978 | } |
3979 | else { | |
ecf4f17c | 3980 | theImage.Bind(aF, aLFIm); |
9b7f3f83 | 3981 | } |
3982 | } | |
9b7f3f83 | 3983 | } |
3984 | } | |
3985 | ||
3986 | //======================================================================= | |
ecf4f17c | 3987 | //function : IntersectEdges |
9b7f3f83 | 3988 | //purpose : |
3989 | //======================================================================= | |
420b38fd | 3990 | void BRepOffset_MakeOffset::IntersectEdges(const TopTools_ListOfShape& theFaces, |
ecf4f17c | 3991 | BRepOffset_DataMapOfShapeOffset& theMapSF, |
3992 | TopTools_DataMapOfShapeShape& theMES, | |
3993 | TopTools_DataMapOfShapeShape& theBuild, | |
3994 | Handle(BRepAlgo_AsDes)& theAsDes, | |
3995 | Handle(BRepAlgo_AsDes)& theAsDes2d) | |
9b7f3f83 | 3996 | { |
ecf4f17c | 3997 | Standard_Real aTolF; |
3998 | TopTools_IndexedDataMapOfShapeListOfShape aDMVV; | |
ecf4f17c | 3999 | // intersect edges created from edges |
4000 | TopTools_IndexedMapOfShape aMFV; | |
420b38fd | 4001 | for (TopTools_ListOfShape::Iterator it (theFaces); it.More(); it.Next()) |
4002 | { | |
4003 | const TopoDS_Face& aF = TopoDS::Face (it.Value()); | |
4004 | aTolF = BRep_Tool::Tolerance (aF); | |
8948e18d | 4005 | if (!BRepOffset_Inter2d::ConnexIntByInt(aF, theMapSF(aF), theMES, theBuild, theAsDes, theAsDes2d, |
4006 | myOffset, aTolF, myAnalyse, aMFV, myImageVV, myEdgeIntEdges, aDMVV)) | |
3e85dfc5 | 4007 | { |
4008 | myError = BRepOffset_CannotExtentEdge; | |
4009 | return; | |
4010 | } | |
9b7f3f83 | 4011 | } |
ecf4f17c | 4012 | // intersect edges created from vertices |
4013 | Standard_Integer i, aNbF = aMFV.Extent(); | |
4014 | for (i = 1; i <= aNbF; ++i) { | |
4015 | const TopoDS_Face& aF = TopoDS::Face(aMFV(i)); | |
4016 | aTolF = BRep_Tool::Tolerance(aF); | |
4017 | BRepOffset_Inter2d::ConnexIntByIntInVert | |
420b38fd | 4018 | (aF, theMapSF(aF), theMES, theBuild, theAsDes, theAsDes2d, aTolF, myAnalyse, aDMVV); |
ecf4f17c | 4019 | } |
4020 | // | |
4021 | // fuse vertices on edges | |
8948e18d | 4022 | if (!BRepOffset_Inter2d::FuseVertices(aDMVV, theAsDes2d, myImageVV)) |
3e85dfc5 | 4023 | { |
4024 | myError = BRepOffset_CannotFuseVertices; | |
4025 | return; | |
4026 | } | |
9b7f3f83 | 4027 | } |
4028 | ||
4029 | //======================================================================= | |
ecf4f17c | 4030 | //function : TrimEdges |
9b7f3f83 | 4031 | //purpose : |
4032 | //======================================================================= | |
3e85dfc5 | 4033 | Standard_Boolean TrimEdges(const TopoDS_Shape& theShape, |
4034 | const Standard_Real theOffset, | |
4035 | const BRepOffset_Analyse& Analyse, | |
4036 | BRepOffset_DataMapOfShapeOffset& theMapSF, | |
4037 | TopTools_DataMapOfShapeShape& theMES, | |
4038 | TopTools_DataMapOfShapeShape& theBuild, | |
4039 | Handle(BRepAlgo_AsDes)& theAsDes, | |
4040 | Handle(BRepAlgo_AsDes)& theAsDes2d, | |
4041 | TopTools_IndexedMapOfShape& theNewEdges, | |
4042 | TopTools_DataMapOfShapeShape& theETrimEInf, | |
4043 | TopTools_DataMapOfShapeListOfShape& theEdgesOrigins) | |
9b7f3f83 | 4044 | { |
ecf4f17c | 4045 | TopExp_Explorer Exp,Exp2,ExpC; |
4046 | TopoDS_Shape NE; | |
4047 | TopoDS_Edge TNE; | |
4048 | TopoDS_Face NF; | |
420b38fd | 4049 | |
4050 | TopTools_ListOfShape aLFaces; | |
4051 | for (Exp.Init (theShape, TopAbs_FACE); Exp.More(); Exp.Next()) | |
4052 | aLFaces.Append (Exp.Current()); | |
4053 | ||
4054 | TopTools_MapOfShape aMFGenerated; | |
4055 | TopTools_IndexedDataMapOfShapeListOfShape aDMEF; | |
4056 | for (TopTools_ListOfShape::Iterator it (Analyse.NewFaces()); it.More(); it.Next()) | |
4057 | { | |
4058 | const TopoDS_Shape& aFG = it.Value(); | |
4059 | aLFaces.Append (aFG); | |
4060 | aMFGenerated.Add (aFG); | |
4061 | TopExp::MapShapesAndUniqueAncestors (aFG, TopAbs_EDGE, TopAbs_FACE, aDMEF); | |
4062 | } | |
4063 | ||
4064 | for (TopTools_ListOfShape::Iterator it (aLFaces); it.More(); it.Next()) | |
4065 | { | |
4066 | const TopoDS_Face& FI = TopoDS::Face (it.Value()); | |
ecf4f17c | 4067 | NF = theMapSF(FI).Face(); |
4068 | if (theMES.IsBound(NF)) { | |
4069 | NF = TopoDS::Face(theMES(NF)); | |
9b7f3f83 | 4070 | } |
4071 | // | |
ecf4f17c | 4072 | TopTools_MapOfShape View; |
4073 | TopTools_IndexedMapOfShape VEmap; | |
4074 | Standard_Integer i, aNb; | |
9b7f3f83 | 4075 | // |
ecf4f17c | 4076 | TopExp::MapShapes(FI.Oriented(TopAbs_FORWARD), TopAbs_EDGE , VEmap); |
4077 | TopExp::MapShapes(FI.Oriented(TopAbs_FORWARD), TopAbs_VERTEX, VEmap); | |
4078 | // | |
4079 | aNb = VEmap.Extent(); | |
4080 | for (i = 1; i <= aNb; ++i) { | |
4081 | const TopoDS_Shape& aS = VEmap(i); | |
4082 | if (!View.Add(aS)) { | |
9b7f3f83 | 4083 | continue; |
4084 | } | |
4085 | // | |
ecf4f17c | 4086 | if (theBuild.IsBound(aS)) { |
4087 | NE = theBuild(aS); | |
4088 | // keep connection to original edges | |
4089 | ExpC.Init(NE, TopAbs_EDGE); | |
4090 | for (; ExpC.More(); ExpC.Next()) { | |
4091 | const TopoDS_Edge& NEC = TopoDS::Edge(ExpC.Current()); | |
4092 | TopTools_ListOfShape* pLEOr = theEdgesOrigins.ChangeSeek(NEC); | |
4093 | if (!pLEOr) { | |
4094 | pLEOr = theEdgesOrigins.Bound(NEC, TopTools_ListOfShape()); | |
4095 | } | |
4096 | AppendToList(*pLEOr, aS); | |
9b7f3f83 | 4097 | } |
ecf4f17c | 4098 | // trim edges |
4099 | if (NE.ShapeType() == TopAbs_EDGE) { | |
4100 | if (theNewEdges.Add(NE)) { | |
3e85dfc5 | 4101 | if (!TrimEdge (TopoDS::Edge(NE),theAsDes2d,theAsDes, theETrimEInf)) |
4102 | return Standard_False; | |
ecf4f17c | 4103 | } |
4104 | } | |
4105 | else { | |
4106 | //------------------------------------------------------------ | |
4107 | // The Intersections are on several edges. | |
4108 | // The pieces without intersections with neighbors | |
4109 | // are removed from AsDes. | |
4110 | //------------------------------------------------------------ | |
4111 | for (ExpC.Init(NE,TopAbs_EDGE); ExpC.More(); ExpC.Next()) { | |
4112 | TopoDS_Edge NEC = TopoDS::Edge(ExpC.Current()); | |
4113 | if (theNewEdges.Add(NEC)) { | |
4114 | if (!theAsDes2d->Descendant(NEC).IsEmpty()) { | |
3e85dfc5 | 4115 | if(!TrimEdge (NEC,theAsDes2d, theAsDes, theETrimEInf)) |
4116 | return Standard_False; | |
ecf4f17c | 4117 | } |
4118 | else { | |
4119 | if (theAsDes->HasAscendant(NEC)) { | |
4120 | theAsDes->Remove(NEC); | |
4121 | } | |
4122 | } | |
4123 | } | |
4124 | } | |
9b7f3f83 | 4125 | } |
4126 | } | |
ecf4f17c | 4127 | else { |
4128 | if (aS.ShapeType() != TopAbs_EDGE) { | |
4129 | continue; | |
4130 | } | |
420b38fd | 4131 | if (aMFGenerated.Contains (FI) && aDMEF.FindFromKey (aS).Extent() == 1) |
4132 | continue; | |
4133 | ||
ecf4f17c | 4134 | NE = theMapSF(FI).Generated(aS); |
4135 | //// modified by jgv, 19.12.03 for OCC4455 //// | |
4136 | NE.Orientation(aS.Orientation()); | |
4137 | // | |
4138 | TopTools_ListOfShape* pLEOr = theEdgesOrigins.ChangeSeek(NE); | |
4139 | if (!pLEOr) { | |
4140 | pLEOr = theEdgesOrigins.Bound(NE, TopTools_ListOfShape()); | |
4141 | } | |
4142 | AppendToList(*pLEOr, aS); | |
4143 | // | |
4144 | if (theMES.IsBound(NE)) { | |
4145 | NE = theMES(NE); | |
4146 | NE.Orientation(aS.Orientation()); | |
4147 | if (theNewEdges.Add(NE)) { | |
3e85dfc5 | 4148 | if (!TrimEdge (TopoDS::Edge(NE), theAsDes2d, theAsDes, theETrimEInf)) |
4149 | return Standard_False; | |
ecf4f17c | 4150 | } |
4151 | } | |
4152 | else { | |
4153 | TopoDS_Edge& anEdge = TopoDS::Edge(NE); | |
4154 | BRepAdaptor_Curve aBAC(anEdge); | |
4155 | if (aBAC.GetType() == GeomAbs_Line) { | |
4156 | TopoDS_Edge aNewEdge; | |
4157 | BRepOffset_Inter2d::ExtentEdge(anEdge, aNewEdge, theOffset); | |
4158 | theETrimEInf.Bind(anEdge, aNewEdge); | |
4159 | } | |
4160 | } | |
4161 | theAsDes->Add(NF,NE); | |
4162 | } | |
9b7f3f83 | 4163 | } |
4164 | } | |
3e85dfc5 | 4165 | return Standard_True; |
9b7f3f83 | 4166 | } |
4167 | ||
4168 | //======================================================================= | |
ecf4f17c | 4169 | //function : TrimEdge |
4170 | //purpose : Trim the edge of the largest of descendants in AsDes2d. | |
4171 | // Order in AsDes two vertices that have trimmed the edge. | |
9b7f3f83 | 4172 | //======================================================================= |
3e85dfc5 | 4173 | Standard_Boolean TrimEdge(TopoDS_Edge& NE, |
ecf4f17c | 4174 | const Handle(BRepAlgo_AsDes)& AsDes2d, |
4175 | Handle(BRepAlgo_AsDes)& AsDes, | |
4176 | TopTools_DataMapOfShapeShape& theETrimEInf) | |
9b7f3f83 | 4177 | { |
ecf4f17c | 4178 | TopoDS_Edge aSourceEdge; |
4179 | TopoDS_Vertex V1,V2; | |
4180 | Standard_Real aT1, aT2; | |
9b7f3f83 | 4181 | // |
ecf4f17c | 4182 | TopExp::Vertices(NE, V1, V2); |
4183 | BRep_Tool::Range(NE, aT1, aT2); | |
4184 | // | |
4185 | BOPTools_AlgoTools::MakeSplitEdge(NE, V1, aT1, V2, aT2, aSourceEdge); | |
4186 | // | |
4187 | // | |
4188 | Standard_Real aSameParTol = Precision::Confusion(); | |
4189 | ||
4190 | Standard_Real U = 0.; | |
4191 | Standard_Real UMin = Precision::Infinite(); | |
4192 | Standard_Real UMax = -UMin; | |
4193 | ||
4194 | const TopTools_ListOfShape& LE = AsDes2d->Descendant(NE); | |
4195 | // | |
4196 | Standard_Boolean bTrim = Standard_False; | |
4197 | // | |
4198 | if (LE.Extent() > 1) { | |
4199 | TopTools_ListIteratorOfListOfShape it (LE); | |
4200 | for (; it.More(); it.Next()) { | |
4201 | TopoDS_Vertex V = TopoDS::Vertex(it.Value()); | |
4202 | if (NE.Orientation() == TopAbs_REVERSED) | |
4203 | V.Reverse(); | |
4204 | //V.Orientation(TopAbs_INTERNAL); | |
4205 | if (!FindParameter(V, NE, U)) { | |
4206 | Standard_Real f, l; | |
4207 | Handle(Geom_Curve) theCurve = BRep_Tool::Curve(NE, f, l); | |
4208 | gp_Pnt thePoint = BRep_Tool::Pnt(V); | |
4209 | GeomAPI_ProjectPointOnCurve Projector(thePoint, theCurve); | |
4210 | if (Projector.NbPoints() == 0) | |
3e85dfc5 | 4211 | { |
4212 | return Standard_False; | |
4213 | } | |
ecf4f17c | 4214 | U = Projector.LowerDistanceParameter(); |
4215 | } | |
4216 | if (U < UMin) { | |
4217 | UMin = U; V1 = V; | |
4218 | } | |
4219 | if (U > UMax) { | |
4220 | UMax = U; V2 = V; | |
4221 | } | |
4222 | } | |
4223 | // | |
4224 | if (V1.IsNull() || V2.IsNull()) { | |
3e85dfc5 | 4225 | return Standard_False; |
ecf4f17c | 4226 | } |
4227 | if (!V1.IsSame(V2)) { | |
4228 | NE.Free( Standard_True ); | |
4229 | BRep_Builder B; | |
4230 | TopAbs_Orientation Or = NE.Orientation(); | |
4231 | NE.Orientation(TopAbs_FORWARD); | |
4232 | TopoDS_Vertex VF,VL; | |
4233 | TopExp::Vertices (NE,VF,VL); | |
4234 | B.Remove(NE,VF); | |
4235 | B.Remove(NE,VL); | |
4236 | B.Add (NE,V1.Oriented(TopAbs_FORWARD)); | |
4237 | B.Add (NE,V2.Oriented(TopAbs_REVERSED)); | |
4238 | B.Range(NE,UMin,UMax); | |
4239 | NE.Orientation(Or); | |
4240 | AsDes->Add(NE,V1.Oriented(TopAbs_FORWARD)); | |
4241 | AsDes->Add(NE,V2.Oriented(TopAbs_REVERSED)); | |
4242 | BRepLib::SameParameter(NE, aSameParTol, Standard_True); | |
9b7f3f83 | 4243 | // |
ecf4f17c | 4244 | bTrim = Standard_True; |
9b7f3f83 | 4245 | } |
4246 | } | |
4247 | // | |
ecf4f17c | 4248 | if (!bTrim) { |
4249 | BRepAdaptor_Curve aBAC(NE); | |
4250 | if (aBAC.GetType() == GeomAbs_Line) { | |
4251 | if (AsDes->HasAscendant(NE)) { | |
4252 | AsDes->Remove(NE); | |
4253 | } | |
4254 | } | |
4255 | } | |
4256 | else | |
4257 | { | |
4258 | if (!theETrimEInf.IsBound(NE)) { | |
4259 | theETrimEInf.Bind(NE, aSourceEdge); | |
4260 | } | |
4261 | } | |
3e85dfc5 | 4262 | return Standard_True; |
9b7f3f83 | 4263 | } |
4264 | ||
4265 | //======================================================================= | |
ecf4f17c | 4266 | //function : GetEnlargedFaces |
9b7f3f83 | 4267 | //purpose : |
4268 | //======================================================================= | |
420b38fd | 4269 | void GetEnlargedFaces(const TopTools_ListOfShape& theFaces, |
ecf4f17c | 4270 | const BRepOffset_DataMapOfShapeOffset& theMapSF, |
4271 | const TopTools_DataMapOfShapeShape& theMES, | |
4272 | TopTools_DataMapOfShapeShape& theFacesOrigins, | |
4273 | BRepAlgo_Image& theImage, | |
4274 | TopTools_ListOfShape& theLSF) | |
9b7f3f83 | 4275 | { |
420b38fd | 4276 | for (TopTools_ListOfShape::Iterator it (theFaces); it.More(); it.Next()) |
4277 | { | |
4278 | const TopoDS_Shape& FI = it.Value(); | |
ecf4f17c | 4279 | const TopoDS_Shape& OFI = theMapSF(FI).Face(); |
4280 | if (theMES.IsBound(OFI)) { | |
4281 | const TopoDS_Face& aLocalFace = TopoDS::Face(theMES(OFI)); | |
4282 | theLSF.Append(aLocalFace); | |
4283 | theImage.SetRoot(aLocalFace); | |
ecf4f17c | 4284 | theFacesOrigins.Bind(aLocalFace, FI); |
4285 | } | |
4286 | } | |
4287 | } | |
4288 | ||
4289 | //======================================================================= | |
4290 | //function : BuildShellsCompleteInter | |
4291 | //purpose : Make the shells from list of faces using MakerVolume algorithm. | |
4292 | // In case there will be more than just one solid, it will be | |
4293 | // rebuilt using only outer faces. | |
4294 | //======================================================================= | |
1155d05a | 4295 | Standard_Boolean BuildShellsCompleteInter(const TopTools_ListOfShape& theLF, |
ecf4f17c | 4296 | BRepAlgo_Image& theImage, |
4297 | TopoDS_Shape& theShells) | |
4298 | { | |
4299 | // make solids | |
4300 | BOPAlgo_MakerVolume aMV1; | |
4301 | aMV1.SetArguments(theLF); | |
4302 | // we need to intersect the faces to process the tangential faces | |
4303 | aMV1.SetIntersect(Standard_True); | |
291fced1 | 4304 | aMV1.SetAvoidInternalShapes(Standard_True); |
ecf4f17c | 4305 | aMV1.Perform(); |
9b7f3f83 | 4306 | // |
33ba8565 | 4307 | Standard_Boolean bDone = ! aMV1.HasErrors(); |
ecf4f17c | 4308 | if (!bDone) { |
9b7f3f83 | 4309 | return bDone; |
4310 | } | |
4311 | // | |
ecf4f17c | 4312 | UpdateHistory(theLF, aMV1, theImage); |
9b7f3f83 | 4313 | // |
ecf4f17c | 4314 | const TopoDS_Shape& aResult1 = aMV1.Shape(); |
4315 | if (aResult1.ShapeType() == TopAbs_SOLID) { | |
4316 | // result is the alone solid, nothing to do | |
4317 | return GetSubShapes(aResult1, TopAbs_SHELL, theShells); | |
4318 | } | |
e7384fd4 | 4319 | |
4320 | // Allocators for effective memory allocations | |
4321 | // Global allocator for the long-living containers | |
4322 | Handle(NCollection_IncAllocator) anAllocGlob = new NCollection_IncAllocator; | |
4323 | // Local allocator for the local containers | |
4324 | Handle(NCollection_IncAllocator) anAllocLoc = new NCollection_IncAllocator; | |
4325 | ||
4326 | // Since the <theImage> object does not support multiple ancestors, | |
4327 | // prepare local copy of the origins, which will be used to resolve | |
4328 | // non-manifold solids produced by Maker Volume algorithm by comparison | |
4329 | // of the normal directions of the split faces with their origins. | |
4330 | TopTools_DataMapOfShapeListOfShape anOrigins(1, anAllocGlob); | |
4331 | TopTools_ListIteratorOfListOfShape aItLR(theImage.Roots()); | |
4332 | for (; aItLR.More(); aItLR.Next()) | |
4333 | { | |
4334 | const TopoDS_Shape& aFR = aItLR.Value(); | |
4335 | ||
4336 | // Reset the local allocator | |
4337 | anAllocLoc->Reset(); | |
4338 | // Find the last splits of the root face, including the ones | |
4339 | // created during MakeVolume operation | |
4340 | TopTools_ListOfShape aLFIm(anAllocLoc); | |
4341 | theImage.LastImage(aFR, aLFIm); | |
4342 | ||
4343 | TopTools_ListIteratorOfListOfShape aItLFIm(aLFIm); | |
4344 | for (; aItLFIm.More(); aItLFIm.Next()) | |
4345 | { | |
4346 | const TopoDS_Shape& aFIm = aItLFIm.Value(); | |
4347 | TopTools_ListOfShape *pLFOr = anOrigins.ChangeSeek(aFIm); | |
4348 | if (!pLFOr) { | |
4349 | pLFOr = anOrigins.Bound(aFIm, TopTools_ListOfShape(anAllocGlob)); | |
4350 | } | |
4351 | pLFOr->Append(aFR); | |
4352 | } | |
4353 | } | |
4354 | ||
4355 | // Reset the local allocator | |
4356 | anAllocLoc->Reset(); | |
4357 | // It is necessary to rebuild the solids, avoiding internal faces | |
4358 | // Map faces to solids | |
4359 | TopTools_IndexedDataMapOfShapeListOfShape aDMFS(1, anAllocLoc); | |
ecf4f17c | 4360 | TopExp::MapShapesAndAncestors(aResult1, TopAbs_FACE, TopAbs_SOLID, aDMFS); |
9b7f3f83 | 4361 | // |
ecf4f17c | 4362 | Standard_Integer i, aNb = aDMFS.Extent(); |
4363 | bDone = (aNb > 0); | |
4364 | if (!bDone) { | |
4365 | // unable to build any solid | |
4366 | return bDone; | |
4367 | } | |
9b7f3f83 | 4368 | // |
ecf4f17c | 4369 | // get faces attached to only one solid |
1155d05a | 4370 | TopTools_ListOfShape aLF(anAllocLoc); |
ecf4f17c | 4371 | for (i = 1; i <= aNb; ++i) { |
4372 | const TopTools_ListOfShape& aLS = aDMFS(i); | |
4373 | if (aLS.Extent() == 1) { | |
4374 | const TopoDS_Shape& aF = aDMFS.FindKey(i); | |
e7384fd4 | 4375 | aLF.Append(aF); |
9b7f3f83 | 4376 | } |
4377 | } | |
4378 | // | |
ecf4f17c | 4379 | // make solids from the new list |
4380 | BOPAlgo_MakerVolume aMV2; | |
e7384fd4 | 4381 | aMV2.SetArguments(aLF); |
ecf4f17c | 4382 | // no need to intersect this time |
4383 | aMV2.SetIntersect(Standard_False); | |
291fced1 | 4384 | aMV2.SetAvoidInternalShapes(Standard_True); |
ecf4f17c | 4385 | aMV2.Perform(); |
33ba8565 | 4386 | bDone = ! aMV2.HasErrors(); |
ecf4f17c | 4387 | if (!bDone) { |
4388 | return bDone; | |
9b7f3f83 | 4389 | } |
4390 | // | |
ecf4f17c | 4391 | const TopoDS_Shape& aResult2 = aMV2.Shape(); |
4392 | if (aResult2.ShapeType() == TopAbs_SOLID) { | |
4393 | return GetSubShapes(aResult2, TopAbs_SHELL, theShells); | |
9b7f3f83 | 4394 | } |
4395 | // | |
ecf4f17c | 4396 | TopExp_Explorer aExp(aResult2, TopAbs_FACE); |
4397 | bDone = aExp.More(); | |
4398 | if (!bDone) { | |
4399 | return bDone; | |
9b7f3f83 | 4400 | } |
4401 | // | |
e7384fd4 | 4402 | aLF.Clear(); |
4403 | aDMFS.Clear(); | |
4404 | anAllocLoc->Reset(); | |
4405 | ||
4406 | // the result is non-manifold - resolve it comparing normal | |
ecf4f17c | 4407 | // directions of the offset faces and original faces |
e7384fd4 | 4408 | for (; aExp.More(); aExp.Next()) |
4409 | { | |
ecf4f17c | 4410 | const TopoDS_Face& aF = TopoDS::Face(aExp.Current()); |
e7384fd4 | 4411 | const TopTools_ListOfShape* pLFOr = anOrigins.Seek(aF); |
4412 | if (!pLFOr) | |
4413 | { | |
4414 | Standard_ASSERT_INVOKE("BRepOffset_MakeOffset::BuildShellsCompleteInterSplit(): " | |
4415 | "Origins map does not contain the split face"); | |
ecf4f17c | 4416 | continue; |
4417 | } | |
e7384fd4 | 4418 | // Check orientation |
4419 | TopTools_ListIteratorOfListOfShape aItLOr(*pLFOr); | |
4420 | for (; aItLOr.More(); aItLOr.Next()) | |
4421 | { | |
4422 | const TopoDS_Face& aFOr = TopoDS::Face(aItLOr.Value()); | |
4423 | if (BRepOffset_Tool::CheckPlanesNormals(aF, aFOr)) | |
4424 | { | |
4425 | aLF.Append(aF); | |
9b7f3f83 | 4426 | break; |
4427 | } | |
4428 | } | |
4429 | } | |
4430 | // | |
ecf4f17c | 4431 | // make solid from most outer faces with correct normal direction |
4432 | BOPAlgo_MakerVolume aMV3; | |
e7384fd4 | 4433 | aMV3.SetArguments(aLF); |
ecf4f17c | 4434 | aMV3.SetIntersect(Standard_False); |
291fced1 | 4435 | aMV3.SetAvoidInternalShapes(Standard_True); |
ecf4f17c | 4436 | aMV3.Perform(); |
33ba8565 | 4437 | bDone = ! aMV3.HasErrors(); |
ecf4f17c | 4438 | if (!bDone) { |
4439 | return bDone; | |
4440 | } | |
4441 | // | |
4442 | const TopoDS_Shape& aResult3 = aMV3.Shape(); | |
4443 | return GetSubShapes(aResult3, TopAbs_SHELL, theShells); | |
9b7f3f83 | 4444 | } |
4445 | ||
420b38fd | 4446 | //======================================================================= |
4447 | //function : Generated | |
4448 | //purpose : | |
4449 | //======================================================================= | |
4450 | const TopTools_ListOfShape& BRepOffset_MakeOffset::Generated (const TopoDS_Shape& theS) | |
4451 | { | |
4452 | myGenerated.Clear(); | |
4453 | const TopAbs_ShapeEnum aType = theS.ShapeType(); | |
4454 | switch (aType) | |
4455 | { | |
4456 | case TopAbs_VERTEX: | |
4457 | { | |
4458 | if (myAnalyse.HasAncestor (theS)) | |
4459 | { | |
4460 | TopTools_MapOfShape aMFence; | |
4461 | const TopTools_ListOfShape& aLA = myAnalyse.Ancestors (theS); | |
4462 | TopTools_ListOfShape::Iterator itLA (aLA); | |
4463 | for (; myGenerated.IsEmpty() && itLA.More(); itLA.Next()) | |
4464 | { | |
4465 | const TopoDS_Shape& aE = itLA.Value(); | |
4466 | if (!myInitOffsetEdge.HasImage (aE)) | |
4467 | continue; | |
4468 | TopTools_ListOfShape aLEIm; | |
4469 | myInitOffsetEdge.LastImage (aE, aLEIm); | |
4470 | TopTools_ListOfShape::Iterator itLEIm (aLEIm); | |
4471 | for (; myGenerated.IsEmpty() && itLEIm.More(); itLEIm.Next()) | |
4472 | { | |
4473 | TopoDS_Iterator itV (itLEIm.Value()); | |
4474 | for (; itV.More(); itV.Next()) | |
4475 | { | |
4476 | if (!aMFence.Add (itV.Value())) | |
4477 | { | |
4478 | myGenerated.Append (itV.Value()); | |
4479 | break; | |
4480 | } | |
4481 | } | |
4482 | } | |
4483 | } | |
4484 | } | |
4485 | } | |
4486 | Standard_FALLTHROUGH | |
4487 | case TopAbs_EDGE: | |
4488 | { | |
4489 | if (myInitOffsetEdge.HasImage (theS)) | |
4490 | { | |
4491 | myInitOffsetEdge.LastImage (theS, myGenerated); | |
4492 | } | |
4493 | } | |
4494 | Standard_FALLTHROUGH | |
4495 | case TopAbs_FACE: | |
4496 | { | |
8948e18d | 4497 | TopoDS_Shape aS = theS; |
4498 | const TopoDS_Shape* aPlanface = myFacePlanfaceMap.Seek(aS); | |
4499 | if (aPlanface) | |
4500 | aS = TopoDS::Face(*aPlanface); | |
4501 | ||
4502 | if (!myFaces.Contains (aS) && | |
4503 | myInitOffsetFace.HasImage (aS)) | |
420b38fd | 4504 | { |
8948e18d | 4505 | myInitOffsetFace.LastImage (aS, myGenerated); |
4506 | ||
4507 | if (!myFaces.IsEmpty()) | |
4508 | { | |
4509 | // Reverse generated shapes in case of small solids. | |
4510 | // Useful only for faces without influence on others. | |
4511 | TopTools_ListIteratorOfListOfShape it(myGenerated); | |
4512 | for (; it.More(); it.Next()) | |
4513 | it.Value().Reverse(); | |
4514 | } | |
420b38fd | 4515 | } |
4516 | break; | |
4517 | } | |
4518 | case TopAbs_SOLID: | |
4519 | { | |
4520 | if (theS.IsSame (myShape)) | |
4521 | myGenerated.Append (myOffsetShape); | |
4522 | break; | |
4523 | } | |
4524 | default: | |
4525 | break; | |
4526 | } | |
4527 | ||
4528 | if (myResMap.IsEmpty()) | |
4529 | TopExp::MapShapes (myOffsetShape, myResMap); | |
4530 | ||
4531 | for (TopTools_ListOfShape::Iterator it (myGenerated); it.More();) | |
4532 | { | |
4533 | if (myResMap.Contains (it.Value())) | |
4534 | it.Next(); | |
4535 | else | |
4536 | myGenerated.Remove (it); | |
4537 | } | |
4538 | ||
4539 | return myGenerated; | |
4540 | } | |
4541 | ||
4542 | //======================================================================= | |
4543 | //function : Modified | |
4544 | //purpose : | |
4545 | //======================================================================= | |
8948e18d | 4546 | const TopTools_ListOfShape& BRepOffset_MakeOffset::Modified (const TopoDS_Shape& theShape) |
420b38fd | 4547 | { |
4548 | myGenerated.Clear(); | |
8948e18d | 4549 | |
4550 | if (theShape.ShapeType() == TopAbs_FACE) | |
4551 | { | |
4552 | TopoDS_Shape aS = theShape; | |
4553 | const TopoDS_Shape* aPlanface = myFacePlanfaceMap.Seek(aS); | |
4554 | if (aPlanface) | |
4555 | aS = TopoDS::Face(*aPlanface); | |
4556 | ||
4557 | if (myFaces.Contains (aS) && | |
4558 | myInitOffsetFace.HasImage (aS)) | |
4559 | { | |
4560 | myInitOffsetFace.LastImage (aS, myGenerated); | |
4561 | ||
4562 | if (!myFaces.IsEmpty()) | |
4563 | { | |
4564 | // Reverse generated shapes in case of small solids. | |
4565 | // Useful only for faces without influence on others. | |
4566 | TopTools_ListIteratorOfListOfShape it(myGenerated); | |
4567 | for (; it.More(); it.Next()) | |
4568 | it.Value().Reverse(); | |
4569 | } | |
4570 | } | |
4571 | } | |
4572 | ||
420b38fd | 4573 | return myGenerated; |
4574 | } | |
4575 | ||
4576 | //======================================================================= | |
4577 | //function : IsDeleted | |
4578 | //purpose : | |
4579 | //======================================================================= | |
4580 | Standard_Boolean BRepOffset_MakeOffset::IsDeleted (const TopoDS_Shape& theS) | |
4581 | { | |
4582 | if (myResMap.IsEmpty()) | |
4583 | TopExp::MapShapes (myOffsetShape, myResMap); | |
4584 | ||
4585 | if (myResMap.Contains (theS)) | |
4586 | return Standard_False; | |
4587 | ||
4588 | return Generated (theS).IsEmpty() | |
4589 | && Modified (theS).IsEmpty(); | |
4590 | } | |
4591 | ||
9b7f3f83 | 4592 | //======================================================================= |
ecf4f17c | 4593 | //function : GetSubShapes |
9b7f3f83 | 4594 | //purpose : |
4595 | //======================================================================= | |
ecf4f17c | 4596 | Standard_Boolean GetSubShapes(const TopoDS_Shape& theShape, |
4597 | const TopAbs_ShapeEnum theSSType, | |
4598 | TopoDS_Shape& theResult) | |
9b7f3f83 | 4599 | { |
ecf4f17c | 4600 | TopExp_Explorer aExp(theShape, theSSType); |
4601 | if (!aExp.More()) { | |
4602 | return Standard_False; | |
9b7f3f83 | 4603 | } |
4604 | // | |
ecf4f17c | 4605 | TopoDS_Compound aResult; |
4606 | BRep_Builder().MakeCompound(aResult); | |
9b7f3f83 | 4607 | // |
ecf4f17c | 4608 | for (; aExp.More(); aExp.Next()) { |
4609 | const TopoDS_Shape& aSS = aExp.Current(); | |
4610 | BRep_Builder().Add(aResult, aSS); | |
9b7f3f83 | 4611 | } |
ecf4f17c | 4612 | theResult = aResult; |
4613 | return Standard_True; | |
9b7f3f83 | 4614 | } |
4615 | ||
ecf4f17c | 4616 | //======================================================================= |
4617 | //function : IsPlanar | |
4618 | //purpose : Checks if all the faces of the shape are planes | |
4619 | //======================================================================= | |
99c9a820 | 4620 | Standard_Boolean BRepOffset_MakeOffset::IsPlanar() |
ecf4f17c | 4621 | { |
99c9a820 | 4622 | Standard_Boolean aIsNonPlanarFound = Standard_False; |
4623 | BRep_Builder aBB; | |
4624 | ||
4625 | TopExp_Explorer aExp(myShape, TopAbs_FACE); | |
4626 | for (; aExp.More(); aExp.Next()) | |
4627 | { | |
ecf4f17c | 4628 | const TopoDS_Face& aF = *(TopoDS_Face*)&aExp.Current(); |
4629 | BRepAdaptor_Surface aBAS(aF, Standard_False); | |
99c9a820 | 4630 | if (aBAS.GetType() == GeomAbs_Plane) |
4631 | continue; | |
4632 | ||
4633 | if (myIsLinearizationAllowed) | |
4634 | { | |
4635 | //define the toleance | |
4636 | Standard_Real aTolForFace = BRep_Tool::Tolerance(aF); | |
4637 | ||
4638 | //try to linearize | |
4639 | Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aF); | |
4640 | GeomLib_IsPlanarSurface aPlanarityChecker(aSurf, Precision::Confusion()); | |
4641 | if (aPlanarityChecker.IsPlanar()) | |
4642 | { | |
4643 | gp_Pln aPln = aPlanarityChecker.Plan(); | |
4644 | Handle(Geom_Plane) aPlane = new Geom_Plane(aPln); | |
4645 | TopoDS_Face aPlanarFace; | |
4646 | aBB.MakeFace(aPlanarFace, aPlane, aTolForFace); | |
4647 | TopoDS_Face aFaceForward = aF; | |
4648 | aFaceForward.Orientation(TopAbs_FORWARD); | |
4649 | TopoDS_Iterator anItFace(aFaceForward); | |
4650 | for (; anItFace.More(); anItFace.Next()) | |
4651 | { | |
4652 | const TopoDS_Shape& aWire = anItFace.Value(); | |
4653 | aBB.Add(aPlanarFace, aWire); | |
4654 | } | |
4655 | RemoveSeamAndDegeneratedEdges(aPlanarFace, aFaceForward); | |
4656 | myFacePlanfaceMap.Bind(aF, aPlanarFace); | |
4657 | if (myFaces.Contains(aF)) | |
4658 | { | |
4659 | myFaces.RemoveKey(aF); | |
4660 | myFaces.Add(aPlanarFace); | |
4661 | } | |
4662 | } | |
4663 | else | |
4664 | aIsNonPlanarFound = Standard_True; | |
4665 | } | |
4666 | else | |
4667 | aIsNonPlanarFound = Standard_True; | |
4668 | } | |
4669 | ||
4670 | return (!aIsNonPlanarFound); | |
4671 | } | |
4672 | ||
4673 | //======================================================================= | |
4674 | //function : RemoveSeamAndDegeneratedEdges | |
4675 | //purpose : Removes useless seam and degenerated edges from a face that becomes planar | |
4676 | //======================================================================= | |
4677 | void RemoveSeamAndDegeneratedEdges(const TopoDS_Face& theFace, | |
4678 | const TopoDS_Face& theOldFace) | |
4679 | { | |
4680 | TopoDS_Face aFace = theFace; | |
4681 | aFace.Orientation(TopAbs_FORWARD); | |
4682 | ||
4683 | Standard_Boolean aIsDegOrSeamFound = Standard_False; | |
4684 | TopTools_SequenceOfShape aEseq; | |
4685 | TopExp_Explorer anExplo(aFace, TopAbs_EDGE); | |
4686 | for (; anExplo.More(); anExplo.Next()) | |
4687 | { | |
4688 | const TopoDS_Edge& anEdge = TopoDS::Edge(anExplo.Current()); | |
4689 | if (BRep_Tool::Degenerated(anEdge) || | |
4690 | BRepTools::IsReallyClosed(anEdge, theOldFace)) | |
4691 | aIsDegOrSeamFound = Standard_True; | |
4692 | else | |
4693 | aEseq.Append(anEdge); | |
4694 | } | |
4695 | ||
4696 | if (!aIsDegOrSeamFound) | |
4697 | return; | |
4698 | ||
4699 | //Reconstruct wires | |
4700 | BRep_Builder aBB; | |
4701 | TopTools_ListOfShape aWlist; | |
4702 | TopoDS_Iterator anItFace(aFace); | |
4703 | for (; anItFace.More(); anItFace.Next()) | |
4704 | aWlist.Append(anItFace.Value()); | |
4705 | ||
4706 | aFace.Free(Standard_True); | |
4707 | TopTools_ListIteratorOfListOfShape anItl(aWlist); | |
4708 | for (; anItl.More(); anItl.Next()) | |
4709 | aBB.Remove(aFace, anItl.Value()); | |
4710 | ||
4711 | while (!aEseq.IsEmpty()) | |
4712 | { | |
4713 | TopoDS_Wire aNewWire; | |
4714 | aBB.MakeWire(aNewWire); | |
4715 | TopoDS_Edge aCurEdge = TopoDS::Edge(aEseq(1)); | |
4716 | aBB.Add(aNewWire, aCurEdge); | |
4717 | aEseq.Remove(1); | |
4718 | TopoDS_Vertex aFirstVertex, aCurVertex; | |
4719 | TopExp::Vertices(aCurEdge, aFirstVertex, aCurVertex, Standard_True); //with orientation | |
4720 | while (!aCurVertex.IsSame(aFirstVertex)) | |
4721 | { | |
4722 | TopoDS_Vertex aV1, aV2; | |
4723 | Standard_Integer ind; | |
4724 | for (ind = 1; ind <= aEseq.Length(); ind++) | |
4725 | { | |
4726 | aCurEdge = TopoDS::Edge(aEseq(ind)); | |
4727 | TopExp::Vertices(aCurEdge, aV1, aV2, Standard_True); //with orientation | |
4728 | if (aV1.IsSame(aCurVertex)) | |
4729 | break; | |
4730 | } | |
b81b237f | 4731 | if (ind > aEseq.Length()) //error occurred: wire is not closed |
99c9a820 | 4732 | break; |
4733 | ||
4734 | aBB.Add(aNewWire, aCurEdge); | |
4735 | aEseq.Remove(ind); | |
4736 | aCurVertex = aV2; | |
ecf4f17c | 4737 | } |
99c9a820 | 4738 | |
4739 | aBB.Add(aFace, aNewWire); | |
ecf4f17c | 4740 | } |
ecf4f17c | 4741 | } |
4742 | ||
9b7f3f83 | 4743 | //======================================================================= |
4744 | //function : IsSolid | |
ecf4f17c | 4745 | //purpose : Checks if the shape is solid |
9b7f3f83 | 4746 | //======================================================================= |
4747 | Standard_Boolean IsSolid(const TopoDS_Shape& theS) | |
4748 | { | |
4749 | TopExp_Explorer aExp(theS, TopAbs_SOLID); | |
4750 | return aExp.More(); | |
4751 | } | |
ecf4f17c | 4752 | |
9b7f3f83 | 4753 | //======================================================================= |
ecf4f17c | 4754 | //function : AppendToList |
4755 | //purpose : Add to a list only unique elements | |
9b7f3f83 | 4756 | //======================================================================= |
ecf4f17c | 4757 | void AppendToList(TopTools_ListOfShape& theList, |
4758 | const TopoDS_Shape& theShape) | |
9b7f3f83 | 4759 | { |
ecf4f17c | 4760 | TopTools_ListIteratorOfListOfShape aIt(theList); |
9b7f3f83 | 4761 | for (; aIt.More(); aIt.Next()) { |
ecf4f17c | 4762 | const TopoDS_Shape& aS = aIt.Value(); |
4763 | if (aS.IsSame(theShape)) { | |
4764 | return; | |
9b7f3f83 | 4765 | } |
4766 | } | |
ecf4f17c | 4767 | theList.Append(theShape); |
9b7f3f83 | 4768 | } |