From 0a5e9121ca489bfb8dd11537e601bc58150fcd04 Mon Sep 17 00:00:00 2001 From: dbv Date: Fri, 5 Aug 2016 16:15:54 +0300 Subject: [PATCH] Issue #1620: Fixed orientation of revolution --- .../ConstructionPlugin_Plane.cpp | 2 +- src/GeomAPI/GeomAPI_Face.cpp | 53 ++++++++++--------- src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp | 35 ------------ src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h | 3 -- src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp | 19 ++++--- src/PartSet/PartSet_WidgetSketchLabel.cpp | 4 +- src/SketchPlugin/SketchPlugin_Sketch.cpp | 2 +- 7 files changed, 44 insertions(+), 74 deletions(-) diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp index 28b6e8b27..d08fa90dc 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp @@ -265,7 +265,7 @@ std::shared_ptr ConstructionPlugin_Plane::createByDistanceFromOth std::shared_ptr aFace(new GeomAPI_Face(aShape)); - std::shared_ptr aPln = GeomAlgoAPI_FaceBuilder::plane(aFace); + std::shared_ptr aPln = aFace->getPlane(); std::shared_ptr aOrig = aPln->location(); std::shared_ptr aDir = aPln->direction(); diff --git a/src/GeomAPI/GeomAPI_Face.cpp b/src/GeomAPI/GeomAPI_Face.cpp index ff6eafc60..096c4bd16 100644 --- a/src/GeomAPI/GeomAPI_Face.cpp +++ b/src/GeomAPI/GeomAPI_Face.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -85,31 +86,31 @@ bool GeomAPI_Face::isCylindrical() const std::shared_ptr GeomAPI_Face::getPlane() const { - const TopoDS_Shape& aShape = const_cast(this)->impl(); - BRepAdaptor_Surface aSurfAdapt(TopoDS::Face(aShape)); - - if (aSurfAdapt.GetType() != GeomAbs_Plane) - return std::shared_ptr(); - - // Obtain central point - double aUMin, aUMax, aVMin, aVMax; - aUMin = aSurfAdapt.FirstUParameter(); - aUMax = aSurfAdapt.LastUParameter(); - aVMin = aSurfAdapt.FirstVParameter(); - aVMax = aSurfAdapt.LastVParameter(); - gp_Pnt aCentralPnt; - gp_Vec aDU, aDV; - aSurfAdapt.D1((aUMin+aUMax)*0.5, (aVMin+aVMax)*0.5, aCentralPnt, aDU, aDV); - std::shared_ptr aCenter( - new GeomAPI_Pnt(aCentralPnt.X(), aCentralPnt.Y(), aCentralPnt.Z())); - - // Obtain plane direction - gp_XYZ aNormalVec = aDU.XYZ().Crossed(aDV.XYZ()); - if (aNormalVec.SquareModulus() < Precision::Confusion() * Precision::Confusion()) - return std::shared_ptr(); - std::shared_ptr aNormal( - new GeomAPI_Dir(aNormalVec.X(), aNormalVec.Y(), aNormalVec.Z())); - - std::shared_ptr aResult(new GeomAPI_Pln(aCenter, aNormal)); + std::shared_ptr aResult; + TopoDS_Shape aShape = this->impl(); + if (aShape.IsNull()) + return aResult; // null shape + if (aShape.ShapeType() != TopAbs_FACE) + return aResult; // not face + TopoDS_Face aFace = TopoDS::Face(aShape); + if (aFace.IsNull()) + return aResult; // not face + Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace); + if (aSurf.IsNull()) + return aResult; // no surface + GeomLib_IsPlanarSurface isPlanar(aSurf); + if(!isPlanar.IsPlanar()) { + return aResult; + } + gp_Pln aPln = isPlanar.Plan(); + double aA, aB, aC, aD; + aPln.Coefficients(aA, aB, aC, aD); + if (aFace.Orientation() == TopAbs_REVERSED) { + aA = -aA; + aB = -aB; + aC = -aC; + aD = -aD; + } + aResult = std::shared_ptr(new GeomAPI_Pln(aA, aB, aC, aD)); return aResult; } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp index b5c5a4aa7..25c0a005a 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -123,37 +122,3 @@ std::shared_ptr GeomAlgoAPI_FaceBuilder::planarFaceByFaceAndVertex aFace->setImpl(new TopoDS_Face(aMakeFace.Face())); return aFace; } - -//================================================================================================== -std::shared_ptr GeomAlgoAPI_FaceBuilder::plane(const std::shared_ptr theFace) -{ - std::shared_ptr aResult; - if (!theFace) - return aResult; // bad shape - TopoDS_Shape aShape = theFace->impl(); - if (aShape.IsNull()) - return aResult; // null shape - if (aShape.ShapeType() != TopAbs_FACE) - return aResult; // not face - TopoDS_Face aFace = TopoDS::Face(aShape); - if (aFace.IsNull()) - return aResult; // not face - Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace); - if (aSurf.IsNull()) - return aResult; // no surface - GeomLib_IsPlanarSurface isPlanar(aSurf); - if(!isPlanar.IsPlanar()) { - return aResult; - } - gp_Pln aPln = isPlanar.Plan(); - double aA, aB, aC, aD; - aPln.Coefficients(aA, aB, aC, aD); - if (aFace.Orientation() == TopAbs_REVERSED) { - aA = -aA; - aB = -aB; - aC = -aC; - aD = -aD; - } - aResult = std::shared_ptr(new GeomAPI_Pln(aA, aB, aC, aD)); - return aResult; -} \ No newline at end of file diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h index c33013f02..4b6524929 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h @@ -50,9 +50,6 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_FaceBuilder /// Creates a planar face parallel to theFace and passing through theVertex. static std::shared_ptr planarFaceByFaceAndVertex(const std::shared_ptr theFace, const std::shared_ptr theVertex); - - /// Returns the plane of the planar face. If it is not planar, returns empty ptr. - static std::shared_ptr plane(const std::shared_ptr theFace); }; #endif diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp index b6bc188eb..9ff572fb4 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp @@ -7,6 +7,7 @@ #include "GeomAlgoAPI_Revolution.h" #include +#include #include #include #include @@ -236,8 +237,12 @@ void GeomAlgoAPI_Revolution::build(const GeomShapePtr& theBaseSh if(!isFromPlanar.IsPlanar() || !isToPlanar.IsPlanar()) {// non-planar shapes is not supported for revolution bounding return; } - gp_Pln aFromPln = isFromPlanar.Plan(); - gp_Pln aToPln = isToPlanar.Plan(); + + std::shared_ptr aGeomFromFace(new GeomAPI_Face(theFromShape)); + std::shared_ptr aGeomToFace(new GeomAPI_Face(theToShape)); + + gp_Pln aFromPln = aGeomFromFace->getPlane()->impl(); + gp_Pln aToPln = aGeomToFace->getPlane()->impl(); // Orienting bounding planes properly so that the center of mass of the base face stays // on the result shape after cut. @@ -323,21 +328,23 @@ void GeomAlgoAPI_Revolution::build(const GeomShapePtr& theBaseSh aResult = aRevolBuilder->Shape(); // Getting bounding face. - TopoDS_Face aBoundingFace; bool isFromFaceSet = false; + std::shared_ptr aGeomBoundingFace; if(theFromShape) { - aBoundingFace = TopoDS::Face(theFromShape->impl()); + aGeomBoundingFace.reset(new GeomAPI_Face(theFromShape)); isFromFaceSet = true; } else if(theToShape) { - aBoundingFace = TopoDS::Face(theToShape->impl()); + aGeomBoundingFace.reset(new GeomAPI_Face(theToShape)); } + TopoDS_Face aBoundingFace = TopoDS::Face(aGeomBoundingFace->impl()); // Getting plane from bounding face. GeomLib_IsPlanarSurface isBoundingPlanar(BRep_Tool::Surface(aBoundingFace)); if(!isBoundingPlanar.IsPlanar()) { // non-planar shapes is not supported for revolution bounding return; } - gp_Pln aBoundingPln = isBoundingPlanar.Plan(); + + gp_Pln aBoundingPln = aGeomBoundingFace->getPlane()->impl(); // Orienting bounding plane properly so that the center of mass of the base face stays // on the result shape after cut. diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 9a94798aa..a19b96a37 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -258,7 +258,7 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs if (aGShape.get() != NULL) { // get plane parameters std::shared_ptr aFace(new GeomAPI_Face(aGShape)); - std::shared_ptr aPlane = GeomAlgoAPI_FaceBuilder::plane(aFace); + std::shared_ptr aPlane = aFace->getPlane(); std::shared_ptr aDir = aPlane->direction(); gp_XYZ aXYZ = aDir->impl().XYZ(); double aTwist = 0.0; @@ -489,7 +489,7 @@ std::shared_ptr PartSet_WidgetSketchLabel::setSketchPlane(const Fea // get plane parameters std::shared_ptr aFace(new GeomAPI_Face(aGShape)); - std::shared_ptr aPlane = GeomAlgoAPI_FaceBuilder::plane(aFace); + std::shared_ptr aPlane = aFace->getPlane(); if (!aPlane.get()) return std::shared_ptr(); diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index ef2ef9c69..5d1b9d3d2 100755 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -217,7 +217,7 @@ void SketchPlugin_Sketch::attributeChanged(const std::string& theID) { if (aSelection) { // update arguments due to the selection value // update the sketch plane std::shared_ptr aFace(new GeomAPI_Face(aSelection)); - std::shared_ptr aPlane = GeomAlgoAPI_FaceBuilder::plane(aFace); + std::shared_ptr aPlane = aFace->getPlane(); if (aPlane) { double anA, aB, aC, aD; aPlane->coefficients(anA, aB, aC, aD); -- 2.39.2