mvdMainWindow.cxx 57.9 KB
Newer Older
1
2
/*=========================================================================

3
  Program:   Monteverdi
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
33
34
35
36
37
38
39
40
41
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

#include "mvdMainWindow.h"
#include "ui_mvdMainWindow.h"


/*****************************************************************************/
/* INCLUDE SECTION                                                           */

//
// Qt includes (sorted by alphabetic order)
//// Must be included before system/custom includes.
#include <QtGui>

//
// System includes (sorted by alphabetic order)

//
// ITK includes (sorted by alphabetic order)

//
// OTB includes (sorted by alphabetic order)

//
// Monteverdi includes (sorted by alphabetic order)
42
#if defined( OTB_USE_QT4 ) && USE_OTB_APPS
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# include "ApplicationsWrapper/mvdApplicationLauncher.h"
# include "ApplicationsWrapper/mvdApplicationsToolBoxController.h"
# include "ApplicationsWrapper/mvdOTBApplicationsModel.h"
# include "ApplicationsWrapper/mvdWrapperQtWidgetView.h"
#endif
//
// #include "Core/mvdDatabaseModel.h"
// #include "Core/mvdDatasetModel.h"
#include "Core/mvdQuicklookModel.h"
#include "Core/mvdVectorImageModel.h"
//
#include "Gui/mvdApplicationsToolBox.h"
#include "Gui/mvdColorSetupController.h"
#include "Gui/mvdColorSetupWidget.h"
#include "Gui/mvdColorDynamicsController.h"
#include "Gui/mvdColorDynamicsWidget.h"
// #include "Gui/mvdDatabaseBrowserController.h"
#if ENABLE_TREE_WIDGET_TEST
// #include "Gui/mvdDatabaseBrowserWidgetTest.h"
#else // ENABLE_TREE_WIDGET_TEST
// #include "Gui/mvdDatabaseBrowserWidget.h"
#endif // ENABLE_TREE_WIDGET_TEST
// #include "Gui/mvdDatasetPropertiesController.h"
// #include "Gui/mvdDatasetPropertiesWidget.h"
#include "Gui/mvdFilenameDragAndDropEventFilter.h"
#include "Gui/mvdHistogramController.h"
#include "Gui/mvdHistogramWidget.h"
#include "Gui/mvdImageViewManipulator.h"
#include "Gui/mvdImageViewRenderer.h"
#include "Gui/mvdImageViewWidget.h"
73
#include "Gui/mvdImportSubDatasetDialog.h"
74
#include "Gui/mvdKeymapDialog.h"
75
#include "Gui/mvdLayerStackController.h"
76
#include "Gui/mvdLayerStackWidget.h"
77
78
79
#if USE_PIXEL_DESCRIPTION
#  include "Gui/mvdPixelDescriptionWidget.h"
#endif // USE_PIXEL_DESCRIPTION
80
81
#include "Gui/mvdQuicklookViewManipulator.h"
#include "Gui/mvdQuicklookViewRenderer.h"
82
#include "Gui/mvdShaderWidget.h"
83
84
85
86
87
#include "Gui/mvdStatusBarWidget.h"
//
#include "mvdApplication.h"
#include "mvdPreferencesDialog.h"

88

