From 1d8e244d3e75b9a09954594e1ce8332ddff3e662 Mon Sep 17 00:00:00 2001 From: Artem Zhidkov Date: Mon, 16 Aug 2021 17:42:39 +0300 Subject: [PATCH] Refactoring of the Bounding Box feature (change names of classes to be more evident) --- src/FeaturesAPI/FeaturesAPI_BoundingBox.cpp | 6 +- src/FeaturesAPI/FeaturesAPI_BoundingBox.h | 6 +- src/FeaturesPlugin/CMakeLists.txt | 8 +- .../FeaturesPlugin_BoundingBox.cpp | 111 ++++++---------- .../FeaturesPlugin_BoundingBox.h | 38 ++---- ...cpp => FeaturesPlugin_BoundingBoxBase.cpp} | 6 +- ...Box.h => FeaturesPlugin_BoundingBoxBase.h} | 14 +- ... => FeaturesPlugin_InspectBoundingBox.cpp} | 121 ++++++++++++------ ....h => FeaturesPlugin_InspectBoundingBox.h} | 44 ++++--- src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp | 6 +- 10 files changed, 180 insertions(+), 180 deletions(-) rename src/FeaturesPlugin/{FeaturesPlugin_CommonBoundingBox.cpp => FeaturesPlugin_BoundingBoxBase.cpp} (94%) rename src/FeaturesPlugin/{FeaturesPlugin_CommonBoundingBox.h => FeaturesPlugin_BoundingBoxBase.h} (82%) rename src/FeaturesPlugin/{FeaturesPlugin_CreateBoundingBox.cpp => FeaturesPlugin_InspectBoundingBox.cpp} (63%) rename src/FeaturesPlugin/{FeaturesPlugin_CreateBoundingBox.h => FeaturesPlugin_InspectBoundingBox.h} (78%) diff --git a/src/FeaturesAPI/FeaturesAPI_BoundingBox.cpp b/src/FeaturesAPI/FeaturesAPI_BoundingBox.cpp index 123a0a4a2..ff60f54f3 100644 --- a/src/FeaturesAPI/FeaturesAPI_BoundingBox.cpp +++ b/src/FeaturesAPI/FeaturesAPI_BoundingBox.cpp @@ -19,7 +19,7 @@ #include "FeaturesAPI_BoundingBox.h" -#include +#include #include #include #include @@ -60,7 +60,7 @@ void FeaturesAPI_BoundingBox::dump(ModelHighAPI_Dumper& theDumper) const const std::string& aDocName = theDumper.name(aBase->document()); AttributeSelectionPtr anAttrObject; - anAttrObject = aBase->selection(FeaturesPlugin_CreateBoundingBox::OBJECT_ID()); + anAttrObject = aBase->selection(FeaturesPlugin_BoundingBox::OBJECT_ID()); theDumper << aBase << " = model.getBoundingBox(" << aDocName << ", " << anAttrObject; @@ -73,7 +73,7 @@ BoundingBoxPtr getBoundingBox(const std::shared_ptr& thePart, { FeaturePtr aFeature = - thePart->addFeature(FeaturesPlugin_CreateBoundingBox::ID()); + thePart->addFeature(FeaturesPlugin_BoundingBox::ID()); BoundingBoxPtr aBoundingBox; diff --git a/src/FeaturesAPI/FeaturesAPI_BoundingBox.h b/src/FeaturesAPI/FeaturesAPI_BoundingBox.h index 959d0d41c..488563dcd 100644 --- a/src/FeaturesAPI/FeaturesAPI_BoundingBox.h +++ b/src/FeaturesAPI/FeaturesAPI_BoundingBox.h @@ -22,7 +22,7 @@ #include "FeaturesAPI.h" -#include "FeaturesPlugin_CreateBoundingBox.h" +#include "FeaturesPlugin_BoundingBox.h" #include #include @@ -50,8 +50,8 @@ public: FEATURESAPI_EXPORT virtual ~FeaturesAPI_BoundingBox(); - INTERFACE_1(FeaturesPlugin_CreateBoundingBox::ID(), - objectSelected, FeaturesPlugin_CreateBoundingBox::OBJECT_ID(), + INTERFACE_1(FeaturesPlugin_BoundingBox::ID(), + objectSelected, FeaturesPlugin_BoundingBox::OBJECT_ID(), ModelAPI_AttributeSelection, /** object selected*/) /// Dump wrapped feature diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 4d52c6119..91dee176f 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -70,8 +70,8 @@ SET(PROJECT_HEADERS FeaturesPlugin_PointCoordinates.h FeaturesPlugin_GeometryCalculation.h FeaturesPlugin_BoundingBox.h - FeaturesPlugin_CommonBoundingBox.h - FeaturesPlugin_CreateBoundingBox.h + FeaturesPlugin_BoundingBoxBase.h + FeaturesPlugin_InspectBoundingBox.h ) SET(PROJECT_SOURCES @@ -122,8 +122,8 @@ SET(PROJECT_SOURCES FeaturesPlugin_PointCoordinates.cpp FeaturesPlugin_GeometryCalculation.cpp FeaturesPlugin_BoundingBox.cpp - FeaturesPlugin_CommonBoundingBox.cpp - FeaturesPlugin_CreateBoundingBox.cpp + FeaturesPlugin_BoundingBoxBase.cpp + FeaturesPlugin_InspectBoundingBox.cpp ) SET(XML_RESOURCES diff --git a/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.cpp b/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.cpp index f2867fec9..158f9013d 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.cpp @@ -19,20 +19,20 @@ #include "FeaturesPlugin_BoundingBox.h" -#include - -#include - -#include - #include #include -#include #include +#include + #include #include #include +#include + +#include +#include + #include #include @@ -54,7 +54,7 @@ void FeaturesPlugin_BoundingBox::initAttributes() data()->addAttribute(X_MAX_COORD_ID(), ModelAPI_AttributeString::typeId()); data()->addAttribute(Y_MAX_COORD_ID(), ModelAPI_AttributeString::typeId()); data()->addAttribute(Z_MAX_COORD_ID(), ModelAPI_AttributeString::typeId()); - data()->addAttribute(CREATEBOX_ID(), ModelAPI_AttributeBoolean::typeId()); + data()->addAttribute(COMPUTE_ID(), ModelAPI_AttributeBoolean::typeId()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), X_MIN_COORD_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Y_MIN_COORD_ID()); @@ -62,13 +62,12 @@ void FeaturesPlugin_BoundingBox::initAttributes() ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), X_MAX_COORD_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Y_MAX_COORD_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Z_MAX_COORD_ID()); - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CREATEBOX_ID()); - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), RESULT_VALUES_ID()); - + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), COMPUTE_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), OBJECT_ID()); data()->addAttribute(RESULT_VALUES_ID(), ModelAPI_AttributeDoubleArray::typeId()); data()->realArray(RESULT_VALUES_ID())->setSize(6); - + data()->boolean(COMPUTE_ID())->setValue(true); } //================================================================================================= @@ -78,44 +77,21 @@ void FeaturesPlugin_BoundingBox::execute() return; createBoxByTwoPoints(); - - if (boolean(CREATEBOX_ID())->value()) { - if (!myCreateFeature.get()) - createBox(); - updateBox(); - } else { - if (myCreateFeature.get()) { - myCreateFeature->eraseResults(); - SessionPtr aSession = ModelAPI_Session::get(); - DocumentPtr aDoc = aSession->activeDocument(); - aDoc->removeFeature(myCreateFeature); - myCreateFeature.reset(); - } - } -} - -//================================================================================================= -void FeaturesPlugin_BoundingBox::attributeChanged(const std::string& theID) -{ - if (theID == OBJECT_ID()) { - if (myCreateFeature.get()) - updateBox(); - } } //================================================================================================= -AttributePtr FeaturesPlugin_BoundingBox::attributResultValues() +void FeaturesPlugin_BoundingBox::attributeChanged(const std::string&) { - return attribute(RESULT_VALUES_ID()); } //================================================================================================= bool FeaturesPlugin_BoundingBox::updateValues() { AttributeSelectionPtr aSelection = selection(OBJECT_ID()); - if (aSelection->isInitialized()) { - AttributeDoubleArrayPtr aValues = + AttributeDoubleArrayPtr aValues = std::dynamic_pointer_cast(attribute(RESULT_VALUES_ID())); + + if (aSelection->isInitialized()) { std::stringstream streamxmin; std::stringstream streamymin; std::stringstream streamzmin; @@ -130,6 +106,12 @@ bool FeaturesPlugin_BoundingBox::updateValues() aShape = aSelection->context()->shape(); } + AttributeBooleanPtr anIsCompute = boolean(COMPUTE_ID()); + if (!anIsCompute->value()) { + myShape = aShape; + anIsCompute->setValue(true); + } + if (aShape && !aShape->isEqual(myShape)) { double aXmin, aXmax, aYmin, aYmax, aZmin, aZmax; std::string anError; @@ -141,7 +123,6 @@ bool FeaturesPlugin_BoundingBox::updateValues() setError("Error in bounding box calculation :" + anError); return false; } - myShape = aShape; streamxmin << std::setprecision(14) << aXmin; aValues->setValue(0, aXmin); @@ -155,45 +136,27 @@ bool FeaturesPlugin_BoundingBox::updateValues() aValues->setValue(4, aZmin); streamzmax << std::setprecision(14) << aZmax; aValues->setValue(5, aZmax); - string(X_MIN_COORD_ID() )->setValue( "X = " + streamxmin.str() ); - string(Y_MIN_COORD_ID() )->setValue( "Y = " + streamymin.str() ); - string(Z_MIN_COORD_ID() )->setValue( "Z = " + streamzmin.str() ); - string(X_MAX_COORD_ID() )->setValue( "X = " + streamxmax.str() ); - string(Y_MAX_COORD_ID() )->setValue( "Y = " + streamymax.str() ); - string(Z_MAX_COORD_ID() )->setValue( "Z = " + streamzmax.str() ); + } else { + streamxmin << std::setprecision(14) << aValues->value(0); + streamxmax << std::setprecision(14) << aValues->value(1); + streamymin << std::setprecision(14) << aValues->value(2); + streamymax << std::setprecision(14) << aValues->value(3); + streamzmin << std::setprecision(14) << aValues->value(4); + streamzmax << std::setprecision(14) << aValues->value(5); } - } - return true; -} - -//================================================================================================= -void FeaturesPlugin_BoundingBox::createBox() -{ - SessionPtr aSession = ModelAPI_Session::get(); - - DocumentPtr aDoc = aSession->activeDocument(); - if (aDoc.get()) { - myCreateFeature = aDoc->addFeature(FeaturesPlugin_CreateBoundingBox::ID()); + string(X_MIN_COORD_ID() )->setValue( "X = " + streamxmin.str() ); + string(Y_MIN_COORD_ID() )->setValue( "Y = " + streamymin.str() ); + string(Z_MIN_COORD_ID() )->setValue( "Z = " + streamzmin.str() ); + string(X_MAX_COORD_ID() )->setValue( "X = " + streamxmax.str() ); + string(Y_MAX_COORD_ID() )->setValue( "Y = " + streamymax.str() ); + string(Z_MAX_COORD_ID() )->setValue( "Z = " + streamzmax.str() ); } + return true; } //================================================================================================= -void FeaturesPlugin_BoundingBox::updateBox() +AttributePtr FeaturesPlugin_BoundingBox::attributResultValues() { - myCreateFeature->boolean(FeaturesPlugin_CreateBoundingBox::COMPUTE_ID())->setValue(false); - myCreateFeature->selection(FeaturesPlugin_CreateBoundingBox::OBJECT_ID()) - ->setValue(selection(OBJECT_ID())->context(), - selection(OBJECT_ID())->value()); - - AttributeDoubleArrayPtr aValuesFeatures = - std::dynamic_pointer_cast - (myCreateFeature->attribute(RESULT_VALUES_ID())); - AttributeDoubleArrayPtr aValues = - std::dynamic_pointer_cast(attribute(RESULT_VALUES_ID())); - for (int anI=0; anI < 6; anI++) - aValuesFeatures->setValue(anI,aValues->value(anI)); - - myCreateFeature->execute(); - myCreateFeature->boolean(FeaturesPlugin_CreateBoundingBox::COMPUTE_ID())->setValue(true); + return attribute(RESULT_VALUES_ID()); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.h b/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.h index 9238942c4..0f8f14dce 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.h +++ b/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.h @@ -20,19 +20,19 @@ #ifndef FeaturesPlugin_BoundingBox_H_ #define FeaturesPlugin_BoundingBox_H_ -#include +#include /// \class FeaturesPlugin_BoundingBox /// \ingroup Plugins -/// \brief Feature to view the Bounding Box. +/// \brief Persistence feature to create the bounding box. -class FeaturesPlugin_BoundingBox : public FeaturesPlugin_CommonBoundingBox +class FeaturesPlugin_BoundingBox : public FeaturesPlugin_BoundingBoxBase { public: - /// Bounding box macro kind. + /// Bounding box kind. inline static const std::string& ID() { - static const std::string MY_ID("BoundingBoxMacro"); + static const std::string MY_ID("BoundingBox"); return MY_ID; } @@ -85,13 +85,6 @@ public: return MY_Z_MAX_COORD_ID; } - /// Attribute name for checkbox create box. - inline static const std::string& CREATEBOX_ID() - { - static const std::string MY_CREATEBOX_ID("createbox"); - return MY_CREATEBOX_ID; - } - /// Attribute name for values of result. inline static const std::string& RESULT_VALUES_ID() { @@ -99,6 +92,13 @@ public: return MY_RESULT_VALUES_ID; } + /// Attribute name for indicate to compute the bounding box. + inline static const std::string& COMPUTE_ID() + { + static const std::string MY_COMPUTE_ID("compute"); + return MY_COMPUTE_ID; + } + /// \return the kind of a feature. virtual const std::string& getKind() { @@ -115,25 +115,15 @@ public: /// \param theID identifier of changed attribute FEATURESPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); - /// Reimplemented from ModelAPI_Feature::isMacro(). Returns true. - FEATURESPLUGIN_EXPORT virtual bool isMacro() const { return true; } + /// Return Attribut values of result. + FEATURESPLUGIN_EXPORT virtual AttributePtr attributResultValues(); /// Use plugin manager for features creation FeaturesPlugin_BoundingBox(); private: - /// Return Attribut values of result. - virtual AttributePtr attributResultValues(); - /// Update values displayed. bool updateValues(); - /// Create Box - void createBox(); - /// Update Box - void updateBox(); - - /// Feature to create box - FeaturePtr myCreateFeature; }; diff --git a/src/FeaturesPlugin/FeaturesPlugin_CommonBoundingBox.cpp b/src/FeaturesPlugin/FeaturesPlugin_BoundingBoxBase.cpp similarity index 94% rename from src/FeaturesPlugin/FeaturesPlugin_CommonBoundingBox.cpp rename to src/FeaturesPlugin/FeaturesPlugin_BoundingBoxBase.cpp index 531616ff2..7da95c85d 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CommonBoundingBox.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_BoundingBoxBase.cpp @@ -17,7 +17,7 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#include "FeaturesPlugin_CommonBoundingBox.h" +#include "FeaturesPlugin_BoundingBoxBase.h" #include @@ -39,7 +39,7 @@ //================================================================================================= -void FeaturesPlugin_CommonBoundingBox::createBoxByTwoPoints() +void FeaturesPlugin_BoundingBoxBase::createBoxByTwoPoints() { AttributeDoubleArrayPtr aValues = std::dynamic_pointer_cast(attributResultValues()); @@ -95,7 +95,7 @@ void FeaturesPlugin_CommonBoundingBox::createBoxByTwoPoints() } //================================================================================================= -void FeaturesPlugin_CommonBoundingBox::loadNamingDS(std::shared_ptr theBoxAlgo, +void FeaturesPlugin_BoundingBoxBase::loadNamingDS(std::shared_ptr theBoxAlgo, std::shared_ptr theResultBox) { // Load the result diff --git a/src/FeaturesPlugin/FeaturesPlugin_CommonBoundingBox.h b/src/FeaturesPlugin/FeaturesPlugin_BoundingBoxBase.h similarity index 82% rename from src/FeaturesPlugin/FeaturesPlugin_CommonBoundingBox.h rename to src/FeaturesPlugin/FeaturesPlugin_BoundingBoxBase.h index c461535d6..862aae8c8 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CommonBoundingBox.h +++ b/src/FeaturesPlugin/FeaturesPlugin_BoundingBoxBase.h @@ -17,8 +17,8 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#ifndef FeaturesPlugin_CommonBoundingBox_H_ -#define FeaturesPlugin_CommonBoundingBox_H_ +#ifndef FeaturesPlugin_BoundingBoxBase_H_ +#define FeaturesPlugin_BoundingBoxBase_H_ #include "FeaturesPlugin.h" #include @@ -30,11 +30,11 @@ #include -/// \class FeaturesPlugin_CommonBoundingBox +/// \class FeaturesPlugin_BoundingBoxBase /// \ingroup Plugins -/// \brief Feature to view the Bounding Box. - -class FeaturesPlugin_CommonBoundingBox : public ModelAPI_Feature +/// \brief Base feature to inspect properties of bounding box +/// and create that box for the selected shape. +class FeaturesPlugin_BoundingBoxBase : public ModelAPI_Feature { public: /// Performs the algorithm and stores results it in the data structure. @@ -44,7 +44,7 @@ public: virtual AttributePtr attributResultValues() = 0; protected: - FeaturesPlugin_CommonBoundingBox() {} + FeaturesPlugin_BoundingBoxBase() {} /// Create box with two points void createBoxByTwoPoints(); diff --git a/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp b/src/FeaturesPlugin/FeaturesPlugin_InspectBoundingBox.cpp similarity index 63% rename from src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp rename to src/FeaturesPlugin/FeaturesPlugin_InspectBoundingBox.cpp index c3c9bea53..aed9de077 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_InspectBoundingBox.cpp @@ -17,32 +17,32 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#include "FeaturesPlugin_CreateBoundingBox.h" +#include "FeaturesPlugin_InspectBoundingBox.h" + +#include + +#include + +#include #include #include -#include #include - +#include #include #include #include -#include - -#include -#include - #include #include //================================================================================================= -FeaturesPlugin_CreateBoundingBox::FeaturesPlugin_CreateBoundingBox() +FeaturesPlugin_InspectBoundingBox::FeaturesPlugin_InspectBoundingBox() { } //================================================================================================= -void FeaturesPlugin_CreateBoundingBox::initAttributes() +void FeaturesPlugin_InspectBoundingBox::initAttributes() { // attribute for object selected data()->addAttribute(OBJECT_ID(), ModelAPI_AttributeSelection::typeId()); @@ -54,7 +54,7 @@ void FeaturesPlugin_CreateBoundingBox::initAttributes() data()->addAttribute(X_MAX_COORD_ID(), ModelAPI_AttributeString::typeId()); data()->addAttribute(Y_MAX_COORD_ID(), ModelAPI_AttributeString::typeId()); data()->addAttribute(Z_MAX_COORD_ID(), ModelAPI_AttributeString::typeId()); - data()->addAttribute(COMPUTE_ID(), ModelAPI_AttributeBoolean::typeId()); + data()->addAttribute(CREATEBOX_ID(), ModelAPI_AttributeBoolean::typeId()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), X_MIN_COORD_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Y_MIN_COORD_ID()); @@ -62,36 +62,60 @@ void FeaturesPlugin_CreateBoundingBox::initAttributes() ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), X_MAX_COORD_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Y_MAX_COORD_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Z_MAX_COORD_ID()); - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), COMPUTE_ID()); - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), OBJECT_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CREATEBOX_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), RESULT_VALUES_ID()); + data()->addAttribute(RESULT_VALUES_ID(), ModelAPI_AttributeDoubleArray::typeId()); data()->realArray(RESULT_VALUES_ID())->setSize(6); - data()->boolean(COMPUTE_ID())->setValue(true); + } //================================================================================================= -void FeaturesPlugin_CreateBoundingBox::execute() +void FeaturesPlugin_InspectBoundingBox::execute() { if (!updateValues()) return; createBoxByTwoPoints(); + + if (boolean(CREATEBOX_ID())->value()) { + if (!myCreateFeature.get()) + createBox(); + updateBox(); + } else { + if (myCreateFeature.get()) { + myCreateFeature->eraseResults(); + SessionPtr aSession = ModelAPI_Session::get(); + DocumentPtr aDoc = aSession->activeDocument(); + aDoc->removeFeature(myCreateFeature); + myCreateFeature.reset(); + } + } } //================================================================================================= -void FeaturesPlugin_CreateBoundingBox::attributeChanged(const std::string& theID) +void FeaturesPlugin_InspectBoundingBox::attributeChanged(const std::string& theID) { + if (theID == OBJECT_ID()) { + if (myCreateFeature.get()) + updateBox(); + } } //================================================================================================= -bool FeaturesPlugin_CreateBoundingBox::updateValues() +AttributePtr FeaturesPlugin_InspectBoundingBox::attributResultValues() { - AttributeSelectionPtr aSelection = selection(OBJECT_ID()); - AttributeDoubleArrayPtr aValues = - std::dynamic_pointer_cast(attribute(RESULT_VALUES_ID())); + return attribute(RESULT_VALUES_ID()); +} +//================================================================================================= +bool FeaturesPlugin_InspectBoundingBox::updateValues() +{ + AttributeSelectionPtr aSelection = selection(OBJECT_ID()); if (aSelection->isInitialized()) { + AttributeDoubleArrayPtr aValues = + std::dynamic_pointer_cast(attribute(RESULT_VALUES_ID())); std::stringstream streamxmin; std::stringstream streamymin; std::stringstream streamzmin; @@ -106,12 +130,6 @@ bool FeaturesPlugin_CreateBoundingBox::updateValues() aShape = aSelection->context()->shape(); } - AttributeBooleanPtr anIsCompute = boolean(COMPUTE_ID()); - if (!anIsCompute->value()) { - myShape = aShape; - anIsCompute->setValue(true); - } - if (aShape && !aShape->isEqual(myShape)) { double aXmin, aXmax, aYmin, aYmax, aZmin, aZmax; std::string anError; @@ -123,6 +141,7 @@ bool FeaturesPlugin_CreateBoundingBox::updateValues() setError("Error in bounding box calculation :" + anError); return false; } + myShape = aShape; streamxmin << std::setprecision(14) << aXmin; aValues->setValue(0, aXmin); @@ -136,27 +155,45 @@ bool FeaturesPlugin_CreateBoundingBox::updateValues() aValues->setValue(4, aZmin); streamzmax << std::setprecision(14) << aZmax; aValues->setValue(5, aZmax); - } else { - streamxmin << std::setprecision(14) << aValues->value(0); - streamxmax << std::setprecision(14) << aValues->value(1); - streamymin << std::setprecision(14) << aValues->value(2); - streamymax << std::setprecision(14) << aValues->value(3); - streamzmin << std::setprecision(14) << aValues->value(4); - streamzmax << std::setprecision(14) << aValues->value(5); + string(X_MIN_COORD_ID() )->setValue( "X = " + streamxmin.str() ); + string(Y_MIN_COORD_ID() )->setValue( "Y = " + streamymin.str() ); + string(Z_MIN_COORD_ID() )->setValue( "Z = " + streamzmin.str() ); + string(X_MAX_COORD_ID() )->setValue( "X = " + streamxmax.str() ); + string(Y_MAX_COORD_ID() )->setValue( "Y = " + streamymax.str() ); + string(Z_MAX_COORD_ID() )->setValue( "Z = " + streamzmax.str() ); } - - string(X_MIN_COORD_ID() )->setValue( "X = " + streamxmin.str() ); - string(Y_MIN_COORD_ID() )->setValue( "Y = " + streamymin.str() ); - string(Z_MIN_COORD_ID() )->setValue( "Z = " + streamzmin.str() ); - string(X_MAX_COORD_ID() )->setValue( "X = " + streamxmax.str() ); - string(Y_MAX_COORD_ID() )->setValue( "Y = " + streamymax.str() ); - string(Z_MAX_COORD_ID() )->setValue( "Z = " + streamzmax.str() ); } return true; } //================================================================================================= -AttributePtr FeaturesPlugin_CreateBoundingBox::attributResultValues() +void FeaturesPlugin_InspectBoundingBox::createBox() { - return attribute(RESULT_VALUES_ID()); + SessionPtr aSession = ModelAPI_Session::get(); + + DocumentPtr aDoc = aSession->activeDocument(); + + if (aDoc.get()) { + myCreateFeature = aDoc->addFeature(FeaturesPlugin_CreateBoundingBox::ID()); + } +} + +//================================================================================================= +void FeaturesPlugin_InspectBoundingBox::updateBox() +{ + myCreateFeature->boolean(FeaturesPlugin_CreateBoundingBox::COMPUTE_ID())->setValue(false); + myCreateFeature->selection(FeaturesPlugin_CreateBoundingBox::OBJECT_ID()) + ->setValue(selection(OBJECT_ID())->context(), + selection(OBJECT_ID())->value()); + + AttributeDoubleArrayPtr aValuesFeatures = + std::dynamic_pointer_cast + (myCreateFeature->attribute(RESULT_VALUES_ID())); + AttributeDoubleArrayPtr aValues = + std::dynamic_pointer_cast(attribute(RESULT_VALUES_ID())); + for (int anI=0; anI < 6; anI++) + aValuesFeatures->setValue(anI,aValues->value(anI)); + + myCreateFeature->execute(); + myCreateFeature->boolean(FeaturesPlugin_CreateBoundingBox::COMPUTE_ID())->setValue(true); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h b/src/FeaturesPlugin/FeaturesPlugin_InspectBoundingBox.h similarity index 78% rename from src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h rename to src/FeaturesPlugin/FeaturesPlugin_InspectBoundingBox.h index c7ead9044..3e224d43a 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h +++ b/src/FeaturesPlugin/FeaturesPlugin_InspectBoundingBox.h @@ -17,22 +17,22 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#ifndef FeaturesPlugin_CreateBoundingBox_H_ -#define FeaturesPlugin_CreateBoundingBox_H_ +#ifndef FeaturesPlugin_InspectBoundingBox_H_ +#define FeaturesPlugin_InspectBoundingBox_H_ -#include +#include -/// \class FeaturesPlugin_BoundingBox +/// \class FeaturesPlugin_InspectBoundingBox /// \ingroup Plugins /// \brief Feature to view the Bounding Box. -class FeaturesPlugin_CreateBoundingBox : public FeaturesPlugin_CommonBoundingBox +class FeaturesPlugin_InspectBoundingBox : public FeaturesPlugin_BoundingBoxBase { public: - /// Bounding box kind. + /// Bounding box macro kind. inline static const std::string& ID() { - static const std::string MY_ID("BoundingBox"); + static const std::string MY_ID("BoundingBoxMacro"); return MY_ID; } @@ -85,6 +85,13 @@ public: return MY_Z_MAX_COORD_ID; } + /// Attribute name for checkbox create box. + inline static const std::string& CREATEBOX_ID() + { + static const std::string MY_CREATEBOX_ID("createbox"); + return MY_CREATEBOX_ID; + } + /// Attribute name for values of result. inline static const std::string& RESULT_VALUES_ID() { @@ -92,13 +99,6 @@ public: return MY_RESULT_VALUES_ID; } - /// Attribute name for indicate to compute the bounding box. - inline static const std::string& COMPUTE_ID() - { - static const std::string MY_COMPUTE_ID("compute"); - return MY_COMPUTE_ID; - } - /// \return the kind of a feature. virtual const std::string& getKind() { @@ -115,15 +115,25 @@ public: /// \param theID identifier of changed attribute FEATURESPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); - /// Return Attribut values of result. - FEATURESPLUGIN_EXPORT virtual AttributePtr attributResultValues(); + /// Reimplemented from ModelAPI_Feature::isMacro(). Returns true. + FEATURESPLUGIN_EXPORT virtual bool isMacro() const { return true; } /// Use plugin manager for features creation - FeaturesPlugin_CreateBoundingBox(); + FeaturesPlugin_InspectBoundingBox(); private: + /// Return Attribut values of result. + virtual AttributePtr attributResultValues(); + /// Update values displayed. bool updateValues(); + /// Create Box + void createBox(); + /// Update Box + void updateBox(); + + /// Feature to create box + FeaturePtr myCreateFeature; }; diff --git a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp index 63d0241e3..20121610e 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -34,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -205,10 +205,10 @@ FeaturePtr FeaturesPlugin_Plugin::createFeature(std::string theFeatureID) return FeaturePtr(new FeaturesPlugin_PointCoordinates); } else if (theFeatureID == FeaturesPlugin_GeometryCalculation::ID()) { return FeaturePtr(new FeaturesPlugin_GeometryCalculation); + } else if (theFeatureID == FeaturesPlugin_InspectBoundingBox::ID()) { + return FeaturePtr(new FeaturesPlugin_InspectBoundingBox); } else if (theFeatureID == FeaturesPlugin_BoundingBox::ID()) { return FeaturePtr(new FeaturesPlugin_BoundingBox); - } else if (theFeatureID == FeaturesPlugin_CreateBoundingBox::ID()) { - return FeaturePtr(new FeaturesPlugin_CreateBoundingBox); } -- 2.39.2