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_Map_Manager.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 <saga_api/saga_api.h>
52
53 #include "res_commands.h"
54 #include "res_dialogs.h"
55
56 #include "helper.h"
57
58 #include "wksp_data_manager.h"
59 #include "wksp_map_buttons.h"
60
61 #include "wksp_layer.h"
62
63 #include "wksp_map_control.h"
64 #include "wksp_map_manager.h"
65 #include "wksp_map.h"
66 #include "wksp_map_layer.h"
67
68
69 ///////////////////////////////////////////////////////////
70 // //
71 // //
72 // //
73 ///////////////////////////////////////////////////////////
74
75 //---------------------------------------------------------
76 CWKSP_Map_Manager *g_pMaps = NULL;
77
78
79 ///////////////////////////////////////////////////////////
80 // //
81 // //
82 // //
83 ///////////////////////////////////////////////////////////
84
85 //---------------------------------------------------------
CWKSP_Map_Manager(void)86 CWKSP_Map_Manager::CWKSP_Map_Manager(void)
87 {
88 g_pMaps = this;
89
90 //-----------------------------------------------------
91 m_Parameters.Add_Int("",
92 "THUMBNAIL_SIZE" , _TL("Thumbnail Size"),
93 _TL(""),
94 75, 10, true
95 );
96
97 m_Parameters.Add_Color("THUMBNAIL_SIZE",
98 "THUMBNAIL_SELCOLOR" , _TL("Selection Color"),
99 _TL(""),
100 Get_Color_asInt(SYS_Get_Color(wxSYS_COLOUR_BTNSHADOW))
101 );
102
103 m_Parameters.Add_Bool("",
104 "CACHE" , _TL("Base Map Caching"),
105 _TL("Enables local disk caching for base maps."),
106 false
107 );
108
109 m_Parameters.Add_FilePath("CACHE",
110 "CACHE_DIR" , _TL("Cache Directory"),
111 _TL("If not specified the cache will be created in the current user's temporary directory."),
112 NULL, NULL, false, true
113 );
114
115 m_Parameters.Add_Choice("",
116 "CROSSHAIR" , _TL("Cross Hair"),
117 _TL("Display a cross hair of a map's current mouse position in all maps."),
118 CSG_String::Format("%s|%s|%s",
119 _TL("no"),
120 _TL("yes"),
121 _TL("projected")
122 ), 0
123 );
124
125 //-----------------------------------------------------
126 m_Parameters.Add_Node("", "NODE_DEFAULTS", _TL("Defaults for New Maps"), _TL(""));
127
128 m_Parameters.Add_Bool("NODE_DEFAULTS",
129 "GOTO_NEWLAYER" , _TL("Zoom to added layer"),
130 _TL(""),
131 false
132 );
133
134 m_Parameters.Add_Bool("NODE_DEFAULTS",
135 "CRS_CHECK" , _TL("CRS Check"),
136 _TL("Perform a coordinate system compatibility check before a layer is added."),
137 true
138 );
139
140 m_Parameters.Add_Bool("NODE_DEFAULTS",
141 "SCALE_BAR" , _TL("Scale Bar"),
142 _TL(""),
143 false
144 );
145
146 m_Parameters.Add_Bool("NODE_DEFAULTS",
147 "FRAME_SHOW" , _TL("Frame"),
148 _TL(""),
149 true
150 );
151
152 m_Parameters.Add_Int("FRAME_SHOW",
153 "FRAME_WIDTH" , _TL("Width"),
154 _TL(""),
155 17, 10, true
156 );
157
158 //-----------------------------------------------------
159 m_Parameters.Add_Node("", "NODE_CLIPBOARD", _TL("Clipboard"), _TL(""));
160
161 m_Parameters.Add_Int("NODE_CLIPBOARD",
162 "CLIP_NX" , _TL("Width"),
163 _TL(""),
164 400, 10, true
165 );
166
167 m_Parameters.Add_Int("NODE_CLIPBOARD",
168 "CLIP_NY" , _TL("Height"),
169 _TL(""),
170 400, 10, true
171 );
172
173 m_Parameters.Add_Bool("NODE_CLIPBOARD",
174 "CLIP_FRAME_SHOW" , _TL("Frame"),
175 _TL(""),
176 true
177 );
178
179 m_Parameters.Add_Int("CLIP_FRAME_SHOW",
180 "CLIP_FRAME_WIDTH" , _TL("Width"),
181 _TL(""),
182 17, 0, true
183 );
184
185 //-----------------------------------------------------
186 m_Parameters.Add_Node("NODE_CLIPBOARD", "NODE_CLIP_LEGEND", _TL("Legend"), _TL(""));
187
188 m_Parameters.Add_Double("NODE_CLIP_LEGEND",
189 "CLIP_LEGEND_SCALE", _TL("Scale"),
190 _TL(""),
191 2.0, 1.0, true
192 );
193
194 m_Parameters.Add_Int("NODE_CLIP_LEGEND",
195 "CLIP_LEGEND_FRAME", _TL("Frame Width"),
196 _TL(""),
197 10, 0, true
198 );
199
200 m_Parameters.Add_Color("NODE_CLIP_LEGEND",
201 "CLIP_LEGEND_COLOR", _TL("Border Color"),
202 _TL(""),
203 SG_GET_RGB(0, 0, 0)
204 );
205
206 //-----------------------------------------------------
207 CONFIG_Read("/MAPS", &m_Parameters);
208
209 m_CrossHair = m_Parameters("CROSSHAIR")->asInt();
210 }
211
212 //---------------------------------------------------------
~CWKSP_Map_Manager(void)213 CWKSP_Map_Manager::~CWKSP_Map_Manager(void)
214 {
215 CONFIG_Write("/MAPS", &m_Parameters);
216
217 g_pMaps = NULL;
218 }
219
220
221 ///////////////////////////////////////////////////////////
222 // //
223 ///////////////////////////////////////////////////////////
224
225 //---------------------------------------------------------
Get_Name(void)226 wxString CWKSP_Map_Manager::Get_Name(void)
227 {
228 return( _TL("Maps") );
229 }
230
231 //---------------------------------------------------------
Get_Description(void)232 wxString CWKSP_Map_Manager::Get_Description(void)
233 {
234 wxString s;
235
236 //-----------------------------------------------------
237 s += wxString::Format("<h4>%s</h4>", _TL("Maps"));
238
239 s += "<table border=\"0\">";
240
241 DESC_ADD_INT(_TL("Number of Maps"), Get_Count());
242
243 s += "</table>";
244
245 //-----------------------------------------------------
246 return( s );
247 }
248
249 //---------------------------------------------------------
Get_Menu(void)250 wxMenu * CWKSP_Map_Manager::Get_Menu(void)
251 {
252 if( Get_Count() < 1 )
253 {
254 return( NULL );
255 }
256
257 wxMenu *pMenu = new wxMenu(Get_Name());
258
259 CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE);
260 pMenu->AppendSeparator();
261 CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_SEARCH);
262
263 return( pMenu );
264 }
265
266
267 ///////////////////////////////////////////////////////////
268 // //
269 ///////////////////////////////////////////////////////////
270
271 //---------------------------------------------------------
On_Command(int Cmd_ID)272 bool CWKSP_Map_Manager::On_Command(int Cmd_ID)
273 {
274 switch( Cmd_ID )
275 {
276 default:
277 return( CWKSP_Base_Manager::On_Command(Cmd_ID) );
278
279 case ID_CMD_WKSP_ITEM_RETURN:
280 break;
281 }
282
283 return( true );
284 }
285
286
287 ///////////////////////////////////////////////////////////
288 // //
289 ///////////////////////////////////////////////////////////
290
291 //---------------------------------------------------------
Parameters_Changed(void)292 void CWKSP_Map_Manager::Parameters_Changed(void)
293 {
294 g_pMap_Buttons->Update_Buttons();
295
296 CWKSP_Base_Manager::Parameters_Changed();
297
298 if( m_CrossHair != m_Parameters("CROSSHAIR")->asInt() )
299 {
300 m_CrossHair = m_Parameters("CROSSHAIR")->asInt();
301
302 if( !m_CrossHair )
303 {
304 for(int i=0; i<Get_Count(); i++)
305 {
306 Get_Map(i)->Set_CrossHair_Off();
307 }
308 }
309 }
310 }
311
312
313 ///////////////////////////////////////////////////////////
314 // //
315 ///////////////////////////////////////////////////////////
316
317 //---------------------------------------------------------
Exists(CWKSP_Map * pMap)318 bool CWKSP_Map_Manager::Exists(CWKSP_Map *pMap)
319 {
320 if( pMap )
321 {
322 for(int i=0; i<Get_Count(); i++)
323 {
324 if( pMap == Get_Map(i) )
325 {
326 return( true );
327 }
328 }
329 }
330
331 return( false );
332 }
333
334 //---------------------------------------------------------
Close(bool bSilent)335 bool CWKSP_Map_Manager::Close(bool bSilent)
336 {
337 return( g_pMap_Ctrl->Close(bSilent) );
338 }
339
340 //---------------------------------------------------------
Add(CWKSP_Map * pMap)341 bool CWKSP_Map_Manager::Add(CWKSP_Map *pMap)
342 {
343 if( pMap )
344 {
345 if( !Exists(pMap) )
346 {
347 Add_Item(pMap);
348 }
349
350 return( true );
351 }
352
353 return( false );
354 }
355
Add(CWKSP_Layer * pLayer)356 bool CWKSP_Map_Manager::Add(CWKSP_Layer *pLayer)
357 {
358 int iMap = DLG_Maps_Add();
359
360 if( iMap >= 0 && Add(pLayer, Get_Map(iMap)) )
361 {
362 Get_Map(iMap)->View_Show(true);
363
364 return( true );
365 }
366
367 return( false );
368 }
369
Add(CWKSP_Layer * pLayer,CWKSP_Map * pMap)370 bool CWKSP_Map_Manager::Add(CWKSP_Layer *pLayer, CWKSP_Map *pMap)
371 {
372 if( pLayer )
373 {
374 if( pMap == NULL )
375 {
376 Add_Item(pMap = new CWKSP_Map);
377 }
378 else if( !Exists(pMap) )
379 {
380 Add_Item(pMap);
381 }
382
383 return( pMap->Add_Layer(pLayer) != NULL );
384 }
385
386 return( false );
387 }
388
389 //---------------------------------------------------------
Del(CWKSP_Layer * pLayer)390 bool CWKSP_Map_Manager::Del(CWKSP_Layer *pLayer)
391 {
392 int i, n;
393
394 for(i=Get_Count()-1, n=0; i>=0; i--)
395 {
396 if( g_pMap_Ctrl->Del_Item(Get_Map(i), pLayer) )
397 {
398 n++;
399 }
400 }
401
402 return( n > 0 );
403 }
404
405 //---------------------------------------------------------
Update(CWKSP_Layer * pLayer,bool bMapsOnly)406 bool CWKSP_Map_Manager::Update(CWKSP_Layer *pLayer, bool bMapsOnly)
407 {
408 int i, n;
409
410 for(i=0, n=0; i<Get_Count(); i++)
411 {
412 if( Get_Map(i)->Update(pLayer, bMapsOnly) )
413 {
414 n++;
415 }
416 }
417
418 return( n > 0 );
419 }
420
421
422 ///////////////////////////////////////////////////////////
423 // //
424 ///////////////////////////////////////////////////////////
425
426 //---------------------------------------------------------
Set_Extents(const TSG_Rect & Extent,const CSG_Projection & Projection)427 void CWKSP_Map_Manager::Set_Extents(const TSG_Rect &Extent, const CSG_Projection &Projection)
428 {
429 for(int i=0; i<Get_Count(); i++)
430 {
431 Get_Map(i)->Lock_Synchronising(true);
432 Get_Map(i)->Set_Extent(Extent, Projection);
433 Get_Map(i)->Lock_Synchronising(false);
434 }
435 }
436
437 //---------------------------------------------------------
Set_Mouse_Position(const TSG_Point & Point,const CSG_Projection & Projection)438 void CWKSP_Map_Manager::Set_Mouse_Position(const TSG_Point &Point, const CSG_Projection &Projection)
439 {
440 if( m_CrossHair > 0 )
441 {
442 m_CrossHair *= -1;
443
444 CSG_Projection Invalid;
445
446 for(int i=0; i<Get_Count(); i++)
447 {
448 Get_Map(i)->Set_CrossHair(Point, m_CrossHair == -2 ? Projection : Invalid);
449 }
450
451 m_CrossHair *= -1;
452 }
453 }
454
455 //---------------------------------------------------------
Toggle_CrossHair(void)456 bool CWKSP_Map_Manager::Toggle_CrossHair(void)
457 {
458 m_Parameters("CROSSHAIR")->Set_Value(m_CrossHair = m_CrossHair != 0 ? 0 : 2);
459
460 if( !m_CrossHair )
461 {
462 for(int i=0; i<Get_Count(); i++)
463 {
464 Get_Map(i)->Set_CrossHair_Off();
465 }
466 }
467
468 return( true );
469 }
470
471
472 ///////////////////////////////////////////////////////////
473 // //
474 // //
475 // //
476 ///////////////////////////////////////////////////////////
477
478 //---------------------------------------------------------
479