1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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 //=======================================================================
237 //function : IsEdgeValidToMerge
238 //purpose : Edge is valid if it is not seam or if it is a seam and the face
239 // has another seam edge.
240 //=======================================================================
241 static Standard_Boolean IsEdgeValidToMerge(const TopoDS_Edge &theEdge,
242 const TopoDS_Face &theFace)
244 Standard_Boolean isValid = Standard_True;
246 if (BRep_Tool::IsClosed(theEdge, theFace)) {
247 // This is a seam edge. Check if there are another seam edges on the face.
248 TopExp_Explorer anExp(theFace, TopAbs_EDGE);
250 for (; anExp.More(); anExp.Next()) {
251 const TopoDS_Shape &aShEdge = anExp.Current();
254 if (theEdge.IsSame(aShEdge)) {
258 // Check if this edge is a seam.
259 TopoDS_Edge anEdge = TopoDS::Edge(aShEdge);
261 if (BRep_Tool::IsClosed(anEdge, theFace)) {
262 isValid = Standard_False;
271 //=======================================================================
274 //=======================================================================
275 TopoDS_Shape BlockFix_UnionFaces::Perform(const TopoDS_Shape& Shape)
277 // Fill Map of faces as keys and list of solids or shells as items.
278 TopTools_IndexedDataMapOfShapeListOfShape aMapFaceSoOrSh;
280 TopAbs_ShapeEnum aType = Shape.ShapeType();
282 if (aType != TopAbs_SHELL) {
283 aType = TopAbs_SOLID;
286 TopExp::MapShapesAndAncestors
287 (Shape, TopAbs_FACE, aType, aMapFaceSoOrSh);
289 // processing each solid
290 Handle(ShapeBuild_ReShape) aContext = new ShapeBuild_ReShape;
291 TopTools_MapOfShape aProcessed;
292 TopExp_Explorer exps;
293 for (exps.Init(Shape, aType); exps.More(); exps.Next()) {
294 TopoDS_Shape aSoOrSh = exps.Current();
296 // creating map of edge faces
297 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
298 TopExp::MapShapesAndAncestors(aSoOrSh, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
300 Standard_Integer NbModif = 0;
301 Standard_Boolean hasFailed = Standard_False;
302 Standard_Real tol = Min(Max(Precision::Confusion(), myTolerance/10.), 0.1);
307 TopTools_MapOfShape mapF;
308 for (exp.Init(aSoOrSh, TopAbs_FACE); exp.More(); exp.Next()) {
309 if (mapF.Add(exp.Current()))
313 bool doUnion = ((myOptimumNbFaces == 0) ||
314 ((myOptimumNbFaces > 0) && (nbf > myOptimumNbFaces)));
316 // processing each face
318 for (exp.Init(aSoOrSh, TopAbs_FACE); exp.More() && doUnion; exp.Next()) {
319 TopoDS_Face aFace = TopoDS::Face(exp.Current().Oriented(TopAbs_FORWARD));
321 if (aProcessed.Contains(aFace)) {
325 Standard_Integer dummy;
326 TopTools_SequenceOfShape edges;
327 AddOrdinaryEdges(edges,aFace,dummy);
329 TopTools_SequenceOfShape faces;
332 //surface and location to construct result
333 TopLoc_Location aBaseLocation;
334 Handle(Geom_Surface) aBaseSurface = BRep_Tool::Surface(aFace,aBaseLocation);
335 aBaseSurface = ClearRts(aBaseSurface);
336 aBaseSurface = Handle(Geom_Surface)::DownCast(aBaseSurface->Copy());
338 // find adjacent faces to union
340 for (i = 1; i <= edges.Length(); i++) {
341 TopoDS_Edge edge = TopoDS::Edge(edges(i));
342 if (BRep_Tool::Degenerated(edge) || !IsEdgeValidToMerge(edge, aFace))
345 const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
346 TopTools_ListIteratorOfListOfShape anIter(aList);
347 for (; anIter.More(); anIter.Next()) {
348 TopoDS_Face anCheckedFace = TopoDS::Face(anIter.Value().Oriented(TopAbs_FORWARD));
349 if (anCheckedFace.IsSame(aFace))
352 if (aProcessed.Contains(anCheckedFace))
355 if (!IsEdgeValidToMerge(edge, anCheckedFace)) {
360 // Check if faces belong to same solids.
361 if (!IsFacesOfSameSolids(aFace, anCheckedFace, aMapFaceSoOrSh)) {
365 if (IsSameDomain(aFace,anCheckedFace)) {
367 if (aList.Extent() != 2) {
368 // non mainfold case is not processed
373 TopoDS_Face aMockUpFace;
375 B.MakeFace(aMockUpFace,aBaseSurface,aBaseLocation,0.);
376 MovePCurves(aMockUpFace,anCheckedFace);
378 if (AddOrdinaryEdges(edges,aMockUpFace,dummy)) {
379 // sequence edges is modified
383 faces.Append(anCheckedFace);
384 aProcessed.Add(anCheckedFace);
390 // all faces collected in the sequence. Perform union of faces
391 if (faces.Length() > 1) {
395 B.MakeFace(aResult,aBaseSurface,aBaseLocation,0);
396 Standard_Integer nbWires = 0;
399 while (edges.Length()>0) {
401 Standard_Boolean isEdge3d = Standard_False;
403 TopTools_MapOfShape aVertices;
407 TopoDS_Edge anEdge = TopoDS::Edge(edges(1));
410 isEdge3d |= !BRep_Tool::Degenerated(anEdge);
413 TopExp::Vertices(anEdge,V1,V2);
417 Standard_Boolean isNewFound = Standard_False;
419 isNewFound = Standard_False;
420 for(Standard_Integer j = 1; j <= edges.Length(); j++) {
421 anEdge = TopoDS::Edge(edges(j));
422 TopExp::Vertices(anEdge,V1,V2);
423 if(aVertices.Contains(V1) || aVertices.Contains(V2)) {
424 isEdge3d |= !BRep_Tool::Degenerated(anEdge);
430 isNewFound = Standard_True;
433 } while (isNewFound);
435 // sorting any type of edges
436 aWire = TopoDS::Wire(aContext->Apply(aWire));
438 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire(aWire,aResult,Precision::Confusion());
440 Standard_Boolean isDegRemoved = Standard_False;
441 if(!sfw->StatusReorder ( ShapeExtend_FAIL )) {
442 // clear degenerated edges if at least one with 3d curve exist
444 Handle(ShapeExtend_WireData) sewd = sfw->WireData();
445 for(Standard_Integer j = 1; j<=sewd->NbEdges();j++) {
446 TopoDS_Edge E = sewd->Edge(j);
447 if(BRep_Tool::Degenerated(E)) {
449 isDegRemoved = Standard_True;
456 sfw->FixDegenerated();
458 TopoDS_Wire aWireFixed = sfw->Wire();
459 aContext->Replace(aWire,aWireFixed);
460 // add resulting wire
462 B.Add(aResult,aWireFixed);
466 Handle(ShapeExtend_WireData) sbwd = sfw->WireData();
467 Standard_Integer nbEdges = sbwd->NbEdges();
468 // sort degenerated edges and create one edge instead of several ones
469 ShapeAnalysis_WireOrder sawo(Standard_False, 0);
470 ShapeAnalysis_Edge sae;
471 Standard_Integer aLastEdge = nbEdges;
472 for(Standard_Integer j = 1; j <= nbEdges; j++) {
474 //smh protection on NULL pcurve
475 Handle(Geom2d_Curve) c2d;
476 if(!sae.PCurve(sbwd->Edge(j),aResult,c2d,f,l)) {
480 sawo.Add(c2d->Value(f).XY(),c2d->Value(l).XY());
484 // constructind one degenerative edge
485 gp_XY aStart, anEnd, tmp;
486 Standard_Integer nbFirst = sawo.Ordered(1);
487 TopoDS_Edge anOrigE = TopoDS::Edge(sbwd->Edge(nbFirst).Oriented(TopAbs_FORWARD));
489 TopoDS_Vertex aDummyV;
490 TopoDS_Edge E = sbe.CopyReplaceVertices(anOrigE,aDummyV,aDummyV);
491 sawo.XY(nbFirst,aStart,tmp);
492 sawo.XY(sawo.Ordered(aLastEdge),tmp,anEnd);
494 gp_XY aVec = anEnd-aStart;
495 Handle(Geom2d_Line) aLine = new Geom2d_Line(aStart,gp_Dir2d(anEnd-aStart));
497 B.UpdateEdge(E,aLine,aResult,0.);
498 B.Range(E,aResult,0.,aVec.Modulus());
499 Handle(Geom_Curve) C3d;
500 B.UpdateEdge(E,C3d,0.);
501 B.Degenerated(E,Standard_True);
509 // perform substitution of face
510 aContext->Replace(aContext->Apply(aFace),aResult);
512 ShapeFix_Face sff (aResult);
513 //Intializing by tolerances
514 sff.SetPrecision(myTolerance);
515 sff.SetMinTolerance(tol);
516 sff.SetMaxTolerance(Max(1.,myTolerance*1000.));
518 sff.FixOrientationMode() = 0;
519 //sff.FixWireMode() = 0;
520 sff.SetContext(aContext);
521 // Applying the fixes
523 if(sff.Status(ShapeExtend_FAIL))
524 hasFailed = Standard_True;
526 // breaking down to several faces
527 TopoDS_Shape theResult = aContext->Apply(aResult);
528 for (TopExp_Explorer aFaceExp (theResult,TopAbs_FACE); aFaceExp.More(); aFaceExp.Next()) {
529 TopoDS_Face aCurrent = TopoDS::Face(aFaceExp.Current().Oriented(TopAbs_FORWARD));
530 Handle(TColGeom_HArray2OfSurface) grid = new TColGeom_HArray2OfSurface ( 1, 1, 1, 1 );
531 grid->SetValue ( 1, 1, aBaseSurface );
532 Handle(ShapeExtend_CompositeSurface) G = new ShapeExtend_CompositeSurface ( grid );
533 ShapeFix_ComposeShell CompShell;
534 CompShell.Init ( G, aBaseLocation, aCurrent, ::Precision::Confusion() );//myPrecision
535 CompShell.SetContext( aContext );
537 TopTools_SequenceOfShape parts;
538 ShapeFix_SequenceOfWireSegment wires;
539 for(TopExp_Explorer W_Exp(aCurrent,TopAbs_WIRE);W_Exp.More();W_Exp.Next()) {
540 Handle(ShapeExtend_WireData) sbwd =
541 new ShapeExtend_WireData ( TopoDS::Wire(W_Exp.Current() ));
542 ShapeFix_WireSegment seg ( sbwd, TopAbs_REVERSED );
546 CompShell.DispatchWires ( parts,wires );
547 for (Standard_Integer j=1; j <= parts.Length(); j++ ) {
548 ShapeFix_Face aFixOrient(TopoDS::Face(parts(j)));
549 aFixOrient.SetContext(aContext);
550 aFixOrient.FixOrientation();
553 TopoDS_Shape CompRes;
554 if ( faces.Length() !=1 ) {
557 for ( i=1; i <= parts.Length(); i++ )
558 B.Add ( S, parts(i) );
561 else CompRes = parts(1);
563 aContext->Replace(aCurrent,CompRes);
566 // remove the remaining faces
567 for(i = 2; i <= faces.Length(); i++)
568 aContext->Remove(faces(i));
570 } // end processing each face
572 //TopoDS_Shape aResult = Shape;
573 if (NbModif > 0 && !hasFailed) {
574 TopoDS_Shape aResult = aContext->Apply(aSoOrSh);
577 for (exp.Init(aResult,TopAbs_EDGE); exp.More(); exp.Next()) {
578 TopoDS_Edge E = TopoDS::Edge(exp.Current());
579 sfe.FixVertexTolerance (E);
580 // ptv add fix same parameter
581 sfe.FixSameParameter(E, myTolerance);
585 for (exp.Init(aSoOrSh, TopAbs_FACE); exp.More(); exp.Next()) {
586 TopoDS_Face aFace = TopoDS::Face(exp.Current().Oriented(TopAbs_FORWARD));
587 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire;
588 sfw->SetContext(aContext);
589 sfw->SetPrecision(myTolerance);
590 sfw->SetMinTolerance(myTolerance);
591 sfw->SetMaxTolerance(Max(1.,myTolerance*1000.));
593 for (TopoDS_Iterator iter (aFace,Standard_False); iter.More(); iter.Next()) {
594 TopoDS_Wire wire = TopoDS::Wire(iter.Value());
600 } // end processing each solid
602 const TopoDS_Shape aResShape = aContext->Apply(Shape);
607 //=======================================================================
608 //function : IsSameDomain
610 //=======================================================================
611 bool getCylinder (Handle(Geom_Surface)& theInSurface, gp_Cylinder& theOutCylinder)
613 bool isCylinder = false;
615 if (theInSurface->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
616 Handle(Geom_CylindricalSurface) aGC = Handle(Geom_CylindricalSurface)::DownCast(theInSurface);
618 theOutCylinder = aGC->Cylinder();
621 else if (theInSurface->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
622 Handle(Geom_SurfaceOfRevolution) aRS =
623 Handle(Geom_SurfaceOfRevolution)::DownCast(theInSurface);
624 Handle(Geom_Curve) aBasis = aRS->BasisCurve();
625 if (aBasis->IsKind(STANDARD_TYPE(Geom_Line))) {
626 Handle(Geom_Line) aBasisLine = Handle(Geom_Line)::DownCast(aBasis);
627 gp_Dir aDir = aRS->Direction();
628 gp_Dir aBasisDir = aBasisLine->Position().Direction();
629 if (aBasisDir.IsParallel(aDir, Precision::Confusion())) {
630 // basis line is parallel to the revolution axis: it is a cylinder
631 gp_Pnt aLoc = aRS->Location();
632 Standard_Real aR = aBasisLine->Lin().Distance(aLoc);
633 gp_Ax3 aCylAx (aLoc, aDir);
635 theOutCylinder = gp_Cylinder(aCylAx, aR);
640 else if (theInSurface->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))) {
641 Handle(Geom_SurfaceOfLinearExtrusion) aLES =
642 Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(theInSurface);
643 Handle(Geom_Curve) aBasis = aLES->BasisCurve();
644 if (aBasis->IsKind(STANDARD_TYPE(Geom_Circle))) {
645 Handle(Geom_Circle) aBasisCircle = Handle(Geom_Circle)::DownCast(aBasis);
646 gp_Dir aDir = aLES->Direction();
647 gp_Dir aBasisDir = aBasisCircle->Position().Direction();
648 if (aBasisDir.IsParallel(aDir, Precision::Confusion())) {
649 // basis circle is normal to the extrusion axis: it is a cylinder
650 gp_Pnt aLoc = aBasisCircle->Location();
651 Standard_Real aR = aBasisCircle->Radius();
652 gp_Ax3 aCylAx (aLoc, aDir);
654 theOutCylinder = gp_Cylinder(aCylAx, aR);
665 Standard_Boolean BlockFix_UnionFaces::IsSameDomain(const TopoDS_Face& aFace,
666 const TopoDS_Face& aCheckedFace) const
668 //checking the same handles
669 TopLoc_Location L1, L2;
670 Handle(Geom_Surface) S1, S2;
672 S1 = BRep_Tool::Surface(aFace,L1);
673 S2 = BRep_Tool::Surface(aCheckedFace,L2);
675 if (S1 == S2 && L1 == L2)
678 // planar and cylindrical cases (IMP 20052)
679 Standard_Real aPrec = Precision::Confusion();
681 S1 = BRep_Tool::Surface(aFace);
682 S2 = BRep_Tool::Surface(aCheckedFace);
687 //Handle(Geom_OffsetSurface) aGOFS1, aGOFS2;
688 //aGOFS1 = Handle(Geom_OffsetSurface)::DownCast(S1);
689 //aGOFS2 = Handle(Geom_OffsetSurface)::DownCast(S2);
690 //if (!aGOFS1.IsNull()) S1 = aGOFS1->BasisSurface();
691 //if (!aGOFS2.IsNull()) S2 = aGOFS2->BasisSurface();
693 // case of two elementary surfaces: use OCCT tool
694 // elementary surfaces: ConicalSurface, CylindricalSurface,
695 // Plane, SphericalSurface and ToroidalSurface
696 if (S1->IsKind(STANDARD_TYPE(Geom_ElementarySurface)) &&
697 S2->IsKind(STANDARD_TYPE(Geom_ElementarySurface)))
699 Handle(GeomAdaptor_HSurface) aGA1 = new GeomAdaptor_HSurface(S1);
700 Handle(GeomAdaptor_HSurface) aGA2 = new GeomAdaptor_HSurface(S2);
702 Handle(BRepTopAdaptor_TopolTool) aTT1 = new BRepTopAdaptor_TopolTool();
703 Handle(BRepTopAdaptor_TopolTool) aTT2 = new BRepTopAdaptor_TopolTool();
706 #if OCC_VERSION_LARGE > 0x06010000
710 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
711 IntPatch_ImpImpIntersection anIIInt (aGA1, aTT1, aGA2, aTT2, aPrec, aPrec);
713 IntPatch_TheIIIntOfIntersection anIIInt (aGA1, aTT1, aGA2, aTT2, aPrec, aPrec);
715 if (!anIIInt.IsDone() || anIIInt.IsEmpty())
718 return anIIInt.TangentFaces();
720 catch (Standard_Failure) {
725 // case of two planar surfaces:
726 // all kinds of surfaces checked, including b-spline and bezier
727 GeomLib_IsPlanarSurface aPlanarityChecker1 (S1, aPrec);
728 if (aPlanarityChecker1.IsPlanar()) {
729 GeomLib_IsPlanarSurface aPlanarityChecker2 (S2, aPrec);
730 if (aPlanarityChecker2.IsPlanar()) {
731 gp_Pln aPln1 = aPlanarityChecker1.Plan();
732 gp_Pln aPln2 = aPlanarityChecker2.Plan();
734 if (aPln1.Position().Direction().IsParallel(aPln2.Position().Direction(), aPrec) &&
735 aPln1.Distance(aPln2) < aPrec) {
741 // case of two cylindrical surfaces, at least one of which is a swept surface
742 // swept surfaces: SurfaceOfLinearExtrusion, SurfaceOfRevolution
743 if ((S1->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) ||
744 S1->IsKind(STANDARD_TYPE(Geom_SweptSurface))) &&
745 (S2->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) ||
746 S2->IsKind(STANDARD_TYPE(Geom_SweptSurface))))
748 gp_Cylinder aCyl1, aCyl2;
749 if (getCylinder(S1, aCyl1) && getCylinder(S2, aCyl2)) {
750 if (fabs(aCyl1.Radius() - aCyl2.Radius()) < aPrec) {
751 gp_Dir aDir1 = aCyl1.Position().Direction();
752 gp_Dir aDir2 = aCyl2.Position().Direction();
753 if (aDir1.IsParallel(aDir2, aPrec)) {
754 gp_Pnt aLoc1 = aCyl1.Location();
755 gp_Pnt aLoc2 = aCyl2.Location();
756 gp_Vec aVec12 (aLoc1, aLoc2);
757 if (aVec12.SquareMagnitude() < aPrec*aPrec ||
758 aVec12.IsParallel(aDir1, aPrec)) {
769 //=======================================================================
770 //function : MovePCurves
772 //=======================================================================
773 void BlockFix_UnionFaces::MovePCurves(TopoDS_Face& aTarget,
774 const TopoDS_Face& aSource) const
777 for(TopExp_Explorer wexp(aSource,TopAbs_WIRE);wexp.More();wexp.Next()) {
778 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire(TopoDS::Wire(wexp.Current()),
779 aTarget, Precision::Confusion());
781 Standard_Boolean isReoredFailed = sfw->StatusReorder ( ShapeExtend_FAIL );
782 sfw->FixEdgeCurves();
787 sfw->FixDegenerated();
789 // remove degenerated edges from not degenerated points
790 ShapeAnalysis_Edge sae;
791 Handle(ShapeExtend_WireData) sewd = sfw->WireData();
792 for(Standard_Integer i = 1; i<=sewd->NbEdges();i++) {
793 TopoDS_Edge E = sewd->Edge(i);
794 if(BRep_Tool::Degenerated(E)&&!sae.HasPCurve(E,aTarget)) {
800 TopoDS_Wire ResWire = sfw->Wire();
801 B.Add(aTarget,ResWire);