viewerControl.cc 26.7 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
*                                                                            *
*                              OpenFlipper                                   *
*      Copyright (C) 2001-2010 by Computer Graphics Group, RWTH Aachen       *
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper is distributed in the hope that it will be useful,            *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*  GNU Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
33
34
35
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
36
37
38
39
40
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
41
\*===========================================================================*/
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57



//=============================================================================
//
//  CLASS CoreWidget - IMPLEMENTATION
//
//=============================================================================


//== INCLUDES =================================================================

#include "CoreWidget.hh"

#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/common/GlobalOptions.hh>
58
#include <OpenFlipper/widgets/snapshotDialog/SnapshotDialog.hh>
59
60
61
62
63
64
65
66
67
68
69


//== IMPLEMENTATION ==========================================================

//=============================================================================

void CoreWidget::slotToggleStereoMode()
{
  stereoActive_ = !stereoActive_;

  if ( stereoActive_ ) {
70
    statusBar_->showMessage(tr("Stereo enabled"));
Dirk Wilden's avatar
Dirk Wilden committed
71
    stereoButton_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"stereo.png") );
72
  } else {
73
    statusBar_->showMessage(tr("Stereo disabled"));
Dirk Wilden's avatar
Dirk Wilden committed
74
    stereoButton_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"mono.png") );
75
76
  }

77
  cursorPainter_->setEnabled (stereoActive_);
78

79
80
81
82
  for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
    examiner_widgets_[i]->setStereoMode(stereoActive_);
}

Jan Möbius's avatar
Jan Möbius committed
83
84
85
86
87
88
89
void CoreWidget::slotSetGlobalBackgroundColor() {
  ACG::Vec4f bc = PluginFunctions::viewerProperties().backgroundColor() * 255.0;

  QColor backCol((int)bc[0], (int)bc[1], (int)bc[2], (int)bc[3]);
  QColor c = QColorDialog::getColor(backCol,this);

  if (c != backCol && c.isValid())
90
    for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i )
Jan Möbius's avatar
Jan Möbius committed
91
92
93
94
95
      PluginFunctions::viewerProperties(i).backgroundColor(ACG::Vec4f(((double) c.redF())   ,
                                                                      ((double) c.greenF()) ,
                                                                      ((double) c.blueF())  ,
                                                                        1.0));

96
  OpenFlipperSettings().setValue("Core/Gui/glViewer/defaultBackgroundColor",c);
Jan Möbius's avatar
Jan Möbius committed
97
98
99

}

100
void CoreWidget::slotSetContextBackgroundColor() {
Jan Möbius's avatar
Jan Möbius committed
101
102
103
104
105
106
107
108
109
110
111
112
113
  ACG::Vec4f bc = PluginFunctions::viewerProperties().backgroundColor() * 255.0;

  QColor backCol((int)bc[0], (int)bc[1], (int)bc[2], (int)bc[3]);
  QColor c = QColorDialog::getColor(backCol,this);

  if (c != backCol && c.isValid())
    PluginFunctions::viewerProperties().backgroundColor(ACG::Vec4f(((double) c.redF())   ,
                                                                    ((double) c.greenF()) ,
                                                                    ((double) c.blueF())  ,
                                                                     1.0));
}


114
115
116
117
118
/// Set the viewer to home position
void CoreWidget::slotContextHomeView() {
  examiner_widgets_[PluginFunctions::activeExaminer()]->home();
}

119
120
/// Show / hide wheels in examiner windows
void CoreWidget::slotSwitchWheels(bool _state) {
121
  std::vector< glViewer* >::iterator it = examiner_widgets_.begin();
122

123
  for(; it != examiner_widgets_.end(); it++)
124
    _state ? (*it)->slotShowWheels() : (*it)->slotHideWheels();
125
}
126

127
128
129
130
131
/// Switch navigation mode
void CoreWidget::slotSwitchNavigation(bool _egomode) {
  std::vector< glViewer* >::iterator it = examiner_widgets_.begin();

  for(; it != examiner_widgets_.end(); it++) {
Mike Kremer's avatar
Mike Kremer committed
132
    _egomode ? (*it)->navigationMode(glViewer::FIRSTPERSON_NAVIGATION) :
133
134
135
136
    	(*it)->navigationMode(glViewer::NORMAL_NAVIGATION);
  }
}

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/// Set the viewer to home position
void CoreWidget::slotGlobalHomeView() {
  for ( int i = 0 ; i < PluginFunctions::viewers() ; ++i )
    examiner_widgets_[i]->home();
}

