From 6409bf5ed45ffadb2b3619fa9cfcb63f41b23f79 Mon Sep 17 00:00:00 2001 From: dbv Date: Thu, 4 Jun 2015 12:08:02 +0300 Subject: [PATCH] Naming fix for revolution. --- src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp | 69 ++++++++++------------ 1 file changed, 31 insertions(+), 38 deletions(-) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp index 53b475656..f2377dd32 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp @@ -200,11 +200,6 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aFromCutBuilder))); aResult = aFromCutBuilder->Shape(); - // Setting naming. - if(aFromCutBuilder->Modified(aRotatedFromFace).Extent() > 0) { - myFirst->setImpl(new TopoDS_Shape(aFromCutBuilder->Modified(aRotatedFromFace).First())); - } - // Cutting revolution with to plane. BRepAlgoAPI_Cut* aToCutBuilder = new BRepAlgoAPI_Cut(aResult, aToSolid); aToCutBuilder->Build(); @@ -214,24 +209,22 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aToCutBuilder))); aResult = aToCutBuilder->Shape(); - // Setting naming. - if(aToCutBuilder->Modified(myFirst->impl()).Extent() > 0) { - myFirst->setImpl(new TopoDS_Shape(aToCutBuilder->Modified(myFirst->impl()).First())); - } else { - for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More (); anExp.Next ()) { - const TopoDS_Shape& aFace = anExp.Current(); - if (aFace.IsPartner(myFirst->impl())) { - myFirst->implPtr()->Orientation(aFace.Orientation()); - } - } - } - if(aToCutBuilder->Modified(aRotatedToFace).Extent() > 0) { - myLast->setImpl(new TopoDS_Shape(aToCutBuilder->Modified(aRotatedToFace).First())); - } - // If after cut we got more than one solids then take closest to the center of mass of the base face. aResult = findClosest(aResult, aBasisCentr); + // Setting naming. + for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More (); anExp.Next ()) { + const TopoDS_Shape& aFaceOnResult = anExp.Current(); + Handle(Geom_Surface) aFaceSurface = BRep_Tool::Surface(TopoDS::Face(aFaceOnResult)); + Handle(Geom_Surface) aFromSurface = BRep_Tool::Surface(TopoDS::Face(aRotatedFromFace)); + Handle(Geom_Surface) aToSurface = BRep_Tool::Surface(TopoDS::Face(aRotatedToFace)); + if(aFaceSurface == aFromSurface) { + myFirst->setImpl(new TopoDS_Shape(aFaceOnResult)); + } + if(aFaceSurface == aToSurface) { + myLast->setImpl(new TopoDS_Shape(aFaceOnResult)); + } + } } else { //Case 3: When only one bounding plane was set. // Getting bounding face. TopoDS_Face aBoundingFace; @@ -272,6 +265,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi gp_Trsf aBoundingTrsf; aBoundingTrsf.SetRotation(anAxis, aBoundingRotAngle / 180.0 * M_PI); BRepBuilderAPI_Transform aBoundingTransform(aBoundingSolid, aBoundingTrsf, true); + TopoDS_Shape aRotatedBoundingFace = aBoundingTransform.Modified(aBoundingFace).First(); aBoundingSolid = aBoundingTransform.Shape(); // Making revolution to the 360 angle. @@ -309,6 +303,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi double aBasisRotAngle = isFromFaceSet ? myToAngle : -myFromAngle; aBasisTrsf.SetRotation(anAxis, aBasisRotAngle / 180.0 * M_PI); BRepBuilderAPI_Transform aBasisTransform(aBasisSolid, aBasisTrsf, true); + TopoDS_Shape aRotatedBasisFace = aBasisTransform.Modified(aBasisFace).First(); aBasisSolid = aBasisTransform.Shape(); // Cutting revolution with basis face. @@ -320,29 +315,27 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi if(anExp.More()) { aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aBasisCutBuilder))); aResult = aCutResult; - - // Setting naming. - std::shared_ptr aBoundPtr = isFromFaceSet ? myFirst : myLast; - if(aBasisCutBuilder->Modified(aBoundPtr->impl()).Extent() > 0) { - aBoundPtr->setImpl(new TopoDS_Shape(aBasisCutBuilder->Modified(aBoundPtr->impl()).First())); - } else { - for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More (); anExp.Next ()) { - const TopoDS_Shape& aFace = anExp.Current(); - if (aFace.IsPartner(aBoundPtr->impl())) { - aBoundPtr->implPtr()->Orientation(aFace.Orientation()); - } - } - } - - if(aBasisCutBuilder->Modified(aBasisFace).Extent() > 0) { - std::shared_ptr aPtr = isFromFaceSet ? myLast : myFirst; - aPtr->setImpl(new TopoDS_Shape(aBasisCutBuilder->Modified(aBasisFace).First())); - } } } // If after cut we got more than one solids then take closest to the center of mass of the base face. aResult = findClosest(aResult, aBasisCentr); + + // Setting naming. + for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More (); anExp.Next ()) { + const TopoDS_Shape& aFaceOnResult = anExp.Current(); + Handle(Geom_Surface) aFaceSurface = BRep_Tool::Surface(TopoDS::Face(aFaceOnResult)); + Handle(Geom_Surface) aBoundingSurface = BRep_Tool::Surface(TopoDS::Face(aRotatedBoundingFace)); + Handle(Geom_Surface) aBasisSurface = BRep_Tool::Surface(TopoDS::Face(aRotatedBasisFace)); + if(aFaceSurface == aBoundingSurface) { + std::shared_ptr aPtr = isFromFaceSet ? myFirst : myLast; + aPtr->setImpl(new TopoDS_Shape(aFaceOnResult)); + } + if(aFaceSurface == aBasisSurface) { + std::shared_ptr aPtr = isFromFaceSet ? myLast : myFirst; + aPtr->setImpl(new TopoDS_Shape(aFaceOnResult)); + } + } } TopExp_Explorer anExp(aResult, TopAbs_SOLID); -- 2.39.2