Salome HOME
1. Check the owner is already selected and do not call for it AddOrRemoveSelected,
[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 #include <AppElements_MainWindow.h>
13
14 #include <ModelAPI_Feature.h>
15 #include <ModelAPI_Session.h>
16 #include <ModelAPI_AttributeDocRef.h>
17 #include <ModelAPI_Data.h>
18 #include <ModelAPI_Result.h>
19 #include <ModelAPI_Object.h>
20
21 XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent)
22     : QObject(theParent),
23       myWorkshop(theParent)
24 {
25   mySelection = new XGUI_Selection(myWorkshop);
26 }
27
28 XGUI_SelectionMgr::~XGUI_SelectionMgr()
29 {
30   delete mySelection;
31 }
32
33 //**************************************************************
34 void XGUI_SelectionMgr::connectViewers()
35 {
36   connect(myWorkshop->objectBrowser(), SIGNAL(selectionChanged()), this,
37           SLOT(onObjectBrowserSelection()));
38
39   //Connect to other viewers
40   connect(myWorkshop->viewer(), SIGNAL(selectionChanged()), this, SLOT(onViewerSelection()));
41 }
42
43 //**************************************************************
44 void XGUI_SelectionMgr::setSelectedOwners(const SelectMgr_IndexedMapOfOwner& theSelectedOwners,
45                                           bool isUpdateViewer)
46 {
47   SelectMgr_IndexedMapOfOwner aSelectedOwners;
48   selection()->selectedOwners(aSelectedOwners);
49
50   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
51   for  (Standard_Integer i = 1, n = theSelectedOwners.Extent(); i <= n; i++)  {
52     Handle(SelectMgr_EntityOwner) anOwner = theSelectedOwners(i);
53     if (aSelectedOwners.FindIndex(anOwner) > 0)
54       continue;
55
56     aContext->AddOrRemoveSelected(anOwner, isUpdateViewer);
57   }
58 }
59
60 //**************************************************************
61 void XGUI_SelectionMgr::onObjectBrowserSelection()
62 {
63   QObjectPtrList aObjects = myWorkshop->objectBrowser()->selectedObjects();
64   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
65   aDisplayer->setSelected(aObjects);
66   emit selectionChanged();
67 }
68
69 //**************************************************************
70 void XGUI_SelectionMgr::onViewerSelection()
71 {
72   QObjectPtrList aFeatures;
73   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
74   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
75     Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
76     ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
77     if (aResult)
78       aFeatures.append(aResult);
79   }
80   bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
81   myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
82   myWorkshop->objectBrowser()->blockSignals(aBlocked);
83
84   emit selectionChanged();
85 }
86
87 //**************************************************************
88 /*QFeatureList XGUI_SelectionMgr::selectedFeatures() const 
89  { 
90  return myWorkshop->objectBrowser()->selectedFeatures(); 
91  }
92
93  //**************************************************************
94  QModelIndexList XGUI_SelectionMgr::selectedIndexes() const 
95  { 
96  return myWorkshop->objectBrowser()->selectedIndexes();
97  }
98
99  //**************************************************************
100  void XGUI_SelectionMgr::selectedAISObjects(AIS_ListOfInteractive& theList) const
101  {
102  Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
103  theList.Clear();
104  for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
105  theList.Append(aContext->SelectedInteractive());
106  }
107
108  //**************************************************************
109  void XGUI_SelectionMgr::selectedShapes(NCollection_List<TopoDS_Shape>& theList) const
110  {
111  theList.Clear();
112  Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
113  for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
114  TopoDS_Shape aShape = aContext->SelectedShape();
115  if (!aShape.IsNull())
116  theList.Append(aShape);
117  }
118  }*/