89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
namespace mvd
{

/*
  TRANSLATOR mvd::MainWindow

  Necessary for lupdate to be aware of C++ namespaces.

  Context comment for translator.
*/


/*****************************************************************************/
/* CONSTANTS                                                                 */

104
#define REFERENCE_LAYER_COMBOBOX_NAME "referenceLayerComboBox"
105

106
107
#define FORCE_NO_GLSL ( ( defined( _DEBUG ) && 0 ) || 0 )

108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*****************************************************************************/
/* STATIC IMPLEMENTATION SECTION                                             */


/*****************************************************************************/
/* CLASS IMPLEMENTATION SECTION                                              */

/*****************************************************************************/
MainWindow
::MainWindow( QWidget* parent, Qt::WindowFlags flags ) :
  I18nMainWindow( parent, flags ),
  m_UI( new mvd::Ui::MainWindow() ),
  m_ColorDynamicsDock( NULL ),
  m_ColorSetupDock( NULL ),
  // m_DatabaseBrowserDock( NULL ),
  // m_DatasetPropertiesDock(NULL),
124
  m_LayerStackDock( NULL ),
125
#if USE_PIXEL_DESCRIPTION
126
  m_PixelDescriptionDock(NULL),
127
#endif // USE_PIXEL_DESCRIPTION
128
  m_HistogramDock( NULL ),
129
#if defined( OTB_USE_QT4 ) && USE_OTB_APPS
130
131
132
133
  m_OtbApplicationsBrowserDock(NULL),
#endif
  m_ImageView( NULL ),
  m_QuicklookViewDock( NULL ),
134
#if USE_TABBED_VIEW
135
  m_CentralTabWidget( NULL ),
136
#endif // USE_TABBED_VIEW
137
138
  m_StatusBarWidget( NULL ),
  m_ShaderWidget( NULL ),
139
  m_FilenameDragAndDropEventFilter( NULL ),
140
  m_KeymapDialog( NULL ),
141
  m_GLSL140( -2 )
142
143
144
{
  m_UI->setupUi( this );

145
146
147
148
  //
  //
  m_KeymapDialog = new KeymapDialog( this );

149
150
151
152
153
154
  //
  // Event filters.
  m_FilenameDragAndDropEventFilter = new FilenameDragAndDropEventFilter( this );

  QObject::connect(
    m_FilenameDragAndDropEventFilter,
155
    SIGNAL( FilenamesDropped( const QStringList & ) ),
156
157
    // to:
    this,
158
    SLOT( ImportImages( const QStringList & ) )
159
160
161
162
163
164
165
166
167
168
169
170
171
172
  );
}

/*****************************************************************************/
MainWindow
::~MainWindow()
{
  delete m_UI;
  m_UI = NULL;
}

/*****************************************************************************/
bool
MainWindow
173
::CheckGLCapabilities()
174
175
176
177
{
  assert( m_ImageView!=NULL );
  assert( m_ImageView->GetRenderer()!=NULL );

Stéphane Albert's avatar
Stéphane Albert committed
178
179
180
181
182
  // Coverity-19845
  //
  // if( m_ImageView==NULL ||
  //     m_ImageView->GetRenderer()==NULL )
  //   return false;
183

184
185
  bool isGLSL = m_ImageView->GetRenderer()->CheckGLCapabilities( &m_GLSL140 );

186
187
188
189
190
191
#if FORCE_NO_GLSL
  m_ImageView->GetRenderer()->SetGLSLEnabled( false );

  isGLSL = false;
#endif // FORCE_NO_GLSL

192
193
194
195
196
197
198
199
200
  // MANTIS-1204
  // {
  //
  // Forward GLSL state to quicklook view.
  assert( GetQuicklookView()!=NULL );
  assert( GetQuicklookView()->GetRenderer()!=NULL );

  GetQuicklookView()->GetRenderer()->SetGLSLEnabled( isGLSL );
  // }
201
202
203

  assert( m_ShaderWidget!=NULL );

204
  m_ShaderWidget->SetGLSLEnabled( isGLSL );
205
206
  m_ShaderWidget->SetGLSL140Enabled( m_GLSL140>=0 );

207
208
209
210
211
  assert( m_StatusBarWidget!=NULL );

  m_StatusBarWidget->SetGLSLEnabled( isGLSL );


212
  return true;
213
214
215
216
217
218
219
}

/*****************************************************************************/
void
MainWindow
::virtual_SetupUI()
{
220
221
222
  assert( m_UI!=NULL );

  setObjectName( PROJECT_NAME );
223
224
225
226
227
228
229
  setWindowTitle( PROJECT_NAME );

  InitializeCentralWidget();

  InitializeDockWidgets();

  InitializeStatusBarWidgets();
230

231
  InitializeRenderToolBar();
232
  InitializeShaderToolBar();
233

234
  if( !RestoreLayout( Monteverdi_UI_VERSION ) )
235
236
237
    {
    qWarning() << "Failed to restore window layout!";
    }
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
}

/*****************************************************************************/
void
MainWindow
::virtual_ConnectUI()
{
  ConnectViewMenu();

  //
  // CHAIN CONTROLLERS.
  // Forward model update signals of color-setup controller...
  QObject::connect(
    m_ColorSetupDock->findChild< AbstractModelController* >(),
    SIGNAL( RgbChannelIndexChanged( RgbwChannel, int ) ),
    // to: ...color-dynamics controller model update signal.
    m_ColorDynamicsDock->findChild< AbstractModelController* >(),
    SLOT( OnRgbChannelIndexChanged( RgbwChannel, int ) )
  );
  QObject::connect(
    m_ColorSetupDock->findChild< AbstractModelController* >(),
    SIGNAL( GrayChannelIndexChanged( int ) ),
    // to: ...color-dynamics controller model update signal.
    m_ColorDynamicsDock->findChild< AbstractModelController* >(),
    SLOT( OnGrayChannelIndexChanged( int ) )
  );
  QObject::connect(
    m_ColorSetupDock->findChild< AbstractModelController* >(),
    SIGNAL( GrayscaleActivated( bool ) ),
    // to: ...color-dynamics controller model update signal.
    m_ColorDynamicsDock->findChild< AbstractModelController* >(),
    SLOT( OnGrayscaleActivated( bool ) )
  );

  QObject::connect(
    m_ColorSetupDock->findChild< AbstractModelController* >(),
    SIGNAL( RgbChannelIndexChanged( RgbwChannel, int ) ),
    // to: ...color-dynamics controller model update signal.
    m_HistogramDock->findChild< AbstractModelController* >(),
    SLOT( OnRgbChannelIndexChanged( RgbwChannel, int ) )
  );
  QObject::connect(
    m_ColorSetupDock->findChild< AbstractModelController* >(),
    SIGNAL( GrayChannelIndexChanged( int ) ),
    // to: ...color-dynamics controller model update signal.
    m_HistogramDock->findChild< AbstractModelController* >(),
    SLOT( OnGrayChannelIndexChanged( int ) )
  );
  QObject::connect(
    m_ColorSetupDock->findChild< AbstractModelController* >(),
    SIGNAL( GrayscaleActivated( bool ) ),
    // to: ...color-dynamics controller model update signal.
    m_HistogramDock->findChild< AbstractModelController* >(),
    SLOT( OnGrayscaleActivated( bool ) )
  );

  QObject::connect(
    m_ColorDynamicsDock->findChild< AbstractModelController* >(),
    SIGNAL( LowIntensityChanged( RgbwChannel, double, bool ) ),
    // to: ...histogram controller model update signal.
    m_HistogramDock->findChild< AbstractModelController* >(),
    SLOT( OnLowIntensityChanged( RgbwChannel, double, bool ) )
  );
  QObject::connect(
    m_ColorDynamicsDock->findChild< AbstractModelController* >(),
    SIGNAL( HighIntensityChanged( RgbwChannel, double, bool ) ),
    // to: ...histogram controller model update signal.
    m_HistogramDock->findChild< AbstractModelController* >(),
    SLOT( OnHighIntensityChanged( RgbwChannel, double, bool ) )
  );
  QObject::connect(
    m_ColorDynamicsDock->findChild< AbstractModelController* >(),
    SIGNAL( HistogramRefreshed() ),
    // to: ...histogram controller model update signal.
    m_HistogramDock->findChild< AbstractModelController* >(),
    SLOT( OnHistogramRefreshed() )
  );

  //
  // close tabs handling
318
#if USE_TABBED_VIEW
319
320
321
322
323
324
  QObject::connect(
    m_CentralTabWidget,
    SIGNAL( tabCloseRequested( int ) ),
    this,
    SLOT( OnTabCloseRequested( int ) )
  );
325
#endif // USE_TABBED_VIEW
326
327

  //
328
329
  // Other connections.

330
  ConnectImageViews();
331
332

  ConnectStatusBar();
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348

  //
  // When everything is connected, install event-filter.
  assert( m_ImageView!=NULL );
  m_ImageView->installEventFilter( m_FilenameDragAndDropEventFilter );

  {
  assert( GetController( m_LayerStackDock )!=NULL );

  LayerStackWidget * layerStackWidget =
    GetController( m_LayerStackDock )->GetWidget< LayerStackWidget >();

  assert( layerStackWidget!=NULL );

  layerStackWidget->InstallEventFilter( m_FilenameDragAndDropEventFilter );
  }
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
}

/*****************************************************************************/
void
MainWindow
::ConnectImageViews()
{
  assert( m_ImageView!=NULL );

  QObject::connect(
    this,
    SIGNAL( UserZoomIn() ),
    // to:
    m_ImageView,
    SLOT( ZoomIn() )
  );

  QObject::connect(
    this,
    SIGNAL( UserZoomOut() ),
    // to:
    m_ImageView,
    SLOT( ZoomOut() )
  );

  QObject::connect(
    this,
    SIGNAL( UserZoomExtent() ),
    m_ImageView,
    SLOT( ZoomToExtent() )
  );

  QObject::connect(
    this,
    SIGNAL( UserZoomFull() ),
    m_ImageView,
    SLOT( ZoomToFullResolution() )
  );

388
389
390
391
392
393
394
  QObject::connect(
    this,
    SIGNAL( UserZoomLayer() ),
    m_ImageView,
    SLOT( ZoomToLayerExtent() )
  );

395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
  //
  // Connect image-views for ROI-changed events.

  const AbstractImageViewManipulator* imageViewManipulator =
    m_ImageView->GetManipulator();

  assert( imageViewManipulator!=NULL );


  ImageViewWidget* quicklookView = GetQuicklookView();
  assert( quicklookView!=NULL );

  const AbstractImageViewManipulator* quicklookManipulator =
    quicklookView->GetManipulator();

  assert( quicklookManipulator!=NULL );


  QObject::connect(
    m_ImageView,
415
416
    SIGNAL( RoiChanged(
        const PointType &, const SizeType &, const SpacingType &, const PointType & )
417
418
419
    ),
    // to:
    quicklookManipulator,
420
421
    SLOT( OnRoiChanged(
        const PointType &, const SizeType &, const SpacingType &, const PointType & )
422
423
424
425
426
427
428
429
430
431
432
    )
  );

  QObject::connect(
    quicklookView,
    SIGNAL( CenterRoiRequested( const PointType& ) ),
    // to:
    imageViewManipulator,
    SLOT( CenterOn( const PointType& ) )
  );

433
434
435
436
437
438
439
440
  // Not needed anymore becaure already done in ImageViewWidget.
  // QObject::connect(
  //   quicklookManipulator,
  //   SIGNAL( RefreshViewRequested() ),
  //   // to:
  //   m_ImageView,
  //   SLOT( updateGL() )
  // );
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467

  //
  // Connect controllers to image-views.
  //

  {
  assert( m_LayerStackDock!=NULL );

  AbstractModelController * controller = GetController( m_LayerStackDock );
  assert( controller!=NULL );

  QObject::connect(
    controller,
    SIGNAL( ApplyAllRequested() ),
    // to:
    m_ImageView,
    SLOT( OnApplyAllRequested() )
  );

  QObject::connect(
    controller,
    SIGNAL( ApplyAllRequested() ),
    // to:
    quicklookView,
    SLOT( OnApplyAllRequested() )
  );
  }
468
469
470
471
472
473
474
475
}

/*****************************************************************************/
void
MainWindow
::ConnectViewMenu()
{
  m_UI->menu_View->addAction( m_UI->m_ToolBar->toggleViewAction() );
476
  m_UI->menu_View->addAction( m_UI->m_RenderToolBar->toggleViewAction() );
477
478
  m_UI->menu_View->addAction( m_UI->m_ShaderToolBar->toggleViewAction() );

479
480
481
482
483
  m_UI->menu_View->addSeparator();

  m_UI->menu_View->addAction( m_ColorSetupDock->toggleViewAction() );
  m_UI->menu_View->addAction( m_ColorDynamicsDock->toggleViewAction() );
  m_UI->menu_View->addAction( m_HistogramDock->toggleViewAction() );
484
  m_UI->menu_View->addAction( m_LayerStackDock->toggleViewAction() );
485
  m_UI->menu_View->addAction( m_QuicklookViewDock->toggleViewAction() );
486
487
488
489
490

  m_UI->menu_View->addSeparator();

  m_UI->menu_View->addSeparator();

491
#if USE_PIXEL_DESCRIPTION
492
  m_UI->menu_View->addAction( m_PixelDescriptionDock->toggleViewAction() );
493
#endif // USE_PIXEL_DESCRIPTION
494
495
496
497
498
}

/*****************************************************************************/
void
MainWindow
499
::ConnectStatusBar()
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
{
  assert( m_StatusBarWidget!=NULL );
  assert( m_ImageView!=NULL );

  QObject::connect(
    m_ImageView,
    SIGNAL( ScaleChanged( double, double ) ),
    // to:
    m_StatusBarWidget,
    SLOT( SetScale( double, double ) )
  );

  QObject::connect(
    m_StatusBarWidget,
    SIGNAL( ScaleChanged( double ) ),
    // to:
    m_ImageView->GetManipulator(),
    SLOT( ZoomTo( double ) )
  );

  QObject::connect(
    m_StatusBarWidget,
    SIGNAL( PixelIndexChanged( const IndexType& ) ),
    // to:
    m_ImageView,
525
    SLOT( CenterOnSelected( const IndexType& ) )
526
  );
527
528
529
530
531
532
533
534

  QObject::connect(
    m_ImageView,
    SIGNAL( PixelInfoChanged( const QPoint &, const PointType &, const PixelInfo::Vector & ) ),
    // to:
    this,
    SLOT( OnPixelInfoChanged( const QPoint &, const PointType &, const PixelInfo::Vector & ) )
  );
535
536
}

537
/*****************************************************************************/
538
539
#if USE_PIXEL_DESCRIPTION

540
541
void
MainWindow
542
::ConnectPixelDescriptionWidget( AbstractLayerModel * model )
543
{
544
545
546
547
  if( model==NULL ||
      !model->inherits( VectorImageModel::staticMetaObject.className() ) )
    return;

548
  // Access vector-image model.
549
550
551
552
553
  VectorImageModel * vectorImageModel =
    qobject_cast< VectorImageModel * >( model );

  assert( vectorImageModel==qobject_cast< VectorImageModel * >( model ) );
  assert( vectorImageModel!=NULL );
554

555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
  //
  // send the physical point of the clicked point in screen
  // vectorImageModel is in charge of pixel information computation
  QObject::connect(
    m_ImageView,
    SIGNAL(
      PhysicalCursorPositionChanged(
	const QPoint &,
	const PointType &,
	const PointType &,
	const DefaultImageType::PixelType &
      )
    ),
    // to:
    vectorImageModel,
    SLOT(
      OnPhysicalCursorPositionChanged(
	const QPoint &,
	const PointType &,
	const PointType &,
	const DefaultImageType::PixelType&
      )
    )
  );

  QObject::connect(
    GetQuicklookView(),
    SIGNAL(
      PhysicalCursorPositionChanged(
	const QPoint &,
	const PointType &,
	const PointType &,
	const DefaultImageType::PixelType&
      )
    ),
    // to:
    vectorImageModel,
    SLOT(
      OnPhysicalCursorPositionChanged(
	const QPoint &,
	const PointType &,
	const PointType &,
	const DefaultImageType::PixelType&
      )
    )
  );

602
  // get the PixelDescription widget
603
604
605
606
  // TODO: Make a widget controller!
  PixelDescriptionWidget * pixelDescriptionWidget = 
    qobject_cast< PixelDescriptionWidget * >(
      m_PixelDescriptionDock->findChild< PixelDescriptionWidget * >()
607
608
    );

609
  assert( pixelDescriptionWidget!=NULL );
610

611
612
613
614
615
616
617
  QObject::connect(
    vectorImageModel,
    SIGNAL( CurrentPhysicalUpdated( const QStringList & ) ),
    // to:
    pixelDescriptionWidget,
    SLOT( OnCurrentPhysicalUpdated( const QStringList & ) )
  );
618

619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
  QObject::connect(
    vectorImageModel,
    SIGNAL( CurrentGeographicUpdated( const QStringList & ) ),
    // to:
    pixelDescriptionWidget,
    SLOT( OnCurrentGeographicUpdated( const QStringList & ) )
  );

  QObject::connect(
    vectorImageModel,
    SIGNAL( CurrentPixelValueUpdated(const VectorImageType::PixelType &, 
                                     const QStringList & ) ),
    // to:
    pixelDescriptionWidget,
    SLOT( OnCurrentPixelValueUpdated(const VectorImageType::PixelType &, 
                                     const QStringList & ) )
  );
636
637
}

638
639
#endif // USE_PIXEL_DESCRIPTION

640
/*****************************************************************************/
641
642
#if USE_PIXEL_DESCRIPTION

643
644
void
MainWindow
645
::DisconnectPixelDescriptionWidget( const AbstractLayerModel * model )
646
{
647
648
649
  if( model==NULL ||
      !model->inherits( VectorImageModel::staticMetaObject.className() ) )
    return;
650
651

  // Access vector-image model.
652
653
654
655
656
  const VectorImageModel * vectorImageModel =
    qobject_cast< const VectorImageModel * >( model );

  assert( vectorImageModel==qobject_cast< const VectorImageModel * >( model ) );
  assert( vectorImageModel!=NULL );
657

658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
  //
  // send the physical point of the clicked point in screen
  // vectorImageModel is in charge of pixel information computation
  QObject::disconnect(
    m_ImageView,
    SIGNAL(
      PhysicalCursorPositionChanged(
	const QPoint &,
	const PointType &,
	const PointType &,
	const DefaultImageType::PixelType &
      )
    ),
    // to:
    vectorImageModel,
    SLOT(
      OnPhysicalCursorPositionChanged(
	const QPoint &,
	const PointType &,
	const PointType &,
	const DefaultImageType::PixelType &
      )
    )
  );

  QObject::disconnect(
    GetQuicklookView(),
    SIGNAL(
      PhysicalCursorPositionChanged(
	const QPoint &,
	const PointType &,
	const PointType &,
	const DefaultImageType::PixelType &
      )
    ),
    // to:
    vectorImageModel,
    SLOT(
      OnPhysicalCursorPositionChanged(
	const QPoint &,
	const PointType &,
	const PointType &,
	const DefaultImageType::PixelType&
      )
    )
  );

705
  // get the PixelDescription widget
706
707
708
709
  // TODO: Make a widget controller!
  PixelDescriptionWidget * pixelDescriptionWidget = 
    qobject_cast< PixelDescriptionWidget * >(
      m_PixelDescriptionDock->findChild< PixelDescriptionWidget * >()
710
711
    );

712
  assert( pixelDescriptionWidget!=NULL );
713

714
715
716
717
718
719
720
  QObject::disconnect(
    vectorImageModel,
    SIGNAL( CurrentPhysicalUpdated( const QStringList & ) ),
    // to:
    pixelDescriptionWidget,
    SLOT( OnCurrentPhysicalUpdated( const QStringList & ) )
  );
721

722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
  QObject::disconnect(
    vectorImageModel,
    SIGNAL( CurrentGeographicUpdated( const QStringList & ) ),
    // to:
    pixelDescriptionWidget,
    SLOT( OnCurrentGeographicUpdated( const QStringList & ) )
  );

  QObject::connect(
    vectorImageModel,
    SIGNAL(
      CurrentPixelValueUpdated(
        const VectorImageType::PixelType &,
        const QStringList &
      )
    ),
    // to:
    pixelDescriptionWidget,
    SLOT(
      OnCurrentPixelValueUpdated(
        const VectorImageType::PixelType &,
        const QStringList &
      )
    )
  );
747
748
}

749
750
#endif // USE_PIXEL_DESCRIPTION

751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
/*****************************************************************************/
void
MainWindow
::InitializeDockWidgets()
{
#define ENABLE_QTOOLBAR_TEST 0
#if ENABLE_QTOOLBAR_TEST
  // XP: QToolBar test.
  QDockWidget* dock =
    AddWidgetToDock(
      m_UI->m_ToolBar,
      "TOOL_BAR",
      tr( "Tool bar" ),
      Qt::TopDockWidgetArea
    );

  m_UI->menu_View->addAction( dock->toggleViewAction() );
#endif

  //
  // Left pane.

  //
  // Right pane.

  // Quicklook-view dock-widget
  assert( m_QuicklookViewDock==NULL );
  assert( m_ImageView!=NULL );
  m_QuicklookViewDock = AddWidgetToDock(
    CreateQuicklookViewWidget( m_ImageView ),
    "QUICKLOOK_VIEW",
    tr( "Quicklook view" ),
    Qt::RightDockWidgetArea
  );

786
  // Histogram-view.
787
788
789
790
791
792
793
794
795
796
  assert( m_HistogramDock==NULL );
  m_HistogramDock =
    AddDockWidget
    < HistogramWidget, HistogramController, QDockWidget >
    ( "HISTOGRAM",
      tr( "Histogram" ),
      Qt::RightDockWidgetArea,
      false
    );

797
798
  tabifyDockWidget( m_QuicklookViewDock, m_HistogramDock );

799
800
#if USE_PIXEL_DESCRIPTION

801
802
803
804
805
806
807
808
809
810
811
812
813
  // Pixel Description (no controller needed here / direct update of
  // the pixel description through signals from VectorImageModel)
  assert( m_PixelDescriptionDock==NULL );
  m_PixelDescriptionDock =
    AddDockWidget
    < PixelDescriptionWidget, QDockWidget >
    ( "CURRENT_PIXEL_DESCRIPTION",
      tr( "Pixel Description" ),
      Qt::RightDockWidgetArea
    );

  tabifyDockWidget( m_PixelDescriptionDock, m_HistogramDock );

814
815
#endif // USE_PIXEL_DESCRIPTION

816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
  // Color-setup.
  assert( m_ColorSetupDock==NULL );
  m_ColorSetupDock =
    AddDockWidget
    < ColorSetupWidget, ColorSetupController, QDockWidget >
    ( "COLOR_SETUP",
      tr( "Color setup" ),
      Qt::RightDockWidgetArea
    );

  // Color-dynamics.
  assert( m_ColorDynamicsDock==NULL );
  m_ColorDynamicsDock =
    AddDockWidget
    < ColorDynamicsWidget, ColorDynamicsController, QDockWidget >
    ( "COLOR_DYNAMICS",
      tr( "Color dynamics" ),
      Qt::RightDockWidgetArea
    );

  // Tabify dock-widgets.
  tabifyDockWidget( m_ColorSetupDock, m_ColorDynamicsDock );
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852


  //
  // Bottom pane
  //

  // Layer-stack editor.
  assert( m_LayerStackDock==NULL );
  m_LayerStackDock = AddDockWidget<
    LayerStackWidget, LayerStackController, QDockWidget >(
      "LAYER_STACK",
      tr( "Layer stack" ),
      Qt::BottomDockWidgetArea
    );

853
854
855
856
857
858
859
}

/*****************************************************************************/
void
MainWindow
::InitializeCentralWidget()
{
860
#if USE_TABBED_VIEW
861
862
863
864
865
866
867
868
869
870
871
872
873
  // Create central tab-widget for multi-view support.
  assert( m_CentralTabWidget==NULL );
  m_CentralTabWidget = new QTabWidget( this );

  // Customize it.
  m_CentralTabWidget->setTabsClosable( true );

  // Set-it up as central widget.
  setCentralWidget( m_CentralTabWidget );

  //
  // access to the quicklook tabBar to remove the close button
  QTabBar* tabBar = m_CentralTabWidget->findChild< QTabBar* >();
874
#endif // USE_TABBED_VIEW
875
876
877
878
879

  // Initialize image-view.
  assert( m_ImageView==NULL );
  m_ImageView = CreateImageViewWidget();

880
#if USE_TABBED_VIEW
881
882
883
884
885
886
887
888
  // Add first tab: image-view.
  int index = m_CentralTabWidget->addTab(
    m_ImageView,
    tr( "Image view" )
  );

  tabBar->setTabButton( index, QTabBar::RightSide, 0);
  tabBar->setTabButton( index, QTabBar::LeftSide, 0);
889
890
891
892
893

#else // USE_TABBED_VIEW
  setCentralWidget( m_ImageView );

#endif // USE_TABBED_VIEW
894
895
}

896
897
898
899
900
/*****************************************************************************/
void
MainWindow
::InitializeRenderToolBar()
{
901
902
  m_UI->m_RenderToolBar->addSeparator();

903
  {
904
  m_UI->m_RenderToolBar->addWidget(
905
    new QLabel( tr( "Proj" ) )
906
907
  );

908
909
910
  QComboBox * comboBox =
    new QComboBox( m_UI->m_RenderToolBar );

911
912
  comboBox->setToolTip( tr( "Select projection used as reference for the view." ) );

913
914
915
  assert( comboBox!=NULL );

  comboBox->setObjectName( "referenceLayerComboBox" );
916
917
918
919
920
921
922
923
924
925
  comboBox->setMinimumSize(
    QSize(
#ifdef _DEBUG
      116,
#else
      128,
#endif
      0
    )
  );
926
927
928

  m_UI->m_RenderToolBar->addWidget( comboBox );
  }
929
}
930

931
932
933
934
935
936
/*****************************************************************************/
void
MainWindow
::InitializeShaderToolBar()
{
  assert( m_ShaderWidget==NULL );
937

938
  {
939
940
941
  m_UI->m_ShaderToolBar->addWidget(
    new QLabel( tr( "Layer FX" ) )
  );
942

943
  m_ShaderWidget = new ShaderWidget( m_UI->m_ShaderToolBar );
944

945
  m_UI->m_ShaderToolBar->addWidget( m_ShaderWidget );
946
947
948
  }
}

949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
/*****************************************************************************/
void
MainWindow
::InitializeStatusBarWidgets()
{
  m_StatusBarWidget = new StatusBarWidget(statusBar());
  statusBar()->addPermanentWidget(m_StatusBarWidget, 1);
}

/*****************************************************************************/
ImageViewWidget*
MainWindow
::CreateImageViewWidget( QGLWidget* sharedGlWidget )
{
  ImageViewRenderer* renderer =
    new ImageViewRenderer( this );

  ImageViewManipulator* manipulator =
    new ImageViewManipulator(
#if USE_VIEW_SETTINGS_SIDE_EFFECT
      renderer->GetViewSettings(),
#endif // USE_VIEW_SETTINGS_SIDE_EFFECT
      this
    );

  ImageViewWidget* imageView = new ImageViewWidget(
    manipulator, // (will be reparented.)
    renderer, // (will be reparented.)
    this,
    sharedGlWidget
  );

  imageView->setMinimumWidth( 256 );

  return imageView;
}

/*****************************************************************************/
ImageViewWidget*
MainWindow
::CreateQuicklookViewWidget( QGLWidget* sharedGlWidget )
{
  QuicklookViewRenderer* renderer =
    new QuicklookViewRenderer( this );

  QuicklookViewManipulator* manipulator =
    new QuicklookViewManipulator(
#if USE_VIEW_SETTINGS_SIDE_EFFECT
      renderer->GetViewSettings(),
#endif // USE_VIEW_SETTINGS_SIDE_EFFECT
      this
    );

  ImageViewWidget* quicklookView = new ImageViewWidget(
    manipulator, // (will be reparented.)
    renderer, // (will be reparented.)
    this,
    sharedGlWidget
  );

1009
  quicklookView->SetPickingEnabled( false );
1010
1011
  quicklookView->SetPickingDefaultStatus( false );
  
1012
1013
1014
1015
1016
1017
1018
1019
  quicklookView->setMinimumSize(  64,  64 );
  quicklookView->setMaximumSize( 512, 512 );
  quicklookView->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum );

