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"
17 #include <ModuleBase_IModule.h>
18 #include <ModuleBase_ViewerPrs.h>
19 #include <ModuleBase_OperationDescription.h>
21 #include <AIS_Shape.hxx>
24 #include "AppElements_Command.h"
26 #include "XGUI_SalomeConnector.h"
29 XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop)
30 : ModuleBase_IWorkshop(theWorkshop),
31 myWorkshop(theWorkshop)
33 XGUI_SelectionMgr* aSelector = myWorkshop->selector();
34 connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
37 XGUI_ModuleConnector::~XGUI_ModuleConnector()
41 ModuleBase_ISelection* XGUI_ModuleConnector::selection() const
43 return myWorkshop->selector()->selection();
46 ModuleBase_IModule* XGUI_ModuleConnector::module() const
48 return myWorkshop->module();
51 ModuleBase_IViewer* XGUI_ModuleConnector::viewer() const
53 return myWorkshop->viewer();
56 ModuleBase_IPropertyPanel* XGUI_ModuleConnector::propertyPanel() const
58 return myWorkshop->propertyPanel();
61 ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const
63 return myWorkshop->operationMgr()->currentOperation();
67 QObjectPtrList XGUI_ModuleConnector::activeObjects(const QObjectPtrList& theObjList) const
69 QObjectPtrList aActiveOPbjects;
70 ModuleBase_IModule* aModule = myWorkshop->module();
71 // Activate objects only which can be activated
72 foreach (ObjectPtr aObj, theObjList) {
73 if (aModule->canActivateSelection(aObj))
74 aActiveOPbjects.append(aObj);
76 return aActiveOPbjects;
79 void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
81 QIntList aTypes = theTypes;
83 XGUI_Displayer* aDisp = myWorkshop->displayer();
84 myWorkshop->module()->customSubShapesSelectionModes(aTypes);
85 aDisp->activateObjects(aTypes, activeObjects(aDisp->displayedObjects()));
88 void XGUI_ModuleConnector::deactivateSubShapesSelection()
90 // Clear selection modes
91 activateModuleSelectionModes();
94 void XGUI_ModuleConnector::activateModuleSelectionModes()
96 XGUI_Displayer* aDisp = myWorkshop->displayer();
97 myWorkshop->activateObjectsSelection(activeObjects(aDisp->displayedObjects()));
100 AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
102 XGUI_Displayer* aDisp = myWorkshop->displayer();
103 return aDisp->getAISObject(theObject);
106 ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
108 XGUI_Displayer* aDisp = myWorkshop->displayer();
109 ObjectPtr anObject = aDisp->getObject(theAIS);
113 void XGUI_ModuleConnector::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues)
115 XGUI_Displayer* aDisp = myWorkshop->displayer();
116 if (theValues.isEmpty()) {
117 myWorkshop->selector()->clearSelection();
119 aDisp->setSelected(theValues);
123 void XGUI_ModuleConnector::setStatusBarMessage(const QString& theMessage)
125 myWorkshop->setStatusBarMessage(theMessage);
128 bool XGUI_ModuleConnector::canStartOperation(QString theId)
130 return myWorkshop->operationMgr()->canStartOperation(theId);
133 void XGUI_ModuleConnector::processLaunchOperation(ModuleBase_Operation* theOperation)
135 XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
137 if (anOperationMgr->startOperation(theOperation)) {
138 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
140 workshop()->propertyPanel()->updateContentWidget(aFOperation->feature());
141 workshop()->propertyPanel()->createContentPanel(aFOperation->feature());
143 if (!theOperation->getDescription()->hasXmlRepresentation()) {
144 if (theOperation->commit())
145 workshop()->updateCommandStatus();
150 ModuleBase_Operation* XGUI_ModuleConnector::findStartedOperation(const QString& theId)
152 return myWorkshop->operationMgr()->findOperation(theId);
155 bool XGUI_ModuleConnector::canStopOperation(ModuleBase_Operation* theOperation)
157 return myWorkshop->operationMgr()->canStopOperation(theOperation);
160 void XGUI_ModuleConnector::stopOperation(ModuleBase_Operation* theOperation)
162 myWorkshop->operationMgr()->stopOperation(theOperation);
165 void XGUI_ModuleConnector::updateCommandStatus()
167 myWorkshop->updateCommandStatus();
170 QMainWindow* XGUI_ModuleConnector::desktop() const
172 return myWorkshop->desktop();
176 std::shared_ptr<Config_FeatureMessage> XGUI_ModuleConnector::featureInfo(const QString& theId) const
179 return myWorkshop->salomeConnector()->featureInfo(theId);
181 AppElements_Command* aAction =
182 dynamic_cast<AppElements_Command*>(myWorkshop->actionsMgr()->action(theId));
184 return aAction->featureMessage();
185 return std::shared_ptr<Config_FeatureMessage>();