Salome HOME
c977072a831a9da84c606555301e3ac4544a0769
[modules/shaper.git] / src / ModuleBase / ModuleBase_FilterValidated.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_FilterValidated.cpp
4 // Created:     17 Mar 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #include "ModuleBase_FilterValidated.h"
8 #include "ModuleBase_IWorkshop.h"
9
10 #include <ModuleBase_IModule.h>
11 #include <ModuleBase_IPropertyPanel.h>
12 #include <ModuleBase_ISelection.h>
13 #include <ModuleBase_Operation.h>
14 #include <ModuleBase_WidgetValidated.h>
15 #include <ModuleBase_WidgetValidator.h>
16 #include <ModuleBase_ViewerPrs.h>
17
18 IMPLEMENT_STANDARD_HANDLE(ModuleBase_FilterValidated, SelectMgr_Filter);
19 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_FilterValidated, SelectMgr_Filter);
20
21 Standard_Boolean ModuleBase_FilterValidated::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
22 {
23   bool aValid = true;
24   ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation();
25   if (anOperation) {
26     ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
27     ModuleBase_ModelWidget* aCurrentWidget = aPanel->preselectionWidget();
28     if (!aCurrentWidget)
29       aCurrentWidget = myWorkshop->module()->activeWidget();
30     if (aCurrentWidget) {
31       ModuleBase_ViewerPrsPtr aPrs(new ModuleBase_ViewerPrs());
32       myWorkshop->selection()->fillPresentation(aPrs, theOwner);
33       ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
34                                                                              (aCurrentWidget);
35       if (aWidgetValidated)
36         aValid = !aWidgetValidated || aWidgetValidated->isValidSelection(aPrs);
37       else{
38         ModuleBase_WidgetValidator* aWidgetValidator = aCurrentWidget->widgetValidator();
39         if (aWidgetValidator)
40           aValid = aWidgetValidator->isValidSelection(aPrs);
41       }
42     }
43   }
44
45 #ifdef DEBUG_FILTERS
46   qDebug(QString("ModuleBase_FilterValidated::IsOk = %1").arg(aValid).toStdString().c_str());
47 #endif
48   return aValid;
49 }
50