1
2 ///////////////////////////////////////////////////////////
3 // //
4 // SAGA //
5 // //
6 // System for Automated Geoscientific Analyses //
7 // //
8 // Application Programming Interface //
9 // //
10 // Library: SAGA_API //
11 // //
12 //-------------------------------------------------------//
13 // //
14 // tool_library.cpp //
15 // //
16 // Copyright (C) 2006 by Olaf Conrad //
17 // //
18 //-------------------------------------------------------//
19 // //
20 // This file is part of 'SAGA - System for Automated //
21 // Geoscientific Analyses'. //
22 // //
23 // This library is free software; you can redistribute //
24 // it and/or modify it under the terms of the GNU Lesser //
25 // General Public License as published by the Free //
26 // Software Foundation, either version 2.1 of the //
27 // License, or (at your option) any later version. //
28 // //
29 // This library is distributed in the hope that it will //
30 // be useful, but WITHOUT ANY WARRANTY; without even the //
31 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
32 // PARTICULAR PURPOSE. See the GNU Lesser General Public //
33 // License for more details. //
34 // //
35 // You should have received a copy of the GNU Lesser //
36 // General Public License along with this program; if //
37 // not, see <http://www.gnu.org/licenses/>. //
38 // //
39 //-------------------------------------------------------//
40 // //
41 // contact: Olaf Conrad //
42 // Institute of Geography //
43 // University of Goettingen //
44 // Goldschmidtstr. 5 //
45 // 37077 Goettingen //
46 // Germany //
47 // //
48 // e-mail: oconrad@saga-gis.org //
49 // //
50 ///////////////////////////////////////////////////////////
51
52 //---------------------------------------------------------
53 #include <wx/dynlib.h>
54 #include <wx/dir.h>
55 #include <wx/filename.h>
56 #include <wx/utils.h>
57
58 #include "tool_chain.h"
59
60
61 ///////////////////////////////////////////////////////////
62 // //
63 // //
64 // //
65 ///////////////////////////////////////////////////////////
66
67 //---------------------------------------------------------
CSG_Tool_Library(void)68 CSG_Tool_Library::CSG_Tool_Library(void)
69 {
70 m_pInterface = NULL;
71 m_pLibrary = NULL;
72 }
73
74 //---------------------------------------------------------
CSG_Tool_Library(const CSG_String & File)75 CSG_Tool_Library::CSG_Tool_Library(const CSG_String &File)
76 {
77 m_pLibrary = new wxDynamicLibrary(SG_File_Get_Path_Absolute(File).c_str(), wxDL_DEFAULT|wxDL_QUIET);
78
79 if( m_pLibrary->IsLoaded()
80 && m_pLibrary->HasSymbol(SYMBOL_TLB_Get_Interface)
81 && m_pLibrary->HasSymbol(SYMBOL_TLB_Initialize)
82 && m_pLibrary->HasSymbol(SYMBOL_TLB_Finalize)
83 && ((TSG_PFNC_TLB_Initialize)m_pLibrary->GetSymbol(SYMBOL_TLB_Initialize))(File) )
84 {
85 m_pInterface = ((TSG_PFNC_TLB_Get_Interface)m_pLibrary->GetSymbol(SYMBOL_TLB_Get_Interface))();
86
87 if( m_pInterface->Get_Count() > 0 )
88 {
89 m_File_Name = m_pInterface->Get_Info(TLB_INFO_File );
90 m_Library_Name = m_pInterface->Get_Info(TLB_INFO_Library);
91
92 return; // success
93 }
94 }
95
96 _Destroy();
97 }
98
99 //---------------------------------------------------------
~CSG_Tool_Library(void)100 CSG_Tool_Library::~CSG_Tool_Library(void)
101 {
102 _Destroy();
103 }
104
105 //---------------------------------------------------------
_Destroy(void)106 bool CSG_Tool_Library::_Destroy(void)
107 {
108 if( m_pLibrary )
109 {
110 if( m_pLibrary->IsLoaded() && m_pLibrary->HasSymbol(SYMBOL_TLB_Finalize) )
111 {
112 TSG_PFNC_TLB_Finalize TLB_Finalize = (TSG_PFNC_TLB_Finalize)m_pLibrary->GetSymbol(SYMBOL_TLB_Finalize);
113
114 TLB_Finalize();
115 }
116
117 delete(m_pLibrary);
118
119 m_pLibrary = NULL;
120 }
121
122 m_pInterface = NULL;
123
124 return( true );
125 }
126
127
128 ///////////////////////////////////////////////////////////
129 // //
130 ///////////////////////////////////////////////////////////
131
132 //---------------------------------------------------------
Get_Info(int Type) const133 CSG_String CSG_Tool_Library::Get_Info(int Type) const
134 {
135 if( m_pInterface != NULL )
136 {
137 return( m_pInterface->Get_Info(Type) );
138 }
139
140 return( "" );
141 }
142
143
144 ///////////////////////////////////////////////////////////
145 // //
146 ///////////////////////////////////////////////////////////
147
148 //---------------------------------------------------------
Get_Tool(int Index,TSG_Tool_Type Type) const149 CSG_Tool * CSG_Tool_Library::Get_Tool(int Index, TSG_Tool_Type Type) const
150 {
151 CSG_Tool *pTool = m_pInterface && Index >= 0 && Index < Get_Count() ? m_pInterface->Get_Tool(Index) : NULL;
152
153 return( pTool && (Type == TOOL_TYPE_Base || Type == pTool->Get_Type()) ? pTool : NULL );
154 }
155
156 //---------------------------------------------------------
Get_Tool(const char * Name,TSG_Tool_Type Type) const157 CSG_Tool * CSG_Tool_Library::Get_Tool(const char *Name, TSG_Tool_Type Type) const { return( Get_Tool(CSG_String(Name), Type) ); }
Get_Tool(const wchar_t * Name,TSG_Tool_Type Type) const158 CSG_Tool * CSG_Tool_Library::Get_Tool(const wchar_t *Name, TSG_Tool_Type Type) const { return( Get_Tool(CSG_String(Name), Type) ); }
Get_Tool(const CSG_String & Name,TSG_Tool_Type Type) const159 CSG_Tool * CSG_Tool_Library::Get_Tool(const CSG_String &Name, TSG_Tool_Type Type) const
160 {
161 for(int i=0; i<Get_Count(); i++)
162 {
163 CSG_Tool *pTool = Get_Tool(i, Type);
164
165 if( pTool && (!pTool->Get_ID().Cmp(Name) || !pTool->Get_Name().Cmp(Name)) )
166 {
167 return( pTool );
168 }
169 }
170
171 return( NULL );
172 }
173
174
175 ///////////////////////////////////////////////////////////
176 // //
177 ///////////////////////////////////////////////////////////
178
179 //---------------------------------------------------------
180 /**
181 * Creates a new instance of the requested tool in addition
182 * to the standard-wise created instance that you can request
183 * with the 'Get_Tool() functions. Tools created with this
184 * function are collected in a separate internal list and can
185 * be removed from memory with the 'Delete_Tool()' function.
186 * This way of tool creation is necessary, if you want to run
187 * a tool simultaneously with different settings.
188 */
189 //---------------------------------------------------------
Create_Tool(int Index,bool bWithGUI)190 CSG_Tool * CSG_Tool_Library::Create_Tool(int Index, bool bWithGUI)
191 {
192 return( m_pInterface ? m_pInterface->Create_Tool(Index, bWithGUI) : NULL );
193 }
194
195 //---------------------------------------------------------
Create_Tool(const char * Name,bool bWithGUI)196 CSG_Tool * CSG_Tool_Library::Create_Tool(const char *Name, bool bWithGUI) { return( Create_Tool(CSG_String(Name), bWithGUI) ); }
Create_Tool(const wchar_t * Name,bool bWithGUI)197 CSG_Tool * CSG_Tool_Library::Create_Tool(const wchar_t *Name, bool bWithGUI) { return( Create_Tool(CSG_String(Name), bWithGUI) ); }
Create_Tool(const CSG_String & Name,bool bWithGUI)198 CSG_Tool * CSG_Tool_Library::Create_Tool(const CSG_String &Name, bool bWithGUI)
199 {
200 int Index; return( Name.asInt(Index) ? Create_Tool(Index, bWithGUI) : NULL );
201 }
202
203 //---------------------------------------------------------
204 /**
205 * Deletes a tool that has been created previously with a call
206 * to the 'Create_Tool()' function.
207 */
208 //---------------------------------------------------------
Delete_Tool(CSG_Tool * pTool)209 bool CSG_Tool_Library::Delete_Tool(CSG_Tool *pTool)
210 {
211 return( m_pInterface ? m_pInterface->Delete_Tool(pTool) : false );
212 }
213
214 //---------------------------------------------------------
Delete_Tools(void)215 bool CSG_Tool_Library::Delete_Tools(void)
216 {
217 return( m_pInterface ? m_pInterface->Delete_Tools() : false );
218 }
219
220
221 ///////////////////////////////////////////////////////////
222 // //
223 ///////////////////////////////////////////////////////////
224
225 //---------------------------------------------------------
Get_Menu(int i) const226 CSG_String CSG_Tool_Library::Get_Menu(int i) const
227 {
228 if( Get_Tool(i) )
229 {
230 return( Get_Tool(i)->Get_MenuPath(true) );
231 }
232
233 return( "" );
234 }
235
236
237 ///////////////////////////////////////////////////////////
238 // //
239 ///////////////////////////////////////////////////////////
240
241 //---------------------------------------------------------
Add_Reference(const CSG_String & Authors,const CSG_String & Year,const CSG_String & Title,const CSG_String & Where,const SG_Char * Link,const SG_Char * Link_Text)242 void CSG_Tool_Library::Add_Reference(const CSG_String &Authors, const CSG_String &Year, const CSG_String &Title, const CSG_String &Where, const SG_Char *Link, const SG_Char *Link_Text)
243 {
244 CSG_String Reference = Authors;
245
246 Reference.Printf("<b>%s (%s):</b> %s. %s", Authors.c_str(), Year.c_str(), Title.c_str(), Where.c_str());
247
248 if( Link && *Link )
249 {
250 Reference += CSG_String::Format(" <a href=\"%s\">%s</a>.", Link, Link_Text && *Link_Text ? Link_Text : Link);
251 }
252
253 if( !Reference.is_Empty() )
254 {
255 m_References += Reference;
256 }
257
258 m_References.Sort();
259 }
260
261 //---------------------------------------------------------
Add_Reference(const CSG_String & Link,const SG_Char * Link_Text)262 void CSG_Tool_Library::Add_Reference(const CSG_String &Link, const SG_Char *Link_Text)
263 {
264 m_References += CSG_String::Format("<a href=\"%s\">%s</a>", Link.c_str(), Link_Text && *Link_Text ? Link_Text : Link.c_str());
265
266 m_References.Sort();
267 }
268
269 //---------------------------------------------------------
Del_References(void)270 void CSG_Tool_Library::Del_References(void)
271 {
272 m_References.Clear();
273 }
274
275
276 ///////////////////////////////////////////////////////////
277 // //
278 // //
279 // //
280 ///////////////////////////////////////////////////////////
281
282 //---------------------------------------------------------
283 CSG_Tool_Library_Manager g_Tool_Library_Manager;
284
285 //---------------------------------------------------------
SG_Get_Tool_Library_Manager(void)286 CSG_Tool_Library_Manager & SG_Get_Tool_Library_Manager (void)
287 {
288 return( g_Tool_Library_Manager );
289 }
290
291
292 ///////////////////////////////////////////////////////////
293 // //
294 ///////////////////////////////////////////////////////////
295
296 //---------------------------------------------------------
CSG_Tool_Library_Manager(void)297 CSG_Tool_Library_Manager::CSG_Tool_Library_Manager(void)
298 {
299 m_pLibraries = NULL;
300 m_nLibraries = 0;
301
302 if( this == &g_Tool_Library_Manager )
303 {
304 CSG_Random::Initialize(); // initialize with current time on startup
305 }
306 }
307
308 //---------------------------------------------------------
~CSG_Tool_Library_Manager(void)309 CSG_Tool_Library_Manager::~CSG_Tool_Library_Manager(void)
310 {
311 Destroy();
312 }
313
314
315 ///////////////////////////////////////////////////////////
316 // //
317 ///////////////////////////////////////////////////////////
318
319 //---------------------------------------------------------
Get_Tool_Count(void) const320 int CSG_Tool_Library_Manager::Get_Tool_Count(void) const
321 {
322 int nTools = 0;
323
324 for(int i=0; i<m_nLibraries; i++)
325 {
326 nTools += m_pLibraries[i]->Get_Count();
327 }
328
329 return( nTools );
330 }
331
332
333 ///////////////////////////////////////////////////////////
334 // //
335 ///////////////////////////////////////////////////////////
336
337 //---------------------------------------------------------
Add_Library(const CSG_String & File)338 CSG_Tool_Library * CSG_Tool_Library_Manager::Add_Library(const CSG_String &File)
339 {
340 //-----------------------------------------------------
341 if( !SG_File_Cmp_Extension(File, "mlb" )
342 && !SG_File_Cmp_Extension(File, "dll" )
343 && !SG_File_Cmp_Extension(File, "so" )
344 && !SG_File_Cmp_Extension(File, "dylib") )
345 {
346 return( _Add_Tool_Chain(File) );
347 }
348
349 //-----------------------------------------------------
350 SG_UI_Msg_Add(CSG_String::Format("%s: %s...", _TL("Loading library"), File.c_str()), true);
351
352 wxFileName fn(File.c_str());
353
354 for(int i=0; i<Get_Count(); i++)
355 {
356 if( fn == Get_Library(i)->Get_File_Name().c_str() )
357 {
358 SG_UI_Msg_Add(_TL("has already been loaded"), false);
359
360 return( NULL );
361 }
362 }
363
364 //-----------------------------------------------------
365 CSG_Tool_Library *pLibrary = new CSG_Tool_Library(File);
366
367 if( pLibrary->is_Valid() )
368 {
369 m_pLibraries = (CSG_Tool_Library **)SG_Realloc(m_pLibraries, (m_nLibraries + 1) * sizeof(CSG_Tool_Library *));
370 m_pLibraries[m_nLibraries++] = pLibrary;
371
372 SG_UI_Msg_Add(_TL("okay"), false, SG_UI_MSG_STYLE_SUCCESS);
373
374 return( pLibrary );
375 }
376
377 delete(pLibrary);
378
379 SG_UI_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE);
380
381 return( NULL );
382 }
383
Add_Library(const char * File)384 CSG_Tool_Library * CSG_Tool_Library_Manager::Add_Library(const char *File)
385 {
386 return( Add_Library(CSG_String(File)) );
387 }
388
Add_Library(const wchar_t * File)389 CSG_Tool_Library * CSG_Tool_Library_Manager::Add_Library(const wchar_t *File)
390 {
391 return( Add_Library(CSG_String(File)) );
392 }
393
394 //---------------------------------------------------------
Add_Directory(const CSG_String & Directory,bool bOnlySubDirectories)395 int CSG_Tool_Library_Manager::Add_Directory(const CSG_String &Directory, bool bOnlySubDirectories)
396 {
397 int nOpened = 0;
398 wxDir Dir;
399
400 if( Dir.Open(Directory.c_str()) )
401 {
402 wxString FileName, DirName(Dir.GetName());
403
404 if( !bOnlySubDirectories && Dir.GetFirst(&FileName, wxEmptyString, wxDIR_FILES) )
405 {
406 do
407 { if( FileName.Find("saga_") < 0 && FileName.Find("wx") < 0 )
408 if( Add_Library(SG_File_Make_Path(&DirName, &FileName)) )
409 {
410 nOpened++;
411 }
412 }
413 while( Dir.GetNext(&FileName) );
414 }
415
416 if( Dir.GetFirst(&FileName, wxEmptyString, wxDIR_DIRS) )
417 {
418 do
419 {
420 if( FileName.CmpNoCase("dll") )
421 {
422 nOpened += Add_Directory(SG_File_Make_Path(&DirName, &FileName), false);
423 }
424 }
425 while( Dir.GetNext(&FileName) );
426 }
427 }
428
429 return( nOpened );
430 }
431
Add_Directory(const char * Directory,bool bOnlySubDirectories)432 int CSG_Tool_Library_Manager::Add_Directory(const char *Directory, bool bOnlySubDirectories)
433 {
434 return( Add_Directory(CSG_String(Directory), bOnlySubDirectories) );
435 }
436
Add_Directory(const wchar_t * Directory,bool bOnlySubDirectories)437 int CSG_Tool_Library_Manager::Add_Directory(const wchar_t *Directory, bool bOnlySubDirectories)
438 {
439 return( Add_Directory(CSG_String(Directory), bOnlySubDirectories) );
440 }
441
442
443 ///////////////////////////////////////////////////////////
444 // //
445 ///////////////////////////////////////////////////////////
446
447 //---------------------------------------------------------
_Add_Tool_Chain(const CSG_String & File)448 CSG_Tool_Library * CSG_Tool_Library_Manager::_Add_Tool_Chain(const CSG_String &File)
449 {
450 //-----------------------------------------------------
451 if( !SG_File_Cmp_Extension(File, "xml") )
452 {
453 return( NULL );
454 }
455
456 //-----------------------------------------------------
457 CSG_Tool_Chains *pLibrary = NULL;
458 CSG_Tool_Chain *pTool = NULL;
459
460 //-----------------------------------------------------
461 { // is tool chain already loaded ?
462 wxFileName fn(File.c_str());
463
464 for(int iLibrary=0; !pTool && iLibrary<Get_Count(); iLibrary++)
465 {
466 if( Get_Library(iLibrary)->Get_Type() == TOOL_CHAINS )
467 {
468 for(int iTool=0; !pTool && iTool<Get_Library(iLibrary)->Get_Count(); iTool++)
469 {
470 if( fn == ((CSG_Tool_Chain *)Get_Library(iLibrary)->Get_Tool(iTool))->Get_File_Name().c_str() )
471 {
472 pLibrary = (CSG_Tool_Chains *)Get_Library(iLibrary);
473 pTool = (CSG_Tool_Chain *)Get_Library(iLibrary)->Get_Tool(iTool);
474 }
475 }
476 }
477 }
478
479 if( pTool ) // ...then try to reload !
480 {
481 SG_UI_ProgressAndMsg_Lock(true);
482 CSG_Tool_Chain Tool(File); // don't reset loaded tool in case reloading fails!!!
483 SG_UI_ProgressAndMsg_Lock(false);
484
485 if( Tool.is_Okay() )
486 {
487 pTool->Create(File);
488 }
489
490 return( pLibrary );
491 }
492 }
493
494 //-----------------------------------------------------
495 pTool = new CSG_Tool_Chain(File);
496
497 if( !pTool || !pTool->is_Okay() )
498 {
499 if( pTool )
500 {
501 delete(pTool);
502 }
503
504 return( NULL );
505 }
506
507 //-----------------------------------------------------
508 CSG_String Library = pTool->Get_Library();
509
510 for(int iLibrary=0; !pLibrary && iLibrary<Get_Count(); iLibrary++)
511 {
512 if( Get_Library(iLibrary)->Get_Type() == TOOL_CHAINS
513 && Get_Library(iLibrary)->Get_Library_Name().Cmp(Library) == 0 )
514 {
515 pLibrary = (CSG_Tool_Chains *)Get_Library(iLibrary);
516 }
517 }
518
519 if( !pLibrary && (pLibrary = new CSG_Tool_Chains(pTool->Get_Library(), SG_File_Get_Path(File))) != NULL )
520 {
521 m_pLibraries = (CSG_Tool_Library **)SG_Realloc(m_pLibraries, (m_nLibraries + 1) * sizeof(CSG_Tool_Library *));
522 m_pLibraries[m_nLibraries++] = pLibrary;
523 }
524
525 if( !pLibrary ) // this should never happen, but who knows...
526 {
527 SG_UI_Msg_Add_Error(CSG_String::Format("%s %s: %s", _TL("ERROR"), _TL("tool chain library"), File.c_str()));
528
529 delete(pTool);
530
531 return( NULL );
532 }
533
534 pLibrary->Add_Tool(pTool);
535
536 //-----------------------------------------------------
537 return( pLibrary );
538 }
539
540
541 ///////////////////////////////////////////////////////////
542 // //
543 ///////////////////////////////////////////////////////////
544
545 //---------------------------------------------------------
Destroy(void)546 bool CSG_Tool_Library_Manager::Destroy(void)
547 {
548 if( m_pLibraries )
549 {
550 for(int i=0; i<Get_Count(); i++)
551 {
552 // #ifndef _SAGA_MSW
553 if( !SG_UI_Get_Window_Main() && m_pLibraries[i]->m_pLibrary )
554 {
555 m_pLibraries[i]->m_pLibrary->Detach();
556 }
557 // #endif
558
559 delete(m_pLibraries[i]);
560 }
561
562 SG_Free(m_pLibraries);
563
564 m_pLibraries = NULL;
565 m_nLibraries = 0;
566 }
567
568 return( true );
569 }
570
571
572 ///////////////////////////////////////////////////////////
573 // //
574 ///////////////////////////////////////////////////////////
575
576 //---------------------------------------------------------
Del_Library(CSG_Tool_Library * pLibrary)577 bool CSG_Tool_Library_Manager::Del_Library(CSG_Tool_Library *pLibrary)
578 {
579 for(int i=0; i<Get_Count(); i++)
580 {
581 if( pLibrary == Get_Library(i) )
582 {
583 return( Del_Library(i) );
584 }
585 }
586
587 return( false );
588 }
589
590 //---------------------------------------------------------
Del_Library(int i)591 bool CSG_Tool_Library_Manager::Del_Library(int i)
592 {
593 if( i >= 0 && i < Get_Count() )
594 {
595 delete(m_pLibraries[i]);
596
597 for(m_nLibraries--; i<m_nLibraries; i++)
598 {
599 m_pLibraries[i] = m_pLibraries[i + 1];
600 }
601
602 m_pLibraries = (CSG_Tool_Library **)SG_Realloc(m_pLibraries, m_nLibraries * sizeof(CSG_Tool_Library *));
603
604 return( true );
605 }
606
607 return( false );
608 }
609
610
611 ///////////////////////////////////////////////////////////
612 // //
613 ///////////////////////////////////////////////////////////
614
615 //---------------------------------------------------------
Get_Library(const CSG_String & Name,bool bLibrary) const616 CSG_Tool_Library * CSG_Tool_Library_Manager::Get_Library(const CSG_String &Name, bool bLibrary) const
617 {
618 for(int i=0; i<Get_Count(); i++)
619 {
620 CSG_Tool_Library *pLibrary = Get_Library(i);
621
622 if( !Name.Cmp(bLibrary ? pLibrary->Get_Library_Name() : pLibrary->Get_Name()) )
623 {
624 return( pLibrary );
625 }
626 }
627
628 return( NULL );
629 }
630
Get_Library(const char * Name,bool bLibrary) const631 CSG_Tool_Library * CSG_Tool_Library_Manager::Get_Library(const char *Name, bool bLibrary) const
632 {
633 return( Get_Library(CSG_String(Name), bLibrary) );
634 }
635
Get_Library(const wchar_t * Name,bool bLibrary) const636 CSG_Tool_Library * CSG_Tool_Library_Manager::Get_Library(const wchar_t *Name, bool bLibrary) const
637 {
638 return( Get_Library(CSG_String(Name), bLibrary) );
639 }
640
641 //---------------------------------------------------------
is_Loaded(CSG_Tool_Library * pLibrary) const642 bool CSG_Tool_Library_Manager::is_Loaded(CSG_Tool_Library *pLibrary) const
643 {
644 for(int i=0; i<Get_Count(); i++)
645 {
646 if( pLibrary == Get_Library(i) )
647 {
648 return( true );
649 }
650 }
651
652 return( false );
653 }
654
655
656 ///////////////////////////////////////////////////////////
657 // //
658 ///////////////////////////////////////////////////////////
659
660 //---------------------------------------------------------
Get_Tool(const char * Library,int ID) const661 CSG_Tool * CSG_Tool_Library_Manager::Get_Tool(const char *Library, int ID) const { return( Get_Tool(CSG_String(Library), ID) ); }
Get_Tool(const wchar_t * Library,int ID) const662 CSG_Tool * CSG_Tool_Library_Manager::Get_Tool(const wchar_t *Library, int ID) const { return( Get_Tool(CSG_String(Library), ID) ); }
Get_Tool(const CSG_String & Library,int ID) const663 CSG_Tool * CSG_Tool_Library_Manager::Get_Tool(const CSG_String &Library, int ID) const
664 {
665 return( Get_Tool(Library, CSG_String::Format("%d", ID)) );
666 }
667
668 //---------------------------------------------------------
Get_Tool(const char * Library,const char * Name) const669 CSG_Tool * CSG_Tool_Library_Manager::Get_Tool(const char *Library, const char *Name) const { return( Get_Tool(CSG_String(Library), CSG_String(Name)) ); }
Get_Tool(const wchar_t * Library,const wchar_t * Name) const670 CSG_Tool * CSG_Tool_Library_Manager::Get_Tool(const wchar_t *Library, const wchar_t *Name) const { return( Get_Tool(CSG_String(Library), CSG_String(Name)) ); }
Get_Tool(const CSG_String & Library,const CSG_String & Name) const671 CSG_Tool * CSG_Tool_Library_Manager::Get_Tool(const CSG_String &Library, const CSG_String &Name) const
672 {
673 for(int i=0; i<Get_Count(); i++)
674 {
675 CSG_Tool_Library *pLibrary = Get_Library(i);
676
677 if( pLibrary->Get_Library_Name().Cmp(Library) == 0 )
678 {
679 CSG_Tool *pTool = pLibrary->Get_Tool(Name);
680
681 if( pTool )
682 {
683 return( pTool );
684 }
685 }
686 }
687
688 return( NULL );
689 }
690
691
692 ///////////////////////////////////////////////////////////
693 // //
694 ///////////////////////////////////////////////////////////
695
696 //---------------------------------------------------------
Create_Tool(const char * Library,int Index,bool bWithGUI) const697 CSG_Tool * CSG_Tool_Library_Manager::Create_Tool(const char *Library, int Index, bool bWithGUI) const { return( Create_Tool(CSG_String(Library), Index, bWithGUI) ); }
Create_Tool(const wchar_t * Library,int Index,bool bWithGUI) const698 CSG_Tool * CSG_Tool_Library_Manager::Create_Tool(const wchar_t *Library, int Index, bool bWithGUI) const { return( Create_Tool(CSG_String(Library), Index, bWithGUI) ); }
Create_Tool(const CSG_String & Library,int Index,bool bWithGUI) const699 CSG_Tool * CSG_Tool_Library_Manager::Create_Tool(const CSG_String &Library, int Index, bool bWithGUI) const
700 {
701 return( Create_Tool(Library, CSG_String::Format("%d", Index), bWithGUI) );
702 }
703
704 //---------------------------------------------------------
Create_Tool(const char * Library,const char * Name,bool bWithGUI) const705 CSG_Tool * CSG_Tool_Library_Manager::Create_Tool(const char *Library, const char *Name, bool bWithGUI) const { return( Create_Tool(CSG_String(Library), CSG_String(Name), bWithGUI) ); }
Create_Tool(const wchar_t * Library,const wchar_t * Name,bool bWithGUI) const706 CSG_Tool * CSG_Tool_Library_Manager::Create_Tool(const wchar_t *Library, const wchar_t *Name, bool bWithGUI) const { return( Create_Tool(CSG_String(Library), CSG_String(Name), bWithGUI) ); }
Create_Tool(const CSG_String & Library,const CSG_String & Name,bool bWithGUI) const707 CSG_Tool * CSG_Tool_Library_Manager::Create_Tool(const CSG_String &Library, const CSG_String &Name, bool bWithGUI) const
708 {
709 for(int i=0; i<Get_Count(); i++)
710 {
711 CSG_Tool_Library *pLibrary = Get_Library(i);
712
713 if( pLibrary->Get_Library_Name().Cmp(Library) == 0 )
714 {
715 CSG_Tool *pTool = pLibrary->Create_Tool(Name, bWithGUI);
716
717 if( pTool )
718 {
719 return( pTool );
720 }
721 }
722 }
723
724 return( NULL );
725 }
726
727 //---------------------------------------------------------
Delete_Tool(CSG_Tool * pTool) const728 bool CSG_Tool_Library_Manager::Delete_Tool(CSG_Tool *pTool) const
729 {
730 for(int i=0; i<Get_Count(); i++)
731 {
732 if( Get_Library(i)->Delete_Tool(pTool) )
733 {
734 return( true );
735 }
736 }
737
738 return( false );
739 }
740
741
742 ///////////////////////////////////////////////////////////
743 // //
744 // //
745 // //
746 ///////////////////////////////////////////////////////////
747
748 //---------------------------------------------------------
749