- if (myIsActive) {
- myTextLine->setText("");
- }
- }
- }
-}
-
-
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::activateSelection(bool toActivate)
-{
- if (myIsActive == toActivate)
- return;
- myIsActive = toActivate;
- updateSelectionName();
- ModuleBase_IViewer* aViewer = myWorkshop->viewer();
-
- if (myIsActive) {
- connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
- QIntList aList;
- foreach (QString aType, myShapeTypes) {
- aList.append(shapeType(aType));
- }
- myWorkshop->activateSubShapesSelection(aList);
- } else {
- disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
- myWorkshop->deactivateSubShapesSelection();
- }
-
- // the initial code is moved here in order to clear filters, it is possible, that it is excessive and
- // is performed outside
- if (myIsActive && !myObjectTypes.isEmpty()) {
- aViewer->clearSelectionFilters();
- }
- SelectMgr_ListOfFilter aFilters;
- selectionFilters(aFilters);
- SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
- for (; aIt.More(); aIt.Next()) {
- const Handle(SelectMgr_Filter)& aSelFilter = aIt.Value();
- if (myIsActive)
- aViewer->addSelectionFilter(aSelFilter);
- else
- aViewer->removeSelectionFilter(aSelFilter);
- }
- // the internal filter should be removed by the widget deactivation, it is done historically
- if (!myIsActive && !myObjTypeFilter.IsNull()) {
- myObjTypeFilter.Nullify();
- }
-}
-
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::selectionFilters(SelectMgr_ListOfFilter& theFilters)
-{
- if (!myObjectTypes.isEmpty() && myObjTypeFilter.IsNull()) {
- myObjTypeFilter = new ModuleBase_ObjectTypesFilter(myWorkshop, myObjectTypes);
- }
- theFilters.Append(myObjTypeFilter);
-
- // apply filters loaded from the XML definition of the widget
- ModuleBase_FilterFactory* aFactory = myWorkshop->selectionFilters();
- SelectMgr_ListOfFilter aFilters;
- aFactory->filters(parentID(), attributeID(), aFilters);
- SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
- for (; aIt.More(); aIt.Next()) {
- Handle(SelectMgr_Filter) aSelFilter = aIt.Value();
- if (aSelFilter.IsNull())
- continue;
-
- theFilters.Append(aSelFilter);
- }
-}
-
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::raisePanel() const
-{
- QWidget* aParent = this->parentWidget();
- QWidget* aLastPanel = 0;
- while (!aParent->inherits("QDockWidget")) {
- aLastPanel = aParent;
- aParent = aParent->parentWidget();
- if (!aParent)
- return;
- }
- if (aParent->inherits("QDockWidget")) {
- QDockWidget* aTabWgt = (QDockWidget*) aParent;
- aTabWgt->raise();
- }
-}
-
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::activateCustom()
-{
- activateSelection(true);
-}
-
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::deactivate()
-{
- activateSelection(false);
-}
-
-//********************************************************************
-bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape)
-{
- SessionPtr aMgr = ModelAPI_Session::get();
- ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
- std::list<ModelAPI_Validator*> aValidators;
- std::list<std::list<std::string> > anArguments;
- aFactory->validators(parentID(), attributeID(), aValidators, anArguments);
-
- // Check the type of selected object
- std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
- bool isValid = true;
- for (; aValidator != aValidators.end(); aValidator++) {
- const ModelAPI_ResultValidator* aResValidator =
- dynamic_cast<const ModelAPI_ResultValidator*>(*aValidator);
- if (aResValidator) {
- isValid = false;
- if (aResValidator->isValid(theObj)) {
- isValid = true;
- break;
- }
- }
- }
- if (!isValid)
- return false;
-
- // Check the acceptability of the object as attribute
- aValidator = aValidators.begin();
- std::list<std::list<std::string> >::iterator aArgs = anArguments.begin();
- for (; aValidator != aValidators.end(); aValidator++, aArgs++) {
- const ModelAPI_RefAttrValidator* aAttrValidator =
- dynamic_cast<const ModelAPI_RefAttrValidator*>(*aValidator);
- if (aAttrValidator) {
- if (!aAttrValidator->isValid(myFeature, *aArgs, theObj)) {
- return false;