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