1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: BlockFix_UnionFaces.cxx
24 // Created: Tue Dec 7 17:15:42 2004
25 // Author: Pavel DURANDIN
27 #include <BlockFix_UnionFaces.hxx>
29 #include <Basics_OCCTVersion.hxx>
31 #include <ShapeAnalysis_WireOrder.hxx>
32 #include <ShapeAnalysis_Edge.hxx>
34 #include <ShapeBuild_Edge.hxx>
35 #include <ShapeBuild_ReShape.hxx>
37 #include <ShapeExtend_WireData.hxx>
38 #include <ShapeExtend_CompositeSurface.hxx>
40 #include <ShapeFix_Face.hxx>
41 #include <ShapeFix_ComposeShell.hxx>
42 #include <ShapeFix_SequenceOfWireSegment.hxx>
43 #include <ShapeFix_WireSegment.hxx>
44 #include <ShapeFix_Wire.hxx>
45 #include <ShapeFix_Edge.hxx>
47 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
48 #include <IntPatch_ImpImpIntersection.hxx>
50 #include <IntPatch_TheIIIntOfIntersection.hxx>
53 #include <BRep_Tool.hxx>
54 #include <BRep_Builder.hxx>
55 #include <BRepTools.hxx>
56 #include <BRepTopAdaptor_TopolTool.hxx>
59 #include <TopExp_Explorer.hxx>
61 #include <TopTools_SequenceOfShape.hxx>
62 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
63 #include <TopTools_ListOfShape.hxx>
64 #include <TopTools_ListIteratorOfListOfShape.hxx>
65 #include <TopTools_MapOfShape.hxx>
66 #include <TopTools_MapIteratorOfMapOfShape.hxx>
69 #include <TopoDS_Edge.hxx>
70 #include <TopoDS_Wire.hxx>
71 #include <TopoDS_Face.hxx>
72 #include <TopoDS_Solid.hxx>
73 #include <TopoDS_Vertex.hxx>
74 #include <TopoDS_Shell.hxx>
75 #include <TopoDS_Iterator.hxx>
76 #include <TopoDS_Shape.hxx>
78 #include <TColGeom_HArray2OfSurface.hxx>
80 #include <GeomAdaptor_HSurface.hxx>
81 #include <GeomLib_IsPlanarSurface.hxx>
83 #include <Geom_Surface.hxx>
84 #include <Geom_Plane.hxx>
85 #include <Geom_OffsetSurface.hxx>
86 #include <Geom_SphericalSurface.hxx>
87 #include <Geom_CylindricalSurface.hxx>
88 #include <Geom_SurfaceOfRevolution.hxx>
89 #include <Geom_SurfaceOfLinearExtrusion.hxx>
90 #include <Geom_RectangularTrimmedSurface.hxx>
92 #include <Geom_Curve.hxx>
93 #include <Geom_Line.hxx>
94 #include <Geom_Circle.hxx>
96 #include <Geom2d_Line.hxx>
99 #include <gp_Pnt2d.hxx>
101 #include <Standard_Failure.hxx>
102 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
104 //=======================================================================
105 //function : BlockFix_UnionFaces
107 //=======================================================================
108 BlockFix_UnionFaces::BlockFix_UnionFaces()
109 : myTolerance(Precision::Confusion()),
114 //=======================================================================
115 //function : GetTolerance
117 //=======================================================================
118 Standard_Real& BlockFix_UnionFaces::GetTolerance()
123 //=======================================================================
124 //function : GetOptimumNbFaces
126 //=======================================================================
127 Standard_Integer& BlockFix_UnionFaces::GetOptimumNbFaces()
129 return myOptimumNbFaces;
132 //=======================================================================
133 //function : AddOrdinaryEdges
135 // adds edges from the shape to the sequence
136 // seams and equal edges are dropped
137 // Returns true if one of original edges dropped
138 //=======================================================================
139 static Standard_Boolean AddOrdinaryEdges(TopTools_SequenceOfShape& edges,
140 const TopoDS_Shape aShape,
141 Standard_Integer& anIndex)
144 TopTools_MapOfShape aNewEdges;
145 //add edges without seams
146 for(TopExp_Explorer exp(aShape,TopAbs_EDGE); exp.More(); exp.Next()) {
147 TopoDS_Shape edge = exp.Current();
148 if(aNewEdges.Contains(edge))
149 aNewEdges.Remove(edge);
154 Standard_Boolean isDropped = Standard_False;
155 //merge edges and drop seams
156 for(Standard_Integer i = 1; i <= edges.Length(); i++) {
157 TopoDS_Shape current = edges(i);
158 if(aNewEdges.Contains(current)) {
160 aNewEdges.Remove(current);
165 isDropped = Standard_True;
171 //add edges to the sequemce
172 for(TopTools_MapIteratorOfMapOfShape anIter(aNewEdges); anIter.More(); anIter.Next())
173 edges.Append(anIter.Key());
178 //=======================================================================
179 //function : ClearRts
181 //=======================================================================
182 static Handle(Geom_Surface) ClearRts(const Handle(Geom_Surface)& aSurface)
184 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
185 Handle(Geom_RectangularTrimmedSurface) rts =
186 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
187 return rts->BasisSurface();
192 //=======================================================================
193 //function : IsFacesOfSameSolids
195 //=======================================================================
196 static Standard_Boolean IsFacesOfSameSolids
197 (const TopoDS_Face &theFace1,
198 const TopoDS_Face &theFace2,
199 const TopTools_IndexedDataMapOfShapeListOfShape &theMapFaceSolids)
201 Standard_Boolean isSame = Standard_False;
203 if (theMapFaceSolids.Contains(theFace1) &&
204 theMapFaceSolids.Contains(theFace2)) {
205 const TopTools_ListOfShape& aList1 = theMapFaceSolids.FindFromKey(theFace1);
206 const TopTools_ListOfShape& aList2 = theMapFaceSolids.FindFromKey(theFace2);
208 if (aList1.Extent() == aList2.Extent()) {
209 TopTools_ListIteratorOfListOfShape anIter1(aList1);
211 isSame = Standard_True;
213 for (; anIter1.More(); anIter1.Next()) {
214 const TopoDS_Shape &aSolid1 = anIter1.Value();
215 TopTools_ListIteratorOfListOfShape anIter2(aList2);
217 for (; anIter2.More(); anIter2.Next()) {
218 if (aSolid1.IsSame(anIter2.Value())) {
219 // Same solid is detected. Break the loop
224 if (!anIter2.More()) {
225 // No same solid is detected. Break the loop.
226 isSame = Standard_False;
236 //=======================================================================
239 //=======================================================================
240 TopoDS_Shape BlockFix_UnionFaces::Perform(const TopoDS_Shape& Shape)
242 Handle(ShapeBuild_ReShape) myContext = new ShapeBuild_ReShape;
243 TopoDS_Shape aResShape = myContext->Apply(Shape);
245 // Fill Map of faces as keys and list of solids as items.
246 TopTools_IndexedDataMapOfShapeListOfShape aMapFaceSolids;
248 TopExp::MapShapesAndAncestors
249 (Shape, TopAbs_FACE, TopAbs_SOLID, aMapFaceSolids);
251 // processing each solid
252 TopExp_Explorer exps;
253 for (exps.Init(Shape, TopAbs_SOLID); exps.More(); exps.Next()) {
254 TopoDS_Solid aSolid = TopoDS::Solid(exps.Current());
256 // creating map of edge faces
257 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
258 TopExp::MapShapesAndAncestors(aSolid, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
260 // map of processed shapes
261 TopTools_MapOfShape aProcessed;
263 Handle(ShapeBuild_ReShape) aContext = new ShapeBuild_ReShape;
265 Standard_Integer NbModif = 0;
266 Standard_Boolean hasFailed = Standard_False;
267 Standard_Real tol = Min(Max(Precision::Confusion(), myTolerance/10.), 0.1);
272 TopTools_MapOfShape mapF;
273 for (exp.Init(aSolid, TopAbs_FACE); exp.More(); exp.Next()) {
274 if (mapF.Add(exp.Current()))
278 bool doUnion = ((myOptimumNbFaces == 0) ||
279 ((myOptimumNbFaces > 0) && (nbf > myOptimumNbFaces)));
281 // processing each face
283 for (exp.Init(aSolid, TopAbs_FACE); exp.More() && doUnion; exp.Next()) {
284 TopoDS_Face aFace = TopoDS::Face(exp.Current().Oriented(TopAbs_FORWARD));
286 if (aProcessed.Contains(aFace))
289 Standard_Integer dummy;
290 TopTools_SequenceOfShape edges;
291 AddOrdinaryEdges(edges,aFace,dummy);
293 TopTools_SequenceOfShape faces;
296 //surface and location to construct result
297 TopLoc_Location aBaseLocation;
298 Handle(Geom_Surface) aBaseSurface = BRep_Tool::Surface(aFace,aBaseLocation);
299 aBaseSurface = ClearRts(aBaseSurface);
301 // find adjacent faces to union
303 for (i = 1; i <= edges.Length(); i++) {
304 TopoDS_Edge edge = TopoDS::Edge(edges(i));
305 if (BRep_Tool::Degenerated(edge) || BRep_Tool::IsClosed(edge, aFace))
308 const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
309 TopTools_ListIteratorOfListOfShape anIter(aList);
310 for (; anIter.More(); anIter.Next()) {
311 TopoDS_Face anCheckedFace = TopoDS::Face(anIter.Value().Oriented(TopAbs_FORWARD));
312 if (anCheckedFace.IsSame(aFace))
315 if (aProcessed.Contains(anCheckedFace))
318 if (BRep_Tool::IsClosed(edge, anCheckedFace)) {
323 // Check if faces belong to same solids.
324 if (!IsFacesOfSameSolids(aFace, anCheckedFace, aMapFaceSolids)) {
328 if (IsSameDomain(aFace,anCheckedFace)) {
330 if (aList.Extent() != 2) {
331 // non mainfold case is not processed
336 TopoDS_Face aMockUpFace;
338 B.MakeFace(aMockUpFace,aBaseSurface,aBaseLocation,0.);
339 MovePCurves(aMockUpFace,anCheckedFace);
341 if (AddOrdinaryEdges(edges,aMockUpFace,dummy)) {
342 // sequence edges is modified
346 faces.Append(anCheckedFace);
347 aProcessed.Add(anCheckedFace);
353 // all faces collected in the sequence. Perform union of faces
354 if (faces.Length() > 1) {
358 B.MakeFace(aResult,aBaseSurface,aBaseLocation,0);
359 Standard_Integer nbWires = 0;
362 while (edges.Length()>0) {
364 Standard_Boolean isEdge3d = Standard_False;
366 TopTools_MapOfShape aVertices;
370 TopoDS_Edge anEdge = TopoDS::Edge(edges(1));
373 isEdge3d |= !BRep_Tool::Degenerated(anEdge);
376 TopExp::Vertices(anEdge,V1,V2);
380 Standard_Boolean isNewFound = Standard_False;
382 isNewFound = Standard_False;
383 for(Standard_Integer j = 1; j <= edges.Length(); j++) {
384 anEdge = TopoDS::Edge(edges(j));
385 TopExp::Vertices(anEdge,V1,V2);
386 if(aVertices.Contains(V1) || aVertices.Contains(V2)) {
387 isEdge3d |= !BRep_Tool::Degenerated(anEdge);
393 isNewFound = Standard_True;
396 } while (isNewFound);
398 // sorting any type of edges
399 aWire = TopoDS::Wire(aContext->Apply(aWire));
401 TopoDS_Face tmpF = TopoDS::Face(aContext->Apply(faces(1).Oriented(TopAbs_FORWARD)));
402 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire(aWire,tmpF,Precision::Confusion());
404 Standard_Boolean isDegRemoved = Standard_False;
405 if(!sfw->StatusReorder ( ShapeExtend_FAIL )) {
406 // clear degenerated edges if at least one with 3d curve exist
408 Handle(ShapeExtend_WireData) sewd = sfw->WireData();
409 for(Standard_Integer j = 1; j<=sewd->NbEdges();j++) {
410 TopoDS_Edge E = sewd->Edge(j);
411 if(BRep_Tool::Degenerated(E)) {
413 isDegRemoved = Standard_True;
420 sfw->FixDegenerated();
422 TopoDS_Wire aWireFixed = sfw->Wire();
423 aContext->Replace(aWire,aWireFixed);
424 // add resulting wire
426 B.Add(aResult,aWireFixed);
430 Handle(ShapeExtend_WireData) sbwd = sfw->WireData();
431 Standard_Integer nbEdges = sbwd->NbEdges();
432 // sort degenerated edges and create one edge instead of several ones
433 ShapeAnalysis_WireOrder sawo(Standard_False, 0);
434 ShapeAnalysis_Edge sae;
435 Standard_Integer aLastEdge = nbEdges;
436 for(Standard_Integer j = 1; j <= nbEdges; j++) {
438 //smh protection on NULL pcurve
439 Handle(Geom2d_Curve) c2d;
440 if(!sae.PCurve(sbwd->Edge(j),tmpF,c2d,f,l)) {
444 sawo.Add(c2d->Value(f).XY(),c2d->Value(l).XY());
448 // constructind one degenerative edge
449 gp_XY aStart, anEnd, tmp;
450 Standard_Integer nbFirst = sawo.Ordered(1);
451 TopoDS_Edge anOrigE = TopoDS::Edge(sbwd->Edge(nbFirst).Oriented(TopAbs_FORWARD));
453 TopoDS_Vertex aDummyV;
454 TopoDS_Edge E = sbe.CopyReplaceVertices(anOrigE,aDummyV,aDummyV);
455 sawo.XY(nbFirst,aStart,tmp);
456 sawo.XY(sawo.Ordered(aLastEdge),tmp,anEnd);
458 gp_XY aVec = anEnd-aStart;
459 Handle(Geom2d_Line) aLine = new Geom2d_Line(aStart,gp_Dir2d(anEnd-aStart));
461 B.UpdateEdge(E,aLine,tmpF,0.);
462 B.Range(E,tmpF,0.,aVec.Modulus());
463 Handle(Geom_Curve) C3d;
464 B.UpdateEdge(E,C3d,0.);
465 B.Degenerated(E,Standard_True);
473 // perform substitution of face
474 aContext->Replace(aContext->Apply(aFace),aResult);
476 ShapeFix_Face sff (aResult);
477 //Intializing by tolerances
478 sff.SetPrecision(myTolerance);
479 sff.SetMinTolerance(tol);
480 sff.SetMaxTolerance(Max(1.,myTolerance*1000.));
482 sff.FixOrientationMode() = 0;
483 //sff.FixWireMode() = 0;
484 sff.SetContext(aContext);
485 // Applying the fixes
487 if(sff.Status(ShapeExtend_FAIL))
488 hasFailed = Standard_True;
490 // breaking down to several faces
491 TopoDS_Shape theResult = aContext->Apply(aResult);
492 for (TopExp_Explorer aFaceExp (theResult,TopAbs_FACE); aFaceExp.More(); aFaceExp.Next()) {
493 TopoDS_Face aCurrent = TopoDS::Face(aFaceExp.Current().Oriented(TopAbs_FORWARD));
494 Handle(TColGeom_HArray2OfSurface) grid = new TColGeom_HArray2OfSurface ( 1, 1, 1, 1 );
495 grid->SetValue ( 1, 1, aBaseSurface );
496 Handle(ShapeExtend_CompositeSurface) G = new ShapeExtend_CompositeSurface ( grid );
497 ShapeFix_ComposeShell CompShell;
498 CompShell.Init ( G, aBaseLocation, aCurrent, ::Precision::Confusion() );//myPrecision
499 CompShell.SetContext( aContext );
501 TopTools_SequenceOfShape parts;
502 ShapeFix_SequenceOfWireSegment wires;
503 for(TopExp_Explorer W_Exp(aCurrent,TopAbs_WIRE);W_Exp.More();W_Exp.Next()) {
504 Handle(ShapeExtend_WireData) sbwd =
505 new ShapeExtend_WireData ( TopoDS::Wire(W_Exp.Current() ));
506 ShapeFix_WireSegment seg ( sbwd, TopAbs_REVERSED );
510 CompShell.DispatchWires ( parts,wires );
511 for (Standard_Integer j=1; j <= parts.Length(); j++ ) {
512 ShapeFix_Face aFixOrient(TopoDS::Face(parts(j)));
513 aFixOrient.SetContext(aContext);
514 aFixOrient.FixOrientation();
517 TopoDS_Shape CompRes;
518 if ( faces.Length() !=1 ) {
521 for ( i=1; i <= parts.Length(); i++ )
522 B.Add ( S, parts(i) );
525 else CompRes = parts(1);
527 aContext->Replace(aCurrent,CompRes);
530 // remove the remaining faces
531 for(i = 2; i <= faces.Length(); i++)
532 aContext->Remove(faces(i));
534 } // end processing each face
536 //TopoDS_Shape aResult = Shape;
537 if (NbModif > 0 && !hasFailed) {
538 TopoDS_Shape aResult = aContext->Apply(aSolid);
541 for (exp.Init(aResult,TopAbs_EDGE); exp.More(); exp.Next()) {
542 TopoDS_Edge E = TopoDS::Edge(exp.Current());
543 sfe.FixVertexTolerance (E);
544 // ptv add fix same parameter
545 sfe.FixSameParameter(E, myTolerance);
548 myContext->Replace(aSolid, aResult);
552 for (exp.Init(aSolid, TopAbs_FACE); exp.More(); exp.Next()) {
553 TopoDS_Face aFace = TopoDS::Face(exp.Current().Oriented(TopAbs_FORWARD));
554 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire;
555 sfw->SetContext(myContext);
556 sfw->SetPrecision(myTolerance);
557 sfw->SetMinTolerance(myTolerance);
558 sfw->SetMaxTolerance(Max(1.,myTolerance*1000.));
560 for (TopoDS_Iterator iter (aFace,Standard_False); iter.More(); iter.Next()) {
561 TopoDS_Wire wire = TopoDS::Wire(iter.Value());
568 } // end processing each solid
570 aResShape = myContext->Apply(Shape);
574 //=======================================================================
575 //function : IsSameDomain
577 //=======================================================================
578 bool getCylinder (Handle(Geom_Surface)& theInSurface, gp_Cylinder& theOutCylinder)
580 bool isCylinder = false;
582 if (theInSurface->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
583 Handle(Geom_CylindricalSurface) aGC = Handle(Geom_CylindricalSurface)::DownCast(theInSurface);
585 theOutCylinder = aGC->Cylinder();
588 else if (theInSurface->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
589 Handle(Geom_SurfaceOfRevolution) aRS =
590 Handle(Geom_SurfaceOfRevolution)::DownCast(theInSurface);
591 Handle(Geom_Curve) aBasis = aRS->BasisCurve();
592 if (aBasis->IsKind(STANDARD_TYPE(Geom_Line))) {
593 Handle(Geom_Line) aBasisLine = Handle(Geom_Line)::DownCast(aBasis);
594 gp_Dir aDir = aRS->Direction();
595 gp_Dir aBasisDir = aBasisLine->Position().Direction();
596 if (aBasisDir.IsParallel(aDir, Precision::Confusion())) {
597 // basis line is parallel to the revolution axis: it is a cylinder
598 gp_Pnt aLoc = aRS->Location();
599 Standard_Real aR = aBasisLine->Lin().Distance(aLoc);
600 gp_Ax3 aCylAx (aLoc, aDir);
602 theOutCylinder = gp_Cylinder(aCylAx, aR);
607 else if (theInSurface->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))) {
608 Handle(Geom_SurfaceOfLinearExtrusion) aLES =
609 Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(theInSurface);
610 Handle(Geom_Curve) aBasis = aLES->BasisCurve();
611 if (aBasis->IsKind(STANDARD_TYPE(Geom_Circle))) {
612 Handle(Geom_Circle) aBasisCircle = Handle(Geom_Circle)::DownCast(aBasis);
613 gp_Dir aDir = aLES->Direction();
614 gp_Dir aBasisDir = aBasisCircle->Position().Direction();
615 if (aBasisDir.IsParallel(aDir, Precision::Confusion())) {
616 // basis circle is normal to the extrusion axis: it is a cylinder
617 gp_Pnt aLoc = aBasisCircle->Location();
618 Standard_Real aR = aBasisCircle->Radius();
619 gp_Ax3 aCylAx (aLoc, aDir);
621 theOutCylinder = gp_Cylinder(aCylAx, aR);
632 Standard_Boolean BlockFix_UnionFaces::IsSameDomain(const TopoDS_Face& aFace,
633 const TopoDS_Face& aCheckedFace) const
635 //checking the same handles
636 TopLoc_Location L1, L2;
637 Handle(Geom_Surface) S1, S2;
639 S1 = BRep_Tool::Surface(aFace,L1);
640 S2 = BRep_Tool::Surface(aCheckedFace,L2);
642 if (S1 == S2 && L1 == L2)
645 // planar and cylindrical cases (IMP 20052)
646 Standard_Real aPrec = Precision::Confusion();
648 S1 = BRep_Tool::Surface(aFace);
649 S2 = BRep_Tool::Surface(aCheckedFace);
654 //Handle(Geom_OffsetSurface) aGOFS1, aGOFS2;
655 //aGOFS1 = Handle(Geom_OffsetSurface)::DownCast(S1);
656 //aGOFS2 = Handle(Geom_OffsetSurface)::DownCast(S2);
657 //if (!aGOFS1.IsNull()) S1 = aGOFS1->BasisSurface();
658 //if (!aGOFS2.IsNull()) S2 = aGOFS2->BasisSurface();
660 // case of two elementary surfaces: use OCCT tool
661 // elementary surfaces: ConicalSurface, CylindricalSurface,
662 // Plane, SphericalSurface and ToroidalSurface
663 if (S1->IsKind(STANDARD_TYPE(Geom_ElementarySurface)) &&
664 S2->IsKind(STANDARD_TYPE(Geom_ElementarySurface)))
666 Handle(GeomAdaptor_HSurface) aGA1 = new GeomAdaptor_HSurface(S1);
667 Handle(GeomAdaptor_HSurface) aGA2 = new GeomAdaptor_HSurface(S2);
669 Handle(BRepTopAdaptor_TopolTool) aTT1 = new BRepTopAdaptor_TopolTool();
670 Handle(BRepTopAdaptor_TopolTool) aTT2 = new BRepTopAdaptor_TopolTool();
673 #if OCC_VERSION_LARGE > 0x06010000
677 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
678 IntPatch_ImpImpIntersection anIIInt (aGA1, aTT1, aGA2, aTT2, aPrec, aPrec);
680 IntPatch_TheIIIntOfIntersection anIIInt (aGA1, aTT1, aGA2, aTT2, aPrec, aPrec);
682 if (!anIIInt.IsDone() || anIIInt.IsEmpty())
685 return anIIInt.TangentFaces();
687 catch (Standard_Failure) {
692 // case of two planar surfaces:
693 // all kinds of surfaces checked, including b-spline and bezier
694 GeomLib_IsPlanarSurface aPlanarityChecker1 (S1, aPrec);
695 if (aPlanarityChecker1.IsPlanar()) {
696 GeomLib_IsPlanarSurface aPlanarityChecker2 (S2, aPrec);
697 if (aPlanarityChecker2.IsPlanar()) {
698 gp_Pln aPln1 = aPlanarityChecker1.Plan();
699 gp_Pln aPln2 = aPlanarityChecker2.Plan();
701 if (aPln1.Position().Direction().IsParallel(aPln2.Position().Direction(), aPrec) &&
702 aPln1.Distance(aPln2) < aPrec) {
708 // case of two cylindrical surfaces, at least one of which is a swept surface
709 // swept surfaces: SurfaceOfLinearExtrusion, SurfaceOfRevolution
710 if ((S1->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) ||
711 S1->IsKind(STANDARD_TYPE(Geom_SweptSurface))) &&
712 (S2->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) ||
713 S2->IsKind(STANDARD_TYPE(Geom_SweptSurface))))
715 gp_Cylinder aCyl1, aCyl2;
716 if (getCylinder(S1, aCyl1) && getCylinder(S2, aCyl2)) {
717 if (fabs(aCyl1.Radius() - aCyl2.Radius()) < aPrec) {
718 gp_Dir aDir1 = aCyl1.Position().Direction();
719 gp_Dir aDir2 = aCyl2.Position().Direction();
720 if (aDir1.IsParallel(aDir2, aPrec)) {
721 gp_Pnt aLoc1 = aCyl1.Location();
722 gp_Pnt aLoc2 = aCyl2.Location();
723 gp_Vec aVec12 (aLoc1, aLoc2);
724 if (aVec12.SquareMagnitude() < aPrec*aPrec ||
725 aVec12.IsParallel(aDir1, aPrec)) {
736 //=======================================================================
737 //function : MovePCurves
739 //=======================================================================
740 void BlockFix_UnionFaces::MovePCurves(TopoDS_Face& aTarget,
741 const TopoDS_Face& aSource) const
744 for(TopExp_Explorer wexp(aSource,TopAbs_WIRE);wexp.More();wexp.Next()) {
745 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire(TopoDS::Wire(wexp.Current()),
746 aTarget, Precision::Confusion());
748 Standard_Boolean isReoredFailed = sfw->StatusReorder ( ShapeExtend_FAIL );
749 sfw->FixEdgeCurves();
754 sfw->FixDegenerated();
756 // remove degenerated edges from not degenerated points
757 ShapeAnalysis_Edge sae;
758 Handle(ShapeExtend_WireData) sewd = sfw->WireData();
759 for(Standard_Integer i = 1; i<=sewd->NbEdges();i++) {
760 TopoDS_Edge E = sewd->Edge(i);
761 if(BRep_Tool::Degenerated(E)&&!sae.HasPCurve(E,aTarget)) {
767 TopoDS_Wire ResWire = sfw->Wire();
768 B.Add(aTarget,ResWire);