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.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/wx.h>
52 #include <wx/treectrl.h>
53 #include <wx/imaglist.h>
54
55 #include <saga_api/saga_api.h>
56
57 #include "res_controls.h"
58 #include "res_images.h"
59
60 #include "helper.h"
61
62 #include "data_source.h"
63
64 #include "saga_frame.h"
65
66 #include "active.h"
67 #include "active_parameters.h"
68 #include "active_description.h"
69 #include "active_history.h"
70 #include "active_legend.h"
71 #include "active_attributes.h"
72 #include "active_info.h"
73
74 #include "wksp_tool.h"
75
76 #include "wksp_data_manager.h"
77 #include "wksp_data_layers.h"
78 #include "wksp_map_buttons.h"
79
80 #include "wksp_layer.h"
81 #include "wksp_shapes.h"
82 #include "wksp_map_layer.h"
83
84
85 ///////////////////////////////////////////////////////////
86 // //
87 // //
88 // //
89 ///////////////////////////////////////////////////////////
90
91 //---------------------------------------------------------
92 // #define ACTIVE_SHOW_ALL_PAGES
93
94
95 ///////////////////////////////////////////////////////////
96 // //
97 // //
98 // //
99 ///////////////////////////////////////////////////////////
100
101 //---------------------------------------------------------
102 enum
103 {
104 IMG_PARAMETERS = 0,
105 IMG_DESCRIPTION,
106 IMG_HISTORY,
107 IMG_LEGEND,
108 IMG_ATTRIBUTES,
109 IMG_INFO
110 };
111
112
113 ///////////////////////////////////////////////////////////
114 // //
115 // //
116 // //
117 ///////////////////////////////////////////////////////////
118
119 //---------------------------------------------------------
120 CActive *g_pActive = NULL;
121
122
123 ///////////////////////////////////////////////////////////
124 // //
125 // //
126 // //
127 ///////////////////////////////////////////////////////////
128
129 //---------------------------------------------------------
BEGIN_EVENT_TABLE(CActive,wxNotebook)130 BEGIN_EVENT_TABLE(CActive, wxNotebook)
131 END_EVENT_TABLE()
132
133
134 ///////////////////////////////////////////////////////////
135 // //
136 ///////////////////////////////////////////////////////////
137
138 //---------------------------------------------------------
139 CActive::CActive(wxWindow *pParent)
140 : wxNotebook(pParent, ID_WND_ACTIVE, wxDefaultPosition, wxDefaultSize, wxNB_TOP|wxNB_MULTILINE, _TL("Properties"))
141 {
142 g_pActive = this;
143
144 m_pItem = NULL;
145
146 //-----------------------------------------------------
147 AssignImageList(new wxImageList(IMG_SIZE_NOTEBOOK, IMG_SIZE_NOTEBOOK, true, 0));
148
149 IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_ACTIVE_PARAMETERS );
150 IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_ACTIVE_DESCRIPTION);
151 IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_ACTIVE_HISTORY );
152 IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_ACTIVE_LEGEND );
153 IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_ACTIVE_ATTRIBUTES );
154 IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_ACTIVE_INFO );
155
156 //-----------------------------------------------------
157 m_pParameters = new CActive_Parameters (this); m_pParameters ->SetName(_TL("Settings" ));
158 m_pDescription = new CActive_Description(this); m_pDescription->SetName(_TL("Description"));
159 m_pHistory = new CActive_History (this); m_pHistory ->SetName(_TL("History" ));
160 m_pLegend = new CActive_Legend (this); m_pLegend ->SetName(_TL("Legend" ));
161 m_pAttributes = new CActive_Attributes (this); m_pAttributes ->SetName(_TL("Attributes" ));
162 m_pInfo = new CActive_Info (this); m_pInfo ->SetName(_TL("Information"));
163
164 #if defined(_SAGA_MSW)
165 m_pParameters ->Hide();
166 m_pDescription->Hide();
167 m_pHistory ->Hide();
168 m_pLegend ->Hide();
169 m_pAttributes ->Hide();
170 m_pInfo ->Hide();
171 #endif
172 }
173
174 //---------------------------------------------------------
Add_Pages(void)175 void CActive::Add_Pages(void)
176 {
177 _Show_Page(m_pParameters );
178 _Show_Page(m_pDescription);
179 #ifdef ACTIVE_SHOW_ALL_PAGES
180 _Show_Page(m_pHistory );
181 _Show_Page(m_pLegend );
182 _Show_Page(m_pAttributes );
183 _Show_Page(m_pInfo );
184 #endif
185 }
186
187 //---------------------------------------------------------
~CActive(void)188 CActive::~CActive(void)
189 {
190 g_pActive = NULL;
191 }
192
193
194 ///////////////////////////////////////////////////////////
195 // //
196 ///////////////////////////////////////////////////////////
197
198 //---------------------------------------------------------
Get_Active_Data_Item(void)199 CWKSP_Data_Item * CActive::Get_Active_Data_Item(void)
200 {
201 if( m_pItem && m_pItem->GetId().IsOk() )
202 {
203 switch( m_pItem->Get_Type() )
204 {
205 case WKSP_ITEM_Table :
206 case WKSP_ITEM_Shapes :
207 case WKSP_ITEM_PointCloud:
208 case WKSP_ITEM_TIN :
209 case WKSP_ITEM_Grid :
210 case WKSP_ITEM_Grids : return( (CWKSP_Data_Item *)m_pItem );
211
212 case WKSP_ITEM_Map_Layer : return( ((CWKSP_Map_Layer *)m_pItem)->Get_Layer() );
213
214 default: break;
215 }
216 }
217
218 return( NULL );
219 }
220
221 //---------------------------------------------------------
Get_Active_Layer(void)222 CWKSP_Layer * CActive::Get_Active_Layer(void)
223 {
224 CWKSP_Data_Item *pItem = Get_Active_Data_Item();
225
226 if( pItem && pItem->Get_Type() != WKSP_ITEM_Table )
227 {
228 return( (CWKSP_Layer *)pItem );
229 }
230
231 return( NULL );
232 }
233
234 //---------------------------------------------------------
Get_Active_Shapes(bool bWithInfo)235 CWKSP_Shapes * CActive::Get_Active_Shapes(bool bWithInfo)
236 {
237 CWKSP_Layer *pLayer = Get_Active_Layer();
238
239 if( pLayer && pLayer->Get_Type() == WKSP_ITEM_Shapes )
240 {
241 CWKSP_Shapes *pShapes = (CWKSP_Shapes *)pLayer;
242
243 if( !bWithInfo || pShapes->Get_Field_Info() >= 0 )
244 {
245 return( pShapes );
246 }
247 }
248
249 return( NULL );
250 }
251
252 //---------------------------------------------------------
Get_Active_Map(void)253 CWKSP_Map * CActive::Get_Active_Map(void)
254 {
255 if( m_pItem && m_pItem->GetId().IsOk() && m_pItem->Get_Type() == WKSP_ITEM_Map )
256 {
257 return( (CWKSP_Map *)m_pItem );
258 }
259
260 return( NULL );
261 }
262
263
264 ///////////////////////////////////////////////////////////
265 // //
266 ///////////////////////////////////////////////////////////
267
268 //---------------------------------------------------------
Set_Active(CWKSP_Base_Item * pItem)269 bool CActive::Set_Active(CWKSP_Base_Item *pItem)
270 {
271 if( pItem == m_pItem )
272 {
273 return( true );
274 }
275
276 //-----------------------------------------------------
277 m_pItem = pItem;
278
279 if( m_pParameters ) m_pParameters->Set_Parameters(m_pItem);
280
281 Update_Description();
282
283 STATUSBAR_Set_Text(SG_T(""), STATUSBAR_VIEW_X);
284 STATUSBAR_Set_Text(SG_T(""), STATUSBAR_VIEW_Y);
285 STATUSBAR_Set_Text(SG_T(""), STATUSBAR_VIEW_Z);
286
287 //-----------------------------------------------------
288 if( m_pItem == NULL )
289 {
290 if( g_pSAGA_Frame ) g_pSAGA_Frame->Set_Pane_Caption(this, _TL("Properties"));
291
292 if( g_pData_Buttons ) g_pData_Buttons->Refresh();
293 if( g_pMap_Buttons ) g_pMap_Buttons ->Refresh();
294
295 size_t nPages = GetPageCount();
296
297 _Hide_Page(m_pHistory );
298 _Hide_Page(m_pLegend );
299 _Hide_Page(m_pAttributes);
300 _Hide_Page(m_pInfo );
301
302 if( nPages != GetPageCount() )
303 {
304 SendSizeEvent();
305 }
306
307 return( true );
308 }
309
310 //-----------------------------------------------------
311 if( g_pSAGA_Frame ) g_pSAGA_Frame->Set_Pane_Caption(this, wxString(_TL("Properties")) + ": " + m_pItem->Get_Name());
312
313 //-----------------------------------------------------
314 size_t nPages = GetPageCount();
315
316 _Show_Page(m_pHistory , Get_Active_Data_Item () != NULL);
317 _Show_Page(m_pLegend , Get_Active_Layer () != NULL || Get_Active_Map() != NULL);
318 _Show_Page(m_pAttributes, Get_Active_Layer () != NULL);
319 _Show_Page(m_pInfo , Get_Active_Shapes(true) != NULL);
320
321 if( nPages != GetPageCount() )
322 {
323 SendSizeEvent();
324 }
325
326 //-----------------------------------------------------
327 if( g_pData_Buttons ) g_pData_Buttons->Refresh(false);
328 if( g_pMap_Buttons ) g_pMap_Buttons ->Refresh(false);
329
330 if( g_pData_Source ) g_pData_Source->Set_Data_Source(m_pItem);
331
332 //-----------------------------------------------------
333 CSG_Data_Object *pObject = Get_Active_Data_Item() ? Get_Active_Data_Item()->Get_Object() : NULL;
334
335 if( SG_Get_Data_Manager().Exists(pObject) &&
336 ( (pObject->Get_ObjectType() == SG_DATAOBJECT_TYPE_Table && ((CSG_Table *)pObject)->Get_Selection_Count() > 0)
337 || (pObject->Get_ObjectType() == SG_DATAOBJECT_TYPE_TIN && ((CSG_Shapes *)pObject)->Get_Selection_Count() > 0)
338 || (pObject->Get_ObjectType() == SG_DATAOBJECT_TYPE_PointCloud && ((CSG_PointCloud *)pObject)->Get_Selection_Count() > 0)
339 || (pObject->Get_ObjectType() == SG_DATAOBJECT_TYPE_Shapes && ((CSG_Shapes *)pObject)->Get_Selection_Count() > 0)) )
340 {
341 g_pData->Update_Views(pObject);
342 }
343
344 return( true );
345 }
346
347
348 ///////////////////////////////////////////////////////////
349 // //
350 ///////////////////////////////////////////////////////////
351
352 //---------------------------------------------------------
_Show_Page(wxWindow * pPage,bool bShow)353 bool CActive::_Show_Page(wxWindow *pPage, bool bShow)
354 {
355 return( bShow ? _Show_Page(pPage) : _Hide_Page(pPage) );
356 }
357
358 //---------------------------------------------------------
_Show_Page(wxWindow * pPage)359 bool CActive::_Show_Page(wxWindow *pPage)
360 {
361 int Image_ID = -1;
362
363 //-----------------------------------------------------
364 if( pPage == m_pParameters ) Image_ID = IMG_PARAMETERS;
365 if( pPage == m_pDescription ) Image_ID = IMG_DESCRIPTION;
366 if( pPage == m_pHistory ) Image_ID = IMG_HISTORY;
367 if( pPage == m_pLegend ) Image_ID = IMG_LEGEND;
368 if( pPage == m_pAttributes ) Image_ID = IMG_ATTRIBUTES;
369 if( pPage == m_pInfo ) Image_ID = IMG_INFO;
370
371 //-----------------------------------------------------
372 if( pPage == m_pHistory ) m_pHistory ->Set_Item(Get_Active_Data_Item());
373 if( pPage == m_pLegend ) m_pLegend ->Set_Item(Get_Active_Layer() ? Get_Active_Layer() : Get_Active_Map() ? m_pItem : NULL);
374 if( pPage == m_pAttributes ) m_pAttributes->Set_Item(Get_Active_Layer());
375 if( pPage == m_pInfo ) m_pInfo ->Set_Item(Get_Active_Shapes(true));
376
377 //-----------------------------------------------------
378 if( pPage )
379 {
380 for(int i=0; i<(int)GetPageCount(); i++)
381 {
382 if( GetPage(i) == pPage )
383 {
384 return( true );
385 }
386 }
387
388 AddPage(pPage, pPage->GetName(), false, Image_ID);
389
390 return( true );
391 }
392
393 return( false );
394 }
395
396 //---------------------------------------------------------
_Hide_Page(wxWindow * pPage)397 bool CActive::_Hide_Page(wxWindow *pPage)
398 {
399 #ifdef ACTIVE_SHOW_ALL_PAGES
400 return( true );
401 #endif
402
403 //-----------------------------------------------------
404 if( pPage == m_pHistory ) m_pHistory ->Set_Item(NULL);
405 if( pPage == m_pLegend ) m_pLegend ->Set_Item(NULL);
406 if( pPage == m_pAttributes ) m_pAttributes->Set_Item(NULL);
407 if( pPage == m_pInfo ) m_pInfo ->Set_Item(NULL);
408
409 //-----------------------------------------------------
410 for(int i=0; i<(int)GetPageCount(); i++)
411 {
412 if( GetPage(i) == pPage )
413 {
414 if( i == GetSelection() )
415 {
416 SetSelection(i - 1);
417 }
418
419 RemovePage(i);
420
421 return( true );
422 }
423 }
424
425 return( false );
426 }
427
428
429 ///////////////////////////////////////////////////////////
430 // //
431 ///////////////////////////////////////////////////////////
432
433 //---------------------------------------------------------
Update(CWKSP_Base_Item * pItem,bool bSave)434 bool CActive::Update(CWKSP_Base_Item *pItem, bool bSave)
435 {
436 if( m_pItem && m_pItem == pItem )
437 {
438 if( m_pParameters )
439 {
440 m_pParameters->Update_Parameters(m_pItem->Get_Parameters(), bSave);
441 }
442
443 if( !bSave )
444 {
445 Update_Description();
446
447 m_pHistory->Set_Item(Get_Active_Data_Item());
448 }
449
450 return( true );
451 }
452
453 return( false );
454 }
455
456 //---------------------------------------------------------
Update_DataObjects(void)457 bool CActive::Update_DataObjects(void)
458 {
459 if( m_pParameters )
460 {
461 m_pParameters->Update_DataObjects();
462 }
463
464 return( true );
465 }
466
467 //---------------------------------------------------------
Update_Description(void)468 bool CActive::Update_Description(void)
469 {
470 if( m_pDescription == NULL )
471 {
472 return( false );
473 }
474
475 wxString Description;
476
477 //-----------------------------------------------------
478 if( m_pItem == NULL )
479 {
480 Description = _TL("No description available");
481 }
482 else
483 {
484 Description = m_pItem->Get_Description();
485 }
486
487 //-----------------------------------------------------
488 if( Description.Length() <= 8192 )
489 {
490 Description.Replace("\n", "<br>");
491 }
492
493 m_pDescription->SetPage(Description);
494
495 return( true );
496 }
497
498 //---------------------------------------------------------
Update_Attributes(bool bSave)499 bool CActive::Update_Attributes(bool bSave)
500 {
501 if( bSave )
502 {
503 m_pAttributes->Save_Changes(true);
504 }
505 else
506 {
507 m_pAttributes->Set_Attributes();
508 }
509
510 m_pInfo->Set_Info();
511
512 return( true );
513 }
514
515 //---------------------------------------------------------
Update_Info(void)516 bool CActive::Update_Info(void)
517 {
518 _Show_Page(m_pInfo, Get_Active_Shapes(true) != NULL);
519
520 return( true );
521 }
522
523
524 ///////////////////////////////////////////////////////////
525 // //
526 // //
527 // //
528 ///////////////////////////////////////////////////////////
529
530 //---------------------------------------------------------
531