X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_Extrusion.cpp;h=29c4aec277baa4167af118b36f05d4f343f9e261;hb=38afbd899a8645c83e17f2c24a17a2b7414911b4;hp=b7e4753079617b402eb64d7b99418b5e34968f43;hpb=b7932ca8834d1561ac081efc42f365bee3f2456d;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.cpp index b7e475307..29c4aec27 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.cpp @@ -1,59 +1,138 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: GeomAlgoAPI_Extrusion.cpp // Created: 06 Jun 2014 // Author: Artem ZHIDKOV #include - +#include +#include +#include #include - #include +#include #include #include #include - +#include +#include +#include +#include +#include #include +#include +#include +#include +#include + const double tolerance = Precision::Angular(); +// Constructor +GeomAlgoAPI_Extrusion::GeomAlgoAPI_Extrusion( + std::shared_ptr theBasis, double theSize) +: mySize(theSize), myDone(false), myShape(new GeomAPI_Shape()), + myFirst(new GeomAPI_Shape()), myLast(new GeomAPI_Shape()) +{ + build(theBasis); +} -boost::shared_ptr GeomAlgoAPI_Extrusion::makeExtrusion( - boost::shared_ptr theShape, boost::shared_ptr theDir, - double theSize) +//============================================================================ +void GeomAlgoAPI_Extrusion::build(const std::shared_ptr& theBasis) { - const TopoDS_Shape& aShape = theShape->impl(); - gp_Vec aDir(theDir->impl().XYZ() * theSize); + bool isFirstNorm = true; + gp_Dir aShapeNormal; + TopoDS_Face aBasis = TopoDS::Face(theBasis->impl()); + Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( + BRep_Tool::Surface(aBasis)); + if (aPlane.IsNull()) // non-planar shapes is not supported for extrusion yet + return; - TopoDS_Shape aPrism = BRepPrimAPI_MakePrism(aShape, aDir); - if (aPrism.IsNull()) - return boost::shared_ptr(); + const gp_Dir& aNormal = aPlane->Pln().Axis().Direction(); + gp_Vec aVec(aNormal); + aVec = aVec * mySize; - boost::shared_ptr aResult(new GeomAPI_Shape()); - aResult->setImpl(new TopoDS_Shape(aPrism)); - return aResult; + BRepPrimAPI_MakePrism* aBuilder = new BRepPrimAPI_MakePrism(aBasis, aVec); + if(aBuilder) { + setImpl(aBuilder); + myDone = aBuilder->IsDone() == Standard_True; + if (myDone) { + TopoDS_Shape aResult; + if(aBuilder->Shape().ShapeType() == TopAbs_COMPOUND) + aResult = GeomAlgoAPI_DFLoader::refineResult(aBuilder->Shape()); + else + aResult = aBuilder->Shape(); + // fill data map to keep correct orientation of sub-shapes + for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) { + std::shared_ptr aCurrentShape(new GeomAPI_Shape()); + aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current())); + myMap.bind(aCurrentShape, aCurrentShape); + } + myShape->setImpl(new TopoDS_Shape(aResult)); + myFirst->setImpl(new TopoDS_Shape(aBuilder->FirstShape())); + myLast->setImpl(new TopoDS_Shape(aBuilder-> LastShape())); + myMkShape = new GeomAlgoAPI_MakeShape (aBuilder); + } + } } -boost::shared_ptr GeomAlgoAPI_Extrusion::makeExtrusion( - boost::shared_ptr theShape, double theSize) +//============================================================================ +const bool GeomAlgoAPI_Extrusion::isDone() const +{return myDone;} + +//============================================================================ +const bool GeomAlgoAPI_Extrusion::isValid() const { - bool isFirstNorm = true; - gp_Dir aShapeNormal; + BRepCheck_Analyzer aChecker(myShape->impl()); + return (aChecker.IsValid() == Standard_True); +} - const TopoDS_Shape& aShape = theShape->impl(); - TopExp_Explorer aFaceExp(aShape, TopAbs_FACE); - for (; aFaceExp.More(); aFaceExp.Next()) { - const TopoDS_Face& aFace = (const TopoDS_Face&) aFaceExp.Current(); - Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(aFace)); - if (aPlane.IsNull()) // non-planar shapes is not supported for extrusion yet - continue; - - const gp_Dir& aNormal = aPlane->Pln().Axis().Direction(); - if (isFirstNorm) { - aShapeNormal = aNormal; - isFirstNorm = false; - } else if (!aShapeNormal.IsEqual(aNormal, tolerance)) // non-planar shapes is not supported for extrusion yet - return boost::shared_ptr(); +//============================================================================ +const bool GeomAlgoAPI_Extrusion::hasVolume() const +{ + bool hasVolume(false); + if(isValid()) { + const TopoDS_Shape& aRShape = myShape->impl(); + GProp_GProps aGProp; + BRepGProp::VolumeProperties(aRShape, aGProp); + if(aGProp.Mass() > Precision::Confusion()) + hasVolume = true; } + return hasVolume; +} + +//============================================================================ +const std::shared_ptr& GeomAlgoAPI_Extrusion::shape () const +{ + return myShape; +} + +//============================================================================ +const std::shared_ptr& GeomAlgoAPI_Extrusion::firstShape() +{ + return myFirst; +} + +//============================================================================ +const std::shared_ptr& GeomAlgoAPI_Extrusion::lastShape() +{ + return myLast; +} - boost::shared_ptr aDir( - new GeomAPI_Dir(aShapeNormal.X(), aShapeNormal.Y(), aShapeNormal.Z())); +//============================================================================ +void GeomAlgoAPI_Extrusion::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const +{ + theMap = myMap; +} - return GeomAlgoAPI_Extrusion::makeExtrusion(theShape, aDir, theSize); +//============================================================================ +GeomAlgoAPI_MakeShape * GeomAlgoAPI_Extrusion::makeShape() const +{ + return myMkShape; } + +//============================================================================ +GeomAlgoAPI_Extrusion::~GeomAlgoAPI_Extrusion() +{ + if (myImpl) { + myMap.clear(); + } +} \ No newline at end of file