From 91b664498fff007ffce9731f842f85f3f498bd75 Mon Sep 17 00:00:00 2001 From: azv Date: Tue, 30 Jul 2019 11:50:46 +0300 Subject: [PATCH] Task 2.5. Combination operations on Groups (issue #2935) Implementation of Group Addition operation from scratch. --- src/CollectionPlugin/CMakeLists.txt | 5 ++ .../CollectionPlugin_GroupAddition.cpp | 45 ++++++++++++ .../CollectionPlugin_GroupAddition.h | 67 ++++++++++++++++++ .../CollectionPlugin_Plugin.cpp | 3 + .../group_addition_widget.xml | 11 +++ .../group_intersection_widget.xml | 15 ++++ .../group_substraction_widget.xml | 15 ++++ src/CollectionPlugin/icons/group_addition.png | Bin 0 -> 362 bytes .../icons/group_intersection.png | Bin 0 -> 384 bytes .../icons/group_substraction.png | Bin 0 -> 369 bytes src/CollectionPlugin/plugin-Collection.xml | 9 +++ src/FeaturesPlugin/FeaturesPlugin_Pipe.cpp | 8 ++- src/Model/Model_AttributeSelection.cpp | 4 ++ src/PartSet/PartSet_Filters.cpp | 3 +- 14 files changed, 180 insertions(+), 5 deletions(-) create mode 100644 src/CollectionPlugin/CollectionPlugin_GroupAddition.cpp create mode 100644 src/CollectionPlugin/CollectionPlugin_GroupAddition.h create mode 100644 src/CollectionPlugin/group_addition_widget.xml create mode 100644 src/CollectionPlugin/group_intersection_widget.xml create mode 100644 src/CollectionPlugin/group_substraction_widget.xml create mode 100644 src/CollectionPlugin/icons/group_addition.png create mode 100644 src/CollectionPlugin/icons/group_intersection.png create mode 100644 src/CollectionPlugin/icons/group_substraction.png diff --git a/src/CollectionPlugin/CMakeLists.txt b/src/CollectionPlugin/CMakeLists.txt index 2e2ff961d..921596cdd 100644 --- a/src/CollectionPlugin/CMakeLists.txt +++ b/src/CollectionPlugin/CMakeLists.txt @@ -31,6 +31,7 @@ SET(PROJECT_HEADERS CollectionPlugin.h CollectionPlugin_Plugin.h CollectionPlugin_Group.h + CollectionPlugin_GroupAddition.h CollectionPlugin_Field.h CollectionPlugin_WidgetCreator.h CollectionPlugin_WidgetField.h @@ -44,6 +45,7 @@ SET(PROJECT_MOC_HEADERS SET(PROJECT_SOURCES CollectionPlugin_Plugin.cpp CollectionPlugin_Group.cpp + CollectionPlugin_GroupAddition.cpp CollectionPlugin_Field.cpp CollectionPlugin_WidgetCreator.cpp CollectionPlugin_WidgetField.cpp @@ -53,6 +55,9 @@ SET(PROJECT_SOURCES SET(XML_RESOURCES plugin-Collection.xml group_widget.xml + group_addition_widget.xml + group_intersection_widget.xml + group_substraction_widget.xml ) SET(TEXT_RESOURCES diff --git a/src/CollectionPlugin/CollectionPlugin_GroupAddition.cpp b/src/CollectionPlugin/CollectionPlugin_GroupAddition.cpp new file mode 100644 index 000000000..1c3795dc3 --- /dev/null +++ b/src/CollectionPlugin/CollectionPlugin_GroupAddition.cpp @@ -0,0 +1,45 @@ +// Copyright (C) 2014-2019 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 "CollectionPlugin_GroupAddition.h" + +#include +#include +#include +#include +#include +#include + +CollectionPlugin_GroupAddition::CollectionPlugin_GroupAddition() +{ +} + +void CollectionPlugin_GroupAddition::initAttributes() +{ + data()->addAttribute(CollectionPlugin_Group::LIST_ID(), + ModelAPI_AttributeSelectionList::typeId()); +} + +void CollectionPlugin_GroupAddition::execute() +{ + if (results().empty() || firstResult()->isDisabled()) { // just create result if not exists + ResultPtr aGroup = document()->createGroup(data()); + setResult(aGroup); + } +} diff --git a/src/CollectionPlugin/CollectionPlugin_GroupAddition.h b/src/CollectionPlugin/CollectionPlugin_GroupAddition.h new file mode 100644 index 000000000..4de080a6e --- /dev/null +++ b/src/CollectionPlugin/CollectionPlugin_GroupAddition.h @@ -0,0 +1,67 @@ +// Copyright (C) 2014-2019 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 COLLECTIONPLUGIN_GROUPADDITION_H_ +#define COLLECTIONPLUGIN_GROUPADDITION_H_ + +#include "CollectionPlugin.h" +#include "CollectionPlugin_Group.h" + +/**\class CollectionPlugin_GroupAddition + * \ingroup Plugins + * \brief Merge several groups of same shape type into single group. + */ +class CollectionPlugin_GroupAddition : public CollectionPlugin_Group +{ + public: + /// Extrusion kind + inline static const std::string& ID() + { + static const std::string MY_GROUP_ID("GroupAddition"); + return MY_GROUP_ID; + } + /// attribute name of selected entities list + inline static const std::string& LIST_ID() + { + static const std::string MY_GROUP_LIST_ID("group_list"); + return MY_GROUP_LIST_ID; + } + + /// Returns the kind of a feature + COLLECTIONPLUGIN_EXPORT virtual const std::string& getKind() + { + static std::string MY_KIND = CollectionPlugin_Group::ID(); + return MY_KIND; + } + + /// Creates a new group result if needed + COLLECTIONPLUGIN_EXPORT virtual void execute(); + + /// Request for initialization of data model of the feature: adding all attributes + COLLECTIONPLUGIN_EXPORT virtual void initAttributes(); + + /// Result of groups is created on the fly and don't stored to the document + COLLECTIONPLUGIN_EXPORT virtual bool isPersistentResult() {return true;} + + /// Use plugin manager for features creation + CollectionPlugin_GroupAddition(); + +}; + +#endif diff --git a/src/CollectionPlugin/CollectionPlugin_Plugin.cpp b/src/CollectionPlugin/CollectionPlugin_Plugin.cpp index 7b0fc28e1..e55620606 100644 --- a/src/CollectionPlugin/CollectionPlugin_Plugin.cpp +++ b/src/CollectionPlugin/CollectionPlugin_Plugin.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -56,6 +57,8 @@ FeaturePtr CollectionPlugin_Plugin::createFeature(std::string theFeatureID) return FeaturePtr(new CollectionPlugin_Group); } else if (theFeatureID == CollectionPlugin_Field::ID()) { return FeaturePtr(new CollectionPlugin_Field); + } else if (theFeatureID == CollectionPlugin_GroupAddition::ID()) { + return FeaturePtr(new CollectionPlugin_GroupAddition); } // feature of such kind is not found diff --git a/src/CollectionPlugin/group_addition_widget.xml b/src/CollectionPlugin/group_addition_widget.xml new file mode 100644 index 000000000..5eab220ac --- /dev/null +++ b/src/CollectionPlugin/group_addition_widget.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/src/CollectionPlugin/group_intersection_widget.xml b/src/CollectionPlugin/group_intersection_widget.xml new file mode 100644 index 000000000..3a1f83feb --- /dev/null +++ b/src/CollectionPlugin/group_intersection_widget.xml @@ -0,0 +1,15 @@ + + + + + + + \ No newline at end of file diff --git a/src/CollectionPlugin/group_substraction_widget.xml b/src/CollectionPlugin/group_substraction_widget.xml new file mode 100644 index 000000000..3a1f83feb --- /dev/null +++ b/src/CollectionPlugin/group_substraction_widget.xml @@ -0,0 +1,15 @@ + + + + + + + \ No newline at end of file diff --git a/src/CollectionPlugin/icons/group_addition.png b/src/CollectionPlugin/icons/group_addition.png new file mode 100644 index 0000000000000000000000000000000000000000..6bc76e0013df328eb982feb1f90b774443f17342 GIT binary patch literal 362 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf2?p zUk71ECym(^Ktah8*NBqf{Irtt#G+J&^73-M%)IR4>q-B4O*xD_h1@0YGj^L1U5NKV{s(wMKX>Y3%iwM6$LluhBR5#?`&zHE;#aPm`j;{^ z(_U*Bw5`6f{MRz08TrZ6f3-dQ`0>M{i@j%44@#_?e08nX*Mxn&W$m@!f*5X{4Lfwz z`>6DfTMC^YCj1m;ZrF3i^+#-r(vtYU%FGQALbP0l+XkK D7k8A0 literal 0 HcmV?d00001 diff --git a/src/CollectionPlugin/icons/group_intersection.png b/src/CollectionPlugin/icons/group_intersection.png new file mode 100644 index 0000000000000000000000000000000000000000..aba074c2ebf9425ebaed57279c8d8612c3edc439 GIT binary patch literal 384 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf2?p zUk71ECym(^Ktah8*NBqf{Irtt#G+J&^73-M%)IR4R@_W7pGc&Vutd_8!sgBMWo;O=p_Uw5v>FnnJhj0G4 zvf+S5?&p91|NNf*P`u~AQ?XtCwIi(p!6wg*Q{)}5+FVuROtSEK@IJmRzSQ{N$Adp2 zg~k7U|NO;i`;h!2O8|9w+Qx1OVJjga_16!bpk->v+>deenZU!7U zbLK!>B7;uuVTaFe{?AYJ+^yOCQh3{$BL{%s({ug9{!iwxGuQt!`s0%JIEa~ne_q_` U9+#BKz<^-zboFyt=akR{0JyrKasU7T literal 0 HcmV?d00001 diff --git a/src/CollectionPlugin/icons/group_substraction.png b/src/CollectionPlugin/icons/group_substraction.png new file mode 100644 index 0000000000000000000000000000000000000000..7db75ec264792e4d7860c88cb769b2946f244682 GIT binary patch literal 369 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf2?p zUk71ECym(^Ktah8*NBqf{Irtt#G+J&^73-M%)IR4R@_W7pGc&Vutd_8!sgBMWo;O=p_Uw5v>FnnJhj0G4 zvf+S5?&p91|NNf*P`u~AQ?XtCwIi(p!6wg*Q{)}5+FVuROtSEK@IJmRzSQ{N$Adp2 zg~k7U|NO;i`; + + + + diff --git a/src/FeaturesPlugin/FeaturesPlugin_Pipe.cpp b/src/FeaturesPlugin/FeaturesPlugin_Pipe.cpp index c3a387887..f5a45f605 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Pipe.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Pipe.cpp @@ -18,6 +18,7 @@ // #include "FeaturesPlugin_Pipe.h" +#include "FeaturesPlugin_Tools.h" #include #include @@ -373,11 +374,12 @@ void FeaturesPlugin_Pipe::storeResult(const ListOfShape& theBaseShapes, aResultBody->loadGeneratedShapes(thePipeAlgo, thePathShape, GeomAPI_Shape::EDGE); // Store from shapes. - storeShapes(aResultBody, theBaseShapes.front()->shapeType(), thePipeAlgo->fromShapes(), "From_"); + FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, thePipeAlgo->fromShapes(), ListOfShape(), + thePipeAlgo, thePipeAlgo->shape(), "From"); // Store to shapes. - storeShapes(aResultBody, theBaseShapes.back()->shapeType(), thePipeAlgo->toShapes(), "To_"); - + FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, thePipeAlgo->toShapes(), ListOfShape(), + thePipeAlgo, thePipeAlgo->shape(), "To"); setResult(aResultBody, theResultIndex); } diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index e9c92ad53..26b45f7c8 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -180,6 +181,9 @@ bool Model_AttributeSelection::setValue(const ObjectPtr& theContext, aSelLab.ForgetAllAttributes(true); TDataStd_UAttribute::Set(aSelLab, kPART_REF_ID); selectPart(std::dynamic_pointer_cast(theContext), theSubShape); + } else if (theContext->groupName() == ModelAPI_ResultGroup::group()) { + aSelLab.ForgetAllAttributes(true); + TDataStd_UAttribute::Set(aSelLab, kSIMPLE_REF_ID); } else { // check the feature context: parent-Part of this feature should not be used FeaturePtr aFeatureContext = std::dynamic_pointer_cast(theContext); if (aFeatureContext.get()) { diff --git a/src/PartSet/PartSet_Filters.cpp b/src/PartSet/PartSet_Filters.cpp index b7e5ccbb1..582161ace 100644 --- a/src/PartSet/PartSet_Filters.cpp +++ b/src/PartSet/PartSet_Filters.cpp @@ -63,8 +63,7 @@ Standard_Boolean PartSet_GlobalFilter::IsOk(const Handle(SelectMgr_EntityOwner)& if (aResultGroupName == ModelAPI_ResultPart::group()) { SessionPtr aMgr = ModelAPI_Session::get(); aValid = aMgr->activeDocument() == aMgr->moduleDocument(); - } else if (aResultGroupName == ModelAPI_ResultGroup::group() || - aResultGroupName == ModelAPI_ResultField::group()) { + } else if (aResultGroupName == ModelAPI_ResultField::group()) { aValid = Standard_False; } else aValid = Standard_True; -- 2.39.2