File: FSK441Display.cpp

package info (click to toggle)
wstools 0.4.8d-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,440 kB
  • ctags: 1,991
  • sloc: cpp: 13,880; makefile: 469
file content (189 lines) | stat: -rw-r--r-- 5,117 bytes parent folder | download | duplicates (2)
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
179
180
181
182
183
184
185
186
187
188
189
/*
 *   Copyright (C) 2002-2004 by Jonathan Naylor G4KLX
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program 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 General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "FSK441Display.h"
#include "FSK441App.h"

#include "FSK441Defs.h"

const int BORDER_SIZE = 5;

enum {
	List_Messages        = 150,
	Menu_Messages_Clear  = 250
};

BEGIN_EVENT_TABLE(CFSK441Display, wxPanel)
	EVT_MENU(Menu_Messages_Clear, CFSK441Display::onClearMessages)
	EVT_LIST_ITEM_SELECTED(List_Messages, CFSK441Display::onMessageSelected)
	EVT_LIST_ITEM_RIGHT_CLICK(List_Messages, CFSK441Display::onMessageClick)
END_EVENT_TABLE()

CFSK441Display::CFSK441Display(wxWindow* parent, int id) :
wxPanel(parent, id),
m_levelGraph(NULL),
m_audioGraph(NULL),
m_messageListCtrl(NULL),
m_messageMenu(NULL),
m_listCount(0),
m_selected(-1),
m_messageList(NULL)
{
	wxASSERT(parent != NULL);

	m_messageMenu = createMessageMenu();

	m_messageList = new CFSK441MessageList(wxKEY_NONE);
	m_messageList->DeleteContents(true);

	wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);

	wxBoxSizer* graphSizer = new wxBoxSizer(wxHORIZONTAL);

	m_levelGraph = new CFSK441LevelGraph(this, -1, wxDefaultPosition, wxSize(FSK441_LEVEL_WIDTH, FSK441_GRAPH_HEIGHT));
	graphSizer->Add(m_levelGraph, 0, wxLEFT | wxBOTTOM | wxRIGHT, BORDER_SIZE);

	m_audioGraph = new CLevelGraph(this, -1, wxDefaultPosition, wxSize(FSK441_AUDIO_WIDTH, FSK441_GRAPH_HEIGHT));
	graphSizer->Add(m_audioGraph, 0, wxALL, 0);

	sizer->Add(graphSizer, 0, wxTOP, BORDER_SIZE);

	m_messageListCtrl = new wxListCtrl(this, List_Messages, wxDefaultPosition, wxSize(FSK441_MESSAGES_WIDTH, FSK441_MESSAGES_HEIGHT));
	m_messageListCtrl->SetSingleStyle(wxLC_REPORT);
	m_messageListCtrl->InsertColumn(0, wxT("Id"));
	m_messageListCtrl->SetColumnWidth(0, 75);
	m_messageListCtrl->InsertColumn(1, wxT("Time"));
	m_messageListCtrl->SetColumnWidth(1, 50);
	m_messageListCtrl->InsertColumn(2, wxT("Length"));
	m_messageListCtrl->SetColumnWidth(2, 50);
	m_messageListCtrl->InsertColumn(3, wxT("Strength"));
	m_messageListCtrl->SetColumnWidth(3, 60);
	m_messageListCtrl->InsertColumn(4, wxT("DF"));
	m_messageListCtrl->SetColumnWidth(4, 60);
	m_messageListCtrl->InsertColumn(5, wxT("Text"));
	m_messageListCtrl->SetColumnWidth(5, 285);

	sizer->Add(m_messageListCtrl, 0, wxALL, 0);

	SetAutoLayout(true);
	sizer->Fit(this);
	sizer->SetSizeHints(this);
	SetSizer(sizer);
}

CFSK441Display::~CFSK441Display()
{
	delete m_messageList;
}

wxMenu* CFSK441Display::createMessageMenu()
{
	wxMenu* menu = new wxMenu();
	menu->Append(Menu_Messages_Clear, wxT("Clear"));

	return menu;
}

void CFSK441Display::onMessageSelected(const wxListEvent& event)
{
	m_selected = event.GetIndex();
}

void CFSK441Display::onMessageClick(const wxListEvent& event)
{
	wxASSERT(m_messageListCtrl != NULL);

	if (m_selected != -1) {
		wxPoint point = event.GetPoint();
		m_messageListCtrl->PopupMenu(m_messageMenu, point);
	}
}

void CFSK441Display::onClearMessages(const wxCommandEvent& event)
{
	wxASSERT(m_messageListCtrl != NULL);
	wxASSERT(m_messageList != NULL);

	m_messageListCtrl->DeleteAllItems();
	m_messageList->Clear();

	m_listCount = 0;
	m_selected  = -1;
}

void CFSK441Display::showMessage(CFSK441Message* message)
{
	wxASSERT(m_spectrumGraph != NULL);
	wxASSERT(m_messageListCtrl != NULL);
	wxASSERT(message != NULL);
	wxASSERT(m_listCount >= 0);

	wxString id = message->getId();

	int pos = id.Find(wxT('_'), true);
	if (pos != -1) {
		wxString tmp = id.Mid(pos + 1);
		id = tmp;
	}

	m_messageListCtrl->InsertItem(0, id, 0);

	wxString text = message->getText();

	wxString buffer;
	buffer.Printf(wxT("%.1f"), message->getTime());
	m_messageListCtrl->SetItem(0, 1, buffer);

	buffer.Printf(wxT("%d"), message->getLength());
	m_messageListCtrl->SetItem(0, 2, buffer);

	buffer.Printf(wxT("%d"), message->getStrength());
	m_messageListCtrl->SetItem(0, 3, buffer);

	buffer.Printf(wxT("%d"), message->getDF());
	m_messageListCtrl->SetItem(0, 4, buffer);

	m_messageListCtrl->SetItem(0, 5, text);

	::wxGetApp().logMessage(*message);

	m_listCount++;

	pos = 0;
	m_messageList->Insert(pos, message);

	// The list is moving down and the selected message has moved down
	// by one
	if (m_selected != -1)
		m_selected++;
}

void CFSK441Display::showLevels(CFSK441Levels* levels) const
{
	wxASSERT(levels != NULL);
	wxASSERT(m_levelGraph != NULL);

	m_levelGraph->addData(levels);
}

void CFSK441Display::showAudio(double audio) const
{
	wxASSERT(m_audioGraph != NULL);

	m_audioGraph->addData(audio);
}