File: aoqplotwindow.cpp

package info (click to toggle)
aoflagger 3.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 4,476 kB
  • sloc: cpp: 51,868; python: 152; sh: 25; makefile: 17
file content (178 lines) | stat: -rw-r--r-- 6,246 bytes parent folder | download
1
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
33
34
35
36
37
38
39
40
41
42
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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
167
168
169
170
171
172
173
174
175
176
177
178
#include "aoqplotwindow.h"

#include "controllers/antennapagecontroller.h"
#include "controllers/aoqplotcontroller.h"
#include "controllers/baselinepagecontroller.h"
#include "controllers/blengthpagecontroller.h"
#include "controllers/frequencypagecontroller.h"
#include "controllers/histogrampagecontroller.h"
#include "controllers/tfpagecontroller.h"
#include "controllers/timepagecontroller.h"

#include <limits>

#include <gtkmm/main.h>
#include <gtkmm/messagedialog.h>

#include "../structures/msmetadata.h"

#include "../quality/histogramtablesformatter.h"
#include "../quality/histogramcollection.h"
#include "../quality/statisticscollection.h"

#include "baselineplotpage.h"
#include "blengthplotpage.h"
#include "frequencyplotpage.h"
#include "histogrampage.h"
#include "summarypage.h"
#include "timefrequencyplotpage.h"

AOQPlotWindow::AOQPlotWindow(AOQPlotController* controller) :
	_controller(controller),
	_activeSheetIndex(-1),
	_pageMenuButton("Sheet"),
	_baselineMI(_pageGroup, "Baselines"),
	_antennaeMI(_pageGroup, "Antennae"),
	_bLengthMI(_pageGroup, "Baseline lengths"),
	_timeMI(_pageGroup, "Time"),
	_frequencyMI(_pageGroup, "Frequency"),
	_timeFrequencyMI(_pageGroup, "Time-frequency"),
	_summaryMI(_pageGroup, "Summary"),
	_histogramMI(_pageGroup, "Histograms")
{
	set_default_icon_name("aoqplot");
	
	_toolbar.append(_pageMenuButton);
	_pageMenuButton.set_menu(_pageMenu);
	_pageMenu.append(_baselineMI);
	_baselineMI.signal_toggled().connect(sigc::mem_fun(*this, &AOQPlotWindow::onChangeSheet));
	_pageMenu.append(_antennaeMI);
	_antennaeMI.signal_toggled().connect(sigc::mem_fun(*this, &AOQPlotWindow::onChangeSheet));
	_pageMenu.append(_bLengthMI);
	_bLengthMI.signal_toggled().connect(sigc::mem_fun(*this, &AOQPlotWindow::onChangeSheet));
	_pageMenu.append(_timeMI);
	_timeMI.signal_toggled().connect(sigc::mem_fun(*this, &AOQPlotWindow::onChangeSheet));
	_pageMenu.append(_frequencyMI);
	_frequencyMI.signal_toggled().connect(sigc::mem_fun(*this, &AOQPlotWindow::onChangeSheet));
	_pageMenu.append(_timeFrequencyMI);
	_timeFrequencyMI.signal_toggled().connect(sigc::mem_fun(*this, &AOQPlotWindow::onChangeSheet));
	_pageMenu.append(_summaryMI);
	_summaryMI.signal_toggled().connect(sigc::mem_fun(*this, &AOQPlotWindow::onChangeSheet));
	_pageMenu.append(_histogramMI);
	_histogramMI.signal_toggled().connect(sigc::mem_fun(*this, &AOQPlotWindow::onChangeSheet));
	_pageMenu.show_all_children();
	
	_vBox.pack_start(_toolbar, Gtk::PACK_SHRINK);
	
	_vBox.pack_end(_statusBar, Gtk::PACK_SHRINK);
	_statusBar.push("Quality plot util is ready. Author: André Offringa (offringa@gmail.com)");
	
	add(_vBox);
	
	_openOptionsWindow.SignalOpen().connect(sigc::mem_fun(*this, &AOQPlotWindow::onOpenOptionsSelected));
	signal_hide().connect(sigc::mem_fun(*this, &AOQPlotWindow::onHide));
	
	_controller->Attach(this);
}

