1 /**********************************************************
2 * Version $Id$
3 *********************************************************/
4
5 ///////////////////////////////////////////////////////////
6 // //
7 // SAGA //
8 // //
9 // System for Automated Geoscientific Analyses //
10 // //
11 // User Interface //
12 // //
13 // Program: SAGA //
14 // //
15 //-------------------------------------------------------//
16 // //
17 // WKSP_Map_Control.cpp //
18 // //
19 // Copyright (C) 2005 by Olaf Conrad //
20 // //
21 //-------------------------------------------------------//
22 // //
23 // This file is part of 'SAGA - System for Automated //
24 // Geoscientific Analyses'. SAGA is free software; you //
25 // can redistribute it and/or modify it under the terms //
26 // of the GNU General Public License as published by the //
27 // Free Software Foundation, either version 2 of the //
28 // License, or (at your option) any later version. //
29 // //
30 // SAGA is distributed in the hope that it will be //
31 // useful, but WITHOUT ANY WARRANTY; without even the //
32 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
33 // PARTICULAR PURPOSE. See the GNU General Public //
34 // License for more details. //
35 // //
36 // You should have received a copy of the GNU General //
37 // Public License along with this program; if not, see //
38 // <http://www.gnu.org/licenses/>. //
39 // //
40 //-------------------------------------------------------//
41 // //
42 // contact: Olaf Conrad //
43 // Institute of Geography //
44 // University of Goettingen //
45 // Goldschmidtstr. 5 //
46 // 37077 Goettingen //
47 // Germany //
48 // //
49 // e-mail: oconrad@saga-gis.org //
50 // //
51 ///////////////////////////////////////////////////////////
52
53 //---------------------------------------------------------
54
55
56 ///////////////////////////////////////////////////////////
57 // //
58 // //
59 // //
60 ///////////////////////////////////////////////////////////
61
62 //---------------------------------------------------------
63 #include <wx/image.h>
64 #include <wx/imaglist.h>
65
66 #include <saga_api/saga_api.h>
67
68 #include "res_controls.h"
69 #include "res_images.h"
70
71 #include "helper.h"
72
73 #include "wksp_map_control.h"
74 #include "wksp_map_manager.h"
75 #include "wksp_map.h"
76 #include "wksp_map_layer.h"
77 #include "wksp_map_buttons.h"
78
79 #include "wksp_shapes.h"
80
81
82 ///////////////////////////////////////////////////////////
83 // //
84 // //
85 // //
86 ///////////////////////////////////////////////////////////
87
88 //---------------------------------------------------------
89 enum
90 {
91 IMG_MAP_MANAGER = 1,
92 IMG_MAP,
93 IMG_MAP_GRATICULE,
94 IMG_MAP_BASEMAP,
95 IMG_SHAPES_POINT,
96 IMG_SHAPES_POINTS,
97 IMG_SHAPES_LINE,
98 IMG_SHAPES_POLYGON,
99 IMG_TIN,
100 IMG_POINTCLOUD,
101 IMG_GRID,
102 IMG_GRIDS
103 };
104
105
106 ///////////////////////////////////////////////////////////
107 // //
108 // //
109 // //
110 ///////////////////////////////////////////////////////////
111
112 //---------------------------------------------------------
113 IMPLEMENT_CLASS(CWKSP_Map_Control, CWKSP_Base_Control)
114
115 //---------------------------------------------------------
116 BEGIN_EVENT_TABLE(CWKSP_Map_Control, CWKSP_Base_Control)
117 EVT_TREE_BEGIN_DRAG (ID_WND_WKSP_MAPS, CWKSP_Map_Control::On_Drag_Begin)
118 EVT_TREE_END_DRAG (ID_WND_WKSP_MAPS, CWKSP_Map_Control::On_Drag_End)
119 END_EVENT_TABLE()
120
121
122 ///////////////////////////////////////////////////////////
123 // //
124 // //
125 // //
126 ///////////////////////////////////////////////////////////
127
128 //---------------------------------------------------------
129 CWKSP_Map_Control *g_pMap_Ctrl = NULL;
130
131
132 ///////////////////////////////////////////////////////////
133 // //
134 // //
135 // //
136 ///////////////////////////////////////////////////////////
137
138 //---------------------------------------------------------
CWKSP_Map_Control(wxWindow * pParent)139 CWKSP_Map_Control::CWKSP_Map_Control(wxWindow *pParent)
140 : CWKSP_Base_Control(pParent, ID_WND_WKSP_MAPS)
141 {
142 g_pMap_Ctrl = this;
143
144 //-----------------------------------------------------
145 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_MAP_MANAGER );
146 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_MAP );
147 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_MAP_GRATICULE );
148 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_MAP_BASEMAP );
149 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_SHAPES_POINT );
150 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_SHAPES_POINTS );
151 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_SHAPES_LINE );
152 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_SHAPES_POLYGON);
153 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_TIN );
154 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_POINTCLOUD );
155 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_GRID );
156 IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_GRIDS );
157
158 //-----------------------------------------------------
159 _Set_Manager(new CWKSP_Map_Manager);
160 }
161
162 //---------------------------------------------------------
~CWKSP_Map_Control(void)163 CWKSP_Map_Control::~CWKSP_Map_Control(void)
164 {
165 _Del_Item(m_pManager, true);
166
167 g_pMap_Ctrl = NULL;
168 }
169
170
171 ///////////////////////////////////////////////////////////
172 // //
173 // //
174 // //
175 ///////////////////////////////////////////////////////////
176
177 //---------------------------------------------------------
OnCompareItems(const wxTreeItemId & item1,const wxTreeItemId & item2)178 int CWKSP_Map_Control::OnCompareItems(const wxTreeItemId &item1, const wxTreeItemId &item2)
179 {
180 CWKSP_Base_Item *p1, *p2;
181
182 if( (p1 = (CWKSP_Base_Item *)GetItemData(item1)) != NULL && (p1->Get_Type() == WKSP_ITEM_Map_Layer || p1->Get_Type() == WKSP_ITEM_Map_Graticule || p1->Get_Type() == WKSP_ITEM_Map_BaseMap)
183 && (p2 = (CWKSP_Base_Item *)GetItemData(item2)) != NULL && (p2->Get_Type() == WKSP_ITEM_Map_Layer || p2->Get_Type() == WKSP_ITEM_Map_Graticule || p2->Get_Type() == WKSP_ITEM_Map_BaseMap) )
184 {
185 return( p1->Get_Index() - p2->Get_Index() );
186 }
187
188 return( wxTreeCtrl::OnCompareItems(item1, item2) );
189 }
190
191
192 ///////////////////////////////////////////////////////////
193 // //
194 // //
195 // //
196 ///////////////////////////////////////////////////////////
197
198 //---------------------------------------------------------
_Get_Image_ID(CWKSP_Base_Item * pItem)199 inline int CWKSP_Map_Control::_Get_Image_ID(CWKSP_Base_Item *pItem)
200 {
201 if( pItem )
202 {
203 if( pItem->Get_Type() == WKSP_ITEM_Map_Graticule )
204 {
205 return( IMG_MAP_GRATICULE );
206 }
207
208 if( pItem->Get_Type() == WKSP_ITEM_Map_BaseMap )
209 {
210 return( IMG_MAP_BASEMAP );
211 }
212
213 if( pItem->Get_Type() == WKSP_ITEM_Map_Layer )
214 {
215 pItem = ((CWKSP_Map_Layer *)pItem)->Get_Layer();
216
217 switch( pItem->Get_Type() )
218 {
219 case WKSP_ITEM_Grid : return( IMG_GRID );
220 case WKSP_ITEM_Grids : return( IMG_GRIDS );
221 case WKSP_ITEM_TIN : return( IMG_TIN );
222 case WKSP_ITEM_PointCloud : return( IMG_POINTCLOUD );
223 case WKSP_ITEM_Shapes :
224 switch( ((CWKSP_Shapes *)pItem)->Get_Shapes()->Get_Type() )
225 {
226 case SHAPE_TYPE_Point : return( IMG_SHAPES_POINT );
227 case SHAPE_TYPE_Points : return( IMG_SHAPES_POINTS );
228 case SHAPE_TYPE_Line : return( IMG_SHAPES_LINE );
229 case SHAPE_TYPE_Polygon: return( IMG_SHAPES_POLYGON );
230 default: break;
231 }
232 default: break;
233 }
234 }
235 }
236
237 return( 0 );
238 }
239
240 //---------------------------------------------------------
Add_Item(CWKSP_Base_Manager * pManager,CWKSP_Base_Item * pItem)241 void CWKSP_Map_Control::Add_Item(CWKSP_Base_Manager *pManager, CWKSP_Base_Item *pItem)
242 {
243 if( pManager && pItem )
244 {
245 if( pManager == Get_Manager() )
246 {
247 _Add_Item(pItem, IMG_MAP, IMG_MAP);
248
249 return;
250 }
251
252 AppendItem (pManager->GetId(), pItem->Get_Name(), _Get_Image_ID(pItem), _Get_Image_ID(pItem), pItem);
253 SortChildren(pManager->GetId());
254 Expand (pManager->GetId());
255
256 if( g_pMap_Buttons )
257 {
258 g_pMap_Buttons->Update_Buttons();
259 }
260 }
261 }
262
263 //---------------------------------------------------------
Del_Item(CWKSP_Map * pMap,CWKSP_Base_Item * pItem)264 bool CWKSP_Map_Control::Del_Item(CWKSP_Map *pMap, CWKSP_Base_Item *pItem)
265 {
266 if( pMap && pItem )
267 {
268 switch( pItem->Get_Type() )
269 {
270 case WKSP_ITEM_Map_Graticule:
271 case WKSP_ITEM_Map_BaseMap:
272 break;
273
274 case WKSP_ITEM_Map_Layer:
275 pItem = pMap->Get_Map_Layer(((CWKSP_Map_Layer *)pItem)->Get_Layer());
276 break;
277
278 default:
279 pItem = pMap->Get_Map_Layer(((CWKSP_Layer *)pItem));
280 break;
281 }
282
283 bool bRefresh = pMap->Get_Count() > 1;
284
285 if( pItem && _Del_Item(pItem, true) )
286 {
287 if( bRefresh )
288 {
289 pMap->View_Refresh(false);
290 }
291
292 return( true );
293 }
294 }
295
296 return( false );
297 }
298
299
300 ///////////////////////////////////////////////////////////
301 // //
302 // //
303 // //
304 ///////////////////////////////////////////////////////////
305
306 //---------------------------------------------------------
On_Drag_Begin(wxTreeEvent & event)307 void CWKSP_Map_Control::On_Drag_Begin(wxTreeEvent &event)
308 {
309 CWKSP_Base_Item *pItem = (CWKSP_Base_Item *)GetItemData(event.GetItem());
310
311 if( pItem
312 && (pItem->Get_Type() == WKSP_ITEM_Map_Layer
313 || pItem->Get_Type() == WKSP_ITEM_Map_Graticule
314 || pItem->Get_Type() == WKSP_ITEM_Map_BaseMap) )
315 {
316 m_draggedItem = event.GetItem();
317
318 event.Allow();
319 }
320 }
321
322 //---------------------------------------------------------
On_Drag_End(wxTreeEvent & event)323 void CWKSP_Map_Control::On_Drag_End(wxTreeEvent &event)
324 {
325 if( event.GetItem().IsOk()
326 && (((CWKSP_Base_Item *)GetItemData(m_draggedItem))->Get_Type() == WKSP_ITEM_Map_Layer
327 || ((CWKSP_Base_Item *)GetItemData(m_draggedItem))->Get_Type() == WKSP_ITEM_Map_Graticule
328 || ((CWKSP_Base_Item *)GetItemData(m_draggedItem))->Get_Type() == WKSP_ITEM_Map_BaseMap ) )
329 {
330 CWKSP_Map *pDst_Map, *pSrc_Map;
331 CWKSP_Base_Item *pSrc, *pDst, *pCpy;
332
333 pDst = (CWKSP_Base_Item *)GetItemData(event.GetItem());
334 pSrc = (CWKSP_Base_Item *)GetItemData(m_draggedItem);
335 pSrc_Map = (CWKSP_Map *)pSrc->Get_Manager();
336
337 switch( pDst->Get_Type() )
338 {
339 default:
340 pDst_Map = NULL;
341 break;
342
343 case WKSP_ITEM_Map:
344 pDst_Map = (CWKSP_Map *)pDst;
345 pDst = NULL;
346 break;
347
348 case WKSP_ITEM_Map_Layer:
349 case WKSP_ITEM_Map_Graticule:
350 case WKSP_ITEM_Map_BaseMap:
351 pDst_Map = (CWKSP_Map *)pDst->Get_Manager();
352 break;
353 }
354
355 if( pDst_Map )
356 {
357 Freeze();
358
359 if( pDst_Map == pSrc_Map )
360 {
361 pDst_Map->Move_To(pSrc, pDst);
362
363 pDst_Map->View_Refresh(false);
364 }
365 else if( (pCpy = pDst_Map->Add_Copy(pSrc)) != NULL )
366 {
367 pDst_Map->Move_To(pCpy, pDst);
368
369 if( pCpy && !wxGetKeyState(WXK_CONTROL) )
370 {
371 Del_Item(pSrc_Map, pSrc);
372 }
373
374 pDst_Map->View_Refresh(false);
375 }
376
377 Thaw();
378 }
379 }
380
381 m_draggedItem = (wxTreeItemId)0l;
382 }
383
384
385 ///////////////////////////////////////////////////////////
386 // //
387 // //
388 // //
389 ///////////////////////////////////////////////////////////
390
391 //---------------------------------------------------------
Close(bool bSilent)392 bool CWKSP_Map_Control::Close(bool bSilent)
393 {
394 return( _Del_Item(m_pManager, bSilent) );
395 }
396
397
398 ///////////////////////////////////////////////////////////
399 // //
400 // //
401 // //
402 ///////////////////////////////////////////////////////////
403
404 //---------------------------------------------------------
405