From: dbv Date: Thu, 24 Dec 2015 07:50:58 +0000 (+0300) Subject: GeomAlgoAPI_Translation now derived from GeomAlgoAPI_MakeShape X-Git-Tag: V_2.1.0~77 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=bbda7e734357dc8f5e16ab7affb48f75e6e8e3c6;p=modules%2Fshaper.git GeomAlgoAPI_Translation now derived from GeomAlgoAPI_MakeShape --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp b/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp index c55d23d81..41a93ddba 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp @@ -89,27 +89,27 @@ void FeaturesPlugin_Translation::execute() aResultPart->setTrsf(*aContext, aTrsf); setResult(aResultPart); } else { - GeomAlgoAPI_Translation aMovementAlgo(aBaseShape, anAxis, aDistance); + GeomAlgoAPI_Translation aTranslationAlgo(aBaseShape, anAxis, aDistance); // Checking that the algorithm worked properly. - if(!aMovementAlgo.isDone()) { - static const std::string aFeatureError = "Movement algorithm failed"; + if(!aTranslationAlgo.isDone()) { + static const std::string aFeatureError = "Translation algorithm failed"; setError(aFeatureError); break; } - if(aMovementAlgo.shape()->isNull()) { + if(aTranslationAlgo.shape()->isNull()) { static const std::string aShapeError = "Resulting shape is Null"; setError(aShapeError); break; } - if(!aMovementAlgo.isValid()) { + if(!aTranslationAlgo.isValid()) { std::string aFeatureError = "Warning: resulting shape is not valid"; setError(aFeatureError); break; } ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); - LoadNamingDS(aMovementAlgo, aResultBody, aBaseShape); + loadNamingDS(aTranslationAlgo, aResultBody, aBaseShape); setResult(aResultBody, aResultIndex); } aResultIndex++; @@ -119,19 +119,19 @@ void FeaturesPlugin_Translation::execute() removeResults(aResultIndex); } -void FeaturesPlugin_Translation::LoadNamingDS(const GeomAlgoAPI_Translation& theMovementAlgo, - std::shared_ptr theResultBody, - std::shared_ptr theBaseShape) +void FeaturesPlugin_Translation::loadNamingDS(GeomAlgoAPI_Translation& theTranslationAlgo, + std::shared_ptr theResultBody, + std::shared_ptr theBaseShape) { // Store result. - theResultBody->storeModified(theBaseShape, theMovementAlgo.shape()); + theResultBody->storeModified(theBaseShape, theTranslationAlgo.shape()); - std::shared_ptr aSubShapes = theMovementAlgo.mapOfShapes(); + std::shared_ptr aSubShapes = theTranslationAlgo.mapOfSubShapes(); - int aMovedTag = 1; - std::string aMovedName = "Moved"; - theResultBody->loadAndOrientModifiedShapes(theMovementAlgo.makeShape().get(), - theBaseShape, GeomAPI_Shape::FACE, - aMovedTag, aMovedName, *aSubShapes.get()); + int aTranslatedTag = 1; + std::string aTranslatedName = "Translated"; + theResultBody->loadAndOrientModifiedShapes(&theTranslationAlgo, + theBaseShape, GeomAPI_Shape::FACE, + aTranslatedTag, aTranslatedName, *aSubShapes.get()); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Translation.h b/src/FeaturesPlugin/FeaturesPlugin_Translation.h index 2f6ce2d92..93d72c33b 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Translation.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Translation.h @@ -13,18 +13,17 @@ #include -/** \class FeaturesPlugin_Translation - * \ingroup Plugins - * \brief Feature for movement objects along the axis. - */ +/// \class FeaturesPlugin_Translation +/// \ingroup Plugins +/// \brief Feature for translation objects along the axis. class FeaturesPlugin_Translation : public ModelAPI_Feature { public: - /// Movement kind. + /// Translation kind. inline static const std::string& ID() { - static const std::string MY_MOVEMENT_ID("Translation"); - return MY_MOVEMENT_ID; + static const std::string MY_TRANSLATION_ID("Translation"); + return MY_TRANSLATION_ID; } /// Attribute name of referenced objects. @@ -65,7 +64,7 @@ class FeaturesPlugin_Translation : public ModelAPI_Feature FeaturesPlugin_Translation(); private: - void LoadNamingDS(const GeomAlgoAPI_Translation& theMovementAlgo, + void loadNamingDS(GeomAlgoAPI_Translation& theTranslationAlgo, std::shared_ptr theResultBody, std::shared_ptr theBaseShape); }; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Translation.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Translation.cpp index 8f505072f..27af5311f 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Translation.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Translation.cpp @@ -4,21 +4,15 @@ // Created: 8 June 2015 // Author: Dmitry Bobylev -#include - -#include +#include "GeomAlgoAPI_Translation.h" #include -#include #include -#include -#include //================================================================================================= GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr theSourceShape, std::shared_ptr theAxis, double theDistance) -: myDone(false) { build(theSourceShape, theAxis, theDistance); } @@ -41,71 +35,22 @@ void GeomAlgoAPI_Translation::build(std::shared_ptr theSourceShap gp_Trsf* aTrsf = new gp_Trsf(); aTrsf->SetTranslation(gp_Vec(anAxis.Direction()) * theDistance); - myTrsf.reset(new GeomAPI_Trsf(aTrsf)); // Transform the shape with copying it. BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true); if(!aBuilder) { return; } - myMkShape.reset(new GeomAlgoAPI_MakeShape(aBuilder)); - - myDone = aBuilder->IsDone() == Standard_True; + this->setImpl(aBuilder); + this->setBuilderType(OCCT_BRepBuilderAPI_MakeShape); - if(!myDone) { + if(aBuilder->IsDone() != Standard_True) { return; } - TopoDS_Shape aResult = aBuilder->Shape(); - // Fill data map to keep correct orientation of sub-shapes. - myMap.reset(new GeomAPI_DataMapOfShapeShape()); - for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More(); anExp.Next()) { - std::shared_ptr aCurrentShape(new GeomAPI_Shape()); - aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current())); - myMap->bind(aCurrentShape, aCurrentShape); - } - - myShape.reset(new GeomAPI_Shape()); - myShape->setImpl(new TopoDS_Shape(aResult)); -} - -//================================================================================================= -const bool GeomAlgoAPI_Translation::isValid() const -{ - BRepCheck_Analyzer aChecker(myShape->impl()); - return (aChecker.IsValid() == Standard_True); -} - -//================================================================================================= -const bool GeomAlgoAPI_Translation::hasVolume() const -{ - bool hasVolume(false); - if(isValid() && (GeomAlgoAPI_ShapeTools::volume(myShape) > Precision::Confusion())) { - hasVolume = true; - } - return hasVolume; -} -//================================================================================================= -const std::shared_ptr& GeomAlgoAPI_Translation::shape() const -{ - return myShape; -} - -//================================================================================================= -std::shared_ptr GeomAlgoAPI_Translation::mapOfShapes() const -{ - return myMap; -} - -//================================================================================================= -std::shared_ptr GeomAlgoAPI_Translation::makeShape() const -{ - return myMkShape; -} - -//================================================================================================= -std::shared_ptr GeomAlgoAPI_Translation::transformation() const -{ - return myTrsf; + std::shared_ptr aShape(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(aResult)); + this->setShape(aShape); + this->setDone(true); } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Translation.h b/src/GeomAlgoAPI/GeomAlgoAPI_Translation.h index e8f3d8147..8f27aaa6f 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Translation.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Translation.h @@ -9,62 +9,29 @@ #include #include + #include -#include #include -#include -/** \class GeomAlgoAPI_Translation - * \ingroup DataAlgo - * \brief Creates a copy of the object by moving it along the axis. - */ -class GeomAlgoAPI_Translation : public GeomAPI_Interface +/// \class GeomAlgoAPI_Translation +/// \ingroup DataAlgo +/// \brief Creates a copy of the object by moving it along the axis. +class GeomAlgoAPI_Translation : public GeomAlgoAPI_MakeShape { public: - /** \brief Creates an object which is obtained from current object by moving it along the axis. - * \param[in] theSourceShape a shape to be moved. - * \param[in] theAxis movement axis. - * \param[in] theDistance movement distance. - */ + /// \brief Creates an object which is obtained from current object by moving it along the axis. + /// \param[in] theSourceShape a shape to be moved. + /// \param[in] theAxis movement axis. + /// \param[in] theDistance movement distance. GEOMALGOAPI_EXPORT GeomAlgoAPI_Translation(std::shared_ptr theSourceShape, std::shared_ptr theAxis, double theDistance); - /// \return true if algorithm succeed. - GEOMALGOAPI_EXPORT const bool isDone() const - { return myDone; } - - /// \return true if resulting shape is valid. - GEOMALGOAPI_EXPORT const bool isValid() const; - - /// \return true if resulting shape has volume. - GEOMALGOAPI_EXPORT const bool hasVolume() const; - - /// \return result of the movement algorithm. - GEOMALGOAPI_EXPORT const std::shared_ptr& shape() const; - - /// \return map of sub-shapes of the result. To be used for History keeping. - GEOMALGOAPI_EXPORT std::shared_ptr mapOfShapes() const; - - /// \return interface for for History processing. - GEOMALGOAPI_EXPORT std::shared_ptr makeShape() const; - - /// Returns the simple transformation - GEOMALGOAPI_EXPORT std::shared_ptr transformation() const; - private: /// Builds resulting shape. void build(std::shared_ptr theSourceShape, std::shared_ptr theAxis, double theDistance); - -private: - /// Fields. - bool myDone; - std::shared_ptr myShape; - std::shared_ptr myMap; - std::shared_ptr myMkShape; - std::shared_ptr myTrsf; }; #endif