1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: XGUI_ModuleConnector.cpp
4 // Created: 3 June 2014
5 // Author: Vitaly Smetannikov
7 #include "XGUI_ModuleConnector.h"
8 #include "XGUI_Workshop.h"
9 #include "XGUI_ViewerProxy.h"
10 #include "XGUI_SelectionMgr.h"
11 #include "XGUI_Selection.h"
12 #include "XGUI_OperationMgr.h"
13 #include "XGUI_Displayer.h"
14 #include "XGUI_PropertyPanel.h"
15 #include "XGUI_ActionsMgr.h"
16 #include "XGUI_ErrorMgr.h"
18 #include <ModuleBase_IModule.h>
19 #include <ModuleBase_ViewerPrs.h>
20 #include <ModuleBase_OperationDescription.h>
22 #include <AIS_Shape.hxx>
25 #include "AppElements_Command.h"
27 #include "XGUI_SalomeConnector.h"
30 XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop)
31 : ModuleBase_IWorkshop(theWorkshop),
32 myWorkshop(theWorkshop)
34 XGUI_SelectionMgr* aSelector = myWorkshop->selector();
35 connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
38 XGUI_ModuleConnector::~XGUI_ModuleConnector()
42 ModuleBase_ISelection* XGUI_ModuleConnector::selection() const
44 return myWorkshop->selector()->selection();
47 ModuleBase_IModule* XGUI_ModuleConnector::module() const
49 return myWorkshop->module();
52 ModuleBase_IViewer* XGUI_ModuleConnector::viewer() const
54 return myWorkshop->viewer();
57 ModuleBase_IPropertyPanel* XGUI_ModuleConnector::propertyPanel() const
59 return myWorkshop->propertyPanel();
62 ModuleBase_IErrorMgr* XGUI_ModuleConnector::errorMgr() const
64 return myWorkshop->errorMgr();
67 ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const
69 return myWorkshop->operationMgr()->currentOperation();
73 QObjectPtrList XGUI_ModuleConnector::activeObjects(const QObjectPtrList& theObjList) const
75 QObjectPtrList aActiveOPbjects;
76 ModuleBase_IModule* aModule = myWorkshop->module();
77 // Activate objects only which can be activated
78 foreach (ObjectPtr aObj, theObjList) {
79 if (aModule->canActivateSelection(aObj))
80 aActiveOPbjects.append(aObj);
82 return aActiveOPbjects;
85 void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
87 QIntList aTypes = theTypes;
89 XGUI_Displayer* aDisp = myWorkshop->displayer();
90 myWorkshop->module()->customSubShapesSelectionModes(aTypes);
91 aDisp->activateObjects(aTypes, activeObjects(aDisp->displayedObjects()));
94 void XGUI_ModuleConnector::deactivateSubShapesSelection()
96 // Clear selection modes
97 activateModuleSelectionModes();
100 void XGUI_ModuleConnector::activateModuleSelectionModes()
102 XGUI_Displayer* aDisp = myWorkshop->displayer();
103 myWorkshop->activateObjectsSelection(activeObjects(aDisp->displayedObjects()));
106 AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
108 XGUI_Displayer* aDisp = myWorkshop->displayer();
109 return aDisp->getAISObject(theObject);
112 ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
114 XGUI_Displayer* aDisp = myWorkshop->displayer();
115 ObjectPtr anObject = aDisp->getObject(theAIS);
119 void XGUI_ModuleConnector::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues)
121 XGUI_Displayer* aDisp = myWorkshop->displayer();
122 if (theValues.isEmpty()) {
123 myWorkshop->selector()->clearSelection();
125 aDisp->setSelected(theValues);
129 void XGUI_ModuleConnector::setStatusBarMessage(const QString& theMessage)
131 myWorkshop->setStatusBarMessage(theMessage);
134 bool XGUI_ModuleConnector::canStartOperation(QString theId, bool& isCommitted)
136 return myWorkshop->operationMgr()->canStartOperation(theId, isCommitted);
139 void XGUI_ModuleConnector::processLaunchOperation(ModuleBase_Operation* theOperation)
141 XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
143 if (anOperationMgr->startOperation(theOperation)) {
144 ModuleBase_OperationFeature* aFOperation =
145 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
147 workshop()->propertyPanel()->updateContentWidget(aFOperation->feature());
148 workshop()->propertyPanel()->createContentPanel(aFOperation->feature());
150 if (!theOperation->getDescription()->hasXmlRepresentation()) {
151 if (theOperation->commit())
152 workshop()->updateCommandStatus();
157 ModuleBase_Operation* XGUI_ModuleConnector::findStartedOperation(const QString& theId)
159 return myWorkshop->operationMgr()->findOperation(theId);
162 bool XGUI_ModuleConnector::canStopOperation(ModuleBase_Operation* theOperation)
164 return myWorkshop->operationMgr()->canStopOperation(theOperation);
167 void XGUI_ModuleConnector::stopOperation(ModuleBase_Operation* theOperation,
170 myWorkshop->operationMgr()->stopOperation(theOperation, isCommitted);
173 void XGUI_ModuleConnector::updateCommandStatus()
175 myWorkshop->updateCommandStatus();
178 QMainWindow* XGUI_ModuleConnector::desktop() const
180 return myWorkshop->desktop();
184 std::shared_ptr<Config_FeatureMessage> XGUI_ModuleConnector::featureInfo(const QString& theId) const
187 return myWorkshop->salomeConnector()->featureInfo(theId);
189 AppElements_Command* aAction =
190 dynamic_cast<AppElements_Command*>(myWorkshop->actionsMgr()->action(theId));
192 return aAction->featureMessage();
193 return std::shared_ptr<Config_FeatureMessage>();