Fixed SRTM positioning (each tile overlaps the next by one sample) and added config...
[tecorrec.git] / tcMainWindow.cpp
blobb63ce3c0df5f12f543e46f80657ff0ec7e0a5478
1 /***************************************************************************
2 * This file is part of Tecorrec. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
4 * *
5 * Tecorrec is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * Tecorrec is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with Tecorrec. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
20 /**
21 * @file tcMainWindow.h
22 * @brief Main application window.
25 #include "tcMainWindow.h"
26 #include "tcViewportWidget.h"
27 #include "tcColourMapWidget.h"
28 #include <tcGlobe.h>
29 #include <tcSrtmCache.h>
30 #include <tcGeoImageData.h>
31 #include <tcChannelManager.h>
32 #include <tcChannel.h>
33 #include <tcChannelConfigWidget.h>
35 #include <QHBoxLayout>
36 #include <QWidget>
37 #include <QMenuBar>
38 #include <QMenu>
39 #include <QStatusBar>
40 #include <QDockWidget>
41 #include <QComboBox>
42 #include <QRadioButton>
43 #include <QSlider>
44 #include <QPushButton>
47 * Constructors + destructor
50 /// Default constructor.
51 tcMainWindow::tcMainWindow()
52 : QMainWindow()
53 , m_viewport(new tcViewportWidget(this))
54 , m_colourMap(new tcColourMapWidget(QStringList()
55 << tr("Red") << tr("Green") << tr("Blue"), this))
56 , m_globe(new tcGlobe(6378.137e3))
58 m_viewport->setGlobe(m_globe);
59 setCentralWidget(m_viewport);
62 // Menu bar
63 QMenuBar* menus = menuBar();
65 QMenu* menuView = menus->addMenu(tr("View", "The menu"));
67 QMenu* menuViewQuality = menuView->addMenu(tr("Elevation Quality", "The menu"));
69 QAction* menuViewQualityAdaptive = menuViewQuality->addAction(tr("Adaptive Resolution"),
70 m_viewport, SLOT(setQualityAdaptive()));
71 QAction* menuViewQualityFull = menuViewQuality->addAction(tr("Full Resolution"),
72 m_viewport, SLOT(setQualityFull()));
74 QMenu* menuViewRender = menuView->addMenu(tr("Render Options", "The menu"));
76 QAction* menuViewRenderNormal = menuViewRender->addAction(tr("Normal", "Polygon mode"),
77 m_viewport, SLOT(setPolygonModeNormal()));
78 QAction* menuViewRenderWireframe = menuViewRender->addAction(tr("Wireframe", "Polygon mode"),
79 m_viewport, SLOT(setPolygonModeWireframe()));
81 QMenu* menuViewRenderColour = menuView->addMenu(tr("Colour Coding", "The menu"));
83 QAction* menuViewRenderColourNone = menuViewRenderColour->addAction(tr("No colour coding"),
84 m_viewport, SLOT(setColourCodingNone()));
85 QAction* menuViewRenderColourElevationSampleAlignment = menuViewRenderColour->addAction(tr("Alignment of elevation samples"),
86 m_viewport, SLOT(setColourCodingElevationSampleAlignment()));
93 // Status bar
94 QStatusBar* statusBar = new QStatusBar(this);
95 connect(m_viewport, SIGNAL(mouseGeoTextChanged(const QString&)),
96 statusBar, SLOT(showMessage(const QString&)));
97 setStatusBar(statusBar);
100 QDockWidget* dockElevation;
102 // Docker for elevation data settings
103 QDockWidget* docker = new QDockWidget(tr("Elevation Data"), this);
104 dockElevation = docker;
105 QWidget* dockerWidget = new QWidget(docker);
106 QVBoxLayout* layout = new QVBoxLayout(dockerWidget);
107 docker->setWidget(dockerWidget);
108 addDockWidget(Qt::LeftDockWidgetArea, docker);
110 // Combo box to select data set
111 QComboBox* elevDataSet = new QComboBox(dockerWidget);
112 layout->addWidget(elevDataSet);
113 QStringList elevDataSets = tcSrtmCache::dataSets();
114 foreach (QString dataSet, elevDataSets)
116 elevDataSet->addItem(dataSet);
118 connect(elevDataSet, SIGNAL(currentIndexChanged(const QString&)), m_viewport, SLOT(setElevationDataSet(const QString&)));
119 if (-1 != elevDataSet->currentIndex())
121 m_viewport->setElevationDataSet(elevDataSet->currentText());
124 // Radio buttons
125 QRadioButton* elevFlat = new QRadioButton(tr("Don't Show Elevation (Flat)"), dockerWidget);
126 layout->addWidget(elevFlat);
127 connect(elevFlat, SIGNAL(pressed()), m_viewport, SLOT(setElevationFlat()));
128 QRadioButton* elevRaw = new QRadioButton(tr("Raw SRTM Elevation Data"), dockerWidget);
129 layout->addWidget(elevRaw);
130 elevRaw->setChecked(true);
131 connect(elevRaw, SIGNAL(pressed()), m_viewport, SLOT(setElevationRaw()));
132 QRadioButton* elevCorrected = new QRadioButton(tr("Corrected SRTM Elevation Data"), dockerWidget);
133 layout->addWidget(elevCorrected);
134 connect(elevCorrected, SIGNAL(pressed()), m_viewport, SLOT(setElevationCorrected()));
135 QSlider* elevCorrectionLevel = new QSlider(Qt::Horizontal, dockerWidget);
136 layout->addWidget(elevCorrectionLevel);
137 elevCorrectionLevel->setRange(0,100);
138 connect(elevCorrectionLevel, SIGNAL(valueChanged(int)), m_viewport, SLOT(setElevationCorrection(int)));
140 // Spacer
141 layout->addStretch();
145 // Docker for satellite imagery
146 QDockWidget* docker = new QDockWidget(tr("Imagery Data"), this);
147 QWidget* dockerWidget = new QWidget(docker);
148 QVBoxLayout* layout = new QVBoxLayout(dockerWidget);
149 docker->setWidget(dockerWidget);
150 tabifyDockWidget(dockElevation, docker);
152 // Button to go to sun view
153 QPushButton* btnSunView = new QPushButton(tr("Sun View"), this);
154 layout->addWidget(btnSunView);
155 connect(btnSunView, SIGNAL(clicked(bool)), m_viewport, SLOT(sunView()));
157 // Grid of colours
158 layout->addWidget(m_colourMap);
159 const tcChannelManager* manager = m_globe->imagery()->channelManager();
160 int numChannels = manager->numChannels();
161 for (int i = 0; i < numChannels; ++i)
163 tcChannel* channel = manager->channel(i);
164 m_colourMap->addInputBand(channel->name(), channel->description());
166 for (int i = 0; i < 3; ++i)
168 m_colourMap->setInputBand(i, 2-i);
170 connect(m_colourMap, SIGNAL(inputBandClicked(int)), this, SLOT(configureChannel(int)));
171 connect(m_colourMap, SIGNAL(inputBandChanged(int, int)), m_viewport, SLOT(setColourMapping(int,int)));
175 // Docker for processing
176 QDockWidget* docker = new QDockWidget(tr("Processing"), this);
177 QWidget* dockerWidget = new QWidget(docker);
178 QVBoxLayout* layout = new QVBoxLayout(dockerWidget);
179 docker->setWidget(dockerWidget);
180 tabifyDockWidget(dockElevation, docker);
182 // Spacer
183 layout->addStretch();
187 /// Destructor.
188 tcMainWindow::~tcMainWindow()
190 delete m_globe;
194 * Private slots
197 /// Show configuration for a channel.
198 void tcMainWindow::configureChannel(int channel)
200 tcChannelManager* manager = m_globe->imagery()->channelManager();
201 tcChannelConfigWidget* configWidget = manager->channel(channel)->configWidget();
202 if (0 != configWidget)
204 connect(configWidget, SIGNAL(updated()),
205 m_viewport, SLOT(updateGL()));
206 connect(configWidget, SIGNAL(texturePointRequested(QObject*, const char*)),
207 m_viewport, SLOT(texturePointMode(QObject*, const char*)));
208 configWidget->setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
209 configWidget->show();