From 9ef2d81a8b97eee85d6506d95f2481fe7fae1e56 Mon Sep 17 00:00:00 2001 From: vsv Date: Fri, 28 Nov 2014 19:23:29 +0300 Subject: [PATCH] Provide selection only in plane of sketcher --- src/ModuleBase/ModuleBase_ViewerFilters.h | 6 ++++-- src/PartSet/PartSet_Module.cpp | 17 +++++++++++++++++ src/PartSet/PartSet_Module.h | 4 ++++ src/PartSet/PartSet_WidgetSketchLabel.cpp | 3 +++ src/PartSet/PartSet_WidgetSketchLabel.h | 3 +++ src/XGUI/XGUI_Displayer.cpp | 7 +++++++ 6 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/ModuleBase/ModuleBase_ViewerFilters.h b/src/ModuleBase/ModuleBase_ViewerFilters.h index e4aa93ae2..4860776f4 100644 --- a/src/ModuleBase/ModuleBase_ViewerFilters.h +++ b/src/ModuleBase/ModuleBase_ViewerFilters.h @@ -44,8 +44,10 @@ DEFINE_STANDARD_HANDLE(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter); class ModuleBase_ShapeInPlaneFilter: public SelectMgr_Filter { public: - Standard_EXPORT ModuleBase_ShapeInPlaneFilter(const gp_Pln& thePane): - SelectMgr_Filter(), myPlane(thePane) {} + Standard_EXPORT ModuleBase_ShapeInPlaneFilter(): SelectMgr_Filter() {} + + void setPlane(const gp_Pln& thePane) { myPlane = thePane; } + gp_Pln plane() const { return myPlane; } Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const; diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 9ced217aa..2f4fbb47a 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -159,6 +159,16 @@ void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation) aDisplayer->erase((*aIt), false); } aDisplayer->erase(myCurrentSketch); + + + if (myPlaneFilter.IsNull()) + myPlaneFilter = new ModuleBase_ShapeInPlaneFilter(); + myWorkshop->viewer()->addSelectionFilter(myPlaneFilter); + if (theOperation->isEditOperation()) { + // If it is editing of sketch then it means that plane is already defined + std::shared_ptr aPln = PartSet_Tools::sketchPlane(myCurrentSketch); + myPlaneFilter->setPlane(aPln->impl()); + } } } @@ -192,9 +202,14 @@ void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation) aDisplayer->display(myCurrentSketch); myCurrentSketch = CompositeFeaturePtr(); + myWorkshop->viewer()->removeSelectionFilter(myPlaneFilter); } } +void PartSet_Module::onPlaneSelected(const std::shared_ptr& thePln) +{ + myPlaneFilter->setPlane(thePln->impl()); +} void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation) @@ -409,6 +424,8 @@ QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* if (theType == "sketch-start-label") { PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId); aWgt->setWorkshop(aWorkshop); + connect(aWgt, SIGNAL(planeSelected(const std::shared_ptr&)), + this, SLOT(onPlaneSelected(const std::shared_ptr&))); theModelWidgets.append(aWgt); return aWgt->getControl(); diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 7c90584b8..305cd88e7 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -82,6 +82,8 @@ protected slots: private slots: void onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape); + void onPlaneSelected(const std::shared_ptr& thePln); + private: /// Converts mouse position to 2d coordinates. /// Member myCurrentSketch has to be correctly defined @@ -104,6 +106,8 @@ protected slots: double myCurX, myCurY; CompositeFeaturePtr myCurrentSketch; QList myEditingFeatures; + + Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter; }; #endif diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index a76691881..37cd83445 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -104,7 +104,10 @@ void PartSet_WidgetSketchLabel::onPlaneSelected() XGUI_Displayer* aDisp = myWorkshop->displayer(); aDisp->removeSelectionFilter(myPlaneFilter); aDisp->closeLocalContexts(); + emit planeSelected(plane()); setSketchingMode(); + + // Update sketcher actions XGUI_ActionsMgr* anActMgr = myWorkshop->actionsMgr(); anActMgr->update(); } diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index 7c1d460be..906e96295 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -61,6 +61,9 @@ Q_OBJECT std::shared_ptr plane() const; +signals: + void planeSelected(const std::shared_ptr& thePln); + private slots: void onPlaneSelected(); diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 74041948e..0ebba5866 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -328,6 +328,9 @@ void XGUI_Displayer::openLocalContext() //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent()) // aAisList.Append(aContext->Current()); + SelectMgr_ListOfFilter aFilters; + aFilters.Assign(aContext->Filters()); + aContext->ClearCurrents(); aContext->OpenLocalContext(); aContext->NotUseDisplayedObjects(); @@ -335,6 +338,10 @@ void XGUI_Displayer::openLocalContext() myUseExternalObjects = false; myActiveSelectionModes.clear(); + SelectMgr_ListIteratorOfListOfFilter aIt(aFilters); + for (;aIt.More(); aIt.Next()) { + aContext->AddFilter(aIt.Value()); + } // Restore selection //AIS_ListIteratorOfListOfInteractive aIt(aAisList); //for(; aIt.More(); aIt.Next()) { -- 2.39.2