From 50e3d509e23eb7bbdc18c61b715b8fba735e540a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me?= Date: Mon, 16 Nov 2020 18:32:37 +0100 Subject: [PATCH] Modifications for "create box" functionality --- src/FeaturesAPI/CMakeLists.txt | 2 + src/FeaturesAPI/FeaturesAPI.i | 1 + src/FeaturesAPI/FeaturesAPI_BoundingBox.cpp | 10 +- src/FeaturesAPI/FeaturesAPI_BoundingBox.h | 6 +- .../FeaturesAPI_GeometryCalculation.cpp | 45 ++++ .../FeaturesAPI_GeometryCalculation.h | 37 +++ src/FeaturesAPI/FeaturesAPI_swig.h | 1 + src/FeaturesPlugin/CMakeLists.txt | 7 + .../CreateBoundingBox_widget.xml | 21 ++ .../FeaturesPlugin_BoundingBox.cpp | 93 +++----- .../FeaturesPlugin_BoundingBox.h | 11 +- .../FeaturesPlugin_CreateBoundingBox.cpp | 212 ++++++++++++++++++ .../FeaturesPlugin_CreateBoundingBox.h | 126 +++++++++++ .../FeaturesPlugin_GeometryCalculation.cpp | 107 +++++++++ .../FeaturesPlugin_GeometryCalculation.h | 101 +++++++++ src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp | 9 +- .../GeometryCalculation_widget.xml | 13 ++ src/FeaturesPlugin/plugin-Features.xml | 12 +- .../GeomAlgoAPI_BasicProperties.cpp | 75 +++++++ src/GeomAlgoAPI/GeomAlgoAPI_BasicProperties.h | 42 ++++ src/GeomAlgoAPI/GeomAlgoAPI_BoundingBox.cpp | 2 +- src/PythonAPI/model/features/__init__.py | 2 +- 22 files changed, 849 insertions(+), 86 deletions(-) create mode 100644 src/FeaturesAPI/FeaturesAPI_GeometryCalculation.cpp create mode 100644 src/FeaturesAPI/FeaturesAPI_GeometryCalculation.h create mode 100644 src/FeaturesPlugin/CreateBoundingBox_widget.xml create mode 100644 src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp create mode 100644 src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h create mode 100644 src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp create mode 100644 src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.h create mode 100644 src/FeaturesPlugin/GeometryCalculation_widget.xml create mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_BasicProperties.cpp create mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_BasicProperties.h diff --git a/src/FeaturesAPI/CMakeLists.txt b/src/FeaturesAPI/CMakeLists.txt index 8294dd39e..c6fbf821c 100644 --- a/src/FeaturesAPI/CMakeLists.txt +++ b/src/FeaturesAPI/CMakeLists.txt @@ -32,6 +32,7 @@ SET(PROJECT_HEADERS FeaturesAPI_Fillet.h FeaturesAPI_Intersection.h FeaturesAPI_Measurement.h + FeaturesAPI_GeometryCalculation.h FeaturesAPI_BoundingBox.h FeaturesAPI_MultiRotation.h FeaturesAPI_MultiTranslation.h @@ -67,6 +68,7 @@ SET(PROJECT_SOURCES FeaturesAPI_Intersection.cpp FeaturesAPI_Measurement.cpp FeaturesAPI_BoundingBox.cpp + FeaturesAPI_GeometryCalculation.cpp FeaturesAPI_MultiRotation.cpp FeaturesAPI_MultiTranslation.cpp FeaturesAPI_Partition.cpp diff --git a/src/FeaturesAPI/FeaturesAPI.i b/src/FeaturesAPI/FeaturesAPI.i index b4f0fbe87..11a7cbcd1 100644 --- a/src/FeaturesAPI/FeaturesAPI.i +++ b/src/FeaturesAPI/FeaturesAPI.i @@ -212,6 +212,7 @@ %include "FeaturesAPI_Fillet.h" %include "FeaturesAPI_Intersection.h" %include "FeaturesAPI_Measurement.h" +%include "FeaturesAPI_GeometryCalculation.h" %include "FeaturesAPI_BoundingBox.h" %include "FeaturesAPI_MultiRotation.h" %include "FeaturesAPI_MultiTranslation.h" diff --git a/src/FeaturesAPI/FeaturesAPI_BoundingBox.cpp b/src/FeaturesAPI/FeaturesAPI_BoundingBox.cpp index cefac8ea0..4d989d0a9 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 @@ -58,23 +58,19 @@ void FeaturesAPI_BoundingBox::dump(ModelHighAPI_Dumper& theDumper) const const std::string& aDocName = theDumper.name(aBase->document()); AttributeSelectionPtr anAttrObject; - anAttrObject = aBase->selection(FeaturesPlugin_BoundingBox::OBJECTS_LIST_ID()); + anAttrObject = aBase->selection(FeaturesPlugin_CreateBoundingBox::OBJECTS_LIST_ID()); theDumper << aBase << " = model.getBoundingBox(" << aDocName << ", " << anAttrObject; - //if (!aBase->data()->version().empty()) - // theDumper << ", keepSubResults = True"; - theDumper << ")" << std::endl; } BoundingBoxPtr getBoundingBox(const std::shared_ptr& thePart, const ModelHighAPI_Selection& theobject) { - FeaturePtr aBoundingBoxFeat = thePart->addFeature(FeaturesPlugin_BoundingBox::ID()); FeaturePtr aFeature = - thePart->addFeature(FeaturesAPI_BoundingBox::ID()); + thePart->addFeature(FeaturesPlugin_CreateBoundingBox::ID()); BoundingBoxPtr aBoundingBox; diff --git a/src/FeaturesAPI/FeaturesAPI_BoundingBox.h b/src/FeaturesAPI/FeaturesAPI_BoundingBox.h index 738c8f8ce..efa82195b 100644 --- a/src/FeaturesAPI/FeaturesAPI_BoundingBox.h +++ b/src/FeaturesAPI/FeaturesAPI_BoundingBox.h @@ -22,7 +22,7 @@ #include "FeaturesAPI.h" -#include "FeaturesPlugin_BoundingBox.h" +#include "FeaturesPlugin_CreateBoundingBox.h" #include #include @@ -50,8 +50,8 @@ public: FEATURESAPI_EXPORT virtual ~FeaturesAPI_BoundingBox(); - INTERFACE_1(FeaturesPlugin_BoundingBox::ID(), - objectselected, FeaturesPlugin_BoundingBox::OBJECTS_LIST_ID(), + INTERFACE_1(FeaturesPlugin_CreateBoundingBox::ID(), + objectselected, FeaturesPlugin_CreateBoundingBox::OBJECTS_LIST_ID(), ModelAPI_AttributeSelection, /** object selected*/) diff --git a/src/FeaturesAPI/FeaturesAPI_GeometryCalculation.cpp b/src/FeaturesAPI/FeaturesAPI_GeometryCalculation.cpp new file mode 100644 index 000000000..9bf0ae406 --- /dev/null +++ b/src/FeaturesAPI/FeaturesAPI_GeometryCalculation.cpp @@ -0,0 +1,45 @@ +// 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 "FeaturesAPI_GeometryCalculation.h" + +#include +#include +#include +#include + +std::list getBasicProperties(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& theObject) +{ + FeaturePtr aPointCoodFeat = thePart->addFeature(FeaturesPlugin_GeometryCalculation::ID()); + + fillAttribute(theObject, aPointCoodFeat + ->selection(FeaturesPlugin_GeometryCalculation::OBJECT_SELECTED_ID())); + std::list res; + + // obtain result + AttributeDoubleArrayPtr aResult = std::dynamic_pointer_cast( + aPointCoodFeat->attribute(FeaturesPlugin_GeometryCalculation::RESULT_VALUES_ID())); + + for ( int i : {0, 1, 2}) + res.push_back( aResult->value(i)); + + return res; +} + diff --git a/src/FeaturesAPI/FeaturesAPI_GeometryCalculation.h b/src/FeaturesAPI/FeaturesAPI_GeometryCalculation.h new file mode 100644 index 000000000..abed69276 --- /dev/null +++ b/src/FeaturesAPI/FeaturesAPI_GeometryCalculation.h @@ -0,0 +1,37 @@ +// 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 FeaturesAPI_GeometryCalculation_H_ +#define FeaturesAPI_GeometryCalculation_H_ + +#include "FeaturesAPI.h" + +#include +#include + +class ModelAPI_Document; +class ModelHighAPI_Selection; + +/// \ingroup CPPHighAPI +/// \brief get the basic properties (lenght, Surface area, volume) +FEATURESAPI_EXPORT +std::list getBasicProperties(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& theObject); + +#endif // FeaturesAPI_GeometryCalculation_H_ \ No newline at end of file diff --git a/src/FeaturesAPI/FeaturesAPI_swig.h b/src/FeaturesAPI/FeaturesAPI_swig.h index 232234267..89d415e98 100644 --- a/src/FeaturesAPI/FeaturesAPI_swig.h +++ b/src/FeaturesAPI/FeaturesAPI_swig.h @@ -35,6 +35,7 @@ #include "FeaturesAPI_Fillet.h" #include "FeaturesAPI_Intersection.h" #include "FeaturesAPI_Measurement.h" + #include "FeaturesAPI_GeometryCalculation.h" #include "FeaturesAPI_BoundingBox.h" #include "FeaturesAPI_MultiRotation.h" #include "FeaturesAPI_MultiTranslation.h" diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index f4a79922b..0e26bae5d 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -70,7 +70,9 @@ SET(PROJECT_HEADERS FeaturesPlugin_Fillet.h FeaturesPlugin_Fillet1D.h FeaturesPlugin_Measurement.h + FeaturesPlugin_GeometryCalculation.h FeaturesPlugin_BoundingBox.h + FeaturesPlugin_CreateBoundingBox.h FeaturesPlugin_FusionFaces.h FeaturesPlugin_RemoveResults.h FeaturesPlugin_Chamfer.h @@ -118,7 +120,9 @@ SET(PROJECT_SOURCES FeaturesPlugin_Fillet.cpp FeaturesPlugin_Fillet1D.cpp FeaturesPlugin_Measurement.cpp + FeaturesPlugin_GeometryCalculation.cpp FeaturesPlugin_BoundingBox.cpp + FeaturesPlugin_CreateBoundingBox.cpp FeaturesPlugin_FusionFaces.cpp FeaturesPlugin_RemoveResults.cpp FeaturesPlugin_Chamfer.cpp @@ -157,7 +161,9 @@ SET(XML_RESOURCES fillet_widget.xml fillet1d_widget.xml measurement_widget.xml + GeometryCalculation_widget.xml BoundingBox_widget.xml + CreateBoundingBox_widget.xml fusion_faces_widget.xml chamfer_widget.xml copy_widget.xml @@ -701,4 +707,5 @@ ADD_UNIT_TESTS(TestExtrusion.py TestFillet1D_Wire_3.py TestFillet1D_Wire_4.py TestFillet1D_Wire_5.py + TestBoundingBox.py ) diff --git a/src/FeaturesPlugin/CreateBoundingBox_widget.xml b/src/FeaturesPlugin/CreateBoundingBox_widget.xml new file mode 100644 index 000000000..02cb6484e --- /dev/null +++ b/src/FeaturesPlugin/CreateBoundingBox_widget.xml @@ -0,0 +1,21 @@ + + + + + + + + + + diff --git a/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.cpp b/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.cpp index f6d530c6a..fe83ea07d 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.cpp @@ -32,6 +32,8 @@ #include #include +#include + #include #include #include @@ -70,12 +72,21 @@ void FeaturesPlugin_BoundingBox::initAttributes() void FeaturesPlugin_BoundingBox::execute() { + updateValues(); if(boolean(CREATEBOX_ID())->value()) { - updateValues(); - createBoxByTwoPoints(); + if( !myCreateFeature.get() ) + createBox(); + updateBox(); }else{ - eraseResults(); + if( myCreateFeature.get() ) + { + myCreateFeature->eraseResults(); + SessionPtr aSession = ModelAPI_Session::get(); + DocumentPtr aDoc = aSession->activeDocument(); + aDoc->removeFeature(myCreateFeature); + myCreateFeature.reset(); + } } } @@ -83,6 +94,8 @@ void FeaturesPlugin_BoundingBox::attributeChanged(const std::string& theID) { if (theID == OBJECTS_LIST_ID()) { updateValues(); + if( myCreateFeature.get() ) + updateBox(); } } @@ -137,74 +150,22 @@ void FeaturesPlugin_BoundingBox::updateValues() } //================================================================================================= -void FeaturesPlugin_BoundingBox::createBoxByTwoPoints() +void FeaturesPlugin_BoundingBox::createBox() { - AttributeDoubleArrayPtr aValues = - std::dynamic_pointer_cast(attribute(RESULT_VALUES_ID())); - - 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())); - + SessionPtr aSession = ModelAPI_Session::get(); - // 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(); + DocumentPtr aDoc = aSession->activeDocument(); - // 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; + if (aDoc.get()) { + myCreateFeature = aDoc->addFeature(FeaturesPlugin_CreateBoundingBox::ID()); } - - int aResultIndex = 0; - ResultBodyPtr aResultBox = document()->createBody(data(), aResultIndex); - loadNamingDS(aBoxAlgo, aResultBox); - setResult(aResultBox, aResultIndex); } -//================================================================================================= -void FeaturesPlugin_BoundingBox::loadNamingDS(std::shared_ptr theBoxAlgo, - std::shared_ptr theResultBox) +void FeaturesPlugin_BoundingBox::updateBox() { - // 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); - } -} + myCreateFeature->selection(FeaturesPlugin_CreateBoundingBox::OBJECTS_LIST_ID()) + ->setValue( selection(OBJECTS_LIST_ID())->context() , + selection(OBJECTS_LIST_ID())->value() ); + myCreateFeature->execute(); +} diff --git a/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.h b/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.h index 997054858..0aceb4e4c 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.h +++ b/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.h @@ -36,7 +36,7 @@ class FeaturesPlugin_BoundingBox : public ModelAPI_Feature public: inline static const std::string& ID() { - static const std::string MY_ID("BoundingBox"); + static const std::string MY_ID("BoundingBoxMacro"); return MY_ID; } @@ -119,14 +119,17 @@ 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; } + /// Use plugin manager for features creation FeaturesPlugin_BoundingBox(); private: void updateValues(); - void createBoxByTwoPoints(); - void loadNamingDS(std::shared_ptr theBoxAlgo, - std::shared_ptr theResultBox); + void createBox(); + void updateBox(); + FeaturePtr myCreateFeature; }; diff --git a/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp b/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp new file mode 100644 index 000000000..6218cc8e3 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp @@ -0,0 +1,212 @@ +// 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_CreateBoundingBox.h" + +#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 + data()->addAttribute(OBJECTS_LIST_ID(), ModelAPI_AttributeSelection::typeId()); + // attributes for result message and values + data()->addAttribute(X_MIN_COOD_ID(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(Y_MIN_COOD_ID(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(Z_MIN_COOD_ID(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(X_MAX_COOD_ID(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(Y_MAX_COOD_ID(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(Z_MAX_COOD_ID(), ModelAPI_AttributeString::typeId()); + + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), X_MIN_COOD_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Y_MIN_COOD_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Z_MIN_COOD_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), X_MAX_COOD_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Y_MAX_COOD_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Z_MAX_COOD_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); + +} + +void FeaturesPlugin_CreateBoundingBox::execute() +{ + updateValues(); + createBoxByTwoPoints(); +} + +void FeaturesPlugin_CreateBoundingBox::attributeChanged(const std::string& theID) +{ + if (theID == OBJECTS_LIST_ID()) { + updateValues(); + } +} + +void FeaturesPlugin_CreateBoundingBox::updateValues() +{ + AttributeSelectionPtr aSelection = selection(OBJECTS_LIST_ID()); + AttributeDoubleArrayPtr aValues = + std::dynamic_pointer_cast(attribute(RESULT_VALUES_ID())); + std::stringstream streamxmin; + std::stringstream streamymin; + std::stringstream streamzmin; + std::stringstream streamxmax; + std::stringstream streamymax; + std::stringstream streamzmax; + GeomShapePtr aShape; + if (aSelection && aSelection->isInitialized()) { + aShape = aSelection->value(); + if (!aShape && aSelection->context()) + aShape = aSelection->context()->shape(); + } + if (aShape){ + double aXmin, aXmax, aYmin,aYmax,aZmin,aZmax; + std::string aError; + if( !GetBoundingBox(aShape, + true, + aXmin, aXmax, + aYmin,aYmax, + aZmin,aZmax, + aError)) + setError("Error in bounding box calculation :" + aError); + + streamxmin << std::setprecision(14) << aXmin; + aValues->setValue(0, aXmin); + streamxmax << std::setprecision(14) << aXmax; + aValues->setValue(1, aXmax); + streamymin << std::setprecision(14) << aYmin; + aValues->setValue(2, aYmin); + streamymax << std::setprecision(14) << aYmax; + aValues->setValue(3, aYmax); + streamzmin << std::setprecision(14) << aZmin; + aValues->setValue(4, aZmin); + streamzmax << std::setprecision(14) << aZmax; + aValues->setValue(5, aZmax); + } + + string(X_MIN_COOD_ID() )->setValue( "X = " + streamxmin.str() ); + string(Y_MIN_COOD_ID() )->setValue( "Y = " + streamymin.str() ); + string(Z_MIN_COOD_ID() )->setValue( "Z = " + streamzmin.str() ); + string(X_MAX_COOD_ID() )->setValue( "X = " + streamxmax.str() ); + string(Y_MAX_COOD_ID() )->setValue( "Y = " + streamymax.str() ); + string(Z_MAX_COOD_ID() )->setValue( "Z = " + streamzmax.str() ); +} + +//================================================================================================= +void FeaturesPlugin_CreateBoundingBox::createBoxByTwoPoints() +{ + 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); + } +} + diff --git a/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h b/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h new file mode 100644 index 000000000..d80cde3ae --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h @@ -0,0 +1,126 @@ +// 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_CreateBoundingBox_H_ +#define FeaturesPlugin_CreateBoundingBox_H_ + +#include "FeaturesPlugin.h" +#include + +#include +#include +#include + +/// \class FeaturesPlugin_BoundingBox +/// \ingroup Plugins +/// \brief Feature to view the Bounding Box. + +class FeaturesPlugin_CreateBoundingBox : public ModelAPI_Feature +{ +public: + inline static const std::string& ID() + { + static const std::string MY_ID("BoundingBox"); + return MY_ID; + } + + /// \return the kind of a feature. + virtual const std::string& getKind() + { + return ID(); + } + + /// Attribute name for object selected. + inline static const std::string& OBJECTS_LIST_ID() + { + static const std::string MY_OBJECTS_LIST_ID("main_objects"); + return MY_OBJECTS_LIST_ID; + } + + /// Attribute name for x coodinate. + inline static const std::string& X_MIN_COOD_ID() + { + static const std::string MY_X_MIN_COOD_ID("xmincoordinate"); + return MY_X_MIN_COOD_ID; + } + + /// Attribute name for y coodinate. + inline static const std::string& Y_MIN_COOD_ID() + { + static const std::string MY_Y_MIN_COOD_ID("ymincoordinate"); + return MY_Y_MIN_COOD_ID; + } + + /// Attribute name for z coodinate. + inline static const std::string& Z_MIN_COOD_ID() + { + static const std::string MY_Z_MIN_COOD_ID("zmincoordinate"); + return MY_Z_MIN_COOD_ID; + } + + /// 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"); + return MY_X_MAX_COOD_ID; + } + + /// Attribute name for y max coodinate. + inline static const std::string& Y_MAX_COOD_ID() + { + static const std::string MY_Y_MAX_COOOD_ID("ymaxcoordinate"); + return MY_Y_MAX_COOOD_ID; + } + + /// Attribute name for z max coodinate. + inline static const std::string& Z_MAX_COOD_ID() + { + static const std::string MY_Z_MAX_COOD_ID("zmaxcoordinate"); + return MY_Z_MAX_COOD_ID; + } + + /// Attribute name for values of result. + inline static const std::string& RESULT_VALUES_ID() + { + static const std::string MY_RESULT_VALUES_ID("result_values"); + return MY_RESULT_VALUES_ID; + } + + /// Performs the algorithm and stores results it in the data structure. + FEATURESPLUGIN_EXPORT virtual void execute(); + + /// Request for initialization of data model of the feature: adding all attributes + FEATURESPLUGIN_EXPORT virtual void initAttributes(); + + /// Called on change of any argument-attribute of this object + /// \param theID identifier of changed attribute + FEATURESPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); + + /// Use plugin manager for features creation + FeaturesPlugin_CreateBoundingBox(); + + private: + void updateValues(); + void createBoxByTwoPoints(); + void loadNamingDS(std::shared_ptr theBoxAlgo, + std::shared_ptr theResultBox); + +}; + +#endif diff --git a/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp b/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp new file mode 100644 index 000000000..c16bc78a3 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp @@ -0,0 +1,107 @@ +// 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_GeometryCalculation.h" + +#include +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include + + +#include +#include + +FeaturesPlugin_GeometryCalculation::FeaturesPlugin_GeometryCalculation() +{ +} + +void FeaturesPlugin_GeometryCalculation::initAttributes() +{ + // attribute for point selected + data()->addAttribute(OBJECT_SELECTED_ID(), ModelAPI_AttributeSelection::typeId()); + // attributes for result message and values + data()->addAttribute(LENGHT_ID(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(AREA_ID(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(VOLUME_ID(), ModelAPI_AttributeString::typeId()); + + data()->addAttribute(RESULT_VALUES_ID(), ModelAPI_AttributeDoubleArray::typeId()); + + data()->realArray(RESULT_VALUES_ID())->setSize(3); + +} + +void FeaturesPlugin_GeometryCalculation::execute() +{ +} + +void FeaturesPlugin_GeometryCalculation::attributeChanged(const std::string& theID) +{ + if (theID == OBJECT_SELECTED_ID()) { + + AttributeSelectionPtr aSelection = selection(OBJECT_SELECTED_ID()); + AttributeDoubleArrayPtr aValues = + std::dynamic_pointer_cast(attribute(RESULT_VALUES_ID())); + std::stringstream streamL; + std::stringstream streamA; + std::stringstream streamV; + GeomShapePtr aShape; + + if (aSelection && aSelection->isInitialized()) { + aShape = aSelection->value(); + if (!aShape && aSelection->context()) + aShape = aSelection->context()->shape(); + } + if (aShape){ + double aTolerance = 0.0001; + double aLength; + double aSurfArea; + double aVolume; + std::string aError; + if( !GetBasicProperties( aShape, + aTolerance, + aLength, + aSurfArea, + aVolume, + aError) ) + setError("Error in Geometry calculation :" + aError); + + streamL << std::setprecision(14) << aLength; + aValues->setValue(0, aLength); + streamA << std::setprecision(14) << aSurfArea; + aValues->setValue(1, aSurfArea); + streamV << std::setprecision(14) << aVolume; + aValues->setValue(2, aVolume); + } + + string(LENGHT_ID() )->setValue( "Lenght = " + streamL.str() ); + string(AREA_ID() )->setValue( "Area = " + streamA.str() ); + string(VOLUME_ID() )->setValue( "Volume = " + streamV.str() ); + } +} + diff --git a/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.h b/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.h new file mode 100644 index 000000000..a41e85365 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.h @@ -0,0 +1,101 @@ +// 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_GeometryCalculation_H_ +#define FeaturesPlugin_GeometryCalculation_H_ + +#include "FeaturesPlugin.h" +#include + +#include +#include + +/// \class FeaturesPlugin_GeometryCalculation +/// \ingroup Plugins +/// \brief Feature for geometry calculation. + +class FeaturesPlugin_GeometryCalculation : public ModelAPI_Feature +{ +public: + inline static const std::string& ID() + { + static const std::string MY_ID("GeometryCalculation"); + return MY_ID; + } + + /// \return the kind of a feature. + virtual const std::string& getKind() + { + return ID(); + } + + /// Attribute name for object selected. + inline static const std::string& OBJECT_SELECTED_ID() + { + static const std::string MY_OBJECT_SELECTED_ID("main_object"); + return MY_OBJECT_SELECTED_ID; + } + + /// Attribute name for lenght + inline static const std::string& LENGHT_ID() + { + static const std::string MY_LENGHT_ID("lenght"); + return MY_LENGHT_ID; + } + + /// Attribute name for area + inline static const std::string& AREA_ID() + { + static const std::string MY_AREA_ID("area"); + return MY_AREA_ID; + } + + /// Attribute name for volume. + inline static const std::string& VOLUME_ID() + { + static const std::string MY_VOLUME_ID("volume"); + return MY_VOLUME_ID; + } + + /// Attribute name for values of result. + inline static const std::string& RESULT_VALUES_ID() + { + static const std::string MY_RESULT_VALUES_ID("result_values"); + return MY_RESULT_VALUES_ID; + } + + /// Performs the algorithm and stores results it in the data structure. + FEATURESPLUGIN_EXPORT virtual void execute(); + + /// Request for initialization of data model of the feature: adding all attributes + FEATURESPLUGIN_EXPORT virtual void initAttributes(); + + /// Called on change of any argument-attribute of this object + /// \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; } + + /// Use plugin manager for features creation + FeaturesPlugin_GeometryCalculation(); + +}; + +#endif diff --git a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp index ba813cc08..8aeaee966 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp @@ -33,7 +33,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -187,9 +189,12 @@ FeaturePtr FeaturesPlugin_Plugin::createFeature(std::string theFeatureID) } else if (theFeatureID == FeaturesPlugin_Fillet1D::ID()) { return FeaturePtr(new FeaturesPlugin_Fillet1D); } else if (theFeatureID == FeaturesPlugin_Measurement::ID()) { - return FeaturePtr(new FeaturesPlugin_Measurement); + } else if (theFeatureID == FeaturesPlugin_GeometryCalculation::ID()) { + return FeaturePtr(new FeaturesPlugin_GeometryCalculation); } else if (theFeatureID == FeaturesPlugin_BoundingBox::ID()) { - return FeaturePtr(new FeaturesPlugin_BoundingBox); + return FeaturePtr(new FeaturesPlugin_BoundingBox); + } else if (theFeatureID == FeaturesPlugin_CreateBoundingBox::ID()) { + return FeaturePtr(new FeaturesPlugin_CreateBoundingBox); } else if (theFeatureID == FeaturesPlugin_RemoveResults::ID()) { return FeaturePtr(new FeaturesPlugin_RemoveResults); } else if (theFeatureID == FeaturesPlugin_Chamfer::ID()) { diff --git a/src/FeaturesPlugin/GeometryCalculation_widget.xml b/src/FeaturesPlugin/GeometryCalculation_widget.xml new file mode 100644 index 000000000..4b5913dc5 --- /dev/null +++ b/src/FeaturesPlugin/GeometryCalculation_widget.xml @@ -0,0 +1,13 @@ + + + + +