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