OpenCPN Partial API docs
Loading...
Searching...
No Matches
rudder_angle.cpp
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 2010 by Jean-Eudes Onfray *
3 * Copyright (C) 2010 by David S. Register *
4 * *
5 * This program 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. *
9 * *
10 * This program 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. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
17 *************************************************************************/
18
25#include "rudder_angle.h"
26
27#include <wx/wxprec.h>
28
29#ifndef WX_PRECOMP
30#include <wx/wx.h>
31#endif
32
33DashboardInstrument_RudderAngle::DashboardInstrument_RudderAngle(
34 wxWindow* parent, wxWindowID id, wxString title,
35 InstrumentProperties* Properties)
36 : DashboardInstrument_Dial(parent, id, title, Properties, OCPN_DBP_STC_RSA,
37 100, 160, -40, +40) {
38 // Default Rudder position is centered
39 m_main_value = 0;
40
41 // SetOptionMainValue("%3.0f Deg", DIAL_POSITION_BOTTOMLEFT);
42 SetOptionMarker(5, DIAL_MARKER_REDGREEN, 2);
43 // Labels are set static because we've no logic to display them this way
44 wxString labels[] = {"40", "30", "20", "10", "0", "10", "20", "30", "40"};
45 SetOptionLabel(10, DIAL_LABEL_HORIZONTAL, wxArrayString(9, labels));
46 // SetOptionExtraValue("%02.0f", DIAL_POSITION_INSIDE);
47}
48
49wxSize DashboardInstrument_RudderAngle::GetSize(int orient, wxSize hint) {
50 InitTitleSize();
51
52 int w;
53 if (orient == wxHORIZONTAL) {
54 w = wxMax(hint.y, (DefaultWidth - m_TitleHeight) / .7);
55 } else {
56 w = wxMax(hint.x, DefaultWidth);
57 }
58 return wxSize(w, m_TitleHeight + w * .7);
59}
60
61void DashboardInstrument_RudderAngle::SetData(DASH_CAP st, double data,
62 wxString unit) {
63 if (st == m_main_value_cap) {
64 // Dial works clockwise but Rudder has negative values for left
65 // and positive for right so we must inverse it.
66 data = -data;
67
68 if (data < m_main_value_min)
69 m_main_value = m_main_value_min;
70 else if (data > m_main_value_max)
71 m_main_value = m_main_value_max;
72 else
73 m_main_value = data;
74 m_main_value_unit = unit;
75 } else if (st == m_extra_value_cap) {
76 m_extra_value = data;
77 m_extra_value_unit = unit;
78 } else
79 return;
80}
81
82void DashboardInstrument_RudderAngle::DrawFrame(wxGCDC* dc) {
83 // We don't need the upper part
84 // Move center up
85 wxSize size = GetClientSize();
86 wxColour cl;
87
88 int drawHeight = GetDataBottom(size.y) - m_DataTop;
89 InitTitleAndDataPosition(drawHeight);
90
91 m_cx = size.x / 2;
92 m_cy = m_DataTop + (drawHeight) * 0.38;
93 m_radius = (drawHeight) * .6;
94
95 dc->SetBrush(*wxTRANSPARENT_BRUSH);
96
97 wxPen pen;
98 pen.SetStyle(wxPENSTYLE_SOLID);
99 pen.SetWidth(2);
100 GetGlobalColor("DASHF", &cl);
101 pen.SetColour(cl);
102 dc->SetPen(pen);
103
104 double angle1 = deg2rad(215); // 305-ANGLE_OFFSET
105 double angle2 = deg2rad(-35); // 55-ANGLE_OFFSET
106 wxCoord x1 = m_cx + (m_radius * cos(angle1));
107 wxCoord y1 = m_cy + (m_radius * sin(angle1));
108 wxCoord x2 = m_cx + (m_radius * cos(angle2));
109 wxCoord y2 = m_cy + (m_radius * sin(angle2));
110 dc->DrawArc(x1, y1, x2, y2, m_cx, m_cy);
111 dc->DrawLine(x1, y1, x2, y2);
112}
113
114void DashboardInstrument_RudderAngle::DrawBackground(wxGCDC* dc) {
115 wxCoord x = m_cx - (m_radius * 0.3);
116 wxCoord y = m_cy - (m_radius * 1.1);
117 wxColour cl;
118 GetGlobalColor("DASH1", &cl);
119 dc->SetBrush(cl);
120 dc->DrawEllipticArc(x, y, m_radius * 0.6, m_radius * 1.4, 0, -180);
121}
DASH_CAP
Definition instrument.h:77
@ OCPN_DBP_STC_RSA
Rudder angle.
Definition instrument.h:96
Dashboard rudder angle instrument.