ATLAS Offline Software
Loading...
Searching...
No Matches
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
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//____________________________________________________________________
28public:
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;
65 m_d->lastEmittedComplexity = 0.5;
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{
92 if (m_d->complexityDisabled)
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;
144 m_d->complexityDisabled = b;
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;
155 m_d->linewidthsDisabled=b;
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;
166 m_d->pointsizesDisabled = b;
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;
177 m_d->baselightingDisabled=b;
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);
188 if (m_d->linewidthsDisabled&&m_d->pointsizesDisabled) {
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;
218 complexityChanged(m_d->lastEmittedComplexity);
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 }
229 if (!m_d->linewidthsDisabled||!m_d->pointsizesDisabled) {
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//____________________________________________________________________
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//____________________________________________________________________
262void 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
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
void setComplexity(const double &)
SoGroup * drawOptionsGroup() const
void setPointSizesDisabled(bool b=true)
void setLineWidths(const double &)
void setPointSizes(const double &)
void complexityChanged(const double &)
VP1DrawOptionsWidget(QWidget *parent=0)
void setLineWidthsDisabled(bool b=true)
void applyState(const QByteArray &)
void setComplexityDisabled(bool b=true)
void setBaseLightingDisabled(bool b=true)
static double getValueLineWidthSlider(const QSlider *)
static void setLimitsLineWidthSlider(QSlider *)
static double getValuePointSizeSlider(const QSlider *)
static void setValuePointSizeSlider(QSlider *, const double &value)
static void setLimitsPointSizeSlider(QSlider *)
static void setValueLineWidthSlider(QSlider *, const double &value)