//********************************************************************
bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
{
- const TopoDS_Shape& aTDSShape = thePrs.shape();
- if (aTDSShape.IsNull())
- return false;
- GeomShapePtr aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
- aShape->setImpl(new TopoDS_Shape(aTDSShape));
-
ObjectPtr anObject = myWorkshop->selection()->getSelectableObject(thePrs.owner());
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+
if (myFeature) {
// We can not select a result of our feature
const std::list<ResultPtr>& aResList = myFeature->results();
DataPtr aData = myFeature->data();
AttributeSelectionListPtr aSelectionListAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(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<GeomAPI_Shape>(new GeomAPI_Shape());
+ aShape->setImpl(new TopoDS_Shape(aTDSShape));
aSelectionListAttr->append(aResult, aShape);
-
+ }
return true;
}
//********************************************************************
void ModuleBase_WidgetMultiSelector::onSelectionChanged()
{
- QList<ModuleBase_ViewerPrs> aSelected = myWorkshop->selection()->getSelected();
+ QList<ModuleBase_ViewerPrs> aSelected = getSelectedEntitiesOrObjects(myWorkshop->selection());
DataPtr aData = myFeature->data();
AttributeSelectionListPtr aSelectionListAttr =
// In order to make reselection possible
// TODO: check with MPV clearAttribute();
- //QObjectPtrList aObjects = myWorkshop->selection()->selectedPresentations();
- QList<ModuleBase_ViewerPrs> 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<ModuleBase_ViewerPrs> 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);
}
+
}
//********************************************************************
#include <ModuleBase_WidgetValidated.h>
#include <ModuleBase_FilterFactory.h>
#include <ModuleBase_IViewer.h>
+#include <ModuleBase_ISelection.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
else
aViewer->removeSelectionFilter(aSelFilter);
}
+
+QList<ModuleBase_ViewerPrs> ModuleBase_WidgetValidated::getSelectedEntitiesOrObjects(
+ ModuleBase_ISelection* theSelection) const
+{
+ QList<ModuleBase_ViewerPrs> 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;
+}
class QWidget;
class ModuleBase_IWorkshop;
+class ModuleBase_ISelection;
class Config_WidgetAPI;
class Handle_SelectMgr_EntityOwner;
/// \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<ModuleBase_ViewerPrs> getSelectedEntitiesOrObjects(ModuleBase_ISelection* theSelection) const;
+
};
#endif /* MODULEBASE_WIDGETVALIDATED_H_ */
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<ModuleBase_ViewerPrs> 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<ModuleBase_ViewerPrs> 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