ATLAS Offline Software
Loading...
Searching...
No Matches
AODCollHandleBase.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7// //
8// Implementation of class AODCollHandleBase //
9// //
10// Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11// Initial version: February 2008 //
12// //
14
15//Local includes
16#include "AODHandleBase.h"
17#include "AODCollHandleBase.h"
18
21#include "AODSysCommonData.h"
22
23//VP1 base includes
30#include "VP1Base/VP1Msg.h"
31
32//SoCoin
33#include <Inventor/nodes/SoSeparator.h>
34#include <Inventor/nodes/SoMaterial.h>
35#include <Inventor/nodes/SoSwitch.h>
36#include "Inventor/nodes/SoDrawStyle.h"
37#include "Inventor/nodes/SoLightModel.h"
38
39//Athena
42
43//Qt
44#include <QComboBox>
45#include <QTreeWidgetItem>
46#include <qdatetime.h>
47#include <vector>
48#include <QString>
49#include <QElapsedTimer>
50
51//____________________________________________________________________
53public:
55 QString name;
56
57 //Extra widgets:
58 QTreeWidgetItem* objBrowseTree = nullptr;
59
60 // N.B. Material button defined in children.
61};
62
63
64
65//____________________________________________________________________
67 //AODCollHandleBase::AODCollHandleBase( AODSysCommonData * cd, const QString& name)
68 : VP1StdCollection(cd->system(),"AODCollHandleBase_FIXME_"+name), m_dbase(new Imp), // Need to add back ObjectType once simple way to create string is added to xAODBase
70 m_type(type),
71 m_commonData(cd),
73{
74 m_dbase->theclass = this;
75 m_dbase->name = name;
76 m_dbase->objBrowseTree = 0;
77}
78
79// //____________________________________________________________________
80// void AODCollHandleBase::init(VP1MaterialButtonBase*)
81// {
82// // m_dbase->matButton = new TrackCollectionSettingsButton;
83// // m_dbase->matButton->setText(text());
84// // VP1StdCollection::init(m_dbase->matButton);//this call is required. Passing in TrackCollectionSettingsButton means we have the more complex button.
85// VP1StdCollection::init();//FIXME
86// setupSettingsFromController(common()->controller());
87// connect(this,SIGNAL(visibilityChanged(bool)),this,SLOT(collVisibilityChanged(bool)));
88//
89// // collSwitch()->addChild(m_dbase->matButton->trackDrawStyle());
90// }
91
92//____________________________________________________________________
94{
95 messageVerbose("destructor start");
96
97
98 // delete the Imp instance
99 delete m_dbase;
100
101 if (m_sephelper) {
102 SoSeparator * sep = m_sephelper->topSeparator();
103 sep->ref();
104 delete m_sephelper;
105 sep->unref();
106 }
107
108 messageVerbose("destructor end");
109}
110
111//____________________________________________________________________
113{
114 messageVerbose("setupSettingsFromController start");
115 if (!controller) {
116 message("Not properly initialized: controller pointer is zero.");
117 return;
118 }
119
121 // connect(common()->system(),SIGNAL(newHandleSelected( const AODHandleBase&)),this,SLOT(handleSelectionChanged()));
123
125 messageVerbose("setupSettingsFromController end");
126}
127
128
129//____________________________________________________________________
130const QString& AODCollHandleBase::name() const
131{
132 return m_dbase->name;
133}
134
135
136//____________________________________________________________________
138{
139 messageVerbose("AODCollHandleBase::recheckCutStatus() & visible="+str(visible()));
140 handle->setVisible( visible() && cut(handle));
141}
142
143//____________________________________________________________________
145{
146 messageVerbose("AODCollHandleBase::recheckCutStatusOfAllVisibleHandles");
147
148 if (!isLoaded())
149 return;
150
151 //This method is called when a cut is tightened - thus we better start by deselectAll to avoid weird highlighting issues.
152 common()->system()->deselectAll();
153
156 AODHandleBase* handle=0;
157 while ((handle=getNextHandle()))
158 {
159 if (handle->visible())
160 recheckCutStatus(handle);
161 }
162 // handle=getNextHandle();
163 // recheckCutStatus(handle);
164
165 // std::vector<AODHandleBase*>::iterator it(m_dbase->handles.begin()),itE(m_dbase->handles.end());
166 // for (;it!=itE;++it) {
167 // if ((*it)->visible())
168 // recheckCutStatus(*it);
169 // }
172
173 message("recheckCutStatusOfAllVisibleHandles: "+str(nShownHandles())+"/"+str(getHandlesList().count())+" pass cuts");
174}
175
176//____________________________________________________________________
178{
179 messageVerbose("AODCollHandleBase::recheckCutStatusOfAllNotVisibleHandles");
180
181 if (!isLoaded()){
182 messageVerbose("AODCollHandleBase::recheckCutStatusOfAllNotVisibleHandles - not yet loaded. Aborting.");
183 return;
184 }
185
187 AODHandleBase* handle=0;
188 // unsigned int i=0;
190 while ((handle=getNextHandle()))
191 {
192 // std::cout<<"Looking at handle "<<++i<<" with visible="<<handle->visible()<<std::endl;
193 if (!handle->visible())
194 recheckCutStatus(handle);
195 }
198
199 message("recheckCutStatusOfAllNotVisibleHandles: "+str(nShownHandles())+"/"+str(getHandlesList().count())+" pass cuts");
200}
201
202//____________________________________________________________________
204{
205 messageVerbose("AODCollHandleBase::recheckCutStatusOfAllHandles()");
206 if (!isLoaded())
207 return;
210 AODHandleBase* handle=0;
211 while ((handle=getNextHandle()))
212 {
213 if (handle->visible())
214 recheckCutStatus(handle);
215 }
218
219 message("recheckCutStatusOfAllHandles: "+str(nShownHandles())+"/"+str(getHandlesList().count())+" pass cuts");
220}
221
222//____________________________________________________________________
224{
225 if (!isLoaded())
226 return;
227 if (VP1Msg::verbose())
228 messageVerbose("update3DObjectsOfAllHandles start");
231 AODHandleBase* handle=0;
232 while ((handle=getNextHandle()))
233 handle->update3DObjects();
234
236 messageVerbose("update3DObjectsOfAllHandles end");
237}
238
239//____________________________________________________________________
241{
242 if (!isLoaded())
243 return;
244 messageVerbose("updateMaterialOfAllHandles start");
247 AODHandleBase* handle=0;
248 while ((handle=getNextHandle()))
249 handle->updateMaterial();
251 messageVerbose("updateMaterialOfAllHandles end");
252}
253
254
255
256// //____________________________________________________________________
257// void AODCollHandleBase::setLabels( AODSystemController::TrackLabelModes labels )
258// {
259// // messageVerbose("setLabels called");
260// // if (m_labels==labels)
261// // return;
262// // messageVerbose("setLabels ==> Changed");
263// // m_labels = labels;
264// // update3DObjectsOfAllHandles();
265// }
266//
267// //____________________________________________________________________
268// void AODCollHandleBase::setLabelTrkOffset( float offset)
269// {
270// // messageVerbose("setLabelTrkOffset called");
271// // if (m_labelsTrkOffset==offset)
272// // return;
273// // messageVerbose("setLabelTrkOffset ==> Changed to "+QString::number(offset));
274// // m_labelsTrkOffset = offset;
275// // update3DObjectsOfAllHandles();
276// }
277//
278// //____________________________________________________________________
279// void AODCollHandleBase::setLabelPosOffsets( QList<int> offsets)
280// {
281// // messageVerbose("setLabelPosOffsets called");
282// // if (m_labelsPosOffsets==offsets)
283// // return;
284// // messageVerbose("setLabelPosOffsets ==> Changed");
285// // m_labelsPosOffsets = offsets;
286// // update3DObjectsOfAllHandles();
287// }
288
289// //____________________________________________________________________
290// void AODCollHandleBase::setColourBy( AODCollHandleBase::COLOURBY cb )
291// {
292// // messageVerbose("setColourBy called");
293// // if (m_colourby==cb)
294// // return;
295// // messageVerbose("setColourBy ==> Changed");
296// // m_colourby=cb;
297// //
298// // //Update gui combobox:
299// // QString targetText;
300// // switch(cb) {
301// // case COLOUR_BYPID:
302// // targetText = Imp::comboBoxEntry_ColourByPID();
303// // break;
304// // case COLOUR_RANDOM:
305// // targetText = Imp::comboBoxEntry_ColourByRandom();
306// // break;
307// // case COLOUR_MOMENTUM:
308// // targetText = Imp::comboBoxEntry_ColourByMomentum();
309// // break;
310// // case COLOUR_CHARGE:
311// // targetText = Imp::comboBoxEntry_ColourByCharge();
312// // break;
313// // case COLOUR_DISTANCE:
314// // targetText = Imp::comboBoxEntry_ColourByDistanceFromSelectedTrack();
315// // break;
316// // case COLOUR_VERTEX:
317// // targetText = Imp::comboBoxEntry_ColourByVertex();
318// // break;
319// // default:
320// // case COLOUR_PERCOLLECTION:
321// // targetText = Imp::comboBoxEntry_ColourByCollection();
322// // break;
323// // }
324// // if (targetText!=m_dbase->comboBox_colourby->currentText()) {
325// // int i = m_dbase->comboBox_colourby->findText(targetText);
326// // if (i>=0&&i<m_dbase->comboBox_colourby->count()) {
327// // bool save = m_dbase->comboBox_colourby->blockSignals(true);
328// // m_dbase->comboBox_colourby->setCurrentIndex(i);
329// // m_dbase->comboBox_colourby->blockSignals(save);
330// // } else {
331// // message("ERROR: Problems finding correct text in combo box");
332// // }
333// // }
334// //
335// // //Actual material updates:
336// // largeChangesBegin();
337// // m_commonData->system()->deselectAll();//Todo: Reselect the selected track handles
338// // //afterwards (collhandles should know selected handles)
339// // updateMaterialOfAllHandles();
340// // largeChangesEnd();
341//
342// }
343//
344// //____________________________________________________________________
345// void AODCollHandleBase::rerandomiseRandomTrackColours()
346// {
347// // if (!isLoaded())
348// // return;
349// // messageVerbose("rerandomiseRandomTrackColours start");
350// // largeChangesBegin();
351// // std::vector<AODHandleBase*>::iterator it(m_dbase->handles.begin()),itE(m_dbase->handles.end());
352// // for (;it!=itE;++it)
353// // (*it)->rerandomiseRandomMaterial();
354// // largeChangesEnd();
355// // messageVerbose("rerandomiseRandomTrackColours end");
356// }
357//
358// //____________________________________________________________________
359// void AODCollHandleBase::handleSelectionChanged()
360// {
361// // if (!isLoaded() || colourBy()!= COLOUR_DISTANCE)
362// // return;
363// // messageVerbose("handleSelectionChanged start");
364// // largeChangesBegin();
365// // std::vector<AODHandleBase*>::iterator it(m_dbase->handles.begin()),itE(m_dbase->handles.end());
366// // for (;it!=itE;++it)
367// // (*it)->updateMaterial();
368// // largeChangesEnd();
369// // messageVerbose("handleSelectionChanged end");
370// }
371
372
373
374//____________________________________________________________________
376{
377 return m_type; // This is the xAOD::Type::ObjectType value
378}
379
381
382 std::stringstream ss;
383 ss << m_type;
384 QString section = QString::fromStdString(ss.str());
385 return section;
386}
387
389 return QString("TODO!");
390}
391
392//____________________________________________________________________
394{
395 if (VP1Msg::verbose())
396 messageVerbose("AODCollHandleBase::collVisibilityChanged => "+str(vis));
397
398 if (!m_sephelper)
400
401 if (!m_dbase->objBrowseTree)
403
404 if (vis){
405 recheckCutStatusOfAllNotVisibleHandles();//Fixme -> ofallhandles? All must be not visible anyway...
406 if (m_dbase->objBrowseTree) m_dbase->objBrowseTree->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); // selectable, enabled
407 }else{
409 // QTreeWidget* trkObjBrowser = common()->controller()->trackObjBrowser();
410 // if (m_dbase->objBrowseTree && trkObjBrowser) {
411 // trkObjBrowser->takeTopLevelItem(trkObjBrowser->indexOfTopLevelItem(m_dbase->objBrowseTree));
412 // delete m_dbase->objBrowseTree; m_dbase->objBrowseTree=0;
413 // }
414 // FIXME - need to loop through handles setting pointers to deleted QTreeWidgetItems
415 if (m_dbase->objBrowseTree) m_dbase->objBrowseTree->setFlags(Qt::ItemFlags()); // not selectable, not enabled
416 }
417}
418
420 messageVerbose("AODCollHandleBase::updateObjectBrowserVisibilityCounts called for "+name());
421 QTreeWidget* trkObjBrowser = common()->controller()->objBrowser();
422 if (!trkObjBrowser || !m_dbase->objBrowseTree) {
423 messageVerbose("AODCollHandleBase::updateObjectBrowserVisibilityCounts: no common()->controller()->objBrowser() and/or d->objBrowseTree. Aborting");
424 messageVerbose("trkObjBrowser: "+str(trkObjBrowser)+"\t d->objBrowseTree: "+str(m_dbase->objBrowseTree));
425 return;
426 }
427 QString text(QString(": (")+QString::number(nShownHandles())+QString("/")+QString::number(getHandlesList().count())+QString(") visible"));
428 m_dbase->objBrowseTree->setText(1, text);
429}
430
432{
433 QElapsedTimer t;
434 t.start();
435 messageVerbose("AODCollHandleBase::fillObjectBrowser called for "+name());
436
437 QTreeWidget* trkObjBrowser = common()->controller()->objBrowser();
438 if (!trkObjBrowser) {
439 messageVerbose("AODCollHandleBase::fillObjectBrowser: no common()->controller()->objBrowser(). Aborting");
440 return;
441 }
442 // if (!nShownHandles()) {
443 // messageVerbose("AODCollHandleBase::fillObjectBrowser: no shown handles, so leaving.");
444 // return; // don't bother with hidden collection
445 // }
446
447 trkObjBrowser->setUpdatesEnabled(false);
448
449 bool firstTime=false;
450 if (!m_dbase->objBrowseTree) {
451 m_dbase->objBrowseTree = new QTreeWidgetItem(0);
452 firstTime=true;
453 messageVerbose("AODCollHandleBase::fillObjectBrowser: First time so creating QTreeWidgetItem.");
454 } else {
455 int index = trkObjBrowser->indexOfTopLevelItem(m_dbase->objBrowseTree);
456 if (index==-1 ) {
457 messageVerbose("Missing from WidgetTree! Will continue but something must be wrong");
458 }
459 }
460
461 messageVerbose("AODCollHandleBase::fillObjectBrowser about to start looping over handles at "+QString::number(t.elapsed())+" ms");
462
463 QList<QTreeWidgetItem *> list;
465 AODHandleBase* handle=0;
466 unsigned int i=0;
467 unsigned int numVisible=0;
468 while ((handle=getNextHandle()))
469 {
470 if (firstTime){
471 handle->fillObjectBrowser(list);
472 } else {
473 handle->updateObjectBrowser();
474 }
475
476 // messageVerbose("AODCollHandleBase::fillObjectBrowser for handle completed in "+QString::number(t.elapsed()));
477
478 if (handle->visible() ) numVisible++;
479 i++;
480 }
481
482 QString text(QString(": (")+QString::number(numVisible)+QString("/")+QString::number(i)+QString(") visible"));
483
484 m_dbase->objBrowseTree->setText(0, name());
485 m_dbase->objBrowseTree->setText(1, text);
486 m_dbase->objBrowseTree->addChildren(list);
487 trkObjBrowser->addTopLevelItem(m_dbase->objBrowseTree);
488 trkObjBrowser->setUpdatesEnabled(true);
489
490 messageVerbose("AODCollHandleBase::fillObjectBrowser completed in "+QString::number(t.elapsed())+" ms");
491
492}
493
494//____________________________________________________________________
496{
497 messageDebug("AODCollHandleBase::assignDefaultMaterial()");
498 VP1QtInventorUtils::setMatColor( m, defaultColor(), 0.18/*brightness*/ );
499}
500
501
502//____________________________________________________________________
504{
505 // return QList<QWidget*>() << m_dbase->comboBox_colourby;
506 return QList<QWidget*>();
507}
508
509//____________________________________________________________________
511{
512 VP1Serialise serialise(0/*version*/,systemBase());
513 // serialise.save(m_dbase->comboBox_colourby);
514 // serialise.disableUnsavedChecks();
515 return serialise.result();
516}
517
518//____________________________________________________________________
520{
521 messageDebug(" AODCollHandleBase::setExtraWidgetsState() - ba: " + ba);
522
523 if (ba.isEmpty())
524 messageVerbose("ExtraWidgetState ByteArray is empty.");
525
526 // VP1Deserialise state(ba, systemBase());
527 // if (state.version()!=0)
528 // return;//just ignore silently... i guess we ought to warn?
529 // state.restore(m_dbase->comboBox_colourby);
530 // state.disableUnrestoredChecks();
531 // colourByComboBoxItemChanged();
532}
533
534
535//____________________________________________________________________
537{
538 messageVerbose("AODCollHandleBase::colourByComboBoxItemChanged()");
539 messageVerbose("Collection detail level combo box changed index");
540
541 messageVerbose("TO BE IMPLEMENTED!!!");
542 /*
543 if (m_dbase->comboBox_colourby->currentText()==Imp::comboBoxEntry_ColourByRandom())
544 setColourBy(COLOUR_RANDOM);
545 else
546 setColourBy(COLOUR_PERCOLLECTION);
547 */
548}
549
550//____________________________________________________________________
551void AODCollHandleBase::setState(const QByteArray&state)
552{
553 VP1Deserialise des(state);
555 if (des.version()!=0&&des.version()!=1) {
556 messageDebug("Warning: Ignoring state with wrong version");
557 return;
558 }
559 bool vis = des.restoreBool();
560
561 QByteArray matState = des.restoreByteArray();
562 // m_dbase->matButton->restoreFromState(matState);
563 QByteArray extraWidgetState = des.version()>=1 ? des.restoreByteArray() : QByteArray();
564 setVisible(vis);
565
566 if (extraWidgetState!=QByteArray())
567 setExtraWidgetsState(extraWidgetState);
568}
569
570//____________________________________________________________________
572{
573 // if (!m_dbase->matButton) {
574 // message("ERROR: persistifiableState() called before init()");
575 // return QByteArray();
576 // }
577 VP1Serialise serialise(1/*version*/);
578 serialise.disableUnsavedChecks();
579 serialise.save(visible());
580 // Q_ASSERT(m_dbase->matButton&&"Did you forget to call init() on this VP1StdCollection?");
581 // serialise.save(m_dbase->matButton->saveState());
582 serialise.save(extraWidgetsState());//version 1+
583 return serialise.result();
584}
585
586
static Double_t ss
AODCollHandleBase * theclass
QTreeWidgetItem * objBrowseTree
AODCollHandleBase(AODSysCommonData *, const QString &name, xAOD::Type::ObjectType)
void recheckCutStatus(AODHandleBase *)
const AODSysCommonData * common() const
virtual void setState(const QByteArray &)
Provide specific implementation.
qint32 provideCollTypeID() const
void recheckCutStatusOfAllNotVisibleHandles()
virtual void assignDefaultMaterial(SoMaterial *) const
virtual void handleIterationBegin()=0
void recheckCutStatusOfAllVisibleHandles()
void setExtraWidgetsState(const QByteArray &)
xAOD::Type::ObjectType m_type
virtual QString provideSection() const
QByteArray extraWidgetsState() const
virtual void setupSettingsFromControllerSpecific(const AODSystemController *)
For extensions specific to this collection.
virtual QByteArray persistifiableState() const
Provide specific implementation.
virtual AODHandleBase * getNextHandle()=0
void setupSettingsFromController(const AODSystemController *)
virtual QString provideSectionToolTip() const
virtual QList< AODHandleBase * > getHandlesList() const =0
AODSysCommonData * m_commonData
virtual QColor defaultColor() const =0
void updateObjectBrowserVisibilityCounts()
QList< QWidget * > provideExtraWidgetsForGuiRow() const
const QString & name() const
virtual bool cut(AODHandleBase *)=0
VP1ExtraSepLayerHelper * m_sephelper
void updateObjectBrowser()
Update object browser QTreeWidgetItem.
bool visible() const
void updateMaterial()
Called after some configuration related to material changes.
virtual void update3DObjects()
Called after some configuration changes, or when the object is first created. Must be overloaded by c...
void setVisible(bool)
use by the collection handle.
virtual void fillObjectBrowser(QList< QTreeWidgetItem * > &list)
Create and fill the object browser QTreeWidgetItem.
const AODSystemController * controller() const
const VP1AODSystem * system() const
QTreeWidget * objBrowser() const
Returns a pointer to the Track Object Browser (if it exists)
virtual void deselectAll(SoCooperativeSelection *exception_sel=0)
QString section() const
QByteArray restoreByteArray()
void disableUnrestoredChecks()
qint32 version() const
void messageVerbose(const QString &) const
void message(const QString &) const
IVP1System * systemBase() const
void messageDebug(const QString &) const
static bool verbose()
Definition VP1Msg.h:31
static void setMatColor(SoMaterial *, const double &r, const double &g, const double &b, const double &brightness=0.0, const double &transp=0.0)
virtual void largeChangesEnd()
SoSeparator * collSep() const
All 3D objects from this coll.
virtual void largeChangesBegin()
QString text() const
VP1StdCollection(IVP1System *, const QString &helperClassName)
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
Definition index.py:1
ObjectType
Type of objects that have a representation in the xAOD EDM.
Definition ObjectType.h:32