ATLAS Offline Software
IVP13DSystem.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // //
7 // Implementation of class IVP13DSystem //
8 // //
9 // Author: Thomas Kittelmann <Thomas.Kittelmann@cern.ch> //
10 // //
11 // Initial version: April 2007 //
12 // //
14 
15 #include "VP1Base/IVP13DSystem.h"
17 #include "VP1Base/VP1Msg.h"
18 
19 #include <Inventor/nodes/SoCamera.h>
20 #include <Inventor/Qt/viewers/SoQtViewer.h>
21 
22 #include <QTimer>
23 
24 #include <iostream>
25 #include <map>
26 
27 //* Always use SoCooperativeSelections
28 //* A selection node should only appear in the subtree of just one system
29 
30 //___________________________________________________________________________________________________________
32 public:
33  // List of selection callbacks.
34  std::vector<SoSelectionPathCB *> _callbacks;
35  //camera lists:
36  std::set<SoCamera*> staticcameras;
37  std::set<SoQtViewer*> viewers;
38 
39  //(De)selection callbacks:
40  static void start_changeselection(void *userdata, SoSelection *sel);
41  static void finished_changeselection(void *userdata, SoSelection *sel);
42  static void made_selection( void * userdata, SoPath * path );
43  static void made_deselection( void * userdata, SoPath * path );
44  static void clickedoutside(void *userdata, SoCooperativeSelection *sel);
45 
46  static std::map<SoCooperativeSelection*,IVP13DSystem*> selection2system;
47  //We add the selection pointers as userdata, so selection2sys is
48  //used to get the system pointer(s) in the callback functions.
49 
50  QSet<SoCooperativeSelection *> selectionsWithDisabledNotifications;
51 
52  std::map<SoCooperativeSelection*,SoPathList> selection2lastpathlist;
54 };
55 
56 std::map<SoCooperativeSelection*,IVP13DSystem*> IVP13DSystem::Imp::selection2system;
57 
58 // Methods invoked upon selection / deselection (to be reimplemented in derived classes).
61 void IVP13DSystem::userChangedSelection(SoCooperativeSelection*, QSet<SoNode*>, QSet<SoPath*>) {}
63 
64 //___________________________________________________________________________________________________________
66 {
67  if (!selection) {
68  std::cout<<"IVP13DSystem::Imp::clickedoutside Error: Got null selection pointer!"<<std::endl;
69  return;
70  }
71  IVP13DSystem * system = dynamic_cast<IVP13DSystem *>(static_cast<IVP1System * >(userdata));
72  if (!system) {
73  std::cout<<"IVP13DSystem::Imp::clickedoutside Error: Could not find system pointer!"<<std::endl;
74  return;
75  }
76  if (system->m_d->selectionsWithDisabledNotifications.contains(selection))
77  return;
78  if (system->m_d->clickedoutsideScheduled)
79  return;
80  system->m_d->clickedoutsideScheduled = true;
81  QTimer::singleShot(0, system, SLOT(activateClickedOutside()));
82 }
83 
84 //___________________________________________________________________________________________________________
86 {
88  return;
91 }
92 
93 //___________________________________________________________________________________________________________
94 void IVP13DSystem::Imp::start_changeselection(void * userdata, SoSelection *sel)
95 {
97  if (!selection) {
98  std::cout<<"IVP13DSystem::Imp::start_changeselection Error: Could not find selection pointer!"<<std::endl;
99  return;
100  }
101 
102  if (selection->policy.getValue()==SoSelection::SINGLE)
103  return;
104 
105  IVP13DSystem * system = static_cast<IVP13DSystem *>(userdata);
106  if (!system) {
107  std::cout<<"IVP13DSystem::Imp::start_changeselection Error: Could not find system pointer!"<<std::endl;
108  return;
109  }
110 
111  if (system->m_d->selectionsWithDisabledNotifications.contains(selection))
112  return;
113 
114  system->m_d->selection2lastpathlist[selection] = *(selection->getList());
115 
116  //redraw and emission of itemFromSystemSelected() take place in finished_changeselection!
117 
118 }
119 
120 //___________________________________________________________________________________________________________
121 void IVP13DSystem::Imp::finished_changeselection(void *userdata, SoSelection *sel)
122 {
124  if (!selection) {
125  std::cout<<"IVP13DSystem::Imp::finished_changeselection Error: Could not find selection pointer!"<<std::endl;
126  return;
127  }
128 
129  IVP13DSystem * system = static_cast<IVP13DSystem *>(userdata);
130  if (!system) {
131  std::cout<<"IVP13DSystem::Imp::finished_changeselection Error: Could not find system pointer!"<<std::endl;
132  return;
133  }
134 
135  selection->touch(); // to redraw
136 
137  if (selection->policy.getValue()==SoSelection::SINGLE)
138  return;
139 
140  //Only take action when selection actually changed between start and finish:
141  if (system->m_d->selection2lastpathlist.find(selection)==system->m_d->selection2lastpathlist.end()) {
142  std::cout<<"IVP13DSystem::Imp::finished_changeselection Error: Could not find last selection path list!"<<std::endl;
143  return;
144  }
145 
146  int nlastselection = system->m_d->selection2lastpathlist[selection].getLength();
147  bool changed = false;
148  if (nlastselection!=selection->getList()->getLength()) {
149  changed = true;
150  } else {
151  for (int i = 0; i < selection->getList()->getLength(); ++i) {
152  if (system->m_d->selection2lastpathlist[selection].get(i)!=selection->getList()->get(i)) {
153  changed = true;
154  break;
155  }
156  }
157  }
158  if (!changed) {
159  system->m_d->selection2lastpathlist.erase(system->m_d->selection2lastpathlist.find(selection));
160  return;
161  }
162 
163  //To avoid having different systems emit itemFromSystemSelected due
164  //to one user interaction, we only emit here if the action resulted
165  //in an increase in the number of selected objects:
166  if (selection->getList()->getLength()>nlastselection) {
167  system->itemFromSystemSelected();//Emit this signal
168  }
169 
170  if (system->m_d->selectionsWithDisabledNotifications.contains(selection))
171  return;
172 
173  QSet<SoNode*> selnodes;
174  QSet<SoPath*> selpaths;
175  int n = selection->getList()->getLength();
176  for (int i = 0; i < n; ++i) {
177  SoPath * path = (*(selection->getList()))[i];
178  if (!path)
179  continue;
180  SoFullPath *fPath = static_cast<SoFullPath *>(path);
181  SoNode * node = fPath->getTail();
182  if (!node)
183  continue;
184  selpaths << fPath;
185  selnodes << node;
186  }
187 
188  system->userChangedSelection(selection,selnodes,selpaths);
189 }
190 
191 //___________________________________________________________________________________________________________
192 void IVP13DSystem::Imp::made_selection( void * userdata, SoPath * path )
193 {
194  SoFullPath *fPath = static_cast<SoFullPath *>(path);
195  if (!fPath)
196  return;
197  SoNode *selectedNode = fPath->getTail();
198  if (!selectedNode)
199  return;
200  SoCooperativeSelection * selection = static_cast<SoCooperativeSelection*>(userdata);
201  if (!selection) {
202  std::cout<<"IVP13DSystem::Imp::made_selection Error: Could not find selection pointer!"<<std::endl;
203  return;
204  }
205  if (selection->policy.getValue()!=SoSelection::SINGLE)
206  return;
207 
209  std::cout << "IVP13DSystem::Imp::made_selection Error: Could not find system pointer!"<<std::endl;
210  return;
211  }
212 
214 
215  system->itemFromSystemSelected();//Emit this signal
216 
217  if (system->m_d->selectionsWithDisabledNotifications.contains(selection))
218  return;
219 
220 
221  system->userSelectedSingleNode(selection,selectedNode,fPath);
222 
223  //redraw takes place in finished_changeselection!
224 }
225 
226 //___________________________________________________________________________________________________________
227 void IVP13DSystem::Imp::made_deselection( void * userdata, SoPath * path )
228 {
229  SoFullPath *fPath = static_cast<SoFullPath *>(path);
230  if (!fPath)
231  return;
232  SoNode *deselectedNode = fPath->getTail();
233  if (!deselectedNode)
234  return;
235 
236  SoCooperativeSelection * selection = static_cast<SoCooperativeSelection*>(userdata);
237  if (!selection) {
238  std::cout<<"IVP13DSystem::Imp::made_deselection Error: Could not find selection pointer!"<<std::endl;
239  return;
240  }
241  if (selection->policy.getValue()!=SoSelection::SINGLE)
242  return;
243 
245  std::cout << "IVP13DSystem::Imp::made_deselection Error: Could not find system pointer!"<<std::endl;
246  return;
247  }
248 
250  if (system->m_d->selectionsWithDisabledNotifications.contains(selection))
251  return;
252 
253  system->userDeselectedSingleNode(selection,deselectedNode,fPath);
254 }
255 
256 //___________________________________________________________________________________________________________
258 {
259  if (!selection) {
260  message("registerSelectionNode Error: NULL selection pointer!");
261  return;
262  }
264  message("registerSelectionNode Error: Trying to register selection node more than once!");
265  return;
266  }
267 
268  selection->addSelectionCallback( Imp::made_selection, selection );
269  selection->addDeselectionCallback( Imp::made_deselection, selection );
270  selection->addStartCallback( Imp::start_changeselection, this );
271  selection->addFinishCallback( Imp::finished_changeselection, this );
272  selection->addClickOutsideCallback( Imp::clickedoutside, this );
273 
275  selection->ref();
276 
277  messageVerbose("selection node registered");
278 }
279 
280 //___________________________________________________________________________________________________________
282 {
283  if (!selection) {
284  message("unregisterSelectionNode Error: NULL selection pointer!");
285  return;
286  }
288  message("registerSelectionNode Error: Trying to unregister unknown selection node!");
289  return;
290  }
291 
292  selection->removeSelectionCallback( Imp::made_selection, selection );
293  selection->removeDeselectionCallback( Imp::made_deselection, selection );
294  selection->removeStartCallback( Imp::start_changeselection, this );
295  selection->removeFinishCallback( Imp::finished_changeselection, this );
296  selection->removeClickOutsideCallback( Imp::clickedoutside, this );
297 
301  selection->unref();
302 
303  messageVerbose("selection node unregistered");
304 
305 }
306 
307 
308 
309 //___________________________________________________________________________________________________________
311 {
312  if (!selection) {
313  message("setUserSelectionNotificationsEnabled Error: NULL selection pointer!");
314  return;
315  }
317  message("setUserSelectionNotificationsEnabled Error: Called for selection which was never registered!");
318  return;
319  }
320  if (enabled != m_d->selectionsWithDisabledNotifications.contains(selection))
321  return;
322 
323  if (enabled)
325  else
327 
328 }
329 
330 //___________________________________________________________________________________________________________
332 {
334  for (it = Imp::selection2system.begin(); it!=itE;++it) {
335  if (it->second!=this)
336  continue;
337  if (it->first!=exception_sel) {
338  if (it->first->policy.getValue()!=SoCooperativeSelection::SINGLE) {
339  Imp::start_changeselection(this, it->first);
340  it->first->deselectAll();
341  Imp::finished_changeselection(this, it->first);
342  } else {
343  if (it->first->getList()->getLength()==1) {
344  Imp::start_changeselection(this, it->first);
345  SoPath * path = static_cast<SoPath*>(it->first->getList()->get(0));
346  Imp::made_deselection(it->first,path);
347  it->first->deselectAll();
348  Imp::finished_changeselection(this, it->first);
349  }
350  }
351  }
352  }
353 }
354 
355 //___________________________________________________________________________________________________________
356 IVP13DSystem::IVP13DSystem( const QString & name, const QString & information, const QString & contact_info):
358 {
360  m_d->clickedoutsideScheduled = false;
361 }
362 
363 //___________________________________________________________________________________________________________
365 {
366  messageDebug("~IVP13DSystem()");
367 
368  m_d->selection2lastpathlist.clear();
369 
370  //Unregister all nodes for this system:
371  std::set<SoCooperativeSelection*> sel2unregister;
373  for (it = Imp::selection2system.begin();it!=itE;++it)
374  if (it->second == this)
375  sel2unregister.insert(it->first);
376  std::set<SoCooperativeSelection*>::iterator itSel, itSelE = sel2unregister.end();
377 
378  for (itSel = sel2unregister.begin();itSel!=itSelE;++itSel) {
379  unregisterSelectionNode(*itSel);
380  }
381 
382  messageDebug("Unregistered all nodes. Unref all camera pointers...");
383 
384  //Unref all camera pointers:
385  std::set<SoCamera*> ::iterator itCam, itCamE = m_d->staticcameras.end();
386  for (itCam = m_d->staticcameras.begin();itCam!=itCamE;++itCam)
387  (*itCam)->unref();
388 
389  messageDebug("Unref all camera pointers: done.");
390 
391  delete m_d; m_d=0;
392 }
393 
394 //___________________________________________________________________________________________________________
395 std::set<SoCamera*> IVP13DSystem::getCameraList()
396 {
397  std::set<SoCamera*> cameralist = m_d->staticcameras;
398  std::set<SoQtViewer*>::const_iterator it, itE=m_d->viewers.end();
399  for (it=m_d->viewers.begin();it!=itE;++it) {
400  SoCamera*cam = (*it)->getCamera();
401  if (cam)
402  cameralist.insert(cam);
403  }
404 
405  //m_d->camerasfromviewer
406  return cameralist;
407 }
408 
409 //___________________________________________________________________________________________________________
410 void IVP13DSystem::registerCamera(SoCamera *cam) {
411  if (!cam)
412  return;
413  m_d->staticcameras.insert(cam);
414  cam->ref();
415 }
416 
417 //___________________________________________________________________________________________________________
418 void IVP13DSystem::registerViewer(SoQtViewer *viewer)
419 {
420  if (!viewer)
421  return;
422  m_d->viewers.insert(viewer);
423 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
IVP13DSystem::userChangedSelection
virtual void userChangedSelection(SoCooperativeSelection *, QSet< SoNode * >, QSet< SoPath * >)
Definition: IVP13DSystem.cxx:61
IVP13DSystem::setUserSelectionNotificationsEnabled
void setUserSelectionNotificationsEnabled(SoCooperativeSelection *sel, bool enabled)
Definition: IVP13DSystem.cxx:310
IVP13DSystem::activateClickedOutside
void activateClickedOutside()
Definition: IVP13DSystem.cxx:85
IVP13DSystem::Imp::selection2system
static std::map< SoCooperativeSelection *, IVP13DSystem * > selection2system
Definition: IVP13DSystem.cxx:46
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
IVP13DSystem::Imp::made_selection
static void made_selection(void *userdata, SoPath *path)
Definition: IVP13DSystem.cxx:192
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
IVP13DSystem::Imp::viewers
std::set< SoQtViewer * > viewers
Definition: IVP13DSystem.cxx:37
VP1Msg.h
IVP1System::information
const QString & information() const
Definition: IVP1System.cxx:56
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
skel.it
it
Definition: skel.GENtoEVGEN.py:396
IVP13DSystem::Imp
Definition: IVP13DSystem.cxx:31
IVP13DSystem::userDeselectedSingleNode
virtual void userDeselectedSingleNode(SoCooperativeSelection *, SoNode *, SoPath *)
Definition: IVP13DSystem.cxx:60
IVP13DSystem::Imp::clickedoutside
static void clickedoutside(void *userdata, SoCooperativeSelection *sel)
Definition: IVP13DSystem.cxx:65
IVP13DSystem::IVP13DSystem
IVP13DSystem(const QString &name, const QString &information, const QString &contact_info)
Definition: IVP13DSystem.cxx:356
TruthTest.itE
itE
Definition: TruthTest.py:25
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
IVP13DSystem::itemFromSystemSelected
void itemFromSystemSelected()
IVP13DSystem::registerSelectionNode
void registerSelectionNode(SoCooperativeSelection *)
Definition: IVP13DSystem.cxx:257
IVP1System
Definition: IVP1System.h:36
IVP13DSystem::Imp::start_changeselection
static void start_changeselection(void *userdata, SoSelection *sel)
Definition: IVP13DSystem.cxx:94
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
sel
sel
Definition: SUSYToolsTester.cxx:97
IVP13DSystem.h
IVP1System::name
const QString & name() const
Definition: IVP1System.cxx:50
PyPoolBrowser.node
node
Definition: PyPoolBrowser.py:131
IVP1System::contact_info
const QString & contact_info() const
Definition: IVP1System.cxx:62
IVP13DSystem::Imp::_callbacks
std::vector< SoSelectionPathCB * > _callbacks
Definition: IVP13DSystem.cxx:34
SoCooperativeSelection::ensureInitClass
static void ensureInitClass()
Definition: SoCooperativeSelection.cxx:26
IVP13DSystem::Imp::staticcameras
std::set< SoCamera * > staticcameras
Definition: IVP13DSystem.cxx:36
selection
const std::string selection
Definition: fbtTestBasics.cxx:74
SoCooperativeSelection.h
IVP1System::messageDebug
void messageDebug(const QString &) const
Definition: IVP1System.cxx:347
IVP13DSystem::registerViewer
void registerViewer(SoQtViewer *viewer)
Definition: IVP13DSystem.cxx:418
IVP13DSystem::getCameraList
CamList getCameraList()
Definition: IVP13DSystem.cxx:395
IVP13DSystem::Imp::made_deselection
static void made_deselection(void *userdata, SoPath *path)
Definition: IVP13DSystem.cxx:227
IVP13DSystem::Imp::selection2lastpathlist
std::map< SoCooperativeSelection *, SoPathList > selection2lastpathlist
Definition: IVP13DSystem.cxx:52
IVP13DSystem::unregisterSelectionNode
void unregisterSelectionNode(SoCooperativeSelection *)
Definition: IVP13DSystem.cxx:281
IVP13DSystem
Definition: IVP13DSystem.h:31
IVP13DSystem::Imp::selectionsWithDisabledNotifications
QSet< SoCooperativeSelection * > selectionsWithDisabledNotifications
Definition: IVP13DSystem.cxx:50
IVP13DSystem::userSelectedSingleNode
virtual void userSelectedSingleNode(SoCooperativeSelection *, SoNode *, SoPath *)
Definition: IVP13DSystem.cxx:59
IVP13DSystem::Imp::finished_changeselection
static void finished_changeselection(void *userdata, SoSelection *sel)
Definition: IVP13DSystem.cxx:121
IVP13DSystem::userClickedOnBgd
virtual void userClickedOnBgd()
Definition: IVP13DSystem.cxx:62
IVP13DSystem::Imp::clickedoutsideScheduled
bool clickedoutsideScheduled
Definition: IVP13DSystem.cxx:53
IVP13DSystem::~IVP13DSystem
virtual ~IVP13DSystem()
Definition: IVP13DSystem.cxx:364
IVP13DSystem::m_d
Imp * m_d
Definition: IVP13DSystem.h:116
IVP1System::message
void message(const QString &) const
Definition: IVP1System.cxx:336
IVP13DSystem::deselectAll
virtual void deselectAll(SoCooperativeSelection *exception_sel=0)
Definition: IVP13DSystem.cxx:331
IVP1System::messageVerbose
void messageVerbose(const QString &) const
Definition: IVP1System.cxx:354
node
Definition: memory_hooks-stdcmalloc.h:74
SoCooperativeSelection
Definition: SoCooperativeSelection.h:29
IVP13DSystem::registerCamera
void registerCamera(SoCamera *camera)
Definition: IVP13DSystem.cxx:410