/// Set the viewers home position
void CoreWidget::slotContextSetHomeView() {
  examiner_widgets_[PluginFunctions::activeExaminer()]->setHome();
}


/// Set the home position for all viewers
void CoreWidget::slotGlobalSetHomeView() {
  for ( int i = 0 ; i < PluginFunctions::viewers() ; ++i )
    examiner_widgets_[i]->setHome();
}

/// Change view on active viewer to view complete scene
void CoreWidget::slotContextViewAll() {
  examiner_widgets_[PluginFunctions::activeExaminer()]->viewAll();
}


/// Change view on all viewers to view complete scene
void CoreWidget::slotGlobalViewAll() {
  for ( int i = 0 ; i < PluginFunctions::viewers() ; ++i )
    examiner_widgets_[i]->viewAll();
}

167
/// Toggle projection mode of the active viewer
168
169
170
171
void CoreWidget::slotContextSwitchProjection() {
  examiner_widgets_[PluginFunctions::activeExaminer()]->toggleProjectionMode();
}

172
/// Toggle projection mode of all viewers to perspective projection
173
174
175
176
177
void CoreWidget::slotGlobalPerspectiveProjection() {
  for ( int i = 0 ; i < PluginFunctions::viewers() ; ++i )
    examiner_widgets_[i]->perspectiveProjection();
}

178
/// Toggle projection mode of all viewers to orthogonal projection
179
180
181
182
183
void CoreWidget::slotGlobalOrthographicProjection() {
  for ( int i = 0 ; i < PluginFunctions::viewers() ; ++i )
    examiner_widgets_[i]->orthographicProjection();
}

184
185
186
187
188
189
190
191
192
193
194
195
196
197

/// If animation is disabled in all viewers, enable it in all viewers. Otherwise disable it.
void CoreWidget::slotGlobalToggleAnimation() {
  int enabledCount  = 0;

  for ( int i = 0 ; i< PluginFunctions::viewers(); ++i ) {
    if ( PluginFunctions::viewerProperties(i).animation() )
      enabledCount++;
  }
  
  slotGlobalChangeAnimation (enabledCount == 0);
}

/// Set the animation mode for all viewers
198
199
200
201
202
void CoreWidget::slotGlobalChangeAnimation(bool _animation){
  for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
    PluginFunctions::viewerProperties(i).animation(_animation);
}

203
/// Set the animation mode for active viewer
204
205
206
207
void CoreWidget::slotLocalChangeAnimation(bool _animation){
  PluginFunctions::viewerProperties().animation(_animation);
}

208
209
210
211
212
213
214
215
216
217
218
219
220
221

/// If backface culling is disabled in all viewers, enable it in all viewers. Otherwise disable it.
void CoreWidget::slotGlobalToggleBackFaceCulling() {
  int enabledCount  = 0;

  for ( int i = 0 ; i< PluginFunctions::viewers(); ++i ) {
    if ( PluginFunctions::viewerProperties(i).backFaceCulling() )
      enabledCount++;
  }
  
  slotGlobalChangeBackFaceCulling (enabledCount == 0);
}

/// Set backface culling for all viewers
222
223
224
void CoreWidget::slotGlobalChangeBackFaceCulling(bool _backFaceCulling){
  for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
    PluginFunctions::viewerProperties(i).backFaceCulling(_backFaceCulling);
225

226
227
}

228
/// Set backface culling for active viewer
229
230
231
232
233
void CoreWidget::slotLocalChangeBackFaceCulling(bool _backFaceCulling){
  PluginFunctions::viewerProperties().backFaceCulling(_backFaceCulling);
}


234
235
236
237
238
239
240
241
242
243
244
245
246
/// If two-sided lighting is disabled in all viewers, enable it in all viewers. Otherwise disable it.
void CoreWidget::slotGlobalToggleTwoSidedLighting() {
  int enabledCount  = 0;

  for ( int i = 0 ; i< PluginFunctions::viewers(); ++i ) {
    if ( PluginFunctions::viewerProperties(i).twoSidedLighting() )
      enabledCount++;
  }
  
  slotGlobalChangeTwoSidedLighting (enabledCount == 0);
}

