Salome HOME
Issue #1015: The validate icon must be greyed and inactive instead of red and active
[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   XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
36 }
37
38 XGUI_ModuleConnector::~XGUI_ModuleConnector()
39 {
40 }
41
42 ModuleBase_ISelection* XGUI_ModuleConnector::selection() const
43 {
44   return myWorkshop->selector()->selection();
45 }
46
47 ModuleBase_IModule* XGUI_ModuleConnector::module() const
48 {
49   return myWorkshop->module();
50 }
51
52 ModuleBase_IViewer* XGUI_ModuleConnector::viewer() const
53 {
54   return myWorkshop->viewer();
55 }
56
57 ModuleBase_IPropertyPanel* XGUI_ModuleConnector::propertyPanel() const
58 {
59   return myWorkshop->propertyPanel();
60 }
61
62 ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const
63 {
64   return myWorkshop->operationMgr()->currentOperation();
65 }
66
67
68 QObjectPtrList XGUI_ModuleConnector::activeObjects(const QObjectPtrList& theObjList) const
69 {
70   QObjectPtrList aActiveOPbjects;
71   ModuleBase_IModule* aModule = myWorkshop->module();
72   // Activate objects only which can be activated
73   foreach (ObjectPtr aObj, theObjList) {
74     if (aModule->canActivateSelection(aObj))
75       aActiveOPbjects.append(aObj);
76   }
77   return aActiveOPbjects;
78 }
79
80 void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
81 {
82   XGUI_Displayer* aDisp = myWorkshop->displayer();
83   aDisp->activateObjects(theTypes, activeObjects(aDisp->displayedObjects()));
84 }
85
86 void XGUI_ModuleConnector::deactivateSubShapesSelection()
87 {
88   // Clear selection modes
89   activateModuleSelectionModes();
90 }
91
92 void XGUI_ModuleConnector::activateModuleSelectionModes()
93 {
94   XGUI_Displayer* aDisp = myWorkshop->displayer();
95   myWorkshop->activateObjectsSelection(activeObjects(aDisp->displayedObjects()));
96 }
97
98 AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
99 {
100   XGUI_Displayer* aDisp = myWorkshop->displayer();
101   return aDisp->getAISObject(theObject);
102 }
103
104 ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
105 {
106   XGUI_Displayer* aDisp = myWorkshop->displayer();
107   ObjectPtr anObject = aDisp->getObject(theAIS);
108   return anObject;
109 }
110
111 void XGUI_ModuleConnector::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues)
112 {
113   XGUI_Displayer* aDisp = myWorkshop->displayer();
114   if (theValues.isEmpty()) {
115     myWorkshop->selector()->clearSelection();
116   } else {
117     aDisp->setSelected(theValues);
118   }    
119 }
120
121 #include <QMainWindow>
122 #include <QStatusBar>
123 void XGUI_ModuleConnector::setStatusBarMessage(const QString& theMessage)
124 {
125 #ifdef HAVE_SALOME
126   //return myWorkshop->salomeConnector()->featureInfo(theId);
127 #else
128   QMainWindow* aDesktop = desktop();
129   aDesktop->statusBar()->showMessage(theMessage);
130
131 #endif
132 }
133
134 bool XGUI_ModuleConnector::canStartOperation(QString theId)
135 {
136   return myWorkshop->operationMgr()->canStartOperation(theId);
137 }
138
139 ModuleBase_Operation* XGUI_ModuleConnector::findStartedOperation(const QString& theId)
140 {
141   return myWorkshop->operationMgr()->findOperation(theId);
142 }
143
144 bool XGUI_ModuleConnector::canStopOperation(ModuleBase_Operation* theOperation)
145 {
146   return myWorkshop->operationMgr()->canStopOperation(theOperation);
147 }
148
149 void XGUI_ModuleConnector::abortOperation(ModuleBase_Operation* theOperation)
150 {
151   myWorkshop->operationMgr()->abortOperation(theOperation);
152 }
153
154 void XGUI_ModuleConnector::updateCommandStatus()
155 {
156   myWorkshop->updateCommandStatus();
157 }
158
159 QMainWindow* XGUI_ModuleConnector::desktop() const 
160
161   return myWorkshop->desktop(); 
162 }
163
164
165 std::shared_ptr<Config_FeatureMessage> XGUI_ModuleConnector::featureInfo(const QString& theId) const
166 {
167 #ifdef HAVE_SALOME
168   return myWorkshop->salomeConnector()->featureInfo(theId);
169 #else 
170   AppElements_Command* aAction = 
171     dynamic_cast<AppElements_Command*>(myWorkshop->actionsMgr()->action(theId));
172   if (aAction)
173     return aAction->featureMessage();
174   return std::shared_ptr<Config_FeatureMessage>();
175 #endif
176 }