  return quicklookView;
}

/*****************************************************************************/
1020
CountType
1021
MainWindow
1022
::ImportImage( const QString& filename, StackedLayerModel::SizeType index )
1023
{
Stéphane Albert's avatar
Stéphane Albert committed
1024
  // qDebug() << this << "::ImportImage(" << filename << "," << index << ")";
1025
1026
1027

  //
  // Get stacked-layer.
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
  assert( Application::Instance() );
  assert(
    Application::Instance()->GetModel()==
    Application::Instance()->GetModel< StackedLayerModel >()
  );

  StackedLayerModel* stackedLayerModel =
    Application::Instance()->GetModel< StackedLayerModel >();

  assert( stackedLayerModel!=NULL );

1039
1040
1041
  //
  // CDS import
  {
1042
    ImportSubDatasetDialog * importDialog = new ImportSubDatasetDialog( filename, this );
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070

    assert( importDialog!=NULL );

    if( importDialog->HasSubDatasets() )
      {
      if( importDialog->exec()==QDialog::Rejected )
	return 0;

      IntVector::size_type count = 0;
      IntVector indices;

      importDialog->GetSubDatasets( indices );

      for( IntVector::size_type i=0;
	   i<indices.size();
	   ++ i )
	count +=
	  ImportImage(
	    QString( "%1?&sdataidx=%2" ).arg( filename ).arg( indices[ i ] ),
	    index + count
	  );

      return count;
      }
  }
  // CDS import.
  //

1071
1072
1073
1074
1075
1076
1077
1078
1079
  //
  // Count images regarding their spatial-reference type.
  size_t gcs = 0; // Geo/Carto/Sensor
  size_t unk = 0; // Unknown

  stackedLayerModel->CountSRT( unk, gcs, gcs, gcs );

  //
  //
1080
1081
1082
1083
1084
1085
  // Coverity-112757
  // {
  SpatialReferenceType srt = SRT_UNKNOWN;

  try
    {
1086
1087
1088
    // qDebug()
    //   << this << "\n"
    //   << "\tQString:" << filename;
1089

1090
1091
1092
    // std::cout
    //   << "\tstd::string: " << QFile::encodeName( filename ).constData()
    //   << std::endl;
1093
1094

    srt = GetSpatialReferenceType( QFile::encodeName( filename ).constData() );
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
    }
  catch( const std::exception & exception )
    {
    QMessageBox::warning(
      this,
      "Warning!",
      tr( "Exception caught while checking Spatial Reference Type of image-file '%1':\n\n%2" )
      .arg( filename )
      .arg( exception.what() )
    );
    }
  // }
  // Coverity-112757.
1108
1109
1110
1111
1112
1113
1114
1115

  QMessageBox::StandardButton button = QMessageBox::NoButton;

  if( unk==0 && gcs>0 && srt==SRT_UNKNOWN )
    {
    button =
      QMessageBox::warning(
	this,
1116
	tr( "Warning!" ),
1117
1118
1119
1120
1121
1122
1123
	tr( "No projection information (geographical or cartographical coordinate-system or sensor model) has been found for image. While already loaded images all have some, they are displayed in a geo-referenced view.\n\nLoading '%1' will cause the display to switch to a non geo-referenced view (where images are displayed relatively regarding their origin and spacing)." )
	.arg( filename ),
	QMessageBox::Ok | QMessageBox::Cancel
      );
    }

  if( button==QMessageBox::Cancel )
1124
    return 0;
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148

  /*
  switch( button )
    {
    case QMessageBox::Cancel:
      return;
      break;

    case QMessageBox::Ok:
      // Disable reference-layer combo-box.
      // Disable layer-stack projection-button.
      break;

    default:
      assert( false && "Unhandled QMessageBox::StandardButton value!" );
      break;
    }
  */

  //
  // Import image file.
  VectorImageModel * imageModel = ImportImage( filename, -1, -1 );

  if( imageModel==NULL )
1149
    return 0;
1150

1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
  //
  // Bypass rendering of image-views.
  assert( m_ImageView!=NULL );
  bool bypassImageView = m_ImageView->SetBypassRenderingEnabled( true );

  ImageViewWidget * quicklookView = GetQuicklookView();
  assert( quicklookView!=NULL );

  bool bypassQuicklookView = quicklookView->SetBypassRenderingEnabled( true );

1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
  //
  // Block some signals.
  //
  // BUGFIX: MANTIS-1120
  // {
  assert( m_UI!=NULL );
  assert( m_UI->m_RenderToolBar!=NULL );

  QComboBox * referenceLayerComboBox =
    m_UI->m_RenderToolBar->findChild< QComboBox * >(
      REFERENCE_LAYER_COMBOBOX_NAME
    );

  assert( referenceLayerComboBox!=NULL );

  bool signalsBlocked = referenceLayerComboBox->blockSignals( true );
  // }

1179
  //
1180
  // Store image-mode in layer-stack.
1181
  stackedLayerModel->Insert( imageModel, index );
1182

1183
1184
  imageModel->setParent( stackedLayerModel );

1185
1186
  stackedLayerModel->SetCurrent( imageModel );

1187
1188
  bool hasReference = stackedLayerModel->HasReference();

1189
  if( !hasReference && srt!=SRT_UNKNOWN )
1190
    stackedLayerModel->SetReference( imageModel  );
1191

1192
1193
1194
  else if( hasReference && srt==SRT_UNKNOWN )
    stackedLayerModel->SetReference( StackedLayerModel::NIL_INDEX );

1195
1196
1197
1198
1199
  //
  // Set zoom-level which forces image-views refresh.
  if( !hasReference )
    UserZoomExtent();

1200
  //
1201
  // Re-activate rendering of image-views.
1202
1203
  m_ImageView->SetBypassRenderingEnabled( bypassImageView );
  quicklookView->SetBypassRenderingEnabled( bypassQuicklookView );
1204
1205
1206
1207
1208
1209
1210
1211
1212

  //
  // Un-block some signals.
  //
  // BUGFIX: MANTIS-1120
  // {
  referenceLayerComboBox->blockSignals( signalsBlocked );
  // }
  //
1213
1214

  return 1;
1215
}
1216

