1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: XGUI_ModuleConnector.cpp
4 // Created: 3 June 2014
5 // Author: Vitaly Smetannikov
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"
16 #include <ModuleBase_IModule.h>
18 #include <AIS_Shape.hxx>
21 XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop)
22 : ModuleBase_IWorkshop(theWorkshop),
23 myWorkshop(theWorkshop)
25 XGUI_SelectionMgr* aSelector = myWorkshop->selector();
26 connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
28 XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
30 //myDocumentShapeFilter = new ModuleBase_ShapeDocumentFilter(this);
33 XGUI_ModuleConnector::~XGUI_ModuleConnector()
35 //myDocumentShapeFilter.Nullify();
38 ModuleBase_ISelection* XGUI_ModuleConnector::selection() const
40 return myWorkshop->selector()->selection();
43 ModuleBase_IModule* XGUI_ModuleConnector::module() const
45 return myWorkshop->module();
48 ModuleBase_IViewer* XGUI_ModuleConnector::viewer() const
50 return myWorkshop->viewer();
53 ModuleBase_IPropertyPanel* XGUI_ModuleConnector::propertyPanel() const
55 return myWorkshop->propertyPanel();
58 ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const
60 return myWorkshop->operationMgr()->currentOperation();
64 QObjectPtrList XGUI_ModuleConnector::activeObjects(const QObjectPtrList& theObjList) const
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);
73 return aActiveOPbjects;
76 void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
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
84 foreach(int aType, theTypes) {
85 if (aType > TopAbs_SHAPE)
88 aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)aType));
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);
95 void XGUI_ModuleConnector::deactivateSubShapesSelection()
97 XGUI_Displayer* aDisp = myWorkshop->displayer();
98 // Clear selection modes
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);
114 AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
116 XGUI_Displayer* aDisp = myWorkshop->displayer();
117 return aDisp->getAISObject(theObject);
120 ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
122 XGUI_Displayer* aDisp = myWorkshop->displayer();
123 return aDisp->getObject(theAIS);
126 void XGUI_ModuleConnector::setSelected(const QList<ModuleBase_ViewerPrs>& theValues)
128 XGUI_Displayer* aDisp = myWorkshop->displayer();
129 if (theValues.isEmpty()) {
130 myWorkshop->selector()->clearSelection();
132 aDisp->setSelected(theValues);
136 bool XGUI_ModuleConnector::canStartOperation(QString theId)
138 return myWorkshop->operationMgr()->canStartOperation(theId);