From: nds Date: Mon, 13 Apr 2015 10:26:21 +0000 (+0300) Subject: The OB selection use in selection controls X-Git-Tag: V_1.1.0~38^2~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a64f7a3f4535a429d27fbc298c323c96060370cf;p=modules%2Fshaper.git The OB selection use in selection controls --- diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 6ae74c061..d1b383dd2 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -198,14 +198,9 @@ void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/) //******************************************************************** bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) { - const TopoDS_Shape& aTDSShape = thePrs.shape(); - if (aTDSShape.IsNull()) - return false; - GeomShapePtr aShape = std::shared_ptr(new GeomAPI_Shape()); - aShape->setImpl(new TopoDS_Shape(aTDSShape)); - ObjectPtr anObject = myWorkshop->selection()->getSelectableObject(thePrs.owner()); ResultPtr aResult = std::dynamic_pointer_cast(anObject); + if (myFeature) { // We can not select a result of our feature const std::list& aResList = myFeature->results(); @@ -226,11 +221,17 @@ bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerP DataPtr aData = myFeature->data(); AttributeSelectionListPtr aSelectionListAttr = std::dynamic_pointer_cast(aData->attribute(attributeID())); - if (aShape->isEqual(aResult->shape())) + + const TopoDS_Shape& aTDSShape = thePrs.shape(); + // if only result is selected, an empty shape is set to the model + if (aTDSShape.IsNull()) { aSelectionListAttr->append(aResult, GeomShapePtr()); - else + } + else { + GeomShapePtr aShape = std::shared_ptr(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(aTDSShape)); aSelectionListAttr->append(aResult, aShape); - + } return true; } @@ -263,7 +264,7 @@ void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged() //******************************************************************** void ModuleBase_WidgetMultiSelector::onSelectionChanged() { - QList aSelected = myWorkshop->selection()->getSelected(); + QList aSelected = getSelectedEntitiesOrObjects(myWorkshop->selection()); DataPtr aData = myFeature->data(); AttributeSelectionListPtr aSelectionListAttr = diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index fcd1e26c2..de8e013d4 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -212,22 +212,26 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged() // In order to make reselection possible // TODO: check with MPV clearAttribute(); - //QObjectPtrList aObjects = myWorkshop->selection()->selectedPresentations(); - QList aSelected = myWorkshop->selection()->getSelected(); - if (aSelected.size() > 0) { - if (isValidSelection(aSelected.first())) { - setSelectionCustom(aSelected.first()); - // the updateObject method should be called to flush the updated sigal. The workshop listens it, - // calls validators for the feature and, as a result, updates the Apply button state. - updateObject(myFeature); - //if (theObj) { - // raisePanel(); - //} - //updateSelectionName(); - //emit valuesChanged(); - emit focusOutWidget(this); - } + QList aSelectedPrs = getSelectedEntitiesOrObjects(myWorkshop->selection()); + if (aSelectedPrs.empty()) + return; + ModuleBase_ViewerPrs aPrs = aSelectedPrs.first(); + if (aPrs.isEmpty() || !isValidSelection(aPrs)) + return; + + if (!aPrs.isEmpty() && isValidSelection(aPrs)) { + setSelectionCustom(aPrs); + // the updateObject method should be called to flush the updated sigal. The workshop listens it, + // calls validators for the feature and, as a result, updates the Apply button state. + updateObject(myFeature); + //if (theObj) { + // raisePanel(); + //} + //updateSelectionName(); + //emit valuesChanged(); + emit focusOutWidget(this); } + } //******************************************************************** diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index 0c84fa8e9..4db4e4bbc 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -107,3 +108,25 @@ void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorksh else aViewer->removeSelectionFilter(aSelFilter); } + +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(); + QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end(); + for (; anIt != aLast; anIt++) { + ObjectPtr anObject = *anIt; + if (anObject.get() != NULL) { + aSelectedPrs.append(ModuleBase_ViewerPrs(anObject, TopoDS_Shape(), NULL)); + } + } + } + return aSelectedPrs; +} diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.h b/src/ModuleBase/ModuleBase_WidgetValidated.h index eb0f8fa7f..8c05cbb04 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.h +++ b/src/ModuleBase/ModuleBase_WidgetValidated.h @@ -18,6 +18,7 @@ class QWidget; class ModuleBase_IWorkshop; +class ModuleBase_ISelection; class Config_WidgetAPI; class Handle_SelectMgr_EntityOwner; @@ -76,6 +77,16 @@ protected: /// \param theWorkshop an active workshop /// \param toActivate a flag about activation or deactivation the filters virtual void activateFilters(ModuleBase_IWorkshop* theWorkshop, const bool toActivate) 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 2bf6d00aa..239aeb75a 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -94,26 +94,12 @@ QList PartSet_WidgetSketchLabel::getControls() const void PartSet_WidgetSketchLabel::onSelectionChanged() { - ModuleBase_ViewerPrs aPrs; - // 1. find selected presentation either in the viewer or in OB - XGUI_Selection* aSelection = myWorkshop->selector()->selection(); - QList aSelected = aSelection->getSelected(); - // the selection in OCC viewer - the selection of a face in the viewer - // it can be th main plane's face of a face on a visualized body - if (!aSelected.empty()) { - aPrs = aSelected.first(); - } - else { - // the selection in Object Browser: the plane object can be used as sketch plane - QObjectPtrList anObjects = aSelection->selectedObjects(); - if (!anObjects.empty()) { - aPrs.setObject(anObjects.first()); - } - } - if (aPrs.isEmpty()) + QList aSelectedPrs = getSelectedEntitiesOrObjects( + myWorkshop->selector()->selection()); + if (aSelectedPrs.empty()) return; - - if (!isValidSelection(aPrs)) + ModuleBase_ViewerPrs aPrs = aSelectedPrs.first(); + if (aPrs.isEmpty() || !isValidSelection(aPrs)) return; // 2. set the selection to sketch