Salome HOME
Redesign of operations architecture
[modules/shaper.git] / src / XGUI / XGUI_ModuleConnector.cpp
1 // File:        XGUI_ModuleConnector.cpp
2 // Created:     3 June 2014
3 // Author:      Vitaly Smetannikov
4
5 #include "XGUI_ModuleConnector.h"
6 #include "XGUI_Workshop.h"
7 #include "XGUI_ViewerProxy.h"
8 #include "XGUI_SelectionMgr.h"
9 #include "XGUI_Selection.h"
10 #include "XGUI_OperationMgr.h"
11 #include "XGUI_Displayer.h"
12
13 #include <AIS_Shape.hxx>
14
15
16 XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop)
17     : ModuleBase_IWorkshop(theWorkshop),
18       myWorkshop(theWorkshop)
19 {
20   XGUI_SelectionMgr* aSelector = myWorkshop->selector();
21   connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
22   
23   XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
24
25   connect(anOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)), 
26           SIGNAL(operationStarted(ModuleBase_Operation*)));
27   connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), 
28           SIGNAL(operationStopped(ModuleBase_Operation*)));
29   connect(anOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)), 
30           SIGNAL(operationResumed(ModuleBase_Operation*)));
31   connect(anOperationMgr, SIGNAL(operationComitted(ModuleBase_Operation*)), 
32           SIGNAL(operationComitted(ModuleBase_Operation*)));
33   connect(anOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)), 
34           SIGNAL(operationAborted(ModuleBase_Operation*)));
35
36   myDocumentShapeFilter = new ModuleBase_ShapeDocumentFilter(this);
37 }
38
39 XGUI_ModuleConnector::~XGUI_ModuleConnector()
40 {
41   myDocumentShapeFilter.Nullify();
42 }
43
44 ModuleBase_ISelection* XGUI_ModuleConnector::selection() const
45 {
46   return myWorkshop->selector()->selection();
47 }
48
49 ModuleBase_IModule* XGUI_ModuleConnector::module() const
50 {
51   return myWorkshop->module();
52 }
53
54 ModuleBase_IViewer* XGUI_ModuleConnector::viewer() const
55 {
56   return myWorkshop->viewer();
57 }
58
59 ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const
60 {
61   return myWorkshop->operationMgr()->currentOperation();
62 }
63
64
65 void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
66 {
67   XGUI_Displayer* aDisp = myWorkshop->displayer();
68   // Close context if it was opened in order to clear stsndard selection modes
69   aDisp->closeLocalContexts(false);
70   aDisp->openLocalContext();
71   // Convert shape types to selection types
72   QIntList aModes;
73   foreach(int aType, theTypes) {
74     aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)aType));
75   }
76   aDisp->activateObjectsOutOfContext(aModes);
77   //TODO: We have to open Local context because at neutral point filters don't work (bug 25340)
78   aDisp->addSelectionFilter(myDocumentShapeFilter);
79 }
80
81 void XGUI_ModuleConnector::deactivateSubShapesSelection()
82 {
83   XGUI_Displayer* aDisp = myWorkshop->displayer();
84   // The document limitation selection has to be only during operation
85   aDisp->removeSelectionFilter(myDocumentShapeFilter);
86   aDisp->closeLocalContexts(false);
87 }
88
89 AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
90 {
91   XGUI_Displayer* aDisp = myWorkshop->displayer();
92   return aDisp->getAISObject(theObject);
93 }
94
95 ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
96 {
97   XGUI_Displayer* aDisp = myWorkshop->displayer();
98   return aDisp->getObject(theAIS);
99 }
100
101 void XGUI_ModuleConnector::setSelected(const QObjectPtrList& theFeatures)
102 {
103   XGUI_Displayer* aDisp = myWorkshop->displayer();
104   aDisp->setSelected(theFeatures);
105 }
106
107 bool XGUI_ModuleConnector::canStartOperation(QString theId)
108 {
109   return myWorkshop->operationMgr()->canStartOperation(theId);
110 }