+//=======================================================================
+//function : makeSolid
+//purpose : auxiliary for CreatePipeWithDifferentSections
+//=======================================================================
+Standard_Boolean makeSolid(
+ BRepOffsetAPI_MakePipeShell aBuilder,
+ const TopoDS_Shape& aSh1,
+ const TopoDS_Shape& aSh2,
+ TopoDS_Shape& aShape)
+{
+ Standard_Boolean isDone = Standard_True;
+ Standard_Integer nbPlanar = 0;
+ if (aSh1.ShapeType() == TopAbs_FACE && aSh2.ShapeType() == TopAbs_FACE)
+ {
+ Handle(Geom_Surface) aS = BRep_Tool::Surface(TopoDS::Face(aSh1));
+ if (aS->IsKind(STANDARD_TYPE(Geom_Plane))) {
+ nbPlanar++;
+ }
+ else if (aS->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
+ Handle(Geom_RectangularTrimmedSurface) aTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(aS);
+ if (aTS->BasisSurface()->IsKind(STANDARD_TYPE(Geom_Plane))) {
+ nbPlanar++;
+ }
+ }
+ aS = BRep_Tool::Surface(TopoDS::Face(aSh2));
+ if (aS->IsKind(STANDARD_TYPE(Geom_Plane))) {
+ nbPlanar++;
+ }
+ else if (aS->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
+ Handle(Geom_RectangularTrimmedSurface) aTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(aS);
+ if (aTS->BasisSurface()->IsKind(STANDARD_TYPE(Geom_Plane))) {
+ nbPlanar++;
+ }
+ }
+ }
+ if (nbPlanar < 2) {
+ TopoDS_Shape aPipe = aBuilder.Shape();
+ // make sewing for result
+ Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
+ Standard_Real aTol = Precision::Confusion();
+ aSewing->SetTolerance(aTol);
+ aSewing->SetFaceMode(Standard_True);
+ aSewing->SetFloatingEdgesMode(Standard_False);
+ aSewing->SetNonManifoldMode(Standard_False);
+ TopExp_Explorer anExp;
+ for (anExp.Init(aPipe, TopAbs_FACE); anExp.More(); anExp.Next()) {
+ aSewing->Add(anExp.Current());
+ }
+ aSewing->Add(aSh1);
+ aSewing->Add(aSh2);
+ aSewing->Perform();
+ aShape = aSewing->SewedShape();
+ if (aShape.ShapeType() == TopAbs_SHELL) {
+ // Build a solid.
+ BRepBuilderAPI_MakeSolid aMkSolid;
+ aMkSolid.Add(TopoDS::Shell(aShape));
+ if (!aMkSolid.IsDone()) {
+ isDone = Standard_False;
+ }
+ else {
+ TopoDS_Solid aSolid = aMkSolid.Solid();
+ BRepClass3d_SolidClassifier aSC(aSolid);
+ aSC.PerformInfinitePoint(Precision::Confusion());
+ if (aSC.State() == TopAbs_IN) {
+ aShape = aSolid.Reversed();
+ }
+ else {
+ aShape = aSolid;
+ }
+ }
+ }
+ else {
+ isDone = Standard_False;
+ }
+ }
+ else {
+ isDone = Standard_False;
+ }
+ if (!isDone) {
+ isDone = aBuilder.MakeSolid();
+ if (isDone) {
+ aShape = aBuilder.Shape();
+ }
+ }
+ return isDone;
+}
+