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_tool_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 Hamburg //
42 // Germany //
43 // //
44 // e-mail: oconrad@saga-gis.org //
45 // //
46 ///////////////////////////////////////////////////////////
47
48 //---------------------------------------------------------
49 #include <wx/dir.h>
50 #include <wx/filename.h>
51
52 #include <saga_api/saga_api.h>
53
54 #include "saga.h"
55 #include "saga_frame.h"
56
57 #include "res_commands.h"
58 #include "res_dialogs.h"
59
60 #include "dlg_parameters.h"
61
62 #include "helper.h"
63
64 #include "wksp_tool_control.h"
65 #include "wksp_tool_manager.h"
66 #include "wksp_tool_library.h"
67 #include "wksp_tool_menu.h"
68 #include "wksp_tool.h"
69
70 #include "wksp_data_manager.h"
71
72
73 ///////////////////////////////////////////////////////////
74 // //
75 // //
76 // //
77 ///////////////////////////////////////////////////////////
78
79 //---------------------------------------------------------
80 CWKSP_Tool_Manager *g_pTools = NULL;
81
82
83 ///////////////////////////////////////////////////////////
84 // //
85 ///////////////////////////////////////////////////////////
86
87 //---------------------------------------------------------
CWKSP_Tool_Manager(void)88 CWKSP_Tool_Manager::CWKSP_Tool_Manager(void)
89 {
90 g_pTools = this;
91
92 m_pMenu_Tools = new CWKSP_Tool_Menu;
93
94 //-----------------------------------------------------
95 m_Parameters.Add_Node("", "NODE_GENERAL", _TL("General"), _TL(""));
96
97 m_Parameters.Add_Bool("NODE_GENERAL",
98 "START_LOGO" , _TL("Show Logo at Start Up"),
99 _TL(""),
100 true
101 );
102
103 m_Parameters.Add_Int("NODE_GENERAL",
104 "PROCESS_UPDATE", _TL("Process Update Frequency [milliseconds]"),
105 _TL(""),
106 0, 0, true
107 );
108
109 m_Parameters.Add_Bool("NODE_GENERAL",
110 "SAVE_CONFIG" , _TL("Save Configuration"),
111 _TL("disabling might help to shut down faster, particularly if started from slow devices"),
112 true
113 );
114
115 #ifdef _OPENMP
116 m_Parameters.Add_Int("NODE_GENERAL",
117 "OMP_THREADS_MAX", _TL("Number of CPU Cores [# physical processors]"),
118 _TW("Number of processors to use for parallelization. Should be set to the number "
119 "of physical processors, and not to the total number of physical and logical processors "
120 "on systems supporting hyper-threading."),
121 SG_OMP_Get_Max_Num_Threads(), 1, true, SG_OMP_Get_Max_Num_Procs(), true
122 );
123 #endif
124
125 //-----------------------------------------------------
126 m_Parameters.Add_Node("", "NODE_TOOLS", _TL("Tools"), _TL(""));
127
128 m_Parameters.Add_Bool("NODE_TOOLS",
129 "BEEP" , _TL("Beep when finished"),
130 _TL(""),
131 false
132 );
133
134 m_Parameters.Add_Choice("NODE_TOOLS",
135 "HELP_SOURCE" , _TL("Tool Description Source"),
136 _TL(""),
137 CSG_String::Format("%s|%s",
138 _TL("built-in"),
139 _TL("online")
140 ), 0
141 );
142
143 //-----------------------------------------------------
144 m_Parameters.Add_Node("", "NODE_FILES", _TL("Files"), _TL(""));
145
146 m_Parameters.Add_FilePath("NODE_FILES",
147 "LNG_FILE_DIC" , _TL("Language Translations"),
148 _TL("Dictionary for translations from built-in (English) to local language (editable text table, utf-8 encoded). You need to restart SAGA to apply the changes."),
149 CSG_String::Format("%s|*.lng;*.txt|%s (*.lng)|*.lng|%s (*.txt)|*.txt|%s|*.*",
150 _TL("Recognized Files"),
151 _TL("Dictionary Files"),
152 _TL("Text Table"),
153 _TL("All Files")
154 )
155 );
156
157 m_Parameters.Add_FilePath("NODE_FILES",
158 "TOOL_MENUS" , _TL("User defined tool menus"),
159 _TL("User defined tool menus."),
160 CSG_String::Format("%s|*.xml|%s|*.*",
161 _TL("XML Files (*.xml)"),
162 _TL("All Files")
163 )
164 );
165
166 //-----------------------------------------------------
167 m_Parameters.Add_Node("", "NODE_LOOK", _TL("Appearance"), _TL(""));
168
169 m_Parameters.Add_Int("NODE_LOOK",
170 "LOOK_TB_SIZE" , _TL("Tool Bar Button Size"),
171 _TL("Tool bar button sizes. You need to restart SAGA to apply the changes."),
172 16, 16, true
173 );
174
175 m_Parameters.Add_Int("NODE_LOOK",
176 "FLOAT_PRECISION", _TL("Floating Point Precision"),
177 _TL("Sets the (max) precision used when floating point values are rendered as text in settings controls. The value set to -1 means infinite precision."),
178 10, -1, true
179 );
180 }
181
182 //---------------------------------------------------------
~CWKSP_Tool_Manager(void)183 CWKSP_Tool_Manager::~CWKSP_Tool_Manager(void)
184 {
185 delete(m_pMenu_Tools);
186
187 g_pTools = NULL;
188 }
189
190
191 ///////////////////////////////////////////////////////////
192 // //
193 ///////////////////////////////////////////////////////////
194
195 //---------------------------------------------------------
196 #define CFG_LIBS "/LIBS"
197 #define CFG_LIBF "LIB_%03d"
198
199 //---------------------------------------------------------
Initialise(void)200 bool CWKSP_Tool_Manager::Initialise(void)
201 {
202 CONFIG_Read("/TOOLS", "DLG_INFO", CDLG_Parameters::m_bInfo);
203
204 CONFIG_Read("/TOOLS", &m_Parameters);
205
206 CONFIG_Do_Save(m_Parameters("SAVE_CONFIG")->asBool());
207
208 g_pSAGA->Process_Set_Frequency(m_Parameters("PROCESS_UPDATE")->asInt());
209
210 #ifdef _OPENMP
211 SG_OMP_Set_Max_Num_Threads(m_Parameters("OMP_THREADS_MAX")->asInt());
212 #endif
213
214 //-----------------------------------------------------
215 #ifdef _SAGA_MSW
216 wxString Default_Path(g_pSAGA->Get_App_Path());
217 #else
218 wxString Default_Path(TOOLS_PATH);
219 #endif
220
221 //-----------------------------------------------------
222 wxString Version; bool bCompatible = CONFIG_Read("/VERSION", "SAGA" , Version) && !Version.Cmp(SAGA_VERSION);
223
224 #ifdef __GNUC__
225 if( bCompatible ) // gcc builds: don't load stored libraries when there is no abi compatibility assured!
226 {
227 long Number;
228
229 if( !CONFIG_Read("/VERSION", "GNUC" , Number) || Number != __GNUC__ )
230 {
231 bCompatible = false;
232 }
233 #ifdef __GNUC_MINOR__
234 else if( !CONFIG_Read("/VERSION", "GNUC_MINOR" , Number) || Number != __GNUC_MINOR__ )
235 {
236 bCompatible = false;
237 }
238 #ifdef __GNUC_PATCHLEVEL__
239 else if( !CONFIG_Read("/VERSION", "GNUC_PATCHLEVEL" , Number) || Number != __GNUC_PATCHLEVEL__ )
240 {
241 bCompatible = false;
242 }
243 #endif
244 #endif
245 }
246 #endif
247
248 //-----------------------------------------------------
249 if( bCompatible )
250 {
251 wxString Library;
252
253 for(int i=0; CONFIG_Read(CFG_LIBS, wxString::Format(CFG_LIBF, i), Library); i++)
254 {
255 if( !wxFileExists(Library) )
256 {
257 wxFileName fn(Library);
258
259 fn.MakeAbsolute(Default_Path);
260
261 Library = fn.GetFullPath();
262 }
263
264 SG_UI_Progress_Lock(true);
265 SG_Get_Tool_Library_Manager().Add_Library(&Library);
266 SG_UI_Progress_Lock(false);
267 }
268 }
269
270 //-----------------------------------------------------
271 if( SG_Get_Tool_Library_Manager().Get_Count() == 0 )
272 {
273 return( _Reload() );
274 }
275
276 return( _Update(false) );
277 }
278
279 //---------------------------------------------------------
Finalise(void)280 bool CWKSP_Tool_Manager::Finalise(void)
281 {
282 CONFIG_Write("/VERSION", "SAGA", SAGA_VERSION);
283
284 #ifdef __GNUC__
285 CONFIG_Write("/VERSION", "GNUC", (long)__GNUC__);
286 #ifdef __GNUC_MINOR__
287 CONFIG_Write("/VERSION", "GNUC_MINOR", (long)__GNUC_MINOR__);
288 #ifdef __GNUC_PATCHLEVEL__
289 CONFIG_Write("/VERSION", "GNUC_PATCHLEVEL", (long)__GNUC_PATCHLEVEL__);
290 #endif
291 #endif
292 #endif
293
294 CONFIG_Write("/TOOLS", "DLG_INFO", CDLG_Parameters::m_bInfo);
295
296 CONFIG_Write("/TOOLS", &m_Parameters);
297
298 //-----------------------------------------------------
299 #ifdef _SAGA_MSW
300 wxString Default_Path(g_pSAGA->Get_App_Path());
301 #else
302 wxString Default_Path(TOOLS_PATH);
303 #endif
304
305 CONFIG_Delete(CFG_LIBS);
306
307 for(int i=0, n=0; i<Get_Count(); i++)
308 {
309 CWKSP_Tool_Group *pGroup = Get_Group(i);
310
311 for(int j=0; j<pGroup->Get_Count(); j++)
312 {
313 CSG_Tool_Library *pLibrary = pGroup->Get_Library(j)->Get_Library();
314
315 if( pLibrary->Get_Type() == TOOL_CHAINS )
316 {
317 for(int j=0; j<pLibrary->Get_Count(); j++)
318 {
319 CONFIG_Write(CFG_LIBS, wxString::Format(CFG_LIBF, n++),
320 Get_FilePath_Relative(Default_Path.c_str(), pLibrary->Get_File_Name(j).c_str())
321 );
322 }
323 }
324 else
325 {
326 CONFIG_Write(CFG_LIBS, wxString::Format(CFG_LIBF, n++),
327 Get_FilePath_Relative(Default_Path.c_str(), pLibrary->Get_File_Name().c_str())
328 );
329 }
330 }
331 }
332
333 return( true );
334 }
335
336
337 ///////////////////////////////////////////////////////////
338 // //
339 ///////////////////////////////////////////////////////////
340
341 //---------------------------------------------------------
On_Parameter_Changed(CSG_Parameters * pParameters,CSG_Parameter * pParameter,int Flags)342 int CWKSP_Tool_Manager::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter, int Flags)
343 {
344 //-----------------------------------------------------
345 if( Flags & PARAMETER_CHECK_VALUES )
346 {
347 if( g_pSAGA_Frame && g_pData )
348 {
349 if( pParameter->Cmp_Identifier("LNG_FILE_DIC")
350 || pParameter->Cmp_Identifier("LOOK_TB_SIZE") )
351 {
352 if( DLG_Message_Confirm(_TL("Restart now ?"), _TL("Restart SAGA to apply the changes")) && g_pData->Close(true) )
353 {
354 m_Parameters.Assign_Values(pParameters);
355
356 g_pSAGA_Frame->Close(true);
357 }
358 }
359 }
360 }
361
362 //-----------------------------------------------------
363 return( CWKSP_Base_Manager::On_Parameter_Changed(pParameters, pParameter, Flags) );
364 }
365
366 //---------------------------------------------------------
Parameters_Changed(void)367 void CWKSP_Tool_Manager::Parameters_Changed(void)
368 {
369 CWKSP_Base_Item::Parameters_Changed();
370
371 if( m_Parameters("SAVE_CONFIG")->asBool() == false )
372 {
373 CONFIG_Write("/TOOLS", &m_Parameters);
374 }
375
376 CONFIG_Do_Save(m_Parameters("SAVE_CONFIG")->asBool());
377
378 g_pSAGA->Process_Set_Frequency(m_Parameters("PROCESS_UPDATE")->asInt());
379
380 #ifdef _OPENMP
381 SG_OMP_Set_Max_Num_Threads(m_Parameters("OMP_THREADS_MAX")->asInt());
382 #endif
383
384 m_pMenu_Tools->Update();
385 }
386
387 //---------------------------------------------------------
Do_Beep(void)388 bool CWKSP_Tool_Manager::Do_Beep(void)
389 {
390 return( m_Parameters("BEEP")->asBool() );
391 }
392
393
394 ///////////////////////////////////////////////////////////
395 // //
396 ///////////////////////////////////////////////////////////
397
398 //---------------------------------------------------------
Get_Name(void)399 wxString CWKSP_Tool_Manager::Get_Name(void)
400 {
401 return( _TL("Tool Libraries") );
402 }
403
404 //---------------------------------------------------------
Get_Description(void)405 wxString CWKSP_Tool_Manager::Get_Description(void)
406 {
407 return( SG_Get_Tool_Library_Manager().Get_Summary().c_str() );
408 }
409
410 //---------------------------------------------------------
Get_Menu(void)411 wxMenu * CWKSP_Tool_Manager::Get_Menu(void)
412 {
413 wxMenu *pMenu = new wxMenu(Get_Name());
414
415 CMD_Menu_Add_Item(pMenu, false, ID_CMD_TOOL_OPEN);
416 CMD_Menu_Add_Item(pMenu, false, ID_CMD_TOOL_RELOAD);
417
418 if( Get_Count() > 0 )
419 {
420 CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE);
421 pMenu->AppendSeparator();
422 CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_SEARCH);
423 pMenu->AppendSeparator();
424 CMD_Menu_Add_Item(pMenu, false, ID_CMD_TOOL_SAVE_DOCS);
425 }
426
427 return( pMenu );
428 }
429
430
431 ///////////////////////////////////////////////////////////
432 // //
433 ///////////////////////////////////////////////////////////
434
435 //---------------------------------------------------------
On_Command(int Cmd_ID)436 bool CWKSP_Tool_Manager::On_Command(int Cmd_ID)
437 {
438 switch( Cmd_ID )
439 {
440 default:
441 return( CWKSP_Base_Manager::On_Command(Cmd_ID) );
442
443 case ID_CMD_TOOL_OPEN:
444 Open();
445 break;
446
447 case ID_CMD_TOOL_RELOAD:
448 _Reload();
449 break;
450
451 case ID_CMD_TOOL_SEARCH:
452 {
453 CWKSP_Base_Item *pItem = g_pTool_Ctrl->Search_Item(_TL("Run Tool"), WKSP_ITEM_Tool);
454
455 if( pItem && pItem->GetId().IsOk() && pItem->Get_Type() == WKSP_ITEM_Tool )
456 {
457 ((CWKSP_Tool *)pItem)->Execute(true);
458 }
459 }
460 break;
461
462 case ID_CMD_TOOL_SAVE_DOCS:
463 {
464 wxString Path;
465
466 if( DLG_Directory(Path, _TL("Create Tool Description Files")) )
467 {
468 MSG_General_Add(wxString::Format(SG_T("%s..."), _TL("Create Tool Description Files")), true, true);
469
470 SG_Get_Tool_Library_Manager().Get_Summary(&Path);
471
472 MSG_General_Add(_TL("okay"), false, false, SG_UI_MSG_STYLE_SUCCESS);
473 }
474 }
475 break;
476 }
477
478 return( true );
479 }
480
481 //---------------------------------------------------------
On_Command_UI(wxUpdateUIEvent & event)482 bool CWKSP_Tool_Manager::On_Command_UI(wxUpdateUIEvent &event)
483 {
484 switch( event.GetId() )
485 {
486 default:
487 return( CWKSP_Base_Manager::On_Command_UI(event) );
488
489 case ID_CMD_WKSP_ITEM_CLOSE:
490 case ID_CMD_TOOL_SEARCH :
491 case ID_CMD_TOOL_SAVE_DOCS :
492 event.Enable(Get_Count() > 0 && g_pTool == NULL);
493 break;
494 }
495
496 return( true );
497 }
498
499 //---------------------------------------------------------
On_Execute(wxCommandEvent & event)500 void CWKSP_Tool_Manager::On_Execute(wxCommandEvent &event)
501 {
502 CWKSP_Tool *pTool;
503
504 if( (pTool = Get_Tool_byID(m_pMenu_Tools->Get_ID_Translated(event.GetId()))) != NULL )
505 {
506 pTool->On_Command(ID_CMD_WKSP_ITEM_RETURN);
507 }
508 }
509
510 //---------------------------------------------------------
On_Execute_UI(wxUpdateUIEvent & event)511 void CWKSP_Tool_Manager::On_Execute_UI(wxUpdateUIEvent &event)
512 {
513 if( g_pTool )
514 {
515 if( g_pTool->Get_Menu_ID() == m_pMenu_Tools->Get_ID_Translated(event.GetId()) )
516 {
517 event.Enable(true);
518 event.Check(true);
519 }
520 else
521 {
522 event.Enable(false);
523 event.Check(false);
524 }
525 }
526 else
527 {
528 event.Enable(true);
529 event.Check(false);
530 }
531 }
532
533
534 ///////////////////////////////////////////////////////////
535 // //
536 ///////////////////////////////////////////////////////////
537
538 //---------------------------------------------------------
Get_Group(const wxString & Group)539 CWKSP_Tool_Group * CWKSP_Tool_Manager::Get_Group(const wxString &Group)
540 {
541 for(int i=0; i<Get_Count(); i++)
542 {
543 if( !Group.Cmp(Get_Group(i)->Get_Name()) )
544 {
545 return( Get_Group(i) );
546 }
547 }
548
549 return( NULL );
550 }
551
552 //---------------------------------------------------------
Get_Library(CSG_Tool_Library * pLibrary)553 CWKSP_Tool_Library * CWKSP_Tool_Manager::Get_Library(CSG_Tool_Library *pLibrary)
554 {
555 for(int i=0; i<Get_Count(); i++)
556 {
557 CWKSP_Tool_Group *pGroup = Get_Group(i);
558
559 for(int j=0; j<pGroup->Get_Count(); j++)
560 {
561 if( pLibrary == pGroup->Get_Library(j)->Get_Library() )
562 {
563 return( pGroup->Get_Library(j) );
564 }
565 }
566 }
567
568 return( NULL );
569 }
570
571 //---------------------------------------------------------
_Reload(void)572 bool CWKSP_Tool_Manager::_Reload(void)
573 {
574 #ifdef _SAGA_MSW
575 SG_Get_Tool_Library_Manager().Add_Directory(SG_File_Make_Path(&g_pSAGA->Get_App_Path(), "tools"));
576 #else // #ifdef _SAGA_LINUX
577 SG_Get_Tool_Library_Manager().Add_Directory(TOOLS_PATH);
578 SG_Get_Tool_Library_Manager().Add_Directory(SG_File_Make_Path(SHARE_PATH, "toolchains")); // look for tool chains
579 #endif
580
581 wxString Path;
582
583 if( wxGetEnv("SAGA_TLB", &Path) )
584 {
585 #ifdef _SAGA_MSW
586 CSG_Strings Paths = SG_String_Tokenize(&Path, ";" ); // colon (':') would split drive from paths!
587 #else // #ifdef _SAGA_LINUX
588 CSG_Strings Paths = SG_String_Tokenize(&Path, ";:"); // colon (':') is more native to non-windows os than semi-colon (';'), we support both...
589 #endif
590
591 for(int i=0; i<Paths.Get_Count(); i++)
592 {
593 SG_Get_Tool_Library_Manager().Add_Directory(Paths[i]);
594 }
595 }
596
597 return( _Update(false) );
598 }
599
600 //---------------------------------------------------------
_Update(bool bSyncToCtrl)601 bool CWKSP_Tool_Manager::_Update(bool bSyncToCtrl)
602 {
603 if( !bSyncToCtrl )
604 {
605 // Get_Control()->Freeze();
606
607 for(int i=SG_Get_Tool_Library_Manager().Get_Count()-1; i>=0; i--)
608 {
609 CSG_Tool_Library *pLibrary = SG_Get_Tool_Library_Manager().Get_Library(i);
610 CWKSP_Tool_Library *pItem = Get_Library(pLibrary);
611
612 if( !pItem )
613 {
614 CWKSP_Tool_Group *pGroup = Get_Group(pLibrary->Get_Category().c_str());
615
616 if( !pGroup )
617 {
618 Add_Item(pGroup = new CWKSP_Tool_Group(pLibrary->Get_Category().c_str()));
619 }
620
621 pGroup->Add_Library(pLibrary);
622 }
623 else if( pItem->Get_Library()->Get_Type() == TOOL_CHAINS )
624 {
625 pItem->Update();
626 }
627 }
628
629 // Get_Control()->Thaw();
630 }
631
632 m_pMenu_Tools->Update();
633
634 return( true );
635 }
636
637 //---------------------------------------------------------
Update(void)638 bool CWKSP_Tool_Manager::Update(void)
639 {
640 return( _Update(true) );
641 }
642
643
644 ///////////////////////////////////////////////////////////
645 // //
646 ///////////////////////////////////////////////////////////
647
648 //---------------------------------------------------------
Get_Menu_Tools(void)649 wxMenu * CWKSP_Tool_Manager::Get_Menu_Tools(void)
650 {
651 return( m_pMenu_Tools->Get_Menu() );
652 }
653
654 //---------------------------------------------------------
Set_Recently_Used(CWKSP_Tool * pTool)655 void CWKSP_Tool_Manager::Set_Recently_Used(CWKSP_Tool *pTool)
656 {
657 m_pMenu_Tools->Set_Recent(pTool);
658 }
659
660
661 ///////////////////////////////////////////////////////////
662 // //
663 ///////////////////////////////////////////////////////////
664
665 //---------------------------------------------------------
Open(void)666 void CWKSP_Tool_Manager::Open(void)
667 {
668 wxArrayString File_Paths;
669
670 if( DLG_Open(File_Paths, ID_DLG_TOOL_OPEN) )
671 {
672 MSG_General_Add_Line();
673
674 bool bUpdate = false;
675
676 for(size_t i=0; i<File_Paths.GetCount(); i++)
677 {
678 if( SG_Get_Tool_Library_Manager().Add_Library(&File_Paths[i]) )
679 {
680 bUpdate = true;
681 }
682 }
683
684 if( bUpdate )
685 {
686 _Update(false);
687 }
688 }
689 }
690
691 //---------------------------------------------------------
Open(const wxString & File_Name)692 bool CWKSP_Tool_Manager::Open(const wxString &File_Name)
693 {
694 if( SG_Get_Tool_Library_Manager().Add_Library(&File_Name) )
695 {
696 _Update(false);
697
698 return( true );
699 }
700
701 return( false );
702 }
703
704
705 ///////////////////////////////////////////////////////////
706 // //
707 ///////////////////////////////////////////////////////////
708
709 //---------------------------------------------------------
Exists(CWKSP_Tool * pTool)710 bool CWKSP_Tool_Manager::Exists(CWKSP_Tool *pTool)
711 {
712 for(int i=0; i<Get_Count(); i++)
713 {
714 CWKSP_Tool_Group *pGroup = Get_Group(i);
715
716 for(int j=0; j<pGroup->Get_Count(); j++)
717 {
718 if( pGroup->Get_Library(j)->Get_Tool(pTool) != NULL )
719 {
720 return( true );
721 }
722 }
723 }
724
725 return( false );
726 }
727
728 //---------------------------------------------------------
Get_Tool_byID(int CMD_ID)729 CWKSP_Tool * CWKSP_Tool_Manager::Get_Tool_byID(int CMD_ID)
730 {
731 CWKSP_Tool *pTool;
732
733 for(int i=0; i<Get_Count(); i++)
734 {
735 CWKSP_Tool_Group *pGroup = Get_Group(i);
736
737 for(int j=0; j<pGroup->Get_Count(); j++)
738 {
739 if( (pTool = pGroup->Get_Library(j)->Get_Tool_byID(CMD_ID)) != NULL )
740 {
741 return( pTool );
742 }
743 }
744 }
745
746 return( NULL );
747 }
748
749
750 ///////////////////////////////////////////////////////////
751 // //
752 // //
753 // //
754 ///////////////////////////////////////////////////////////
755
756 //---------------------------------------------------------
CWKSP_Tool_Group(const wxString & Name)757 CWKSP_Tool_Group::CWKSP_Tool_Group(const wxString &Name)
758 {
759 m_Name = Name;
760 }
761
762 //---------------------------------------------------------
~CWKSP_Tool_Group(void)763 CWKSP_Tool_Group::~CWKSP_Tool_Group(void)
764 {}
765
766
767 ///////////////////////////////////////////////////////////
768 // //
769 ///////////////////////////////////////////////////////////
770
771 //---------------------------------------------------------
772 #define SUMMARY_ADD_STR(label, value) wxString::Format("<tr><td valign=\"top\"><b>%s</b></td><td valign=\"top\">%s</td></tr>", label, value)
773 #define SUMMARY_ADD_INT(label, value) wxString::Format("<tr><td valign=\"top\"><b>%s</b></td><td valign=\"top\">%d</td></tr>", label, value)
774
775 //---------------------------------------------------------
Get_Description(void)776 wxString CWKSP_Tool_Group::Get_Description(void)
777 {
778 wxString s;
779
780 s += wxString::Format("<h4>%s</h4>", _TL("Tool Libraries"));
781
782 s += "<table border=\"0\">";
783
784 s += SUMMARY_ADD_STR(_TL("Category" ), Get_Name().c_str());
785 s += SUMMARY_ADD_INT(_TL("Libraries"), Get_Count());
786
787 s += "</table>";
788
789 //-----------------------------------------------------
790 s += wxString::Format("<hr><h4>%s</h4><table border=\"0\">", _TL("Tool Libraries"));
791
792 s += wxString::Format("<tr align=\"left\"><th>%s</th><th>%s</th><th>%s</th></tr>",
793 _TL("Library"),
794 _TL("Name" ),
795 _TL("Tools" )
796 );
797
798 for(int i=0; i<Get_Count(); i++)
799 {
800 s += wxString::Format("<tr><td valign=\"top\"><i>%s</i></td><td valign=\"top\">%s</td><td valign=\"top\" align=\"right\">%d</td></tr>",
801 Get_Library(i)->Get_Library()->Get_Library_Name().c_str(),
802 Get_Library(i)->Get_Name().c_str(),
803 Get_Library(i)->Get_Count()
804 );
805 }
806
807 s += "</table>";
808
809 return( s );
810 }
811
812
813 ///////////////////////////////////////////////////////////
814 // //
815 ///////////////////////////////////////////////////////////
816
817 //---------------------------------------------------------
Get_Menu(void)818 wxMenu * CWKSP_Tool_Group::Get_Menu(void)
819 {
820 wxMenu *pMenu = new wxMenu(Get_Name());
821
822 CMD_Menu_Add_Item(pMenu, false, ID_CMD_TOOL_OPEN);
823 CMD_Menu_Add_Item(pMenu, false, ID_CMD_TOOL_RELOAD);
824 CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE);
825 pMenu->AppendSeparator();
826 CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_SEARCH);
827
828 return( pMenu );
829 }
830
831
832 ///////////////////////////////////////////////////////////
833 // //
834 ///////////////////////////////////////////////////////////
835
836 //---------------------------------------------------------
On_Command(int Cmd_ID)837 bool CWKSP_Tool_Group::On_Command(int Cmd_ID)
838 {
839 // switch( Cmd_ID )
840 {
841 // default:
842 return( CWKSP_Base_Manager::On_Command(Cmd_ID) );
843 }
844 }
845
846 //---------------------------------------------------------
On_Command_UI(wxUpdateUIEvent & event)847 bool CWKSP_Tool_Group::On_Command_UI(wxUpdateUIEvent &event)
848 {
849 // switch( event.GetId() )
850 {
851 // default:
852 return( CWKSP_Base_Manager::On_Command_UI(event) );
853 }
854 }
855
856
857 ///////////////////////////////////////////////////////////
858 // //
859 ///////////////////////////////////////////////////////////
860
861 //---------------------------------------------------------
Add_Library(CSG_Tool_Library * pLibrary)862 bool CWKSP_Tool_Group::Add_Library(CSG_Tool_Library *pLibrary)
863 {
864 return( pLibrary && Add_Item(new CWKSP_Tool_Library(pLibrary)) );
865 }
866
867 //---------------------------------------------------------
Get_Library(CSG_Tool_Library * pLibrary)868 CWKSP_Tool_Library * CWKSP_Tool_Group::Get_Library(CSG_Tool_Library *pLibrary)
869 {
870 for(int i=0; i<Get_Count(); i++)
871 {
872 if( pLibrary == Get_Library(i)->Get_Library() )
873 {
874 return( Get_Library(i) );
875 }
876 }
877
878 return( NULL );
879 }
880
881
882 ///////////////////////////////////////////////////////////
883 // //
884 // //
885 // //
886 ///////////////////////////////////////////////////////////
887
888 //---------------------------------------------------------
889