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_Base_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 Hamburg                  //
42 //                Germany                                //
43 //                                                       //
44 //    e-mail:     oconrad@saga-gis.org                   //
45 //                                                       //
46 ///////////////////////////////////////////////////////////
47 
48 //---------------------------------------------------------
49 #include <wx/window.h>
50 #include <wx/image.h>
51 #include <wx/imaglist.h>
52 
53 #include <saga_api/saga_api.h>
54 
55 #include "helper.h"
56 
57 #include "saga_frame.h"
58 
59 #include "res_commands.h"
60 #include "res_controls.h"
61 #include "res_dialogs.h"
62 #include "res_images.h"
63 
64 #include "active.h"
65 
66 #include "wksp.h"
67 
68 #include "wksp_base_control.h"
69 #include "wksp_base_manager.h"
70 
71 #include "wksp_tool_control.h"
72 #include "wksp_tool_manager.h"
73 #include "wksp_tool.h"
74 
75 #include "wksp_data_manager.h"
76 #include "wksp_data_layers.h"
77 #include "wksp_table.h"
78 
79 #include "wksp_map_manager.h"
80 #include "wksp_map.h"
81 #include "wksp_map_buttons.h"
82 #include "wksp_layer.h"
83 
84 
85 ///////////////////////////////////////////////////////////
86 //														 //
87 //														 //
88 //														 //
89 ///////////////////////////////////////////////////////////
90 
91 //---------------------------------------------------------
92 enum
93 {
94 	IMG_NO_ITEMS	= 0,
95 	IMG_ROOT
96 };
97 
98 
99 ///////////////////////////////////////////////////////////
100 //														 //
101 //														 //
102 //														 //
103 ///////////////////////////////////////////////////////////
104 
105 //---------------------------------------------------------
IMPLEMENT_CLASS(CWKSP_Base_Control,wxTreeCtrl)106 IMPLEMENT_CLASS(CWKSP_Base_Control, wxTreeCtrl)
107 
108 //---------------------------------------------------------
109 BEGIN_EVENT_TABLE(CWKSP_Base_Control, wxTreeCtrl)
110 	EVT_TREE_ITEM_RIGHT_CLICK(ID_WND_WKSP_TOOLS, CWKSP_Base_Control::On_Item_RClick    )
111 	EVT_TREE_DELETE_ITEM     (ID_WND_WKSP_TOOLS, CWKSP_Base_Control::On_Item_Delete    )
112 	EVT_TREE_SEL_CHANGED     (ID_WND_WKSP_TOOLS, CWKSP_Base_Control::On_Item_SelChanged)
113 	EVT_TREE_KEY_DOWN        (ID_WND_WKSP_TOOLS, CWKSP_Base_Control::On_Item_KeyDown   )
114 
115 	EVT_TREE_ITEM_RIGHT_CLICK(ID_WND_WKSP_DATA , CWKSP_Base_Control::On_Item_RClick    )
116 	EVT_TREE_DELETE_ITEM     (ID_WND_WKSP_DATA , CWKSP_Base_Control::On_Item_Delete    )
117 	EVT_TREE_SEL_CHANGED     (ID_WND_WKSP_DATA , CWKSP_Base_Control::On_Item_SelChanged)
118 	EVT_TREE_KEY_DOWN        (ID_WND_WKSP_DATA , CWKSP_Base_Control::On_Item_KeyDown   )
119 
120 	EVT_TREE_ITEM_RIGHT_CLICK(ID_WND_WKSP_MAPS , CWKSP_Base_Control::On_Item_RClick    )
121 	EVT_TREE_DELETE_ITEM     (ID_WND_WKSP_MAPS , CWKSP_Base_Control::On_Item_Delete    )
122 	EVT_TREE_SEL_CHANGED     (ID_WND_WKSP_MAPS , CWKSP_Base_Control::On_Item_SelChanged)
123 	EVT_TREE_KEY_DOWN        (ID_WND_WKSP_MAPS , CWKSP_Base_Control::On_Item_KeyDown   )
124 
125 	EVT_LEFT_DOWN            (CWKSP_Base_Control::On_Item_LClick )
126 	EVT_LEFT_DCLICK          (CWKSP_Base_Control::On_Item_LDClick)
127 END_EVENT_TABLE()
128 
129 
130 ///////////////////////////////////////////////////////////
131 //														 //
132 //														 //
133 //														 //
134 ///////////////////////////////////////////////////////////
135 
136 //---------------------------------------------------------
137 CWKSP_Base_Control::CWKSP_Base_Control(wxWindow *pParent, wxWindowID id)
138 	: wxTreeCtrl(pParent, id, wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS)
139 {
140 	m_pManager	= NULL;
141 
142 	AssignImageList(new wxImageList(IMG_SIZE_TREECTRL, IMG_SIZE_TREECTRL, true, 0));
143 
144 	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_NOITEMS);
145 }
146 
147 //---------------------------------------------------------
~CWKSP_Base_Control(void)148 CWKSP_Base_Control::~CWKSP_Base_Control(void)
149 {}
150 
151 
152 ///////////////////////////////////////////////////////////
153 //														 //
154 ///////////////////////////////////////////////////////////
155 
156 //---------------------------------------------------------
_Set_Manager(CWKSP_Base_Manager * pManager)157 bool CWKSP_Base_Control::_Set_Manager(CWKSP_Base_Manager *pManager)
158 {
159 	if( m_pManager == NULL )
160 	{
161 		m_pManager	= pManager;
162 
163 		AddRoot   (m_pManager->Get_Name(), IMG_ROOT, IMG_ROOT, m_pManager);
164 		AppendItem(m_pManager->GetId(), _TL("<no items>"), IMG_NO_ITEMS, IMG_NO_ITEMS, NULL);
165 		Expand    (m_pManager->GetId());
166 
167 		return( true );
168 	}
169 
170 	return( false );
171 }
172 
173 
174 ///////////////////////////////////////////////////////////
175 //														 //
176 ///////////////////////////////////////////////////////////
177 
178 //---------------------------------------------------------
On_Command(wxCommandEvent & event)179 void CWKSP_Base_Control::On_Command(wxCommandEvent &event)
180 {
181 	switch( event.GetId() )
182 	{
183 	case ID_CMD_WKSP_ITEM_CLOSE:
184 		_Del_Active(false);
185 		break;
186 
187 	case ID_CMD_WKSP_ITEM_SHOW:
188 		_Show_Active();
189 		break;
190 
191 	case ID_CMD_WKSP_ITEM_SETTINGS_LOAD:
192 		_Load_Settings();
193 		break;
194 
195 	case ID_CMD_WKSP_ITEM_SETTINGS_COPY:
196 		_Copy_Settings();
197 		break;
198 
199 	case ID_CMD_WKSP_ITEM_SEARCH:
200 		_Search_Item();
201 		break;
202 
203 	//-----------------------------------------------------
204 	default:
205 		if( !m_pManager->On_Command(event.GetId()) )
206 		{
207 			CWKSP_Base_Item	*pItem	= Get_Item_Selected();
208 
209 			if( pItem )
210 			{
211 				pItem->On_Command(event.GetId());
212 			}
213 		}
214 	}
215 }
216 
217 //---------------------------------------------------------
On_Command_UI(wxUpdateUIEvent & event)218 void CWKSP_Base_Control::On_Command_UI(wxUpdateUIEvent &event)
219 {
220 	if( !m_pManager->On_Command_UI(event) )
221 	{
222 		CWKSP_Base_Item	*pItem	= Get_Item_Selected();
223 
224 		if( pItem )
225 		{
226 			pItem->On_Command_UI(event);
227 		}
228 	}
229 }
230 
231 
232 ///////////////////////////////////////////////////////////
233 //														 //
234 ///////////////////////////////////////////////////////////
235 
236 //---------------------------------------------------------
_Add_Item(CWKSP_Base_Item * pItem,int Image,int selImage,bool bSort)237 bool CWKSP_Base_Control::_Add_Item(CWKSP_Base_Item *pItem, int Image, int selImage, bool bSort)
238 {
239 	if( pItem != NULL && pItem->Get_Manager() == m_pManager )
240 	{
241 		if( m_pManager->Get_Count() == 1 )
242 		{
243 			DeleteChildren(m_pManager->GetId());
244 		}
245 
246 		AppendItem(m_pManager->GetId(), pItem->Get_Name(), Image, selImage, pItem);
247 
248 		if( bSort )
249 		{
250 			SortChildren(m_pManager->GetId());
251 		}
252 
253 		Expand(m_pManager->GetId());
254 
255 		return( true );
256 	}
257 
258 	return( false );
259 }
260 
261 //---------------------------------------------------------
Del_Item(CWKSP_Base_Item * pItem,bool bSilent)262 bool CWKSP_Base_Control::Del_Item(CWKSP_Base_Item *pItem, bool bSilent)
263 {
264 	return( _Del_Item(pItem, bSilent) );
265 }
266 
_Del_Item(CWKSP_Base_Item * pItem,bool bSilent)267 bool CWKSP_Base_Control::_Del_Item(CWKSP_Base_Item *pItem, bool bSilent)
268 {
269 	//-----------------------------------------------------
270 	if( pItem == NULL || pItem->GetId().IsOk() == false || pItem->Get_Control() != this )
271 	{
272 		return( false );
273 	}
274 
275 	if( pItem->Get_Type() == WKSP_ITEM_Tool && ((CWKSP_Tool *)pItem)->Get_Tool()->Get_Type() != TOOL_TYPE_Chain )
276 	{	// tool libraries can be unloaded, tools not! (except of tool chain tools)
277 		return( false );
278 	}
279 
280 	if( pItem->Get_Type() == WKSP_ITEM_Table &&	((CWKSP_Table *)pItem)->Get_Object()->Get_ObjectType() != SG_DATAOBJECT_TYPE_Table )
281 	{
282 		return( false );
283 	}
284 
285 	if( !bSilent && !_Del_Item_Confirm(pItem) )
286 	{
287 		return( false );
288 	}
289 
290 	//-----------------------------------------------------
291 	if( m_pManager == g_pActive->Get_Active() && Get_Selection_Count() > 1 )
292 	{
293 		g_pActive->Set_Active(NULL);
294 	}
295 
296 	//-----------------------------------------------------
297 	if( pItem == m_pManager )
298 	{
299 		if( m_pManager->Get_Count() > 0 )
300 		{
301 			Freeze();
302 
303 			if( m_pManager == g_pData || m_pManager == g_pMaps )
304 			{
305 				if( g_pData_Buttons )	{	g_pData_Buttons->Freeze();	}
306 				if( g_pMap_Buttons  )	{	g_pMap_Buttons ->Freeze();	}
307 
308 				g_pSAGA_Frame->Close_Children();
309 			}
310 
311 			//---------------------------------------------
312 			DeleteChildren	(m_pManager->GetId());
313 			AppendItem		(m_pManager->GetId(), _TL("<no items>"), 0, 0, NULL);
314 			Expand			(m_pManager->GetId());
315 
316 			if( g_pTools == m_pManager )
317 			{
318 				g_pTools->Update();
319 			}
320 
321 			if( g_pData == m_pManager )
322 			{
323 				g_pData->MultiSelect_Check();
324 			}
325 
326 			//---------------------------------------------
327 			Thaw();
328 
329 			if( m_pManager == g_pData || m_pManager == g_pMaps )
330 			{
331 				if( g_pData_Buttons )	{	g_pData_Buttons->Thaw();	g_pData_Buttons->Update_Buttons();	}
332 				if( g_pMap_Buttons  )	{	g_pMap_Buttons ->Thaw();	g_pMap_Buttons ->Update_Buttons();	}
333 			}
334 		}
335 	}
336 
337 	//-----------------------------------------------------
338 	else
339 	{
340 		CWKSP_Base_Manager	*pItem_Manager	= pItem->Get_Manager();
341 
342 		Freeze();
343 
344 		Delete(pItem->GetId());
345 
346 		if( pItem_Manager != NULL && pItem_Manager->Get_Count() == 0 )
347 		{
348 			Thaw();
349 
350 			if( m_pManager->Get_Type() == WKSP_ITEM_Data_Manager )
351 			{
352 				g_pData_Buttons->Update_Buttons();
353 			}
354 
355 			if( m_pManager->Get_Type() == WKSP_ITEM_Map_Manager )
356 			{
357 				g_pMap_Buttons->Update_Buttons();
358 			}
359 
360 			return( _Del_Item(pItem_Manager, true) );
361 		}
362 
363 		if( m_pManager->Get_Type() == WKSP_ITEM_Tool_Manager )
364 		{
365 			g_pTools->Update();
366 		}
367 
368 		if( pItem_Manager != NULL && pItem_Manager->Get_Type() == WKSP_ITEM_Map )
369 		{
370 			((CWKSP_Map *)pItem_Manager)->View_Refresh(false);
371 		}
372 
373 		Thaw();
374 
375 		Refresh();
376 
377 		if( m_pManager->Get_Type() == WKSP_ITEM_Data_Manager )
378 		{
379 			g_pData_Buttons->Update_Buttons();
380 		}
381 
382 		if( m_pManager->Get_Type() == WKSP_ITEM_Map_Manager )
383 		{
384 			g_pMap_Buttons->Update_Buttons();
385 		}
386 	}
387 
388 	//-----------------------------------------------------
389 	return( true );
390 }
391 
392 //---------------------------------------------------------
_Del_Item_Confirm(CWKSP_Base_Item * pItem)393 bool CWKSP_Base_Control::_Del_Item_Confirm(CWKSP_Base_Item *pItem)
394 {
395 	if( DLG_Message_Confirm(ID_DLG_DELETE) )
396 	{
397 		if( m_pManager->Get_Type() == WKSP_ITEM_Data_Manager )
398 		{
399 			return( g_pData->Save_Modified(pItem) );
400 		}
401 
402 		return( true );
403 	}
404 
405 	return( false );
406 }
407 
408 
409 ///////////////////////////////////////////////////////////
410 //														 //
411 ///////////////////////////////////////////////////////////
412 
413 //---------------------------------------------------------
Get_Selection_Count(void)414 int CWKSP_Base_Control::Get_Selection_Count(void)
415 {
416 	return( GetSelection().IsOk() ? 1 : 0 );
417 }
418 
419 //---------------------------------------------------------
Get_Item_Selected(bool bUpdate)420 CWKSP_Base_Item * CWKSP_Base_Control::Get_Item_Selected(bool bUpdate)
421 {
422 	wxTreeItemId	ID	= GetSelection();
423 
424 	return( ID.IsOk() ? (CWKSP_Base_Item *)GetItemData(ID) : NULL );
425 }
426 
427 //---------------------------------------------------------
Set_Item_Selected(CWKSP_Base_Item * pItem,bool bKeepMultipleSelection)428 bool CWKSP_Base_Control::Set_Item_Selected(CWKSP_Base_Item *pItem, bool bKeepMultipleSelection)
429 {
430 	if( pItem && pItem->GetId().IsOk() && pItem->Get_Control() == this )
431 	{
432 		SelectItem(pItem->GetId());
433 
434 		return( true );
435 	}
436 
437 	return( false );
438 }
439 
440 
441 ///////////////////////////////////////////////////////////
442 //														 //
443 ///////////////////////////////////////////////////////////
444 
445 //---------------------------------------------------------
Get_Menu(void)446 wxMenu * CWKSP_Base_Control::Get_Menu(void)
447 {
448 	CWKSP_Base_Item	*pItem	= Get_Item_Selected();
449 
450 	return( pItem ? pItem->Get_Menu() : NULL );
451 }
452 
453 
454 ///////////////////////////////////////////////////////////
455 //														 //
456 ///////////////////////////////////////////////////////////
457 
458 //---------------------------------------------------------
_Del_Active(bool bSilent)459 bool CWKSP_Base_Control::_Del_Active(bool bSilent)
460 {
461 	if( m_pManager->Get_Type() == WKSP_ITEM_Data_Manager && PROCESS_is_Executing() )	// never allow data deletion during tool execution!
462 	{
463 		return( false );
464 	}
465 
466 	wxTreeItemId	ID	= GetSelection();
467 
468 	if( ID.IsOk() )
469 	{
470 		_Del_Item((CWKSP_Base_Item *)GetItemData(ID), bSilent);
471 	}
472 
473 	return( true );
474 }
475 
476 //---------------------------------------------------------
_Show_Active(void)477 bool CWKSP_Base_Control::_Show_Active(void)
478 {
479 	wxArrayTreeItemIds	IDs;
480 
481 	if( (GetWindowStyle() & wxTR_MULTIPLE) != 0 && GetSelections(IDs) > 0 && ((CWKSP_Base_Item *)GetItemData(IDs[0]))->Get_Control() == this )
482 	{
483 		int	iMap = 0;
484 
485 		for(size_t iItem=0; iItem<IDs.GetCount(); iItem++)
486 		{
487 			CWKSP_Base_Item *pItem = IDs[iItem].IsOk() ? (CWKSP_Base_Item *)GetItemData(IDs[iItem]) : NULL;
488 
489 			if( pItem )
490 			{
491 				switch( pItem->Get_Type() )
492 				{
493 				case WKSP_ITEM_Table     :
494 					((CWKSP_Table *)pItem)->Set_View(true);
495 					break;
496 
497 				case WKSP_ITEM_Grid      :
498 				case WKSP_ITEM_Grids     :
499 				case WKSP_ITEM_Shapes    :
500 				case WKSP_ITEM_TIN       :
501 				case WKSP_ITEM_PointCloud:
502 					iMap	= 1;
503 					break;
504 
505 				default:
506 					break;
507 				}
508 			}
509 		}
510 
511 		if( iMap && (iMap = DLG_Maps_Add()) >= 0 )
512 		{
513 			for(size_t iItem=0; iItem<IDs.GetCount(); iItem++)
514 			{
515 				CWKSP_Base_Item *pItem = IDs[iItem].IsOk() ? (CWKSP_Base_Item *)GetItemData(IDs[iItem]) : NULL;
516 
517 				if( pItem )
518 				{
519 					switch( pItem->Get_Type() )
520 					{
521 					case WKSP_ITEM_Grid      :
522 					case WKSP_ITEM_Grids     :
523 					case WKSP_ITEM_Shapes    :
524 					case WKSP_ITEM_TIN       :
525 					case WKSP_ITEM_PointCloud:
526 						g_pMaps->Add((CWKSP_Layer *)pItem, g_pMaps->Get_Map(iMap));
527 						break;
528 
529 					default:
530 						break;
531 					}
532 				}
533 			}
534 
535 			g_pMaps->Get_Map(iMap)->View_Show(true);
536 
537 			return( true );
538 		}
539 	}
540 
541 	return( false );
542 }
543 
544 
545 ///////////////////////////////////////////////////////////
546 //														 //
547 ///////////////////////////////////////////////////////////
548 
549 //---------------------------------------------------------
_Load_Settings(void)550 bool CWKSP_Base_Control::_Load_Settings(void)
551 {
552 	wxString		File_Path;
553 	CSG_MetaData	Data;
554 
555 	if( Get_Selection_Count() > 0 && DLG_Open(File_Path, ID_DLG_PARAMETERS_OPEN) && Data.Load(&File_Path) )
556 	{
557 		if(	GetWindowStyle() & wxTR_MULTIPLE )
558 		{
559 			wxArrayTreeItemIds	IDs;
560 
561 			if( GetSelections(IDs) > 0 )
562 			{
563 				for(size_t i=0; i<IDs.GetCount(); i++)
564 				{
565 					_Load_Settings(&Data, (CWKSP_Base_Item *)GetItemData(IDs[i]));
566 				}
567 			}
568 		}
569 		else
570 		{
571 			_Load_Settings(&Data, Get_Item_Selected());
572 		}
573 
574 		return( true );
575 	}
576 
577 	return( false );
578 }
579 
580 //---------------------------------------------------------
_Load_Settings(CSG_MetaData * pData,CWKSP_Base_Item * pItem)581 bool CWKSP_Base_Control::_Load_Settings(CSG_MetaData *pData, CWKSP_Base_Item *pItem)
582 {
583 	if( pData && pItem && pItem->Get_Parameters() )
584 	{
585 		if( pItem->Get_Parameters()->Serialize(*pData, false) )
586 		{
587 			pItem->Parameters_Changed();
588 		}
589 
590 		return( true );
591 	}
592 
593 	return( false );
594 }
595 
596 //---------------------------------------------------------
DLG_Copy_Settings(CSG_Table & List,CWKSP_Base_Item * pItem)597 void	DLG_Copy_Settings(CSG_Table &List, CWKSP_Base_Item *pItem)
598 {
599 	if( pItem )
600 	{
601 		if( pItem->is_Manager() )
602 		{
603 			for(int i=0; i<((CWKSP_Base_Manager *)pItem)->Get_Count(); i++)
604 			{
605 				DLG_Copy_Settings(List, ((CWKSP_Base_Manager *)pItem)->Get_Item(i));
606 			}
607 		}
608 		else if( pItem->Get_Parameters() )
609 		{
610 			CSG_Table_Record	*pEntry	= List.Add_Record();
611 
612 			pEntry->Set_Value(0, CSG_String(wxString::Format("[%s] %s", pItem->Get_Manager()->Get_Name(), pItem->Get_Name()).wc_str()));
613 			pEntry->Set_Value(1, CSG_String::Format("%p", pItem->Get_Parameters()));
614 		}
615 	}
616 }
617 
618 //---------------------------------------------------------
DLG_Copy_Settings(void)619 CSG_Parameters *	DLG_Copy_Settings(void)
620 {
621 	CSG_Table	List;
622 
623 	List.Add_Field(SG_T("NAME"), SG_DATATYPE_String);
624 	List.Add_Field(SG_T("PRMS"), SG_DATATYPE_String);
625 
626 	DLG_Copy_Settings(List, (CWKSP_Base_Item *)g_pData->Get_Grids      ());
627 	DLG_Copy_Settings(List, (CWKSP_Base_Item *)g_pData->Get_Shapes     ());
628 	DLG_Copy_Settings(List, (CWKSP_Base_Item *)g_pData->Get_TINs       ());
629 	DLG_Copy_Settings(List, (CWKSP_Base_Item *)g_pData->Get_PointClouds());
630 
631 	if( List.Get_Count() > 0 )
632 	{
633 		wxArrayString	Items;
634 
635 		for(int i=0; i<List.Get_Count(); i++)
636 		{
637 			Items.Add(List.Get_Record(i)->asString(0));
638 		}
639 
640 		wxSingleChoiceDialog	dlg(MDI_Get_Top_Window(),
641 			_TL("Copy Settings from..."),
642 			_TL("Select a layer to copy settings from it."),
643 			Items
644 		);
645 
646 		void	*pParameters;
647 
648 		if( dlg.ShowModal() == wxID_OK && SG_SSCANF(List.Get_Record(dlg.GetSelection())->asString(1), SG_T("%p"), &pParameters) == 1 )
649 		{
650 			return( (CSG_Parameters *)pParameters );
651 		}
652 	}
653 
654 	return( NULL );
655 }
656 
657 //---------------------------------------------------------
_Copy_Settings(CSG_Parameters * pParameters,CWKSP_Base_Item * pItem)658 bool CWKSP_Base_Control::_Copy_Settings(CSG_Parameters *pParameters, CWKSP_Base_Item *pItem)
659 {
660 	if( pParameters && pItem && pParameters != pItem->Get_Parameters() )
661 	{
662 		for(int i=0; i<pParameters->Get_Count(); i++)
663 		{
664 			CSG_Parameter	*pSource	= pParameters->Get_Parameter(i);
665 
666 			if(	SG_STR_CMP(pSource->Get_Identifier(), SG_T("OBJECT_NAME")) )
667 		//	&&	SG_STR_CMP(pSource->Get_Identifier(), SG_T("LUT_ATTRIB"))
668 		//	&&	SG_STR_CMP(pSource->Get_Identifier(), SG_T("METRIC_ATTRIB"))
669 		//	&&	SG_STR_CMP(pSource->Get_Identifier(), SG_T("LABEL_ATTRIB"))
670 		//	&&	SG_STR_CMP(pSource->Get_Identifier(), SG_T("LABEL_ATTRIB_SIZE_BY"))	)
671 			{
672 				CSG_Parameter	*pTarget	= pItem->Get_Parameter(pSource->Get_Identifier());
673 
674 				if( pTarget && pTarget->Get_Type() == pSource->Get_Type() )
675 				{
676 					pTarget->Set_Value(pSource);
677 				}
678 			}
679 		}
680 
681 		pItem->Parameters_Changed();
682 
683 		return( true );
684 	}
685 
686 	return( false );
687 }
688 
689 //---------------------------------------------------------
_Copy_Settings(void)690 bool CWKSP_Base_Control::_Copy_Settings(void)
691 {
692 	CSG_Parameters	*pParameters = Get_Selection_Count() > 0 ? DLG_Copy_Settings() : NULL;
693 
694 	if( pParameters )
695 	{
696 		wxArrayTreeItemIds	IDs;
697 
698 		if(	(GetWindowStyle() & wxTR_MULTIPLE) && GetSelections(IDs) > 0 )
699 		{
700 			for(size_t i=0; i<IDs.GetCount(); i++)
701 			{
702 				_Copy_Settings(pParameters, (CWKSP_Base_Item *)GetItemData(IDs[i]));
703 			}
704 
705 			return( true );
706 		}
707 		else
708 		{
709 			return( _Copy_Settings(pParameters, Get_Item_Selected()) );
710 		}
711 	}
712 
713 	return( false );
714 }
715 
716 
717 ///////////////////////////////////////////////////////////
718 //														 //
719 ///////////////////////////////////////////////////////////
720 
721 //---------------------------------------------------------
_Search_Compare(wxString A,wxString B,bool bCase)722 bool CWKSP_Base_Control::_Search_Compare(wxString A, wxString B, bool bCase)
723 {
724 	return( bCase ? B.Find(A) != wxNOT_FOUND : B.MakeUpper().Find(A.MakeUpper().c_str()) != wxNOT_FOUND );
725 }
726 
727 //---------------------------------------------------------
_Search_Get_List(CSG_Table * pList,CWKSP_Base_Item * pItem,const wxString & String,bool bName,bool bDesc,bool bCase,TWKSP_Item Type)728 bool CWKSP_Base_Control::_Search_Get_List(CSG_Table *pList, CWKSP_Base_Item *pItem, const wxString &String, bool bName, bool bDesc, bool bCase, TWKSP_Item Type)
729 {
730 	if( pItem == NULL )
731 	{
732 		return( false );
733 	}
734 
735 	if(	Type == WKSP_ITEM_Undefined || Type == pItem->Get_Type() )
736 	{
737 		if( (bName && _Search_Compare(String, pItem->Get_Name       (), bCase))
738 		||  (bDesc && _Search_Compare(String, pItem->Get_Description(), bCase)) )
739 		{
740 			CSG_Table_Record	*pRecord	= pList->Add_Record();
741 
742 			pRecord->Set_Value(0, pItem->Get_Name().wx_str());
743 			pRecord->Set_Value(1, pItem->Get_Type_Name(pItem->Get_Type()).wx_str());
744 			pRecord->Set_Value(2, CSG_String::Format("%p", pItem));
745 		}
746 	}
747 
748 	if( pItem->is_Manager() )
749 	{
750 		for(int i=0; i<((CWKSP_Base_Manager *)pItem)->Get_Count(); i++)
751 		{
752 			_Search_Get_List(pList, ((CWKSP_Base_Manager *)pItem)->Get_Item(i), String, bName, bDesc, bCase, Type);
753 		}
754 	}
755 
756 	return( true );
757 }
758 
759 //---------------------------------------------------------
Search_Item(const wxString & Caption,TWKSP_Item Type)760 CWKSP_Base_Item * CWKSP_Base_Control::Search_Item(const wxString &Caption, TWKSP_Item Type)
761 {
762 	static CSG_Parameters	Search(Caption);
763 
764 	if( Search.Get_Count() == 0 )
765 	{
766 		Search.Add_String("", "STRING", _TL("Search for..." ), _TL(""), ""   );
767 		Search.Add_Bool  ("", "NAME"  , _TL("Name"          ), _TL(""), true );
768 		Search.Add_Bool  ("", "DESC"  , _TL("Description"   ), _TL(""), false);
769 		Search.Add_Bool  ("", "CASE"  , _TL("Case Sensitive"), _TL(""), false);
770 	}
771 
772 	if( !DLG_Parameters(&Search) )
773 	{
774 		return( NULL );
775 	}
776 
777 	//-----------------------------------------------------
778 	CSG_Table	List;
779 
780 	List.Add_Field(_TL("NAME"), SG_DATATYPE_String);
781 	List.Add_Field(_TL("TYPE"), SG_DATATYPE_String);
782 	List.Add_Field(_TL("ADDR"), SG_DATATYPE_String);
783 
784 	_Search_Get_List(&List, m_pManager, Search("STRING")->asString(), Search("NAME")->asBool(), Search("DESC")->asBool(), Search("CASE")->asBool(), Type);
785 
786 	if( List.Get_Count() <= 0 )
787 	{
788 		wxMessageBox(_TL("Search text not found"), _TL("Search for..."), wxOK|wxICON_EXCLAMATION);
789 
790 		return( NULL );
791 	}
792 
793 	//-----------------------------------------------------
794 	List.Set_Index(1, TABLE_INDEX_Ascending, 0, TABLE_INDEX_Ascending);
795 
796 	wxArrayString	Items;
797 
798 	for(int i=0; i<List.Get_Count(); i++)
799 	{
800 		if( Type == WKSP_ITEM_Undefined )
801 		{
802 			Items.Add(wxString::Format("[%s] %s", List[i].asString(1), List[i].asString(0)));
803 		}
804 		else
805 		{
806 			Items.Add(List[i].asString(0));
807 		}
808 	}
809 
810 	//-----------------------------------------------------
811 	wxSingleChoiceDialog	dlg(MDI_Get_Top_Window(),
812 		wxString::Format("%s: '%s'", _TL("Search Result"), Search("STRING")->asString()),
813 		Caption, Items
814 	);
815 
816 	void	*pItem;
817 
818 	if( dlg.ShowModal() != wxID_OK || SG_SSCANF(List[dlg.GetSelection()].asString(2), SG_T("%p"), &pItem) != 1 )
819 	{
820 		return( NULL );
821 	}
822 
823 	return( (CWKSP_Base_Item *)pItem );
824 }
825 
826 //---------------------------------------------------------
_Search_Item(void)827 bool CWKSP_Base_Control::_Search_Item(void)
828 {
829 	CWKSP_Base_Item	*pItem	= Search_Item(_TL("Locate..."));
830 
831 	if( pItem && pItem->GetId().IsOk() )
832 	{
833 		EnsureVisible	(pItem->GetId());
834 		SelectItem		(pItem->GetId());
835 		ScrollTo		(pItem->GetId());
836 
837 		return( true );
838 	}
839 
840 	return( false );
841 }
842 
843 
844 ///////////////////////////////////////////////////////////
845 //														 //
846 ///////////////////////////////////////////////////////////
847 
848 //---------------------------------------------------------
On_Item_LClick(wxMouseEvent & event)849 void CWKSP_Base_Control::On_Item_LClick(wxMouseEvent &event)
850 {
851 	g_pActive->Set_Active(Get_Item_Selected());
852 
853 	event.Skip();
854 }
855 
856 //---------------------------------------------------------
On_Item_LDClick(wxMouseEvent & event)857 void CWKSP_Base_Control::On_Item_LDClick(wxMouseEvent &event)
858 {
859 	CWKSP_Base_Item	*pItem;
860 
861 	if( (pItem = Get_Item_Selected()) != NULL )
862 	{
863 		pItem->On_Command(ID_CMD_WKSP_ITEM_RETURN);
864 	}
865 }
866 
867 //---------------------------------------------------------
On_Item_RClick(wxTreeEvent & event)868 void CWKSP_Base_Control::On_Item_RClick(wxTreeEvent &event)
869 {
870 	if( m_pManager->Get_Type() != WKSP_ITEM_Data_Manager )
871 	{
872 		SelectItem(event.GetItem());
873 	}
874 
875 	if( Get_Selection_Count() <= 1 )
876 	{
877 		g_pActive->Set_Active(Get_Item_Selected());
878 	}
879 
880 	wxMenu	*pMenu	= Get_Menu();
881 
882 	if( pMenu )
883 	{
884 		PopupMenu(pMenu);
885 
886 		delete(pMenu);
887 	}
888 
889 	event.Skip();
890 }
891 
892 //---------------------------------------------------------
On_Item_KeyDown(wxTreeEvent & event)893 void CWKSP_Base_Control::On_Item_KeyDown(wxTreeEvent &event)
894 {
895 	switch( event.GetKeyCode() )
896 	{
897 	case WXK_DELETE:
898 		_Del_Active(false);
899 		break;
900 
901 	default: {
902 		CWKSP_Base_Item	*pItem = Get_Item_Selected();
903 
904 		if( pItem )
905 		{
906 			switch( event.GetKeyCode() )
907 			{
908 			default:
909 				break;
910 
911 			case WXK_RETURN:
912 				pItem->On_Command(ID_CMD_WKSP_ITEM_RETURN);
913 				break;
914 			}
915 		}
916 		break; }
917 	}
918 }
919 
920 //---------------------------------------------------------
On_Item_SelChanged(wxTreeEvent & event)921 void CWKSP_Base_Control::On_Item_SelChanged(wxTreeEvent &event)
922 {
923 	if( g_pActive )
924 	{
925 		CWKSP_Base_Item	*pItem	= Get_Item_Selected(true);
926 
927 		if( pItem )
928 		{
929 			g_pActive->Set_Active(pItem);
930 		}
931 	}
932 
933 	event.Skip();
934 }
935 
936 //---------------------------------------------------------
On_Item_Delete(wxTreeEvent & event)937 void CWKSP_Base_Control::On_Item_Delete(wxTreeEvent &event)
938 {
939 	event.Skip();
940 }
941 
942 
943 ///////////////////////////////////////////////////////////
944 //														 //
945 //														 //
946 //														 //
947 ///////////////////////////////////////////////////////////
948 
949 //---------------------------------------------------------
950