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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include "XGUI_ModuleConnector.h"
21 #include "XGUI_Workshop.h"
22 #include "XGUI_ViewerProxy.h"
23 #include "XGUI_SelectionMgr.h"
24 #include "XGUI_Selection.h"
25 #include "XGUI_OperationMgr.h"
26 #include "XGUI_Displayer.h"
27 #include "XGUI_PropertyPanel.h"
28 #include "XGUI_ActionsMgr.h"
29 #include "XGUI_ErrorMgr.h"
31 #include <ModuleBase_IModule.h>
32 #include <ModuleBase_ViewerPrs.h>
33 #include <ModuleBase_OperationDescription.h>
35 #include <AIS_Shape.hxx>
38 #include "AppElements_Command.h"
40 #include "XGUI_SalomeConnector.h"
43 XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop)
44 : ModuleBase_IWorkshop(theWorkshop),
45 myWorkshop(theWorkshop)
47 XGUI_SelectionMgr* aSelector = myWorkshop->selector();
48 connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
51 XGUI_ModuleConnector::~XGUI_ModuleConnector()
55 ModuleBase_ISelection* XGUI_ModuleConnector::selection() const
57 return myWorkshop->selector()->selection();
60 ModuleBase_IModule* XGUI_ModuleConnector::module() const
62 return myWorkshop->module();
65 ModuleBase_IViewer* XGUI_ModuleConnector::viewer() const
67 return myWorkshop->viewer();
70 ModuleBase_IPropertyPanel* XGUI_ModuleConnector::propertyPanel() const
72 return myWorkshop->propertyPanel();
75 ModuleBase_IErrorMgr* XGUI_ModuleConnector::errorMgr() const
77 return myWorkshop->errorMgr();
80 ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const
82 return myWorkshop->operationMgr()->currentOperation();
86 QObjectPtrList XGUI_ModuleConnector::activeObjects(const QObjectPtrList& theObjList) const
88 QObjectPtrList aActiveOPbjects;
89 ModuleBase_IModule* aModule = myWorkshop->module();
90 // Activate objects only which can be activated
91 foreach (ObjectPtr aObj, theObjList) {
92 if (aModule->canActivateSelection(aObj))
93 aActiveOPbjects.append(aObj);
95 return aActiveOPbjects;
98 void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
100 QIntList aTypes = theTypes;
102 XGUI_Displayer* aDisp = myWorkshop->displayer();
103 myWorkshop->module()->customSubShapesSelectionModes(aTypes);
104 aDisp->activateObjects(aTypes, activeObjects(aDisp->displayedObjects()));
107 void XGUI_ModuleConnector::deactivateSubShapesSelection()
109 // Clear selection modes
110 activateModuleSelectionModes();
113 void XGUI_ModuleConnector::activateModuleSelectionModes()
115 XGUI_Displayer* aDisp = myWorkshop->displayer();
116 myWorkshop->activateObjectsSelection(activeObjects(aDisp->displayedObjects()));
119 AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
121 XGUI_Displayer* aDisp = myWorkshop->displayer();
122 return aDisp->getAISObject(theObject);
125 ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
127 XGUI_Displayer* aDisp = myWorkshop->displayer();
128 ObjectPtr anObject = aDisp->getObject(theAIS);
132 void XGUI_ModuleConnector::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues)
134 XGUI_Displayer* aDisp = myWorkshop->displayer();
135 if (theValues.isEmpty()) {
136 myWorkshop->selector()->clearSelection();
138 aDisp->setSelected(theValues);
141 void XGUI_ModuleConnector::setStatusBarMessage(const QString& theMessage)
143 myWorkshop->setStatusBarMessage(theMessage);
146 bool XGUI_ModuleConnector::canStartOperation(QString theId, bool& isCommitted)
148 return myWorkshop->operationMgr()->canStartOperation(theId, isCommitted);
151 void XGUI_ModuleConnector::processLaunchOperation(ModuleBase_Operation* theOperation)
153 XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
155 if (anOperationMgr->startOperation(theOperation)) {
156 ModuleBase_OperationFeature* aFOperation =
157 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
159 workshop()->propertyPanel()->updateContentWidget(aFOperation->feature());
160 workshop()->propertyPanel()->createContentPanel(aFOperation->feature());
162 if (!theOperation->getDescription()->hasXmlRepresentation()) {
163 if (theOperation->commit())
164 workshop()->updateCommandStatus();
169 ModuleBase_Operation* XGUI_ModuleConnector::findStartedOperation(const QString& theId)
171 return myWorkshop->operationMgr()->findOperation(theId);
174 bool XGUI_ModuleConnector::canStopOperation(ModuleBase_Operation* theOperation)
176 return myWorkshop->operationMgr()->canStopOperation(theOperation);
179 void XGUI_ModuleConnector::stopOperation(ModuleBase_Operation* theOperation,
182 myWorkshop->operationMgr()->stopOperation(theOperation, isCommitted);
185 void XGUI_ModuleConnector::updateCommandStatus()
187 myWorkshop->updateCommandStatus();
190 QMainWindow* XGUI_ModuleConnector::desktop() const
192 return myWorkshop->desktop();
196 std::shared_ptr<Config_FeatureMessage> XGUI_ModuleConnector::featureInfo(const QString& theId) const
199 return myWorkshop->salomeConnector()->featureInfo(theId);
201 AppElements_Command* aAction =
202 dynamic_cast<AppElements_Command*>(myWorkshop->actionsMgr()->action(theId));
204 return aAction->featureMessage();
205 return std::shared_ptr<Config_FeatureMessage>();