Salome HOME
Merge branch 'Results_Hierarchy'
[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     bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
141     aBrowser->setObjectsSelected(anObjects);
142     myWorkshop->objectBrowser()->blockSignals(aBlocked);
143   }
144 }
145
146 void XGUI_ModuleConnector::setStatusBarMessage(const QString& theMessage)
147 {
148   myWorkshop->setStatusBarMessage(theMessage);
149 }
150
151 bool XGUI_ModuleConnector::canStartOperation(QString theId, bool& isCommitted)
152 {
153   return myWorkshop->operationMgr()->canStartOperation(theId, isCommitted);
154 }
155
156 void XGUI_ModuleConnector::processLaunchOperation(ModuleBase_Operation* theOperation)
157 {
158   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
159
160   if (anOperationMgr->startOperation(theOperation)) {
161     ModuleBase_OperationFeature* aFOperation =
162       dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
163     if (aFOperation) {
164       workshop()->propertyPanel()->updateContentWidget(aFOperation->feature());
165       workshop()->propertyPanel()->createContentPanel(aFOperation->feature());
166     }
167     if (!theOperation->getDescription()->hasXmlRepresentation()) {
168       if (theOperation->commit())
169         workshop()->updateCommandStatus();
170     }
171   }
172 }
173
174 ModuleBase_Operation* XGUI_ModuleConnector::findStartedOperation(const QString& theId)
175 {
176   return myWorkshop->operationMgr()->findOperation(theId);
177 }
178
179 bool XGUI_ModuleConnector::canStopOperation(ModuleBase_Operation* theOperation)
180 {
181   return myWorkshop->operationMgr()->canStopOperation(theOperation);
182 }
183
184 void XGUI_ModuleConnector::stopOperation(ModuleBase_Operation* theOperation,
185                                          bool& isCommitted)
186 {
187   myWorkshop->operationMgr()->stopOperation(theOperation, isCommitted);
188 }
189
190 void XGUI_ModuleConnector::updateCommandStatus()
191 {
192   myWorkshop->updateCommandStatus();
193 }
194
195 QMainWindow* XGUI_ModuleConnector::desktop() const
196 {
197   return myWorkshop->desktop();
198 }
199
200 bool XGUI_ModuleConnector::hasSHIFTPressed() const
201 {
202   return myWorkshop->operationMgr()->hasSHIFTPressed();
203 }
204
205 std::shared_ptr<Config_FeatureMessage> XGUI_ModuleConnector::featureInfo(const QString& theId) const
206 {
207 #ifdef HAVE_SALOME
208   return myWorkshop->salomeConnector()->featureInfo(theId);
209 #else
210   AppElements_Command* aAction =
211     dynamic_cast<AppElements_Command*>(myWorkshop->actionsMgr()->action(theId));
212   if (aAction)
213     return aAction->featureMessage();
214   return std::shared_ptr<Config_FeatureMessage>();
215 #endif
216 }