ATLAS Offline Software
VP1DrawOptionsWidget.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 // //
8 // Implementation of class VP1DrawOptionsWidget //
9 // //
10 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11 // Initial version: August 2008 //
12 // //
14 
17 #include "VP1Base/VP1Serialise.h"
18 #include "VP1Base/VP1Deserialise.h"
19 #include "ui_vp1drawoptionsform.h"
20 #include <Inventor/nodes/SoGroup.h>
21 #include <Inventor/nodes/SoComplexity.h>
22 #include <Inventor/nodes/SoLightModel.h>
23 #include <Inventor/nodes/SoDrawStyle.h>
24 
25 
26 //____________________________________________________________________
28 public:
29  Ui::DrawOptionsForm ui;
30  SoGroup * group;
31  SoComplexity * complexity;
32  SoLightModel * baseLightModel;
33  SoDrawStyle * drawStyle;
39 };
40 
41 
42 //____________________________________________________________________
44  : QWidget(parent), m_d(new Imp)
45 {
46  m_d->ui.setupUi(this);
47  VP1QtInventorUtils::setLimitsLineWidthSlider(m_d->ui.horizontalSlider_linewidths);
48  VP1QtInventorUtils::setValueLineWidthSlider(m_d->ui.horizontalSlider_linewidths,1.2);
49  VP1QtInventorUtils::setLimitsPointSizeSlider(m_d->ui.horizontalSlider_pointsizes);
50  VP1QtInventorUtils::setValuePointSizeSlider(m_d->ui.horizontalSlider_pointsizes,1.2);
51  m_d->linewidthsDisabled = false;
52  m_d->pointsizesDisabled = false;
53  m_d->complexityDisabled = false;
54  m_d->baselightingDisabled = false;
55  m_d->group = new SoGroup;
56  m_d->group->setName("DrawOptionsGroup");
57  m_d->group->ref();
58  m_d->complexity = new SoComplexity;
59  m_d->complexity->ref();
60  m_d->drawStyle = new SoDrawStyle;
61  m_d->drawStyle->ref();
62  m_d->baseLightModel = new SoLightModel;
63  m_d->baseLightModel->ref();
64  m_d->baseLightModel->model = SoLightModel::BASE_COLOR;
66  updateNodes();
67  connect(m_d->ui.horizontalSlider_linewidths,SIGNAL(valueChanged(int)),this,SLOT(updateNodes()));
68  connect(m_d->ui.horizontalSlider_pointsizes,SIGNAL(valueChanged(int)),this,SLOT(updateNodes()));
69  connect(m_d->ui.horizontalSlider_complexity,SIGNAL(valueChanged(int)),this,SLOT(updateNodes()));
70  connect(m_d->ui.checkBox_useBaseLightModel,SIGNAL(toggled(bool)),this,SLOT(updateNodes()));
71 }
72 
73 //____________________________________________________________________
75 {
76  m_d->group->unref();
77  m_d->complexity->unref();
78  m_d->drawStyle->unref();
79  m_d->baseLightModel->unref();
80  delete m_d;
81 }
82 
83 //____________________________________________________________________
85 {
86  return m_d->group;
87 }
88 
89 //____________________________________________________________________
91 {
93  return 0.5;
94  const int val = m_d->ui.horizontalSlider_complexity->value();
95  const int min = m_d->ui.horizontalSlider_complexity->minimum();
96  const int max = m_d->ui.horizontalSlider_complexity->maximum();
97  if(val==min)
98  return 0.0;
99  if(val==max)
100  return 1.0;
101  return std::min<double>(1.0,std::max<double>(0.0,(val-min)/(max*1.0)));
102 }
103 
104 //____________________________________________________________________
106 {
107  int min = m_d->ui.horizontalSlider_complexity->minimum();
108  int max = m_d->ui.horizontalSlider_complexity->maximum();
109  int newval = std::min(max,std::max(min,(min+static_cast<int>((max-min)*c+0.5))));
110  if (m_d->ui.horizontalSlider_complexity->value()!=newval) {
111  m_d->ui.horizontalSlider_complexity->setValue(newval);
112  updateNodes();
113  }
114 }
115 
116 //____________________________________________________________________
118 {
119  VP1QtInventorUtils::setValueLineWidthSlider(m_d->ui.horizontalSlider_linewidths,lw);
120  updateNodes();
121 }
122 
123 //____________________________________________________________________
125 {
126  VP1QtInventorUtils::setValuePointSizeSlider(m_d->ui.horizontalSlider_pointsizes,ps);
127  updateNodes();
128 }
129 
130 //____________________________________________________________________
132 {
133  if (m_d->ui.checkBox_useBaseLightModel->isChecked()==b)
134  return;
135  m_d->ui.checkBox_useBaseLightModel->setChecked(b);
136  updateNodes();
137 }
138 
139 //____________________________________________________________________
141 {
142  if (m_d->complexityDisabled==b)
143  return;
145  m_d->ui.label_curve_realism->setVisible(!b);
146  m_d->ui.horizontalSlider_complexity->setVisible(!b);
147  updateNodes();
148 }
149 
150 //____________________________________________________________________
152 {
153  if (m_d->linewidthsDisabled==b)
154  return;
156  m_d->ui.label_linewidths->setVisible(!b);
157  m_d->ui.horizontalSlider_linewidths->setVisible(!b);
158  updateNodes();
159 }
160 
161 //____________________________________________________________________
163 {
164  if (m_d->pointsizesDisabled==b)
165  return;
167  m_d->ui.label_pointsizes->setVisible(!b);
168  m_d->ui.horizontalSlider_pointsizes->setVisible(!b);
169  updateNodes();
170 }
171 
172 //____________________________________________________________________
174 {
175  if (m_d->baselightingDisabled==b)
176  return;
178  m_d->ui.checkBox_useBaseLightModel->setVisible(!b);
179  updateNodes();
180 }
181 
182 //____________________________________________________________________
184 {
185  // 1) Update attachments
186 
187  bool drawStyleAttached(m_d->group->findChild(m_d->drawStyle)>=0);
189  if (drawStyleAttached)
190  m_d->group->removeChild(m_d->drawStyle);
191  } else {
192  if (!drawStyleAttached)
193  m_d->group->addChild(m_d->drawStyle);
194  }
195 
196  bool complexityAttached(m_d->group->findChild(m_d->complexity)>=0);
197  if (m_d->complexityDisabled) {
198  if (complexityAttached)
199  m_d->group->removeChild(m_d->complexity);
200  } else {
201  if (!complexityAttached)
202  m_d->group->addChild(m_d->complexity);
203  }
204 
205  bool lightModelAttached(m_d->group->findChild(m_d->baseLightModel)>=0);
206  bool lightModelAttachedGoal = !m_d->baselightingDisabled && m_d->ui.checkBox_useBaseLightModel->isChecked();
207  if (lightModelAttachedGoal!=lightModelAttached) {
208  if (lightModelAttached)
209  m_d->group->removeChild(m_d->baseLightModel);
210  else
211  m_d->group->addChild(m_d->baseLightModel);
212  }
213 
214  // 2) Emit complexityChanged?
215  double complexityval = complexity();
216  if (m_d->lastEmittedComplexity!=complexityval) {
217  m_d->lastEmittedComplexity=complexityval;
219  }
220 
221  // 3) Update fields
222  if (!m_d->complexityDisabled){
223  //We avoid setting the complexity value exactly to 0:
224  complexityval = std::min<double>(1.0,std::max<double>(0.0,0.01+0.991*complexityval));
225  }
226  if (m_d->complexity->value.getValue()!=complexityval){
227  m_d->complexity->value.setValue(complexityval);
228  }
230  double val_lw = m_d->linewidthsDisabled ? 0 : VP1QtInventorUtils::getValueLineWidthSlider(m_d->ui.horizontalSlider_linewidths);
231  double val_ps = m_d->pointsizesDisabled ? 0 : VP1QtInventorUtils::getValuePointSizeSlider(m_d->ui.horizontalSlider_pointsizes);
232  if (m_d->drawStyle->lineWidth.getValue()!=val_lw)
233  m_d->drawStyle->lineWidth = val_lw;
234  if (m_d->drawStyle->pointSize.getValue()!=val_ps)
235  m_d->drawStyle->pointSize = val_ps;
236  }
237 
238 
239 }
240 
241 //____________________________________________________________________
242 QByteArray VP1DrawOptionsWidget::state() const
243 {
244  VP1Serialise s(0/*version*/);
245 
246  //Line width/point size:
247  s.save(VP1QtInventorUtils::getValueLineWidthSlider(m_d->ui.horizontalSlider_linewidths));
248  s.save(VP1QtInventorUtils::getValuePointSizeSlider(m_d->ui.horizontalSlider_pointsizes));
249  s.widgetHandled(m_d->ui.horizontalSlider_linewidths);
250  s.widgetHandled(m_d->ui.horizontalSlider_pointsizes);
251 
252  s.save(m_d->ui.horizontalSlider_complexity);
253  s.save(m_d->ui.checkBox_useBaseLightModel);
254 
255  s.widgetHandled(this);
256  s.warnUnsaved(this);
257 
258  return s.result();
259 }
260 
261 //____________________________________________________________________
262 void VP1DrawOptionsWidget::applyState(const QByteArray& ba)
263 {
264  VP1Deserialise s(ba);
265 
266  if (s.version()!=0)
267  return;//ignore silently
268 
269  VP1QtInventorUtils::setValueLineWidthSlider(m_d->ui.horizontalSlider_linewidths,s.restoreDouble());
270  VP1QtInventorUtils::setValuePointSizeSlider(m_d->ui.horizontalSlider_pointsizes,s.restoreDouble());
271  s.widgetHandled(m_d->ui.horizontalSlider_linewidths);
272  s.widgetHandled(m_d->ui.horizontalSlider_pointsizes);
273 
274  s.restore(m_d->ui.horizontalSlider_complexity);
275  s.restore(m_d->ui.checkBox_useBaseLightModel);
276 
277  s.widgetHandled(this);
278  s.warnUnrestored(this);
279 
280  updateNodes();
281 
282 }
283 
VP1Serialise.h
VP1DrawOptionsWidget::Imp::ui
Ui::DrawOptionsForm ui
Definition: VP1DrawOptionsWidget.cxx:29
VP1QtInventorUtils::getValueLineWidthSlider
static double getValueLineWidthSlider(const QSlider *)
Definition: VP1QtInventorUtils.cxx:1619
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
VP1Deserialise.h
VP1Serialise
Definition: VP1Serialise.h:45
VP1DrawOptionsWidget::setPointSizes
void setPointSizes(const double &)
Definition: VP1DrawOptionsWidget.cxx:124
VP1DrawOptionsWidget::Imp::linewidthsDisabled
bool linewidthsDisabled
Definition: VP1DrawOptionsWidget.cxx:34
VP1DrawOptionsWidget::setUseBaseLighting
void setUseBaseLighting(bool)
Definition: VP1DrawOptionsWidget.cxx:131
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
python.LumiCalcWorking.lw
lw
Definition: LumiCalcWorking.py:112
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
VP1DrawOptionsWidget.h
VP1DrawOptionsWidget::setLineWidths
void setLineWidths(const double &)
Definition: VP1DrawOptionsWidget.cxx:117
VP1DrawOptionsWidget::state
QByteArray state() const
Definition: VP1DrawOptionsWidget.cxx:242
VP1DrawOptionsWidget::setLineWidthsDisabled
void setLineWidthsDisabled(bool b=true)
Definition: VP1DrawOptionsWidget.cxx:151
VP1DrawOptionsWidget::drawOptionsGroup
SoGroup * drawOptionsGroup() const
Definition: VP1DrawOptionsWidget.cxx:84
VP1DrawOptionsWidget::Imp::pointsizesDisabled
bool pointsizesDisabled
Definition: VP1DrawOptionsWidget.cxx:35
VP1DrawOptionsWidget::complexityChanged
void complexityChanged(const double &)
VP1DrawOptionsWidget::~VP1DrawOptionsWidget
virtual ~VP1DrawOptionsWidget()
Definition: VP1DrawOptionsWidget.cxx:74
VP1QtInventorUtils.h
VP1QtInventorUtils::setLimitsPointSizeSlider
static void setLimitsPointSizeSlider(QSlider *)
Definition: VP1QtInventorUtils.cxx:1577
VP1DrawOptionsWidget::VP1DrawOptionsWidget
VP1DrawOptionsWidget(QWidget *parent=0)
Definition: VP1DrawOptionsWidget.cxx:43
VP1DrawOptionsWidget::setComplexity
void setComplexity(const double &)
Definition: VP1DrawOptionsWidget.cxx:105
VP1QtInventorUtils::getValuePointSizeSlider
static double getValuePointSizeSlider(const QSlider *)
Definition: VP1QtInventorUtils.cxx:1630
VP1DrawOptionsWidget::applyState
void applyState(const QByteArray &)
Definition: VP1DrawOptionsWidget.cxx:262
VP1DrawOptionsWidget::Imp::baselightingDisabled
bool baselightingDisabled
Definition: VP1DrawOptionsWidget.cxx:37
VP1DrawOptionsWidget::Imp::lastEmittedComplexity
double lastEmittedComplexity
Definition: VP1DrawOptionsWidget.cxx:38
test_pyathena.parent
parent
Definition: test_pyathena.py:15
VP1DrawOptionsWidget::Imp::complexityDisabled
bool complexityDisabled
Definition: VP1DrawOptionsWidget.cxx:36
VP1Deserialise
Definition: VP1Deserialise.h:44
VP1QtInventorUtils::setValueLineWidthSlider
static void setValueLineWidthSlider(QSlider *, const double &value)
Definition: VP1QtInventorUtils.cxx:1593
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
VP1DrawOptionsWidget::Imp
Definition: VP1DrawOptionsWidget.cxx:27
VP1DrawOptionsWidget::updateNodes
void updateNodes()
Definition: VP1DrawOptionsWidget.cxx:183
VP1QtInventorUtils::setValuePointSizeSlider
static void setValuePointSizeSlider(QSlider *, const double &value)
Definition: VP1QtInventorUtils.cxx:1606
VP1QtInventorUtils::setLimitsLineWidthSlider
static void setLimitsLineWidthSlider(QSlider *)
Definition: VP1QtInventorUtils.cxx:1563
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
VP1DrawOptionsWidget::setPointSizesDisabled
void setPointSizesDisabled(bool b=true)
Definition: VP1DrawOptionsWidget.cxx:162
VP1DrawOptionsWidget::Imp::group
SoGroup * group
Definition: VP1DrawOptionsWidget.cxx:30
VP1DrawOptionsWidget::Imp::drawStyle
SoDrawStyle * drawStyle
Definition: VP1DrawOptionsWidget.cxx:33
VP1DrawOptionsWidget::m_d
Imp * m_d
Definition: VP1DrawOptionsWidget.h:59
python.compressB64.c
def c
Definition: compressB64.py:93
VP1DrawOptionsWidget::Imp::baseLightModel
SoLightModel * baseLightModel
Definition: VP1DrawOptionsWidget.cxx:32
VP1DrawOptionsWidget::complexity
double complexity() const
Definition: VP1DrawOptionsWidget.cxx:90
VP1DrawOptionsWidget::setBaseLightingDisabled
void setBaseLightingDisabled(bool b=true)
Definition: VP1DrawOptionsWidget.cxx:173
VP1DrawOptionsWidget::Imp::complexity
SoComplexity * complexity
Definition: VP1DrawOptionsWidget.cxx:31
VP1DrawOptionsWidget::setComplexityDisabled
void setComplexityDisabled(bool b=true)
Definition: VP1DrawOptionsWidget.cxx:140