ATLAS Offline Software
Loading...
Searching...
No Matches
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
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//____________________________________________________________________
31public:
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),
47 SoSwitch* theswitch;
48 SoSeparator* collsep;
49 QCheckBox * checkBox;
50 SoMaterial * material;
54 bool visible;
55 bool loaded;
58 qint32 id;
60 QString text;
61 QList<QWidget*> extraWidgets;
64};
65
66//____________________________________________________________________
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();
95 assignDefaultMaterial(m_d->material);
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());
101 m_d->matButton->setMaterial(m_d->material);
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//____________________________________________________________________
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
199 visibilityChanged(m_d->visible);
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//____________________________________________________________________
212SoSeparator * VP1StdCollection::collSep() const
213{
214 if (!m_d->collsep)
215 message("ERROR: collSep() called before init()");
216 return m_d->collsep;
217}
218
219//____________________________________________________________________
220SoMaterial * 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);
233 ++(m_d->largechangescount_sep);
234 m_d->theswitch->enableNotify(false);
235 ++(m_d->largechangescount_switch);
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{
260 m_d->extraWidgets = provideExtraWidgetsForGuiRow();
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//____________________________________________________________________
288void 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);
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
306 m_d->matButton->copyValuesFromMaterial(m_d->material);
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;
354 m_d->lastMatTransparency = t;
355 m_d->lastMatBrightness = b;
357}
VP1Collection(IVP1System *sys=0, const QString &helperClassName="VP1Collection")
virtual QList< QWidget * > widgetsForGuiRow() const
QByteArray restoreByteArray()
void disableUnrestoredChecks()
qint32 version() const
void messageVerbose(const QString &) const
const QString & helperClassName() const
void message(const QString &) const
void messageDebug(const QString &) const
static bool deserialiseSoMaterial(QByteArray &, SoMaterial *&)
QList< QWidget * > extraWidgets
VP1MaterialButtonBase * matButton
virtual bool load()=0
virtual QString matButtonToolTip() const
virtual void setExtraWidgetsState(const QByteArray &)
QList< QWidget * > provideWidgetsForGuiRow() const
double collMaterialTransparency() const
virtual qint32 provideCollTypeID() const
virtual void collMaterialTransparencyAndBrightnessChanged()
bool problemsLoading() const
virtual void assignDefaultMaterial(SoMaterial *) const =0
SoMaterial * material() const
virtual void largeChangesEnd()
virtual void init(VP1MaterialButtonBase *button=0)
SoSeparator * collSep() const
All 3D objects from this coll.
SoSwitch * collSwitch() const
Add this somewhere in your scenegraph (do not add any children here!)
virtual void largeChangesBegin()
virtual QString checkBoxToolTip() const
qint32 collTypeID() const
virtual QByteArray providePersistifiableID() const
double collMaterialBrightness() const
void possibleChangeMatTranspOrBrightness()
virtual QByteArray persistifiableState() const
Provide default implementation based on widget list + version.
void visibilityChanged(bool)
QString text() const
virtual QByteArray extraWidgetsState() const
virtual void setState(const QByteArray &)
Provide default implementation based on widget list + version.
virtual QList< QWidget * > provideExtraWidgetsForGuiRow() const
virtual QString provideText() const =0
VP1StdCollection(IVP1System *, const QString &helperClassName)