ATLAS Offline Software
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
13 #include "VP1Base/VP1Serialise.h"
14 #include "VP1Base/VP1Deserialise.h"
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 //____________________________________________________________________
37 public:
40  QWidget * editwindow;
41  Ui::IParticleCollectionSettingsForm editwindow_ui{};
42 
44 
45  SoDrawStyle * trackDrawStyle;
46  SoLightModel * lightModel;
47 
48  //GUI - last values
52  QList<VP1Interval> last_cutAllowedPhi;
53  int dim;
55 
56  void initEditWindow();
57 };
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);
72  editwindow_ui.setupUi(editwindow);
73  matButton = editwindow_ui.pushButton_matButton;
74 }
75 
78 }
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;
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()));
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();
166  return true;
167 }
168 
170 {
171  if (!m_d->matButton) m_d->initEditWindow();
173 }
175 {
176  if (!m_d->matButton) m_d->initEditWindow();
178 }
180 {
181  if (!m_d->matButton) m_d->initEditWindow();
183 }
185 {
186  if (!m_d->matButton) m_d->initEditWindow();
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");
378 }
379 
381 {
382  if (m_d->last_cutAllowedEta==cutAllowedEta()) return;
383  messageVerbose("cutAllowedEta() changed");
386 }
387 
389 {
390  if (m_d->last_cutAllowedPhi==cutAllowedPhi()) return;
391  messageVerbose("cutAllowedPhi() changed");
394 }
395 
396 
397 
VP1Serialise.h
base
std::string base
Definition: hcg.cxx:78
IParticleCollectionSettingsButton::lastAppliedShininess
virtual double lastAppliedShininess() const
Definition: IParticleCollectionSettingsButton.cxx:179
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
VP1Deserialise.h
yodamerge_tmp.dim
dim
Definition: yodamerge_tmp.py:239
VP1Serialise
Definition: VP1Serialise.h:45
IParticleCollectionSettingsButton::cutAllowedEtaChanged
void cutAllowedEtaChanged(const VP1Interval &)
IParticleCollectionSettingsButton::initEditWindow
void initEditWindow()
Definition: IParticleCollectionSettingsButton.cxx:76
RoiUtil::serialise
void serialise(const std::vector< const IRoiDescriptor * > &rois, roiserial_type &s)
serialise an entire vector of IRoiDescriptors
Definition: RoiSerialise.cxx:45
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
mat
GeoMaterial * mat
Definition: LArDetectorConstructionTBEC.cxx:55
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
IParticleCollectionSettingsButton::cutAllowedPt
VP1Interval cutAllowedPt() const
Definition: IParticleCollectionSettingsButton.cxx:325
VP1MaterialButton
Definition: VP1MaterialButton.h:46
VP1HelperClassBase::messageVerbose
void messageVerbose(const QString &) const
Definition: VP1HelperClassBase.cxx:78
IParticleCollectionSettingsButton::Imp::last_cutAllowedP
VP1Interval last_cutAllowedP
Definition: IParticleCollectionSettingsButton.cxx:50
IParticleCollectionSettingsButton::Imp::trackDrawStyle
SoDrawStyle * trackDrawStyle
Definition: IParticleCollectionSettingsButton.cxx:45
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
IParticleCollectionSettingsButton::mousePressEvent
void mousePressEvent(QMouseEvent *event)
Definition: IParticleCollectionSettingsButton.cxx:223
IParticleCollectionSettingsButton::lightModel
SoLightModel * lightModel() const
Definition: IParticleCollectionSettingsButton.cxx:216
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
IParticleCollectionSettingsButton::lastAppliedTransparency
virtual double lastAppliedTransparency() const
Definition: IParticleCollectionSettingsButton.cxx:174
VP1MaterialButton::lastAppliedDiffuseColour
QColor lastAppliedDiffuseColour() const
Definition: VP1MaterialButton.cxx:167
IParticleCollectionSettingsButton::setDimension
void setDimension(int dim)
Definition: IParticleCollectionSettingsButton.cxx:143
VP1String::str
static QString str(const QString &s)
Definition: VP1String.h:49
VP1ColorSelectButton::setColButtonProperties
static void setColButtonProperties(QPushButton *, const QColor &col, int dim)
Definition: VP1ColorSelectButton.cxx:49
IParticleCollectionSettingsButton.h
IParticleCollectionSettingsButton::saveState
QByteArray saveState() const
fill out with the state of the object (used for drag and drop etc)
Definition: IParticleCollectionSettingsButton.cxx:298
IParticleCollectionSettingsButton::Imp::lightModel
SoLightModel * lightModel
Definition: IParticleCollectionSettingsButton.cxx:46
VP1QtInventorUtils.h
IParticleCollectionSettingsButton::Imp::last_cutAllowedPt
VP1Interval last_cutAllowedPt
Definition: IParticleCollectionSettingsButton.cxx:49
VP1Deserialise::version
qint32 version() const
Definition: VP1Deserialise.cxx:143
IParticleCollectionSettingsButton::updateButton
void updateButton()
Definition: IParticleCollectionSettingsButton.cxx:135
IParticleCollectionSettingsButton::Imp::last_cutAllowedPhi
QList< VP1Interval > last_cutAllowedPhi
Definition: IParticleCollectionSettingsButton.cxx:52
IParticleCollectionSettingsButton::updateLightModel
void updateLightModel(bool)
Definition: IParticleCollectionSettingsButton.cxx:198
IParticleCollectionSettingsButton::updateDrawStyle
void updateDrawStyle()
Definition: IParticleCollectionSettingsButton.cxx:191
IParticleCollectionSettingsButton::possibleChange_cutAllowedPt
void possibleChange_cutAllowedPt()
Definition: IParticleCollectionSettingsButton.cxx:370
IParticleCollectionSettingsButton::Imp::dragStartPosition
QPoint dragStartPosition
Definition: IParticleCollectionSettingsButton.cxx:54
IParticleCollectionSettingsButton::m_d
Imp * m_d
Definition: IParticleCollectionSettingsButton.h:67
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
IParticleCollectionSettingsButton::cutAllowedEta
VP1Interval cutAllowedEta() const
Definition: IParticleCollectionSettingsButton.cxx:359
VP1MaterialButton::lastAppliedBrightness
double lastAppliedBrightness() const
Definition: VP1MaterialButton.cxx:173
IParticleCollectionSettingsButton::Imp::last_cutAllowedEta
VP1Interval last_cutAllowedEta
Definition: IParticleCollectionSettingsButton.cxx:51
test_pyathena.parent
parent
Definition: test_pyathena.py:15
IParticleCollectionSettingsButton::Imp::editwindow_ui
Ui::IParticleCollectionSettingsForm editwindow_ui
Definition: IParticleCollectionSettingsButton.cxx:41
IParticleCollectionSettingsButton::cutAllowedPhi
QList< VP1Interval > cutAllowedPhi() const
Definition: IParticleCollectionSettingsButton.cxx:365
VP1Deserialise::restore
void restore(QCheckBox *sb)
Definition: VP1Deserialise.cxx:245
VP1ColorSelectButton.h
IParticleCollectionSettingsButton
Definition: IParticleCollectionSettingsButton.h:13
VP1Deserialise
Definition: VP1Deserialise.h:44
IParticleCollectionSettingsButton::possibleChange_cutAllowedPhi
void possibleChange_cutAllowedPhi()
Definition: IParticleCollectionSettingsButton.cxx:388
IParticleCollectionSettingsButton::lastAppliedBrightness
virtual double lastAppliedBrightness() const
Definition: IParticleCollectionSettingsButton.cxx:184
IParticleCollectionSettingsButton::possibleChange_cutAllowedEta
void possibleChange_cutAllowedEta()
Definition: IParticleCollectionSettingsButton.cxx:380
VP1MaterialButton::setMaterial
bool setMaterial(SoMaterial *)
Definition: VP1MaterialButton.cxx:447
VP1HelperClassBase::systemBase
IVP1System * systemBase() const
Definition: VP1HelperClassBase.h:50
IParticleCollectionSettingsButton::setText
virtual void setText(const QString &)
Definition: IParticleCollectionSettingsButton.cxx:82
IParticleCollectionSettingsButton::dragEnterEvent
void dragEnterEvent(QDragEnterEvent *event)
Definition: IParticleCollectionSettingsButton.cxx:231
VP1Deserialise::widgetHandled
void widgetHandled(QWidget *)
Definition: VP1Deserialise.cxx:658
IParticleCollectionSettingsButton::Imp::theclass
IParticleCollectionSettingsButton * theclass
Definition: IParticleCollectionSettingsButton.cxx:39
IParticleCollectionSettingsButton::~IParticleCollectionSettingsButton
virtual ~IParticleCollectionSettingsButton()
Definition: IParticleCollectionSettingsButton.cxx:127
VP1MaterialButtonBase
Definition: VP1MaterialButton.h:25
VP1MaterialButton::lastAppliedShininess
double lastAppliedShininess() const
Definition: VP1MaterialButton.cxx:172
IParticleCollectionSettingsButton::IParticleCollectionSettingsButton
IParticleCollectionSettingsButton(QWidget *parent=0, int dim=25)
Definition: IParticleCollectionSettingsButton.cxx:90
VP1Deserialise::warnUnrestored
void warnUnrestored(QObject *)
Definition: VP1Deserialise.cxx:696
IParticleCollectionSettingsButton::restoreFromState
void restoreFromState(const QByteArray &)
Definition: IParticleCollectionSettingsButton.cxx:312
VP1Interval
Definition: VP1Interval.h:23
IParticleCollectionSettingsButton::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *event)
Definition: IParticleCollectionSettingsButton.cxx:238
IParticleCollectionSettingsButton::cutAllowedPtChanged
void cutAllowedPtChanged(const VP1Interval &)
IParticleCollectionSettingsButton::Imp::dim
int dim
Definition: IParticleCollectionSettingsButton.cxx:53
IParticleCollectionSettingsButton::lastAppliedChanged
void lastAppliedChanged()
IParticleCollectionSettingsButton::showEditMaterialDialog
void showEditMaterialDialog()
Definition: IParticleCollectionSettingsButton.cxx:151
IParticleCollectionSettingsButton::setMaterial
virtual bool setMaterial(SoMaterial *)
Definition: IParticleCollectionSettingsButton.cxx:162
IParticleCollectionSettingsButton::cutAllowedPhiChanged
void cutAllowedPhiChanged(const QList< VP1Interval > &)
IParticleCollectionSettingsButton::Imp::matButton
VP1MaterialButton * matButton
Definition: IParticleCollectionSettingsButton.cxx:43
IParticleCollectionSettingsButton::Imp::editwindow
QWidget * editwindow
Definition: IParticleCollectionSettingsButton.cxx:40
IParticleCollectionSettingsButton::copyValuesFromMaterial
virtual void copyValuesFromMaterial(SoMaterial *)
Definition: IParticleCollectionSettingsButton.cxx:169
IParticleCollectionSettingsButton::Imp
Definition: IParticleCollectionSettingsButton.cxx:36
VP1MaterialButton::lastAppliedTransparency
double lastAppliedTransparency() const
Definition: VP1MaterialButton.cxx:171
IParticleCollectionSettingsButton::drawStyle
SoDrawStyle * drawStyle() const
Definition: IParticleCollectionSettingsButton.cxx:211
IParticleCollectionSettingsButton::dropEvent
void dropEvent(QDropEvent *event)
Definition: IParticleCollectionSettingsButton.cxx:290
IParticleCollectionSettingsButton::Imp::initEditWindow
void initEditWindow()
Definition: IParticleCollectionSettingsButton.cxx:60
IParticleCollectionSettingsButton::Imp::Imp
Imp()
Definition: IParticleCollectionSettingsButton.cxx:38