Salome HOME
Provide preselection
[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     this, SIGNAL(operationStarted(ModuleBase_Operation*)));
27   connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), 
28     this, SIGNAL(operationStopped(ModuleBase_Operation*)));
29
30   myDocumentShapeFilter = new ModuleBase_ShapeDocumentFilter(this);
31 }
32
33 XGUI_ModuleConnector::~XGUI_ModuleConnector()
34 {
35   myDocumentShapeFilter.Nullify();
36 }
37
38 ModuleBase_ISelection* XGUI_ModuleConnector::selection() const
39 {
40   return myWorkshop->selector()->selection();
41 }
42
43 ModuleBase_IModule* XGUI_ModuleConnector::module() const
44 {
45   return myWorkshop->module();
46 }
47
48 ModuleBase_IViewer* XGUI_ModuleConnector::viewer() const
49 {
50   return myWorkshop->viewer();
51 }
52
53 ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const
54 {
55   return myWorkshop->operationMgr()->currentOperation();
56 }
57
58
59 void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
60 {
61   XGUI_Displayer* aDisp = myWorkshop->displayer();
62   aDisp->openLocalContext();
63   // Convert shape types to selection types
64   QIntList aModes;
65   foreach(int aType, theTypes) {
66     aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)aType));
67   }
68   aDisp->activateObjectsOutOfContext(aModes);
69   //TODO: We have to open Local context because at neutral point filters don't work (bug 25340)
70   aDisp->addSelectionFilter(myDocumentShapeFilter);
71 }
72
73 void XGUI_ModuleConnector::deactivateSubShapesSelection()
74 {
75   XGUI_Displayer* aDisp = myWorkshop->displayer();
76   // The document limitation selection has to be only during operation
77   aDisp->removeSelectionFilter(myDocumentShapeFilter);
78   aDisp->closeLocalContexts(false);
79 }
80
81 AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
82 {
83   XGUI_Displayer* aDisp = myWorkshop->displayer();
84   return aDisp->getAISObject(theObject);
85 }
86
87 ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
88 {
89   XGUI_Displayer* aDisp = myWorkshop->displayer();
90   return aDisp->getObject(theAIS);
91 }
92
93 void XGUI_ModuleConnector::setSelected(const QList<ObjectPtr>& theFeatures)
94 {
95   XGUI_Displayer* aDisp = myWorkshop->displayer();
96   aDisp->setSelected(theFeatures);
97 }