Salome HOME
Issue #2806: Provide correct selection with Shift button when Multi selector widget...
[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 bool XGUI_ModuleConnector::isVisible(const ObjectPtr& theObject) const
113 {
114   XGUI_Displayer* aDisp = myWorkshop->displayer();
115   return aDisp->isVisible(theObject);
116 }
117
118
119 ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
120 {
121   XGUI_Displayer* aDisp = myWorkshop->displayer();
122   ObjectPtr anObject = aDisp->getObject(theAIS);
123   return anObject;
124 }
125
126 void XGUI_ModuleConnector::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues)
127 {
128   XGUI_Displayer* aDisp = myWorkshop->displayer();
129   XGUI_ObjectsBrowser* aBrowser = myWorkshop->objectBrowser();
130   if (theValues.isEmpty()) {
131     myWorkshop->selector()->clearSelection();
132     aBrowser->treeView()->clearSelection();
133   } else {
134     aDisp->setSelected(theValues);
135     // Synchronise the selection with Object browser
136     QObjectPtrList anObjects;
137     foreach(ModuleBase_ViewerPrsPtr aVal, theValues) {
138       anObjects.append(aVal->object());
139     }
140     aBrowser->setObjectsSelected(anObjects);
141   }
142 }
143
144 void XGUI_ModuleConnector::setStatusBarMessage(const QString& theMessage)
145 {
146   myWorkshop->setStatusBarMessage(theMessage);
147 }
148
149 bool XGUI_ModuleConnector::canStartOperation(QString theId, bool& isCommitted)
150 {
151   return myWorkshop->operationMgr()->canStartOperation(theId, isCommitted);
152 }
153
154 void XGUI_ModuleConnector::processLaunchOperation(ModuleBase_Operation* theOperation)
155 {
156   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
157
158   if (anOperationMgr->startOperation(theOperation)) {
159     ModuleBase_OperationFeature* aFOperation =
160       dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
161     if (aFOperation) {
162       workshop()->propertyPanel()->updateContentWidget(aFOperation->feature());
163       workshop()->propertyPanel()->createContentPanel(aFOperation->feature());
164     }
165     if (!theOperation->getDescription()->hasXmlRepresentation()) {
166       if (theOperation->commit())
167         workshop()->updateCommandStatus();
168     }
169   }
170 }
171
172 ModuleBase_Operation* XGUI_ModuleConnector::findStartedOperation(const QString& theId)
173 {
174   return myWorkshop->operationMgr()->findOperation(theId);
175 }
176
177 bool XGUI_ModuleConnector::canStopOperation(ModuleBase_Operation* theOperation)
178 {
179   return myWorkshop->operationMgr()->canStopOperation(theOperation);
180 }
181
182 void XGUI_ModuleConnector::stopOperation(ModuleBase_Operation* theOperation,
183                                          bool& isCommitted)
184 {
185   myWorkshop->operationMgr()->stopOperation(theOperation, isCommitted);
186 }
187
188 void XGUI_ModuleConnector::updateCommandStatus()
189 {
190   myWorkshop->updateCommandStatus();
191 }
192
193 QMainWindow* XGUI_ModuleConnector::desktop() const
194 {
195   return myWorkshop->desktop();
196 }
197
198 bool XGUI_ModuleConnector::hasSHIFTPressed() const
199 {
200   return myWorkshop->operationMgr()->hasSHIFTPressed();
201 }
202
203 std::shared_ptr<Config_FeatureMessage> XGUI_ModuleConnector::featureInfo(const QString& theId) const
204 {
205 #ifdef HAVE_SALOME
206   return myWorkshop->salomeConnector()->featureInfo(theId);
207 #else
208   AppElements_Command* aAction =
209     dynamic_cast<AppElements_Command*>(myWorkshop->actionsMgr()->action(theId));
210   if (aAction)
211     return aAction->featureMessage();
212   return std::shared_ptr<Config_FeatureMessage>();
213 #endif
214 }