1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "XGUI_ModuleConnector.h"
22 #include "XGUI_Workshop.h"
23 #include "XGUI_ViewerProxy.h"
24 #include "XGUI_SelectionMgr.h"
25 #include "XGUI_Selection.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"
32 #include <ModuleBase_IModule.h>
33 #include <ModuleBase_ViewerPrs.h>
34 #include <ModuleBase_OperationDescription.h>
36 #include <AIS_Shape.hxx>
39 #include "AppElements_Command.h"
41 #include "XGUI_SalomeConnector.h"
44 XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop)
45 : ModuleBase_IWorkshop(theWorkshop),
46 myWorkshop(theWorkshop)
48 XGUI_SelectionMgr* aSelector = myWorkshop->selector();
49 connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
52 XGUI_ModuleConnector::~XGUI_ModuleConnector()
56 ModuleBase_ISelection* XGUI_ModuleConnector::selection() const
58 return myWorkshop->selector()->selection();
61 ModuleBase_IModule* XGUI_ModuleConnector::module() const
63 return myWorkshop->module();
66 ModuleBase_IViewer* XGUI_ModuleConnector::viewer() const
68 return myWorkshop->viewer();
71 ModuleBase_IPropertyPanel* XGUI_ModuleConnector::propertyPanel() const
73 return myWorkshop->propertyPanel();
76 ModuleBase_IErrorMgr* XGUI_ModuleConnector::errorMgr() const
78 return myWorkshop->errorMgr();
81 ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const
83 return myWorkshop->operationMgr()->currentOperation();
87 QObjectPtrList XGUI_ModuleConnector::activeObjects(const QObjectPtrList& theObjList) const
89 QObjectPtrList aActiveOPbjects;
90 ModuleBase_IModule* aModule = myWorkshop->module();
91 // Activate objects only which can be activated
92 foreach (ObjectPtr aObj, theObjList) {
93 if (aModule->canActivateSelection(aObj))
94 aActiveOPbjects.append(aObj);
96 return aActiveOPbjects;
99 void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
101 QIntList aTypes = theTypes;
103 XGUI_Displayer* aDisp = myWorkshop->displayer();
104 myWorkshop->module()->customSubShapesSelectionModes(aTypes);
105 aDisp->activateObjects(aTypes, activeObjects(aDisp->displayedObjects()));
108 void XGUI_ModuleConnector::deactivateSubShapesSelection()
110 // Clear selection modes
111 activateModuleSelectionModes();
114 void XGUI_ModuleConnector::activateModuleSelectionModes()
116 XGUI_Displayer* aDisp = myWorkshop->displayer();
117 myWorkshop->activateObjectsSelection(activeObjects(aDisp->displayedObjects()));
120 AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
122 XGUI_Displayer* aDisp = myWorkshop->displayer();
123 return aDisp->getAISObject(theObject);
126 ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
128 XGUI_Displayer* aDisp = myWorkshop->displayer();
129 ObjectPtr anObject = aDisp->getObject(theAIS);
133 void XGUI_ModuleConnector::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues)
135 XGUI_Displayer* aDisp = myWorkshop->displayer();
136 if (theValues.isEmpty()) {
137 myWorkshop->selector()->clearSelection();
139 aDisp->setSelected(theValues);
142 void XGUI_ModuleConnector::setStatusBarMessage(const QString& theMessage)
144 myWorkshop->setStatusBarMessage(theMessage);
147 bool XGUI_ModuleConnector::canStartOperation(QString theId, bool& isCommitted)
149 return myWorkshop->operationMgr()->canStartOperation(theId, isCommitted);
152 void XGUI_ModuleConnector::processLaunchOperation(ModuleBase_Operation* theOperation)
154 XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
156 if (anOperationMgr->startOperation(theOperation)) {
157 ModuleBase_OperationFeature* aFOperation =
158 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
160 workshop()->propertyPanel()->updateContentWidget(aFOperation->feature());
161 workshop()->propertyPanel()->createContentPanel(aFOperation->feature());
163 if (!theOperation->getDescription()->hasXmlRepresentation()) {
164 if (theOperation->commit())
165 workshop()->updateCommandStatus();
170 ModuleBase_Operation* XGUI_ModuleConnector::findStartedOperation(const QString& theId)
172 return myWorkshop->operationMgr()->findOperation(theId);
175 bool XGUI_ModuleConnector::canStopOperation(ModuleBase_Operation* theOperation)
177 return myWorkshop->operationMgr()->canStopOperation(theOperation);
180 void XGUI_ModuleConnector::stopOperation(ModuleBase_Operation* theOperation,
183 myWorkshop->operationMgr()->stopOperation(theOperation, isCommitted);
186 void XGUI_ModuleConnector::updateCommandStatus()
188 myWorkshop->updateCommandStatus();
191 QMainWindow* XGUI_ModuleConnector::desktop() const
193 return myWorkshop->desktop();
197 std::shared_ptr<Config_FeatureMessage> XGUI_ModuleConnector::featureInfo(const QString& theId) const
200 return myWorkshop->salomeConnector()->featureInfo(theId);
202 AppElements_Command* aAction =
203 dynamic_cast<AppElements_Command*>(myWorkshop->actionsMgr()->action(theId));
205 return aAction->featureMessage();
206 return std::shared_ptr<Config_FeatureMessage>();