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<ModuleBase_ViewerPrs> getSelected() const = 0;
+ virtual QList<ModuleBase_ViewerPrs> getSelected(const SelectionPlace& thePlace = Browser) const = 0;
/// Returns a list of viewer highlited presentations
/// \return list of presentations
// Check that the selected result are not results of operation feature
FeaturePtr aFeature = feature();
if (aFeature) {
- QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
+ QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected(ModuleBase_ISelection::AllControls);
std::list<ResultPtr> aResults = aFeature->results();
QObjectPtrList aResList;
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
//********************************************************************
void ModuleBase_WidgetMultiSelector::onSelectionChanged()
{
- QList<ModuleBase_ViewerPrs> aSelected = getSelectedEntitiesOrObjects(myWorkshop->selection());
+ QList<ModuleBase_ViewerPrs> aSelected = myWorkshop->selection()->getSelected(ModuleBase_ISelection::AllControls);
DataPtr aData = myFeature->data();
AttributeSelectionListPtr aSelectionListAttr =
setObject(ObjectPtr(), std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape()));
bool aHasObject = false;
- QList<ModuleBase_ViewerPrs> aSelectedPrs = getSelectedEntitiesOrObjects(myWorkshop->selection());
+ QList<ModuleBase_ViewerPrs> aSelectedPrs = myWorkshop->selection()->getSelected(ModuleBase_ISelection::AllControls);
if (!aSelectedPrs.empty()) {
ModuleBase_ViewerPrs aPrs = aSelectedPrs.first();
if (!aPrs.isEmpty() && isValidSelection(aPrs)) {
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
std::list<std::list<std::string> >& theArguments) const
{
}
-
-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();
- aSelectedPrs = ModuleBase_ISelection::getViewerPrs(anObjects);
- }
- return aSelectedPrs;
-}
/// \param theArguments a list of validators arguments
virtual void customValidators(std::list<ModelAPI_Validator*>& theValidators,
std::list<std::list<std::string> >& 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<ModuleBase_ViewerPrs> getSelectedEntitiesOrObjects(ModuleBase_ISelection* theSelection) const;
-
};
#endif /* MODULEBASE_WIDGETVALIDATED_H_ */
void PartSet_WidgetSketchLabel::onSelectionChanged()
{
- QList<ModuleBase_ViewerPrs> aSelectedPrs = getSelectedEntitiesOrObjects(
- myWorkshop->selector()->selection());
+ QList<ModuleBase_ViewerPrs> aSelectedPrs = myWorkshop->selector()->selection()->getSelected(
+ ModuleBase_ISelection::AllControls);
if (aSelectedPrs.empty())
return;
ModuleBase_ViewerPrs aPrs = aSelectedPrs.first();
{
}
-QList<ModuleBase_ViewerPrs> XGUI_Selection::getSelected() const
+QList<ModuleBase_ViewerPrs> XGUI_Selection::getSelected(const SelectionPlace& thePlace) const
{
- QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
-
QList<ModuleBase_ViewerPrs> 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<ModuleBase_ViewerPrs>& thePresentations) const
+{
Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
if (aContext.IsNull())
- return aPresentations;
+ return;
if (aContext->HasOpenedContext()) {
+ QList<long> 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();
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<ModuleBase_ViewerPrs>& thePresentations) const
+{
+ // collect the objects of the parameter presentation to avoid a repeted objects in the result
+ QObjectPtrList aPresentationObjects;
+ QList<ModuleBase_ViewerPrs>::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,
/// Returns a list of viewer selected presentations
/// \return list of presentations
- virtual QList<ModuleBase_ViewerPrs> getSelected() const;
+ virtual QList<ModuleBase_ViewerPrs> getSelected(const SelectionPlace& thePlace = Browser) const;
/// Fills the viewer presentation parameters by the parameters from the owner
/// \param thePrs a container for selection
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<ModuleBase_ViewerPrs>& 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<ModuleBase_ViewerPrs>& thePresentations) const;
+
+private:
XGUI_Workshop* myWorkshop;
};
//**************************************************************
void XGUI_SelectionMgr::onObjectBrowserSelection()
{
- QObjectPtrList aObjects = myWorkshop->objectBrowser()->selectedObjects();
- QList<ModuleBase_ViewerPrs> aSelectedPrs = ModuleBase_ISelection::getViewerPrs(aObjects);
+ QList<ModuleBase_ViewerPrs> aSelectedPrs =
+ myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser);
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
aDisplayer->setSelected(aSelectedPrs);
bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
myWorkshop->objectBrowser()->blockSignals(aBlocked);
- QList<ModuleBase_ViewerPrs> aSelectedPrs = ModuleBase_ISelection::getViewerPrs(aFeatures);
+
+ QList<ModuleBase_ViewerPrs> aSelectedPrs =
+ myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser);
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
aDisplayer->setSelected(aSelectedPrs);