/// Set two-sided lighting for all viewers
247
248
249
250
251
void CoreWidget::slotGlobalChangeTwoSidedLighting(bool _lighting) {
  for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
    PluginFunctions::viewerProperties(i).twoSidedLighting(_lighting);
}

252
/// Set two-sided lighting for active viewer
253
254
255
256
void CoreWidget::slotLocalChangeTwoSidedLighting(bool _lighting) {
  PluginFunctions::viewerProperties().twoSidedLighting(_lighting);
}

257
258
259
260
261
262
263
264
265
266
267
268
269
270

/// If multisampling is disabled in all viewers, enable it in all viewers. Otherwise disable it.
void CoreWidget::slotGlobalToggleMultisampling() {
  int enabledCount  = 0;

  for ( int i = 0 ; i< PluginFunctions::viewers(); ++i ) {
    if ( PluginFunctions::viewerProperties(i).multisampling() )
      enabledCount++;
  }
  
  slotGlobalChangeMultisampling (enabledCount == 0);
}

/// Set multisampling for all viewers
271
272
273
274
275
void CoreWidget::slotGlobalChangeMultisampling(bool _multisampling) {
  for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
    PluginFunctions::viewerProperties(i).multisampling( _multisampling );
}

276
/// Set multisampling for active viewer
277
278
279
280
void CoreWidget::slotLocalChangeMultisampling(bool _multisampling) {
  PluginFunctions::viewerProperties().multisampling( _multisampling );
}

281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300

/// If mipmapping is disabled in all viewers, enable it in all viewers. Otherwise disable it.
void CoreWidget::slotGlobalToggleMipmapping() {
  int enabledCount  = 0;

  for ( int i = 0 ; i< PluginFunctions::viewers(); ++i ) {
    if ( PluginFunctions::viewerProperties(i).mipmapping() )
      enabledCount++;
  }
  
  slotGlobalChangeMipmapping (enabledCount == 0);
}

/// Set mipmapping for all viewers
void CoreWidget::slotGlobalChangeMipmapping(bool _mipmapping) {
  for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
    PluginFunctions::viewerProperties(i).mipmapping( _mipmapping );
}

/// Set mipmapping for active viewer
Mike Kremer's avatar
Mike Kremer committed
301
302
303
304
void CoreWidget::slotLocalChangeMipmapping(bool _mipmapping) {
  PluginFunctions::viewerProperties().mipmapping( _mipmapping );
}

Dirk Wilden's avatar
Dirk Wilden committed
305
/// Take a snapshot of the current Viewer
306
void CoreWidget::slotExaminerSnapshot() {
Dirk Wilden's avatar
Dirk Wilden committed
307
308
309
310

  QFileInfo fi(PluginFunctions::viewerProperties().snapshotName());
  int counter = PluginFunctions::viewerProperties().snapshotCounter();

Jan Möbius's avatar
Jan Möbius committed
311
312
313
314
315
316
    // Add leading zeros
  QString number = QString::number(counter);
  while ( number.size() < 7 )
    number = "0" + number;

  QString suggest = fi.baseName() + "." + number + ".";
Dirk Wilden's avatar
Dirk Wilden committed
317
318
319
320
321
322

  QString format="png";

  if (fi.completeSuffix() == "ppm")
    format="ppmraw";

Jan Möbius's avatar
Jan Möbius committed
323
324
325
  if (fi.completeSuffix() == "jpg")
    format="jpg";

Dirk Wilden's avatar
Dirk Wilden committed
326
327
  suggest += format;

Dirk Wilden's avatar
Dirk Wilden committed
328
329
330
  QFileDialog dialog(this);
  dialog.setFileMode(QFileDialog::AnyFile);
  dialog.setDefaultSuffix("png");
331
  dialog.setNameFilter(tr("Images (*.png *.ppm *.jpg)"));
Dirk Wilden's avatar
Dirk Wilden committed
332
333
334
335
336
  dialog.setFileMode(QFileDialog::AnyFile);
  dialog.setConfirmOverwrite(true);
  dialog.setDirectory( fi.path() );
  dialog.selectFile( suggest );
  dialog.setAcceptMode(QFileDialog::AcceptSave);
337
  dialog.setWindowTitle(tr("Save Snapshot"));
Dirk Wilden's avatar
Dirk Wilden committed
338

Dirk Wilden's avatar
Dirk Wilden committed
339
340
341
342
343
 if (dialog.exec()){
     QString newName = dialog.selectedFiles()[0];

      if (newName != fi.path() + OpenFlipper::Options::dirSeparator() + suggest)
        PluginFunctions::viewerProperties().snapshotBaseFileName(newName);
Dirk Wilden's avatar
Dirk Wilden committed
344

Dirk Wilden's avatar
Dirk Wilden committed
345
346
      QImage image;
      examiner_widgets_[PluginFunctions::activeExaminer()]->snapshot(image);
Dirk Wilden's avatar
Dirk Wilden committed
347

Dirk Wilden's avatar
Dirk Wilden committed
348
      image.save(newName);
Dirk Wilden's avatar
Dirk Wilden committed
349
350
351
352
353
354
355
  }
}