1217
1218
1219
1220
1221
1222
1223
1224
/*****************************************************************************/
void
MainWindow
::ImportImages( const QStringList & filenames )
{
  if( filenames.isEmpty() )
    return;

1225
1226
  if( !BuildGDALOverviews( filenames ) )
    return;
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241

  if( filenames.count()==1 )
    ImportImage( filenames.front(), 0 );

  else
    {
    StackedLayerModel::SizeType i = 0;

    for( QStringList::const_iterator it( filenames.constBegin() );
         it!=filenames.end();
	 ++it )
      {
        ImportImage( *it, i ++ );
      }
    }
1242
1243
1244
1245
1246
1247
1248
1249

  assert( m_ImageView!=NULL );
  m_ImageView->updateGL();

  ImageViewWidget * quicklookView = GetQuicklookView();
  assert( quicklookView!=NULL );

  quicklookView->updateGL();
1250
1251
1252
1253
1254
1255
1256
}

/*****************************************************************************/
void
MainWindow
::closeEvent( QCloseEvent* event )
{
1257
1258
  assert( event!=NULL );

1259
1260
1261
1262
  {
    //
    // List OTB-application widgets.
    typedef QList< mvd::Wrapper::QtWidgetView * > QtWidgetViewList;
1263

1264
    QtWidgetViewList children( findChildren< mvd::Wrapper::QtWidgetView * >() );
1265

1266
    QStringList names;
1267

1268
1269
1270
1271
1272
    //
    // Find out which OTB-applications are running.
    for( QtWidgetViewList::iterator it( children.begin() );
	 it!=children.end();
	 ++ it )
1273
      {
1274
1275
1276
1277
1278
      assert( *it );

      if( !( *it )->IsClosable() )
	{
	assert( !( *it )->GetApplication().IsNull() );
1279

1280
	// qDebug() << "OTB-application:" << ( *it )->GetApplication()->GetDocName();
1281

1282
1283
	names.push_back( ( *it )->GetApplication()->GetDocName() );
	}
1284
1285
      }

1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
    //
    // If some OTB-application is running, display warning, names and
    // prevent to close.
    if( !names.isEmpty() )
      {
      QMessageBox::warning(
	this,
	tr( "Warning!" ),
	tr(
	  PROJECT_NAME
	  " cannot exit while some OTB-application is running!\n\n"
	  "Please wait for following OTB-applicatio(s) to exit:\n- %1"
	)
	.arg( names.join( "\n- " ) )
      );
1301

1302
      event->ignore();
1303

1304
1305
1306
      return;
      }
  }
1307

1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336

  {
    assert( I18nCoreApplication::Instance()!=NULL );
    assert( I18nCoreApplication::Instance()->GetModel()==
	    I18nCoreApplication::Instance()->GetModel< StackedLayerModel >() );

    StackedLayerModel * stackedLayerModel =
      I18nCoreApplication::Instance()->GetModel< StackedLayerModel >();

    if( stackedLayerModel!=NULL &&
	!stackedLayerModel->IsEmpty() )
      {
      QMessageBox::StandardButton button =
	QMessageBox::question(
	  this,
	  PROJECT_NAME,
	  tr( "Some files have been loaded. Are you sure you want to quit?" ),
	  QMessageBox::Yes | QMessageBox::No
	);

      if( button==QMessageBox::No )
	{
	event->ignore();

	return;
	}
      }
  }

1337

1338
  SaveLayout( Monteverdi_UI_VERSION );
1339
1340


1341
1342
  //
  // Otherwise, close.
1343
1344
1345
1346
  I18nMainWindow::closeEvent( event );
}

