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