///Take a snapshot of the whole application
void CoreWidget::applicationSnapshotDialog() {

  QFileInfo fi(snapshotName_);
356
357
358
  
  if (snapshotName_ == "")
    fi.setFile( OpenFlipperSettings().value("Core/CurrentDir").toString() + QDir::separator() + "snap.png" );
Dirk Wilden's avatar
Dirk Wilden committed
359

Jan Möbius's avatar
Jan Möbius committed
360
361
362
363
364
  // Add leading zeros
  QString number = QString::number(snapshotCounter_);
  while ( number.size() < 7 )
    number = "0" + number;

365
  QString suggest = fi.path() + QDir::separator() + fi.baseName() + "." + number + ".";
Dirk Wilden's avatar
Dirk Wilden committed
366
367
368
369
370
371

  QString format="png";

  if (fi.completeSuffix() == "ppm")
    format="ppmraw";

Jan Möbius's avatar
Jan Möbius committed
372
373
374
  if (fi.completeSuffix() == "jpg")
    format="jpg";

Dirk Wilden's avatar
Dirk Wilden committed
375
376
  suggest += format;

377
378
379
  int w = width();
  int h = height();

380
381
  SnapshotDialog dialog(suggest, false, w, h, 0);
  
382
383
384
  connect(&dialog, SIGNAL(resizeApplication(int,int)), this, SIGNAL(resizeApplication(int,int)) );

  bool ok = dialog.exec();
385
386

  if ( ok ){
387
    QString newName = dialog.filename->text();
Dirk Wilden's avatar
Dirk Wilden committed
388

389
390
391
392
    if (newName != suggest){
      
      OpenFlipperSettings().setValue("Core/CurrentDir", QFileInfo(newName).absolutePath() );
      
Dirk Wilden's avatar
Dirk Wilden committed
393
      snapshotName_ = newName;
394
      snapshotCounter_ = 1;
Dirk Wilden's avatar
Dirk Wilden committed
395
396
397
398
399
400
401
402
403
    }else
      snapshotCounter_++;

    QApplication::processEvents();

    QPixmap pic = QPixmap::grabWindow( winId() );

    pic.save(newName);
  }
404
405

  emit resizeApplication(w,h);
Dirk Wilden's avatar
Dirk Wilden committed
406
407
408
409
410
411
412
}

///Take a snapshot of the whole application
void CoreWidget::applicationSnapshot() {

  QFileInfo fi(snapshotName_);

Jan Möbius's avatar
Jan Möbius committed
413
414
415
416
417
418
  // Add leading zeros
  QString number = QString::number(snapshotCounter_++);
  while ( number.size() < 7 )
    number = "0" + number;

  QString suggest = fi.path() + QDir::separator() +fi.baseName() + "." + number + ".";
Dirk Wilden's avatar
Dirk Wilden committed
419
420
421
422
423
424

  QString format="png";

  if (fi.completeSuffix() == "ppm")
    format="ppmraw";

425
426
427
  if (fi.completeSuffix() == "jpg")
    format="jpg";

Dirk Wilden's avatar
Dirk Wilden committed
428
429
430
431
432
433
434
  suggest += format;

  QApplication::processEvents();

  QPixmap pic = QPixmap::grabWindow( winId() );

  pic.save(suggest);
435
436
}

Dirk Wilden's avatar
Dirk Wilden committed
437
438
439
440
441

