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_Data_Control.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 "res_commands.h"
57 #include "res_controls.h"
58 #include "res_images.h"
59 #include "res_dialogs.h"
60
61 #include "active.h"
62
63 #include "wksp_data_control.h"
64 #include "wksp_data_manager.h"
65 #include "wksp_data_layers.h"
66
67 #include "wksp_table_manager.h"
68 #include "wksp_table.h"
69
70 #include "wksp_shapes_manager.h"
71 #include "wksp_shapes_type.h"
72 #include "wksp_shapes.h"
73
74 #include "wksp_tin_manager.h"
75 #include "wksp_tin.h"
76
77 #include "wksp_grid_manager.h"
78 #include "wksp_grid_system.h"
79 #include "wksp_grid.h"
80
81
82 ///////////////////////////////////////////////////////////
83 // //
84 // //
85 // //
86 ///////////////////////////////////////////////////////////
87
88 //---------------------------------------------------------
89 enum
90 {
91 IMG_DATA_MANAGER = 1,
92 IMG_TABLE_MANAGER,
93 IMG_TABLE,
94 IMG_SHAPES_MANAGER,
95 IMG_SHAPES_POINT,
96 IMG_SHAPES_POINTS,
97 IMG_SHAPES_LINE,
98 IMG_SHAPES_POLYGON,
99 IMG_TIN_MANAGER,
100 IMG_TIN,
101 IMG_POINTCLOUD_MANAGER,
102 IMG_POINTCLOUD,
103 IMG_GRID_MANAGER,
104 IMG_GRID_SYSTEM,
105 IMG_GRID,
106 IMG_GRIDS
107 };
108
109
110 ///////////////////////////////////////////////////////////
111 // //
112 // //
113 // //
114 ///////////////////////////////////////////////////////////
115
116 //---------------------------------------------------------
117 IMPLEMENT_CLASS(CWKSP_Data_Control, CWKSP_Base_Control)
118
119 //---------------------------------------------------------
120 BEGIN_EVENT_TABLE(CWKSP_Data_Control, CWKSP_Base_Control)
121 END_EVENT_TABLE()
122
123
124 ///////////////////////////////////////////////////////////
125 // //
126 // //
127 // //
128 ///////////////////////////////////////////////////////////
129
130 //---------------------------------------------------------
131 CWKSP_Data_Control *g_pData_Ctrl = NULL;
132
133
134 ///////////////////////////////////////////////////////////
135 // //
136 // //
137 // //
138 ///////////////////////////////////////////////////////////
139
140 //---------------------------------------------------------
CWKSP_Data_Control(wxWindow * pParent)141 CWKSP_Data_Control::CWKSP_Data_Control(wxWindow *pParent)
142 : CWKSP_Base_Control(pParent, ID_WND_WKSP_DATA)
143 {
144 g_pData_Ctrl = this;
145
146 SetWindowStyle(wxTR_HAS_BUTTONS|wxTR_MULTIPLE);
147
148 //-----------------------------------------------------
149 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_DATA_MANAGER );
150 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_TABLE_MANAGER );
151 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_TABLE );
152 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_SHAPES_MANAGER );
153 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_SHAPES_POINT );
154 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_SHAPES_POINTS );
155 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_SHAPES_LINE );
156 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_SHAPES_POLYGON );
157 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_TIN_MANAGER );
158 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_TIN );
159 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_POINTCLOUD_MANAGER);
160 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_POINTCLOUD );
161 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_GRID_MANAGER );
162 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_GRID_SYSTEM );
163 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_GRID );
164 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_GRIDS );
165
166 //-----------------------------------------------------
167 _Set_Manager(new CWKSP_Data_Manager);
168 }
169
170 //---------------------------------------------------------
~CWKSP_Data_Control(void)171 CWKSP_Data_Control::~CWKSP_Data_Control(void)
172 {
173 _Del_Item(m_pManager, true);
174
175 g_pData_Ctrl = NULL;
176 }
177
178
179 ///////////////////////////////////////////////////////////
180 // //
181 ///////////////////////////////////////////////////////////
182
183 //---------------------------------------------------------
_Get_Image_ID(CWKSP_Base_Item * pItem)184 inline int CWKSP_Data_Control::_Get_Image_ID(CWKSP_Base_Item *pItem)
185 {
186 if( pItem )
187 {
188 switch( pItem->Get_Type() )
189 {
190 case WKSP_ITEM_Data_Manager : return( IMG_DATA_MANAGER );
191 case WKSP_ITEM_Table_Manager : return( IMG_TABLE_MANAGER );
192 case WKSP_ITEM_Table : return( IMG_TABLE );
193 case WKSP_ITEM_TIN_Manager : return( IMG_TIN_MANAGER );
194 case WKSP_ITEM_TIN : return( IMG_TIN );
195 case WKSP_ITEM_PointCloud_Manager: return( IMG_POINTCLOUD_MANAGER );
196 case WKSP_ITEM_PointCloud : return( IMG_POINTCLOUD );
197 case WKSP_ITEM_Grid_Manager : return( IMG_GRID_MANAGER );
198 case WKSP_ITEM_Grid_System : return( IMG_GRID_SYSTEM );
199 case WKSP_ITEM_Grid : return( IMG_GRID );
200 case WKSP_ITEM_Grids : return( IMG_GRIDS );
201 case WKSP_ITEM_Shapes_Manager : return( IMG_SHAPES_MANAGER );
202 case WKSP_ITEM_Shapes_Type :
203 case WKSP_ITEM_Shapes :
204 switch( pItem->Get_Type() == WKSP_ITEM_Shapes
205 ? ((CWKSP_Shapes *)pItem)->Get_Shapes()->Get_Type()
206 : ((CWKSP_Shapes_Type *)pItem)->Get_Shape_Type() )
207 {
208 case SHAPE_TYPE_Point : return( IMG_SHAPES_POINT );
209 case SHAPE_TYPE_Points : return( IMG_SHAPES_POINTS );
210 case SHAPE_TYPE_Line : return( IMG_SHAPES_LINE );
211 case SHAPE_TYPE_Polygon : return( IMG_SHAPES_POLYGON );
212 default : break;
213 }
214 default : break;
215 }
216 }
217
218 return( 0 );
219 }
220
221 //---------------------------------------------------------
Add_Item(CWKSP_Base_Manager * pManager,CWKSP_Base_Item * pItem)222 void CWKSP_Data_Control::Add_Item(CWKSP_Base_Manager *pManager, CWKSP_Base_Item *pItem)
223 {
224 if( pManager && pItem )
225 {
226 if( pManager == Get_Manager() )
227 {
228 _Add_Item(pItem, _Get_Image_ID(pItem), _Get_Image_ID(pItem), true);
229
230 return;
231 }
232
233 AppendItem (pManager->GetId(), pItem->Get_Name(), _Get_Image_ID(pItem), _Get_Image_ID(pItem), pItem);
234 SortChildren(pManager->GetId());
235 Expand (pManager->GetId());
236
237 //-------------------------------------------------
238 if( g_pData_Buttons )
239 {
240 g_pData_Buttons->Update_Buttons();
241 }
242 }
243 }
244
245
246 ///////////////////////////////////////////////////////////
247 // //
248 ///////////////////////////////////////////////////////////
249
250 //---------------------------------------------------------
Close(bool bSilent)251 bool CWKSP_Data_Control::Close(bool bSilent)
252 {
253 return( _Del_Item(m_pManager, bSilent) );
254 }
255
256
257 ///////////////////////////////////////////////////////////
258 // //
259 ///////////////////////////////////////////////////////////
260
261 //---------------------------------------------------------
Get_Selection_Count(void)262 int CWKSP_Data_Control::Get_Selection_Count(void)
263 {
264 wxArrayTreeItemIds IDs;
265
266 return( GetSelections(IDs) );
267 }
268
269 //---------------------------------------------------------
Get_Item_Selected(bool bUpdate)270 CWKSP_Base_Item * CWKSP_Data_Control::Get_Item_Selected(bool bUpdate)
271 {
272 if( bUpdate )
273 {
274 Get_Manager()->MultiSelect_Check();
275 }
276
277 if( Get_Manager()->MultiSelect_Count() > 0 )
278 {
279 return( Get_Manager() );
280 }
281
282 wxArrayTreeItemIds IDs;
283
284 if( GetSelections(IDs) == 1 )
285 {
286 return( (CWKSP_Base_Item *)GetItemData(IDs[0]) );
287 }
288
289 return( NULL );
290 }
291
292 //---------------------------------------------------------
Set_Item_Selected(CWKSP_Base_Item * pItem,bool bKeepMultipleSelection)293 bool CWKSP_Data_Control::Set_Item_Selected(CWKSP_Base_Item *pItem, bool bKeepMultipleSelection)
294 {
295 if( pItem && pItem->GetId().IsOk() && pItem->Get_Control() == this )
296 {
297 if( bKeepMultipleSelection )
298 {
299 ToggleItemSelection(pItem->GetId());
300
301 g_pActive->Set_Active(Get_Item_Selected());
302 }
303 else
304 {
305 UnselectAll(); SelectItem(pItem->GetId());
306
307 g_pActive->Set_Active(pItem);
308 }
309
310 return( true );
311 }
312
313 return( false );
314 }
315
316 //---------------------------------------------------------
_Del_Active(bool bSilent)317 bool CWKSP_Data_Control::_Del_Active(bool bSilent)
318 {
319 wxArrayTreeItemIds IDs;
320
321 if( GetSelections(IDs) == 0 )
322 {
323 return( true );
324 }
325
326 if( !bSilent && (!DLG_Message_Confirm(ID_DLG_DELETE) || !g_pData->Save_Modified_Sel()) )
327 {
328 return( false );
329 }
330
331 UnselectAll();
332
333 g_pActive->Set_Active(NULL);
334
335 for(size_t i=0; i<IDs.GetCount(); i++)
336 {
337 if( IDs[i].IsOk() )
338 {
339 _Del_Item((CWKSP_Base_Item *)GetItemData(IDs[i]), true);
340 }
341 }
342
343 Get_Manager()->MultiSelect_Check();
344
345 SetFocus();
346
347 return( true );
348 }
349
350
351 ///////////////////////////////////////////////////////////
352 // //
353 // //
354 // //
355 ///////////////////////////////////////////////////////////
356
357 //---------------------------------------------------------
358