]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_ActiveControlMgr.cpp
Salome HOME
#2309 Possibility to hide faces
[modules/shaper.git] / src / XGUI / XGUI_ActiveControlMgr.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include <XGUI_ActiveControlMgr.h>
22 #include <XGUI_ActiveControlSelector.h>
23
24 #include <ModuleBase_IModule.h>
25 #include <ModuleBase_IWorkshop.h>
26
27 //********************************************************************
28 XGUI_ActiveControlMgr::XGUI_ActiveControlMgr(ModuleBase_IWorkshop* theWorkshop)
29 : myWorkshop(theWorkshop), myActiveSelector(0)
30 {
31   connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
32 }
33
34 //********************************************************************
35 void XGUI_ActiveControlMgr::addSelector(XGUI_ActiveControlSelector* theSelector)
36 {
37   mySelectors.append(theSelector);
38   connect(theSelector, SIGNAL(activated()), this, SLOT(onSelectorActivated()));
39   connect(theSelector, SIGNAL(deactivated()), this, SLOT(onSelectorDeactivated()));
40 }
41
42 //********************************************************************
43 XGUI_ActiveControlSelector* XGUI_ActiveControlMgr::getSelector(const QString& theType)
44 {
45   XGUI_ActiveControlSelector* aSelector;
46   for (int i = 0, aCount = mySelectors.count(); i < aCount; i++)
47   {
48     if (mySelectors[i]->getType() != theType)
49       continue;
50     aSelector = mySelectors[i];
51     break;
52   }
53   return aSelector;
54 }
55
56 //********************************************************************
57 void XGUI_ActiveControlMgr::onSelectorActivated()
58 {
59   XGUI_ActiveControlSelector* aSelector = qobject_cast<XGUI_ActiveControlSelector*>(sender());
60   if (!aSelector || aSelector == myActiveSelector)
61     return;
62
63   if (myActiveSelector)
64     myActiveSelector->setActive(false);
65
66   activateSelector(aSelector);
67 }
68
69 //********************************************************************
70 void XGUI_ActiveControlMgr::onSelectorDeactivated()
71 {
72   XGUI_ActiveControlSelector* aSelector = qobject_cast<XGUI_ActiveControlSelector*>(sender());
73   if (!aSelector)
74     return;
75
76   myActiveSelector = NULL;
77
78   aSelector->setActive(false);
79   myWorkshop->module()->updateActiveSelectionFilters();
80
81   XGUI_ActiveControlSelector* aSelectorToBeActivated = 0;
82   for (int i = 0, aCount = mySelectors.count(); i < aCount; i++)
83   {
84     if (!mySelectors[i]->needToBeActiated())
85       continue;
86     aSelectorToBeActivated = mySelectors[i];
87     break;
88   }
89   if (aSelectorToBeActivated)
90     activateSelector(aSelectorToBeActivated);
91 }
92
93 //********************************************************************
94 void XGUI_ActiveControlMgr::onSelectionChanged()
95 {
96   if (!myActiveSelector)
97     return;
98
99   myActiveSelector->processSelection();
100 }
101
102 //********************************************************************
103 void XGUI_ActiveControlMgr::activateSelector(XGUI_ActiveControlSelector* theSelector)
104 {
105   myActiveSelector = theSelector;
106   theSelector->setActive(true);
107
108   myWorkshop->module()->updateActiveSelectionFilters();
109 }