ATLAS Offline Software
Loading...
Searching...
No Matches
VertexCollectionSettingsButton.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_pervertexcollectionsettings_form.h"
9
10//VP1
14#include "VP1Base/VP1Interval.h"
15
16//SoCoin
17
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//____________________________________________________________________
65
66//____________________________________________________________________
68{
69 if (editwindow)
70 return;
71 theclass->messageVerbose("Initialising material editor dialog");
72 editwindow = new QWidget(0,Qt::WindowStaysOnTopHint);
74 matButton = editwindow_ui.pushButton_matButton;
75}
76
77//____________________________________________________________________
79{
80 if (m_d->editwindow)
81 m_d->editwindow->setWindowTitle(t);
82 setToolTip(t);
83}
84
85//____________________________________________________________________
87 : VP1MaterialButtonBase(parent,0,"VP1MaterialButton"), m_d(new Imp)
88{
89 m_d->dim = dim;
90
91 m_d->theclass = this;
92 m_d->initEditWindow();
93
94 //Draw Styles / Complexity:
95
96 m_d->vertexDrawStyle = new SoDrawStyle;
97 m_d->vertexDrawStyle->setName("VertexDrawStyle");
98 m_d->vertexDrawStyle->pointSize=5.0;
99 m_d->vertexDrawStyle->ref();
101 connect(m_d->editwindow_ui.horizontalSlider_vertexSize,SIGNAL(valueChanged(int)),this,SIGNAL(vertexSizeChanged(int)));
102
103 m_d->vertexLightModel = new SoLightModel;
104 m_d->vertexLightModel->setName("VertexLightModel");
105 m_d->vertexLightModel->ref();
107 connect(m_d->editwindow_ui.checkBox_verticesUseBaseLightModel,SIGNAL(toggled(bool)),this,SLOT(updateVertexLightModel(bool)));
108
109 // R
110 connect(m_d->editwindow_ui.checkBox_cut_r,SIGNAL(toggled(bool)),this,SLOT(possibleChange_cutAllowedR()));
111 connect(m_d->editwindow_ui.checkBox_cut_r_range_forcesymmetric,SIGNAL(toggled(bool)),this,SLOT(possibleChange_cutAllowedR()));
112 connect(m_d->editwindow_ui.checkBox_cut_r_excludeRange,SIGNAL(toggled(bool)),this,SLOT(possibleChange_cutAllowedR()));
113 connect(m_d->editwindow_ui.doubleSpinBox_cut_r_lower,SIGNAL(valueChanged(double)),this,SLOT(possibleChange_cutAllowedR()));
114 connect(m_d->editwindow_ui.doubleSpinBox_cut_r_upper,SIGNAL(valueChanged(double)),this,SLOT(possibleChange_cutAllowedR()));
115
116 // Y
117 connect(m_d->editwindow_ui.checkBox_cut_y,SIGNAL(toggled(bool)),this,SLOT(possibleChange_cutAllowedY()));
118 connect(m_d->editwindow_ui.checkBox_cut_y_range_forcesymmetric,SIGNAL(toggled(bool)),this,SLOT(possibleChange_cutAllowedY()));
119 connect(m_d->editwindow_ui.checkBox_cut_y_excludeRange,SIGNAL(toggled(bool)),this,SLOT(possibleChange_cutAllowedY()));
120 connect(m_d->editwindow_ui.doubleSpinBox_cut_y_lower,SIGNAL(valueChanged(double)),this,SLOT(possibleChange_cutAllowedY()));
121 connect(m_d->editwindow_ui.doubleSpinBox_cut_y_upper,SIGNAL(valueChanged(double)),this,SLOT(possibleChange_cutAllowedY()));
122 // Z
123 connect(m_d->editwindow_ui.checkBox_cut_z,SIGNAL(toggled(bool)),this,SLOT(possibleChange_cutAllowedZ()));
124 connect(m_d->editwindow_ui.checkBox_cut_z_range_forcesymmetric,SIGNAL(toggled(bool)),this,SLOT(possibleChange_cutAllowedZ()));
125 connect(m_d->editwindow_ui.checkBox_cut_z_excludeRange,SIGNAL(toggled(bool)),this,SLOT(possibleChange_cutAllowedZ()));
126 connect(m_d->editwindow_ui.doubleSpinBox_cut_z_lower,SIGNAL(valueChanged(double)),this,SLOT(possibleChange_cutAllowedZ()));
127 connect(m_d->editwindow_ui.doubleSpinBox_cut_z_upper,SIGNAL(valueChanged(double)),this,SLOT(possibleChange_cutAllowedZ()));
128
129
130
131 connect(this,SIGNAL(clicked()),this,SLOT(showEditMaterialDialog()));
132 connect(m_d->editwindow_ui.pushButton_close,SIGNAL(clicked()),this,SLOT(showEditMaterialDialog()));
133 connect(m_d->matButton,SIGNAL(lastAppliedChanged()),this,SLOT(updateButton()));
134 connect(m_d->matButton,SIGNAL(lastAppliedChanged()),this,SIGNAL(lastAppliedChanged()));
135 setAcceptDrops(true);
136
137 QTimer::singleShot(0, this, SLOT(updateButton()));
138
139}
140
141// QWidget& VertexCollectionSettingsButton::editWindow() {
142// if (!m_d->editwindow)
143// initEditWindow();
144// return *(m_d->editwindow);
145// }
147{
148 delete m_d->editwindow;
149 m_d->vertexDrawStyle->unref();
150 m_d->vertexLightModel->unref();
151 delete m_d;
152}
153
155{
156 if (objectName().isEmpty())
157 setObjectName("VertexCollectionSettingsButton");
158 messageVerbose("setColButtonProperties: color=" + str(m_d->matButton->lastAppliedDiffuseColour()));
159 VP1ColorSelectButton::setColButtonProperties(this,m_d->matButton->lastAppliedDiffuseColour(),m_d->dim);
160}
161
163{
164 if (m_d->dim == dim)
165 return;
166 m_d->dim = dim;
167 updateButton();
168}
169
171{
172 if (!m_d->editwindow)
173 m_d->initEditWindow();
174
175 if (m_d->editwindow->isHidden())
176 m_d->editwindow->show();
177 else
178 m_d->editwindow->hide();
179}
180
182{
183 // std::cout<<"VertexCollectionSettingsButton::setMaterial with mat="<<mat<<std::endl;
184 if (!m_d->matButton) m_d->initEditWindow();
185 m_d->matButton->setMaterial(mat);
186 return true;
187}
188
190{
191 if (!m_d->matButton) m_d->initEditWindow();
192 m_d->matButton->setMaterial(mat);
193}
195{
196 if (!m_d->matButton) m_d->initEditWindow();
197 return m_d->matButton->lastAppliedTransparency();
198}
200{
201 if (!m_d->matButton) m_d->initEditWindow();
202 return m_d->matButton->lastAppliedShininess();
203}
205{
206 if (!m_d->matButton) m_d->initEditWindow();
207 return m_d->matButton->lastAppliedBrightness();
208}
209
210
212{
213 // double val = VP1QtInventorUtils::getValueLineWidthSlider(m_d->editwindow_ui.horizontalSlider_vertexSize);
214 // if (m_d->vertexDrawStyle->lineWidth.getValue()!=val)
215 // m_d->vertexDrawStyle->lineWidth = val;
216}
217
219{
220 if (m_d->vertexLightModel->model.getValue()!=(base?SoLightModel::BASE_COLOR:SoLightModel::PHONG)) {
221 messageVerbose("VertexLightModel changed (base = "+str(base));
222 if (base)
223 m_d->vertexLightModel->model.setValue(SoLightModel::BASE_COLOR);
224 else
225 m_d->vertexLightModel->model.setValue(SoLightModel::PHONG);
226 }
227}
228
229
231{
232 return m_d->vertexDrawStyle;
233}
234
236{
237 return m_d->vertexLightModel;
238}
239
241{
242 return m_d->editwindow_ui.horizontalSlider_vertexSize->value();
243}
244
245//____________________________________________________________________
247{
248 if (event->button() == Qt::LeftButton)
249 m_d->dragStartPosition = event->pos();
250 QPushButton::mousePressEvent(event);
251}
252
253//____________________________________________________________________
255{
256 if (event->source()!=this && event->mimeData()->hasFormat("vp1/material"))
257 event->acceptProposedAction();
258}
259
260//____________________________________________________________________
262{
263 if (!(event->buttons() & Qt::LeftButton))
264 return;
265 if ((event->pos() - m_d->dragStartPosition).manhattanLength()
266 < QApplication::startDragDistance())
267 return;
268
269 QDrag *drag = new QDrag(this);
270 QMimeData *mimeData = new QMimeData;
271
273 // For dragging state onto other material buttons: //
275
276 QByteArray byteArray = saveState();
277
278 // buffer.close();
279 mimeData->setData("vp1/material", byteArray);
280
281 // ////////////////////////////////////////////////////////
282 // // For dragging c++ code for defining this material //
283 // // into e.g. an editor: //
284 // ////////////////////////////////////////////////////////
285 //
286 // QString s = "SoMaterial * mat = new SoMaterial;\n";
287 // QString str_ambient = m_d->toSbColTxt(m_d->lastapplied_ambient);
288 // if (str_ambient!="SbColor(0.2,0.2,0.2)")
289 // s += "mat->ambientColor.setValue("+str_ambient+");\n";
290 // QString str_diffuse = m_d->toSbColTxt(m_d->lastapplied_diffuse);
291 // if (str_diffuse!="SbColor(0.8,0.8,0.8)")
292 // s += "mat->diffuseColor.setValue("+str_diffuse+");\n";
293 // QString str_specular = m_d->toSbColTxt(m_d->lastapplied_specular);
294 // if (str_specular!="SbColor(0,0,0)")
295 // s += "mat->specularColor.setValue("+str_specular+");\n";
296 // QString str_emissive = m_d->toSbColTxt(m_d->lastapplied_emissive);
297 // if (str_emissive!="SbColor(0,0,0)")
298 // s += "mat->emissiveColor.setValue("+str_emissive+");\n";
299 // QString str_shininess = m_d->printFloat(m_d->lastapplied_shininess/100.0);
300 // if (str_shininess!="0.2")
301 // s += "mat->shininess.setValue("+str_shininess+");\n";
302 // QString str_transparency = m_d->printFloat(m_d->lastapplied_transparency/100.0);
303 // if (str_transparency!="0")
304 // s += "mat->transparency.setValue("+str_transparency+");\n";
305 // mimeData->setText(s);
306
307 //Execute drag:
308 drag->setMimeData(mimeData);//drag assumes ownership of mimeData
309 drag->exec(Qt::CopyAction | Qt::MoveAction);
310}
311
312//____________________________________________________________________
314{
315 QByteArray data = event->mimeData()->data("vp1/material");
316 event->acceptProposedAction();
318}
319
320
322 // messageVerbose("getState");
323 // if (m_d->editwindow_ui.checkBox_tracksUseBaseLightModel->isChecked()) messageVerbose("checked!");
324 VP1Serialise serialise(1/*version*/);
325
326 // MATERIAL BUTTON (color,...)
327 serialise.save(m_d->matButton);
328
329 // serialise.disableUnsavedChecks();
330
331 // VERTEX SETTINGS
332 serialise.save(m_d->editwindow_ui.horizontalSlider_vertexSize);
333 serialise.save(m_d->editwindow_ui.checkBox_verticesUseBaseLightModel);
334
335 // R
336 serialise.save(m_d->editwindow_ui.checkBox_cut_r);
337 serialise.save(m_d->editwindow_ui.checkBox_cut_r_range_forcesymmetric);
338 serialise.save(m_d->editwindow_ui.checkBox_cut_r_excludeRange);
339 serialise.save(m_d->editwindow_ui.doubleSpinBox_cut_r_lower);
340 serialise.save(m_d->editwindow_ui.doubleSpinBox_cut_r_upper);
341
342 // Y
343 serialise.save(m_d->editwindow_ui.checkBox_cut_y);
344 serialise.save(m_d->editwindow_ui.checkBox_cut_y_range_forcesymmetric);
345 serialise.save(m_d->editwindow_ui.checkBox_cut_y_excludeRange);
346 serialise.save(m_d->editwindow_ui.doubleSpinBox_cut_y_lower);
347 serialise.save(m_d->editwindow_ui.doubleSpinBox_cut_y_upper);
348 // Z
349 serialise.save(m_d->editwindow_ui.checkBox_cut_z);
350 serialise.save(m_d->editwindow_ui.checkBox_cut_z_range_forcesymmetric);
351 serialise.save(m_d->editwindow_ui.checkBox_cut_z_excludeRange);
352 serialise.save(m_d->editwindow_ui.doubleSpinBox_cut_z_lower);
353 serialise.save(m_d->editwindow_ui.doubleSpinBox_cut_z_upper);
354
355 serialise.widgetHandled(this);
356 serialise.warnUnsaved(this);
357 return serialise.result();
358}
359
361
362 VP1Deserialise state(ba,systemBase());
363 if (state.version()<0||state.version()>1)
364 return;//Ignore silently
365
366 // MATERIAL BUTTON (color,...)
367 state.restore(m_d->matButton);
368
369 // VERTEX SETTINGS
370 state.restore(m_d->editwindow_ui.horizontalSlider_vertexSize);
371 state.restore(m_d->editwindow_ui.checkBox_verticesUseBaseLightModel);
372
373 // R
374 state.restore(m_d->editwindow_ui.checkBox_cut_r);
375 state.restore(m_d->editwindow_ui.checkBox_cut_r_range_forcesymmetric);
376 state.restore(m_d->editwindow_ui.checkBox_cut_r_excludeRange);
377 state.restore(m_d->editwindow_ui.doubleSpinBox_cut_r_lower);
378 state.restore(m_d->editwindow_ui.doubleSpinBox_cut_r_upper);
379
380 // Y
381 state.restore(m_d->editwindow_ui.checkBox_cut_y);
382 state.restore(m_d->editwindow_ui.checkBox_cut_y_range_forcesymmetric);
383 state.restore(m_d->editwindow_ui.checkBox_cut_y_excludeRange);
384 state.restore(m_d->editwindow_ui.doubleSpinBox_cut_y_lower);
385 state.restore(m_d->editwindow_ui.doubleSpinBox_cut_y_upper);
386 // Z
387 state.restore(m_d->editwindow_ui.checkBox_cut_z);
388 state.restore(m_d->editwindow_ui.checkBox_cut_z_range_forcesymmetric);
389 state.restore(m_d->editwindow_ui.checkBox_cut_z_excludeRange);
390 state.restore(m_d->editwindow_ui.doubleSpinBox_cut_z_lower);
391 state.restore(m_d->editwindow_ui.doubleSpinBox_cut_z_upper);
392
393 state.widgetHandled(this);
394 state.warnUnrestored(this);
395
397 updateVertexLightModel(m_d->editwindow_ui.checkBox_verticesUseBaseLightModel);
398 updateButton();
399 //FIXME - anything else need updating?
400}
401
402//____________________________________________________________________
404{
405 if (!m_d->editwindow)
406 m_d->initEditWindow();
407 if (!m_d->editwindow_ui.checkBox_cut_r)
408 return VP1Interval();
409
410 const double minFromInterface=m_d->editwindow_ui.doubleSpinBox_cut_r_lower->value()*1000;
411 const double maxFromInterface=m_d->editwindow_ui.doubleSpinBox_cut_r_upper->value()*1000;
412
413 double min=0.0,max=0.0;
414
415 min = (m_d->editwindow_ui.checkBox_cut_r->isChecked() ? minFromInterface : -std::numeric_limits<double>::infinity());
416 max = (m_d->editwindow_ui.checkBox_cut_r->isChecked() ? maxFromInterface : std::numeric_limits<double>::infinity());
417
418 // FIXME - add symmetry logic
419
420 //message("cutAllowedPt: min,max="+QString::number(min)+","+QString::number(max));
421
422 if (max<min)
423 return VP1Interval();
424
425 return VP1Interval( min, max );//fixme: closed interval??
426}
427
428//____________________________________________________________________
430{
431 if (!m_d->editwindow)
432 m_d->initEditWindow();
433 if (!m_d->editwindow_ui.checkBox_cut_y)
434 return VP1Interval();
435
436 const double minFromInterface = m_d->editwindow_ui.doubleSpinBox_cut_y_lower->value();//*1000;
437 const double maxFromInterface = m_d->editwindow_ui.doubleSpinBox_cut_y_upper->value();//*1000;
438
439 double min=0.0,max=0.0;
440
441 min = (m_d->editwindow_ui.checkBox_cut_y->isChecked() ? minFromInterface : -std::numeric_limits<double>::infinity());
442 max = (m_d->editwindow_ui.checkBox_cut_y->isChecked() ? maxFromInterface : std::numeric_limits<double>::infinity());
443
444 // FIXME - add symmetry logic
445
446 //message("cutAllowedPt: min,max="+QString::number(min)+","+QString::number(max));
447
448 if (max < min)
449 return VP1Interval();
450
451 return VP1Interval( min, max );//fixme: closed interval??
452}
453//____________________________________________________________________
455{
456 if (!m_d->editwindow)
457 m_d->initEditWindow();
458 if (!m_d->editwindow_ui.checkBox_cut_z)
459 return VP1Interval();
460
461 const double minFromInterface=m_d->editwindow_ui.doubleSpinBox_cut_z_lower->value();//*1000;
462 const double maxFromInterface=m_d->editwindow_ui.doubleSpinBox_cut_z_upper->value();//*1000;
463
464 double min=0.0,max=0.0;
465
466 min = (m_d->editwindow_ui.checkBox_cut_z->isChecked() ? minFromInterface : -std::numeric_limits<double>::infinity());
467 max = (m_d->editwindow_ui.checkBox_cut_z->isChecked() ? maxFromInterface : std::numeric_limits<double>::infinity());
468
469 // FIXME - add symmetry logic
470
471 //message("cutAllowedPt: min,max="+QString::number(min)+","+QString::number(max));
472
473 if (max<min)
474 return VP1Interval();
475
476 return VP1Interval( min, max );//fixme: closed interval??
477}
478//____________________________________________________________________
480{
481 messageVerbose("possibleChange_cutAllowedR() ");
482
483 if (m_d->last_cutAllowedR==cutAllowedR()) return;
484 messageVerbose("cutAllowedR() changed");
485 m_d->last_cutAllowedR= cutAllowedR();
486 emit cutAllowedRChanged(m_d->last_cutAllowedR);
487}
488//____________________________________________________________________
490{
491 messageVerbose("possibleChange_cutAllowedY() ");
492
493 if (m_d->last_cutAllowedY == cutAllowedY()) return;
494 messageVerbose("cutAllowedY() changed");
495 m_d->last_cutAllowedY = cutAllowedY();
496 emit cutAllowedYChanged(m_d->last_cutAllowedY);
497}
498//____________________________________________________________________
500{
501 messageVerbose("possibleChange_cutAllowedZ() ");
502
503 if (m_d->last_cutAllowedZ==cutAllowedZ()) return;
504 messageVerbose("cutAllowedZ() changed");
505 m_d->last_cutAllowedZ= cutAllowedZ();
506 emit cutAllowedZChanged(m_d->last_cutAllowedZ);
507}
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
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="")
void cutAllowedZChanged(const VP1Interval &)
void cutAllowedYChanged(const VP1Interval &)
void cutAllowedRChanged(const VP1Interval &)
VertexCollectionSettingsButton(QWidget *parent=0, int dim=25)
QByteArray saveState() const
fill out with the state of the object (used for drag and drop etc)
std::string base
Definition hcg.cxx:81