///Take a snapshot of all viewers
void CoreWidget::viewerSnapshotDialog() {

  QFileInfo fi(snapshotName_);
442
443
444
  
  if (snapshotName_ == "")
    fi.setFile( OpenFlipperSettings().value("Core/CurrentDir").toString() + QDir::separator() + "snap.png" );
Dirk Wilden's avatar
Dirk Wilden committed
445

Jan Möbius's avatar
Jan Möbius committed
446
447
448
449
450
  // Add leading zeros
  QString number = QString::number(snapshotCounter_);
  while ( number.size() < 7 )
    number = "0" + number;

451
  QString suggest = fi.path() + QDir::separator() + fi.baseName() + "." + number + ".";
Dirk Wilden's avatar
Dirk Wilden committed
452
453
454
455
456
457

  QString format="png";

  if (fi.completeSuffix() == "ppm")
    format="ppmraw";

Jan Möbius's avatar
Jan Möbius committed
458
459
460
  if (fi.completeSuffix() == "jpg")
    format="jpg";

Dirk Wilden's avatar
Dirk Wilden committed
461
462
  suggest += format;

463
464
  int w = glView_->width();
  int h = glView_->height();
465
  
466
467
  SnapshotDialog dialog(suggest, true, w, h, 0);
  
468
469
470
471
  bool ok = dialog.exec();

  if (ok){
    QString newName = dialog.filename->text();
Dirk Wilden's avatar
Dirk Wilden committed
472

473
474
475
476
    if (newName != suggest){
      
      OpenFlipperSettings().setValue("Core/CurrentDir", QFileInfo(newName).absolutePath() );
      
Dirk Wilden's avatar
Dirk Wilden committed
477
      snapshotName_ = newName;
478
479
      snapshotCounter_ = 1;
      
Dirk Wilden's avatar
Dirk Wilden committed
480
481
    }else
      snapshotCounter_++;
482
    
Dirk Wilden's avatar
Dirk Wilden committed
483
484
485
486
487
488
489
    //now take the snapshot
    switch ( baseLayout_->mode() ){

      case QtMultiViewLayout::SingleView:
      {
        QImage finalImage;

490
        examiner_widgets_[PluginFunctions::activeExaminer()]->snapshot(finalImage,
491
                dialog.snapWidth->value(), dialog.snapHeight->value(),
492
493
                dialog.transparent->isChecked(), dialog.hideCoordsys->isChecked(),
		dialog.multisampling->isChecked() ? dialog.num_samples->value() : 1);
Dirk Wilden's avatar
Dirk Wilden committed
494
495
496
497
498
499
500

        finalImage.save(newName);

        break;
      }
      case QtMultiViewLayout::Grid:
      {
501
502
503
504
505
506
507
508
        // Compute size of each viewer
        int w = dialog.snapWidth->value();
        int h = dialog.snapHeight->value();
        
        // Relative size of first viewer (in relation to the other viewers
        double relSizeW = (double)examiner_widgets_[0]->glWidth() / (double)glScene_->width();
        double relSizeH = (double)examiner_widgets_[0]->glHeight() / (double)glScene_->height();
          
Dirk Wilden's avatar
Dirk Wilden committed
509
510
        QImage img0,img1,img2,img3;

511
512
513
514
515
516
517
518
        examiner_widgets_[0]->snapshot(img0, (int)((double)w * relSizeW),           (int)((double)h * relSizeH),
                                       dialog.transparent->isChecked(), dialog.hideCoordsys->isChecked());
        examiner_widgets_[1]->snapshot(img1, (int)((double)w * (1.0 - relSizeW)),   (int)((double)h * relSizeH),
                                       dialog.transparent->isChecked(), dialog.hideCoordsys->isChecked());
        examiner_widgets_[2]->snapshot(img2, (int)((double)w * relSizeW),           (int)((double)h * (1.0 - relSizeH)),
                                       dialog.transparent->isChecked(), dialog.hideCoordsys->isChecked());
        examiner_widgets_[3]->snapshot(img3, (int)((double)w * (1.0 - relSizeW)),   (int)((double)h * (1.0 - relSizeH)),
                                       dialog.transparent->isChecked(), dialog.hideCoordsys->isChecked());
519
520
521
522
523
        
        img0.save("/home/kremer/multsnap0.png");
        img1.save("/home/kremer/multsnap1.png");
        img2.save("/home/kremer/multsnap2.png");
        img3.save("/home/kremer/multsnap3.png");
Dirk Wilden's avatar
Dirk Wilden committed
524

525
        QImage finalImage(img0.width() + img1.width()+2, img0.height() + img2.height()+2, QImage::Format_ARGB32_Premultiplied);
Dirk Wilden's avatar
Dirk Wilden committed
526
527

        QPainter painter(&finalImage);
528
529
530

        painter.fillRect(0,0,finalImage.width(), finalImage.height(), QBrush(Qt::gray));

Dirk Wilden's avatar
Dirk Wilden committed
531
532
        painter.drawImage(QRectF(           0,             0, img0.width(), img0.height()),img0,
                          QRectF(           0,             0, img0.width(), img0.height()) );
533
        painter.drawImage(QRectF(img0.width()+2,           0, img1.width(), img1.height()),img1,
Dirk Wilden's avatar
Dirk Wilden committed
534
                          QRectF(           0,             0, img1.width(), img1.height()) );
535
        painter.drawImage(QRectF(          0,img0.height()+2, img2.width(), img2.height()),img2,
Dirk Wilden's avatar
Dirk Wilden committed
536
                          QRectF(           0,             0, img2.width(), img2.height()) );
537
        painter.drawImage(QRectF(img0.width()+2, img0.height()+2, img3.width(), img3.height()),img3,
Dirk Wilden's avatar
Dirk Wilden committed
538
539
540
541
542
543
544
545
                          QRectF(           0,             0, img3.width(), img3.height()) );

        finalImage.save(newName);

        break;
      }
      case QtMultiViewLayout::HSplit:
      {
546
547
548
549
550
551
552
553
554
555
        // Compute size of each viewer
        int w = dialog.snapWidth->value();
        int h = dialog.snapHeight->value();
        
        // Relative size of first viewer (in relation to the other viewers
        double relSizeW = (double)examiner_widgets_[0]->glWidth() / (double)glScene_->width();
        double relSizeH1 = (double)examiner_widgets_[1]->glHeight() / (double)glScene_->height();
        double relSizeH2 = (double)examiner_widgets_[2]->glHeight() / (double)glScene_->height();
        double relSizeH3 = (double)examiner_widgets_[3]->glHeight() / (double)glScene_->height();
          
Dirk Wilden's avatar
Dirk Wilden committed
556
557
        QImage img0,img1,img2,img3;

558
559
560
561
562
563
564
565
        examiner_widgets_[0]->snapshot(img0, (int)((double)w * relSizeW), h,
                                       dialog.transparent->isChecked(), dialog.hideCoordsys->isChecked());
        examiner_widgets_[1]->snapshot(img1, (int)((double)w * (1.0 - relSizeW)), relSizeH1 * (double)h,
                                       dialog.transparent->isChecked(), dialog.hideCoordsys->isChecked());
        examiner_widgets_[2]->snapshot(img2, (int)((double)w * (1.0 - relSizeW)), relSizeH2 * (double)h,
                                       dialog.transparent->isChecked(), dialog.hideCoordsys->isChecked());
        examiner_widgets_[3]->snapshot(img3, (int)((double)w * (1.0 - relSizeW)), relSizeH3 * (double)h,
                                       dialog.transparent->isChecked(), dialog.hideCoordsys->isChecked());
Dirk Wilden's avatar
Dirk Wilden committed
566

567
        QImage finalImage(img0.width() + img1.width() +2, img0.height(), QImage::Format_ARGB32_Premultiplied);
Dirk Wilden's avatar
Dirk Wilden committed
568
569

        QPainter painter(&finalImage);
570
571
572

        painter.fillRect(0,0,finalImage.width(), finalImage.height(), QBrush(Qt::gray));

Dirk Wilden's avatar
Dirk Wilden committed
573
574
        painter.drawImage(QRectF(           0,             0, img0.width(), img0.height()),img0,
                          QRectF(           0,             0, img0.width(), img0.height()) );
575
        painter.drawImage(QRectF(img0.width()+2,             0, img1.width(), img1.height()),img1,
Dirk Wilden's avatar
Dirk Wilden committed
576
                          QRectF(           0,             0, img1.width(), img1.height()) );
577
        painter.drawImage(QRectF(img0.width()+2, img1.height()+2, img2.width(), img2.height()),img2,
Dirk Wilden's avatar
Dirk Wilden committed
578
                          QRectF(           0,             0, img2.width(), img2.height()) );
579
        painter.drawImage(QRectF(img0.width()+2, img1.height()+img2.height()+4, img3.width(),img3.height()),img3,
Dirk Wilden's avatar
Dirk Wilden committed
580
581
582
583
584
585
586
587
588
589
                          QRectF(           0,             0, img3.width(), img3.height()) );

        finalImage.save(newName);

        break;
      }
      default: break;

    }
  }
590
  //glView_->resize(w, h);
Dirk Wilden's avatar
Dirk Wilden committed
591
592
}

