X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_Extrusion.cpp;h=29c4aec277baa4167af118b36f05d4f343f9e261;hb=8d8878b385494638fbe5fad10bbcdee9c9d04f30;hp=d5f2c4379debded24d1f39ee735f1efac3cbd172;hpb=4fcd5da2d972334e887716499b0ea75d9d6c51c2;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.cpp index d5f2c4379..29c4aec27 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: GeomAlgoAPI_Extrusion.cpp // Created: 06 Jun 2014 // Author: Artem ZHIDKOV @@ -5,7 +7,7 @@ #include #include #include -#include +#include #include #include #include @@ -19,174 +21,118 @@ #include #include #include -#include +#include +#include +#include const double tolerance = Precision::Angular(); - // Constructor -GeomAlgoAPI_Extrusion::GeomAlgoAPI_Extrusion (boost::shared_ptr theBasis, double theSize) - : mySize(theSize), myBuilder(NULL), myDone(false), myShape(new GeomAPI_Shape()) - { - myBasis = theBasis->impl(); - build(); - } - - //============================================================================ - void GeomAlgoAPI_Extrusion::build() - { - bool isFirstNorm = true; - gp_Dir aShapeNormal; - - //const TopoDS_Shape& aShape = theShape->impl(); - Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(TopoDS::Face(myBasis))); - if (aPlane.IsNull()) // non-planar shapes is not supported for extrusion yet - return; - - const gp_Dir& aNormal = aPlane->Pln().Axis().Direction(); - gp_Vec aVec(aNormal); - aVec = aVec * mySize; +// 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); +} - myBuilder = new BRepPrimAPI_MakePrism(myBasis, aVec); - if(myBuilder != NULL) { - myDone = myBuilder->IsDone(); - if(myDone) { - if(myBuilder->Shape().ShapeType() == TopAbs_COMPOUND) - myResult = GeomAlgoAPI_DFLoader::refineResult(myBuilder->Shape()); - else - myResult = myBuilder->Shape(); - myShape->setImpl((void *)&myResult); - myFirst->setImpl((void *)&(myBuilder->FirstShape())); - myLast->setImpl((void *)&(myBuilder-> LastShape())); - } - } +//============================================================================ +void GeomAlgoAPI_Extrusion::build(const std::shared_ptr& theBasis) +{ + 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; + + const gp_Dir& aNormal = aPlane->Pln().Axis().Direction(); + gp_Vec aVec(aNormal); + aVec = aVec * mySize; + + 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); + } } +} - //============================================================================ +//============================================================================ const bool GeomAlgoAPI_Extrusion::isDone() const {return myDone;} - //============================================================================ +//============================================================================ const bool GeomAlgoAPI_Extrusion::isValid() const { - bool isValid(false); - if(myDone && !myBuilder->Shape().IsNull()) { - BRepCheck_Analyzer aChecker(myBuilder->Shape()); - isValid = aChecker.IsValid(); - } - return isValid; - } - - //============================================================================ - const bool GeomAlgoAPI_Extrusion::hasVolume() const - { - bool hasVolume(false); - if(isValid()) { - const TopoDS_Shape& aRShape = myBuilder->Shape(); - GProp_GProps aGProp; - BRepGProp::VolumeProperties(aRShape, aGProp); - if(aGProp.Mass() > Precision::Confusion()) - hasVolume = true; - } - return hasVolume; - } + BRepCheck_Analyzer aChecker(myShape->impl()); + return (aChecker.IsValid() == Standard_True); +} - //============================================================================ -const boost::shared_ptr& GeomAlgoAPI_Extrusion::shape () const -{return myShape;} - - //============================================================================ - const ListOfShape& GeomAlgoAPI_Extrusion::generated(const boost::shared_ptr theShape) - { - myHistory.clear(); - if(myDone) { - const TopTools_ListOfShape& aList = myBuilder->Generated(theShape->impl()); - TopTools_ListIteratorOfListOfShape it(aList); - for(;it.More();it.Next()) { - boost::shared_ptr aShape(new GeomAPI_Shape()); - aShape->setImpl(&(it.Value())); - myHistory.push_back(aShape); - } - } - return myHistory; - } - - //============================================================================ - const boost::shared_ptr& GeomAlgoAPI_Extrusion::firstShape() - { - return myFirst; - } - - //============================================================================ - const boost::shared_ptr& GeomAlgoAPI_Extrusion::lastShape() - { - return myLast; - } - - //============================================================================ - /* - void GeomAlgoAPI_Extrusion::LoadNamingDS(boost::shared_ptr theResultBody, - boost::shared_ptr theContext) +//============================================================================ +const bool GeomAlgoAPI_Extrusion::hasVolume() const { + bool hasVolume(false); if(isValid()) { - const TopoDS_Shape& aShape = myBuilder->Shape(); - TopoDS_Shape aResult = GeomAlgoAPI_DFLoader::refineResult(aShape); - boost::shared_ptr aData = boost::dynamic_pointer_cast(theResultBody->data()); - if (aData) { - const TDF_Label& aShapeLab = aData->shapeLab(); - const Handle(TDF_TagSource)& Tagger = TDF_TagSource::Set(aShapeLab); - if (Tagger.IsNull()) return; - Tagger->Set(0); + const TopoDS_Shape& aRShape = myShape->impl(); + GProp_GProps aGProp; + BRepGProp::VolumeProperties(aRShape, aGProp); + if(aGProp.Mass() > Precision::Confusion()) + hasVolume = true; + } + return hasVolume; +} - TNaming_Builder aBuilder (aShapeLab); - if(myBasis.IsEqual(theContext->impl())) - aBuilder.Generated(aResult); - else - aBuilder.Generated(theContext->impl(), aResult); +//============================================================================ +const std::shared_ptr& GeomAlgoAPI_Extrusion::shape () const +{ + return myShape; +} - TopTools_DataMapOfShapeShape aSubShapes; - for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) { - aSubShapes.Bind(Exp.Current(),Exp.Current()); - } +//============================================================================ +const std::shared_ptr& GeomAlgoAPI_Extrusion::firstShape() +{ + return myFirst; +} - //Insert lateral face : Face from Edge - TNaming_Builder aLateralFaceBuilder(aShapeLab.NewChild()); - GeomAlgoAPI_DFLoader::loadAndOrientGeneratedShapes(*myBuilder, myBasis, TopAbs_EDGE, aLateralFaceBuilder, aSubShapes); +//============================================================================ +const std::shared_ptr& GeomAlgoAPI_Extrusion::lastShape() +{ + return myLast; +} - //Insert bottom face - TopoDS_Shape aBottomFace = myBuilder->FirstShape(); - if (!aBottomFace.IsNull()) { - if (aBottomFace.ShapeType() != TopAbs_COMPOUND) { - TNaming_Builder aBottomBuilder(aShapeLab.NewChild()); //2 - if (aSubShapes.IsBound(aBottomFace)) { - aBottomFace = aSubShapes(aBottomFace); - } - aBottomBuilder.Generated(aBottomFace); - } else { - TopoDS_Iterator itr(aBottomFace); - for (; itr.More(); itr.Next()) { - TNaming_Builder aBottomBuilder(aShapeLab.NewChild()); - aBottomBuilder.Generated(itr.Value()); - } - } +//============================================================================ +void GeomAlgoAPI_Extrusion::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const +{ + theMap = myMap; +} - } +//============================================================================ +GeomAlgoAPI_MakeShape * GeomAlgoAPI_Extrusion::makeShape() const +{ + return myMkShape; +} - //Insert top face - TopoDS_Shape aTopFace = myBuilder->LastShape(); - if (!aTopFace.IsNull()) { - if (aTopFace.ShapeType() != TopAbs_COMPOUND) { - TNaming_Builder aTopBuilder(aShapeLab.NewChild()); //3 - if (aSubShapes.IsBound(aTopFace)) { - aTopFace = aSubShapes(aTopFace); - } - aTopBuilder.Generated(aTopFace); - } else { - TopoDS_Iterator itr(aTopFace); - for (; itr.More(); itr.Next()) { - TNaming_Builder aTopBuilder(aShapeLab.NewChild()); - aTopBuilder.Generated(itr.Value()); - } - } - } - } +//============================================================================ +GeomAlgoAPI_Extrusion::~GeomAlgoAPI_Extrusion() +{ + if (myImpl) { + myMap.clear(); } - */ \ No newline at end of file +} \ No newline at end of file