/*****************************************************************************/
1347
1348
1349
1350
1351
1352
1353
1354
void
MainWindow
::virtual_InitializeUI()
{
  assert( Application::Instance() );

  Application::Instance()->SetModel( new StackedLayerModel() ); 
}
1355

1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
/*****************************************************************************/
void
MainWindow
::ConnectReferenceLayerComboBox( StackedLayerModel * model )
{
  assert( model!=NULL );

  QComboBox * comboBox =
    m_UI->m_RenderToolBar->findChild< QComboBox * >(
      REFERENCE_LAYER_COMBOBOX_NAME
    );

  assert( comboBox!=NULL );

  QObject::connect(
    comboBox,
    SIGNAL( currentIndexChanged( int ) ),
    // to:
    this,
    SLOT( OnReferenceLayerCurrentIndexChanged( int ) )
  );

  QObject::connect(
    model,
    SIGNAL( ContentChanged() ),
    // to:
    this,
    SLOT( RefreshReferenceLayerComboBox() )
  );

1386
1387
1388
1389
1390
1391
1392
1393
  QObject::connect(
    model,
    SIGNAL( ContentReset() ),
    // to:
    this,
    SLOT( RefreshReferenceLayerComboBox() )
  );

1394
1395
1396
1397
1398
1399
1400
  QObject::connect(
    model,
    SIGNAL( OrderChanged() ),
    // to:
    this,
    SLOT( RefreshReferenceLayerComboBox() )
  );
1401
1402
1403
1404
1405
1406

  QObject::connect(
    model,
    SIGNAL( ReferenceChanged( size_t ) ),
    // to:
    this,
1407
    SLOT( OnReferenceLayerChanged( size_t ) )
1408
  );
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
}

