From: dbv Date: Mon, 22 Jun 2015 13:32:40 +0000 (+0300) Subject: Improvement #635: Move maximum functionality to API class X-Git-Tag: V_1.3.0~210 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8030eb14e6863867336c9d09653db64c1c5a4db8;p=modules%2Fshaper.git Improvement #635: Move maximum functionality to API class --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp index 0e2dc5079..4a3e69108 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp @@ -159,7 +159,7 @@ void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Prism& theFeature, //Insert lateral face : Face from Edge std::string aLatName = "LateralFace"; - theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape().get(), theBasis, EDGE,_LATERAL_TAG, aLatName, *aSubShapes.get()); + theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape().get(), theBasis, EDGE,_LATERAL_TAG, aLatName, *aSubShapes); //Insert bottom face std::string aBotName = "BottomFace"; diff --git a/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp b/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp index 8f34e2f56..21aab4513 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp @@ -165,11 +165,10 @@ void FeaturesPlugin_Revolution::LoadNamingDS(GeomAlgoAPI_Revolution& theFeature, else theResultBody->storeGenerated(theContext, theFeature.shape()); - GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape(); - theFeature.mapOfShapes(*aSubShapes); + std::shared_ptr aSubShapes = theFeature.mapOfShapes(); std::string aGeneratedName = "LateralFace"; - theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape(), theBasis, EDGE,_LATERAL_TAG, aGeneratedName, *aSubShapes); + theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape().get(), theBasis, EDGE,_LATERAL_TAG, aGeneratedName, *aSubShapes); //Insert from face std::string aBotName = "FromFace"; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp index b0c7be684..22bde17c0 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp @@ -11,7 +11,7 @@ GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape(void* theMkShape) : GeomAPI_Interface(theMkShape),myShape(new GeomAPI_Shape()) { - myShape->setImpl((void *)&implPtr()->Shape()); + myShape->setImpl(new TopoDS_Shape(implPtr()->Shape())); } GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape() diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp index 9dbdb045c..6d36708b4 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp @@ -24,11 +24,20 @@ #include //================================================================================================= -GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(const std::shared_ptr& theBasis, - const std::shared_ptr& theFromShape, - double theFromSize, - const std::shared_ptr& theToShape, - double theToSize) +GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(std::shared_ptr theBasis, + double theFromSize, + double theToSize) +: myDone(false) +{ + build(theBasis, std::shared_ptr(), theFromSize, std::shared_ptr(), theToSize); +} + +//================================================================================================= +GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(std::shared_ptr theBasis, + std::shared_ptr theFromShape, + double theFromSize, + std::shared_ptr theToShape, + double theToSize) : myDone(false) { build(theBasis, theFromShape, theFromSize, theToShape, theToSize); @@ -114,7 +123,7 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBasis, myFirst->setImpl(new TopoDS_Shape(aBuilder->Modified(aFromShape).First())); myLast = std::make_shared(); myLast->setImpl(new TopoDS_Shape(aBuilder->Modified(aToShape).First())); - myMkShape = std::shared_ptr(new GeomAlgoAPI_MakeShape()); + myMkShape = std::make_shared(); myMkShape->setImpl(aBuilder); } } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h index 91096aa88..642ff9b30 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h @@ -24,16 +24,25 @@ 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] theFromSize offset for "from" plane. - * \param[in] theToShape top bounding shape. * \param[in] theToSize offset for "to" plane. */ - GEOMALGOAPI_EXPORT GeomAlgoAPI_Prism(const std::shared_ptr& theBasis, - const std::shared_ptr& theFromShape, - double theFromSize, - const std::shared_ptr& theToShape, - double theToSize); + GEOMALGOAPI_EXPORT GeomAlgoAPI_Prism(std::shared_ptr theBasis, + double theFromSize, + double theToSize); + + /** \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. Can be empty. In this case offset will be applied to the basis. + * \param[in] theFromSize offset for "from" plane. + * \param[in] theToShape top bounding shape. Can be empty. In this case offset will be applied to the basis. + * \param[in] theToSize offset for "to" plane. + */ + GEOMALGOAPI_EXPORT GeomAlgoAPI_Prism(std::shared_ptr theBasis, + std::shared_ptr theFromShape, + double theFromSize, + std::shared_ptr theToShape, + double theToSize); /// \return true if algorithm succeed. GEOMALGOAPI_EXPORT bool isDone() const; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp index f2377dd32..295886fbd 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp @@ -27,6 +27,16 @@ #include #include +//================================================================================================= +GeomAlgoAPI_Revolution::GeomAlgoAPI_Revolution(std::shared_ptr theBasis, + std::shared_ptr theAxis, + double theFromAngle, + double theToAngle) +: myDone(false) +{ + build(theBasis, theAxis, std::shared_ptr(), theFromAngle, std::shared_ptr(), theToAngle); +} + //================================================================================================= GeomAlgoAPI_Revolution::GeomAlgoAPI_Revolution(std::shared_ptr theBasis, std::shared_ptr theAxis, @@ -34,16 +44,9 @@ GeomAlgoAPI_Revolution::GeomAlgoAPI_Revolution(std::shared_ptr th double theFromAngle, std::shared_ptr theToShape, double theToAngle) -: myAxis(theAxis), - myFromShape(theFromShape), - myFromAngle(theFromAngle), - myToShape(theToShape), - myToAngle(theToAngle), - myDone(false), - myShape(new GeomAPI_Shape()), - myFirst(new GeomAPI_Shape()),myLast(new GeomAPI_Shape()) +: myDone(false) { - build(theBasis); + build(theBasis, theAxis, theFromShape, theFromAngle, theToShape, theToAngle); } //================================================================================================= @@ -102,11 +105,16 @@ TopoDS_Shape GeomAlgoAPI_Revolution::findClosest(const TopoDS_Shape& theShape, c } //================================================================================================= -void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasis) +void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasis, + const std::shared_ptr& theAxis, + const std::shared_ptr& theFromShape, + double theFromAngle, + const std::shared_ptr& theToShape, + double theToAngle) { - if(!theBasis || !myAxis || - (((!myFromShape && !myToShape) || (myFromShape && myToShape && myFromShape->isEqual(myToShape))) - && (myFromAngle == 0.0 && myToAngle == 0.0))) { + if(!theBasis || !theAxis || + (((!theFromShape && !theToShape) || (theFromShape && theToShape && theFromShape->isEqual(theToShape))) + && (theFromAngle == 0.0 && theToAngle == 0.0))) { return; } @@ -116,23 +124,25 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi return; } gp_Pln aBasisPln = isBasisPlanar.Plan(); - gp_Ax1 anAxis = myAxis->impl(); + gp_Ax1 anAxis = theAxis->impl(); ListOfMakeShape aListOfMakeShape; + myFirst = std::make_shared(); + myLast = std::make_shared(); TopoDS_Shape aResult; - if(!myFromShape && !myToShape) { // Case 1: When only angles was set. + if(!theFromShape && !theToShape) { // Case 1: When only angles was set. // Rotating base face with the negative value of "from angle". gp_Trsf aBaseTrsf; - aBaseTrsf.SetRotation(anAxis, -myFromAngle / 180.0 * M_PI); + aBaseTrsf.SetRotation(anAxis, -theFromAngle / 180.0 * M_PI); BRepBuilderAPI_Transform* aBaseTransform = new BRepBuilderAPI_Transform(aBasisFace, aBaseTrsf, true); - aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aBaseTransform))); + aListOfMakeShape.push_back(std::make_shared(aBaseTransform)); TopoDS_Shape aRotatedBaseShape = aBaseTransform->Shape(); // Making revolution to the angle equal to the sum of "from angle" and "to angle". - double anAngle = myFromAngle + myToAngle; + double anAngle = theFromAngle + theToAngle; BRepPrimAPI_MakeRevol* aRevolBuilder = new BRepPrimAPI_MakeRevol(aRotatedBaseShape, anAxis, anAngle / 180 * M_PI, @@ -141,16 +151,16 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi if(!aRevolBuilder->IsDone()) { return; } - aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aRevolBuilder))); + aListOfMakeShape.push_back(std::make_shared(aRevolBuilder)); aResult = aRevolBuilder->Shape(); // Setting naming. myFirst->setImpl(new TopoDS_Shape(aRevolBuilder->FirstShape())); myLast->setImpl(new TopoDS_Shape(aRevolBuilder->LastShape())); - } else if(myFromShape && myToShape) { // Case 2: When both bounding planes were set. + } else if(theFromShape && theToShape) { // Case 2: When both bounding planes were set. // Getting bounding faces. - TopoDS_Face aFromFace = TopoDS::Face(myFromShape->impl()); - TopoDS_Face aToFace = TopoDS::Face(myToShape->impl()); + TopoDS_Face aFromFace = TopoDS::Face(theFromShape->impl()); + TopoDS_Face aToFace = TopoDS::Face(theToShape->impl()); // Getting planes from bounding face. GeomLib_IsPlanarSurface isFromPlanar(BRep_Tool::Surface(aFromFace)); @@ -174,8 +184,8 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi // Rotating bounding planes to the specified angle. gp_Trsf aFromTrsf; gp_Trsf aToTrsf; - double aFromRotAngle = ((aFromPln.Axis().Direction() * aBasisPln.Axis().Direction()) > 0) ? -myFromAngle : myFromAngle; - double aToRotAngle = ((aToPln.Axis().Direction() * aBasisPln.Axis().Direction()) > 0) ? -myToAngle : myToAngle; + double aFromRotAngle = ((aFromPln.Axis().Direction() * aBasisPln.Axis().Direction()) > 0) ? -theFromAngle : theFromAngle; + double aToRotAngle = ((aToPln.Axis().Direction() * aBasisPln.Axis().Direction()) > 0) ? -theToAngle : theToAngle; aFromTrsf.SetRotation(anAxis,aFromRotAngle / 180.0 * M_PI); aToTrsf.SetRotation(anAxis, aToRotAngle / 180.0 * M_PI); BRepBuilderAPI_Transform aFromTransform(aFromSolid, aFromTrsf, true); @@ -188,7 +198,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi // Making revolution to the 360 angle. BRepPrimAPI_MakeRevol* aRevolBuilder = new BRepPrimAPI_MakeRevol(aBasisFace, anAxis, 2 * M_PI, Standard_True); aRevolBuilder->Build(); - aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aRevolBuilder))); + aListOfMakeShape.push_back(std::make_shared(aRevolBuilder)); TopoDS_Shape aRevolShape = aRevolBuilder->Shape(); // Cutting revolution with from plane. @@ -197,7 +207,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi if(!aFromCutBuilder->IsDone()) { return; } - aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aFromCutBuilder))); + aListOfMakeShape.push_back(std::make_shared(aFromCutBuilder)); aResult = aFromCutBuilder->Shape(); // Cutting revolution with to plane. @@ -206,7 +216,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi if(!aToCutBuilder->IsDone()) { return; } - aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aToCutBuilder))); + aListOfMakeShape.push_back(std::make_shared(aToCutBuilder)); aResult = aToCutBuilder->Shape(); // If after cut we got more than one solids then take closest to the center of mass of the base face. @@ -229,11 +239,11 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi // Getting bounding face. TopoDS_Face aBoundingFace; bool isFromFaceSet = false; - if(myFromShape) { - aBoundingFace = TopoDS::Face(myFromShape->impl()); + if(theFromShape) { + aBoundingFace = TopoDS::Face(theFromShape->impl()); isFromFaceSet = true; - } else if(myToShape) { - aBoundingFace = TopoDS::Face(myToShape->impl()); + } else if(theToShape) { + aBoundingFace = TopoDS::Face(theToShape->impl()); } // Getting plane from bounding face. @@ -252,7 +262,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi TopoDS_Shape aBoundingSolid = makeSolidFromFace(aBoundingFace); // Rotating bounding plane to the specified angle. - double aBoundingRotAngle = isFromFaceSet ? myFromAngle : myToAngle; + double aBoundingRotAngle = isFromFaceSet ? theFromAngle : theToAngle; if(aBoundingPln.Axis().IsParallel(aBasisPln.Axis(), Precision::Confusion())) { if(isFromFaceSet) aBoundingRotAngle = -aBoundingRotAngle; } else { @@ -271,7 +281,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi // Making revolution to the 360 angle. BRepPrimAPI_MakeRevol* aRevolBuilder = new BRepPrimAPI_MakeRevol(aBasisFace, anAxis, 2 * M_PI, Standard_True); aRevolBuilder->Build(); - aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aRevolBuilder))); + aListOfMakeShape.push_back(std::make_shared(aRevolBuilder)); TopoDS_Shape aRevolShape = aRevolBuilder->Shape(); // Cutting revolution with bounding plane. @@ -280,7 +290,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi if(!aBoundingCutBuilder->IsDone()) { return; } - aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aBoundingCutBuilder))); + aListOfMakeShape.push_back(std::make_shared(aBoundingCutBuilder)); aResult = aBoundingCutBuilder->Shape(); TopExp_Explorer anExp1(aResult, TopAbs_SOLID); @@ -300,7 +310,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi // Rotating basis face to the specified angle. gp_Trsf aBasisTrsf; - double aBasisRotAngle = isFromFaceSet ? myToAngle : -myFromAngle; + double aBasisRotAngle = isFromFaceSet ? theToAngle : -theFromAngle; aBasisTrsf.SetRotation(anAxis, aBasisRotAngle / 180.0 * M_PI); BRepBuilderAPI_Transform aBasisTransform(aBasisSolid, aBasisTrsf, true); TopoDS_Shape aRotatedBasisFace = aBasisTransform.Modified(aBasisFace).First(); @@ -313,7 +323,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi TopoDS_Shape aCutResult = aBasisCutBuilder->Shape(); TopExp_Explorer anExp(aCutResult, TopAbs_SOLID); if(anExp.More()) { - aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aBasisCutBuilder))); + aListOfMakeShape.push_back(std::make_shared(aBasisCutBuilder)); aResult = aCutResult; } } @@ -344,13 +354,15 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi } // 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)); - myMkShape = new GeomAlgoAPI_MakeShapeList(aListOfMakeShape); + myMkShape = std::make_shared(); myDone = true; return; } @@ -401,21 +413,13 @@ const std::shared_ptr& GeomAlgoAPI_Revolution::lastShape() } //================================================================================================= -void GeomAlgoAPI_Revolution::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const +std::shared_ptr GeomAlgoAPI_Revolution::mapOfShapes() const { - theMap = myMap; + return myMap; } //================================================================================================= -GeomAlgoAPI_MakeShape* GeomAlgoAPI_Revolution::makeShape() const +std::shared_ptr GeomAlgoAPI_Revolution::makeShape() const { return myMkShape; } - -//================================================================================================= -GeomAlgoAPI_Revolution::~GeomAlgoAPI_Revolution() -{ - if (myImpl) { - myMap.clear(); - } -} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.h b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.h index a6df8b5aa..a10b093b0 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.h @@ -32,13 +32,22 @@ class TopoDS_Solid; class GeomAlgoAPI_Revolution : public GeomAPI_Interface { public: - /** \brief Creates revolution for the given shape - * \param[in] theBasis face for revolution - * \param[in] theFromShape from bounding shape - * \param[in] theFromAngle from angle - * \param[in] theToShape to bounding shape - * \param[in] theToAngle to angle - * \return a solid which is obtained from specified one + /** \brief Creates revolution for the given shape. + * \param[in] theBasis face for revolution. + * \param[in] theFromAngle from angle. + * \param[in] theToAngle to angle. + */ + GEOMALGOAPI_EXPORT GeomAlgoAPI_Revolution(std::shared_ptr theBasis, + std::shared_ptr theAxis, + double theFromAngle, + double theToAngle); + + /** \brief Creates revolution for the given shape. + * \param[in] theBasis face for revolution. + * \param[in] theFromShape from bounding shape. Can be empty. In this case offset will be applied to the basis. + * \param[in] theFromAngle from angle. + * \param[in] theToShape to bounding shape. Can be empty. In this case offset will be applied to the basis. + * \param[in] theToAngle to angle. */ GEOMALGOAPI_EXPORT GeomAlgoAPI_Revolution(std::shared_ptr theBasis, std::shared_ptr theAxis, @@ -66,13 +75,10 @@ public: GEOMALGOAPI_EXPORT const std::shared_ptr& lastShape(); /// \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_Revolution(); + GEOMALGOAPI_EXPORT std::shared_ptr makeShape() const; private: /** \brief Constructs infinite face from thePlane, and with axis located on the same side @@ -94,21 +100,21 @@ private: TopoDS_Shape findClosest(const TopoDS_Shape& theShape, const gp_Pnt& thePoint); /// Builds resulting shape. - void build(const std::shared_ptr& theBasis); + void build(const std::shared_ptr& theBasis, + const std::shared_ptr& theAxis, + const std::shared_ptr& theFromShape, + double theFromAngle, + const std::shared_ptr& theToShape, + double theToAngle); private: /// Fields. - std::shared_ptr myAxis; - std::shared_ptr myFromShape; - double myFromAngle; - std::shared_ptr myToShape; - double myToAngle; 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 \ No newline at end of file