Salome HOME
Merge branch 'master' into cgt/devCEA
[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 #include "ModuleBase_IViewer.h"
10
11 #include <ModuleBase_IModule.h>
12 #include <ModuleBase_IPropertyPanel.h>
13 #include <ModuleBase_ISelection.h>
14 #include <ModuleBase_Operation.h>
15 #include <ModuleBase_WidgetValidated.h>
16 #include <ModuleBase_WidgetValidator.h>
17 #include <ModuleBase_ViewerPrs.h>
18 #include <ModuleBase_Tools.h>
19
20 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_FilterValidated, SelectMgr_Filter);
21
22 Standard_Boolean ModuleBase_FilterValidated::
23   IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
24 {
25   bool aValid = true;
26   ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation();
27   if (anOperation) {
28     ModuleBase_IViewer* aViewer = myWorkshop->viewer();
29     Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
30
31     ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
32     if (aPanel) {
33       ModuleBase_ModelWidget* aCurrentWidget = aPanel->preselectionWidget();
34       if (!aCurrentWidget)
35         aCurrentWidget = myWorkshop->module()->activeWidget();
36       if (aCurrentWidget) {
37         ModuleBase_ViewerPrsPtr aPrs(new ModuleBase_ViewerPrs());
38         myWorkshop->selection()->fillPresentation(aPrs, theOwner);
39         ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
40                                                                                (aCurrentWidget);
41         if (aWidgetValidated)
42           aValid = !aWidgetValidated || aWidgetValidated->isValidSelection(aPrs);
43         else{
44           ModuleBase_WidgetValidator* aWidgetValidator = aCurrentWidget->widgetValidator();
45           if (aWidgetValidator)
46             aValid = aWidgetValidator->isValidSelection(aPrs);
47         }
48       }
49     }
50   }
51
52 #ifdef DEBUG_FILTERS
53   qDebug(QString("ModuleBase_FilterValidated::IsOk = %1").arg(aValid).toStdString().c_str());
54 #endif
55   return aValid;
56 }
57