Dirk Wilden's avatar
Dirk Wilden committed
593
///Take a snapshot of all viewers
Dirk Wilden's avatar
Dirk Wilden committed
594
595
596
597
void CoreWidget::viewerSnapshot() {

  QFileInfo fi(snapshotName_);

Jan Möbius's avatar
Jan Möbius committed
598
599
600
601
602
603
  // Add leading zeros
  QString number = QString::number(snapshotCounter_++);
  while ( number.size() < 7 )
    number = "0" + number;

  QString suggest = fi.path() + QDir::separator() +fi.baseName() + "." + number + ".";
Dirk Wilden's avatar
Dirk Wilden committed
604
605
606
607
608
609

  QString format="png";

  if (fi.completeSuffix() == "ppm")
    format="ppmraw";

Jan Möbius's avatar
Jan Möbius committed
610
611
612
  if (fi.completeSuffix() == "jpg")
    format="jpg";

Dirk Wilden's avatar
Dirk Wilden committed
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
  suggest += format;


  switch ( baseLayout_->mode() ){

    case QtMultiViewLayout::SingleView:
    {
      QImage finalImage;

      examiner_widgets_[PluginFunctions::activeExaminer()]->snapshot(finalImage);

      finalImage.save(suggest);

      break;
    }
    case QtMultiViewLayout::Grid:
    {
Dirk Wilden's avatar
Dirk Wilden committed
630
      QImage img0,img1,img2,img3;
631
      
Dirk Wilden's avatar
Dirk Wilden committed
632
633
634
635
636
      examiner_widgets_[0]->snapshot(img0);
      examiner_widgets_[1]->snapshot(img1);
      examiner_widgets_[2]->snapshot(img2);
      examiner_widgets_[3]->snapshot(img3);

637
      QImage finalImage(img0.width() + img1.width() + 2, img0.height() + img2.height() + 2, QImage::Format_ARGB32_Premultiplied);
Dirk Wilden's avatar
Dirk Wilden committed
638
639

      QPainter painter(&finalImage);
640
641
642

      painter.fillRect(0,0,finalImage.width(), finalImage.height(), QBrush(Qt::gray));

Dirk Wilden's avatar
Dirk Wilden committed
643
644
      painter.drawImage(QRectF(           0,             0, img0.width(), img0.height()),img0,
                        QRectF(           0,             0, img0.width(), img0.height()) );
645
      painter.drawImage(QRectF(img0.width()+2,           0, img1.width(), img1.height()),img1,
Dirk Wilden's avatar
Dirk Wilden committed
646
                        QRectF(           0,             0, img1.width(), img1.height()) );
647
      painter.drawImage(QRectF(           0, img0.height()+2, img2.width(), img2.height()),img2,
Dirk Wilden's avatar
Dirk Wilden committed
648
                        QRectF(           0,             0, img2.width(), img2.height()) );
649
      painter.drawImage(QRectF(img0.width()+2, img0.height()+2, img3.width(), img3.height()),img3,
Dirk Wilden's avatar
Dirk Wilden committed
650
651
652
                        QRectF(           0,             0, img3.width(), img3.height()) );

      finalImage.save(suggest);
Dirk Wilden's avatar
Dirk Wilden committed
653
654
655
656
657
658
659
660
661
662
663
664

      break;
    }
    case QtMultiViewLayout::HSplit:
    {
      QImage img0,img1,img2,img3;

      examiner_widgets_[0]->snapshot(img0);
      examiner_widgets_[1]->snapshot(img1);
      examiner_widgets_[2]->snapshot(img2);
      examiner_widgets_[3]->snapshot(img3);

665
      QImage finalImage(img0.width() + img1.width() + 2, img0.height(), QImage::Format_ARGB32_Premultiplied);
Dirk Wilden's avatar
Dirk Wilden committed
666

Dirk Wilden's avatar
Dirk Wilden committed
667
      QPainter painter(&finalImage);
668
669
670

      painter.fillRect(0,0,finalImage.width(), finalImage.height(), QBrush(Qt::gray));

Dirk Wilden's avatar
Dirk Wilden committed
671
672
      painter.drawImage(QRectF(           0,             0, img0.width(), img0.height()),img0,
                        QRectF(           0,             0, img0.width(), img0.height()) );
673
      painter.drawImage(QRectF(img0.width()+2,             0, img1.width(), img1.height()),img1,
Dirk Wilden's avatar
Dirk Wilden committed
674
                        QRectF(           0,             0, img1.width(), img1.height()) );
675
      painter.drawImage(QRectF(img0.width()+2, img1.height()+2, img2.width(), img2.height()),img2,
Dirk Wilden's avatar
Dirk Wilden committed
676
                        QRectF(           0,             0, img2.width(), img2.height()) );
677
      painter.drawImage(QRectF(img0.width()+2, img1.height()+img2.height()+4, img3.width(),img3.height()),img3,
Dirk Wilden's avatar
Dirk Wilden committed
678
                        QRectF(           0,             0, img3.width(), img3.height()) );
Dirk Wilden's avatar
Dirk Wilden committed
679
680
681
682
683
684
685
686
687

      finalImage.save(suggest);

      break;
    }
    default: break;

  }
}
Dirk Wilden's avatar
Dirk Wilden committed
688
689
690
691
692
693
694
695

