From 83125ac0d43cd4bb99b9f4b256d21e7ea267b4e0 Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 16 Dec 2019 19:09:21 +0300 Subject: [PATCH] Issue #18429: Provide selection of external objects for angle constraint. --- .../PartSet_WidgetFeaturePointSelector.cpp | 43 +++++++++++++++++-- .../PartSet_WidgetFeaturePointSelector.h | 17 +++++++- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/PartSet/PartSet_WidgetFeaturePointSelector.cpp b/src/PartSet/PartSet_WidgetFeaturePointSelector.cpp index 7b5aff07d..173e14627 100644 --- a/src/PartSet/PartSet_WidgetFeaturePointSelector.cpp +++ b/src/PartSet/PartSet_WidgetFeaturePointSelector.cpp @@ -17,6 +17,10 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +#include "PartSet_WidgetFeaturePointSelector.h" +#include "PartSet_Tools.h" +#include "PartSet_ExternalObjectsMgr.h" + #include #include @@ -40,9 +44,6 @@ #include #include -#include "PartSet_WidgetFeaturePointSelector.h" -#include "PartSet_Tools.h" - #include #include @@ -75,10 +76,13 @@ PartSet_WidgetFeaturePointSelector::PartSet_WidgetFeaturePointSelector(QWidget* myPreviewObjectAttribute = anAttributesList[2].toStdString(); myPreviewPointAttribute = anAttributesList[3].toStdString(); } + myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"), + theData->getProperty("can_create_external"), true); } PartSet_WidgetFeaturePointSelector::~PartSet_WidgetFeaturePointSelector() { + delete myExternalObjectMgr; } //******************************************************************** @@ -155,6 +159,19 @@ void PartSet_WidgetFeaturePointSelector::mouseReleased(ModuleBase_IViewWindow* t if (theEvent->button() != Qt::LeftButton) return; + ModuleBase_ISelection* aSelection = myWorkshop->selection(); + QList aSelected = aSelection->getSelected(ModuleBase_ISelection::Viewer); + + ModuleBase_ViewerPrsPtr aPrs = + !aSelected.empty() ? aSelected.first() : ModuleBase_ViewerPrsPtr(); + if (aPrs.get() && aPrs->object().get()) { + myPreviewObject = aSelection->getResult(aPrs); + GeomShapePtr aShape = aSelection->getShape(aPrs); + myExternalObjectMgr->getGeomSelection(aPrs, myPreviewObject, aShape, + myWorkshop, sketch(), true); + } + myPreviewPoint = PartSet_Tools::getPnt2d(theEvent, theWindow, mySketch); + ObjectPtr aPreviewObject; GeomPnt2dPtr aPreviewPoint; if (myHasPreview) { @@ -261,3 +278,23 @@ void PartSet_WidgetFeaturePointSelector::setPreSelection( // sub-segments in the viewer, secondly preselection of restart operation is processed by // special reentrant message sent by the feature } + +//******************************************************************** +void PartSet_WidgetFeaturePointSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs, + ObjectPtr& theObject, GeomShapePtr& theShape) +{ + ModuleBase_WidgetShapeSelector::getGeomSelection(thePrs, theObject, theShape); + + myExternalObjectMgr->getGeomSelection(thePrs, theObject, theShape, + myWorkshop, sketch(), myIsInValidate); + myPreviewObject = theObject; +} + +//******************************************************************** +void PartSet_WidgetFeaturePointSelector::restoreAttributeValue(const AttributePtr& theAttribute, + const bool theValid) +{ + ModuleBase_WidgetShapeSelector::restoreAttributeValue(theAttribute, theValid); + myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true); + myPreviewObject = ObjectPtr(); +} diff --git a/src/PartSet/PartSet_WidgetFeaturePointSelector.h b/src/PartSet/PartSet_WidgetFeaturePointSelector.h index 972b30ede..445303133 100644 --- a/src/PartSet/PartSet_WidgetFeaturePointSelector.h +++ b/src/PartSet/PartSet_WidgetFeaturePointSelector.h @@ -36,6 +36,7 @@ class ModuleBase_IWorkshop; class Config_WidgetAPI; class ModuleBase_IViewWindow; class ModuleBase_ViewerPrs; +class PartSet_ExternalObjectsMgr; class GeomAPI_Pnt; class GeomAPI_Pnt2d; @@ -115,10 +116,23 @@ protected: /// a shape. If the attribute do not uses the shape, it is empty virtual QList> getAttributeSelection() const; -protected: /// The methiod called when widget is activated virtual void activateCustom(); + /// Return an object and geom shape by the viewer presentation + /// \param thePrs a selection + /// \param theObject an output object + /// \param theShape a shape of the selection + virtual void getGeomSelection(const std::shared_ptr& thePrs, + ObjectPtr& theObject, GeomShapePtr& theShape); + + /// Creates a backup of the current values of the attribute + /// It should be realized in the specific widget because of different + /// parameters of the current attribute + /// \param theAttribute an attribute + /// \param theValid a boolean flag, if restore happens for valid parameters + void restoreAttributeValue(const AttributePtr& theAttribute, const bool theValid); + protected: bool fillFeature(const std::shared_ptr& theSelectedPrs, ModuleBase_IViewWindow* theWnd, @@ -137,6 +151,7 @@ protected: bool myHasPreview; std::shared_ptr myPreviewObject; std::shared_ptr myPreviewPoint; + PartSet_ExternalObjectsMgr* myExternalObjectMgr; ///< reference to external objects manager }; #endif \ No newline at end of file -- 2.39.2