From: Jérôme Date: Tue, 24 Nov 2020 10:10:43 +0000 (+0100) Subject: Add visualization for bounding Box X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b8ad780d7681e50c5a00b78239f1bb9d4119eca3;p=modules%2Fshaper.git Add visualization for bounding Box --- diff --git a/src/FeaturesAPI/FeaturesAPI_BoundingBox.cpp b/src/FeaturesAPI/FeaturesAPI_BoundingBox.cpp index 4d989d0a9..19191a09b 100644 --- a/src/FeaturesAPI/FeaturesAPI_BoundingBox.cpp +++ b/src/FeaturesAPI/FeaturesAPI_BoundingBox.cpp @@ -28,7 +28,7 @@ #include #include - +//================================================================================================= FeaturesAPI_BoundingBox:: FeaturesAPI_BoundingBox(const std::shared_ptr& theFeature) : ModelHighAPI_Interface(theFeature) @@ -36,6 +36,7 @@ FeaturesAPI_BoundingBox:: initialize(); } +//================================================================================================= FeaturesAPI_BoundingBox::FeaturesAPI_BoundingBox( const std::shared_ptr& theFeature, const ModelHighAPI_Selection& theobject) @@ -47,11 +48,12 @@ FeaturesAPI_BoundingBox::FeaturesAPI_BoundingBox( } } - +//================================================================================================= FeaturesAPI_BoundingBox::~FeaturesAPI_BoundingBox() { } +//================================================================================================= void FeaturesAPI_BoundingBox::dump(ModelHighAPI_Dumper& theDumper) const { FeaturePtr aBase = feature(); @@ -65,6 +67,7 @@ void FeaturesAPI_BoundingBox::dump(ModelHighAPI_Dumper& theDumper) const theDumper << ")" << std::endl; } +//================================================================================================= BoundingBoxPtr getBoundingBox(const std::shared_ptr& thePart, const ModelHighAPI_Selection& theobject) { diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 0e26bae5d..ec8382c3e 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -73,6 +73,7 @@ SET(PROJECT_HEADERS FeaturesPlugin_GeometryCalculation.h FeaturesPlugin_BoundingBox.h FeaturesPlugin_CreateBoundingBox.h + FeaturesPlugin_CommonBoundingBox.h FeaturesPlugin_FusionFaces.h FeaturesPlugin_RemoveResults.h FeaturesPlugin_Chamfer.h @@ -123,6 +124,7 @@ SET(PROJECT_SOURCES FeaturesPlugin_GeometryCalculation.cpp FeaturesPlugin_BoundingBox.cpp FeaturesPlugin_CreateBoundingBox.cpp + FeaturesPlugin_CommonBoundingBox.cpp FeaturesPlugin_FusionFaces.cpp FeaturesPlugin_RemoveResults.cpp FeaturesPlugin_Chamfer.cpp diff --git a/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.cpp b/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.cpp index fe83ea07d..0b92fcea4 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.cpp @@ -22,26 +22,26 @@ #include #include #include -#include #include + +#include + #include #include #include -#include -#include #include -#include #include #include #include -#include +//================================================================================================= FeaturesPlugin_BoundingBox::FeaturesPlugin_BoundingBox() { } +//================================================================================================= void FeaturesPlugin_BoundingBox::initAttributes() { // attribute for object selected @@ -70,17 +70,18 @@ void FeaturesPlugin_BoundingBox::initAttributes() } +//================================================================================================= void FeaturesPlugin_BoundingBox::execute() { updateValues(); - if(boolean(CREATEBOX_ID())->value()) - { - if( !myCreateFeature.get() ) + createBoxByTwoPoints(); + + if (boolean(CREATEBOX_ID())->value()) { + if (!myCreateFeature.get()) createBox(); updateBox(); - }else{ - if( myCreateFeature.get() ) - { + } else { + if (myCreateFeature.get()) { myCreateFeature->eraseResults(); SessionPtr aSession = ModelAPI_Session::get(); DocumentPtr aDoc = aSession->activeDocument(); @@ -90,15 +91,24 @@ void FeaturesPlugin_BoundingBox::execute() } } +//================================================================================================= void FeaturesPlugin_BoundingBox::attributeChanged(const std::string& theID) { if (theID == OBJECTS_LIST_ID()) { updateValues(); - if( myCreateFeature.get() ) + createBoxByTwoPoints(); + if (myCreateFeature.get()) updateBox(); } } +//================================================================================================= +AttributePtr FeaturesPlugin_BoundingBox::attributResultValues() +{ + return attribute(RESULT_VALUES_ID()); +} + +//================================================================================================= void FeaturesPlugin_BoundingBox::updateValues() { AttributeSelectionPtr aSelection = selection(OBJECTS_LIST_ID()); @@ -116,10 +126,10 @@ void FeaturesPlugin_BoundingBox::updateValues() if (!aShape && aSelection->context()) aShape = aSelection->context()->shape(); } - if (aShape){ + if (aShape) { double aXmin, aXmax, aYmin,aYmax,aZmin,aZmax; std::string aError; - if( !GetBoundingBox(aShape, + if (!GetBoundingBox(aShape, true, aXmin, aXmax, aYmin,aYmax, @@ -161,6 +171,7 @@ void FeaturesPlugin_BoundingBox::createBox() } } +//================================================================================================= void FeaturesPlugin_BoundingBox::updateBox() { myCreateFeature->selection(FeaturesPlugin_CreateBoundingBox::OBJECTS_LIST_ID()) diff --git a/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.h b/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.h index 0aceb4e4c..cb1f1aacd 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.h +++ b/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.h @@ -20,18 +20,13 @@ #ifndef FeaturesPlugin_BoundingBox_H_ #define FeaturesPlugin_BoundingBox_H_ -#include "FeaturesPlugin.h" -#include - -#include -#include -#include +#include /// \class FeaturesPlugin_BoundingBox /// \ingroup Plugins /// \brief Feature to view the Bounding Box. -class FeaturesPlugin_BoundingBox : public ModelAPI_Feature +class FeaturesPlugin_BoundingBox : public FeaturesPlugin_CommonBoundingBox { public: inline static const std::string& ID() @@ -74,7 +69,7 @@ public: return MY_Z_MIN_COOD_ID; } - /// Attribute name for x max coodinate. + /// Attribute name for x max coodinate. inline static const std::string& X_MAX_COOD_ID() { static const std::string MY_X_MAX_COOD_ID("xmaxcoordinate"); @@ -126,9 +121,17 @@ public: FeaturesPlugin_BoundingBox(); private: + /// Return Attribut values of result. + virtual AttributePtr attributResultValues(); + + /// Update values displayed. void 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_CommonBoundingBox.cpp new file mode 100644 index 000000000..6edc82590 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_CommonBoundingBox.cpp @@ -0,0 +1,119 @@ +// Copyright (C) 2018-2020 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "FeaturesPlugin_CommonBoundingBox.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + + +//================================================================================================= +void FeaturesPlugin_CommonBoundingBox::createBoxByTwoPoints() +{ + AttributeDoubleArrayPtr aValues = + std::dynamic_pointer_cast(attributResultValues()); + + SessionPtr aSession = ModelAPI_Session::get(); + + DocumentPtr aDoc = aSession->activeDocument(); + + GeomVertexPtr vertexFirst = + GeomAlgoAPI_PointBuilder::vertex( aValues->value(0), + aValues->value(2), + aValues->value(4)); + + GeomVertexPtr vertexSecond = + GeomAlgoAPI_PointBuilder::vertex( aValues->value(1), + aValues->value(3), + aValues->value(5)); + + + std::shared_ptr aBoxAlgo; + + + aBoxAlgo = std::shared_ptr( + new GeomAlgoAPI_Box(vertexFirst->point(),vertexSecond->point())); + + + // These checks should be made to the GUI for the feature but + // the corresponding validator does not exist yet. + if (!aBoxAlgo->check()) { + setError(aBoxAlgo->getError()); + return; + } + + // Build the box + aBoxAlgo->build(); + + // Check if the creation of the box + if (!aBoxAlgo->isDone()) { + // The error is not displayed in a popup window. It must be in the message console. + setError(aBoxAlgo->getError()); + return; + } + if (!aBoxAlgo->checkValid("Box builder with two points")) { + // The error is not displayed in a popup window. It must be in the message console. + setError(aBoxAlgo->getError()); + return; + } + + int aResultIndex = 0; + ResultBodyPtr aResultBox = document()->createBody(data(), aResultIndex); + loadNamingDS(aBoxAlgo, aResultBox); + setResult(aResultBox, aResultIndex); +} + +//================================================================================================= +void FeaturesPlugin_CommonBoundingBox::loadNamingDS(std::shared_ptr theBoxAlgo, + std::shared_ptr theResultBox) +{ + // Load the result + theResultBox->store(theBoxAlgo->shape()); + + // Prepare the naming + theBoxAlgo->prepareNamingFaces(); + + // Insert to faces + std::map< std::string, std::shared_ptr > listOfFaces = + theBoxAlgo->getCreatedFaces(); + for (std::map< std::string, std::shared_ptr >::iterator it = listOfFaces.begin(); + it != listOfFaces.end(); + ++it) { + theResultBox->generated((*it).second, (*it).first); + } +} + diff --git a/src/FeaturesPlugin/FeaturesPlugin_CommonBoundingBox.h b/src/FeaturesPlugin/FeaturesPlugin_CommonBoundingBox.h new file mode 100644 index 000000000..18ba75972 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_CommonBoundingBox.h @@ -0,0 +1,58 @@ +// Copyright (C) 2018-2020 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef FeaturesPlugin_CommonBoundingBox_H_ +#define FeaturesPlugin_CommonBoundingBox_H_ + +#include "FeaturesPlugin.h" +#include + +#include +#include +#include + +#include + +/// \class FeaturesPlugin_CommonBoundingBox +/// \ingroup Plugins +/// \brief Feature to view the Bounding Box. + +class FeaturesPlugin_CommonBoundingBox : public ModelAPI_Feature +{ +public: + + /// Performs the algorithm and stores results it in the data structure. + FEATURESPLUGIN_EXPORT virtual void execute(){}; + + /// Return Attribut values of result. + virtual AttributePtr attributResultValues() = 0; + + protected: + FeaturesPlugin_CommonBoundingBox() {} + + /// Create box with two points + void createBoxByTwoPoints(); + + /// Create namming + void loadNamingDS(std::shared_ptr theBoxAlgo, + std::shared_ptr theResultBox); + +}; + +#endif diff --git a/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp b/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp index 6218cc8e3..df636ce89 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp @@ -22,28 +22,28 @@ #include #include #include -#include -#include #include + #include #include #include -#include -#include + +#include + #include #include -#include #include #include #include -#include +//================================================================================================= FeaturesPlugin_CreateBoundingBox::FeaturesPlugin_CreateBoundingBox() { } +//================================================================================================= void FeaturesPlugin_CreateBoundingBox::initAttributes() { // attribute for object selected @@ -70,12 +70,14 @@ void FeaturesPlugin_CreateBoundingBox::initAttributes() } +//================================================================================================= void FeaturesPlugin_CreateBoundingBox::execute() { updateValues(); createBoxByTwoPoints(); } +//================================================================================================= void FeaturesPlugin_CreateBoundingBox::attributeChanged(const std::string& theID) { if (theID == OBJECTS_LIST_ID()) { @@ -83,6 +85,7 @@ void FeaturesPlugin_CreateBoundingBox::attributeChanged(const std::string& theID } } +//================================================================================================= void FeaturesPlugin_CreateBoundingBox::updateValues() { AttributeSelectionPtr aSelection = selection(OBJECTS_LIST_ID()); @@ -134,79 +137,7 @@ void FeaturesPlugin_CreateBoundingBox::updateValues() } //================================================================================================= -void FeaturesPlugin_CreateBoundingBox::createBoxByTwoPoints() +AttributePtr FeaturesPlugin_CreateBoundingBox::attributResultValues() { - AttributeDoubleArrayPtr aValues = - std::dynamic_pointer_cast(attribute(RESULT_VALUES_ID())); - - SessionPtr aSession = ModelAPI_Session::get(); - - DocumentPtr aDoc = aSession->activeDocument(); - - GeomVertexPtr vertexFirst = - GeomAlgoAPI_PointBuilder::vertex( aValues->value(0), - aValues->value(2), - aValues->value(4)); - - GeomVertexPtr vertexSecond = - GeomAlgoAPI_PointBuilder::vertex( aValues->value(1), - aValues->value(3), - aValues->value(5)); - - - std::shared_ptr aBoxAlgo; - - - aBoxAlgo = std::shared_ptr( - new GeomAlgoAPI_Box(vertexFirst->point(),vertexSecond->point())); - - - // These checks should be made to the GUI for the feature but - // the corresponding validator does not exist yet. - if (!aBoxAlgo->check()) { - setError(aBoxAlgo->getError()); - return; - } - - // Build the box - aBoxAlgo->build(); - - // Check if the creation of the box - if(!aBoxAlgo->isDone()) { - // The error is not displayed in a popup window. It must be in the message console. - setError(aBoxAlgo->getError()); - return; - } - if(!aBoxAlgo->checkValid("Box builder with two points")) { - // The error is not displayed in a popup window. It must be in the message console. - setError(aBoxAlgo->getError()); - return; - } - - int aResultIndex = 0; - ResultBodyPtr aResultBox = document()->createBody(data(), aResultIndex); - loadNamingDS(aBoxAlgo, aResultBox); - setResult(aResultBox, aResultIndex); -} - -//================================================================================================= -void FeaturesPlugin_CreateBoundingBox::loadNamingDS(std::shared_ptr theBoxAlgo, - std::shared_ptr theResultBox) -{ - // Load the result - theResultBox->store(theBoxAlgo->shape()); - - // Prepare the naming - theBoxAlgo->prepareNamingFaces(); - - // Insert to faces - std::map< std::string, std::shared_ptr > listOfFaces = - theBoxAlgo->getCreatedFaces(); - for (std::map< std::string, std::shared_ptr >::iterator it = listOfFaces.begin(); - it != listOfFaces.end(); - ++it) - { - theResultBox->generated((*it).second, (*it).first); - } + return attribute(RESULT_VALUES_ID()); } - diff --git a/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h b/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h index d80cde3ae..d06732c26 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h +++ b/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h @@ -20,18 +20,13 @@ #ifndef FeaturesPlugin_CreateBoundingBox_H_ #define FeaturesPlugin_CreateBoundingBox_H_ -#include "FeaturesPlugin.h" -#include - -#include -#include -#include +#include /// \class FeaturesPlugin_BoundingBox /// \ingroup Plugins /// \brief Feature to view the Bounding Box. -class FeaturesPlugin_CreateBoundingBox : public ModelAPI_Feature +class FeaturesPlugin_CreateBoundingBox : public FeaturesPlugin_CommonBoundingBox { public: inline static const std::string& ID() @@ -112,14 +107,15 @@ 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(); + /// Use plugin manager for features creation FeaturesPlugin_CreateBoundingBox(); private: + /// Update values displayed. void updateValues(); - void createBoxByTwoPoints(); - void loadNamingDS(std::shared_ptr theBoxAlgo, - std::shared_ptr theResultBox); }; diff --git a/src/FeaturesPlugin/Test/TestBoundingBox.py b/src/FeaturesPlugin/Test/TestBoundingBox.py index e3d7d24c9..426a6df16 100644 --- a/src/FeaturesPlugin/Test/TestBoundingBox.py +++ b/src/FeaturesPlugin/Test/TestBoundingBox.py @@ -24,7 +24,6 @@ # Initialization of the test #========================================================================= -import salome import os import math