1 // Copyright (C) 2014-2019 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_ModuleConnector.h"
21 #include "XGUI_Workshop.h"
22 #include "XGUI_ViewerProxy.h"
23 #include "XGUI_Selection.h"
24 #include "XGUI_SelectionActivate.h"
25 #include "XGUI_SelectionMgr.h"
26 #include "XGUI_OperationMgr.h"
27 #include "XGUI_Displayer.h"
28 #include "XGUI_PropertyPanel.h"
29 #include "XGUI_ActionsMgr.h"
30 #include "XGUI_ErrorMgr.h"
31 #include "XGUI_ObjectsBrowser.h"
33 #include <ModuleBase_IModule.h>
34 #include <ModuleBase_ViewerPrs.h>
35 #include <ModuleBase_OperationDescription.h>
37 #include <AIS_Shape.hxx>
40 #include "AppElements_Command.h"
42 #include "XGUI_SalomeConnector.h"
45 XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop)
46 : ModuleBase_IWorkshop(theWorkshop),
47 myWorkshop(theWorkshop)
49 XGUI_SelectionMgr* aSelector = myWorkshop->selector();
50 connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
53 XGUI_ModuleConnector::~XGUI_ModuleConnector()
57 ModuleBase_ISelection* XGUI_ModuleConnector::selection() const
59 return myWorkshop->selector()->selection();
62 ModuleBase_IModule* XGUI_ModuleConnector::module() const
64 return myWorkshop->module();
67 ModuleBase_IViewer* XGUI_ModuleConnector::viewer() const
69 return myWorkshop->viewer();
72 ModuleBase_IPropertyPanel* XGUI_ModuleConnector::propertyPanel() const
74 return myWorkshop->propertyPanel();
77 ModuleBase_IErrorMgr* XGUI_ModuleConnector::errorMgr() const
79 return myWorkshop->errorMgr();
82 ModuleBase_ISelectionActivate* XGUI_ModuleConnector::selectionActivate() const
84 return myWorkshop->selectionActivate();
87 ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const
89 return myWorkshop->operationMgr()->currentOperation();
93 QObjectPtrList XGUI_ModuleConnector::activeObjects(const QObjectPtrList& theObjList) const
95 QObjectPtrList aActiveOPbjects;
96 ModuleBase_IModule* aModule = myWorkshop->module();
97 // Activate objects only which can be activated
98 foreach (ObjectPtr aObj, theObjList) {
99 if (aModule->canActivateSelection(aObj))
100 aActiveOPbjects.append(aObj);
102 return aActiveOPbjects;
105 AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
107 XGUI_Displayer* aDisp = myWorkshop->displayer();
108 return aDisp->getAISObject(theObject);
111 bool XGUI_ModuleConnector::isVisible(const ObjectPtr& theObject) const
113 XGUI_Displayer* aDisp = myWorkshop->displayer();
114 return aDisp->isVisible(theObject);
118 ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
120 XGUI_Displayer* aDisp = myWorkshop->displayer();
121 ObjectPtr anObject = aDisp->getObject(theAIS);
125 void XGUI_ModuleConnector::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues)
127 XGUI_Displayer* aDisp = myWorkshop->displayer();
128 XGUI_ObjectsBrowser* aBrowser = myWorkshop->objectBrowser();
129 if (theValues.isEmpty()) {
130 myWorkshop->selector()->clearSelection();
131 aBrowser->treeView()->clearSelection();
133 aDisp->setSelected(theValues);
134 // Synchronise the selection with Object browser
135 QObjectPtrList anObjects;
136 foreach(ModuleBase_ViewerPrsPtr aVal, theValues) {
137 anObjects.append(aVal->object());
139 aBrowser->setObjectsSelected(anObjects);
143 void XGUI_ModuleConnector::setStatusBarMessage(const QString& theMessage)
145 myWorkshop->setStatusBarMessage(theMessage);
148 bool XGUI_ModuleConnector::canStartOperation(QString theId, bool& isCommitted)
150 return myWorkshop->operationMgr()->canStartOperation(theId, isCommitted);
153 void XGUI_ModuleConnector::processLaunchOperation(ModuleBase_Operation* theOperation)
155 XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
157 if (anOperationMgr->startOperation(theOperation)) {
158 ModuleBase_OperationFeature* aFOperation =
159 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
161 workshop()->propertyPanel()->updateContentWidget(aFOperation->feature());
162 workshop()->propertyPanel()->createContentPanel(aFOperation->feature());
164 if (!theOperation->getDescription()->hasXmlRepresentation()) {
165 if (theOperation->commit())
166 workshop()->updateCommandStatus();
171 ModuleBase_Operation* XGUI_ModuleConnector::findStartedOperation(const QString& theId)
173 return myWorkshop->operationMgr()->findOperation(theId);
176 bool XGUI_ModuleConnector::canStopOperation(ModuleBase_Operation* theOperation)
178 return myWorkshop->operationMgr()->canStopOperation(theOperation);
181 void XGUI_ModuleConnector::stopOperation(ModuleBase_Operation* theOperation,
184 myWorkshop->operationMgr()->stopOperation(theOperation, isCommitted);
187 void XGUI_ModuleConnector::updateCommandStatus()
189 myWorkshop->updateCommandStatus();
192 QMainWindow* XGUI_ModuleConnector::desktop() const
194 return myWorkshop->desktop();
197 bool XGUI_ModuleConnector::hasSHIFTPressed() const
199 return myWorkshop->operationMgr()->hasSHIFTPressed();
202 std::shared_ptr<Config_FeatureMessage> XGUI_ModuleConnector::featureInfo(const QString& theId) const
205 return myWorkshop->salomeConnector()->featureInfo(theId);
207 AppElements_Command* aAction =
208 dynamic_cast<AppElements_Command*>(myWorkshop->actionsMgr()->action(theId));
210 return aAction->featureMessage();
211 return std::shared_ptr<Config_FeatureMessage>();
215 void XGUI_ModuleConnector::deactivateCurrentSelector()
217 myWorkshop->deactivateCurrentSelector();
220 QObjectPtrList XGUI_ModuleConnector::displayedObjects() const
222 return myWorkshop->displayer()->displayedObjects();
225 bool XGUI_ModuleConnector::enableUpdateViewer(bool isEnabled)
227 return myWorkshop->displayer()->enableUpdateViewer(isEnabled);
231 void XGUI_ModuleConnector::applyCurrentSelectionModes(const AISObjectPtr& theAIS)
233 Handle(AIS_InteractiveObject) anIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
234 myWorkshop->selectionActivate()->activate(anIO, false);