ATLAS Offline Software
VP1StdCollection.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 // //
8 // Implementation of class VP1StdCollection //
9 // //
10 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11 // Initial version: June 2008 //
12 // //
14 
17 #include "VP1Base/VP1Serialise.h"
18 #include "VP1Base/VP1Deserialise.h"
20 
21 #include <Inventor/C/errors/debugerror.h>
22 #include <Inventor/nodes/SoSwitch.h>
23 #include <Inventor/nodes/SoMaterial.h>
24 #include <Inventor/nodes/SoSeparator.h>
25 
26 #include <QCheckBox>
27 
28 #include <iostream>
29 //____________________________________________________________________
31 public:
32  Imp() : theswitch(0),
33  collsep(0),
34  checkBox(0),
35  material(0),
38  matButton(0),
39  visible(false),
40  loaded(false),
41  problemsloading(false),
42  textProvided(false),
43  id(-1),
44  idProvided(false),
46  lastMatBrightness(0) {}
47  SoSwitch* theswitch;
48  SoSeparator* collsep;
49  QCheckBox * checkBox;
50  SoMaterial * material;
54  bool visible;
55  bool loaded;
58  qint32 id;
59  bool idProvided;
60  QString text;
61  QList<QWidget*> extraWidgets;
64 };
65 
66 //____________________________________________________________________
67 VP1StdCollection::VP1StdCollection(IVP1System* sys,const QString& helperClassName)
68  : VP1Collection(sys,helperClassName), m_d(new Imp)
69 {
70 }
71 
72 //____________________________________________________________________
74 {
75  //The object names should not contain all sorts of funky chars (mat button style sheets wont work for instance):
76  QString safetext(text());
77  safetext.replace(' ','_');
78  safetext.replace('[','_');
79  safetext.replace(']','_');
80  safetext.replace('/','_');
81  safetext.replace('.','_');
82  safetext.replace(',','_');
83  safetext.replace('<','_');
84  safetext.replace('>','_');
85  safetext.replace('&','_');
86 
87  m_d->theswitch = new SoSwitch;
88  m_d->theswitch->ref();
89  m_d->theswitch->setName(("StdCollSwitch"+safetext).toStdString().c_str());
90 
91  // get a default material for the collection
92  m_d->material = new SoMaterial;
93  m_d->material->setName(("StdCollMat"+safetext).toStdString().c_str());
94  m_d->material->ref();
96 
97  // the material button hosting the default material
98  button==0?m_d->matButton = new VP1MaterialButton:m_d->matButton=button; // Use button if something has been passed in...
99  m_d->matButton->setObjectName("matButtonColl_"+safetext);
100  m_d->matButton->setToolTip(matButtonToolTip());
102  connect(m_d->matButton,SIGNAL(lastAppliedChanged()),this,SLOT(possibleChangeMatTranspOrBrightness()));
103 
104  // the collection checkbox
105  m_d->checkBox = new QCheckBox();
106  m_d->checkBox->setText(m_d->checkBox->fontMetrics().elidedText(text(), Qt::ElideRight, 140 ));
107  m_d->checkBox->setObjectName("checkBoxColl_"+safetext);
108  m_d->checkBox->setToolTip(checkBoxToolTip());
109  connect(m_d->checkBox,SIGNAL(toggled(bool)),this,SLOT(setVisible(bool)));
110 
111  m_d->collsep = new SoSeparator;
112  m_d->collsep->ref();
113  m_d->collsep->setName(("StdCollSep"+safetext).toStdString().c_str());
114 
116 }
117 
118 //____________________________________________________________________
120 {
121  delete m_d->checkBox;
122  delete m_d->matButton;
123  for (QWidget*w : m_d->extraWidgets)
124  delete w;
125  m_d->material->unref();
126  m_d->collsep->unref();
127  m_d->theswitch->unref();
128  delete m_d;
129 }
130 
131 //____________________________________________________________________
132 QString VP1StdCollection::text() const
133 {
134  if (!m_d->textProvided) {
135  m_d->textProvided = true;
136  m_d->text = provideText();
137  }
138  return m_d->text;
139 }
140 
141 //____________________________________________________________________
143 {
144  return m_d->visible;
145 }
146 
147 //____________________________________________________________________
149 {
150  return m_d->loaded;
151 }
152 
153 //____________________________________________________________________
155 {
156  return m_d->problemsloading;
157 }
158 
159 //____________________________________________________________________
161 {
162  if (m_d->visible==b||problemsLoading())
163  return;
164  m_d->visible=b;
165  messageVerbose("Visible state ("+text()+") => "+str(m_d->visible));
166 
167  //Possibly load:
168  if (m_d->visible&&!m_d->loaded) {
169  m_d->loaded = true;
170  m_d->theswitch->whichChild = SO_SWITCH_NONE;
171  bool ok = load();
172  if (!ok) {
173  m_d->problemsloading = true;
174  m_d->visible = false;
175  m_d->checkBox->blockSignals(true);
176  m_d->checkBox->setChecked(false);
177  m_d->checkBox->setToolTip("Problems encountered during attempt to load this collection");
178  for (QWidget*w : widgetsForGuiRow())
179  w->setEnabled(false);
180  message("Problems loading "+text());
181  return;
182  }
183  m_d->theswitch->addChild(m_d->material);
184  m_d->theswitch->addChild(m_d->collsep);
185  }
186 
187  Q_ASSERT(!problemsLoading());
188 
189  //Update checkbox and switch:
190  if (m_d->checkBox->isChecked()!=m_d->visible) {
191  bool save = m_d->checkBox->blockSignals(true);
192  m_d->checkBox->setChecked(m_d->visible);
193  if (!save)
194  m_d->checkBox->blockSignals(false);
195  }
196  if ((m_d->theswitch->whichChild.getValue()==SO_SWITCH_ALL) != m_d->visible)
197  m_d->theswitch->whichChild = ( m_d->visible ? SO_SWITCH_ALL : SO_SWITCH_NONE );
198 
200 }
201 
202 
203 //____________________________________________________________________
205 {
206  if (!m_d->theswitch)
207  message("ERROR: collSwitch() called before init()");
208  return m_d->theswitch;
209 }
210 
211 //____________________________________________________________________
212 SoSeparator * VP1StdCollection::collSep() const
213 {
214  if (!m_d->collsep)
215  message("ERROR: collSep() called before init()");
216  return m_d->collsep;
217 }
218 
219 //____________________________________________________________________
220 SoMaterial * VP1StdCollection::material() const
221 {
222  if (!m_d->material)
223  message("ERROR: material() called before init()");
224  return m_d->material;
225 }
226 
227 //____________________________________________________________________
229 {
230  if (!m_d->collsep)
231  message("ERROR: largeChangesBegin() called before init()");
232  m_d->collsep->enableNotify(false);
234  m_d->theswitch->enableNotify(false);
236 }
237 
238 //____________________________________________________________________
240 {
241  if (!m_d->collsep)
242  message("ERROR: largeChangesEnd() called before init()");
243  if (m_d->largechangescount_sep>0) {
244  if (--(m_d->largechangescount_sep)==0) {
245  m_d->collsep->enableNotify(true);
246  m_d->collsep->touch();
247  }
248  }
249  if (m_d->largechangescount_switch>0) {
250  if (--(m_d->largechangescount_switch)==0) {
251  m_d->theswitch->enableNotify(true);
252  m_d->theswitch->touch();
253  }
254  }
255 }
256 
257 //____________________________________________________________________
259 {
261 
262  QList<QWidget*> l;
263  l << m_d->checkBox;
264  l << m_d->matButton;
265  l << m_d->extraWidgets;
266  return l;
267 }
268 
269 //____________________________________________________________________
271 {
272  messageDebug("VP1StdCollection::persistifiableState()");
273 
274  if (!m_d->material) {
275  message("ERROR: persistifiableState() called before init()");
276  return QByteArray();
277  }
278  VP1Serialise serialise(1/*version*/);
279  serialise.disableUnsavedChecks();
280  serialise.save(m_d->visible);
281  Q_ASSERT(m_d->material&&"Did you forget to call init() on this VP1StdCollection?");
282  serialise.save(m_d->material);
283  serialise.save(extraWidgetsState());//version 1+
284  return serialise.result();
285 }
286 
287 //____________________________________________________________________
288 void VP1StdCollection::setState(const QByteArray&state)
289 {
290  if (!m_d->material) {
291  message("ERROR: setState(..) called before init()");
292  return;
293  }
294  VP1Deserialise des(state);
295  des.disableUnrestoredChecks();
296  if (des.version()!=0&&des.version()!=1) {
297  messageDebug("Warning: Ignoring state with wrong version");
298  return;
299  }
300  bool vis = des.restoreBool();
301 
302  QByteArray matState = des.restoreByteArray();
303  QByteArray extraWidgetState = des.version()>=1 ? des.restoreByteArray() : QByteArray();
304 
307  // m_d->material->restoreFromState(matState);
308  setVisible(vis);
309 
310  if (extraWidgetState!=QByteArray())
311  setExtraWidgetsState(extraWidgetState);
312 }
313 
314 //____________________________________________________________________
316 {
317  if (!m_d->idProvided) {
318  m_d->idProvided = true;
319  m_d->id = provideCollTypeID();
320  }
321  return m_d->id;
322 }
323 
324 //____________________________________________________________________
326 {
327  VP1Serialise serialise(-10/*version*/);//we use negative versions here (0 and -10 already used),
328  //to allow derived classes to use positive numbers.
329  serialise.disableUnsavedChecks();
330  serialise.save(collTypeID());
331  serialise.save(text());
332  return serialise.result();
333 }
334 
335 //____________________________________________________________________
337 {
338  return m_d->lastMatTransparency;
339 }
340 
341 //____________________________________________________________________
343 {
344  return m_d->lastMatBrightness;
345 }
346 
347 //____________________________________________________________________
349 {
350  double t = m_d->matButton->lastAppliedTransparency();
351  double b = m_d->matButton->lastAppliedBrightness();
352  if ( m_d->lastMatTransparency == t && m_d->lastMatBrightness == b )
353  return;
357 }
VP1Serialise.h
VP1StdCollection::collMaterialTransparency
double collMaterialTransparency() const
Definition: VP1StdCollection.cxx:336
VP1Deserialise.h
VP1Serialise
Definition: VP1Serialise.h:45
VP1StdCollection::checkBoxToolTip
virtual QString checkBoxToolTip() const
Definition: VP1StdCollection.h:76
VP1StdCollection::Imp::theswitch
SoSwitch * theswitch
Definition: VP1StdCollection.cxx:47
VP1StdCollection::VP1StdCollection
VP1StdCollection(IVP1System *, const QString &helperClassName)
Definition: VP1StdCollection.cxx:67
VP1StdCollection::material
SoMaterial * material() const
Definition: VP1StdCollection.cxx:220
RoiUtil::serialise
void serialise(const std::vector< const IRoiDescriptor * > &rois, roiserial_type &s)
serialise an entire vector of IRoiDescriptors
Definition: RoiSerialise.cxx:45
VP1StdCollection::Imp::loaded
bool loaded
Definition: VP1StdCollection.cxx:55
VP1StdCollection::~VP1StdCollection
virtual ~VP1StdCollection()
Definition: VP1StdCollection.cxx:119
VP1MaterialButton.h
VP1StdCollection::collTypeID
qint32 collTypeID() const
Definition: VP1StdCollection.cxx:315
VP1StdCollection::possibleChangeMatTranspOrBrightness
void possibleChangeMatTranspOrBrightness()
Definition: VP1StdCollection.cxx:348
VP1MaterialButton
Definition: VP1MaterialButton.h:46
VP1HelperClassBase::messageVerbose
void messageVerbose(const QString &) const
Definition: VP1HelperClassBase.cxx:78
VP1StdCollection::collSwitch
SoSwitch * collSwitch() const
Add this somewhere in your scenegraph (do not add any children here!)
Definition: VP1StdCollection.cxx:204
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
VP1MaterialButtonBase::lastAppliedBrightness
virtual double lastAppliedBrightness() const =0
VP1StdCollection::Imp::collsep
SoSeparator * collsep
Definition: VP1StdCollection.cxx:48
VP1StdCollection::init
virtual void init(VP1MaterialButtonBase *button=0)
Definition: VP1StdCollection.cxx:73
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
VP1StdCollection::largeChangesBegin
virtual void largeChangesBegin()
Definition: VP1StdCollection.cxx:228
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
VP1StdCollection::extraWidgetsState
virtual QByteArray extraWidgetsState() const
Definition: VP1StdCollection.h:89
VP1StdCollection::providePersistifiableID
virtual QByteArray providePersistifiableID() const
Definition: VP1StdCollection.cxx:325
VP1String::str
static QString str(const QString &s)
Definition: VP1String.h:49
VP1HelperClassBase::messageDebug
void messageDebug(const QString &) const
Definition: VP1HelperClassBase.cxx:65
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
VP1QtInventorUtils::deserialiseSoMaterial
static bool deserialiseSoMaterial(QByteArray &, SoMaterial *&)
Definition: VP1QtInventorUtils.cxx:1188
VP1QtInventorUtils.h
VP1StdCollection::Imp::id
qint32 id
Definition: VP1StdCollection.cxx:58
VP1StdCollection::Imp::material
SoMaterial * material
Definition: VP1StdCollection.cxx:50
checkTP.save
def save(self, fileName="./columbo.out")
Definition: checkTP.py:178
IVP1System
Definition: IVP1System.h:36
VP1StdCollection::Imp::visible
bool visible
Definition: VP1StdCollection.cxx:54
VP1StdCollection::setVisible
void setVisible(bool)
Definition: VP1StdCollection.cxx:160
VP1StdCollection::load
virtual bool load()=0
VP1StdCollection::Imp::matButton
VP1MaterialButtonBase * matButton
Definition: VP1StdCollection.cxx:53
VP1StdCollection::visibilityChanged
void visibilityChanged(bool)
VP1StdCollection::provideExtraWidgetsForGuiRow
virtual QList< QWidget * > provideExtraWidgetsForGuiRow() const
Definition: VP1StdCollection.h:88
VP1StdCollection::Imp::extraWidgets
QList< QWidget * > extraWidgets
Definition: VP1StdCollection.cxx:61
VP1StdCollection::text
QString text() const
Definition: VP1StdCollection.cxx:132
VP1StdCollection::collMaterialBrightness
double collMaterialBrightness() const
Definition: VP1StdCollection.cxx:342
VP1Deserialise
Definition: VP1Deserialise.h:44
VP1MaterialButtonBase::copyValuesFromMaterial
virtual void copyValuesFromMaterial(SoMaterial *)=0
VP1StdCollection::Imp::idProvided
bool idProvided
Definition: VP1StdCollection.cxx:59
VP1Collection
Definition: VP1Collection.h:31
VP1StdCollection::problemsLoading
bool problemsLoading() const
Definition: VP1StdCollection.cxx:154
VP1StdCollection::collMaterialTransparencyAndBrightnessChanged
virtual void collMaterialTransparencyAndBrightnessChanged()
Definition: VP1StdCollection.h:79
VP1StdCollection::Imp::lastMatBrightness
double lastMatBrightness
Definition: VP1StdCollection.cxx:63
VP1StdCollection::Imp::lastMatTransparency
double lastMatTransparency
Definition: VP1StdCollection.cxx:62
VP1StdCollection::Imp
Definition: VP1StdCollection.cxx:30
VP1StdCollection::Imp::problemsloading
bool problemsloading
Definition: VP1StdCollection.cxx:56
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
VP1Collection::widgetsForGuiRow
virtual QList< QWidget * > widgetsForGuiRow() const
Definition: VP1Collection.cxx:62
VP1MaterialButtonBase::setMaterial
virtual bool setMaterial(SoMaterial *)=0
VP1StdCollection::isLoaded
bool isLoaded() const
Definition: VP1StdCollection.cxx:148
VP1MaterialButtonBase
Definition: VP1MaterialButton.h:25
VP1StdCollection::largeChangesEnd
virtual void largeChangesEnd()
Definition: VP1StdCollection.cxx:239
VP1StdCollection::assignDefaultMaterial
virtual void assignDefaultMaterial(SoMaterial *) const =0
VP1StdCollection::Imp::largechangescount_sep
int largechangescount_sep
Definition: VP1StdCollection.cxx:51
VP1StdCollection::Imp::largechangescount_switch
int largechangescount_switch
Definition: VP1StdCollection.cxx:52
VP1StdCollection::collSep
SoSeparator * collSep() const
All 3D objects from this coll.
Definition: VP1StdCollection.cxx:212
VP1StdCollection::matButtonToolTip
virtual QString matButtonToolTip() const
Definition: VP1StdCollection.h:77
VP1StdCollection::visible
bool visible() const
Definition: VP1StdCollection.cxx:142
VP1HelperClassBase::message
void message(const QString &) const
Definition: VP1HelperClassBase.cxx:49
VP1StdCollection::Imp::text
QString text
Definition: VP1StdCollection.cxx:60
VP1StdCollection::Imp::checkBox
QCheckBox * checkBox
Definition: VP1StdCollection.cxx:49
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
VP1StdCollection::m_d
Imp * m_d
Definition: VP1StdCollection.h:102
VP1StdCollection.h
VP1StdCollection::persistifiableState
virtual QByteArray persistifiableState() const
Provide default implementation based on widget list + version.
Definition: VP1StdCollection.cxx:270
VP1StdCollection::provideText
virtual QString provideText() const =0
VP1StdCollection::Imp::textProvided
bool textProvided
Definition: VP1StdCollection.cxx:57
VP1StdCollection::setState
virtual void setState(const QByteArray &)
Provide default implementation based on widget list + version.
Definition: VP1StdCollection.cxx:288
VP1StdCollection::provideCollTypeID
virtual qint32 provideCollTypeID() const
Definition: VP1StdCollection.h:92
VP1StdCollection::setExtraWidgetsState
virtual void setExtraWidgetsState(const QByteArray &)
Definition: VP1StdCollection.h:90
query_example.des
des
Definition: query_example.py:9
VP1MaterialButtonBase::lastAppliedTransparency
virtual double lastAppliedTransparency() const =0
VP1StdCollection::provideWidgetsForGuiRow
QList< QWidget * > provideWidgetsForGuiRow() const
Definition: VP1StdCollection.cxx:258
VP1StdCollection::Imp::Imp
Imp()
Definition: VP1StdCollection.cxx:32