ATLAS Offline Software
Loading...
Searching...
No Matches
IVP13DStandardChannelWidget.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
6// //
7// Implementation of class IVP13DStandardChannelWidget //
8// //
9// Author: Thomas Kittelmann <Thomas.Kittelmann@cern.ch> //
10// //
11// Initial version: April 2007 //
12// //
14
18#include "VP1Base/VP1Msg.h"
19#include "ui_vp13dstandardchannelsnapshotgroupbox.h"
20
22#include "VP1Base/VP1QtUtils.h"
27
28#include <Inventor/C/errors/debugerror.h>
29#include <Inventor/actions/SoLineHighlightRenderAction.h>
30#include <Inventor/actions/SoBoxHighlightRenderAction.h>
31#include <Inventor/nodes/SoPerspectiveCamera.h>
32#include <Inventor/SoOffscreenRenderer.h>
33
34#include <QSplitter>
35#include <QVBoxLayout>
36#include <QMap>
37#include <QTimer>
38#include <QBuffer>
39#include <QByteArray>
40#include <QDir>
41#include <QFile>
42#include <QFileInfo>
43
44#include <cassert>
45
47public:
50 SoSeparator * root;
53 QMap<IVP13DSystem*,SoSeparator*> system2rootNodes;
54
55 QMap<QCheckBox*,IVP1System*> checkbox2system;
56 QList<IVP1System*> systemsAllowedControllers;
58 QList<QPair<IVP1System*,bool> > system2switchable;
59 QMap<IVP1System*,bool> system2startdisabled;
60 QList<IVP13DSystem*> systemsAllowedCameraList;
61 void updateSystemState(QCheckBox*);
62
63 //Snapshots:
64 Ui::VP13DStandardChannelSnapShotGroupBox uisnapshot;
65
66 void setupSplitter(QWidget * rightwidget);
67
68 void autoSnapshot();
69
70 static const int min3dx = 150;
71 static const int min3dy = 180;
72
73
74 QMap<IVP1System*,QWidget*> sys2tabpage;
76
78
79 // restoreFromState versions
80 void restoreFromState_v7(QDataStream& state);
81
82
83};
84
85//___________________________________________________________________________
87{
88 m_d->viewer->launchStereoEditor();
89}
90
91
92//___________________________________________________________________________
94{
95 m_d->viewer->setAntiAlias(aa);
96 return true;
97}
98
99//___________________________________________________________________________
101{
102 return m_d->viewer->isAntiAlias();
103}
104
105//___________________________________________________________________________
107 const QString & contact_info, bool detectorViewButtons)
109{
110 m_d->detectorViewButtons = detectorViewButtons;
111 m_d->need_initial_viewall=true;
112 m_d->channel=this;
113 m_d->uisnapshot.checkBox_as_shown = 0;//Use this to see if the uisnapshot pointers are initialised/
114
116
117 m_d->root= new SoSeparator;
118 m_d->root->setName("StandardChannelWidgetSceneRoot");
119 m_d->root->ref();
120 m_d->viewer = 0;
121
122 m_d->tabwidget = 0;
123
124 m_d->extradisplaywidget_splitter = 0;
125}
126
127//___________________________________________________________________________
129{
130 m_d->root->unref();
131 delete m_d;
132}
133
134//___________________________________________________________________________
135void IVP13DStandardChannelWidget::addSystem( IVP13DSystem*system, const SystemOptions& options ) {
136
137
138 bool switchable = ! (options & DisallowSwitchable);
139 bool allowController = ! (options & DisallowController);
140 bool allowExtraDisplayWidget = ! (options & DisallowExtraDisplayWidget);
141 bool startDisabled = (options & StartDisabled);
142
143 registerSystem(system);
144 if (!( options & DisallowCameraAccess ))
145 m_d->systemsAllowedCameraList << system;
146
147 SoSeparator * sysroot = system->getSceneGraph();
148 assert(!m_d->system2rootNodes.contains(system));
149 m_d->system2rootNodes.insert(system,sysroot);
150 m_d->root->addChild(sysroot);
151
152 m_d->system2switchable << QPair<IVP1System*,bool>(system,switchable);
153
154 assert(!m_d->system2startdisabled.contains(system));
155 m_d->system2startdisabled.insert(system,startDisabled);
156 assert(m_d->system2startdisabled.contains(system));
157
158 if (allowController) {
159 m_d->systemsAllowedControllers << system;
160 connect(system,SIGNAL(itemFromSystemSelected()),this,SLOT(showControlsForSystem()));
161 }
162
163 if (allowExtraDisplayWidget)
164 m_d->systemsAllowedExtraDisplayWidgets << system;
165}
166
167//___________________________________________________________________________
169
170 //Set up the controller.
171 QWidget * snapshotgroupbox = new QWidget();
172 m_d->uisnapshot.setupUi(snapshotgroupbox);
173
174 VP1ColorSelectButton * colorselectbutton_dummy;
176 m_d->sys2tabpage,m_d->tabwidget,
177 m_d->system2switchable,
178 m_d->checkbox2system,
179 colorselectbutton_dummy,
180 snapshotgroupbox,true ));
181 short x,y;
182 SoOffscreenRenderer::getMaximumResolution().getValue(x,y);
183
184 // now the range is set in the ui file.
185// m_d->uisnapshot.spinBox_width->setRange ( 1, x/4 - 10 );
186// m_d->uisnapshot.spinBox_height->setRange ( 1, y/4 - 10 );
187
188 connect(m_d->uisnapshot.checkBox_as_shown,SIGNAL(toggled(bool)),this,SLOT(updateSnapshotDim()));
189 connect(m_d->uisnapshot.spinBox_width,SIGNAL(valueChanged(int)),this,SLOT(updateSnapshotDim()));
190 connect(m_d->uisnapshot.spinBox_height,SIGNAL(valueChanged(int)),this,SLOT(updateSnapshotDim()));
191 connect(m_d->uisnapshot.radioButton_width,SIGNAL(toggled(bool)),this,SLOT(updateSnapshotDim()));
192 connect(m_d->uisnapshot.radioButton_height,SIGNAL(toggled(bool)),this,SLOT(updateSnapshotDim()));
193
194 connect(m_d->uisnapshot.groupBox_imagePresets,SIGNAL(toggled(bool)),this,SLOT(setImageFromPresets()));
195 connect(m_d->uisnapshot.radioButton_720p,SIGNAL(toggled(bool)),this,SLOT(setImageFromPresets()));
196 connect(m_d->uisnapshot.radioButton_1080p,SIGNAL(toggled(bool)),this,SLOT(setImageFromPresets()));
197 connect(m_d->uisnapshot.radioButton_4K,SIGNAL(toggled(bool)),this,SLOT(setImageFromPresets()));
198 connect(m_d->uisnapshot.radioButton_8K,SIGNAL(toggled(bool)),this,SLOT(setImageFromPresets()));
199
200
201 // m_d->systemsAllowedControllers.clear();
202 m_d->system2switchable.clear();
203
204 QMapIterator<QCheckBox*,IVP1System*> it(m_d->checkbox2system);
205 while (it.hasNext()) {
206 it.next();
207
208 assert(m_d->system2startdisabled.contains(it.value()));
209 if (m_d->system2startdisabled[it.value()]) {
210 it.key()->setChecked(false);
211 m_d->updateSystemState(it.key());
212 }
213
214 connect(it.key(),SIGNAL(toggled(bool)),this,SLOT(toggleSystemActive()));
215
216 }
217
218 QTimer::singleShot(0, this, SLOT(updateSnapshotDim()));
219
220
221 //Setup viewer (with possible splitter for extra widgets):
222 QList<QPair<QString,QWidget*> > sysname2extradisplay;
223 for (IVP13DSystem* sys : m_d->systemsAllowedExtraDisplayWidgets) {
224 QWidget * edwidget = sys->buildExtraDisplayWidget();
225 if (edwidget)
226 sysname2extradisplay << QPair<QString,QWidget*>(sys->name(),edwidget);
227 }
228
229 if (sysname2extradisplay.count()==0) {
230 m_d->viewer = new VP1ExaminerViewer(this,m_d->detectorViewButtons);
231 setMinimumSize(m_d->min3dx,m_d->min3dy);
232 } else if (sysname2extradisplay.count()==1) {
233 m_d->setupSplitter(sysname2extradisplay.front().second);
234 } else if (sysname2extradisplay.count()>1) {
235 VP1TabWidget * tabWidget = new VP1TabWidget();
236 for (int i = 0; i < sysname2extradisplay.count(); ++i) {
237 tabWidget->addTab(sysname2extradisplay.at(i).second,sysname2extradisplay.at(i).first);
238 }
239 tabWidget->setCurrentIndex(0);
240 m_d->setupSplitter(tabWidget);
241 }
242
243 registerRenderArea(m_d->viewer);//remember this...
244
245 m_d->viewer->setSceneGraph(m_d->root);
246 m_d->viewer->setGLRenderAction(new SoLineHighlightRenderAction());
247 //m_d->viewer->setGLRenderAction(new SoBoxHighlightRenderAction());
248
249 // Default Transparency Type
250 // m_d->viewer->setTransparencyType( SoGLRenderAction::DELAYED_BLEND ); // old
251 m_d->viewer->setTransparencyType( SoGLRenderAction::BLEND ); // this looks better for geometry volumes
252
253 //Setup camera info:
254 for (IVP13DSystem*sys : m_d->systemsAllowedCameraList)
255 sys->registerViewer(m_d->viewer);
256
257
258 /* We want to change the default value for the "As shown" option
259 * At the beginning the option was set to True by default, but
260 * the most used setting when creating event displays for ATLAS is
261 * False, because we want to save the full image as a snapshot,
262 * without the frame and buttons from VP1.
263 * So we now set it to False by default.
264 * (We do that with setChecked() in order to not having to change
265 * the whole logics behind.
266 */
267 m_d->uisnapshot.checkBox_as_shown->setChecked(false); // fixme: check if that works, or if it's still TRUE
268
269}
270
271//___________________________________________________________________________
273{
274 QVBoxLayout * vboxLayout = new QVBoxLayout(channel);
275 vboxLayout->setContentsMargins(0, 0, 0, 0);
276 extradisplaywidget_splitter = new QSplitter(channel);
277 extradisplaywidget_splitter->setObjectName("3DchannelSplitter");
278 extradisplaywidget_splitter->setOrientation(Qt::Horizontal);
279 QWidget * widget_viewer = new QWidget(extradisplaywidget_splitter);
280 widget_viewer->setObjectName("widget_viewer");
281 extradisplaywidget_splitter->addWidget(widget_viewer);
282 rightwidget->setParent(extradisplaywidget_splitter);
283 extradisplaywidget_splitter->addWidget(rightwidget);
284 vboxLayout->addWidget(extradisplaywidget_splitter);
285 viewer = new VP1ExaminerViewer(widget_viewer);
286 widget_viewer->setMinimumSize(min3dx,min3dy);
287 connect(extradisplaywidget_splitter,SIGNAL(splitterMoved (int,int)),channel,SLOT(updateSnapshotDim()));
288}
289
290//___________________________________________________________________________
292{
293 VP1Msg::messageVerbose("IVP13DStandardChannelWidget::Imp::autoSnapshot()");
294
295 int runnumber(0);
296 unsigned long long eventnumber(0);
297 channel->getRunEvtNumber(runnumber,eventnumber);
298
299 #if defined BUILDVP1LIGHT
300 QString snapshotDirName = VP1QtUtils::expertSettingValue("general","ExpertSettings/VP1_SCREENSHOTS_DIR");
301 #else
302 QString snapshotDirName = VP1QtUtils::environmentVariableValue("VP1_SCREENSHOTS_DIR");
303 #endif
304
305 QFileInfo snapshotDir(snapshotDirName);
306 if(!snapshotDir.exists()||!snapshotDir.isDir()||!snapshotDir.isReadable()||!snapshotDir.isWritable()) {
307 channel->message("The directory for storing VP1 snapshots "+snapshotDirName+" either does not exist or is not writable");
308 return;
309 }
310
311 QString guess;
312 QString chnlname = channel->name().toLower();
313 chnlname.replace(' ','_');
314 QString base=snapshotDirName+QDir::separator()+"vp1_"+chnlname+"_run"+QString::number(runnumber)+"_evt"+QString::number(eventnumber);
315 guess=base;
316 int i(2);
317 while (QFile::exists(guess+".png")) {
318 guess=base+"_"+QString::number(i++);
319 }
320 guess+=".png";
321
322 QPixmap pm = channel->getSnapshot();
323 if (pm.isNull()) {
324 VP1Msg::messageVerbose("pm==NULL, return...");
325 return;
326 }
327 pm.save(guess);
328}
329
330//___________________________________________________________________________
332{
333 VP1Msg::messageVerbose("IVP13DStandardChannelWidget::lastOfActiveSystemsRefreshed() called.");
334
335 if (m_d->need_initial_viewall) {
336 m_d->viewer->viewAll();
337 m_d->viewer->storeCameraParametersForReset();
338 m_d->need_initial_viewall=false;
339 }
340
341 if(VP1QtUtils::environmentVariableIsSet("VP1_SCREENSHOTS_DIR"))
342 m_d->autoSnapshot();
343
344 if (m_d->viewer->startTourEachEvent())
345 m_d->viewer->startTour();
346
347 // apparently this is the last method called when all systems have been drawn
348 // so we call here the renderPixmap() method is we are in "batch-mode"
349
350
351
352}
353
354//___________________________________________________________________________
358
359//___________________________________________________________________________
361{
362 IVP13DSystem * sys3d = static_cast<IVP13DSystem*>(sys);
363 if (sys3d)
364 sys3d->deselectAll();
365}
366
367//___________________________________________________________________________
369{
370 QCheckBox * cb = static_cast<QCheckBox*>(sender()); assert(cb);
371 m_d->updateSystemState(cb);
372}
373
374
375//___________________________________________________________________________
377{
378
379 assert(checkbox2system.contains(cb));
380 IVP13DSystem*sys = static_cast<IVP13DSystem*>(checkbox2system.value(cb)); assert(sys);
381
382 assert(system2rootNodes.contains(sys));
383 SoSeparator * sysroot = system2rootNodes.value(sys);
384 int ichild = root->findChild(sysroot);
385 if (cb->isChecked()) {
386 channel->turnOn(sys);
387 if (ichild==-1)
388 root->addChild(sysroot);
389 sysroot->unref();
390 if (tabwidget&&sys2tabpage.contains(sys)) {
391 int sysindex = systemsAllowedControllers.indexOf(sys);
392 if (sysindex>=0) {
393 IVP1System*nextsystem(0);
394 for (int i=sysindex+1;i<systemsAllowedControllers.count();++i) {
395 //Loop through latter systems with controllers in order and
396 //find the first of those which currently has an active
397 //controller:
398 IVP1System* testsys = systemsAllowedControllers.at(i);
399 if (sys2tabpage.contains(testsys)&&tabwidget->indexOf(sys2tabpage[testsys])>-1) {
400 nextsystem=testsys;
401 break;
402 }
403 }
404 //put before tab of "nextsystem" (or at the end if no nextsystem):
405 int index = (nextsystem?tabwidget->indexOf(sys2tabpage[nextsystem]):99999);
406 tabwidget->insertTab(index,sys2tabpage[sys],sys->name());
407 int index2 = tabwidget->indexOf(sys2tabpage[sys]);
408 if (index2!=-1) {
409 tabwidget->setTabEnabled(index2,true);
410 }
411 }
412 }
413 } else {
414 //Fixme: if system being turned off has selections, we should deselect!!
415 channel->turnOff(sys,false);
416 assert(ichild!=-1);
417 sysroot->ref();
418 root->removeChild(ichild);
419 if (tabwidget&&sys2tabpage.contains(sys)) {
420 int index = tabwidget->indexOf(sys2tabpage[sys]);
421 if (index!=-1) {
422 tabwidget->setTabEnabled(index,false);
423 tabwidget->removeTab(index);
424 }
425 }
426 }
427}
428
429//___________________________________________________________________________
430void IVP13DStandardChannelWidget::addSystem(IVP13DSystemSimple* sys, const SystemOptions& options )
431{
432 addSystem((IVP13DSystem*)sys,options);
433}
434
435//___________________________________________________________________________
437{
438 if (m_d->viewer->isAnimating())
439 m_d->viewer->stopAnimating();
440}
441
442//___________________________________________________________________________
443QPixmap IVP13DStandardChannelWidget::getSnapshot(bool transp, int width, bool batch)
444{
445 VP1Msg::messageDebug("IVP13DStandardChannelWidget::getSnapshot() - transparent bkg: "+QString::number(transp)+" , width: "+QString::number(width)+" , batch: "+QString::number(batch));
446 // SoToVRML2Action tovrml2;
447 // tovrml2.apply(m_d->selection);
448 // SoVRMLGroup *newroot = tovrml2.getVRML2SceneGraph();
449 // newroot->ref();
450 // SoOutput out;
451 // out.openFile("out.wrl");
452 // out.setHeaderString("#VRML V2.0 utf8");
453 // SoWriteAction wra(&out);
454 // wra.apply(newroot);
455 // out.closeFile();
456
457
458 VP1Msg::messageVerbose("checkBox_as_shown: " + QString::number(m_d->uisnapshot.checkBox_as_shown->isChecked()) );
459 VP1Msg::messageVerbose("spinBox_width: " + QString::number(m_d->uisnapshot.spinBox_width->value()) );
460 VP1Msg::messageVerbose("spinBox_height: " + QString::number(m_d->uisnapshot.spinBox_height->value()) );
461 VP1Msg::messageVerbose("checkBox_transp: " + QString::number(m_d->uisnapshot.checkBox_transp->isChecked()) );
462
463 if (m_d->uisnapshot.checkBox_as_shown->isChecked()) {
464 VP1Msg::messageVerbose("'As shown' option checked - using IVP13DChannelWidget::getSnapshot()");
466 }
467 VP1Msg::messageVerbose("'As shown' option NOT checked");
468
469 // if width is set programmatically, we set the new value in the GUI field
470 int original_width = 0;
471 if (width) {
472 VP1Msg::messageVerbose("'width' passed at function call. Setting the value of the GUI field to: " + QString::number(width));
473 original_width = m_d->uisnapshot.spinBox_width->value();
474 m_d->uisnapshot.spinBox_width->setValue( width );
475 }
476
477
478 // if transparent bkg is requested programmatically, we force it
479 if (transp) {
480 VP1Msg::messageVerbose("'transp' option set - using VP1QtInventorUtils::renderToPixmap() with transp set to 'true'");
482 m_d->uisnapshot.spinBox_width->value(),
483 m_d->uisnapshot.spinBox_height->value(),
484 true);
485 }
486
487 // if changed programatically, set the width back to the original value set by the user
488 if (width) m_d->uisnapshot.spinBox_width->setValue( original_width );
489
490 // default, with user's preferences from the GUI
491 VP1Msg::messageVerbose("save the screenshot with the default tool (with settings from GUI) - using VP1QtInventorUtils::renderToPixmap()");
493 m_d->uisnapshot.spinBox_width->value(),
494 m_d->uisnapshot.spinBox_height->value(),
495 m_d->uisnapshot.checkBox_transp->isChecked());
496
497 //return QPixmap(); // for DEBUG
498
499}
500
501//___________________________________________________________________________
503{
504 VP1Msg::messageDebug("IVP13DStandardChannelWidget::setImageFromPresets()");
505
506 disconnect(m_d->uisnapshot.spinBox_width,SIGNAL(valueChanged(int)),this,SLOT(updateSnapshotDim()));
507 disconnect(m_d->uisnapshot.spinBox_height,SIGNAL(valueChanged(int)),this,SLOT(updateSnapshotDim()));
508
509 if (m_d->uisnapshot.radioButton_720p->isChecked()) {
510 m_d->uisnapshot.spinBox_width->setValue(1280);
511 m_d->uisnapshot.spinBox_height->setValue(720);
512 }
513 else if (m_d->uisnapshot.radioButton_1080p->isChecked()) {
514 m_d->uisnapshot.spinBox_width->setValue(1920);
515 m_d->uisnapshot.spinBox_height->setValue(1080);
516 }
517 else if (m_d->uisnapshot.radioButton_4K->isChecked()) {
518 m_d->uisnapshot.spinBox_width->setValue(4096);
519 m_d->uisnapshot.spinBox_height->setValue(2160);
520 }
521 else if (m_d->uisnapshot.radioButton_8K->isChecked()) {
522 m_d->uisnapshot.spinBox_width->setValue(8192);
523 m_d->uisnapshot.spinBox_height->setValue(4320);
524 }
525 else {
526 VP1Msg::messageDebug("ERROR! Sender unknown!!");
527 }
528
529 connect(m_d->uisnapshot.spinBox_width,SIGNAL(valueChanged(int)),this,SLOT(updateSnapshotDim()));
530 connect(m_d->uisnapshot.spinBox_height,SIGNAL(valueChanged(int)),this,SLOT(updateSnapshotDim()));
531
532 // update
534}
535
536
537//___________________________________________________________________________
539{
540 VP1Msg::messageDebug("IVP13DStandardChannelWidget::updateSnapshotDim()");
541
542 // if (!m_d->uisnapshot.checkBox_as_shown)
543// return;
544// if (sender()==m_d->uisnapshot.spinBox_width)
545// m_d->uisnapshot.radioButton_width->setChecked(true);
546// else if (sender()==m_d->uisnapshot.spinBox_height)
547// m_d->uisnapshot.radioButton_height->setChecked(true);
548
549 if (!m_d->uisnapshot.checkBox_as_shown)
550 return;
551
552 if (sender()==m_d->uisnapshot.spinBox_width)
553 m_d->uisnapshot.radioButton_width->setChecked(true);
554 else if (sender()==m_d->uisnapshot.spinBox_height)
555 m_d->uisnapshot.radioButton_height->setChecked(true);
556
557 /*
558 * Get widget width and height
559 * Note: the method "getNormalWidget" is from the "SoQtGLWidget" class
560 * and it returns a QWidget object
561 */
562 int onscreen_width = m_d->viewer->getNormalWidget()->geometry().width();
563 int onscreen_height = m_d->viewer->getNormalWidget()->geometry().height();
564
565 if ( m_d->uisnapshot.checkBox_as_shown->isChecked() ) {
566 disconnect(m_d->uisnapshot.spinBox_width,SIGNAL(valueChanged(int)),this,SLOT(updateSnapshotDim()));
567 disconnect(m_d->uisnapshot.spinBox_height,SIGNAL(valueChanged(int)),this,SLOT(updateSnapshotDim()));
568 m_d->uisnapshot.spinBox_width->setValue(onscreen_width);
569 m_d->uisnapshot.spinBox_height->setValue(onscreen_height);
570 connect(m_d->uisnapshot.spinBox_width,SIGNAL(valueChanged(int)),this,SLOT(updateSnapshotDim()));
571 connect(m_d->uisnapshot.spinBox_height,SIGNAL(valueChanged(int)),this,SLOT(updateSnapshotDim()));
572 } else {
573 if (m_d->uisnapshot.checkBox_lockRatio->isChecked()) {
574 VP1Msg::messageDebug("checkBox_lockRatio is checked - updating only rendering size");
575 if (m_d->uisnapshot.radioButton_width->isChecked()) {
576 disconnect(m_d->uisnapshot.spinBox_height,SIGNAL(valueChanged(int)),this,SLOT(updateSnapshotDim()));
577 m_d->uisnapshot.spinBox_height->setValue(static_cast<int>(m_d->uisnapshot.spinBox_width->value()*static_cast<double>(onscreen_height)/onscreen_width+0.5));
578 connect(m_d->uisnapshot.spinBox_height,SIGNAL(valueChanged(int)),this,SLOT(updateSnapshotDim()));
579 } else {
580 disconnect(m_d->uisnapshot.spinBox_width,SIGNAL(valueChanged(int)),this,SLOT(updateSnapshotDim()));
581 m_d->uisnapshot.spinBox_width->setValue(static_cast<int>(m_d->uisnapshot.spinBox_height->value()*static_cast<double>(onscreen_width)/onscreen_height+0.5));
582 connect(m_d->uisnapshot.spinBox_width,SIGNAL(valueChanged(int)),this,SLOT(updateSnapshotDim()));
583 }
584 }
585 else {
586 VP1Msg::messageDebug("checkBox_lockRatio is NOT checked - Updating the widget size as well");
587
588// if (m_d->uisnapshot.radioButton_width->isChecked() ) {
589// int newWidth = static_cast<int>(m_d->uisnapshot.spinBox_width->value() * static_cast<double>(onscreen_height) / m_d->uisnapshot.spinBox_height->value() + 0.5);
590// m_d->viewer->getNormalWidget()->resize(newWidth, onscreen_height);
591// } else if (m_d->uisnapshot.radioButton_height->isChecked()) {
592// int newHeight = static_cast<int>( onscreen_width * static_cast<double>(m_d->uisnapshot.spinBox_height->value()) / m_d->uisnapshot.spinBox_width->value() + 0.5);
593// m_d->viewer->resize(onscreen_width, newHeight);
594// }
595
596 }
597 }
598
599 //Finally, ensure that we are within the ranges:
600 if (m_d->uisnapshot.spinBox_width->value()>=m_d->uisnapshot.spinBox_width->maximum()) {
601 disconnect(m_d->uisnapshot.spinBox_width,SIGNAL(valueChanged(int)),this,SLOT(updateSnapshotDim()));
602 disconnect(m_d->uisnapshot.spinBox_height,SIGNAL(valueChanged(int)),this,SLOT(updateSnapshotDim()));
603 m_d->uisnapshot.spinBox_width->setValue(m_d->uisnapshot.spinBox_width->maximum());
604 m_d->uisnapshot.spinBox_height->setValue(static_cast<int>(m_d->uisnapshot.spinBox_width->value()*static_cast<double>(onscreen_height)/onscreen_width+0.5));
605 connect(m_d->uisnapshot.spinBox_width,SIGNAL(valueChanged(int)),this,SLOT(updateSnapshotDim()));
606 connect(m_d->uisnapshot.spinBox_height,SIGNAL(valueChanged(int)),this,SLOT(updateSnapshotDim()));
607 }
608 if (m_d->uisnapshot.spinBox_height->value()>=m_d->uisnapshot.spinBox_height->maximum()) {
609 disconnect(m_d->uisnapshot.spinBox_width,SIGNAL(valueChanged(int)),this,SLOT(updateSnapshotDim()));
610 disconnect(m_d->uisnapshot.spinBox_height,SIGNAL(valueChanged(int)),this,SLOT(updateSnapshotDim()));
611 m_d->uisnapshot.spinBox_height->setValue(m_d->uisnapshot.spinBox_height->maximum());
612 m_d->uisnapshot.spinBox_width->setValue(static_cast<int>(m_d->uisnapshot.spinBox_height->value()*static_cast<double>(onscreen_width)/onscreen_width+0.5));
613 connect(m_d->uisnapshot.spinBox_width,SIGNAL(valueChanged(int)),this,SLOT(updateSnapshotDim()));
614 connect(m_d->uisnapshot.spinBox_height,SIGNAL(valueChanged(int)),this,SLOT(updateSnapshotDim()));
615 }
616
617}
618
619//___________________________________________________________________________
621{
622 VP1Msg::messageVerbose("IVP13DStandardChannelWidget::dockResized()");
623 QTimer::singleShot(0, this, SLOT(updateSnapshotDim()));
625}
626
627//___________________________________________________________________________
629{
630 VP1Msg::messageVerbose("IVP13DStandardChannelWidget::saveState");
631
632
633 // NEW VERSION
634
635//
636// // ===> Setup stream writing to a byteArray:
637// QByteArray byteArray;
638// QBuffer buffer(&byteArray);
639// buffer.open(QIODevice::WriteOnly);
640// QDataStream out(&buffer);
641//
642// /*
643// * --- GET DATA TO BE SAVED ---
644// */
645//
646// //Systems turned on/off:
647// //Fixme: Make sure that if you have two copies of the same system,
648// //that the text in the checkbox gets appended some stuff like [1],
649// //[2], etc., so that the strings used here will be unique.
650// QMap<QString, bool> sysname2turnedon;
651// QMap<QCheckBox*,IVP1System*>::const_iterator it = m_d->checkbox2system.constBegin();
652// while (it != m_d->checkbox2system.constEnd()) {
653// sysname2turnedon.insert(it.key()->text(),it.key()->isChecked());
654// ++it;
655// }
656//
657//
658// // snapshot settings
659// bool transp_checked = m_d->uisnapshot.checkBox_transp->isChecked();
660// bool widthfixed = m_d->uisnapshot.radioButton_width->isChecked();
661// bool as_shown = m_d->uisnapshot.checkBox_as_shown->isChecked();
662//
663// bool locked_ratio = m_d->uisnapshot.checkBox_lockRatio->isChecked();
664//
665// qint32 width = (qint32)(m_d->uisnapshot.spinBox_width->value());
666// qint32 height = (qint32)(m_d->uisnapshot.spinBox_height->value());
667//
668// // image presets
669// bool isUsingPreset = m_d->uisnapshot.groupBox_imagePresets->isChecked();
670// bool is720p = m_d->uisnapshot.radioButton_720p->isChecked();
671// bool is1080p = m_d->uisnapshot.radioButton_1080p->isChecked();
672// bool is4K = m_d->uisnapshot.radioButton_4K->isChecked();
673// bool is8K = m_d->uisnapshot.radioButton_8K->isChecked();
674//
675// // active tab
676// QString tab_index = (m_d->tabwidget ? m_d->tabwidget->tabText(m_d->tabwidget->currentIndex()) : QString("") );
677//
678//
679// /*
680// * --- WRITE DATA ---
681// */
682//
683// // ------- SAVE -------
684// out << (qint32)7; //version
685// out << IVP13DChannelWidget::saveState();//Always include state info from the base class.
686// out << sysname2turnedon;
687// out << ( m_d->extradisplaywidget_splitter ? m_d->extradisplaywidget_splitter->saveState() : QByteArray() );
688// out << m_d->viewer->saveState();
689// out << transp_checked;
690// out << widthfixed;
691// out << as_shown;
692// out << locked_ratio; // new in v. 7
693// out << width; // new in v. 7
694// out << height; // new in v. 7
695// out << isUsingPreset; // new in v. 7
696// out << is720p; // new in v. 7
697// out << is1080p; // new in v. 7
698// out << is4K; // new in v. 7
699// out << is8K; // new in v. 7
700// out << tab_index;
701// // --------------------
702//
703// // ===> Finish up:
704// buffer.close();
705// return byteArray;
706//
707//
708
709
710
711 // OLD VERSION
712
713 // ===> Setup stream writing to a byteArray:
714 QByteArray byteArray;
715 QBuffer buffer(&byteArray);
716 buffer.open(QIODevice::WriteOnly);
717 QDataStream out(&buffer);
718
719 // ===> Write Data:
720
721 //Version & base state:
722 out << (qint32)6; //version
723 out << IVP13DChannelWidget::saveState();//Always include state info from the base class.
724
725 //version 3 had bgd color output here;
726
727 //Systems turned on/off:
728 //Fixme: Make sure that if you have two copies of the same system,
729 //that the text in the checkbox gets appended some stuff like [1],
730 //[2], etc., so that the strings used here will be unique.
731 QMap<QString, bool> sysname2turnedon;
732 QMap<QCheckBox*,IVP1System*>::const_iterator it = m_d->checkbox2system.constBegin();
733 while (it != m_d->checkbox2system.constEnd()) {
734 sysname2turnedon.insert(it.key()->text(),it.key()->isChecked());
735 ++it;
736 }
737
738 //Versions 3+ follow here.
739
740 out << sysname2turnedon;
741
742 out << ( m_d->extradisplaywidget_splitter ? m_d->extradisplaywidget_splitter->saveState() : QByteArray() );
743
744 out << m_d->viewer->saveState();
745
746 //version <=3 had bool here.
747
748 out << m_d->uisnapshot.checkBox_transp->isChecked();
749 bool widthfixed = m_d->uisnapshot.radioButton_width->isChecked();
750 bool as_shown = m_d->uisnapshot.checkBox_as_shown->isChecked();
751 out << widthfixed;
752 out << as_shown;
753 if (!as_shown)
754 out << (qint32)(widthfixed ? m_d->uisnapshot.spinBox_width->value() : m_d->uisnapshot.spinBox_height->value());
755
756 if (m_d->tabwidget)
757 out << m_d->tabwidget->tabText(m_d->tabwidget->currentIndex());
758 else
759 out << QString("");
760
761 //In version 5 we output a bool here.
762
763 // ===> Finish up:
764 buffer.close();
765 return byteArray;
766
767
768}
769
770//___________________________________________________________________________
772{
773 VP1Msg::messageVerbose("IVP13DStandardChannelWidget::restoreFromState");
774
775 // ===> Setup stream for getting the contents of the byteArray:
776 QBuffer buffer(&ba);
777 buffer.open(QIODevice::ReadOnly);
778 QDataStream state(&buffer);
779 // ===> Check version and pass on state info to base class:
780 qint32 version;
781 state >> version;
782
783 message("Configuration file version: " + QString::number(version) );
784
785 if (version<0||version>7) {
786 message("Warning: State data in .vp1 file is in wrong format - ignoring!");
787 return;
788 }
789
790 QByteArray basestate;
791 state >> basestate;
793
794
795 // ===> Decode the state info:
796
797 if (version == 7)
798 m_d->restoreFromState_v7(state);
799
800 if (version<=3) {
801 QColor bgdcol_dummy;
802 state >> bgdcol_dummy;
803 }
804
805 //Switch systems on/off:
806 QMap<QString, bool> sysname2turnedon;
807 state >> sysname2turnedon;
808 QMap<QCheckBox*,IVP1System*>::const_iterator it = m_d->checkbox2system.constBegin();
809 while (it != m_d->checkbox2system.constEnd()) {
810 if (sysname2turnedon.contains(it.key()->text())) {
811 if (sysname2turnedon[it.key()->text()]!=it.key()->isChecked())
812 it.key()->setChecked(sysname2turnedon[it.key()->text()]);
813 } else {
814 message("Warning: Config data does not contain information about switched state of subsystem '"+it.key()->text()+"'");
815 }
816 ++it;
817 }
818
819 if (version<=2) {
820 // We stop here to avoid too messy code.
821 buffer.close();
822 return;
823 }
824
825 //Splitter:
826 QByteArray splitstate;
827 state >> splitstate;
828 if (m_d->extradisplaywidget_splitter)
829 m_d->extradisplaywidget_splitter->restoreState(splitstate);
830
831 //Viewer settings:
832 QByteArray ba_viewer;
833 state >> ba_viewer;
834 m_d->viewer->restoreFromState(ba_viewer);//Fixme: reset camera???
835 m_d->need_initial_viewall = false;
836
837 //Snapshot parameters:
838 bool aa_dummy, transp, widthfixed, as_shown;
839 if (version<=3)
840 state >> aa_dummy;
841 state >> transp; state >> widthfixed; state >> as_shown;
842 m_d->uisnapshot.checkBox_transp->setChecked(transp);
843 m_d->uisnapshot.checkBox_as_shown->setChecked(as_shown);
844 if (widthfixed) {
845 m_d->uisnapshot.radioButton_width->setChecked(true);
846 m_d->uisnapshot.radioButton_height->setChecked(false);
847 } else {
848 m_d->uisnapshot.radioButton_width->setChecked(false);
849 m_d->uisnapshot.radioButton_height->setChecked(true);
850 }
851 if (!as_shown) {
852 qint32 fixval;
853 state >> fixval;
854 if (widthfixed)
855 m_d->uisnapshot.spinBox_width->setValue(fixval);
856 else
857 m_d->uisnapshot.spinBox_height->setValue(fixval);
858 }
859
860 QString tabname;
861 state >> tabname;
862 if (m_d->tabwidget) {
863 for (int i = 0; i < m_d->tabwidget->count(); ++i) {
864 if (m_d->tabwidget->tabText(i) == tabname) {
865 m_d->tabwidget->setCurrentIndex(i);
866 break;
867 }
868 }
869 }
870
871 if (version==5) {
872 bool b;
873 state >> b;
874 }
875
876
877 // ===> Finish up:
878 buffer.close();
879}
880
881//___________________________________________________________________________
883{
884 if (!m_d->tabwidget)
885 return;
886 IVP1System * sys = static_cast<IVP1System*>(sender());
887 if (!sys) {
888 message("showControlsForSystem Error: Unable to determine system identity.");
889 return;
890 }
891 if (!m_d->sys2tabpage.contains(sys)) {
892 //Dont send warning here. The system in question might simply not have a controller!
893 return;
894 }
895
896 int index = m_d->tabwidget->indexOf(m_d->sys2tabpage[sys]);
897 if (index<0||!m_d->tabwidget->isTabEnabled(index)) {
898 message("Warning: Asked to show controller for a disabled system. Surely you jest?");
899 return;
900 }
901 m_d->tabwidget->setCurrentIndex(index);
902}
903
904
905//___________________________________________________________________________
907
908 VP1Msg::messageVerbose("IVP13DStandardChannelWidget::Imp::restoreFromState_v7");
909
910 /*
911 * --- VARIABLES TO BE RESTORED ---
912 */
913 //Switch systems on/off:
914 QMap<QString, bool> sysname2turnedon;
915 //Splitter:
916 QByteArray splitstate;
917 //Viewer settings:
918 QByteArray ba_viewer;
919 // Snapshot parameters:
920 bool transp, widthfixed, as_shown;
921 bool locked_ratio;
922 qint32 width, height;
923 // image format presets
924 bool isUsingPresets;
925 bool is720p;
926 bool is1080p;
927 bool is4K;
928 bool is8K;
929 // Active tab
930 QString tabname;
931
932
933 /*
934 * ------- GET STATE -------
935 */
936 // 'version' restored already
937 // 'basestate' restored already
938 state >> sysname2turnedon;
939 state >> splitstate;
940 state >> ba_viewer;
941 state >> transp;
942 state >> widthfixed;
943 state >> as_shown;
944 state >> locked_ratio;
945 state >> width;
946 state >> height;
947 state >> isUsingPresets;
948 state >> is720p;
949 state >> is1080p;
950 state >> is4K;
951 state >> is8K;
952 state >> tabname;
953 // -------------------------
954
955
956
957
958 /*
959 * --- RESTORE VARIABLES ---
960 */
961
962 //Switch systems on/off:
963 QMap<QCheckBox*,IVP1System*>::const_iterator it = checkbox2system.constBegin();
964 while (it != checkbox2system.constEnd()) {
965 if (sysname2turnedon.contains(it.key()->text())) {
966 if (sysname2turnedon[it.key()->text()]!=it.key()->isChecked())
967 it.key()->setChecked(sysname2turnedon[it.key()->text()]);
968 } else {
969 channel->message("Warning: Config data does not contain information about switched state of subsystem '"+it.key()->text()+"'");
970 }
971 ++it;
972 }
973
974
975 //Splitter:
977 extradisplaywidget_splitter->restoreState(splitstate);
978
979 //Viewer settings:
980 viewer->restoreFromState(ba_viewer);//Fixme: reset camera???
981 need_initial_viewall = false;
982
983
984 // Snapshot parameters - Set Width and Height
985 uisnapshot.checkBox_transp->setChecked(transp);
986 uisnapshot.checkBox_as_shown->setChecked(as_shown);
987 if (widthfixed) {
988 uisnapshot.radioButton_width->setChecked(true);
989 uisnapshot.radioButton_height->setChecked(false);
990 } else {
991 uisnapshot.radioButton_width->setChecked(false);
992 uisnapshot.radioButton_height->setChecked(true);
993 }
994 if (!as_shown) {
995 uisnapshot.spinBox_width->setValue(width);
996 uisnapshot.spinBox_height->setValue(height);
997 }
998
999 // image format presets
1000 if (isUsingPresets)
1001 uisnapshot.groupBox_imagePresets->setChecked(true);
1002 if (is720p)
1003 uisnapshot.radioButton_720p->setChecked(true);
1004 else if (is1080p)
1005 uisnapshot.radioButton_1080p->setChecked(true);
1006 else if (is4K)
1007 uisnapshot.radioButton_4K->setChecked(true);
1008 else if (is8K)
1009 uisnapshot.radioButton_8K->setChecked(true);
1010
1011
1012 // Set active tab
1013 if (tabwidget) {
1014 for (int i = 0; i < tabwidget->count(); ++i) {
1015 if (tabwidget->tabText(i) == tabname) {
1016 tabwidget->setCurrentIndex(i);
1017 break;
1018 }
1019 }
1020 }
1021}
1022
1023
const double width
#define y
#define x
virtual QByteArray saveState()
void registerRenderArea(VP1ExaminerViewer *)
virtual QPixmap getSnapshot(bool transp=false, int width=0, bool batch=false)
IVP13DChannelWidget(const QString &name, const QString &information, const QString &contact_info)
virtual void restoreFromState(QByteArray)
QMap< IVP1System *, QWidget * > sys2tabpage
Ui::VP13DStandardChannelSnapShotGroupBox uisnapshot
QList< IVP13DSystem * > systemsAllowedExtraDisplayWidgets
QMap< QCheckBox *, IVP1System * > checkbox2system
QMap< IVP13DSystem *, SoSeparator * > system2rootNodes
QList< QPair< IVP1System *, bool > > system2switchable
IVP13DStandardChannelWidget(const QString &name, const QString &information, const QString &contact_info, bool detectorViewButtons=true)
virtual QPixmap getSnapshot(bool transp=false, int width=0, bool batch=false)
void addSystem(IVP13DSystem *, const SystemOptions &options=AllowAll)
virtual void systemRefreshed(IVP1System *)
virtual SoSeparator * getSceneGraph() const =0
virtual void deselectAll(SoCooperativeSelection *exception_sel=0)
void registerSystem(IVP1System *)
virtual void dockResized()
void registerController(QWidget *)
void message(QString)
const QString & information() const
const QString & name() const
const QString & contact_info() const
static QWidget * compositionController(const QList< IVP1System * > &systemsWithControllersAllowed, QMap< IVP1System *, QWidget * > &sys2tabpage, VP1TabWidget *&tabwidget, const QList< QPair< IVP1System *, bool > > &system2switchable, QMap< QCheckBox *, IVP1System * > &checkbox2system, VP1ColorSelectButton *&colorselectbutton, QWidget *extrawidget=0, bool nobgdcolorsel=false)
static void messageVerbose(const QString &)
Definition VP1Msg.cxx:84
static void messageDebug(const QString &)
Definition VP1Msg.cxx:39
static QPixmap renderToPixmap(VP1ExaminerViewer *ra, int pixels_x, int pixels_y, bool transparent_background=false, double actualRenderedSizeFact=1.0)
static QString expertSettingValue(const QString &type, const QString &name)
static bool environmentVariableIsSet(const QString &name)
static QString environmentVariableValue(const QString &name)
std::string base
Definition hcg.cxx:81
static std::vector< uint32_t > runnumber
Definition iLumiCalc.h:37
Definition index.py:1