1 /***************************************************************************
2 * This file is part of Tecorrec. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
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. *
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. *
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 ***************************************************************************/
21 * @file tcMainWindow.h
22 * @brief Main application window.
25 #include "tcMainWindow.h"
26 #include "tcViewportWidget.h"
27 #include "tcColourMapWidget.h"
29 #include <tcSrtmCache.h>
30 #include <tcGeoImageData.h>
31 #include <tcChannelManager.h>
32 #include <tcChannel.h>
33 #include <tcChannelConfigWidget.h>
34 #include <tcExportText.h>
37 #include <qwt_plot_curve.h>
39 #include <QHBoxLayout>
44 #include <QDockWidget>
47 #include <QRadioButton>
49 #include <QPushButton>
50 #include <QButtonGroup>
53 * Constructors + destructor
56 /// Default constructor.
57 tcMainWindow::tcMainWindow()
59 , m_viewport(new tcViewportWidget(this))
60 , m_colourMap(new tcColourMapWidget(QStringList()
61 << tr("Red") << tr("Green") << tr("Blue") << tr("A") << tr("B") << tr("C"), this))
62 , m_globe(new tcGlobe(6378.137e3
))
65 m_viewport
->setGlobe(m_globe
);
66 setCentralWidget(m_viewport
);
70 QMenuBar
* menus
= menuBar();
72 QMenu
* menuFile
= menus
->addMenu(tr("File", "The menu"));
74 QMenu
* menuFileExport
= menuFile
->addMenu(tr("Export", "The menu"));
76 QAction
* menuFileExportText
= menuFileExport
->addAction(tr("Export as Text"),
77 this, SLOT(exportText()));
80 QMenu
* menuView
= menus
->addMenu(tr("View", "The menu"));
82 QMenu
* menuViewQuality
= menuView
->addMenu(tr("Elevation Quality", "The menu"));
84 QAction
* menuViewQualityAdaptive
= menuViewQuality
->addAction(tr("Adaptive Resolution"),
85 m_viewport
, SLOT(setQualityAdaptive()));
86 QAction
* menuViewQualityFull
= menuViewQuality
->addAction(tr("Full Resolution"),
87 m_viewport
, SLOT(setQualityFull()));
89 QMenu
* menuViewRender
= menuView
->addMenu(tr("Render Options", "The menu"));
91 QAction
* menuViewRenderNormal
= menuViewRender
->addAction(tr("Normal", "Polygon mode"),
92 m_viewport
, SLOT(setPolygonModeNormal()));
93 QAction
* menuViewRenderWireframe
= menuViewRender
->addAction(tr("Wireframe", "Polygon mode"),
94 m_viewport
, SLOT(setPolygonModeWireframe()));
96 QMenu
* menuViewRenderColour
= menuView
->addMenu(tr("Colour Coding", "The menu"));
98 QAction
* menuViewRenderColourNone
= menuViewRenderColour
->addAction(tr("No colour coding"),
99 m_viewport
, SLOT(setColourCodingNone()));
100 QAction
* menuViewRenderColourElevationSampleAlignment
= menuViewRenderColour
->addAction(tr("Alignment of elevation samples"),
101 m_viewport
, SLOT(setColourCodingElevationSampleAlignment()));
109 QStatusBar
* statusBar
= new QStatusBar(this);
110 connect(m_viewport
, SIGNAL(mouseGeoTextChanged(const QString
&)),
111 statusBar
, SLOT(showMessage(const QString
&)));
112 foreach (tcGeoImageData
* imagery
, m_globe
->imagery())
114 connect(imagery
->channelManager(), SIGNAL(progressing(const QString
&)),
115 statusBar
, SLOT(showMessage(const QString
&)));
117 connect(m_globe
->dem(), SIGNAL(progressing(const QString
&)),
118 statusBar
, SLOT(showMessage(const QString
&)));
119 setStatusBar(statusBar
);
122 QDockWidget
* dockElevation
;
124 // Docker for elevation data settings
125 QDockWidget
* docker
= new QDockWidget(tr("Elevation Data"), this);
126 dockElevation
= docker
;
127 QWidget
* dockerWidget
= new QWidget(docker
);
128 QVBoxLayout
* layout
= new QVBoxLayout(dockerWidget
);
129 docker
->setWidget(dockerWidget
);
130 addDockWidget(Qt::LeftDockWidgetArea
, docker
);
132 // Combo box to select data set
133 QStringList elevDataSets
= tcSrtmCache::dataSets();
134 QString elevTypeNames
[2] = {
138 const char* elevDatasetSlot
[2] = { SLOT(setPrimaryElevationDataSet(const QString
&)), SLOT(setSecondaryElevationDataSet(const QString
&)) };
139 const char* elevFlatSlot
[2] = { SLOT(setPrimaryElevationFlat()), SLOT(setSecondaryElevationFlat()) };
140 const char* elevRawSlot
[2] = { SLOT(setPrimaryElevationRaw()), SLOT(setSecondaryElevationRaw()) };
141 const char* elevCorrectedSlot
[2] = { SLOT(setPrimaryElevationCorrected()), SLOT(setSecondaryElevationCorrected()) };
142 for (int i
= 0; i
< 2; ++i
)
144 QLabel
* elevInterpolationLabel
= new QLabel(elevTypeNames
[i
], dockerWidget
);
145 layout
->addWidget(elevInterpolationLabel
);
147 QComboBox
* elevDataSet
= new QComboBox(dockerWidget
);
148 layout
->addWidget(elevDataSet
);
149 elevDataSet
->addItem("");
150 foreach (QString dataSet
, elevDataSets
)
152 elevDataSet
->addItem(dataSet
);
154 connect(elevDataSet
, SIGNAL(currentIndexChanged(const QString
&)), m_viewport
, elevDatasetSlot
[i
]);
155 if (-1 != elevDataSet
->currentIndex())
157 m_viewport
->setPrimaryElevationDataSet(elevDataSet
->currentText());
161 QButtonGroup
* elevGroup
= new QButtonGroup(dockerWidget
);
162 QRadioButton
* elevFlat
= new QRadioButton(tr("Don't Show Elevation (Flat)"), dockerWidget
);
163 layout
->addWidget(elevFlat
);
164 elevGroup
->addButton(elevFlat
);
165 connect(elevFlat
, SIGNAL(pressed()), m_viewport
, elevFlatSlot
[i
]);
166 QRadioButton
* elevRaw
= new QRadioButton(tr("Raw SRTM Elevation Data"), dockerWidget
);
167 layout
->addWidget(elevRaw
);
168 elevGroup
->addButton(elevRaw
);
169 connect(elevRaw
, SIGNAL(pressed()), m_viewport
, elevRawSlot
[i
]);
170 QRadioButton
* elevCorrected
= new QRadioButton(tr("Corrected SRTM Elevation Data"), dockerWidget
);
171 layout
->addWidget(elevCorrected
);
172 elevGroup
->addButton(elevCorrected
);
173 elevCorrected
->setChecked(true);
174 connect(elevCorrected
, SIGNAL(pressed()), m_viewport
, elevCorrectedSlot
[i
]);
177 layout
->addStretch();
180 QLabel
* elevInterpolationLabel
= new QLabel(tr("Interpolate between DEMs"), dockerWidget
);
181 layout
->addWidget(elevInterpolationLabel
);
182 QSlider
* elevCorrectionLevel
= new QSlider(Qt::Horizontal
, dockerWidget
);
183 layout
->addWidget(elevCorrectionLevel
);
184 elevCorrectionLevel
->setRange(0,100);
185 elevCorrectionLevel
->setValue(100);
186 connect(elevCorrectionLevel
, SIGNAL(valueChanged(int)), m_viewport
, SLOT(setElevationInterpolation(int)));
189 layout
->addStretch();
193 // Docker for satellite imagery
194 QDockWidget
* docker
= new QDockWidget(tr("Imagery Data"), this);
195 QWidget
* dockerWidget
= new QWidget(docker
);
196 QVBoxLayout
* layout
= new QVBoxLayout(dockerWidget
);
197 docker
->setWidget(dockerWidget
);
198 tabifyDockWidget(dockElevation
, docker
);
201 layout
->addWidget(m_colourMap
);
202 foreach (tcGeoImageData
* imagery
, m_globe
->imagery())
204 const tcChannelManager
* manager
= imagery
->channelManager();
205 int numChannels
= manager
->numChannels();
206 m_colourMap
->addInputGroupSeparator(imagery
->name());
207 for (int i
= 0; i
< numChannels
; ++i
)
209 tcChannel
* channel
= manager
->channel(i
);
210 m_colourMap
->addInputBand(channel
->name(), channel
->description());
213 connect(m_colourMap
, SIGNAL(inputBandClicked(int, int)), this, SLOT(configureChannel(int, int)));
214 connect(m_colourMap
, SIGNAL(inputGroupClicked(int)), m_viewport
, SLOT(sunView(int)));
215 connect(m_colourMap
, SIGNAL(inputBandChanged(int, int, int)), m_viewport
, SLOT(setColourMapping(int, int, int)));
216 for (int i
= 0; i
< 3; ++i
)
218 m_colourMap
->setInputBand(i
, 2-i
);
223 // Docker for processing
224 QDockWidget
* docker
= new QDockWidget(tr("Processing"), this);
225 QWidget
* dockerWidget
= new QWidget(docker
);
226 QVBoxLayout
* layout
= new QVBoxLayout(dockerWidget
);
227 docker
->setWidget(dockerWidget
);
228 tabifyDockWidget(dockElevation
, docker
);
231 QwtPlot
* plot
= new QwtPlot(this);
232 layout
->addWidget(plot
);
233 plot
->setTitle("This is a test");
234 //plot->setAutoLegend(true);
235 //plot->setLegendPosition(Qwt::bottom);
236 //plot->setAxisTitle(xBottom, "x");
237 //plot->setAxisTitle(yLeft, "y");
238 QwtPlotCurve
* cSin
= new QwtPlotCurve("y=sin(x)");
239 cSin
->setPen(QPen(Qt::red
));
240 const int points
= 500;
243 for (int i
= 0; i
< points
; ++i
)
245 x
[i
] = (3.0 * 3.14 / double(points
))*double(i
);
246 sn
[i
] = 2.0*sin(x
[i
]);
248 cSin
->setData(x
, sn
, points
);
254 layout
->addStretch();
259 tcMainWindow::~tcMainWindow()
268 /// Show configuration for a channel.
269 void tcMainWindow::configureChannel(int channel
, int group
)
271 tcChannelManager
* manager
= m_globe
->imagery()[group
]->channelManager();
272 tcChannelConfigWidget
* configWidget
= manager
->channel(channel
)->configWidget();
273 if (0 != configWidget
)
275 connect(configWidget
, SIGNAL(updated()),
276 m_viewport
, SLOT(updateGL()));
277 connect(configWidget
, SIGNAL(newSlice(const tcGeo
&, const tcGeo
&)),
278 m_viewport
, SLOT(setSlice(const tcGeo
&, const tcGeo
&)));
279 connect(configWidget
, SIGNAL(texturePointRequested(QObject
*, const char*)),
280 m_viewport
, SLOT(texturePointMode(QObject
*, const char*)));
281 configWidget
->setWindowFlags(Qt::Tool
| Qt::WindowStaysOnTopHint
);
282 configWidget
->show();
287 void tcMainWindow::exportText()
289 if (0 == m_exportText
)
291 m_exportText
= new tcExportText(m_globe
->imagery(), this);
293 m_exportText
->setWindowFlags(Qt::Dialog
| Qt::WindowStaysOnTopHint
);
294 m_exportText
->show();