/*****************************************************************************/
void
MainWindow
::SetupReferenceLayerComboBox( StackedLayerModel * model )
{
  QComboBox * comboBox =
    m_UI->m_RenderToolBar->findChild< QComboBox * >(
      REFERENCE_LAYER_COMBOBOX_NAME
    );

  assert( comboBox!=NULL );

1423
1424
1425

  bool signalsBlocked = comboBox->blockSignals( true );
  {
1426
1427
  comboBox->clear();

1428
  comboBox->addItem( "None" );
1429
1430
1431
  }
  comboBox->blockSignals( signalsBlocked );

1432

1433
1434
1435
  if( model==NULL )
    return;

1436

1437
1438
1439
  for( StackedLayerModel::SizeType i=0;
       i<model->GetCount();
       ++i )
1440
    {
1441
1442
1443
1444
    AbstractLayerModel * layer = model->At( i );
    assert( layer!=NULL );

    if( layer->inherits( VectorImageModel::staticMetaObject.className() ) )
1445
1446
      {
      const VectorImageModel * vectorImageModel =
1447
        qobject_cast< const VectorImageModel * >( layer );
1448
1449
1450
1451

      assert( vectorImageModel!=NULL );

      comboBox->addItem(
1452
1453
        QString( "%1 (%2)" )
        .arg( layer->GetAuthorityCode( true ).c_str()  )
1454
1455
1456
1457
1458
1459
1460
        .arg( QFileInfo( vectorImageModel->GetFilename() ).fileName() )
      );
      }
    else
      qDebug() << "Unhandled AbstractLayerModel subclass.";
    }

1461
1462
1463
1464
1465
1466
1467
1468
  {
  size_t gcs = 0; // Geo/Carto/Sensor
  size_t unk = 0; // Unknown

  model->CountSRT( unk, gcs, gcs, gcs );

  comboBox->setEnabled( model->GetCount()>0 && unk==0 );
  }
1469

1470
1471
1472
  comboBox->setCurrentIndex(
    model->GetReferenceIndex()>=model->GetCount()
    ? 0 // comboBox->count() - 1
1473
    : model->GetReferenceIndex() + 1
1474
  );
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
}

