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[] = {"40", "30", "20", "10", "0", "10", "20", "30", "40"};
55 SetOptionLabel(10, DIAL_LABEL_HORIZONTAL, wxArrayString(9, labels));
56 // SetOptionExtraValue(_T("%02.0f"), DIAL_POSITION_INSIDE);
57}
58
59wxSize DashboardInstrument_RudderAngle::GetSize(int orient, wxSize hint) {
60 InitTitleSize();
61
62 int w;
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
71void DashboardInstrument_RudderAngle::SetData(DASH_CAP st, double data,
72 wxString unit) {
73 if (st == m_MainValueCap) {
74 // Dial works clockwise but Rudder has negative values for left
75 // and positive for right so we must inverse it.
76 data = -data;
77
78 if (data < m_MainValueMin)
79 m_MainValue = m_MainValueMin;
80 else if (data > m_MainValueMax)
81 m_MainValue = m_MainValueMax;
82 else
83 m_MainValue = data;
84 m_MainValueUnit = unit;
85 } else if (st == m_ExtraValueCap) {
86 m_ExtraValue = data;
87 m_ExtraValueUnit = unit;
88 } else
89 return;
90}
91
92void DashboardInstrument_RudderAngle::DrawFrame(wxGCDC* dc) {
93 // We don't need the upper part
94 // Move center up
95 wxSize size = GetClientSize();
96 wxColour cl;
97
98 int drawHeight = GetDataBottom(size.y) - m_DataTop;
99 InitTitleAndDataPosition(drawHeight);
100
101 m_cx = size.x / 2;
102 m_cy = m_DataTop + (drawHeight) * 0.38;
103 m_radius = (drawHeight) * .6;
104
105 dc->SetBrush(*wxTRANSPARENT_BRUSH);
106
107 wxPen pen;
108 pen.SetStyle(wxPENSTYLE_SOLID);
109 pen.SetWidth(2);
110 GetGlobalColor("DASHF", &cl);
111 pen.SetColour(cl);
112 dc->SetPen(pen);
113
114 double angle1 = deg2rad(215); // 305-ANGLE_OFFSET
115 double angle2 = deg2rad(-35); // 55-ANGLE_OFFSET
116 wxCoord x1 = m_cx + (m_radius * cos(angle1));
117 wxCoord y1 = m_cy + (m_radius * sin(angle1));
118 wxCoord x2 = m_cx + (m_radius * cos(angle2));
119 wxCoord y2 = m_cy + (m_radius * sin(angle2));
120 dc->DrawArc(x1, y1, x2, y2, m_cx, m_cy);
121 dc->DrawLine(x1, y1, x2, y2);
122}
123
124void DashboardInstrument_RudderAngle::DrawBackground(wxGCDC* dc) {
125 wxCoord x = m_cx - (m_radius * 0.3);
126 wxCoord y = m_cy - (m_radius * 1.1);
127 wxColour cl;
128 GetGlobalColor("DASH1", &cl);
129 dc->SetBrush(cl);
130 dc->DrawEllipticArc(x, y, m_radius * 0.6, m_radius * 1.4, 0, -180);
131}