void AOQPlotWindow::Open(const std::vector<std::string> &files)
{
	show_all();
	_openOptionsWindow.ShowForFile(files);
}

void AOQPlotWindow::onOpenOptionsSelected(const std::vector<std::string>& files, bool downsampleTime, bool downsampleFreq, size_t timeCount, size_t freqCount, bool correctHistograms)
{
	_controller->ReadStatistics(files, downsampleTime, downsampleFreq, timeCount, freqCount, correctHistograms);
	_activeSheetIndex = -1;
	onChangeSheet();
	show();
}

void AOQPlotWindow::onStatusChange(const std::string &newStatus)
{
	_statusBar.pop();
	_statusBar.push(newStatus);
}

void AOQPlotWindow::onChangeSheet()
{
	int selectedSheet = -1;
	if(_baselineMI.get_active())
		selectedSheet = 0;
	else if(_antennaeMI.get_active())
		selectedSheet = 1;
	else if(_bLengthMI.get_active())
		selectedSheet = 2;
	else if(_timeMI.get_active())
		selectedSheet = 3;
	else if(_frequencyMI.get_active())
		selectedSheet = 4;
	else if(_timeFrequencyMI.get_active())
		selectedSheet = 5;
	else if(_summaryMI.get_active())
		selectedSheet = 6;
	else if(_histogramMI.get_active())
		selectedSheet = 7;
	
	if(selectedSheet != _activeSheetIndex)
	{
		switch(selectedSheet)
		{
		case 0:
			_pageController.reset(new BaselinePageController());
			_activeSheet.reset(new BaselinePlotPage( static_cast<BaselinePageController*>(_pageController.get())));
			SetStatus("Baseline statistics");
			break;
		case 1:
			_pageController.reset(new AntennaePageController());
			_activeSheet.reset(new TwoDimensionalPlotPage( static_cast<AntennaePageController*>(_pageController.get())));
			SetStatus("Antennae statistics");
			break;
		case 2:
			_pageController.reset(new BLengthPageController());
			_activeSheet.reset(new BLengthPlotPage( static_cast<BLengthPageController*>(_pageController.get())));
			SetStatus("Baseline length statistics");
			break;
		case 3:
			_pageController.reset(new TimePageController());
			_activeSheet.reset(new TwoDimensionalPlotPage( static_cast<TimePageController*>(_pageController.get())));
			SetStatus("Time statistics");
			break;
		case 4:
			_pageController.reset(new FrequencyPageController());
			_activeSheet.reset(new FrequencyPlotPage(static_cast<FrequencyPageController*>(_pageController.get())));
			SetStatus("Frequency statistics");
			break;
		case 5:
			_pageController.reset(new TFPageController());
			_activeSheet.reset(new TimeFrequencyPlotPage( static_cast<TFPageController*>(_pageController.get())));
			SetStatus("Time-frequency statistics");
			break;
		case 6:
			_pageController.reset(new SummaryPageController());
			_activeSheet.reset(new SummaryPage( static_cast<SummaryPageController*>(_pageController.get())));
			SetStatus("Summary");
			break;
		case 7:
			_pageController.reset(new HistogramPageController());
			_activeSheet.reset(new HistogramPage( static_cast<HistogramPageController*>(_pageController.get())));
			SetStatus("Histograms");
			break;
		}
		
		_activeSheetIndex = selectedSheet;
		_controller->Initialize(_pageController.get(), selectedSheet != 5);
		_activeSheet->SignalStatusChange().connect(sigc::mem_fun(*this, &AOQPlotWindow::onStatusChange));
		_activeSheet->InitializeToolbar(_toolbar);
		_toolbar.show_all();
		_vBox.pack_start(*_activeSheet);
		_activeSheet->show_all();
	}
}

void AOQPlotWindow::ShowError(const std::string& message)
{
	Gtk::MessageDialog dialog(*this, message, false, Gtk::MESSAGE_ERROR);
	dialog.run();
}