Salome HOME
1. CanStopOperation knows which operation is stopped. Scenario: Unpress Sketch in...
[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
16 #include <ModuleBase_IModule.h>
17
18 #include <AIS_Shape.hxx>
19
20
21 XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop)
22     : ModuleBase_IWorkshop(theWorkshop),
23       myWorkshop(theWorkshop)
24 {
25   XGUI_SelectionMgr* aSelector = myWorkshop->selector();
26   connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
27   
28   XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
29 }
30
31 XGUI_ModuleConnector::~XGUI_ModuleConnector()
32 {
33 }
34
35 ModuleBase_ISelection* XGUI_ModuleConnector::selection() const
36 {
37   return myWorkshop->selector()->selection();
38 }
39
40 ModuleBase_IModule* XGUI_ModuleConnector::module() const
41 {
42   return myWorkshop->module();
43 }
44
45 ModuleBase_IViewer* XGUI_ModuleConnector::viewer() const
46 {
47   return myWorkshop->viewer();
48 }
49
50 ModuleBase_IPropertyPanel* XGUI_ModuleConnector::propertyPanel() const
51 {
52   return myWorkshop->propertyPanel();
53 }
54
55 ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const
56 {
57   return myWorkshop->operationMgr()->currentOperation();
58 }
59
60
61 QObjectPtrList XGUI_ModuleConnector::activeObjects(const QObjectPtrList& theObjList) const
62 {
63   QObjectPtrList aActiveOPbjects;
64   ModuleBase_IModule* aModule = myWorkshop->module();
65   // Activate objects only which can be activated
66   foreach (ObjectPtr aObj, theObjList) {
67     if (aModule->canActivateSelection(aObj))
68       aActiveOPbjects.append(aObj);
69   }
70   return aActiveOPbjects;
71 }
72
73 void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
74 {
75   XGUI_Displayer* aDisp = myWorkshop->displayer();
76   aDisp->activateObjects(theTypes, activeObjects(aDisp->displayedObjects()));
77 }
78
79 void XGUI_ModuleConnector::deactivateSubShapesSelection()
80 {
81   // Clear selection modes
82   activateModuleSelectionModes();
83 }
84
85 void XGUI_ModuleConnector::activateModuleSelectionModes()
86 {
87   XGUI_Displayer* aDisp = myWorkshop->displayer();
88   QIntList aModes;
89   module()->activeSelectionModes(aModes);
90   aDisp->activateObjects(aModes, activeObjects(aDisp->displayedObjects()));
91 }
92
93 AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
94 {
95   XGUI_Displayer* aDisp = myWorkshop->displayer();
96   return aDisp->getAISObject(theObject);
97 }
98
99 ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
100 {
101   XGUI_Displayer* aDisp = myWorkshop->displayer();
102   ObjectPtr anObject = aDisp->getObject(theAIS);
103   return anObject;
104 }
105
106 void XGUI_ModuleConnector::setSelected(const QList<ModuleBase_ViewerPrs>& theValues)
107 {
108   XGUI_Displayer* aDisp = myWorkshop->displayer();
109   if (theValues.isEmpty()) {
110     myWorkshop->selector()->clearSelection();
111   } else {
112     aDisp->setSelected(theValues);
113   }    
114 }
115
116 bool XGUI_ModuleConnector::canStartOperation(QString theId)
117 {
118   return myWorkshop->operationMgr()->canStartOperation(theId);
119 }
120
121 ModuleBase_Operation* XGUI_ModuleConnector::findStartedOperation(const QString& theId)
122 {
123   return myWorkshop->operationMgr()->findOperation(theId);
124 }
125
126 bool XGUI_ModuleConnector::canStopOperation(ModuleBase_Operation* theOperation)
127 {
128   return myWorkshop->operationMgr()->canStopOperation(theOperation);
129 }
130
131 void XGUI_ModuleConnector::abortOperation(ModuleBase_Operation* theOperation)
132 {
133   myWorkshop->operationMgr()->abortOperation(theOperation);
134 }