Salome HOME
Issue #1393 Angle constraint : incorrect angle displayed. solution: arc's passed...
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetValidator.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 #include <ModuleBase_WidgetValidator.h>
4
5 #include <ModuleBase_ModelWidget.h>
6 #include <ModuleBase_ViewerPrs.h>
7 #include <ModuleBase_IViewer.h>
8 #include <ModuleBase_IWorkshop.h>
9
10 ModuleBase_WidgetValidator::ModuleBase_WidgetValidator(ModuleBase_ModelWidget* theModelWidget,
11                                                        ModuleBase_IWorkshop* theWorkshop)
12 : myModelWidget(theModelWidget), myWorkshop(theWorkshop)
13 {
14 }
15
16 ModuleBase_WidgetValidator::~ModuleBase_WidgetValidator()
17 {
18 }
19
20 //********************************************************************
21 bool ModuleBase_WidgetValidator::isValidSelection(const ModuleBase_ViewerPrsPtr& theValue)
22 {
23   bool aValid = false;
24   if (getValidState(theValue, aValid))
25     return aValid;
26
27   aValid = myModelWidget->isValidSelectionCustom(theValue);
28
29   storeValidState(theValue, aValid);
30   return aValid;
31 }
32
33 bool ModuleBase_WidgetValidator::activateFilters(const bool toActivate)
34 {
35   ModuleBase_IViewer* aViewer = myWorkshop->viewer();
36
37   Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter();
38   bool aHasSelectionFilter = aViewer->hasSelectionFilter(aSelFilter);
39
40   if (toActivate)
41     aViewer->addSelectionFilter(aSelFilter);
42   else {
43     aViewer->removeSelectionFilter(aSelFilter);
44     clearValidatedCash();
45   }
46
47   return aHasSelectionFilter;
48 }
49
50 bool ModuleBase_WidgetValidator::isFilterActivated() const
51 {
52   bool isActivated = false;
53
54   Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter();
55   ModuleBase_IViewer* aViewer = myWorkshop->viewer();
56
57   return aViewer->hasSelectionFilter(aSelFilter);
58 }
59
60 void ModuleBase_WidgetValidator::clearValidatedCash()
61 {
62   myValidPrs.clear();
63   myInvalidPrs.clear();
64 }
65
66 bool ModuleBase_WidgetValidator::getValidState(const ModuleBase_ViewerPrsPtr& theValue, bool& theValid)
67 {
68   bool aValidPrs = myValidPrs.contains(theValue);
69   bool anInvalidPrs = myInvalidPrs.contains(theValue);
70
71   if (aValidPrs)
72     theValid = true;
73   else if (anInvalidPrs)
74     theValid = false;
75
76   return aValidPrs || anInvalidPrs;
77 }
78
79 //********************************************************************
80 void ModuleBase_WidgetValidator::storeValidState(const ModuleBase_ViewerPrsPtr& theValue, const bool theValid)
81 {
82   bool aValidPrs = myInvalidPrs.contains(theValue);
83   bool anInvalidPrs = myInvalidPrs.contains(theValue);
84
85   if (theValid) {
86     if (!aValidPrs)
87       myValidPrs.append(theValue);
88     // the commented code will be useful when the valid state of the presentation
89     // will be changable between activate/deactivate. Currently it does not happen.
90     //if (anInvalidPrs)
91     //  myInvalidPrs.removeOne(theValue);
92   }
93   else { // !theValid
94     if (!anInvalidPrs)
95       myInvalidPrs.append(theValue);
96     //if (!aValidPrs)
97     //  myValidPrs.removeOne(theValue);
98   }
99 #ifdef DEBUG_VALID_STATE
100   qDebug(QString("storeValidState: myValidPrs.size() = %1, myInvalidPrs.size() = %2").arg(myValidPrs.count())
101                  .arg(myInvalidPrs.count()).toStdString().c_str());
102 #endif
103 }