Salome HOME
Merge branch 'Dev_1.2.0' of newgeom:newgeom 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 QObjectPtrList XGUI_ModuleConnector::activeObjects(const QObjectPtrList& theObjList) const
65 {
66   QObjectPtrList aActiveOPbjects;
67   ModuleBase_IModule* aModule = myWorkshop->module();
68   // Activate objects only which can be activated
69   foreach (ObjectPtr aObj, theObjList) {
70     if (aModule->canActivateSelection(aObj))
71       aActiveOPbjects.append(aObj);
72   }
73   return aActiveOPbjects;
74 }
75
76 void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
77 {
78   XGUI_Displayer* aDisp = myWorkshop->displayer();
79   // Close context if it was opened in order to clear stsndard selection modes
80   //aDisp->closeLocalContexts(false);
81   //aDisp->openLocalContext();
82   // Convert shape types to selection types
83   QIntList aModes;
84   foreach(int aType, theTypes) {
85     if (aType > TopAbs_SHAPE) 
86       aModes.append(aType);
87     else
88       aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)aType));
89   }
90   aDisp->activateObjects(aModes, activeObjects(aDisp->displayedObjects()));
91   //TODO: We have to open Local context because at neutral point filters don't work (bug 25340)
92   //aDisp->addSelectionFilter(myDocumentShapeFilter);
93 }
94
95 void XGUI_ModuleConnector::deactivateSubShapesSelection()
96 {
97   XGUI_Displayer* aDisp = myWorkshop->displayer();
98   // Clear selection modes
99   QIntList aModes;
100   // TODO: check on OCC6.9.0
101   // the module current active modes should not be deactivated in order to save the objects selected
102   // the deactivate object in the mode of selection leads to the object is deselected in the viewer.
103   // But, in OCC6.8.0 this deselection does not happened automatically. It is necessary to call
104   // ClearOutdatedSelection, but this method has an error in the realization, which should be fixed in
105   // the OCC6.9.0 release. Moreother, it is possible that ClearOutdatedSelection will be called inside
106   // Deactivate method of AIS_InteractiveContext. In this case, we need not call it.
107   module()->activeSelectionModes(aModes);
108   aDisp->activateObjects(aModes, activeObjects(aDisp->displayedObjects()));
109   // The document limitation selection has to be only during operation
110   //aDisp->removeSelectionFilter(myDocumentShapeFilter);
111   //aDisp->closeLocalContexts(false);
112 }
113
114 AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
115 {
116   XGUI_Displayer* aDisp = myWorkshop->displayer();
117   return aDisp->getAISObject(theObject);
118 }
119
120 ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
121 {
122   XGUI_Displayer* aDisp = myWorkshop->displayer();
123   return aDisp->getObject(theAIS);
124 }
125
126 void XGUI_ModuleConnector::setSelected(const QList<ModuleBase_ViewerPrs>& theValues)
127 {
128   XGUI_Displayer* aDisp = myWorkshop->displayer();
129   if (theValues.isEmpty()) {
130     myWorkshop->selector()->clearSelection();
131   } else {
132     aDisp->setSelected(theValues);
133   }    
134 }
135
136 bool XGUI_ModuleConnector::canStartOperation(QString theId)
137 {
138   return myWorkshop->operationMgr()->canStartOperation(theId);
139 }
140