Salome HOME
Merge branch 'Dev_1.2.0' of newgeom:newgeom.git into Dev_1.2.0
[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   //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_IPropertyPanel* XGUI_ModuleConnector::propertyPanel() const
54 {
55   return myWorkshop->propertyPanel();
56 }
57
58 ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const
59 {
60   return myWorkshop->operationMgr()->currentOperation();
61 }
62
63
64 void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
65 {
66   XGUI_Displayer* aDisp = myWorkshop->displayer();
67   // Close context if it was opened in order to clear stsndard selection modes
68   //aDisp->closeLocalContexts(false);
69   //aDisp->openLocalContext();
70   // Convert shape types to selection types
71   QIntList aModes;
72   foreach(int aType, theTypes) {
73     if (aType > TopAbs_SHAPE) 
74       aModes.append(aType);
75     else
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   // Clear selection modes
87   QIntList aModes;
88   // TODO: check on OCC6.9.0
89   // the module current active modes should not be deactivated in order to save the objects selected
90   // the deactivate object in the mode of selection leads to the object is deselected in the viewer.
91   // But, in OCC6.8.0 this deselection does not happened automatically. It is necessary to call
92   // ClearOutdatedSelection, but this method has an error in the realization, which should be fixed in
93   // the OCC6.9.0 release. Moreother, it is possible that ClearOutdatedSelection will be called inside
94   // Deactivate method of AIS_InteractiveContext. In this case, we need not call it.
95   module()->activeSelectionModes(aModes);
96   aDisp->activateObjects(aModes);
97   // The document limitation selection has to be only during operation
98   //aDisp->removeSelectionFilter(myDocumentShapeFilter);
99   //aDisp->closeLocalContexts(false);
100 }
101
102 AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
103 {
104   XGUI_Displayer* aDisp = myWorkshop->displayer();
105   return aDisp->getAISObject(theObject);
106 }
107
108 ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
109 {
110   XGUI_Displayer* aDisp = myWorkshop->displayer();
111   return aDisp->getObject(theAIS);
112 }
113
114 void XGUI_ModuleConnector::setSelected(const QObjectPtrList& theFeatures)
115 {
116   XGUI_Displayer* aDisp = myWorkshop->displayer();
117   if (theFeatures.isEmpty()) {
118     myWorkshop->selector()->clearSelection();
119   } else {
120     aDisp->setSelected(theFeatures);
121   }    
122 }
123
124 bool XGUI_ModuleConnector::canStartOperation(QString theId)
125 {
126   return myWorkshop->operationMgr()->canStartOperation(theId);
127 }
128