Salome HOME
4f2130509984d134c0c2bf2190fe2b48febe0670
[modules/shaper.git] / src / XGUI / XGUI_ModuleConnector.cpp
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "XGUI_ModuleConnector.h"
22 #include "XGUI_Workshop.h"
23 #include "XGUI_ViewerProxy.h"
24 #include "XGUI_Selection.h"
25 #include "XGUI_SelectionActivate.h"
26 #include "XGUI_SelectionMgr.h"
27 #include "XGUI_OperationMgr.h"
28 #include "XGUI_Displayer.h"
29 #include "XGUI_PropertyPanel.h"
30 #include "XGUI_ActionsMgr.h"
31 #include "XGUI_ErrorMgr.h"
32 #include "XGUI_ObjectsBrowser.h"
33
34 #include <ModuleBase_IModule.h>
35 #include <ModuleBase_ViewerPrs.h>
36 #include <ModuleBase_OperationDescription.h>
37
38 #include <AIS_Shape.hxx>
39
40 #ifndef HAVE_SALOME
41 #include "AppElements_Command.h"
42 #else
43 #include "XGUI_SalomeConnector.h"
44 #endif
45
46 XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop)
47     : ModuleBase_IWorkshop(theWorkshop),
48       myWorkshop(theWorkshop)
49 {
50   XGUI_SelectionMgr* aSelector = myWorkshop->selector();
51   connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
52 }
53
54 XGUI_ModuleConnector::~XGUI_ModuleConnector()
55 {
56 }
57
58 ModuleBase_ISelection* XGUI_ModuleConnector::selection() const
59 {
60   return myWorkshop->selector()->selection();
61 }
62
63 ModuleBase_IModule* XGUI_ModuleConnector::module() const
64 {
65   return myWorkshop->module();
66 }
67
68 ModuleBase_IViewer* XGUI_ModuleConnector::viewer() const
69 {
70   return myWorkshop->viewer();
71 }
72
73 ModuleBase_IPropertyPanel* XGUI_ModuleConnector::propertyPanel() const
74 {
75   return myWorkshop->propertyPanel();
76 }
77
78 ModuleBase_IErrorMgr* XGUI_ModuleConnector::errorMgr() const
79 {
80   return myWorkshop->errorMgr();
81 }
82
83 ModuleBase_ISelectionActivate* XGUI_ModuleConnector::selectionActivate() const
84 {
85   return myWorkshop->selectionActivate();
86 }
87
88 ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const
89 {
90   return myWorkshop->operationMgr()->currentOperation();
91 }
92
93
94 QObjectPtrList XGUI_ModuleConnector::activeObjects(const QObjectPtrList& theObjList) const
95 {
96   QObjectPtrList aActiveOPbjects;
97   ModuleBase_IModule* aModule = myWorkshop->module();
98   // Activate objects only which can be activated
99   foreach (ObjectPtr aObj, theObjList) {
100     if (aModule->canActivateSelection(aObj))
101       aActiveOPbjects.append(aObj);
102   }
103   return aActiveOPbjects;
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   XGUI_ObjectsBrowser* aBrowser = myWorkshop->objectBrowser();
123   if (theValues.isEmpty()) {
124     myWorkshop->selector()->clearSelection();
125     aBrowser->treeView()->clearSelection();
126   } else {
127     aDisp->setSelected(theValues);
128     // Synchronise the selection with Object browser
129     QObjectPtrList anObjects;
130     foreach(ModuleBase_ViewerPrsPtr aVal, theValues) {
131       anObjects.append(aVal->object());
132     }
133     bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
134     aBrowser->setObjectsSelected(anObjects);
135     myWorkshop->objectBrowser()->blockSignals(aBlocked);
136   }
137 }
138
139 void XGUI_ModuleConnector::setStatusBarMessage(const QString& theMessage)
140 {
141   myWorkshop->setStatusBarMessage(theMessage);
142 }
143
144 bool XGUI_ModuleConnector::canStartOperation(QString theId, bool& isCommitted)
145 {
146   return myWorkshop->operationMgr()->canStartOperation(theId, isCommitted);
147 }
148
149 void XGUI_ModuleConnector::processLaunchOperation(ModuleBase_Operation* theOperation)
150 {
151   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
152
153   if (anOperationMgr->startOperation(theOperation)) {
154     ModuleBase_OperationFeature* aFOperation =
155       dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
156     if (aFOperation) {
157       workshop()->propertyPanel()->updateContentWidget(aFOperation->feature());
158       workshop()->propertyPanel()->createContentPanel(aFOperation->feature());
159     }
160     if (!theOperation->getDescription()->hasXmlRepresentation()) {
161       if (theOperation->commit())
162         workshop()->updateCommandStatus();
163     }
164   }
165 }
166
167 ModuleBase_Operation* XGUI_ModuleConnector::findStartedOperation(const QString& theId)
168 {
169   return myWorkshop->operationMgr()->findOperation(theId);
170 }
171
172 bool XGUI_ModuleConnector::canStopOperation(ModuleBase_Operation* theOperation)
173 {
174   return myWorkshop->operationMgr()->canStopOperation(theOperation);
175 }
176
177 void XGUI_ModuleConnector::stopOperation(ModuleBase_Operation* theOperation,
178                                          bool& isCommitted)
179 {
180   myWorkshop->operationMgr()->stopOperation(theOperation, isCommitted);
181 }
182
183 void XGUI_ModuleConnector::updateCommandStatus()
184 {
185   myWorkshop->updateCommandStatus();
186 }
187
188 QMainWindow* XGUI_ModuleConnector::desktop() const
189 {
190   return myWorkshop->desktop();
191 }
192
193 bool XGUI_ModuleConnector::hasSHIFTPressed() const
194 {
195   return myWorkshop->operationMgr()->hasSHIFTPressed();
196 }
197
198 std::shared_ptr<Config_FeatureMessage> XGUI_ModuleConnector::featureInfo(const QString& theId) const
199 {
200 #ifdef HAVE_SALOME
201   return myWorkshop->salomeConnector()->featureInfo(theId);
202 #else
203   AppElements_Command* aAction =
204     dynamic_cast<AppElements_Command*>(myWorkshop->actionsMgr()->action(theId));
205   if (aAction)
206     return aAction->featureMessage();
207   return std::shared_ptr<Config_FeatureMessage>();
208 #endif
209 }