Updated FSF address in all files. Fixes ticket:51
[debian/gnuradio] / ezdop / src / host / hunter / src / tactical.cc
1 /*
2  Copyright 2006 Johnathan Corgan.
3  
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License version 2
6  as published by the Free Software Foundation.
7  
8  This software is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  GNU General Public License for more details.
12  
13  You should have received a copy of the GNU General Public License
14  along with GNU Radio; see the file COPYING.  If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street,
16  Boston, MA 02110-1301, USA.
17 */
18
19 // Application level includes
20 #include "tactical.h"
21
22 // wxWidgets includes
23 #include <wx/dc.h>
24 #include <wx/dcclient.h>
25 #include <wx/log.h>
26
27 // System level includes
28 #include <cmath>
29
30 // Event table for TacticalPanel
31 BEGIN_EVENT_TABLE(TacticalPanel, wxPanel)
32     EVT_PAINT(TacticalPanel::OnPaint)
33     EVT_SIZE(TacticalPanel::OnSize)
34 END_EVENT_TABLE()
35
36 TacticalPanel::TacticalPanel(wxWindow *parent) :
37 wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize)
38 {
39     m_orientation = TrackUp;
40     m_display_doppler = false;
41     m_display_known = false;
42     m_display_estimated = false;
43     
44         m_heading = 0.0;
45         m_doppler_bearing = -1.0;
46     m_estimated_bearing = -1.0;
47     m_actual_bearing = -1.0;
48     
49         SetBackgroundColour(*wxBLACK);
50 }
51
52 void TacticalPanel::OnPaint(wxPaintEvent &event)
53 {
54     wxPaintDC dc(this);
55         drawPanel(dc);
56 }
57
58 void TacticalPanel::drawPanel(wxDC &dc)
59 {
60     float radians;
61     float brg = 0;
62     
63     // Draw circle
64         dc.SetPen(wxPen(*wxRED, 2, wxSOLID));
65         dc.SetBrush(wxBrush(*wxBLACK, wxTRANSPARENT));
66     dc.DrawCircle(m_center, m_radius);
67
68     // Calculate end of doppler bearing line
69     // Doppler bearings are relative and must be adjusted for north up display
70     wxPoint doppler_tip = m_center;
71     if (m_doppler_bearing >= 0.0) {
72         brg = m_doppler_bearing;
73         if (m_orientation == NorthUp) {
74             brg += m_heading;
75             if (brg >= 360.0)
76                 brg -= 360.0;
77         }
78         radians = brg*M_PI/180.0;
79         doppler_tip = wxPoint((int)(m_center.x+sin(radians)*m_radius*0.95),
80                       (int)(m_height-(m_center.y+cos(radians)*m_radius*0.95)));
81     }
82         
83     // Calculate end of actual bearing line
84     // Actual bearings are absolute and must be adjusted for track up display
85     wxPoint actual_tip = m_center;
86     if (m_actual_bearing >= 0.0) {
87         brg = m_actual_bearing;
88         if (m_orientation == TrackUp) {
89             brg -= m_heading;
90             if (brg < 0.0)
91                 brg += 360.0;
92         }
93         radians = brg*M_PI/180.0;
94         actual_tip = wxPoint((int)(m_center.x+sin(radians)*m_radius*0.95),
95                      (int)(m_height-(m_center.y+cos(radians)*m_radius*0.95)));
96     }
97
98     // Calculate end of estimated bearing line
99     // Estimated bearings are absolute and must be adjusted for track up display
100     wxPoint estimated_tip = m_center;
101     if (m_estimated_bearing >= 0.0) {
102         brg = m_estimated_bearing;
103         if (m_orientation == TrackUp) {
104             brg -= m_heading;
105             if (brg < 0.0)
106                 brg += 360.0;
107         }
108         radians = brg*M_PI/180.0;
109         estimated_tip = wxPoint((int)(m_center.x+sin(radians)*m_radius*0.95),
110                      (int)(m_height-(m_center.y+cos(radians)*m_radius*0.95)));
111     }
112
113     if (m_display_known) {
114         dc.SetPen(wxPen(*wxBLUE, 10, wxSOLID));
115         dc.DrawLine(m_center, actual_tip);
116     }
117     
118     if (m_display_estimated) {
119         dc.SetPen(wxPen(*wxWHITE, 10, wxSOLID));
120         dc.DrawLine(m_center, estimated_tip);
121         }
122
123     if (m_display_doppler) {
124         dc.SetPen(wxPen(*wxGREEN, 10, wxSOLID));
125         dc.DrawLine(m_center, doppler_tip);
126     }
127 }
128
129 void TacticalPanel::OnSize(wxSizeEvent &event)
130 {
131     GetClientSize(&m_width, &m_height);
132     m_center = wxPoint(m_width/2, m_height/2);
133
134         // Circle at 95% of window size
135     if (m_width > m_height)
136         m_radius = m_height/2;
137     else
138         m_radius = m_width/2;
139     m_radius = (int)(m_radius*0.95);
140         
141     Refresh();
142 }