1
2 ///////////////////////////////////////////////////////////
3 // //
4 // SAGA //
5 // //
6 // System for Automated Geoscientific Analyses //
7 // //
8 // User Interface //
9 // //
10 // Program: SAGA //
11 // //
12 //-------------------------------------------------------//
13 // //
14 // ACTIVE_Parameters.cpp //
15 // //
16 // Copyright (C) 2005 by Olaf Conrad //
17 // //
18 //-------------------------------------------------------//
19 // //
20 // This file is part of 'SAGA - System for Automated //
21 // Geoscientific Analyses'. SAGA is free software; you //
22 // can redistribute it and/or modify it under the terms //
23 // of the GNU General Public License as published by the //
24 // Free Software Foundation, either version 2 of the //
25 // License, or (at your option) any later version. //
26 // //
27 // SAGA is distributed in the hope that it will be //
28 // useful, but WITHOUT ANY WARRANTY; without even the //
29 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
30 // PARTICULAR PURPOSE. See the GNU General Public //
31 // License for more details. //
32 // //
33 // You should have received a copy of the GNU General //
34 // Public License along with this program; if not, see //
35 // <http://www.gnu.org/licenses/>. //
36 // //
37 //-------------------------------------------------------//
38 // //
39 // contact: Olaf Conrad //
40 // Institute of Geography //
41 // University of Goettingen //
42 // Goldschmidtstr. 5 //
43 // 37077 Goettingen //
44 // Germany //
45 // //
46 // e-mail: oconrad@saga-gis.org //
47 // //
48 ///////////////////////////////////////////////////////////
49
50 //---------------------------------------------------------
51 #include <wx/event.h>
52 #include <wx/button.h>
53
54 #include "res_controls.h"
55
56 #include "wksp_layer.h"
57 #include "wksp_tool.h"
58 #include "wksp_map_manager.h"
59
60 #include "parameters_control.h"
61
62 #include "active_parameters.h"
63
64
65 ///////////////////////////////////////////////////////////
66 // //
67 // //
68 // //
69 ///////////////////////////////////////////////////////////
70
71 //---------------------------------------------------------
IMPLEMENT_CLASS(CActive_Parameters,wxPanel)72 IMPLEMENT_CLASS(CActive_Parameters, wxPanel)
73
74 //---------------------------------------------------------
75 BEGIN_EVENT_TABLE(CActive_Parameters, wxPanel)
76 EVT_SIZE (CActive_Parameters::On_Size)
77 EVT_KEY_DOWN (CActive_Parameters::On_Key)
78
79 EVT_BUTTON (ID_BTN_APPLY , CActive_Parameters::On_Apply)
80 EVT_UPDATE_UI (ID_BTN_APPLY , CActive_Parameters::On_Apply_UI)
81 EVT_BUTTON (ID_BTN_RESTORE, CActive_Parameters::On_Restore)
82 EVT_UPDATE_UI (ID_BTN_RESTORE, CActive_Parameters::On_Restore_UI)
83
84 EVT_BUTTON (ID_BTN_EXECUTE, CActive_Parameters::On_Execute)
85 EVT_BUTTON (ID_BTN_LOAD , CActive_Parameters::On_Load)
86 EVT_BUTTON (ID_BTN_SAVE , CActive_Parameters::On_Save)
87 END_EVENT_TABLE()
88
89
90 ///////////////////////////////////////////////////////////
91 // //
92 ///////////////////////////////////////////////////////////
93
94 //---------------------------------------------------------
95 CActive_Parameters::CActive_Parameters(wxWindow *pParent)
96 : wxPanel(pParent, ID_WND_ACTIVE_PARAMETERS, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE|wxTAB_TRAVERSAL)
97 {
98 m_pItem = NULL;
99 m_pControl = new CParameters_Control(this);
100
101 //-----------------------------------------------------
102 m_Btn_Apply = new wxButton(this, ID_BTN_APPLY , CTRL_Get_Name(ID_BTN_APPLY ), wxPoint(0, 0));
103 m_Btn_Restore = new wxButton(this, ID_BTN_RESTORE, CTRL_Get_Name(ID_BTN_RESTORE), wxPoint(0, 0));
104 m_Btn_Execute = new wxButton(this, ID_BTN_EXECUTE, CTRL_Get_Name(ID_BTN_EXECUTE), wxPoint(0, 0));
105 m_Btn_Load = new wxButton(this, ID_BTN_LOAD , CTRL_Get_Name(ID_BTN_LOAD ), wxPoint(0, 0));
106 m_Btn_Save = new wxButton(this, ID_BTN_SAVE , CTRL_Get_Name(ID_BTN_SAVE ), wxPoint(0, 0));
107
108 m_Btn_Apply ->Show(false);
109 m_Btn_Restore ->Show(false);
110 m_Btn_Execute ->Show(false);
111 m_Btn_Load ->Show(false);
112 m_Btn_Save ->Show(false);
113
114 m_btn_height = m_Btn_Apply->GetDefaultSize().y;
115
116 m_pControl->Set_Parameters(NULL);
117
118 Set_Parameters(NULL);
119 }
120
121 //---------------------------------------------------------
~CActive_Parameters(void)122 CActive_Parameters::~CActive_Parameters(void)
123 {}
124
125
126 ///////////////////////////////////////////////////////////
127 // //
128 ///////////////////////////////////////////////////////////
129
130 //---------------------------------------------------------
On_Size(wxSizeEvent & event)131 void CActive_Parameters::On_Size(wxSizeEvent &event)
132 {
133 _Set_Positions();
134
135 event.Skip();
136 }
137
138 //---------------------------------------------------------
_Set_Positions(void)139 void CActive_Parameters::_Set_Positions(void)
140 {
141 int nButtons = (m_Btn_Apply ->IsShown() ? 1 : 0)
142 + (m_Btn_Restore->IsShown() ? 1 : 0)
143 + (m_Btn_Execute->IsShown() ? 1 : 0)
144 + (m_Btn_Load ->IsShown() ? 1 : 0)
145 + (m_Btn_Save ->IsShown() ? 1 : 0);
146
147 wxRect r(GetClientRect());
148
149 if( nButtons > 0 )
150 {
151 #define BUTTON_DIST 1
152
153 m_pControl->SetSize(r.GetTop(), r.GetLeft(), r.GetWidth(), r.GetHeight() - (m_btn_height + 4 * BUTTON_DIST));
154
155 r = wxRect(
156 r.GetLeft () + BUTTON_DIST,
157 r.GetBottom() - m_btn_height,
158 r.GetWidth () / nButtons - 2 * BUTTON_DIST,
159 m_btn_height
160 );
161
162 #define SET_BTN_POS(BTN) if( BTN->IsShown() ) { BTN->SetSize(r); r.SetLeft(r.GetLeft() + r.GetWidth() + 2 * BUTTON_DIST); }
163
164 SET_BTN_POS(m_Btn_Apply );
165 SET_BTN_POS(m_Btn_Restore);
166 SET_BTN_POS(m_Btn_Execute);
167 SET_BTN_POS(m_Btn_Load );
168 SET_BTN_POS(m_Btn_Save );
169 }
170 else
171 {
172 m_pControl->SetSize(r);
173 }
174 }
175
176
177 ///////////////////////////////////////////////////////////
178 // //
179 ///////////////////////////////////////////////////////////
180
181 //---------------------------------------------------------
On_Key(wxKeyEvent & event)182 void CActive_Parameters::On_Key(wxKeyEvent &event)
183 {
184 if( event.GetKeyCode() == WXK_RETURN && m_pItem )
185 {
186 if( m_pControl->is_Modified() )
187 {
188 Update_Parameters(m_pItem->Get_Parameters(), true);
189 }
190 else if( m_pItem->Get_Type() == WKSP_ITEM_Tool )
191 {
192 m_pControl->Save_Changes(true);
193
194 ((CWKSP_Tool *)m_pItem)->Execute(false);
195 }
196 }
197
198 event.Skip();
199 }
200
201 //---------------------------------------------------------
On_Apply(wxCommandEvent & event)202 void CActive_Parameters::On_Apply(wxCommandEvent &event)
203 {
204 if( m_pItem )
205 {
206 Update_Parameters(m_pItem->Get_Parameters(), true);
207 }
208 }
209
On_Apply_UI(wxUpdateUIEvent & event)210 void CActive_Parameters::On_Apply_UI(wxUpdateUIEvent &event)
211 {
212 event.Enable(m_pControl->is_Modified());
213 }
214
215 //---------------------------------------------------------
On_Restore(wxCommandEvent & event)216 void CActive_Parameters::On_Restore(wxCommandEvent &event)
217 {
218 Restore_Parameters();
219 }
220
On_Restore_UI(wxUpdateUIEvent & event)221 void CActive_Parameters::On_Restore_UI(wxUpdateUIEvent &event)
222 {
223 event.Enable(m_pControl->is_Modified());
224 }
225
226 //---------------------------------------------------------
On_Execute(wxCommandEvent & event)227 void CActive_Parameters::On_Execute(wxCommandEvent &event)
228 {
229 if( m_pItem && m_pItem->Get_Type() == WKSP_ITEM_Tool )
230 {
231 m_pControl->Save_Changes(true);
232
233 ((CWKSP_Tool *)m_pItem)->Execute(false);
234 }
235 }
236
237 //---------------------------------------------------------
On_Load(wxCommandEvent & event)238 void CActive_Parameters::On_Load(wxCommandEvent &event)
239 {
240 m_pControl->Load();
241 }
242
243 //---------------------------------------------------------
On_Save(wxCommandEvent & event)244 void CActive_Parameters::On_Save(wxCommandEvent &event)
245 {
246 m_pControl->Save();
247 }
248
249
250 ///////////////////////////////////////////////////////////
251 // //
252 ///////////////////////////////////////////////////////////
253
254 //---------------------------------------------------------
Set_Parameters(CWKSP_Base_Item * pItem)255 bool CActive_Parameters::Set_Parameters(CWKSP_Base_Item *pItem)
256 {
257 if( m_pItem && m_pControl->Save_Changes(false) )
258 {
259 m_pItem->Parameters_Changed();
260
261 switch( m_pItem->Get_Type() )
262 {
263 case WKSP_ITEM_Shapes :
264 case WKSP_ITEM_TIN :
265 case WKSP_ITEM_PointCloud:
266 case WKSP_ITEM_Grid :
267 case WKSP_ITEM_Grids :
268 g_pMaps->Update((CWKSP_Layer *)m_pItem, false);
269 break;
270
271 default:
272 break;
273 }
274 }
275
276 //-----------------------------------------------------
277 if( m_pItem != pItem )
278 {
279 m_pItem = pItem;
280
281 Freeze();
282
283 if( m_pItem && m_pItem->Get_Parameters() )
284 {
285 m_pControl->Set_Parameters(m_pItem->Get_Parameters());
286
287 m_Btn_Apply ->Show(true);
288 m_Btn_Restore->Show(true);
289 m_Btn_Execute->Show(m_pItem->Get_Type() == WKSP_ITEM_Tool);
290 m_Btn_Load ->Show(true);
291 m_Btn_Save ->Show(true);
292 }
293 else
294 {
295 m_pControl->Set_Parameters(NULL);
296
297 m_Btn_Apply ->Show(false);
298 m_Btn_Restore->Show(false);
299 m_Btn_Execute->Show(false);
300 m_Btn_Load ->Show(false);
301 m_Btn_Save ->Show(false);
302 }
303
304 if( m_pItem )
305 {
306 _Set_Positions();
307 }
308
309 Update();
310
311 Thaw();
312 }
313
314 return( true );
315 }
316
317 //---------------------------------------------------------
Update_Parameters(CSG_Parameters * pParameters,bool bSave)318 bool CActive_Parameters::Update_Parameters(CSG_Parameters *pParameters, bool bSave)
319 {
320 if( pParameters && m_pItem && (m_pItem->Get_Parameters() == pParameters || m_pControl->Get_Parameters() == pParameters) )
321 {
322 CWKSP_Base_Item *pItem = m_pItem; m_pItem = NULL;
323
324 if( bSave )
325 {
326 m_pControl->Save_Changes(true);
327
328 pItem->Parameters_Changed();
329 }
330 else
331 {
332 m_pControl->Set_Parameters(pParameters);
333 }
334
335 m_pItem = pItem;
336
337 return( true );
338 }
339
340 return( false );
341 }
342
343 //---------------------------------------------------------
Update_DataObjects(void)344 bool CActive_Parameters::Update_DataObjects(void)
345 {
346 return( m_pControl->Update_DataObjects() );
347 }
348
349 //---------------------------------------------------------
Restore_Parameters(void)350 bool CActive_Parameters::Restore_Parameters(void)
351 {
352 return( m_pControl->Restore() );
353 }
354
355
356 ///////////////////////////////////////////////////////////
357 // //
358 // //
359 // //
360 ///////////////////////////////////////////////////////////
361
362 //---------------------------------------------------------
363