ATLAS Offline Software
Loading...
Searching...
No Matches
IParticleCollectionSettingsButton.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Local
8#include "ui_periparticlecollectionsettings_form.h"
9#include "ui_settings_cuts_form.h"
10
11//VP1
15
16//SoCoin
17#include "Inventor/nodes/SoDrawStyle.h"
18#include "Inventor/nodes/SoLightModel.h"
19
20// Qt
21#include <QTimer>
22#include <QByteArray>
23#include <QBuffer>
24#include <QDataStream>
25#include <QMouseEvent>
26#include <QDragEnterEvent>
27#include <QDropEvent>
28#include <QShortcut>
29#include <QMimeData>
30#include <QDrag>
31
32// Misc
33#include <iostream>
34
35//____________________________________________________________________
58
59//____________________________________________________________________
61{
62 /*
63 * Note: the Eta-Phi widget is inserted
64 * promoting an empty QWidget to VP1EtaPhiCutWidget
65 * directly in the periparticlecollectionsettingsform.ui!!
66 */
67
68 if (editwindow)
69 return;
70 theclass->messageVerbose("Initialising material editor dialog");
71 editwindow = new QWidget(0,Qt::WindowStaysOnTopHint);
73 matButton = editwindow_ui.pushButton_matButton;
74}
75
79
80
81//____________________________________________________________________
83{
84 if (m_d->editwindow)
85 m_d->editwindow->setWindowTitle(t);
86 setToolTip(t);
87}
88
89//____________________________________________________________________
91 : VP1MaterialButtonBase(parent,0,"VP1MaterialButton"), m_d(new Imp)
92{
93 m_d->dim = dim;
94
95 m_d->theclass = this;
96 m_d->initEditWindow();
97
98 // -> cutAllowedP/Pt
99 connect(m_d->editwindow_ui.checkBox_cut_minpt,SIGNAL(toggled(bool)),this,SLOT(possibleChange_cutAllowedPt()));
100 connect(m_d->editwindow_ui.checkBox_cut_maxpt,SIGNAL(toggled(bool)),this,SLOT(possibleChange_cutAllowedPt()));
101 connect(m_d->editwindow_ui.doubleSpinBox_cut_minpt_gev,SIGNAL(valueChanged(double)),this,SLOT(possibleChange_cutAllowedPt()));
102 connect(m_d->editwindow_ui.doubleSpinBox_cut_maxpt_gev,SIGNAL(valueChanged(double)),this,SLOT(possibleChange_cutAllowedPt()));
103 connect(m_d->editwindow_ui.checkBox_cut_minpt,SIGNAL(toggled(bool)),this,SLOT(possibleChange_cutAllowedPt()));
104 connect(m_d->editwindow_ui.comboBox_momtype,SIGNAL(currentIndexChanged(int)),this,SLOT(possibleChange_cutAllowedPt()));
105
106 // -> cutAllowedEta
107 connect(m_d->editwindow_ui.etaPhiCutWidget,SIGNAL(allowedEtaChanged(const VP1Interval&)),this,SLOT(possibleChange_cutAllowedEta()));
108
109 // -> cutAllowedPhi
110 connect(m_d->editwindow_ui.etaPhiCutWidget,SIGNAL(allowedPhiChanged(const QList<VP1Interval>&)),this,SLOT(possibleChange_cutAllowedPhi()));
111
112 connect(this,SIGNAL(clicked()),this,SLOT(showEditMaterialDialog()));
113 connect(m_d->editwindow_ui.pushButton_close,SIGNAL(clicked()),this,SLOT(showEditMaterialDialog()));
114 connect(m_d->matButton,SIGNAL(lastAppliedChanged()),this,SLOT(updateButton()));
115 connect(m_d->matButton,SIGNAL(lastAppliedChanged()),this,SIGNAL(lastAppliedChanged()));
116 setAcceptDrops(true);
117
118 QTimer::singleShot(0, this, SLOT(updateButton()));
119
120}
121
122// QWidget& IParticleCollectionSettingsButton::editWindow() {
123// if (!m_d->editwindow)
124// initEditWindow();
125// return *(m_d->editwindow);
126// }
128{
129 delete m_d->editwindow;
130 m_d->trackDrawStyle->unref();
131 m_d->lightModel->unref();
132 delete m_d;
133}
134
136{
137 if (objectName().isEmpty())
138 setObjectName("IParticleCollectionSettingsButton");
139 messageVerbose("setColButtonProperties: color=" + str(m_d->matButton->lastAppliedDiffuseColour()));
140 VP1ColorSelectButton::setColButtonProperties(this,m_d->matButton->lastAppliedDiffuseColour(),m_d->dim);
141}
142
144{
145 if (m_d->dim == dim)
146 return;
147 m_d->dim = dim;
148 updateButton();
149}
150
152{
153 if (!m_d->editwindow)
154 m_d->initEditWindow();
155
156 if (m_d->editwindow->isHidden())
157 m_d->editwindow->show();
158 else
159 m_d->editwindow->hide();
160}
161
163{
164 if (!m_d->matButton) m_d->initEditWindow();
165 m_d->matButton->setMaterial(mat);
166 return true;
167}
168
170{
171 if (!m_d->matButton) m_d->initEditWindow();
172 m_d->matButton->setMaterial(mat);
173}
175{
176 if (!m_d->matButton) m_d->initEditWindow();
177 return m_d->matButton->lastAppliedTransparency();
178}
180{
181 if (!m_d->matButton) m_d->initEditWindow();
182 return m_d->matButton->lastAppliedShininess();
183}
185{
186 if (!m_d->matButton) m_d->initEditWindow();
187 return m_d->matButton->lastAppliedBrightness();
188}
189
190
192{
193 // double val = VP1QtInventorUtils::getValueLineWidthSlider(m_d->editwindow_ui.horizontalSlider_trackWidth);
194 // if (m_d->trackDrawStyle->lineWidth.getValue()!=val)
195 // m_d->trackDrawStyle->lineWidth = val;
196}
197
199{
200 if (m_d->lightModel->model.getValue()!=(base?SoLightModel::BASE_COLOR:SoLightModel::PHONG)) {
201 messageVerbose("lightModel changed (base = "+str(base));
202 if (base)
203 m_d->lightModel->model.setValue(SoLightModel::BASE_COLOR);
204 else
205 m_d->lightModel->model.setValue(SoLightModel::PHONG);
206 }
207}
208
209
210
212{
213 return m_d->trackDrawStyle;
214}
215
217{
218 return m_d->lightModel;
219}
220
221
222//____________________________________________________________________
224{
225 if (event->button() == Qt::LeftButton)
226 m_d->dragStartPosition = event->pos();
227 QPushButton::mousePressEvent(event);
228}
229
230//____________________________________________________________________
232{
233 if (event->source()!=this && event->mimeData()->hasFormat("vp1/material"))
234 event->acceptProposedAction();
235}
236
237//____________________________________________________________________
239{
240 if (!(event->buttons() & Qt::LeftButton))
241 return;
242 if ((event->pos() - m_d->dragStartPosition).manhattanLength()
243 < QApplication::startDragDistance())
244 return;
245
246 QDrag *drag = new QDrag(this);
247 QMimeData *mimeData = new QMimeData;
248
250 // For dragging state onto other material buttons: //
252
253 QByteArray byteArray = saveState();
254
255 // buffer.close();
256 mimeData->setData("vp1/material", byteArray);
257
258 // ////////////////////////////////////////////////////////
259 // // For dragging c++ code for defining this material //
260 // // into e.g. an editor: //
261 // ////////////////////////////////////////////////////////
262 //
263 // QString s = "SoMaterial * mat = new SoMaterial;\n";
264 // QString str_ambient = m_d->toSbColTxt(m_d->lastapplied_ambient);
265 // if (str_ambient!="SbColor(0.2,0.2,0.2)")
266 // s += "mat->ambientColor.setValue("+str_ambient+");\n";
267 // QString str_diffuse = m_d->toSbColTxt(m_d->lastapplied_diffuse);
268 // if (str_diffuse!="SbColor(0.8,0.8,0.8)")
269 // s += "mat->diffuseColor.setValue("+str_diffuse+");\n";
270 // QString str_specular = m_d->toSbColTxt(m_d->lastapplied_specular);
271 // if (str_specular!="SbColor(0,0,0)")
272 // s += "mat->specularColor.setValue("+str_specular+");\n";
273 // QString str_emissive = m_d->toSbColTxt(m_d->lastapplied_emissive);
274 // if (str_emissive!="SbColor(0,0,0)")
275 // s += "mat->emissiveColor.setValue("+str_emissive+");\n";
276 // QString str_shininess = m_d->printFloat(m_d->lastapplied_shininess/100.0);
277 // if (str_shininess!="0.2")
278 // s += "mat->shininess.setValue("+str_shininess+");\n";
279 // QString str_transparency = m_d->printFloat(m_d->lastapplied_transparency/100.0);
280 // if (str_transparency!="0")
281 // s += "mat->transparency.setValue("+str_transparency+");\n";
282 // mimeData->setText(s);
283
284 //Execute drag:
285 drag->setMimeData(mimeData);//drag assumes ownership of mimeData
286 drag->exec(Qt::CopyAction | Qt::MoveAction);
287}
288
289//____________________________________________________________________
291{
292 QByteArray data = event->mimeData()->data("vp1/material");
293 event->acceptProposedAction();
295}
296
297
299 // messageVerbose("getState");
300 // if (m_d->editwindow_ui.checkBox_tracksUseBaseLightModel->isChecked()) messageVerbose("checked!");
301 VP1Serialise serialise(1/*version*/);
302
303 serialise.save(m_d->matButton);
304 // serialise.disableUnsavedChecks();
305 // FIXME - what about eta/phi?
306
307 serialise.widgetHandled(this);
308 serialise.warnUnsaved(this);
309 return serialise.result();
310}
311
313
314 VP1Deserialise state(ba,systemBase());
315 if (state.version()<0||state.version()>1)
316 return;//Ignore silently
317 state.restore(m_d->matButton);
318 state.widgetHandled(this);
319 state.warnUnrestored(this);
320 updateButton();
321 //FIXME - anything else need updating?
322}
323
324//____________________________________________________________________
326{
327 if (!m_d->editwindow_ui.checkBox_cut_minpt)
328 return VP1Interval();
329
330 // will set range to negative if we have momcut=P
331 // if minCut unset then min=-inf
332 // if minCut set, and Pt selected, then min=-minCut
333 // if minCut set, and P selected, then min=-maxCut
334 // etc
335 bool isPCut = m_d->editwindow_ui.comboBox_momtype->currentText()=="P";
336
337 const double minFromInterface=m_d->editwindow_ui.doubleSpinBox_cut_minpt_gev->value()*1000;
338 const double maxFromInterface=m_d->editwindow_ui.doubleSpinBox_cut_maxpt_gev->value()*1000;
339
340 double min=0.0,max=0.0;
341 if (!isPCut) {
342 //Pt cut
343 min = (m_d->editwindow_ui.checkBox_cut_minpt->isChecked() ? minFromInterface : -std::numeric_limits<double>::infinity());
344 max = (m_d->editwindow_ui.checkBox_cut_maxpt->isChecked() ? maxFromInterface : std::numeric_limits<double>::infinity());
345 } else {
346 min = (m_d->editwindow_ui.checkBox_cut_maxpt->isChecked() ? -maxFromInterface : -std::numeric_limits<double>::infinity());
347 max = (m_d->editwindow_ui.checkBox_cut_minpt->isChecked() ? -minFromInterface : std::numeric_limits<double>::infinity());
348 }
349
350 //message("cutAllowedPt: min,max="+QString::number(min)+","+QString::number(max));
351
352 if (max<min)
353 return VP1Interval();
354
355 return VP1Interval( min, max );//fixme: closed interval??
356}
357
358//____________________________________________________________________
360{
361 return m_d->editwindow_ui.etaPhiCutWidget->allowedEta();
362}
363
364//____________________________________________________________________
366{
367 return m_d->editwindow_ui.etaPhiCutWidget->allowedPhi();
368}
369
371{
372 messageVerbose("IParticleCollectionSettingsButton::possibleChange_cutAllowedPt() ");
373
374 if (m_d->last_cutAllowedPt==cutAllowedPt()) return;
375 messageVerbose("cutAllowedPt() changed");
376 m_d->last_cutAllowedPt = cutAllowedPt();
377 emit cutAllowedPtChanged(m_d->last_cutAllowedPt);
378}
379
381{
382 if (m_d->last_cutAllowedEta==cutAllowedEta()) return;
383 messageVerbose("cutAllowedEta() changed");
384 m_d->last_cutAllowedEta=cutAllowedEta();
385 emit cutAllowedEtaChanged(m_d->last_cutAllowedEta);
386}
387
389{
390 if (m_d->last_cutAllowedPhi==cutAllowedPhi()) return;
391 messageVerbose("cutAllowedPhi() changed");
392 m_d->last_cutAllowedPhi=cutAllowedPhi();
393 emit cutAllowedPhiChanged(m_d->last_cutAllowedPhi);
394}
395
396
397
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
void cutAllowedPhiChanged(const QList< VP1Interval > &)
QByteArray saveState() const
fill out with the state of the object (used for drag and drop etc)
void cutAllowedEtaChanged(const VP1Interval &)
IParticleCollectionSettingsButton(QWidget *parent=0, int dim=25)
void cutAllowedPtChanged(const VP1Interval &)
static void setColButtonProperties(QPushButton *, const QColor &col, int dim)
void restore(QCheckBox *sb)
void warnUnrestored(QObject *)
void widgetHandled(QWidget *)
qint32 version() const
void messageVerbose(const QString &) const
IVP1System * systemBase() const
VP1MaterialButtonBase(QWidget *parent, IVP1System *sys=0, const QString &helpername="")
std::string base
Definition hcg.cxx:81