OpenCPN Partial API docs
Loading...
Searching...
No Matches
rudder_angle.cpp
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
30// For compilers that support precompilation, includes "wx/wx.h".
31#include <wx/wxprec.h>
32
33#ifdef __BORLANDC__
34#pragma hdrstop
35#endif
36
37// for all others, include the necessary headers (this file is usually all you
38// need because it includes almost all "standard" wxWidgets headers)
39#ifndef WX_PRECOMP
40#include <wx/wx.h>
41#endif
42
43DashboardInstrument_RudderAngle::DashboardInstrument_RudderAngle(
44 wxWindow* parent, wxWindowID id, wxString title,
45 InstrumentProperties* Properties)
46 : DashboardInstrument_Dial(parent, id, title, Properties, OCPN_DBP_STC_RSA,
47 100, 160, -40, +40) {
48 // Default Rudder position is centered
49 m_MainValue = 0;
50
51 // SetOptionMainValue(_T("%3.0f Deg"), DIAL_POSITION_BOTTOMLEFT);
52 SetOptionMarker(5, DIAL_MARKER_REDGREEN, 2);
53 // Labels are set static because we've no logic to display them this way
54 wxString labels[] = {_T("40"), _T("30"), _T("20"), _T("10"), _T("0"),
55 _T("10"), _T("20"), _T("30"), _T("40")};
56 SetOptionLabel(10, DIAL_LABEL_HORIZONTAL, wxArrayString(9, labels));
57 // SetOptionExtraValue(_T("%02.0f"), DIAL_POSITION_INSIDE);
58}
59
60wxSize DashboardInstrument_RudderAngle::GetSize(int orient, wxSize hint) {
61 InitTitleSize();
62
63 int w;
64 if (orient == wxHORIZONTAL) {
65 w = wxMax(hint.y, (DefaultWidth - m_TitleHeight) / .7);
66 } else {
67 w = wxMax(hint.x, DefaultWidth);
68 }
69 return wxSize(w, m_TitleHeight + w * .7);
70}
71
72void DashboardInstrument_RudderAngle::SetData(DASH_CAP st, double data,
73 wxString unit) {
74 if (st == m_MainValueCap) {
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)
80 m_MainValue = m_MainValueMin;
81 else if (data > m_MainValueMax)
82 m_MainValue = m_MainValueMax;
83 else
84 m_MainValue = data;
85 m_MainValueUnit = unit;
86 } else if (st == m_ExtraValueCap) {
87 m_ExtraValue = data;
88 m_ExtraValueUnit = unit;
89 } else
90 return;
91}
92
93void DashboardInstrument_RudderAngle::DrawFrame(wxGCDC* dc) {
94 // We don't need the upper part
95 // Move center up
96 wxSize size = GetClientSize();
97 wxColour cl;
98
99 int drawHeight = GetDataBottom(size.y) - m_DataTop;
100 InitTitleAndDataPosition(drawHeight);
101
102 m_cx = size.x / 2;
103 m_cy = m_DataTop + (drawHeight) * 0.38;
104 m_radius = (drawHeight) * .6;
105
106 dc->SetBrush(*wxTRANSPARENT_BRUSH);
107
108 wxPen pen;
109 pen.SetStyle(wxPENSTYLE_SOLID);
110 pen.SetWidth(2);
111 GetGlobalColor(_T("DASHF"), &cl);
112 pen.SetColour(cl);
113 dc->SetPen(pen);
114
115 double angle1 = deg2rad(215); // 305-ANGLE_OFFSET
116 double angle2 = deg2rad(-35); // 55-ANGLE_OFFSET
117 wxCoord x1 = m_cx + (m_radius * cos(angle1));
118 wxCoord y1 = m_cy + (m_radius * sin(angle1));
119 wxCoord x2 = m_cx + (m_radius * cos(angle2));
120 wxCoord y2 = m_cy + (m_radius * sin(angle2));
121 dc->DrawArc(x1, y1, x2, y2, m_cx, m_cy);
122 dc->DrawLine(x1, y1, x2, y2);
123}
124
125void DashboardInstrument_RudderAngle::DrawBackground(wxGCDC* dc) {
126 wxCoord x = m_cx - (m_radius * 0.3);
127 wxCoord y = m_cy - (m_radius * 1.1);
128 wxColour cl;
129 GetGlobalColor(_T("DASH1"), &cl);
130 dc->SetBrush(cl);
131 dc->DrawEllipticArc(x, y, m_radius * 0.6, m_radius * 1.4, 0, -180);
132}