void CoreWidget::applicationSnapshotName(QString _name) {

  snapshotName_ = _name;
  snapshotCounter_ = 0;
}


696
697
698
699
700
701
702
703
void CoreWidget::slotPasteView( ) {
  examiner_widgets_[PluginFunctions::activeExaminer()]->actionPasteView();
}

void CoreWidget::slotCopyView( ) {
  examiner_widgets_[PluginFunctions::activeExaminer()]->actionCopyView();
}

Dirk Wilden's avatar
Dirk Wilden committed
704
void CoreWidget::slotCoordSysVisibility(bool _visible){
705

Dirk Wilden's avatar
Dirk Wilden committed
706
707
708
709
  ACG::SceneGraph::BaseNode* root = PluginFunctions::getSceneGraphRootNode();
  ACG::SceneGraph::BaseNode* coordSys = root->find("Core Coordsys Node");

  if (coordSys == 0){
710
    emit log( LOGERR, tr("CoordSys Node not found"));
Dirk Wilden's avatar
Dirk Wilden committed
711
712
713
    return;
  }

714
if (_visible)
Dirk Wilden's avatar
Dirk Wilden committed
715
    coordSys->show();
716
  else
Dirk Wilden's avatar
Dirk Wilden committed
717
    coordSys->hide();
718

719
720
  for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
    examiner_widgets_[i]->updateGL();
721

Dirk Wilden's avatar
Dirk Wilden committed
722
}
Jan Möbius's avatar
Jan Möbius committed
723

