1 // Copyright (C) 2014-2020 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "XGUI_ActiveControlMgr.h"
21 #include "XGUI_ActiveControlSelector.h"
22 #include "XGUI_SelectionActivate.h"
23 #include "XGUI_SelectionMgr.h"
24 #include "XGUI_Tools.h"
25 #include "XGUI_Workshop.h"
27 #include <ModuleBase_IModule.h>
28 #include <ModuleBase_IWorkshop.h>
30 //#define DEBUG_ACTIVE_SELECTOR
32 #ifdef DEBUG_ACTIVE_SELECTOR
33 void debugInfo(const QString& theMessage, XGUI_ActiveControlSelector* theSelector)
35 std::cout << theMessage.toStdString().c_str() << ", active: "
36 << (theSelector ? theSelector->getType().toStdString().c_str() : "NULL") << std::endl;
40 //********************************************************************
41 XGUI_ActiveControlMgr::XGUI_ActiveControlMgr(ModuleBase_IWorkshop* theWorkshop)
42 : myWorkshop(theWorkshop), myActiveSelector(0), myIsBlocked(false)
44 connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
47 //********************************************************************
48 void XGUI_ActiveControlMgr::addSelector(XGUI_ActiveControlSelector* theSelector)
50 mySelectors.append(theSelector);
51 connect(theSelector, SIGNAL(activated()), this, SLOT(onSelectorActivated()));
52 connect(theSelector, SIGNAL(deactivated()), this, SLOT(onSelectorDeactivated()));
55 //********************************************************************
56 XGUI_ActiveControlSelector* XGUI_ActiveControlMgr::getSelector(const QString& theType)
58 XGUI_ActiveControlSelector* aSelector = 0;
59 for (int i = 0, aCount = mySelectors.count(); i < aCount; i++)
61 if (mySelectors[i]->getType() != theType)
63 aSelector = mySelectors[i];
69 //********************************************************************
70 void XGUI_ActiveControlMgr::onSelectorActivated()
72 XGUI_ActiveControlSelector* aSelector = qobject_cast<XGUI_ActiveControlSelector*>(sender());
73 if (!aSelector || aSelector == myActiveSelector)
76 if (myIsBlocked) // we've come here from the same method
79 if (myActiveSelector) {
80 myActiveSelector->setActive(false);
82 activateSelector(aSelector);
83 XGUI_Tools::workshop(myWorkshop)->selectionActivate()->updateSelectionModes();
84 XGUI_Tools::workshop(myWorkshop)->selectionActivate()->updateSelectionFilters();
86 #ifdef DEBUG_ACTIVE_SELECTOR
87 debugInfo("onSelectorActivated", myActiveSelector);
92 //********************************************************************
93 void XGUI_ActiveControlMgr::onSelectorDeactivated()
95 XGUI_ActiveControlSelector* aSelector = qobject_cast<XGUI_ActiveControlSelector*>(sender());
96 deactivateSelector(aSelector);
99 //********************************************************************
100 void XGUI_ActiveControlMgr::deactivateSelector(XGUI_ActiveControlSelector* theSelector)
102 if (!theSelector || theSelector != myActiveSelector || !myActiveSelector)
105 if (myIsBlocked) // we've come here from the same method
109 myActiveSelector->setActive(false);
110 activateSelector(NULL);
112 XGUI_ActiveControlSelector* aSelectorToBeActivated = 0;
113 for (int i = 0, aCount = mySelectors.count(); i < aCount; i++) {
114 if (!mySelectors[i]->needToBeActivated())
116 aSelectorToBeActivated = mySelectors[i];
119 if (aSelectorToBeActivated)
120 activateSelector(aSelectorToBeActivated);
122 XGUI_Tools::workshop(myWorkshop)->selectionActivate()->updateSelectionModes();
123 XGUI_Tools::workshop(myWorkshop)->selectionActivate()->updateSelectionFilters();
124 #ifdef DEBUG_ACTIVE_SELECTOR
125 debugInfo("onSelectorDeactivated", myActiveSelector);
130 //********************************************************************
131 void XGUI_ActiveControlMgr::onSelectionChanged()
133 if (!myActiveSelector)
136 myActiveSelector->processSelection();
137 #ifdef DEBUG_ACTIVE_SELECTOR
138 debugInfo("onSelectionChanged", myActiveSelector);
142 //********************************************************************
143 void XGUI_ActiveControlMgr::activateSelector(XGUI_ActiveControlSelector* theSelector)
145 myActiveSelector = theSelector;
146 if (myActiveSelector)
147 myActiveSelector->setActive(true);