1
2 ///////////////////////////////////////////////////////////
3 // //
4 // SAGA //
5 // //
6 // System for Automated Geoscientific Analyses //
7 // //
8 // Application Programming Interface //
9 // //
10 // Library: SAGA_GDI //
11 // //
12 //-------------------------------------------------------//
13 // //
14 // sgdi_diagram.cpp //
15 // //
16 // Copyright (C) 2009 by //
17 // Olaf Conrad //
18 // //
19 //-------------------------------------------------------//
20 // //
21 // This file is part of 'SAGA - System for Automated //
22 // Geoscientific Analyses'. SAGA is free software; you //
23 // can redistribute it and/or modify it under the terms //
24 // of the GNU General Public License as published by the //
25 // Free Software Foundation, either version 2 of the //
26 // License, or (at your option) any later version. //
27 // //
28 // SAGA is distributed in the hope that it will be //
29 // useful, but WITHOUT ANY WARRANTY; without even the //
30 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
31 // PARTICULAR PURPOSE. See the GNU General Public //
32 // License for more details. //
33 // //
34 // You should have received a copy of the GNU General //
35 // Public License along with this program; if not, see //
36 // <http://www.gnu.org/licenses/>. //
37 // //
38 //-------------------------------------------------------//
39 // //
40 // e-mail: oconrad@saga-gis.org //
41 // //
42 // contact: Olaf Conrad //
43 // Institute of Geography //
44 // University of Hamburg //
45 // Germany //
46 // //
47 ///////////////////////////////////////////////////////////
48
49 //---------------------------------------------------------
50 #include <wx/wxprec.h>
51 #include <wx/settings.h>
52 #include <wx/dc.h>
53 #include <wx/dcclient.h>
54 #include <wx/dcmemory.h>
55 #include <wx/clipbrd.h>
56
57 //---------------------------------------------------------
58 #include "sgdi_diagram.h"
59 #include "sgdi_helper.h"
60
61
62 ///////////////////////////////////////////////////////////
63 // //
64 // //
65 // //
66 ///////////////////////////////////////////////////////////
67
68 //---------------------------------------------------------
BEGIN_EVENT_TABLE(CSGDI_Diagram,wxPanel)69 BEGIN_EVENT_TABLE(CSGDI_Diagram, wxPanel)
70 EVT_LEFT_DOWN (CSGDI_Diagram::_On_Mouse_Click)
71 EVT_RIGHT_DOWN (CSGDI_Diagram::_On_Mouse_Click)
72 EVT_PAINT (CSGDI_Diagram::_On_Paint)
73 END_EVENT_TABLE()
74
75
76 ///////////////////////////////////////////////////////////
77 // //
78 ///////////////////////////////////////////////////////////
79
80 //---------------------------------------------------------
81 CSGDI_Diagram::CSGDI_Diagram(wxWindow *pParent)
82 : wxPanel(pParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL|wxSUNKEN_BORDER)
83 {
84 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
85
86 m_xName = _TL("X");
87 m_yName = _TL("Y");
88 }
89
90 //---------------------------------------------------------
~CSGDI_Diagram(void)91 CSGDI_Diagram::~CSGDI_Diagram(void)
92 {
93 }
94
95
96 ///////////////////////////////////////////////////////////
97 // //
98 ///////////////////////////////////////////////////////////
99
100 //---------------------------------------------------------
Set_xScale(double Minimum,double Maximum)101 bool CSGDI_Diagram::Set_xScale(double Minimum, double Maximum)
102 {
103 return( false );
104 }
105
106 //---------------------------------------------------------
Set_yScale(double Minimum,double Maximum)107 bool CSGDI_Diagram::Set_yScale(double Minimum, double Maximum)
108 {
109 return( false );
110 }
111
112
113 ///////////////////////////////////////////////////////////
114 // //
115 ///////////////////////////////////////////////////////////
116
117 //---------------------------------------------------------
_On_Mouse_Click(wxMouseEvent & event)118 void CSGDI_Diagram::_On_Mouse_Click(wxMouseEvent &event)
119 {
120 if( event.RightDown() && SG_UI_Dlg_Continue(_TL("Copy to Clipboard"), _TL("Variogram")) )
121 {
122 wxBitmap BMP(GetSize());
123 wxMemoryDC dc;
124
125 dc.SelectObject(BMP);
126 dc.SetBackground(*wxWHITE_BRUSH);
127 dc.Clear();
128
129 _Draw(dc);
130
131 dc.SelectObject(wxNullBitmap);
132
133 if( wxTheClipboard->Open() )
134 {
135 wxBitmapDataObject *pBMP = new wxBitmapDataObject;
136 pBMP->SetBitmap(BMP);
137 wxTheClipboard->SetData(pBMP);
138 wxTheClipboard->Close();
139 }
140 }
141 }
142
143 //---------------------------------------------------------
_On_Paint(wxPaintEvent & WXUNUSED (event))144 void CSGDI_Diagram::_On_Paint(wxPaintEvent &WXUNUSED(event))
145 {
146 wxPaintDC dc(this);
147
148 _Draw(dc);
149 }
150
151
152 ///////////////////////////////////////////////////////////
153 // //
154 ///////////////////////////////////////////////////////////
155
156 //---------------------------------------------------------
157 #define RULER_LABEL_HEIGHT 20
158
159 //---------------------------------------------------------
_Draw(wxDC & dc)160 bool CSGDI_Diagram::_Draw(wxDC &dc)
161 {
162 if( m_xMin < m_xMax && m_yMin < m_yMax )
163 {
164 double dx, dy;
165
166 m_rDiagram = wxRect(RULER_LABEL_HEIGHT, 0, GetClientSize().x - RULER_LABEL_HEIGHT, GetClientSize().y - RULER_LABEL_HEIGHT);
167
168 dc.SetTextForeground(wxColour(0, 0, 0));
169 dc.SetFont(wxFont((int)(0.5 * RULER_LABEL_HEIGHT), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
170
171 Draw_Text(dc, TEXTALIGN_TOPCENTER , 0, m_rDiagram.GetY() + m_rDiagram.GetHeight() / 2, 90, m_yName);
172 Draw_Text(dc, TEXTALIGN_BOTTOMCENTER, m_rDiagram.GetX() + m_rDiagram.GetWidth() / 2, GetClientSize().y, m_xName);
173
174 Draw_Ruler(dc, m_rDiagram, true , m_xMin, m_xMax);
175 Draw_Ruler(dc, m_rDiagram, false, m_yMin, m_yMax);
176
177 //---------------------------------------------------------------------
178 dx = m_rDiagram.GetWidth() / (m_xMax - m_xMin);
179 dy = m_rDiagram.GetHeight() / (m_yMax - m_yMin);
180
181 On_Draw(dc, m_rDiagram);
182
183 return( true );
184 }
185
186 dc.DrawLine(0, 0, GetClientSize().x, GetClientSize().y);
187 dc.DrawLine(0, GetClientSize().y, GetClientSize().x, 0);
188
189 return( false );
190 }
191
192 //---------------------------------------------------------
193 #define DIAGRAM_BUFFER 100
194
195 //---------------------------------------------------------
Get_xToScreen(double x,bool bKeepInRange)196 int CSGDI_Diagram::Get_xToScreen(double x, bool bKeepInRange)
197 {
198 int i = m_rDiagram.GetX() + (int)(m_rDiagram.GetWidth () * (x - m_xMin) / (m_xMax - m_xMin));
199
200 if( bKeepInRange )
201 {
202 if( i < m_rDiagram.GetLeft () - DIAGRAM_BUFFER )
203 i = m_rDiagram.GetLeft () - DIAGRAM_BUFFER;
204 else if( i > m_rDiagram.GetRight () + DIAGRAM_BUFFER )
205 i = m_rDiagram.GetRight () + DIAGRAM_BUFFER;
206 }
207
208 return( i );
209 }
210
211 //---------------------------------------------------------
Get_yToScreen(double y,bool bKeepInRange)212 int CSGDI_Diagram::Get_yToScreen(double y, bool bKeepInRange)
213 {
214 int i = m_rDiagram.GetY() - (int)(m_rDiagram.GetHeight() * (y - m_yMin) / (m_yMax - m_yMin)) + m_rDiagram.GetHeight();
215
216 if( bKeepInRange )
217 {
218 if( i < m_rDiagram.GetTop () - DIAGRAM_BUFFER )
219 i = m_rDiagram.GetTop () - DIAGRAM_BUFFER;
220 else if( i > m_rDiagram.GetBottom() + DIAGRAM_BUFFER )
221 i = m_rDiagram.GetBottom() + DIAGRAM_BUFFER;
222 }
223
224 return( i );
225 }
226
227 //---------------------------------------------------------
Get_ToScreen(wxPoint & Point,double x,double y)228 bool CSGDI_Diagram::Get_ToScreen(wxPoint &Point, double x, double y)
229 {
230 bool bResult = true;
231
232 Point.x = Get_xToScreen(x, false);
233
234 if( Point.x < m_rDiagram.GetLeft () - DIAGRAM_BUFFER )
235 {
236 Point.x = m_rDiagram.GetLeft () - DIAGRAM_BUFFER;
237 bResult = false;
238 }
239 else if( Point.x > m_rDiagram.GetRight () + DIAGRAM_BUFFER )
240 {
241 Point.x = m_rDiagram.GetRight () + DIAGRAM_BUFFER;
242 bResult = false;
243 }
244
245 Point.y = Get_yToScreen(y, false);
246
247 if( Point.y < m_rDiagram.GetTop () - DIAGRAM_BUFFER )
248 {
249 Point.y = m_rDiagram.GetTop () - DIAGRAM_BUFFER;
250 bResult = false;
251 }
252 else if( Point.y > m_rDiagram.GetBottom() + DIAGRAM_BUFFER )
253 {
254 Point.y = m_rDiagram.GetBottom() + DIAGRAM_BUFFER;
255 bResult = false;
256 }
257
258 return( bResult );
259 }
260
261
262 ///////////////////////////////////////////////////////////
263 // //
264 // //
265 // //
266 ///////////////////////////////////////////////////////////
267
268 //---------------------------------------------------------
269