724
725
726
727
void CoreWidget::slotSetViewingDirection(QAction* _action) {

  PluginFunctions::setFixedView( _action->data().toInt() );
}
728

729
730
731
732
733
void CoreWidget::slotLockRotation(bool _lock) {

  PluginFunctions::allowRotation( !_lock, PluginFunctions::activeExaminer() );
}

734
void CoreWidget::moveBack() {
Mike Kremer's avatar
Mike Kremer committed
735
    examiner_widgets_[PluginFunctions::activeExaminer()]->moveBack();
736
}
Mike Kremer's avatar
Mike Kremer committed
737

738
void CoreWidget::moveForward() {
Mike Kremer's avatar
Mike Kremer committed
739
    examiner_widgets_[PluginFunctions::activeExaminer()]->moveForward();
740
}
Mike Kremer's avatar
Mike Kremer committed
741

742
void CoreWidget::strafeLeft() {
Mike Kremer's avatar
Mike Kremer committed
743
    examiner_widgets_[PluginFunctions::activeExaminer()]->strafeLeft();
744
}
Mike Kremer's avatar
Mike Kremer committed
745

746
void CoreWidget::strafeRight() {
Mike Kremer's avatar
Mike Kremer committed
747
    examiner_widgets_[PluginFunctions::activeExaminer()]->strafeRight();
748
749
}

750
//=============================================================================