Salome HOME
Preparations for Split operation. It includes:
[modules/shaper.git] / src / XGUI / XGUI_ModuleConnector.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        XGUI_ModuleConnector.cpp
4 // Created:     3 June 2014
5 // Author:      Vitaly Smetannikov
6
7 #include "XGUI_ModuleConnector.h"
8 #include "XGUI_Workshop.h"
9 #include "XGUI_ViewerProxy.h"
10 #include "XGUI_SelectionMgr.h"
11 #include "XGUI_Selection.h"
12 #include "XGUI_OperationMgr.h"
13 #include "XGUI_Displayer.h"
14 #include "XGUI_PropertyPanel.h"
15 #include "XGUI_ActionsMgr.h"
16
17 #include <ModuleBase_IModule.h>
18 #include <ModuleBase_ViewerPrs.h>
19 #include <ModuleBase_OperationDescription.h>
20
21 #include <AIS_Shape.hxx>
22
23 #ifndef HAVE_SALOME
24 #include "AppElements_Command.h"
25 #else
26 #include "XGUI_SalomeConnector.h"
27 #endif
28
29 XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop)
30     : ModuleBase_IWorkshop(theWorkshop),
31       myWorkshop(theWorkshop)
32 {
33   XGUI_SelectionMgr* aSelector = myWorkshop->selector();
34   connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
35 }
36
37 XGUI_ModuleConnector::~XGUI_ModuleConnector()
38 {
39 }
40
41 ModuleBase_ISelection* XGUI_ModuleConnector::selection() const
42 {
43   return myWorkshop->selector()->selection();
44 }
45
46 ModuleBase_IModule* XGUI_ModuleConnector::module() const
47 {
48   return myWorkshop->module();
49 }
50
51 ModuleBase_IViewer* XGUI_ModuleConnector::viewer() const
52 {
53   return myWorkshop->viewer();
54 }
55
56 ModuleBase_IPropertyPanel* XGUI_ModuleConnector::propertyPanel() const
57 {
58   return myWorkshop->propertyPanel();
59 }
60
61 ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const
62 {
63   return myWorkshop->operationMgr()->currentOperation();
64 }
65
66
67 QObjectPtrList XGUI_ModuleConnector::activeObjects(const QObjectPtrList& theObjList) const
68 {
69   QObjectPtrList aActiveOPbjects;
70   ModuleBase_IModule* aModule = myWorkshop->module();
71   // Activate objects only which can be activated
72   foreach (ObjectPtr aObj, theObjList) {
73     if (aModule->canActivateSelection(aObj))
74       aActiveOPbjects.append(aObj);
75   }
76   return aActiveOPbjects;
77 }
78
79 void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
80 {
81   QIntList aTypes = theTypes;
82
83   XGUI_Displayer* aDisp = myWorkshop->displayer();
84   myWorkshop->module()->customSubShapesSelectionModes(aTypes);
85   aDisp->activateObjects(aTypes, activeObjects(aDisp->displayedObjects()));
86 }
87
88 void XGUI_ModuleConnector::deactivateSubShapesSelection()
89 {
90   // Clear selection modes
91   activateModuleSelectionModes();
92 }
93
94 void XGUI_ModuleConnector::activateModuleSelectionModes()
95 {
96   XGUI_Displayer* aDisp = myWorkshop->displayer();
97   myWorkshop->activateObjectsSelection(activeObjects(aDisp->displayedObjects()));
98 }
99
100 AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
101 {
102   XGUI_Displayer* aDisp = myWorkshop->displayer();
103   return aDisp->getAISObject(theObject);
104 }
105
106 ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
107 {
108   XGUI_Displayer* aDisp = myWorkshop->displayer();
109   ObjectPtr anObject = aDisp->getObject(theAIS);
110   return anObject;
111 }
112
113 void XGUI_ModuleConnector::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues)
114 {
115   XGUI_Displayer* aDisp = myWorkshop->displayer();
116   if (theValues.isEmpty()) {
117     myWorkshop->selector()->clearSelection();
118   } else {
119     aDisp->setSelected(theValues);
120   }    
121 }
122
123 void XGUI_ModuleConnector::setStatusBarMessage(const QString& theMessage)
124 {
125   myWorkshop->setStatusBarMessage(theMessage);
126 }
127
128 bool XGUI_ModuleConnector::canStartOperation(QString theId)
129 {
130   return myWorkshop->operationMgr()->canStartOperation(theId);
131 }
132
133 void XGUI_ModuleConnector::processLaunchOperation(ModuleBase_Operation* theOperation)
134 {
135   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
136
137   if (anOperationMgr->startOperation(theOperation)) {
138     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
139     if (aFOperation) {
140       workshop()->propertyPanel()->updateContentWidget(aFOperation->feature());
141       workshop()->propertyPanel()->createContentPanel(aFOperation->feature());
142     }
143     if (!theOperation->getDescription()->hasXmlRepresentation()) {
144       if (theOperation->commit())
145         workshop()->updateCommandStatus();
146     }
147   }
148 }
149
150 ModuleBase_Operation* XGUI_ModuleConnector::findStartedOperation(const QString& theId)
151 {
152   return myWorkshop->operationMgr()->findOperation(theId);
153 }
154
155 bool XGUI_ModuleConnector::canStopOperation(ModuleBase_Operation* theOperation)
156 {
157   return myWorkshop->operationMgr()->canStopOperation(theOperation);
158 }
159
160 void XGUI_ModuleConnector::stopOperation(ModuleBase_Operation* theOperation)
161 {
162   myWorkshop->operationMgr()->stopOperation(theOperation);
163 }
164
165 void XGUI_ModuleConnector::updateCommandStatus()
166 {
167   myWorkshop->updateCommandStatus();
168 }
169
170 QMainWindow* XGUI_ModuleConnector::desktop() const 
171
172   return myWorkshop->desktop(); 
173 }
174
175
176 std::shared_ptr<Config_FeatureMessage> XGUI_ModuleConnector::featureInfo(const QString& theId) const
177 {
178 #ifdef HAVE_SALOME
179   return myWorkshop->salomeConnector()->featureInfo(theId);
180 #else 
181   AppElements_Command* aAction = 
182     dynamic_cast<AppElements_Command*>(myWorkshop->actionsMgr()->action(theId));
183   if (aAction)
184     return aAction->featureMessage();
185   return std::shared_ptr<Config_FeatureMessage>();
186 #endif
187 }