/*****************************************************************************/
void
MainWindow
::DisconnectReferenceLayerComboBox( StackedLayerModel * model )
{
  QComboBox * comboBox =
    m_UI->m_RenderToolBar->findChild< QComboBox * >(
      REFERENCE_LAYER_COMBOBOX_NAME
    );

  assert( comboBox!=NULL );

  QObject::disconnect(
    comboBox,
    SIGNAL( currentIndexChanged( int ) ),
    // to:
    this,
    SLOT( OnReferenceLayerCurrentIndexChanged( int ) )
  );

  if( model!=NULL )
    {
    QObject::disconnect(
      model,
      SIGNAL( ContentChanged() ),
      // to:
      this,
      SLOT( RefreshReferenceLayerComboBox() )
    );

1507
1508
1509
1510
1511
1512
1513
1514
    QObject::disconnect(
      model,
      SIGNAL( ContentReset() ),
      // to:
      this,
      SLOT( RefreshReferenceLayerComboBox() )
    );

1515
1516
1517
1518
1519
1520
1521
    QObject::disconnect(
      model,
      SIGNAL( OrderChanged() ),
      // to:
      this,
      SLOT( RefreshReferenceLayerComboBox() )
    );
1522
1523
1524
1525
1526
1527

    QObject::disconnect(
      model,
      SIGNAL( ReferenceChanged( size_t ) ),
      // to:
      this,
1528
      SLOT( OnReferenceLayerChanged( size_t ) )
1529
    );
1530
1531
1532
1533
1534
1535
    }

  comboBox->clear();
  comboBox->setEnabled( false );
}

