1
2 ///////////////////////////////////////////////////////////
3 // //
4 // SAGA //
5 // //
6 // System for Automated Geoscientific Analyses //
7 // //
8 // User Interface //
9 // //
10 // Program: SAGA //
11 // //
12 //-------------------------------------------------------//
13 // //
14 // WKSP.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/image.h>
52 #include <wx/imaglist.h>
53
54 #include <saga_api/saga_api.h>
55
56 #include "helper.h"
57
58 #include "res_commands.h"
59 #include "res_controls.h"
60 #include "res_images.h"
61 #include "res_dialogs.h"
62
63 #include "active.h"
64
65 #include "wksp.h"
66
67 #include "wksp_tool_control.h"
68 #include "wksp_tool_manager.h"
69 #include "wksp_tool.h"
70
71 #include "wksp_data_control.h"
72 #include "wksp_data_manager.h"
73 #include "wksp_data_layers.h"
74
75 #include "wksp_map_control.h"
76 #include "wksp_map_manager.h"
77 #include "wksp_map_buttons.h"
78
79
80 ///////////////////////////////////////////////////////////
81 // //
82 // //
83 // //
84 ///////////////////////////////////////////////////////////
85
86 //---------------------------------------------------------
87 enum
88 {
89 IMG_TOOLS = 0,
90 IMG_DATA,
91 IMG_MAPS
92 };
93
94
95 ///////////////////////////////////////////////////////////
96 // //
97 // //
98 // //
99 ///////////////////////////////////////////////////////////
100
101 //---------------------------------------------------------
102 #define SUBNB_CAPTION_TREE _TL("Tree")
103 #define SUBNB_CAPTION_BUTTONS _TL("Thumbnails")
104
105 //---------------------------------------------------------
106 #define SUBNB_CREATE(ID, Name) pNotebook = new wxNotebook(this, ID, wxDefaultPosition, wxDefaultSize, wxNB_TOP|wxNB_MULTILINE, Name);\
107 pNotebook ->AssignImageList(new wxImageList(IMG_SIZE_NOTEBOOK, IMG_SIZE_NOTEBOOK, true, 0));\
108 pNotebook ->IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_WKSP_TREEVIEW);\
109 pNotebook ->IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_WKSP_THUMBNAILS);
110
111
112 ///////////////////////////////////////////////////////////
113 // //
114 // //
115 // //
116 ///////////////////////////////////////////////////////////
117
118 //---------------------------------------------------------
119 CWKSP *g_pWKSP = NULL;
120
121
122 ///////////////////////////////////////////////////////////
123 // //
124 // //
125 // //
126 ///////////////////////////////////////////////////////////
127
128 //---------------------------------------------------------
BEGIN_EVENT_TABLE(CWKSP,wxNotebook)129 BEGIN_EVENT_TABLE(CWKSP, wxNotebook)
130 EVT_NOTEBOOK_PAGE_CHANGING (ID_WND_WKSP, CWKSP::On_Page_Changing)
131 EVT_NOTEBOOK_PAGE_CHANGED (ID_WND_WKSP, CWKSP::On_Page_Changed)
132 END_EVENT_TABLE()
133
134
135 ///////////////////////////////////////////////////////////
136 // //
137 // //
138 // //
139 ///////////////////////////////////////////////////////////
140
141 //---------------------------------------------------------
142 CWKSP::CWKSP(wxWindow *pParent)
143 : wxNotebook(pParent, ID_WND_WKSP, wxDefaultPosition, wxDefaultSize, wxNB_TOP|wxNB_MULTILINE, _TL("Manager"))
144 {
145 wxNotebook *pNotebook;
146
147 //-----------------------------------------------------
148 g_pWKSP = this;
149
150 //-----------------------------------------------------
151 AssignImageList(new wxImageList(IMG_SIZE_NOTEBOOK, IMG_SIZE_NOTEBOOK, true, 0));
152
153 IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_WKSP_TOOLS);
154 IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_WKSP_DATA);
155 IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_WKSP_MAPS);
156
157 //-----------------------------------------------------
158 m_pTools = new CWKSP_Tool_Control(this);
159
160 SUBNB_CREATE(ID_WND_WKSP_DATA, _TL("Data"));
161 m_pData = new CWKSP_Data_Control(pNotebook);
162 m_pData_Buttons = new CWKSP_Data_Buttons(pNotebook);
163
164 SUBNB_CREATE(ID_WND_WKSP_MAPS, _TL("Maps"));
165 m_pMaps = new CWKSP_Map_Control (pNotebook);
166 m_pMaps_Buttons = new CWKSP_Map_Buttons (pNotebook);
167 }
168
169 //---------------------------------------------------------
Add_Pages(void)170 void CWKSP::Add_Pages(void)
171 {
172 long lValue;
173
174 //-----------------------------------------------------
175 AddPage(m_pTools , _TL("Tools"), false, IMG_TOOLS);
176 AddPage(m_pData->GetParent(), _TL("Data" ), false, IMG_DATA );
177 AddPage(m_pMaps->GetParent(), _TL("Maps" ), false, IMG_MAPS );
178
179 if( CONFIG_Read("/DATA", "TAB", lValue) )
180 {
181 SetSelection((size_t)lValue);
182 }
183
184 //-----------------------------------------------------
185 ((wxNotebook *)m_pData->GetParent())->AddPage(m_pData , SUBNB_CAPTION_TREE , false, 0);
186 ((wxNotebook *)m_pData->GetParent())->AddPage(m_pData_Buttons , SUBNB_CAPTION_BUTTONS , false, 1);
187
188 if( CONFIG_Read("/DATA/BUTTONS", "TAB", lValue) )
189 {
190 ((wxNotebook *)m_pData->GetParent())->SetSelection((size_t)lValue);
191 }
192
193 //-----------------------------------------------------
194 ((wxNotebook *)m_pMaps->GetParent())->AddPage(m_pMaps , SUBNB_CAPTION_TREE , false, 0);
195 ((wxNotebook *)m_pMaps->GetParent())->AddPage(m_pMaps_Buttons , SUBNB_CAPTION_BUTTONS , false, 1);
196
197 if( CONFIG_Read("/MAPS/BUTTONS", "TAB", lValue) )
198 {
199 ((wxNotebook *)m_pMaps->GetParent())->SetSelection((size_t)lValue);
200 }
201 }
202
203 //---------------------------------------------------------
~CWKSP(void)204 CWKSP::~CWKSP(void)
205 {
206 CONFIG_Write("/DATA", "TAB", (long)GetSelection());
207
208 CONFIG_Write("/DATA/BUTTONS", "TAB", (long)((wxNotebook *)m_pData->GetParent())->GetSelection());
209 CONFIG_Write("/MAPS/BUTTONS", "TAB", (long)((wxNotebook *)m_pMaps->GetParent())->GetSelection());
210
211 g_pWKSP = NULL;
212 }
213
214
215 ///////////////////////////////////////////////////////////
216 // //
217 ///////////////////////////////////////////////////////////
218
219 //---------------------------------------------------------
On_Page_Changing(wxNotebookEvent & event)220 void CWKSP::On_Page_Changing(wxNotebookEvent &event)
221 {
222 event.Skip();
223 }
224
225 //---------------------------------------------------------
On_Page_Changed(wxNotebookEvent & event)226 void CWKSP::On_Page_Changed(wxNotebookEvent &event)
227 {
228 event.Skip();
229
230 if( event.GetSelection() >= 0 && g_pActive )
231 {
232 CWKSP_Base_Item *pItem = NULL;
233
234 if( GetPage(event.GetSelection()) == m_pTools )
235 {
236 pItem = m_pTools->Get_Item_Selected();
237 }
238 else if( GetPage(event.GetSelection()) == m_pData->GetParent() )
239 {
240 pItem = m_pData->Get_Item_Selected();
241 }
242 else if( GetPage(event.GetSelection()) == m_pMaps->GetParent() )
243 {
244 pItem = m_pMaps->Get_Item_Selected();
245 }
246
247 if( pItem )
248 {
249 g_pActive->Set_Active(pItem);
250 }
251 }
252 }
253
254
255 ///////////////////////////////////////////////////////////
256 // //
257 ///////////////////////////////////////////////////////////
258
259 //---------------------------------------------------------
On_Command(wxCommandEvent & event)260 void CWKSP::On_Command(wxCommandEvent &event)
261 {
262 if( (event.GetId() >= ID_CMD_TABLE_RECENT_FIRST && event.GetId() <= ID_CMD_TABLE_RECENT_LAST )
263 || (event.GetId() >= ID_CMD_SHAPES_RECENT_FIRST && event.GetId() <= ID_CMD_SHAPES_RECENT_LAST )
264 || (event.GetId() >= ID_CMD_POINTCLOUD_RECENT_FIRST && event.GetId() <= ID_CMD_POINTCLOUD_RECENT_LAST )
265 || (event.GetId() >= ID_CMD_TIN_RECENT_FIRST && event.GetId() <= ID_CMD_TIN_RECENT_LAST )
266 || (event.GetId() >= ID_CMD_GRID_RECENT_FIRST && event.GetId() <= ID_CMD_GRID_RECENT_LAST )
267 || (event.GetId() >= ID_CMD_DATA_PROJECT_RECENT_FIRST && event.GetId() <= ID_CMD_DATA_PROJECT_RECENT_LAST) )
268 {
269 m_pData->On_Command(event);
270 }
271 else switch( event.GetId() )
272 {
273 default:
274 if( !g_pActive->Get_Active() || !g_pActive->Get_Active()->On_Command(event.GetId()) )
275 {
276 if( GetCurrentPage() )
277 {
278 switch( GetCurrentPage()->GetId() )
279 {
280 case ID_WND_WKSP_TOOLS: m_pTools->On_Command(event); break;
281 case ID_WND_WKSP_DATA : m_pData ->On_Command(event); break;
282 case ID_WND_WKSP_MAPS : m_pMaps ->On_Command(event); break;
283 }
284 }
285 }
286 break;
287
288 case ID_CMD_WKSP_ITEM_CLOSE:
289 if( GetCurrentPage() )
290 {
291 switch( GetCurrentPage()->GetId() )
292 {
293 case ID_WND_WKSP_TOOLS: m_pTools->On_Command(event); break;
294 case ID_WND_WKSP_DATA : m_pData ->On_Command(event); break;
295 case ID_WND_WKSP_MAPS : m_pMaps ->On_Command(event); break;
296 }
297 }
298 break;
299
300 case ID_CMD_TOOL_OPEN:
301 m_pTools->On_Command(event);
302 break;
303
304 case ID_CMD_TOOL_SEARCH:
305 m_pTools->On_Command(event);
306 break;
307
308 case ID_CMD_DATA_PROJECT_OPEN:
309 case ID_CMD_DATA_PROJECT_OPEN_ADD:
310 case ID_CMD_DATA_PROJECT_NEW:
311 case ID_CMD_DATA_PROJECT_SAVE:
312 case ID_CMD_DATA_PROJECT_SAVE_AS:
313 case ID_CMD_DATA_PROJECT_COPY:
314 case ID_CMD_DATA_PROJECT_COPY_DB:
315 case ID_CMD_DATA_PROJECT_BROWSE:
316 case ID_CMD_TABLE_OPEN:
317 case ID_CMD_SHAPES_OPEN:
318 case ID_CMD_TIN_OPEN:
319 case ID_CMD_POINTCLOUD_OPEN:
320 case ID_CMD_GRID_OPEN:
321 m_pData->On_Command(event);
322 break;
323
324 case ID_CMD_DATA_OPEN:
325 Open();
326 break;
327 }
328 }
329
330 //---------------------------------------------------------
On_Command_UI(wxUpdateUIEvent & event)331 void CWKSP::On_Command_UI(wxUpdateUIEvent &event)
332 {
333 switch( event.GetId() )
334 {
335 default:
336 if( !g_pActive->Get_Active() || !g_pActive->Get_Active()->On_Command_UI(event) )
337 {
338 m_pTools->On_Command_UI(event);
339 m_pData ->On_Command_UI(event);
340 m_pMaps ->On_Command_UI(event);
341 }
342 break;
343
344 case ID_CMD_DATA_PROJECT_NEW:
345 event.Enable(g_pTool == NULL && (
346 m_pData->Get_Manager()->Get_Count() > 0 ||
347 m_pMaps->Get_Manager()->Get_Count() > 0
348 ));
349 break;
350
351 case ID_CMD_WKSP_ITEM_CLOSE:
352 if( GetCurrentPage() )
353 {
354 switch( GetCurrentPage()->GetId() )
355 {
356 case ID_WND_WKSP_TOOLS: m_pTools->On_Command_UI(event); break;
357 case ID_WND_WKSP_DATA : m_pData ->On_Command_UI(event); break;
358 case ID_WND_WKSP_MAPS : m_pMaps ->On_Command_UI(event); break;
359 }
360 }
361 break;
362
363 case ID_CMD_DATA_OPEN:
364 break;
365
366 case ID_CMD_TOOL_SEARCH:
367 m_pTools->On_Command_UI(event);
368 break;
369
370 case ID_CMD_DATA_PROJECT_SAVE:
371 case ID_CMD_DATA_PROJECT_SAVE_AS:
372 case ID_CMD_DATA_PROJECT_COPY:
373 case ID_CMD_DATA_PROJECT_COPY_DB:
374 event.Enable(g_pData->Get_Count() > 0);
375 break;
376 }
377 }
378
379 //---------------------------------------------------------
On_Command_Tool(wxCommandEvent & event)380 void CWKSP::On_Command_Tool(wxCommandEvent &event)
381 {
382 m_pTools->On_Execute(event);
383 }
384
On_Command_UI_Tool(wxUpdateUIEvent & event)385 void CWKSP::On_Command_UI_Tool(wxUpdateUIEvent &event)
386 {
387 m_pTools->On_Execute_UI(event);
388 }
389
390
391 ///////////////////////////////////////////////////////////
392 // //
393 ///////////////////////////////////////////////////////////
394
395 //---------------------------------------------------------
Open(void)396 bool CWKSP::Open(void)
397 {
398 wxArrayString File_Paths;
399
400 if( DLG_Open(File_Paths, ID_DLG_FILE_OPEN) )
401 {
402 MSG_General_Add_Line();
403
404 for(size_t i=0; i<File_Paths.GetCount(); i++)
405 {
406 Open(File_Paths[i]);
407 }
408
409 return( true );
410 }
411
412 return( false );
413 }
414
415 //---------------------------------------------------------
Open(const wxString & File_Name)416 bool CWKSP::Open(const wxString &File_Name)
417 {
418 return( m_pTools->Get_Manager()->Open(File_Name)
419 || m_pData ->Get_Manager()->Open(File_Name)
420 );
421 }
422
423
424 ///////////////////////////////////////////////////////////
425 // //
426 // //
427 // //
428 ///////////////////////////////////////////////////////////
429
430 //---------------------------------------------------------
431