]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_SelectionMgr.cpp
Salome HOME
A correction to check modified value in extrusion cut/sketch/etc operations.
[modules/shaper.git] / src / XGUI / XGUI_SelectionMgr.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 #include "XGUI_SelectionMgr.h"
4
5 #include "XGUI_Workshop.h"
6 #include "XGUI_ObjectsBrowser.h"
7 #include "XGUI_SalomeConnector.h"
8 #include "XGUI_ViewerProxy.h"
9 #include "XGUI_Displayer.h"
10 #include "XGUI_Selection.h"
11
12 #ifndef HAVE_SALOME
13 #include <AppElements_MainWindow.h>
14 #endif
15
16 #include <ModelAPI_Feature.h>
17 #include <ModelAPI_Session.h>
18 #include <ModelAPI_AttributeDocRef.h>
19 #include <ModelAPI_Data.h>
20 #include <ModelAPI_Result.h>
21 #include <ModelAPI_Object.h>
22
23 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
24
25 XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent)
26     : QObject(theParent),
27       myWorkshop(theParent)
28 {
29   mySelection = new XGUI_Selection(myWorkshop);
30 }
31
32 XGUI_SelectionMgr::~XGUI_SelectionMgr()
33 {
34   delete mySelection;
35 }
36
37 //**************************************************************
38 void XGUI_SelectionMgr::connectViewers()
39 {
40   connect(myWorkshop->objectBrowser(), SIGNAL(selectionChanged()), this,
41           SLOT(onObjectBrowserSelection()));
42
43   //Connect to other viewers
44   connect(myWorkshop->viewer(), SIGNAL(selectionChanged()), this, SLOT(onViewerSelection()));
45 }
46
47 //**************************************************************
48 void XGUI_SelectionMgr::setSelectedOwners(const SelectMgr_IndexedMapOfOwner& theSelectedOwners,
49                                           bool isUpdateViewer)
50 {
51   SelectMgr_IndexedMapOfOwner aSelectedOwners;
52   selection()->selectedOwners(aSelectedOwners);
53
54   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
55   if (!aContext.IsNull()) {
56     for  (Standard_Integer i = 1, n = theSelectedOwners.Extent(); i <= n; i++)  {
57       Handle(SelectMgr_EntityOwner) anOwner = theSelectedOwners(i);
58       if (aSelectedOwners.FindIndex(anOwner) > 0)
59         continue;
60
61       aContext->AddOrRemoveSelected(anOwner, isUpdateViewer);
62     }
63   }
64 }
65
66 //**************************************************************
67 void XGUI_SelectionMgr::updateSelectedOwners(bool isUpdateViewer)
68 {
69   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
70   if (aContext.IsNull())
71     return;
72
73   const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
74
75   SelectMgr_IndexedMapOfOwner anOwnersToDeselect;
76
77   SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
78   for (; anIt.More(); anIt.Next()) {
79     Handle(SelectMgr_Filter) aFilter = anIt.Value();
80     for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
81       Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
82       if (!aFilter->IsOk(anOwner))
83         anOwnersToDeselect.Add(aContext->SelectedOwner());
84     }
85   }
86
87   setSelectedOwners(anOwnersToDeselect, false);
88
89   if (isUpdateViewer)
90     aContext->UpdateCurrentViewer();
91 }
92
93 //**************************************************************
94 void XGUI_SelectionMgr::onObjectBrowserSelection()
95 {
96   QList<ModuleBase_ViewerPrs> aSelectedPrs =
97              myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser);
98
99   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
100   aDisplayer->setSelected(aSelectedPrs);
101   emit selectionChanged();
102 }
103
104 //**************************************************************
105 void XGUI_SelectionMgr::onViewerSelection()
106 {
107   QObjectPtrList aFeatures;
108   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
109   if (!aContext.IsNull()) {
110     for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
111       Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
112       ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
113       if (aResult)
114         aFeatures.append(aResult);
115     }
116   }
117   bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
118   myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
119   myWorkshop->objectBrowser()->blockSignals(aBlocked);
120
121   emit selectionChanged();
122 }
123
124 //**************************************************************
125 void XGUI_SelectionMgr::clearSelection()
126 {
127   QObjectPtrList aFeatures;
128   bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
129   myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
130   myWorkshop->objectBrowser()->blockSignals(aBlocked);
131   
132   QList<ModuleBase_ViewerPrs> aSelectedPrs =
133              myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser);
134
135   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
136   aDisplayer->setSelected(aSelectedPrs);
137
138   emit selectionChanged();
139 }