Salome HOME
59baeb5159658c27b1c2aeb3fa00d8096cbf8ea9
[modules/shaper.git] / src / XGUI / XGUI_ModuleConnector.cpp
1 // Copyright (C) 2014-2021  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "XGUI_ModuleConnector.h"
21 #include "XGUI_Workshop.h"
22 #include "XGUI_ViewerProxy.h"
23 #include "XGUI_Selection.h"
24 #include "XGUI_SelectionActivate.h"
25 #include "XGUI_SelectionMgr.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"
31 #include "XGUI_ObjectsBrowser.h"
32
33 #include <ModuleBase_IModule.h>
34 #include <ModuleBase_ViewerPrs.h>
35 #include <ModuleBase_OperationDescription.h>
36
37 #include <AIS_Shape.hxx>
38
39 #ifndef HAVE_SALOME
40 #include "AppElements_Command.h"
41 #else
42 #include "XGUI_SalomeConnector.h"
43 #endif
44
45 XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop)
46     : ModuleBase_IWorkshop(theWorkshop),
47       myWorkshop(theWorkshop)
48 {
49   XGUI_SelectionMgr* aSelector = myWorkshop->selector();
50   connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
51 }
52
53 XGUI_ModuleConnector::~XGUI_ModuleConnector()
54 {
55 }
56
57 ModuleBase_ISelection* XGUI_ModuleConnector::selection() const
58 {
59   return myWorkshop->selector()->selection();
60 }
61
62 ModuleBase_IModule* XGUI_ModuleConnector::module() const
63 {
64   return myWorkshop->module();
65 }
66
67 ModuleBase_IViewer* XGUI_ModuleConnector::viewer() const
68 {
69   return myWorkshop->viewer();
70 }
71
72 ModuleBase_IPropertyPanel* XGUI_ModuleConnector::propertyPanel() const
73 {
74   return myWorkshop->propertyPanel();
75 }
76
77 ModuleBase_IErrorMgr* XGUI_ModuleConnector::errorMgr() const
78 {
79   return myWorkshop->errorMgr();
80 }
81
82 ModuleBase_ISelectionActivate* XGUI_ModuleConnector::selectionActivate() const
83 {
84   return myWorkshop->selectionActivate();
85 }
86
87 ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const
88 {
89   return myWorkshop->operationMgr()->currentOperation();
90 }
91
92
93 QObjectPtrList XGUI_ModuleConnector::activeObjects(const QObjectPtrList& theObjList) const
94 {
95   QObjectPtrList aActiveOPbjects;
96   ModuleBase_IModule* aModule = myWorkshop->module();
97   // Activate objects only which can be activated
98   foreach (ObjectPtr aObj, theObjList) {
99     if (aModule->canActivateSelection(aObj))
100       aActiveOPbjects.append(aObj);
101   }
102   return aActiveOPbjects;
103 }
104
105 AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
106 {
107   XGUI_Displayer* aDisp = myWorkshop->displayer();
108   return aDisp->getAISObject(theObject);
109 }
110
111 bool XGUI_ModuleConnector::isVisible(const ObjectPtr& theObject) const
112 {
113   XGUI_Displayer* aDisp = myWorkshop->displayer();
114   return aDisp->isVisible(theObject);
115 }
116
117
118 ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
119 {
120   XGUI_Displayer* aDisp = myWorkshop->displayer();
121   ObjectPtr anObject = aDisp->getObject(theAIS);
122   return anObject;
123 }
124
125 void XGUI_ModuleConnector::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues)
126 {
127   XGUI_ObjectsBrowser* aBrowser = myWorkshop->objectBrowser();
128   if (theValues.isEmpty()) {
129     myWorkshop->selector()->clearSelection();
130     aBrowser->treeView()->clearSelection();
131   } else {
132     myWorkshop->selector()->setSelected(theValues);
133   }
134 }
135
136 void XGUI_ModuleConnector::setStatusBarMessage(const QString& theMessage)
137 {
138   myWorkshop->setStatusBarMessage(theMessage);
139 }
140
141 bool XGUI_ModuleConnector::canStartOperation(QString theId, bool& isCommitted)
142 {
143   return myWorkshop->operationMgr()->canStartOperation(theId, isCommitted);
144 }
145
146 void XGUI_ModuleConnector::processLaunchOperation(ModuleBase_Operation* theOperation)
147 {
148   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
149
150   if (anOperationMgr->startOperation(theOperation)) {
151     ModuleBase_OperationFeature* aFOperation =
152       dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
153     if (aFOperation) {
154       workshop()->propertyPanel()->updateContentWidget(aFOperation->feature());
155       workshop()->propertyPanel()->createContentPanel(aFOperation->feature());
156     }
157     if (!theOperation->getDescription()->hasXmlRepresentation()) {
158       if (theOperation->commit())
159         workshop()->updateCommandStatus();
160     }
161   }
162 }
163
164 ModuleBase_Operation* XGUI_ModuleConnector::findStartedOperation(const QString& theId)
165 {
166   return myWorkshop->operationMgr()->findOperation(theId);
167 }
168
169 bool XGUI_ModuleConnector::canStopOperation(ModuleBase_Operation* theOperation)
170 {
171   return myWorkshop->operationMgr()->canStopOperation(theOperation);
172 }
173
174 void XGUI_ModuleConnector::stopOperation(ModuleBase_Operation* theOperation,
175                                          bool& isCommitted)
176 {
177   myWorkshop->operationMgr()->stopOperation(theOperation, isCommitted);
178 }
179
180 void XGUI_ModuleConnector::updateCommandStatus()
181 {
182   myWorkshop->updateCommandStatus();
183 }
184
185 QMainWindow* XGUI_ModuleConnector::desktop() const
186 {
187   return myWorkshop->desktop();
188 }
189
190 bool XGUI_ModuleConnector::hasSHIFTPressed() const
191 {
192   return myWorkshop->operationMgr()->hasSHIFTPressed();
193 }
194
195 std::shared_ptr<Config_FeatureMessage> XGUI_ModuleConnector::featureInfo(const QString& theId) const
196 {
197 #ifdef HAVE_SALOME
198   return myWorkshop->salomeConnector()->featureInfo(theId);
199 #else
200   AppElements_Command* aAction =
201     dynamic_cast<AppElements_Command*>(myWorkshop->actionsMgr()->action(theId));
202   if (aAction)
203     return aAction->featureMessage();
204   return std::shared_ptr<Config_FeatureMessage>();
205 #endif
206 }
207
208 void XGUI_ModuleConnector::deactivateCurrentSelector()
209 {
210   myWorkshop->deactivateCurrentSelector();
211 }
212
213 QObjectPtrList XGUI_ModuleConnector::displayedObjects() const
214 {
215   return myWorkshop->displayer()->displayedObjects();
216 }
217
218 bool XGUI_ModuleConnector::enableUpdateViewer(bool isEnabled)
219 {
220   return myWorkshop->displayer()->enableUpdateViewer(isEnabled);
221 }
222
223
224 void XGUI_ModuleConnector::applyCurrentSelectionModes(const AISObjectPtr& theAIS)
225 {
226   Handle(AIS_InteractiveObject) anIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
227   myWorkshop->selectionActivate()->activate(anIO, false);
228 }
229
230
231 void XGUI_ModuleConnector::undo()
232 {
233   myWorkshop->onUndo();
234 }
235
236 void XGUI_ModuleConnector::setCancelEnabled(bool toEnable)
237 {
238   XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr();
239   QAction* aAbortAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll);
240   QAction* aAbortAllAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
241   if (aAbortAction) {
242     aAbortAction->setEnabled(toEnable);
243   }
244   if (aAbortAllAction) {
245     aAbortAllAction->setEnabled(toEnable);
246   }
247 }
248
249 bool XGUI_ModuleConnector::isCancelEnabled() const
250 {
251   XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr();
252   QAction* aAbortAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll);
253   QAction* aAbortAllAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
254   bool isEnabled = false;
255   if (aAbortAction) {
256     isEnabled = true;
257   }
258   if (aAbortAllAction) {
259     isEnabled &= true;
260   }
261   return isEnabled;
262 }
263
264 void XGUI_ModuleConnector::showHelpPage(const QString& thePage) const
265 {
266   workshop()->showHelpPage(thePage);
267 }