1 /******************************************************************************
2 * $Id: rudder_angle.cpp, v1.0 2010/08/26 SethDart Exp $
3 *
4 * Project: OpenCPN
5 * Purpose: Dashboard Plugin
6 * Author: Jean-Eudes Onfray
7 *
8 ***************************************************************************
9 * Copyright (C) 2010 by David S. Register *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License for more details. *
20 * *
21 * You should have received a copy of the GNU General Public License *
22 * along with this program; if not, write to the *
23 * Free Software Foundation, Inc., *
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
25 ***************************************************************************
26 */
27
28 #include "rudder_angle.h"
29 #include "wx28compat.h"
30
31 // For compilers that support precompilation, includes "wx/wx.h".
32 #include <wx/wxprec.h>
33
34 #ifdef __BORLANDC__
35 #pragma hdrstop
36 #endif
37
38 // for all others, include the necessary headers (this file is usually all you
39 // need because it includes almost all "standard" wxWidgets headers)
40 #ifndef WX_PRECOMP
41 #include <wx/wx.h>
42 #endif
43
DashboardInstrument_RudderAngle(wxWindow * parent,wxWindowID id,wxString title)44 DashboardInstrument_RudderAngle::DashboardInstrument_RudderAngle( wxWindow *parent, wxWindowID id, wxString title) :
45 DashboardInstrument_Dial( parent, id, title, OCPN_DBP_STC_RSA, 100, 160, -40, +40)
46 {
47 // Default Rudder position is centered
48 m_MainValue = 0;
49
50 //SetOptionMainValue(_T("%3.0f Deg"), DIAL_POSITION_BOTTOMLEFT);
51 SetOptionMarker(5, DIAL_MARKER_REDGREEN, 2);
52 // Labels are set static because we've no logic to display them this way
53 wxString labels[] = {_T("40"), _T("30"), _T("20"), _T("10"), _T("0"), _T("10"), _T("20"), _T("30"), _T("40")};
54 SetOptionLabel(10, DIAL_LABEL_HORIZONTAL, wxArrayString(9, labels));
55 // SetOptionExtraValue(_T("%02.0f"), DIAL_POSITION_INSIDE);
56 }
57
GetSize(int orient,wxSize hint)58 wxSize DashboardInstrument_RudderAngle::GetSize( int orient, wxSize hint )
59 {
60 wxClientDC dc(this);
61 int w;
62 dc.GetTextExtent(m_title, &w, &m_TitleHeight, 0, 0, g_pFontTitle);
63 if( orient == wxHORIZONTAL ) {
64 w = wxMax(hint.y, (DefaultWidth-m_TitleHeight)/.7);
65 } else {
66 w = wxMax(hint.x, DefaultWidth);
67 }
68 return wxSize( w, m_TitleHeight+w*.7 );
69 }
70
SetData(int st,double data,wxString unit)71 void DashboardInstrument_RudderAngle::SetData(int st, double data, wxString unit)
72 {
73 if (st == m_MainValueCap)
74 {
75 // Dial works clockwise but Rudder has negative values for left
76 // and positive for right so we must inverse it.
77 data = -data;
78
79 if (data < m_MainValueMin) m_MainValue = m_MainValueMin;
80 else if (data > m_MainValueMax) m_MainValue = m_MainValueMax;
81 else m_MainValue = data;
82 m_MainValueUnit = unit;
83 }
84 else if (st == m_ExtraValueCap)
85 {
86 m_ExtraValue = data;
87 m_ExtraValueUnit = unit;
88 }
89 else return;
90 }
91
DrawFrame(wxGCDC * dc)92 void DashboardInstrument_RudderAngle::DrawFrame(wxGCDC* dc)
93 {
94 // We don't need the upper part
95 // Move center up
96 wxSize size = GetClientSize();
97 wxColour cl;
98
99 m_cx = size.x / 2;
100 m_cy = m_TitleHeight + (size.y - m_TitleHeight) * 0.38;
101 m_radius = (size.y - m_TitleHeight)*.6;
102
103 dc->SetBrush(*wxTRANSPARENT_BRUSH);
104
105 wxPen pen;
106 pen.SetStyle(wxPENSTYLE_SOLID);
107 pen.SetWidth(2);
108 GetGlobalColor(_T("DASHF"), &cl);
109 pen.SetColour(cl);
110 dc->SetPen(pen);
111
112 double angle1 = deg2rad(215); // 305-ANGLE_OFFSET
113 double angle2 = deg2rad(-35); // 55-ANGLE_OFFSET
114 wxCoord x1 = m_cx + (m_radius * cos(angle1));
115 wxCoord y1 = m_cy + (m_radius * sin(angle1));
116 wxCoord x2 = m_cx + (m_radius * cos(angle2));
117 wxCoord y2 = m_cy + (m_radius * sin(angle2));
118 dc->DrawArc(x1, y1, x2, y2, m_cx, m_cy);
119 dc->DrawLine(x1, y1, x2, y2);
120 }
121
DrawBackground(wxGCDC * dc)122 void DashboardInstrument_RudderAngle::DrawBackground(wxGCDC* dc)
123 {
124 wxCoord x = m_cx - (m_radius * 0.3);
125 wxCoord y = m_cy - (m_radius * 0.5);
126 wxColour cl;
127 GetGlobalColor(_T("DASH1"), &cl);
128 dc->SetBrush( cl );
129 dc->DrawEllipticArc(x, y, m_radius * 0.6, m_radius * 1.4, 0, 180);
130 }
131
132