1536
1537
1538
1539
1540
1541
1542
/****************************************************************************/
#if USE_OTB_APPS

void
MainWindow
::SetupOTBApplications()
{
1543
1544
  // qDebug() << this << "::SetupOTBApplications()";
  // qDebug() << "{";
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554

  assert( m_OtbApplicationsBrowserDock==NULL );

  //
  // Load OTB-applications and create browser in dock-widget .
  m_OtbApplicationsBrowserDock =
    AddDockWidget
    < ApplicationsToolBox, ApplicationsToolBoxController, QDockWidget >
    ( "APPLICATIONS_BROWSER",
      tr( "OTB-Applications browser" ),
1555
      Qt::RightDockWidgetArea,
1556
1557
1558
      true
    );

1559
  tabifyDockWidget( m_HistogramDock, m_OtbApplicationsBrowserDock );
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604

  SetControllerModel(
    m_OtbApplicationsBrowserDock,
    Application::Instance()->GetOTBApplicationsModel()
  );

  //
  // Connect signals.
  //
  // need to get the ApplicationToolBox widget to setup connections.
  // a double click on the tree widget should trigger a signal connected
  // to this MainWindow slot. this slot will be in charge of getting the
  // widget of the application selected, and show it in the
  // MainWindow centralView.

  // # Step 1 : get the ApplicationToolBoxWidget
  ApplicationsToolBox* appWidget =
    qobject_cast< ApplicationsToolBox * >(
      m_OtbApplicationsBrowserDock->findChild< ApplicationsToolBox* >()
    );
  assert( appWidget!=NULL );

  // # Step 2 : setup connections
  QObject::connect(
    appWidget,
    SIGNAL( ApplicationToLaunchSelected(const QString &, const QString &) ),
    this,
    SLOT( OnApplicationToLaunchSelected(const QString &, const QString &) )
  );

  // # Step 3 : connect close slots
  // TODO

  //
  // Update main-window UI.
  m_UI->action_LoadOTBApplications->setEnabled( false );

  m_UI->menu_View->addAction(
    m_OtbApplicationsBrowserDock->toggleViewAction()
  );

  m_UI->menu_View->addAction(
    m_OtbApplicationsBrowserDock->toggleViewAction()
  );

1605
  // qDebug() << "}";
1606
1607
1608
1609
}

#endif // USE_OTB_APPS

1610
1611
/*****************************************************************************/
/* SLOTS                                                                     */
1612
1613
1614
1615
1616
/*****************************************************************************/
void
MainWindow
::on_action_Keymap_triggered()
{
1617
1618
1619
1620
  assert( m_KeymapDialog!=NULL );

  if( m_KeymapDialog->isVisible() )
    return;
1621

1622
  m_KeymapDialog->show();
1623
1624
}

1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
/****************************************************************************/
void
MainWindow
::on_action_LoadOTBApplications_triggered()
{
#if USE_OTB_APPS
  SetupOTBApplications();
#endif // USE_OTB_APPS
}

1635
1636
1637
/*****************************************************************************/
void
MainWindow
1638
::on_action_OpenImage_triggered()
1639
1640
1641
{
  //
  // Select filename.
1642
1643
  ImportImages(
    I18nMainWindow::GetOpenFileNames( this, tr( "Open file..." ) )
1644
1645
1646
1647
1648
1649
  );
}

/*****************************************************************************/
void
MainWindow
1650
::on_action_Preferences_triggered()
1651
1652
1653
1654
1655
1656
{
  PreferencesDialog prefDialog( this );

  prefDialog.exec();
}

1657
1658
1659
1660
1661
1662
1663
/*****************************************************************************/
void
MainWindow
::on_action_SaveScreenshot_triggered()
{
  assert( m_ImageView!=NULL );

1664
  m_ImageView->SaveScreenshot( false );
1665
1666
}

1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
/*****************************************************************************/
void
MainWindow
::on_action_ZoomIn_triggered()
{
  emit UserZoomIn();
}

/*****************************************************************************/
void
MainWindow
::on_action_ZoomOut_triggered()
{
  emit UserZoomOut();
}

/*****************************************************************************/
void
MainWindow
::on_action_ZoomExtent_triggered()
{
  emit UserZoomExtent();
}

/*****************************************************************************/
void
MainWindow
::on_action_ZoomFull_triggered()
{
  emit UserZoomFull();
}

1699
1700
1701
1702
1703
1704
1705
1706
/*****************************************************************************/
void
MainWindow
::on_action_ZoomLayer_triggered()
{
  emit UserZoomLayer();
}