From a94eeab620f6c2a559f5fea9b7d638423d010e62 Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 16 Jun 2015 12:22:33 +0300 Subject: [PATCH] Preselection using in operations --- src/ModuleBase/ModuleBase_ISelection.h | 4 +- src/ModuleBase/ModuleBase_Operation.cpp | 4 +- .../ModuleBase_WidgetMultiSelector.cpp | 2 +- .../ModuleBase_WidgetShapeSelector.cpp | 2 +- src/ModuleBase/ModuleBase_WidgetSwitch.h | 4 ++ src/ModuleBase/ModuleBase_WidgetValidated.cpp | 16 ----- src/ModuleBase/ModuleBase_WidgetValidated.h | 10 ---- src/PartSet/PartSet_WidgetSketchLabel.cpp | 4 +- src/XGUI/XGUI_Selection.cpp | 60 ++++++++++++------- src/XGUI/XGUI_Selection.h | 15 ++++- src/XGUI/XGUI_SelectionMgr.cpp | 8 ++- 11 files changed, 71 insertions(+), 58 deletions(-) diff --git a/src/ModuleBase/ModuleBase_ISelection.h b/src/ModuleBase/ModuleBase_ISelection.h index e6a92d558..0f653f631 100644 --- a/src/ModuleBase/ModuleBase_ISelection.h +++ b/src/ModuleBase/ModuleBase_ISelection.h @@ -31,10 +31,12 @@ class Handle_SelectMgr_EntityOwner; class ModuleBase_ISelection { public: + /// Types of the selection place, where the selection is obtained + enum SelectionPlace { Browser, Viewer, AllControls }; /// Returns a list of viewer selected presentations /// \return list of presentations - virtual QList getSelected() const = 0; + virtual QList getSelected(const SelectionPlace& thePlace = Browser) const = 0; /// Returns a list of viewer highlited presentations /// \return list of presentations diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 7722b9ee7..492637ba5 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -333,7 +333,7 @@ void ModuleBase_Operation::initSelection(ModuleBase_ISelection* theSelection, // Check that the selected result are not results of operation feature FeaturePtr aFeature = feature(); if (aFeature) { - QList aSelected = theSelection->getSelected(); + QList aSelected = theSelection->getSelected(ModuleBase_ISelection::AllControls); std::list aResults = aFeature->results(); QObjectPtrList aResList; @@ -346,7 +346,7 @@ void ModuleBase_Operation::initSelection(ModuleBase_ISelection* theSelection, aPreSelected.append(aPrs); } } else - aPreSelected = theSelection->getSelected(); + aPreSelected = theSelection->getSelected(ModuleBase_ISelection::AllControls); // convert the selection values to the values, which are set to the operation widgets diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 18b88a145..6f413e634 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -406,7 +406,7 @@ void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged() //******************************************************************** void ModuleBase_WidgetMultiSelector::onSelectionChanged() { - QList aSelected = getSelectedEntitiesOrObjects(myWorkshop->selection()); + QList aSelected = myWorkshop->selection()->getSelected(ModuleBase_ISelection::AllControls); DataPtr aData = myFeature->data(); AttributeSelectionListPtr aSelectionListAttr = diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 34666e3b8..457a9f6ff 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -215,7 +215,7 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged() setObject(ObjectPtr(), std::shared_ptr(new GeomAPI_Shape())); bool aHasObject = false; - QList aSelectedPrs = getSelectedEntitiesOrObjects(myWorkshop->selection()); + QList aSelectedPrs = myWorkshop->selection()->getSelected(ModuleBase_ISelection::AllControls); if (!aSelectedPrs.empty()) { ModuleBase_ViewerPrs aPrs = aSelectedPrs.first(); if (!aPrs.isEmpty() && isValidSelection(aPrs)) { diff --git a/src/ModuleBase/ModuleBase_WidgetSwitch.h b/src/ModuleBase/ModuleBase_WidgetSwitch.h index 5772a3d08..aafb6224f 100644 --- a/src/ModuleBase/ModuleBase_WidgetSwitch.h +++ b/src/ModuleBase/ModuleBase_WidgetSwitch.h @@ -31,6 +31,10 @@ class MODULEBASE_EXPORT ModuleBase_WidgetSwitch : public ModuleBase_PagedContain const std::string& theParentId); virtual ~ModuleBase_WidgetSwitch(); + /// Defines if it is supported to set the value in this widget + /// It returns false because this is an info widget + virtual bool canSetValue() const { return false; }; + /// Add a page to the widget /// \param theWidget a page widget /// \param theName a name of page diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index 6caa7de0b..b329e36c9 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -140,19 +140,3 @@ void ModuleBase_WidgetValidated::customValidators(std::list std::list >& theArguments) const { } - -QList ModuleBase_WidgetValidated::getSelectedEntitiesOrObjects( - ModuleBase_ISelection* theSelection) const -{ - QList aSelectedPrs; - - // find selected presentation either in the viewer or in OB - // the selection in OCC viewer - the selection of a sub-shapes in the viewer - aSelectedPrs = theSelection->getSelected(); - if (aSelectedPrs.empty()) { - // the selection in Object Browser - QObjectPtrList anObjects = theSelection->selectedObjects(); - aSelectedPrs = ModuleBase_ISelection::getViewerPrs(anObjects); - } - return aSelectedPrs; -} diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.h b/src/ModuleBase/ModuleBase_WidgetValidated.h index 5c4f319dc..e13fb166f 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.h +++ b/src/ModuleBase/ModuleBase_WidgetValidated.h @@ -90,16 +90,6 @@ protected: /// \param theArguments a list of validators arguments virtual void customValidators(std::list& theValidators, std::list >& theArguments) const; - - /// Returns a list of selected presentations. Firstly it is obtained from the viewer, - /// if there are not selected objects in the viewer, it get the selection from the object browser. - /// If the browser has selected objects, the viewer prs objects are created with only object - /// field of the presentation initialized. The widget should accept the selection in the object - /// browser at the same way as in the viewer. - /// \param theSelection a selection, where the selected objects and presentations are found - /// \return a list of presentations - QList getSelectedEntitiesOrObjects(ModuleBase_ISelection* theSelection) const; - }; #endif /* MODULEBASE_WIDGETVALIDATED_H_ */ diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 0d1b2bd2c..e72f1bff5 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -101,8 +101,8 @@ QList PartSet_WidgetSketchLabel::getControls() const void PartSet_WidgetSketchLabel::onSelectionChanged() { - QList aSelectedPrs = getSelectedEntitiesOrObjects( - myWorkshop->selector()->selection()); + QList aSelectedPrs = myWorkshop->selector()->selection()->getSelected( + ModuleBase_ISelection::AllControls); if (aSelectedPrs.empty()) return; ModuleBase_ViewerPrs aPrs = aSelectedPrs.first(); diff --git a/src/XGUI/XGUI_Selection.cpp b/src/XGUI/XGUI_Selection.cpp index ea99308aa..8a14e7d18 100644 --- a/src/XGUI/XGUI_Selection.cpp +++ b/src/XGUI/XGUI_Selection.cpp @@ -24,18 +24,33 @@ XGUI_Selection::XGUI_Selection(XGUI_Workshop* theWorkshop) { } -QList XGUI_Selection::getSelected() const +QList XGUI_Selection::getSelected(const SelectionPlace& thePlace) const { - QList aSelectedIds; // Remember of selected address in order to avoid duplicates - QList aPresentations; - XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + switch (thePlace) { + case Browser: + getSelectedInBrowser(aPresentations); + break; + case Viewer: + getSelectedInViewer(aPresentations); + break; + case AllControls: + getSelectedInViewer(aPresentations); + getSelectedInBrowser(aPresentations); + break; + } + return aPresentations; +} + +void XGUI_Selection::getSelectedInViewer(QList& thePresentations) const +{ Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); if (aContext.IsNull()) - return aPresentations; + return; if (aContext->HasOpenedContext()) { + QList aSelectedIds; // Remember of selected address in order to avoid duplicates for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { ModuleBase_ViewerPrs aPrs; Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner(); @@ -46,25 +61,30 @@ QList XGUI_Selection::getSelected() const fillPresentation(aPrs, anOwner); - aPresentations.append(aPrs); + if (!thePresentations.contains(aPrs)) // TODO: check whether the presentation in a list + thePresentations.append(aPrs); } } - /* else { - for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent()) { - ModuleBase_ViewerPrs aPrs; - Handle(AIS_InteractiveObject) anIO = aContext->Current(); - if (aSelectedIds.contains((long)anIO.Access())) - continue; - - aSelectedIds.append((long)anIO.Access()); - aPrs.setInteractive(anIO); +} - ObjectPtr aFeature = aDisplayer->getObject(anIO); - aPrs.setFeature(aFeature); - aPresentations.append(aPrs); +void XGUI_Selection::getSelectedInBrowser(QList& thePresentations) const +{ + // collect the objects of the parameter presentation to avoid a repeted objects in the result + QObjectPtrList aPresentationObjects; + QList::const_iterator aPrsIt = thePresentations.begin(), + aPrsLast = thePresentations.end(); + for (; aPrsIt != aPrsLast; aPrsIt++) { + aPresentationObjects.push_back((*aPrsIt).object()); + } + + QObjectPtrList anObjects = selectedObjects(); + QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end(); + for (; anIt != aLast; anIt++) { + ObjectPtr anObject = *anIt; + if (anObject.get() != NULL && !aPresentationObjects.contains(anObject)) { + thePresentations.append(ModuleBase_ViewerPrs(anObject, TopoDS_Shape(), NULL)); } - }*/ - return aPresentations; + } } void XGUI_Selection::fillPresentation(ModuleBase_ViewerPrs& thePrs, diff --git a/src/XGUI/XGUI_Selection.h b/src/XGUI/XGUI_Selection.h index ea5886a8a..caf1088f7 100644 --- a/src/XGUI/XGUI_Selection.h +++ b/src/XGUI/XGUI_Selection.h @@ -36,7 +36,7 @@ class XGUI_EXPORT XGUI_Selection : public ModuleBase_ISelection /// Returns a list of viewer selected presentations /// \return list of presentations - virtual QList getSelected() const; + virtual QList getSelected(const SelectionPlace& thePlace = Browser) const; /// Fills the viewer presentation parameters by the parameters from the owner /// \param thePrs a container for selection @@ -88,7 +88,18 @@ class XGUI_EXPORT XGUI_Selection : public ModuleBase_ISelection void entityOwners(const Handle_AIS_InteractiveObject& theObject, SelectMgr_IndexedMapOfOwner& theOwners) const; - private: +protected: + /// Fills the list of presentations by objects selected in the viewer. + /// \param thePresentations an output list of presentation + void getSelectedInViewer(QList& thePresentations) const; + /// Fills the list of presentations by objects selected in the object browser. + /// ViewerPrs contains only object parameter not empty. + /// If the given list of presentations already has a viewer presentation with the same object + /// as selected in the browser, a new item is not appended to the list of presentations. + /// \param thePresentations an output list of presentation + void getSelectedInBrowser(QList& thePresentations) const; + +private: XGUI_Workshop* myWorkshop; }; diff --git a/src/XGUI/XGUI_SelectionMgr.cpp b/src/XGUI/XGUI_SelectionMgr.cpp index 517f24866..05c86e20e 100644 --- a/src/XGUI/XGUI_SelectionMgr.cpp +++ b/src/XGUI/XGUI_SelectionMgr.cpp @@ -86,8 +86,8 @@ void XGUI_SelectionMgr::updateSelectedOwners(bool isUpdateViewer) //************************************************************** void XGUI_SelectionMgr::onObjectBrowserSelection() { - QObjectPtrList aObjects = myWorkshop->objectBrowser()->selectedObjects(); - QList aSelectedPrs = ModuleBase_ISelection::getViewerPrs(aObjects); + QList aSelectedPrs = + myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser); XGUI_Displayer* aDisplayer = myWorkshop->displayer(); aDisplayer->setSelected(aSelectedPrs); @@ -119,7 +119,9 @@ void XGUI_SelectionMgr::clearSelection() bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true); myWorkshop->objectBrowser()->setObjectsSelected(aFeatures); myWorkshop->objectBrowser()->blockSignals(aBlocked); - QList aSelectedPrs = ModuleBase_ISelection::getViewerPrs(aFeatures); + + QList aSelectedPrs = + myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser); XGUI_Displayer* aDisplayer = myWorkshop->displayer(); aDisplayer->setSelected(aSelectedPrs); -- 2.39.2