From f6384badef95ee8e9aff9ccfa5b49e339df58822 Mon Sep 17 00:00:00 2001 From: dbv Date: Fri, 8 Apr 2016 11:19:47 +0300 Subject: [PATCH] Fixes for naming in revolution --- src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp | 41 +++----- src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp | 110 +++++++++++++-------- 2 files changed, 85 insertions(+), 66 deletions(-) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp index 45e0adfeb..510668afa 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp @@ -110,25 +110,30 @@ void GeomAlgoAPI_Prism::build(const GeomShapePtr& theBaseShape, } // Getting direction. - gp_Pnt aLoc; gp_Vec aDirVec; std::shared_ptr aBaseLoc; std::shared_ptr aBaseDir; GeomShapePtr aBasePlane; const bool isBoundingShapesSet = theFromShape.get() || theToShape.get(); BRepBuilderAPI_FindPlane aFindPlane(aBaseShape); - if(aBaseShape.ShapeType() == TopAbs_VERTEX || aBaseShape.ShapeType() == TopAbs_EDGE || - aFindPlane.Found() != Standard_True) { - // Direction should be set. - if(!theDirection.get()) { - return; - } - + if(theDirection.get()) { aBaseDir = theDirection; aDirVec = theDirection->impl(); + } else if(aBaseShape.ShapeType() != TopAbs_VERTEX && + aBaseShape.ShapeType() != TopAbs_EDGE && + aFindPlane.Found() == Standard_True){ + Handle(Geom_Plane) aPlane = aFindPlane.Plane(); + gp_Pnt aLoc = aPlane->Axis().Location(); + aDirVec = aPlane->Axis().Direction(); + aBaseLoc.reset(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z())); + aBaseDir.reset(new GeomAPI_Dir(aDirVec.X(), aDirVec.Y(), aDirVec.Z())); + } else { + return; + } + if(!aBaseLoc.get()) { + gp_Pnt aLoc; gp_XYZ aDirXYZ = aDirVec.XYZ(); Standard_Real aMinParam = Precision::Infinite(); - for(TopExp_Explorer anExp(aBaseShape, TopAbs_VERTEX); anExp.More(); anExp.Next()) { const TopoDS_Shape& aVertex = anExp.Current(); gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aVertex)); @@ -138,19 +143,8 @@ void GeomAlgoAPI_Prism::build(const GeomShapePtr& theBaseShape, aLoc = aPnt; } } - } else { - if(!theDirection.get()) { - Handle(Geom_Plane) aPlane = aFindPlane.Plane(); - aLoc = aPlane->Axis().Location(); - aDirVec = aPlane->Axis().Direction(); - - aBaseDir.reset(new GeomAPI_Dir(aDirVec.X(), aDirVec.Y(), aDirVec.Z())); - } else { - aBaseDir = theDirection; - aDirVec = theDirection->impl(); - } + aBaseLoc.reset(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z())); } - aBaseLoc.reset(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z())); aBasePlane = GeomAlgoAPI_FaceBuilder::planarFace(aBaseLoc, aBaseDir); TopoDS_Shape aResult; @@ -372,16 +366,15 @@ void GeomAlgoAPI_Prism::build(const GeomShapePtr& theBaseShape, // Naming for extrusion from vertex, edge. for(TopExp_Explorer anExp(aResult, aShapeTypeToExp); anExp.More(); anExp.Next()) { const TopoDS_Shape& aShape = anExp.Current(); + GeomShapePtr aGeomSh(new GeomAPI_Shape()); if(aShapeTypeToExp == TopAbs_VERTEX) { gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape)); IntTools_Context anIntTools; if(anIntTools.IsValidPointForFace(aPnt, aToFace, Precision::Confusion()) == Standard_True) { - GeomShapePtr aGeomSh(new GeomAPI_Shape()); aGeomSh->setImpl(new TopoDS_Shape(aShape)); this->addToShape(aGeomSh); } if(anIntTools.IsValidPointForFace(aPnt, aFromFace, Precision::Confusion()) == Standard_True) { - GeomShapePtr aGeomSh(new GeomAPI_Shape()); aGeomSh->setImpl(new TopoDS_Shape(aShape)); this->addFromShape(aGeomSh); } @@ -390,14 +383,12 @@ void GeomAlgoAPI_Prism::build(const GeomShapePtr& theBaseShape, BRepLib_CheckCurveOnSurface anEdgeCheck(anEdge, aToFace); anEdgeCheck.Perform(); if(anEdgeCheck.MaxDistance() < Precision::Confusion()) { - GeomShapePtr aGeomSh(new GeomAPI_Shape()); aGeomSh->setImpl(new TopoDS_Shape(aShape)); this->addToShape(aGeomSh); } anEdgeCheck.Init(anEdge, aFromFace); anEdgeCheck.Perform(); if(anEdgeCheck.MaxDistance() < Precision::Confusion()) { - GeomShapePtr aGeomSh(new GeomAPI_Shape()); aGeomSh->setImpl(new TopoDS_Shape(aShape)); this->addFromShape(aGeomSh); } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp index 38b2eb57e..92e5924ea 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp @@ -297,16 +297,15 @@ void GeomAlgoAPI_Revolution::build(const GeomShapePtr& theBaseSh // Setting naming. for(TopExp_Explorer anExp(aResult, aShapeTypeToExp); anExp.More (); anExp.Next ()) { const TopoDS_Shape& aShape = anExp.Current(); + GeomShapePtr aGeomSh(new GeomAPI_Shape()); if(aShapeTypeToExp == TopAbs_VERTEX) { gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape)); IntTools_Context anIntTools; if(anIntTools.IsValidPointForFace(aPnt, TopoDS::Face(aRotatedToFace), Precision::Confusion()) == Standard_True) { - GeomShapePtr aGeomSh(new GeomAPI_Shape()); aGeomSh->setImpl(new TopoDS_Shape(aShape)); this->addToShape(aGeomSh); } if(anIntTools.IsValidPointForFace(aPnt, TopoDS::Face(aRotatedFromFace), Precision::Confusion()) == Standard_True) { - GeomShapePtr aGeomSh(new GeomAPI_Shape()); aGeomSh->setImpl(new TopoDS_Shape(aShape)); this->addFromShape(aGeomSh); } @@ -315,14 +314,12 @@ void GeomAlgoAPI_Revolution::build(const GeomShapePtr& theBaseSh BRepLib_CheckCurveOnSurface anEdgeCheck(anEdge, TopoDS::Face(aRotatedToFace)); anEdgeCheck.Perform(); if(anEdgeCheck.MaxDistance() < Precision::Confusion()) { - GeomShapePtr aGeomSh(new GeomAPI_Shape()); aGeomSh->setImpl(new TopoDS_Shape(aShape)); this->addToShape(aGeomSh); } anEdgeCheck.Init(anEdge, TopoDS::Face(aRotatedFromFace)); anEdgeCheck.Perform(); if(anEdgeCheck.MaxDistance() < Precision::Confusion()) { - GeomShapePtr aGeomSh(new GeomAPI_Shape()); aGeomSh->setImpl(new TopoDS_Shape(aShape)); this->addFromShape(aGeomSh); } @@ -331,14 +328,12 @@ void GeomAlgoAPI_Revolution::build(const GeomShapePtr& theBaseSh Handle(Geom_Surface) aFromSurface = BRep_Tool::Surface(TopoDS::Face(aRotatedFromFace)); Handle(Geom_Surface) aToSurface = BRep_Tool::Surface(TopoDS::Face(aRotatedToFace)); if(aFaceSurface == aFromSurface) { - GeomShapePtr aFSHape(new GeomAPI_Shape); - aFSHape->setImpl(new TopoDS_Shape(aShape)); - this->addFromShape(aFSHape); + aGeomSh->setImpl(new TopoDS_Shape(aShape)); + this->addFromShape(aGeomSh); } if(aFaceSurface == aToSurface) { - GeomShapePtr aTSHape(new GeomAPI_Shape); - aTSHape->setImpl(new TopoDS_Shape(aShape)); - this->addToShape(aTSHape); + aGeomSh->setImpl(new TopoDS_Shape(aShape)); + this->addToShape(aGeomSh); } } } @@ -403,13 +398,18 @@ void GeomAlgoAPI_Revolution::build(const GeomShapePtr& theBaseSh } this->appendAlgo(std::shared_ptr(new GeomAlgoAPI_MakeShape(aBoundingCutBuilder))); aResult = aBoundingCutBuilder->Shape(); + if(aResult.ShapeType() == TopAbs_COMPOUND) { + aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); + } // Setting naming. - const TopTools_ListOfShape& aBndShapes = aBoundingCutBuilder->Modified(aBoundingFace); - for(TopTools_ListIteratorOfListOfShape anIt(aBndShapes); anIt.More(); anIt.Next()) { - GeomShapePtr aShape(new GeomAPI_Shape()); - aShape->setImpl(new TopoDS_Shape(anIt.Value())); - isFromFaceSet ? this->addFromShape(aShape) : this->addToShape(aShape); + if(aShapeTypeToExp == TopAbs_FACE) { + const TopTools_ListOfShape& aBndShapes = aBoundingCutBuilder->Modified(aBoundingFace); + for(TopTools_ListIteratorOfListOfShape anIt(aBndShapes); anIt.More(); anIt.Next()) { + GeomShapePtr aShape(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(anIt.Value())); + isFromFaceSet ? this->addFromShape(aShape) : this->addToShape(aShape); + } } // Try to cut with base face. If it can not be done then keep result of cut with bounding plane. @@ -425,11 +425,10 @@ void GeomAlgoAPI_Revolution::build(const GeomShapePtr& theBaseSh aBasePlane->Axis().Direction().Y(), aBasePlane->Axis().Direction().Z())); GeomShapePtr aPln = GeomAlgoAPI_FaceBuilder::planarFace(theCenter, theNormal); - aList.push_back(aSh); std::list > aBoundingPoints = GeomAlgoAPI_ShapeTools::getBoundingBox(aList); - aSh = GeomAlgoAPI_ShapeTools::fitPlaneToBox(aPln, aBoundingPoints); + aModifiedBaseShape = aSh->impl(); } else { aModifiedBaseShape = aBaseShape; } @@ -459,27 +458,24 @@ void GeomAlgoAPI_Revolution::build(const GeomShapePtr& theBaseSh aBaseCutBuilder->Build(); if(aBaseCutBuilder->IsDone()) { TopoDS_Shape aCutResult = aBaseCutBuilder->Shape(); - TopExp_Explorer anExp(aCutResult, TopAbs_SOLID); - if(anExp.More()) { + TopoDS_Iterator aCheckIt(aCutResult); + if(aCheckIt.More()) { this->appendAlgo(std::shared_ptr(new GeomAlgoAPI_MakeShape(aBaseCutBuilder))); aResult = aCutResult; + if(aResult.ShapeType() == TopAbs_COMPOUND) { + aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); + } + if(aShapeTypeToExp == TopAbs_FACE) { + const TopTools_ListOfShape& aBsShapes = aBaseCutBuilder->Modified(aBoundingFace); + for(TopTools_ListIteratorOfListOfShape anIt(aBsShapes); anIt.More(); anIt.Next()) { + GeomShapePtr aShape(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(anIt.Value())); + isFromFaceSet ? this->addToShape(aShape) : this->addFromShape(aShape); + } + } } } - const TopTools_ListOfShape& aBsShapes = aBaseCutBuilder->Modified(aBoundingFace); - for(TopTools_ListIteratorOfListOfShape anIt(aBsShapes); anIt.More(); anIt.Next()) { - GeomShapePtr aShape(new GeomAPI_Shape()); - aShape->setImpl(new TopoDS_Shape(anIt.Value())); - isFromFaceSet ? this->addToShape(aShape) : this->addFromShape(aShape); - } - - TopExp_Explorer anExp(aResult, TopAbs_SOLID); - if(!anExp.More()) { - return; - } - if(aResult.ShapeType() == TopAbs_COMPOUND) { - aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); - } if(aResult.ShapeType() == TopAbs_COMPOUND) { GeomShapePtr aCompound(new GeomAPI_Shape); aCompound->setImpl(new TopoDS_Shape(aResult)); @@ -505,14 +501,46 @@ void GeomAlgoAPI_Revolution::build(const GeomShapePtr& theBaseSh aResult = findClosest(aResult, aBaseCentre); // 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)); - if(aFaceSurface == aBoundingSurface) { - GeomShapePtr aShape(new GeomAPI_Shape()); - aShape->setImpl(new TopoDS_Shape(aFaceOnResult)); - isFromFaceSet ? this->addFromShape(aShape) : this->addToShape(aShape); + for(TopExp_Explorer anExp(aResult, aShapeTypeToExp); anExp.More (); anExp.Next ()) { + const TopoDS_Shape& aShape = anExp.Current(); + GeomShapePtr aGeomSh(new GeomAPI_Shape()); + if(aShapeTypeToExp == TopAbs_VERTEX) { + gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape)); + IntTools_Context anIntTools; + if(anIntTools.IsValidPointForFace(aPnt, TopoDS::Face(aRotatedBoundingFace), Precision::Confusion()) == Standard_True) { + aGeomSh->setImpl(new TopoDS_Shape(aShape)); + isFromFaceSet ? this->addFromShape(aGeomSh) : this->addToShape(aGeomSh); + } + if(anIntTools.IsValidPointForFace(aPnt, TopoDS::Face(aModifiedBaseShape), Precision::Confusion()) == Standard_True) { + aGeomSh->setImpl(new TopoDS_Shape(aShape)); + isFromFaceSet ? this->addToShape(aGeomSh) : this->addFromShape(aGeomSh); + } + } else if(aShapeTypeToExp == TopAbs_EDGE) { + TopoDS_Edge anEdge = TopoDS::Edge(aShape); + BRepLib_CheckCurveOnSurface anEdgeCheck(anEdge, TopoDS::Face(aRotatedBoundingFace)); + anEdgeCheck.Perform(); + if(anEdgeCheck.MaxDistance() < Precision::Confusion()) { + aGeomSh->setImpl(new TopoDS_Shape(aShape)); + isFromFaceSet ? this->addFromShape(aGeomSh) : this->addToShape(aGeomSh); + } + anEdgeCheck.Init(anEdge, TopoDS::Face(aModifiedBaseShape)); + anEdgeCheck.Perform(); + if(anEdgeCheck.MaxDistance() < Precision::Confusion()) { + aGeomSh->setImpl(new TopoDS_Shape(aShape)); + isFromFaceSet ? this->addToShape(aGeomSh) : this->addFromShape(aGeomSh); + } + } else { + Handle(Geom_Surface) aFaceSurface = BRep_Tool::Surface(TopoDS::Face(aShape)); + Handle(Geom_Surface) aBoundingSurface = BRep_Tool::Surface(TopoDS::Face(aRotatedBoundingFace)); + Handle(Geom_Surface) aBaseSurface = BRep_Tool::Surface(TopoDS::Face(aModifiedBaseShape)); + if(aFaceSurface == aBoundingSurface) { + aGeomSh->setImpl(new TopoDS_Shape(aShape)); + isFromFaceSet ? this->addFromShape(aGeomSh) : this->addToShape(aGeomSh); + } + if(aFaceSurface == aBaseSurface) { + aGeomSh->setImpl(new TopoDS_Shape(aShape)); + isFromFaceSet ? this->addToShape(aGeomSh) : this->addFromShape(aGeomSh); + } } } } -- 2.39.2