Salome HOME
Merge branch 'BR_internationalization'
[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
20 #include <AIS_Shape.hxx>
21
22 #ifndef HAVE_SALOME
23 #include "AppElements_Command.h"
24 #else
25 #include "XGUI_SalomeConnector.h"
26 #endif
27
28 XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop)
29     : ModuleBase_IWorkshop(theWorkshop),
30       myWorkshop(theWorkshop)
31 {
32   XGUI_SelectionMgr* aSelector = myWorkshop->selector();
33   connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
34 }
35
36 XGUI_ModuleConnector::~XGUI_ModuleConnector()
37 {
38 }
39
40 ModuleBase_ISelection* XGUI_ModuleConnector::selection() const
41 {
42   return myWorkshop->selector()->selection();
43 }
44
45 ModuleBase_IModule* XGUI_ModuleConnector::module() const
46 {
47   return myWorkshop->module();
48 }
49
50 ModuleBase_IViewer* XGUI_ModuleConnector::viewer() const
51 {
52   return myWorkshop->viewer();
53 }
54
55 ModuleBase_IPropertyPanel* XGUI_ModuleConnector::propertyPanel() const
56 {
57   return myWorkshop->propertyPanel();
58 }
59
60 ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const
61 {
62   return myWorkshop->operationMgr()->currentOperation();
63 }
64
65
66 QObjectPtrList XGUI_ModuleConnector::activeObjects(const QObjectPtrList& theObjList) const
67 {
68   QObjectPtrList aActiveOPbjects;
69   ModuleBase_IModule* aModule = myWorkshop->module();
70   // Activate objects only which can be activated
71   foreach (ObjectPtr aObj, theObjList) {
72     if (aModule->canActivateSelection(aObj))
73       aActiveOPbjects.append(aObj);
74   }
75   return aActiveOPbjects;
76 }
77
78 void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
79 {
80   QIntList aTypes = theTypes;
81
82   XGUI_Displayer* aDisp = myWorkshop->displayer();
83   myWorkshop->module()->customSubShapesSelectionModes(aTypes);
84   aDisp->activateObjects(aTypes, activeObjects(aDisp->displayedObjects()));
85 }
86
87 void XGUI_ModuleConnector::deactivateSubShapesSelection()
88 {
89   // Clear selection modes
90   activateModuleSelectionModes();
91 }
92
93 void XGUI_ModuleConnector::activateModuleSelectionModes()
94 {
95   XGUI_Displayer* aDisp = myWorkshop->displayer();
96   myWorkshop->activateObjectsSelection(activeObjects(aDisp->displayedObjects()));
97 }
98
99 AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
100 {
101   XGUI_Displayer* aDisp = myWorkshop->displayer();
102   return aDisp->getAISObject(theObject);
103 }
104
105 ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
106 {
107   XGUI_Displayer* aDisp = myWorkshop->displayer();
108   ObjectPtr anObject = aDisp->getObject(theAIS);
109   return anObject;
110 }
111
112 void XGUI_ModuleConnector::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues)
113 {
114   XGUI_Displayer* aDisp = myWorkshop->displayer();
115   if (theValues.isEmpty()) {
116     myWorkshop->selector()->clearSelection();
117   } else {
118     aDisp->setSelected(theValues);
119   }    
120 }
121
122 void XGUI_ModuleConnector::setStatusBarMessage(const QString& theMessage)
123 {
124   myWorkshop->setStatusBarMessage(theMessage);
125 }
126
127 bool XGUI_ModuleConnector::canStartOperation(QString theId)
128 {
129   return myWorkshop->operationMgr()->canStartOperation(theId);
130 }
131
132 ModuleBase_Operation* XGUI_ModuleConnector::findStartedOperation(const QString& theId)
133 {
134   return myWorkshop->operationMgr()->findOperation(theId);
135 }
136
137 bool XGUI_ModuleConnector::canStopOperation(ModuleBase_Operation* theOperation)
138 {
139   return myWorkshop->operationMgr()->canStopOperation(theOperation);
140 }
141
142 void XGUI_ModuleConnector::abortOperation(ModuleBase_Operation* theOperation)
143 {
144   myWorkshop->operationMgr()->abortOperation(theOperation);
145 }
146
147 void XGUI_ModuleConnector::updateCommandStatus()
148 {
149   myWorkshop->updateCommandStatus();
150 }
151
152 QMainWindow* XGUI_ModuleConnector::desktop() const 
153
154   return myWorkshop->desktop(); 
155 }
156
157
158 std::shared_ptr<Config_FeatureMessage> XGUI_ModuleConnector::featureInfo(const QString& theId) const
159 {
160 #ifdef HAVE_SALOME
161   return myWorkshop->salomeConnector()->featureInfo(theId);
162 #else 
163   AppElements_Command* aAction = 
164     dynamic_cast<AppElements_Command*>(myWorkshop->actionsMgr()->action(theId));
165   if (aAction)
166     return aAction->featureMessage();
167   return std::shared_ptr<Config_FeatureMessage>();
168 #endif
169 }