Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / XGUI / XGUI_ModuleConnector.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        XGUI_ModuleConnector.cpp
4 // Created:     3 June 2014
5 // Author:      Vitaly Smetannikov
6
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"
17
18 #include <ModuleBase_IModule.h>
19 #include <ModuleBase_ViewerPrs.h>
20 #include <ModuleBase_OperationDescription.h>
21
22 #include <AIS_Shape.hxx>
23
24 #ifndef HAVE_SALOME
25 #include "AppElements_Command.h"
26 #else
27 #include "XGUI_SalomeConnector.h"
28 #endif
29
30 XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop)
31     : ModuleBase_IWorkshop(theWorkshop),
32       myWorkshop(theWorkshop)
33 {
34   XGUI_SelectionMgr* aSelector = myWorkshop->selector();
35   connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
36 }
37
38 XGUI_ModuleConnector::~XGUI_ModuleConnector()
39 {
40 }
41
42 ModuleBase_ISelection* XGUI_ModuleConnector::selection() const
43 {
44   return myWorkshop->selector()->selection();
45 }
46
47 ModuleBase_IModule* XGUI_ModuleConnector::module() const
48 {
49   return myWorkshop->module();
50 }
51
52 ModuleBase_IViewer* XGUI_ModuleConnector::viewer() const
53 {
54   return myWorkshop->viewer();
55 }
56
57 ModuleBase_IPropertyPanel* XGUI_ModuleConnector::propertyPanel() const
58 {
59   return myWorkshop->propertyPanel();
60 }
61
62 ModuleBase_IErrorMgr* XGUI_ModuleConnector::errorMgr() const
63 {
64   return myWorkshop->errorMgr();
65 }
66
67 ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const
68 {
69   return myWorkshop->operationMgr()->currentOperation();
70 }
71
72
73 QObjectPtrList XGUI_ModuleConnector::activeObjects(const QObjectPtrList& theObjList) const
74 {
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);
81   }
82   return aActiveOPbjects;
83 }
84
85 void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
86 {
87   QIntList aTypes = theTypes;
88
89   XGUI_Displayer* aDisp = myWorkshop->displayer();
90   myWorkshop->module()->customSubShapesSelectionModes(aTypes);
91   aDisp->activateObjects(aTypes, activeObjects(aDisp->displayedObjects()));
92 }
93
94 void XGUI_ModuleConnector::deactivateSubShapesSelection()
95 {
96   // Clear selection modes
97   activateModuleSelectionModes();
98 }
99
100 void XGUI_ModuleConnector::activateModuleSelectionModes()
101 {
102   XGUI_Displayer* aDisp = myWorkshop->displayer();
103   myWorkshop->activateObjectsSelection(activeObjects(aDisp->displayedObjects()));
104 }
105
106 AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
107 {
108   XGUI_Displayer* aDisp = myWorkshop->displayer();
109   return aDisp->getAISObject(theObject);
110 }
111
112 ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
113 {
114   XGUI_Displayer* aDisp = myWorkshop->displayer();
115   ObjectPtr anObject = aDisp->getObject(theAIS);
116   return anObject;
117 }
118
119 void XGUI_ModuleConnector::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues)
120 {
121   XGUI_Displayer* aDisp = myWorkshop->displayer();
122   if (theValues.isEmpty()) {
123     myWorkshop->selector()->clearSelection();
124   } else {
125     aDisp->setSelected(theValues);
126   }
127 }
128
129 void XGUI_ModuleConnector::setStatusBarMessage(const QString& theMessage)
130 {
131   myWorkshop->setStatusBarMessage(theMessage);
132 }
133
134 bool XGUI_ModuleConnector::canStartOperation(QString theId, bool& isCommitted)
135 {
136   return myWorkshop->operationMgr()->canStartOperation(theId, isCommitted);
137 }
138
139 void XGUI_ModuleConnector::processLaunchOperation(ModuleBase_Operation* theOperation)
140 {
141   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
142
143   if (anOperationMgr->startOperation(theOperation)) {
144     ModuleBase_OperationFeature* aFOperation =
145       dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
146     if (aFOperation) {
147       workshop()->propertyPanel()->updateContentWidget(aFOperation->feature());
148       workshop()->propertyPanel()->createContentPanel(aFOperation->feature());
149     }
150     if (!theOperation->getDescription()->hasXmlRepresentation()) {
151       if (theOperation->commit())
152         workshop()->updateCommandStatus();
153     }
154   }
155 }
156
157 ModuleBase_Operation* XGUI_ModuleConnector::findStartedOperation(const QString& theId)
158 {
159   return myWorkshop->operationMgr()->findOperation(theId);
160 }
161
162 bool XGUI_ModuleConnector::canStopOperation(ModuleBase_Operation* theOperation)
163 {
164   return myWorkshop->operationMgr()->canStopOperation(theOperation);
165 }
166
167 void XGUI_ModuleConnector::stopOperation(ModuleBase_Operation* theOperation,
168                                          bool& isCommitted)
169 {
170   myWorkshop->operationMgr()->stopOperation(theOperation, isCommitted);
171 }
172
173 void XGUI_ModuleConnector::updateCommandStatus()
174 {
175   myWorkshop->updateCommandStatus();
176 }
177
178 QMainWindow* XGUI_ModuleConnector::desktop() const
179 {
180   return myWorkshop->desktop();
181 }
182
183
184 std::shared_ptr<Config_FeatureMessage> XGUI_ModuleConnector::featureInfo(const QString& theId) const
185 {
186 #ifdef HAVE_SALOME
187   return myWorkshop->salomeConnector()->featureInfo(theId);
188 #else
189   AppElements_Command* aAction =
190     dynamic_cast<AppElements_Command*>(myWorkshop->actionsMgr()->action(theId));
191   if (aAction)
192     return aAction->featureMessage();
193   return std::shared_ptr<Config_FeatureMessage>();
194 #endif
195 }