Salome HOME
Parameters management implementation
[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 #endif
25
26 XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop)
27     : ModuleBase_IWorkshop(theWorkshop),
28       myWorkshop(theWorkshop)
29 {
30   XGUI_SelectionMgr* aSelector = myWorkshop->selector();
31   connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
32   
33   XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
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 bool XGUI_ModuleConnector::canStartOperation(QString theId)
120 {
121   return myWorkshop->operationMgr()->canStartOperation(theId);
122 }
123
124 ModuleBase_Operation* XGUI_ModuleConnector::findStartedOperation(const QString& theId)
125 {
126   return myWorkshop->operationMgr()->findOperation(theId);
127 }
128
129 bool XGUI_ModuleConnector::canStopOperation(ModuleBase_Operation* theOperation)
130 {
131   return myWorkshop->operationMgr()->canStopOperation(theOperation);
132 }
133
134 void XGUI_ModuleConnector::abortOperation(ModuleBase_Operation* theOperation)
135 {
136   myWorkshop->operationMgr()->abortOperation(theOperation);
137 }
138
139 void XGUI_ModuleConnector::updateCommandStatus()
140 {
141   myWorkshop->updateCommandStatus();
142 }
143
144 QMainWindow* XGUI_ModuleConnector::desktop() const 
145
146   return myWorkshop->desktop(); 
147 }
148
149
150 std::shared_ptr<Config_FeatureMessage> XGUI_ModuleConnector::featureInfo(const QString& theId) const
151 {
152 #ifdef HAVE_SALOME
153   return myWorkshop->salomeConnector()->featureInfo(theId);
154 #else 
155   AppElements_Command* aAction = 
156     dynamic_cast<AppElements_Command*>(myWorkshop->actionsMgr()->action(theId));
157   if (aAction)
158     return aAction->featureMessage();
159   return std::shared_ptr<Config_FeatureMessage>();
160 #endif
161 }