From: dbv Date: Wed, 10 Jun 2015 13:06:22 +0000 (+0300) Subject: Prism algo interface changes for more convenient use in nested features. X-Git-Tag: V_1.3.0~254 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3af53fdb27a2f546f9acd8dfe2fa2343213fe7cc;p=modules%2Fshaper.git Prism algo interface changes for more convenient use in nested features. --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp index 7fd7c1301..fa7484b65 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp @@ -17,8 +17,6 @@ #include #include #include -#include -#include #include #include #include @@ -107,37 +105,7 @@ void FeaturesPlugin_Extrusion::execute() aBaseShape = std::dynamic_pointer_cast(aConstruction->face(aFaceIndex)); } - // If bounding faces was not set creating them. - std::shared_ptr aBaseFace(new GeomAPI_Face(aBaseShape)); - std::shared_ptr aBasePln = aBaseFace->getPlane(); - std::shared_ptr aBaseDir = aBasePln->direction(); - std::shared_ptr aBaseLoc = aBasePln->location(); - std::shared_ptr aBasePlane = GeomAlgoAPI_FaceBuilder::planarFace(aBaseLoc, aBaseDir); - - std::shared_ptr aBoundingFromShape = aFromShape ? aFromShape : aBasePlane; - std::shared_ptr aBoundingToShape = aToShape ? aToShape : aBasePlane; - - // Moving bounding faces according to "from" and "to" sizes. - std::shared_ptr aFromFace(new GeomAPI_Face(aBoundingFromShape)); - std::shared_ptr aFromPln = aFromFace->getPlane(); - std::shared_ptr aFromLoc = aFromPln->location(); - std::shared_ptr aFromDir = aFromPln->direction(); - - std::shared_ptr aToFace(new GeomAPI_Face(aBoundingToShape)); - std::shared_ptr aToPln = aToFace->getPlane(); - std::shared_ptr aToLoc = aToPln->location(); - std::shared_ptr aToDir = aToPln->direction(); - - bool aSign = aFromLoc->xyz()->dot(aBaseDir->xyz()) > aToLoc->xyz()->dot(aBaseDir->xyz()); - - std::shared_ptr aFromPnt(new GeomAPI_Pnt(aFromLoc->xyz()->added(aBaseDir->xyz()->multiplied(aSign ? aFromSize : -aFromSize)))); - aBoundingFromShape = GeomAlgoAPI_FaceBuilder::planarFace(aFromPnt, aFromDir); - - std::shared_ptr aToPnt(new GeomAPI_Pnt(aToLoc->xyz()->added(aBaseDir->xyz()->multiplied(aSign ? -aToSize : aToSize)))); - aBoundingToShape = GeomAlgoAPI_FaceBuilder::planarFace(aToPnt, aToDir); - - //GeomAlgoAPI_Extrusion aFeature(aFace, aFromSize); - GeomAlgoAPI_Prism aFeature(aBaseShape, aBoundingFromShape, aBoundingToShape); + GeomAlgoAPI_Prism aFeature(aBaseShape, aFromShape, aFromSize, aToShape, aToSize); if(!aFeature.isDone()) { static const std::string aFeatureError = "Extrusion algorithm failed"; setError(aFeatureError); @@ -181,12 +149,11 @@ void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Prism& theFeature, else theResultBody->storeGenerated(theBasis, theFeature.shape()); - GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape(); - theFeature.mapOfShapes(*aSubShapes); + std::shared_ptr aSubShapes = theFeature.mapOfShapes(); //Insert lateral face : Face from Edge std::string aLatName = "LateralFace"; - theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape(), theBasis, EDGE,_LATERAL_TAG, aLatName, *aSubShapes); + theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape().get(), theBasis, EDGE,_LATERAL_TAG, aLatName, *aSubShapes.get()); //Insert bottom face std::string aBotName = "BottomFace"; diff --git a/src/GeomAPI/GeomAPI_Interface.h b/src/GeomAPI/GeomAPI_Interface.h index 0e79a10f6..49db964fc 100644 --- a/src/GeomAPI/GeomAPI_Interface.h +++ b/src/GeomAPI/GeomAPI_Interface.h @@ -35,7 +35,7 @@ class GEOMAPI_EXPORT GeomAPI_Interface return static_cast(myImpl); } /// Returns the reference object of the impl - template inline const T& impl() + template inline const T& impl() const { return *(static_cast(myImpl)); } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp index 7d2cf3233..41bb42be3 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp @@ -6,7 +6,12 @@ #include +#include +#include +#include +#include #include +#include #include #include @@ -19,26 +24,60 @@ #include //================================================================================================= -GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(std::shared_ptr theBasis, - std::shared_ptr theFromShape, - std::shared_ptr theToShape) -: myFromShape(theFromShape), - myToShape(theToShape), - myDone(false), - myShape(new GeomAPI_Shape()), - myFirst(new GeomAPI_Shape()),myLast(new GeomAPI_Shape()) +GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(const std::shared_ptr& theBasis, + const std::shared_ptr& theFromShape, + double theFromDistance, + const std::shared_ptr& theToShape, + double theToDistance) +: myDone(false) { - build(theBasis); + build(theBasis, theFromShape, theFromDistance, theToShape, theToDistance); } //================================================================================================= -void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBasis) +void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBasis, + const std::shared_ptr& theFromShape, + double theFromDistance, + const std::shared_ptr& theToShape, + double theToDistance) { - if(!theBasis || !myFromShape || !myToShape || - (myFromShape && myToShape && myFromShape->isEqual(myToShape))) { + if(!theBasis || + (((!theFromShape && !theToShape) || (theFromShape && theToShape && theFromShape->isEqual(theToShape))) + && (theFromDistance == 0.0 && theToDistance == 0.0))) { return; } + // If bounding faces was not set creating them. + std::shared_ptr aBaseFace(new GeomAPI_Face(theBasis)); + std::shared_ptr aBasePln = aBaseFace->getPlane(); + std::shared_ptr aBaseDir = aBasePln->direction(); + std::shared_ptr aBaseLoc = aBasePln->location(); + std::shared_ptr aBasePlane = GeomAlgoAPI_FaceBuilder::planarFace(aBaseLoc, aBaseDir); + + std::shared_ptr aBoundingFromShape = theFromShape ? theFromShape : aBasePlane; + std::shared_ptr aBoundingToShape = theToShape ? theToShape : aBasePlane; + + // Moving bounding faces according to "from" and "to" sizes. + std::shared_ptr aFromFace(new GeomAPI_Face(aBoundingFromShape)); + std::shared_ptr aFromPln = aFromFace->getPlane(); + std::shared_ptr aFromLoc = aFromPln->location(); + std::shared_ptr aFromDir = aFromPln->direction(); + + std::shared_ptr aToFace(new GeomAPI_Face(aBoundingToShape)); + std::shared_ptr aToPln = aToFace->getPlane(); + std::shared_ptr aToLoc = aToPln->location(); + std::shared_ptr aToDir = aToPln->direction(); + + bool aSign = aFromLoc->xyz()->dot(aBaseDir->xyz()) > aToLoc->xyz()->dot(aBaseDir->xyz()); + + std::shared_ptr aFromPnt(new GeomAPI_Pnt(aFromLoc->xyz()->added(aBaseDir->xyz()->multiplied( + aSign ? theFromDistance : -theFromDistance)))); + aBoundingFromShape = GeomAlgoAPI_FaceBuilder::planarFace(aFromPnt, aFromDir); + + std::shared_ptr aToPnt(new GeomAPI_Pnt(aToLoc->xyz()->added(aBaseDir->xyz()->multiplied( + aSign ? -theToDistance : theToDistance)))); + aBoundingToShape = GeomAlgoAPI_FaceBuilder::planarFace(aToPnt, aToDir); + 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 @@ -49,9 +88,8 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBasis) BRepFeat_MakePrism* aBuilder = new BRepFeat_MakePrism(aBasis, aBasis, aBasis, aNormal, 2, Standard_True); if(aBuilder) { - setImpl(aBuilder); - TopoDS_Shape aFromShape = myFromShape->impl(); - TopoDS_Shape aToShape = myToShape->impl(); + const TopoDS_Shape& aFromShape = aBoundingFromShape->impl(); + const TopoDS_Shape& aToShape = aBoundingToShape->impl(); aBuilder->Perform(aFromShape, aToShape); myDone = aBuilder->IsDone() == Standard_True; if(myDone){ @@ -64,34 +102,39 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBasis) aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); } // fill data map to keep correct orientation of sub-shapes + myMap = std::make_shared(); 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); + myMap->bind(aCurrentShape, aCurrentShape); } + myShape = std::make_shared(); myShape->setImpl(new TopoDS_Shape(aResult)); + myFirst = std::make_shared(); myFirst->setImpl(new TopoDS_Shape(aBuilder->Modified(aFromShape).First())); + myLast = std::make_shared(); myLast->setImpl(new TopoDS_Shape(aBuilder->Modified(aToShape).First())); - myMkShape = new GeomAlgoAPI_MakeShape (aBuilder); + myMkShape = std::shared_ptr(new GeomAlgoAPI_MakeShape()); + myMkShape->setImpl(aBuilder); } } } //================================================================================================= -const bool GeomAlgoAPI_Prism::isDone() const +bool GeomAlgoAPI_Prism::isDone() const { return myDone; } //================================================================================================= -const bool GeomAlgoAPI_Prism::isValid() const +bool GeomAlgoAPI_Prism::isValid() const { BRepCheck_Analyzer aChecker(myShape->impl()); return (aChecker.IsValid() == Standard_True); } //================================================================================================= -const bool GeomAlgoAPI_Prism::hasVolume() const +bool GeomAlgoAPI_Prism::hasVolume() const { bool hasVolume(false); if(isValid()) { @@ -105,39 +148,31 @@ const bool GeomAlgoAPI_Prism::hasVolume() const } //================================================================================================= -const std::shared_ptr& GeomAlgoAPI_Prism::shape () const +std::shared_ptr GeomAlgoAPI_Prism::shape() const { return myShape; } //================================================================================================= -const std::shared_ptr& GeomAlgoAPI_Prism::firstShape() +std::shared_ptr GeomAlgoAPI_Prism::firstShape() const { return myFirst; } //================================================================================================= -const std::shared_ptr& GeomAlgoAPI_Prism::lastShape() +std::shared_ptr GeomAlgoAPI_Prism::lastShape() const { return myLast; } //================================================================================================= -void GeomAlgoAPI_Prism::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const +std::shared_ptr GeomAlgoAPI_Prism::mapOfShapes() const { - theMap = myMap; + return myMap; } //================================================================================================= -GeomAlgoAPI_MakeShape* GeomAlgoAPI_Prism::makeShape() const +std::shared_ptr GeomAlgoAPI_Prism::makeShape() const { return myMkShape; } - -//================================================================================================= -GeomAlgoAPI_Prism::~GeomAlgoAPI_Prism() -{ - if (myImpl) { - myMap.clear(); - } -} \ No newline at end of file diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h index fde00d55d..2631e4bc2 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h @@ -23,55 +23,58 @@ class GeomAlgoAPI_Prism : public GeomAPI_Interface { public: /** \brief Creates extrusion for the given shape along the normal for this shape. - * \param[in] theBasis face or wire to be extruded; - * \param[in] theFromShape bottom bounding shape; - * \param[in] theToShape top bounding shape; + * \param[in] theBasis face or wire to be extruded. + * \param[in] theFromShape bottom bounding shape. + * \param[in] theFromDistance offset for "from" plane. + * \param[in] theToShape top bounding shape. + * \param[in] theToDistance offset for "to" plane. */ - GEOMALGOAPI_EXPORT GeomAlgoAPI_Prism(std::shared_ptr theBasis, - std::shared_ptr theFromShape, - std::shared_ptr theToShape); + GEOMALGOAPI_EXPORT GeomAlgoAPI_Prism(const std::shared_ptr& theBasis, + const std::shared_ptr& theFromShape, + double theFromDistance, + const std::shared_ptr& theToShape, + double theToDistance); /// \return true if algorithm succeed. - GEOMALGOAPI_EXPORT const bool isDone() const; + GEOMALGOAPI_EXPORT bool isDone() const; /// \return true if resulting shape is valid. - GEOMALGOAPI_EXPORT const bool isValid() const; + GEOMALGOAPI_EXPORT bool isValid() const; /// \return true if resulting shape has volume. - GEOMALGOAPI_EXPORT const bool hasVolume() const; + GEOMALGOAPI_EXPORT bool hasVolume() const; /// \return result of the Prism algorithm. - GEOMALGOAPI_EXPORT const std::shared_ptr& shape() const; + GEOMALGOAPI_EXPORT std::shared_ptr shape() const; /// \returns the first shape. - GEOMALGOAPI_EXPORT const std::shared_ptr& firstShape(); + GEOMALGOAPI_EXPORT std::shared_ptr firstShape() const; /// \return the last shape. - GEOMALGOAPI_EXPORT const std::shared_ptr& lastShape(); + GEOMALGOAPI_EXPORT std::shared_ptr lastShape() const; /// \return map of sub-shapes of the result. To be used for History keeping. - GEOMALGOAPI_EXPORT void mapOfShapes(GeomAPI_DataMapOfShapeShape& theMap) const; + GEOMALGOAPI_EXPORT std::shared_ptr mapOfShapes() const; /// \return interface for History processing. - GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape* makeShape() const; - - /// Destructor. - GEOMALGOAPI_EXPORT ~GeomAlgoAPI_Prism(); + GEOMALGOAPI_EXPORT std::shared_ptr makeShape() const; private: /// Builds resulting shape. - void build(const std::shared_ptr& theBasis); + void build(const std::shared_ptr& theBasis, + const std::shared_ptr& theFromShape, + double theFromDistance, + const std::shared_ptr& theToShape, + double theToDistance); private: /// Fields. - std::shared_ptr myFromShape; - std::shared_ptr myToShape; bool myDone; std::shared_ptr myShape; std::shared_ptr myFirst; std::shared_ptr myLast; - GeomAPI_DataMapOfShapeShape myMap; - GeomAlgoAPI_MakeShape* myMkShape; + std::shared_ptr myMap; + std::shared_ptr myMkShape; }; #endif