]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_ModuleConnector.cpp
Salome HOME
9fab49052887fc88866bd1c95b8095b55117d4ee
[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   XGUI_Displayer* aDisp = myWorkshop->displayer();
81   aDisp->activateObjects(theTypes, activeObjects(aDisp->displayedObjects()));
82 }
83
84 void XGUI_ModuleConnector::deactivateSubShapesSelection()
85 {
86   // Clear selection modes
87   activateModuleSelectionModes();
88 }
89
90 void XGUI_ModuleConnector::activateModuleSelectionModes()
91 {
92   XGUI_Displayer* aDisp = myWorkshop->displayer();
93   myWorkshop->activateObjectsSelection(activeObjects(aDisp->displayedObjects()));
94 }
95
96 AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
97 {
98   XGUI_Displayer* aDisp = myWorkshop->displayer();
99   return aDisp->getAISObject(theObject);
100 }
101
102 ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
103 {
104   XGUI_Displayer* aDisp = myWorkshop->displayer();
105   ObjectPtr anObject = aDisp->getObject(theAIS);
106   return anObject;
107 }
108
109 void XGUI_ModuleConnector::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues)
110 {
111   XGUI_Displayer* aDisp = myWorkshop->displayer();
112   if (theValues.isEmpty()) {
113     myWorkshop->selector()->clearSelection();
114   } else {
115     aDisp->setSelected(theValues);
116   }    
117 }
118
119 void XGUI_ModuleConnector::setStatusBarMessage(const QString& theMessage)
120 {
121   myWorkshop->setStatusBarMessage(theMessage);
122 }
123
124 bool XGUI_ModuleConnector::canStartOperation(QString theId)
125 {
126   return myWorkshop->operationMgr()->canStartOperation(theId);
127 }
128
129 ModuleBase_Operation* XGUI_ModuleConnector::findStartedOperation(const QString& theId)
130 {
131   return myWorkshop->operationMgr()->findOperation(theId);
132 }
133
134 bool XGUI_ModuleConnector::canStopOperation(ModuleBase_Operation* theOperation)
135 {
136   return myWorkshop->operationMgr()->canStopOperation(theOperation);
137 }
138
139 void XGUI_ModuleConnector::abortOperation(ModuleBase_Operation* theOperation)
140 {
141   myWorkshop->operationMgr()->abortOperation(theOperation);
142 }
143
144 void XGUI_ModuleConnector::updateCommandStatus()
145 {
146   myWorkshop->updateCommandStatus();
147 }
148
149 QMainWindow* XGUI_ModuleConnector::desktop() const 
150
151   return myWorkshop->desktop(); 
152 }
153
154
155 std::shared_ptr<Config_FeatureMessage> XGUI_ModuleConnector::featureInfo(const QString& theId) const
156 {
157 #ifdef HAVE_SALOME
158   return myWorkshop->salomeConnector()->featureInfo(theId);
159 #else 
160   AppElements_Command* aAction = 
161     dynamic_cast<AppElements_Command*>(myWorkshop->actionsMgr()->action(theId));
162   if (aAction)
163     return aAction->featureMessage();
164   return std::shared_ptr<Config_FeatureMessage>();
165 #endif
166 }