ATLAS Offline Software
Loading...
Searching...
No Matches
MissingEtCollectionSettingsButton.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
7
8#include "ui_permissingetcollectionsettings_form.h"
9
10//VP1
15#include "VP1Base/VP1Interval.h"
16
17//SoCoin
18#include "Inventor/nodes/SoDrawStyle.h"
19#include "Inventor/nodes/SoLightModel.h"
20#include "Inventor/nodes/SoMaterial.h"
21
22// Qt
23#include <QTimer>
24#include <QByteArray>
25#include <QBuffer>
26#include <QDataStream>
27#include <QMouseEvent>
28#include <QDragEnterEvent>
29#include <QDropEvent>
30#include <QShortcut>
31#include <QMimeData>
32#include <QDrag>
33
34// Misc
35#include <iostream>
36
37//____________________________________________________________________
39public:
45 QWidget * editwindow;
46 Ui::MissingEtSettingsForm editwindow_ui{};
47
48 VP1MaterialButton* matButton;// main collection colour
49
50 int dim;
51
52 SoDrawStyle * vertexDrawStyle;
53 SoLightModel * vertexLightModel;
54
55 //GUI - last values
59
61
62 void initEditWindow();
63};
64
65//____________________________________________________________________
67{
68 if (editwindow)
69 return;
70 theclass->messageVerbose("Initializing material editor dialog");
71 editwindow = new QWidget(0,Qt::WindowStaysOnTopHint);
73
74 // hide Eta cut widget
75 editwindow_ui.etaphi_widget->showEtaCut(false);
76
77 matButton = editwindow_ui.pushButton_matButton;
78
79}
80
81//____________________________________________________________________
83{
84 if (m_d->editwindow)
85 m_d->editwindow->setWindowTitle(t);
86 setToolTip(t);
87}
88
89//____________________________________________________________________
92{
93 m_d->dim = dim;
94
95 m_d->theclass = this;
96 m_d->initEditWindow();
97
98 //Draw Styles / Complexity:
99
100 m_d->vertexDrawStyle = new SoDrawStyle;
101 m_d->vertexDrawStyle->setName("VertexDrawStyle");
102 m_d->vertexDrawStyle->pointSize=5.0;
103 m_d->vertexDrawStyle->ref();
105
106 // MET length and thickness
107 connect(m_d->editwindow_ui.horizontalSlider_met_len,SIGNAL(valueChanged(int)),this,SIGNAL(metSizeChanged(int)));
108 connect(m_d->editwindow_ui.horizontalSlider_met_thickness,SIGNAL(valueChanged(int)),this,SIGNAL(metSizeChanged(int)));
109
110 // Light model
111 m_d->vertexLightModel = new SoLightModel;
112 m_d->vertexLightModel->setName("METLightModel");
113 m_d->vertexLightModel->ref();
114
116 connect(m_d->editwindow_ui.checkBox_verticesUseBaseLightModel,SIGNAL(toggled(bool)),this,SLOT(updateVertexLightModel(bool)));
117
118 // Phi cut
119 connect(m_d->editwindow_ui.etaphi_widget,SIGNAL(allowedPhiChanged(const QList<VP1Interval>&)),this,SIGNAL(cutAllowedPhiChanged(const QList<VP1Interval>&)));
120
121// // R
122// connect(m_d->editwindow_ui.checkBox_cut_r,SIGNAL(toggled(bool)),this,SLOT(possibleChange_cutAllowedR()));
123// connect(m_d->editwindow_ui.checkBox_cut_r_range_forcesymmetric,SIGNAL(toggled(bool)),this,SLOT(possibleChange_cutAllowedR()));
124// connect(m_d->editwindow_ui.checkBox_cut_r_excludeRange,SIGNAL(toggled(bool)),this,SLOT(possibleChange_cutAllowedR()));
125// connect(m_d->editwindow_ui.doubleSpinBox_cut_r_lower,SIGNAL(valueChanged(double)),this,SLOT(possibleChange_cutAllowedR()));
126// connect(m_d->editwindow_ui.doubleSpinBox_cut_r_upper,SIGNAL(valueChanged(double)),this,SLOT(possibleChange_cutAllowedR()));
127
128// // Z
129// connect(m_d->editwindow_ui.checkBox_cut_z,SIGNAL(toggled(bool)),this,SLOT(possibleChange_cutAllowedZ()));
130// connect(m_d->editwindow_ui.checkBox_cut_z_range_forcesymmetric,SIGNAL(toggled(bool)),this,SLOT(possibleChange_cutAllowedZ()));
131// connect(m_d->editwindow_ui.checkBox_cut_z_excludeRange,SIGNAL(toggled(bool)),this,SLOT(possibleChange_cutAllowedZ()));
132// connect(m_d->editwindow_ui.doubleSpinBox_cut_z_lower,SIGNAL(valueChanged(double)),this,SLOT(possibleChange_cutAllowedZ()));
133// connect(m_d->editwindow_ui.doubleSpinBox_cut_z_upper,SIGNAL(valueChanged(double)),this,SLOT(possibleChange_cutAllowedZ()));
134
135
136 // Material
137 connect(this,SIGNAL(clicked()),this,SLOT(showEditMaterialDialog()));
138 connect(m_d->editwindow_ui.pushButton_close,SIGNAL(clicked()),this,SLOT(showEditMaterialDialog()));
139 connect(m_d->matButton,SIGNAL(lastAppliedChanged()),this,SLOT(updateButton()));
140 connect(m_d->matButton,SIGNAL(lastAppliedChanged()),this,SIGNAL(lastAppliedChanged()));
141 setAcceptDrops(true);
142
143 QTimer::singleShot(0, this, SLOT(updateButton()));
144
145}
146
147// QWidget& MissingEtCollectionSettingsButton::editWindow() {
148// if (!m_d->editwindow)
149// initEditWindow();
150// return *(m_d->editwindow);
151// }
153{
154 delete m_d->editwindow;
155 m_d->vertexDrawStyle->unref();
156 m_d->vertexLightModel->unref();
157 delete m_d;
158}
159
161{
162 if (objectName().isEmpty())
163 setObjectName("MissingEtCollectionSettingsButton");
164 messageVerbose("setColButtonProperties: color=" + str(m_d->matButton->lastAppliedDiffuseColour()));
165 VP1ColorSelectButton::setColButtonProperties(this,m_d->matButton->lastAppliedDiffuseColour(),m_d->dim);
166}
167
169{
170 if (m_d->dim == dim)
171 return;
172 m_d->dim = dim;
173 updateButton();
174}
175
177{
178 if (!m_d->editwindow)
179 m_d->initEditWindow();
180
181 if (m_d->editwindow->isHidden())
182 m_d->editwindow->show();
183 else
184 m_d->editwindow->hide();
185}
186
188{
189 // std::cout<<"MissingEtCollectionSettingsButton::setMaterial with mat="<<mat<<std::endl;
190 if (!m_d->matButton) m_d->initEditWindow();
191 m_d->matButton->setMaterial(mat);
192 return true;
193}
194
196{
197 if (!m_d->matButton) m_d->initEditWindow();
198 m_d->matButton->setMaterial(mat);
199}
201{
202 if (!m_d->matButton) m_d->initEditWindow();
203 return m_d->matButton->lastAppliedTransparency();
204}
206{
207 if (!m_d->matButton) m_d->initEditWindow();
208 return m_d->matButton->lastAppliedShininess();
209}
211{
212 if (!m_d->matButton) m_d->initEditWindow();
213 return m_d->matButton->lastAppliedBrightness();
214}
215
216
218{
219 // TODO: Do I need this???
220
221 // double val = VP1QtInventorUtils::getValueLineWidthSlider(m_d->editwindow_ui.horizontalSlider_vertexSize);
222 // if (m_d->vertexDrawStyle->lineWidth.getValue()!=val)
223 // m_d->vertexDrawStyle->lineWidth = val;
224}
225
227{
228 if (m_d->vertexLightModel->model.getValue()!=(base?SoLightModel::BASE_COLOR:SoLightModel::PHONG)) {
229 messageVerbose("VertexLightModel changed (base = "+str(base));
230 if (base)
231 m_d->vertexLightModel->model.setValue(SoLightModel::BASE_COLOR);
232 else
233 m_d->vertexLightModel->model.setValue(SoLightModel::PHONG);
234 }
235}
236
237
238//SoDrawStyle * MissingEtCollectionSettingsButton::vertexDrawStyle() const
239//{
240// return m_d->vertexDrawStyle;
241//}
242//
243//SoLightModel * MissingEtCollectionSettingsButton::vertexLightModel() const
244//{
245// return m_d->vertexLightModel;
246//}
247
249{
250 return m_d->editwindow_ui.horizontalSlider_met_len->value();
251}
252
254{
255 return m_d->editwindow_ui.horizontalSlider_met_thickness->value();
256}
257
258
259//____________________________________________________________________
261{
262 if (event->button() == Qt::LeftButton)
263 m_d->dragStartPosition = event->pos();
264 QPushButton::mousePressEvent(event);
265}
266
267//____________________________________________________________________
269{
270 if (event->source()!=this && event->mimeData()->hasFormat("vp1/material"))
271 event->acceptProposedAction();
272}
273
274//____________________________________________________________________
276{
277 if (!(event->buttons() & Qt::LeftButton))
278 return;
279 if ((event->pos() - m_d->dragStartPosition).manhattanLength()
280 < QApplication::startDragDistance())
281 return;
282
283 QDrag *drag = new QDrag(this);
284 QMimeData *mimeData = new QMimeData;
285
287 // For dragging state onto other material buttons: //
289
290 QByteArray byteArray = saveState();
291
292 // buffer.close();
293 mimeData->setData("vp1/material", byteArray);
294
295 // ////////////////////////////////////////////////////////
296 // // For dragging c++ code for defining this material //
297 // // into e.g. an editor: //
298 // ////////////////////////////////////////////////////////
299 //
300 // QString s = "SoMaterial * mat = new SoMaterial;\n";
301 // QString str_ambient = m_d->toSbColTxt(m_d->lastapplied_ambient);
302 // if (str_ambient!="SbColor(0.2,0.2,0.2)")
303 // s += "mat->ambientColor.setValue("+str_ambient+");\n";
304 // QString str_diffuse = m_d->toSbColTxt(m_d->lastapplied_diffuse);
305 // if (str_diffuse!="SbColor(0.8,0.8,0.8)")
306 // s += "mat->diffuseColor.setValue("+str_diffuse+");\n";
307 // QString str_specular = m_d->toSbColTxt(m_d->lastapplied_specular);
308 // if (str_specular!="SbColor(0,0,0)")
309 // s += "mat->specularColor.setValue("+str_specular+");\n";
310 // QString str_emissive = m_d->toSbColTxt(m_d->lastapplied_emissive);
311 // if (str_emissive!="SbColor(0,0,0)")
312 // s += "mat->emissiveColor.setValue("+str_emissive+");\n";
313 // QString str_shininess = m_d->printFloat(m_d->lastapplied_shininess/100.0);
314 // if (str_shininess!="0.2")
315 // s += "mat->shininess.setValue("+str_shininess+");\n";
316 // QString str_transparency = m_d->printFloat(m_d->lastapplied_transparency/100.0);
317 // if (str_transparency!="0")
318 // s += "mat->transparency.setValue("+str_transparency+");\n";
319 // mimeData->setText(s);
320
321 //Execute drag:
322 drag->setMimeData(mimeData);//drag assumes ownership of mimeData
323 drag->exec(Qt::CopyAction | Qt::MoveAction);
324}
325
326//____________________________________________________________________
328{
329 QByteArray data = event->mimeData()->data("vp1/material");
330 event->acceptProposedAction();
332}
333
334
336 // messageVerbose("getState");
337 // if (m_d->editwindow_ui.checkBox_tracksUseBaseLightModel->isChecked()) messageVerbose("checked!");
338 VP1Serialise serialise(1/*version*/);
339
340 serialise.save(m_d->matButton);
341 // serialise.disableUnsavedChecks();
342
343 // MET length and thickness
344 serialise.save(m_d->editwindow_ui.horizontalSlider_met_len);
345 serialise.save(m_d->editwindow_ui.horizontalSlider_met_thickness);
346
347 // Light model
348 serialise.save(m_d->editwindow_ui.checkBox_verticesUseBaseLightModel);
349
350 // ETA-PHI CUTS (from VP1Base/VP1EtaPhiCutWidget.cxx)
351 serialise.save(m_d->editwindow_ui.etaphi_widget);
352
353
354// // R
355// serialise.save(m_d->editwindow_ui.checkBox_cut_r);
356// serialise.save(m_d->editwindow_ui.checkBox_cut_r_range_forcesymmetric);
357// serialise.save(m_d->editwindow_ui.checkBox_cut_r_excludeRange);
358// serialise.save(m_d->editwindow_ui.doubleSpinBox_cut_r_lower);
359// serialise.save(m_d->editwindow_ui.doubleSpinBox_cut_r_upper);
360
362// serialise.save(m_d->editwindow_ui.checkBox_cut_z);
363// serialise.save(m_d->editwindow_ui.checkBox_cut_z_range_forcesymmetric);
364// serialise.save(m_d->editwindow_ui.checkBox_cut_z_excludeRange);
365// serialise.save(m_d->editwindow_ui.doubleSpinBox_cut_z_lower);
366// serialise.save(m_d->editwindow_ui.doubleSpinBox_cut_z_upper);
367
368 serialise.widgetHandled(this);
369 serialise.warnUnsaved(this);
370 return serialise.result();
371}
372
374
375 VP1Deserialise state(ba,systemBase());
376 if (state.version()<0||state.version()>1)
377 return;//Ignore silently
378
379 // MATERIAL BUTTON (color,...)
380 state.restore(m_d->matButton);
381
382 // MET length and thickness
383 state.restore(m_d->editwindow_ui.horizontalSlider_met_len);
384 state.restore(m_d->editwindow_ui.horizontalSlider_met_thickness);
385
386 // Light model
387 state.restore(m_d->editwindow_ui.checkBox_verticesUseBaseLightModel);
388
389 // ETA-PHI CUTS (from VP1Base/VP1EtaPhiCutWidget.cxx)
390 state.restore(m_d->editwindow_ui.etaphi_widget);
391
392 state.widgetHandled(this);
393 state.warnUnrestored(this);
394
396 updateVertexLightModel(m_d->editwindow_ui.checkBox_verticesUseBaseLightModel);
397
398 updateButton();
399 //FIXME - anything else need updating?
400}
401
402
403//____________________________________________________________________
405{
406 if (!m_d->editwindow)
407 m_d->initEditWindow();
408 return m_d->editwindow_ui.etaphi_widget->allowedPhi();
409}
410
411
412
413
415//VP1Interval MissingEtCollectionSettingsButton::cutAllowedR() const
416//{
417// if (!m_d->editwindow)
418// m_d->initEditWindow();
419// if (!m_d->editwindow_ui.checkBox_cut_r)
420// return VP1Interval();
421//
422// const double minFromInterface=m_d->editwindow_ui.doubleSpinBox_cut_r_lower->value()*1000;
423// const double maxFromInterface=m_d->editwindow_ui.doubleSpinBox_cut_r_upper->value()*1000;
424//
425// double min=0.0,max=0.0;
426//
427// min = (m_d->editwindow_ui.checkBox_cut_r->isChecked() ? minFromInterface : -std::numeric_limits<double>::infinity());
428// max = (m_d->editwindow_ui.checkBox_cut_r->isChecked() ? maxFromInterface : std::numeric_limits<double>::infinity());
429//
430// // FIXME - add symmetry logic
431//
432// //message("cutAllowedPt: min,max="+QString::number(min)+","+QString::number(max));
433//
434// if (max<min)
435// return VP1Interval();
436//
437// return VP1Interval( min, max );//fixme: closed interval??
438//}
439
441//VP1Interval MissingEtCollectionSettingsButton::cutAllowedZ() const
442//{
443// if (!m_d->editwindow)
444// m_d->initEditWindow();
445// if (!m_d->editwindow_ui.checkBox_cut_z)
446// return VP1Interval();
447//
448// const double minFromInterface=m_d->editwindow_ui.doubleSpinBox_cut_z_lower->value()*1000;
449// const double maxFromInterface=m_d->editwindow_ui.doubleSpinBox_cut_z_upper->value()*1000;
450//
451// double min=0.0,max=0.0;
452//
453// min = (m_d->editwindow_ui.checkBox_cut_z->isChecked() ? minFromInterface : -std::numeric_limits<double>::infinity());
454// max = (m_d->editwindow_ui.checkBox_cut_z->isChecked() ? maxFromInterface : std::numeric_limits<double>::infinity());
455//
456// // FIXME - add symmetry logic
457//
458// //message("cutAllowedPt: min,max="+QString::number(min)+","+QString::number(max));
459//
460// if (max<min)
461// return VP1Interval();
462//
463// return VP1Interval( min, max );//fixme: closed interval??
464//}
465
466//void MissingEtCollectionSettingsButton::possibleChange_cutAllowedR()
467//{
468// messageVerbose("possibleChange_cutAllowedR() ");
469//
470// if (m_d->last_cutAllowedR==cutAllowedR()) return;
471// messageVerbose("cutAllowedR() changed");
472// m_d->last_cutAllowedR= cutAllowedR();
473// emit cutAllowedRChanged(m_d->last_cutAllowedR);
474//}
475
476//void MissingEtCollectionSettingsButton::possibleChange_cutAllowedZ()
477//{
478// messageVerbose("possibleChange_cutAllowedZ() ");
479//
480// if (m_d->last_cutAllowedZ==cutAllowedZ()) return;
481// messageVerbose("cutAllowedZ() changed");
482// m_d->last_cutAllowedZ= cutAllowedZ();
483// emit cutAllowedZChanged(m_d->last_cutAllowedZ);
484//}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
MissingEtCollectionSettingsButton(QWidget *parent=0, int dim=25)
void cutAllowedPhiChanged(const QList< VP1Interval > &)
QByteArray saveState() const
fill out with the state of the object (used for drag and drop etc)
VP1CollectionSettingsButtonBase(QWidget *parent=0, int dim=25)
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
std::string base
Definition hcg.cxx:81