Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
18 //
19
20 #include "XGUI_ModuleConnector.h"
21 #include "XGUI_Workshop.h"
22 #include "XGUI_ViewerProxy.h"
23 #include "XGUI_SelectionMgr.h"
24 #include "XGUI_Selection.h"
25 #include "XGUI_OperationMgr.h"
26 #include "XGUI_Displayer.h"
27 #include "XGUI_PropertyPanel.h"
28 #include "XGUI_ActionsMgr.h"
29 #include "XGUI_ErrorMgr.h"
30
31 #include <ModuleBase_IModule.h>
32 #include <ModuleBase_ViewerPrs.h>
33 #include <ModuleBase_OperationDescription.h>
34
35 #include <AIS_Shape.hxx>
36
37 #ifndef HAVE_SALOME
38 #include "AppElements_Command.h"
39 #else
40 #include "XGUI_SalomeConnector.h"
41 #endif
42
43 XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop)
44     : ModuleBase_IWorkshop(theWorkshop),
45       myWorkshop(theWorkshop)
46 {
47   XGUI_SelectionMgr* aSelector = myWorkshop->selector();
48   connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
49 }
50
51 XGUI_ModuleConnector::~XGUI_ModuleConnector()
52 {
53 }
54
55 ModuleBase_ISelection* XGUI_ModuleConnector::selection() const
56 {
57   return myWorkshop->selector()->selection();
58 }
59
60 ModuleBase_IModule* XGUI_ModuleConnector::module() const
61 {
62   return myWorkshop->module();
63 }
64
65 ModuleBase_IViewer* XGUI_ModuleConnector::viewer() const
66 {
67   return myWorkshop->viewer();
68 }
69
70 ModuleBase_IPropertyPanel* XGUI_ModuleConnector::propertyPanel() const
71 {
72   return myWorkshop->propertyPanel();
73 }
74
75 ModuleBase_IErrorMgr* XGUI_ModuleConnector::errorMgr() const
76 {
77   return myWorkshop->errorMgr();
78 }
79
80 ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const
81 {
82   return myWorkshop->operationMgr()->currentOperation();
83 }
84
85
86 QObjectPtrList XGUI_ModuleConnector::activeObjects(const QObjectPtrList& theObjList) const
87 {
88   QObjectPtrList aActiveOPbjects;
89   ModuleBase_IModule* aModule = myWorkshop->module();
90   // Activate objects only which can be activated
91   foreach (ObjectPtr aObj, theObjList) {
92     if (aModule->canActivateSelection(aObj))
93       aActiveOPbjects.append(aObj);
94   }
95   return aActiveOPbjects;
96 }
97
98 void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
99 {
100   QIntList aTypes = theTypes;
101
102   XGUI_Displayer* aDisp = myWorkshop->displayer();
103   myWorkshop->module()->customSubShapesSelectionModes(aTypes);
104   aDisp->activateObjects(aTypes, activeObjects(aDisp->displayedObjects()));
105 }
106
107 void XGUI_ModuleConnector::deactivateSubShapesSelection()
108 {
109   // Clear selection modes
110   activateModuleSelectionModes();
111 }
112
113 void XGUI_ModuleConnector::activateModuleSelectionModes()
114 {
115   XGUI_Displayer* aDisp = myWorkshop->displayer();
116   myWorkshop->activateObjectsSelection(activeObjects(aDisp->displayedObjects()));
117 }
118
119 AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
120 {
121   XGUI_Displayer* aDisp = myWorkshop->displayer();
122   return aDisp->getAISObject(theObject);
123 }
124
125 ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
126 {
127   XGUI_Displayer* aDisp = myWorkshop->displayer();
128   ObjectPtr anObject = aDisp->getObject(theAIS);
129   return anObject;
130 }
131
132 void XGUI_ModuleConnector::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues)
133 {
134   XGUI_Displayer* aDisp = myWorkshop->displayer();
135   if (theValues.isEmpty()) {
136     myWorkshop->selector()->clearSelection();
137   } else
138     aDisp->setSelected(theValues);
139 }
140
141 void XGUI_ModuleConnector::setStatusBarMessage(const QString& theMessage)
142 {
143   myWorkshop->setStatusBarMessage(theMessage);
144 }
145
146 bool XGUI_ModuleConnector::canStartOperation(QString theId, bool& isCommitted)
147 {
148   return myWorkshop->operationMgr()->canStartOperation(theId, isCommitted);
149 }
150
151 void XGUI_ModuleConnector::processLaunchOperation(ModuleBase_Operation* theOperation)
152 {
153   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
154
155   if (anOperationMgr->startOperation(theOperation)) {
156     ModuleBase_OperationFeature* aFOperation =
157       dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
158     if (aFOperation) {
159       workshop()->propertyPanel()->updateContentWidget(aFOperation->feature());
160       workshop()->propertyPanel()->createContentPanel(aFOperation->feature());
161     }
162     if (!theOperation->getDescription()->hasXmlRepresentation()) {
163       if (theOperation->commit())
164         workshop()->updateCommandStatus();
165     }
166   }
167 }
168
169 ModuleBase_Operation* XGUI_ModuleConnector::findStartedOperation(const QString& theId)
170 {
171   return myWorkshop->operationMgr()->findOperation(theId);
172 }
173
174 bool XGUI_ModuleConnector::canStopOperation(ModuleBase_Operation* theOperation)
175 {
176   return myWorkshop->operationMgr()->canStopOperation(theOperation);
177 }
178
179 void XGUI_ModuleConnector::stopOperation(ModuleBase_Operation* theOperation,
180                                          bool& isCommitted)
181 {
182   myWorkshop->operationMgr()->stopOperation(theOperation, isCommitted);
183 }
184
185 void XGUI_ModuleConnector::updateCommandStatus()
186 {
187   myWorkshop->updateCommandStatus();
188 }
189
190 QMainWindow* XGUI_ModuleConnector::desktop() const
191 {
192   return myWorkshop->desktop();
193 }
194
195
196 std::shared_ptr<Config_FeatureMessage> XGUI_ModuleConnector::featureInfo(const QString& theId) const
197 {
198 #ifdef HAVE_SALOME
199   return myWorkshop->salomeConnector()->featureInfo(theId);
200 #else
201   AppElements_Command* aAction =
202     dynamic_cast<AppElements_Command*>(myWorkshop->actionsMgr()->action(theId));
203   if (aAction)
204     return aAction->featureMessage();
205   return std::shared_ptr<Config_FeatureMessage>();
206 #endif
207 }