SAGA API Version 9.12
Loading...
Searching...
No Matches
tool_library.h
Go to the documentation of this file.
1
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.h //
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// //
51
52//---------------------------------------------------------
53#ifndef HEADER_INCLUDED__SAGA_API__tool_library_H
54#define HEADER_INCLUDED__SAGA_API__tool_library_H
55
56
58// //
59// //
60// //
62
63//---------------------------------------------------------
72
73
75// //
76// //
77// //
79
80//---------------------------------------------------------
81#include "tool.h"
82
83
85// //
86// //
87// //
89
90//---------------------------------------------------------
95
96
98// //
99// //
100// //
102
103//---------------------------------------------------------
105{
107
108public:
109
110 virtual ESG_Library_Type Get_Type (void) const { return( ESG_Library_Type::Library ); }
111
112 bool is_Valid (void) const { return( Get_Count() > 0 ); }
113
114 const CSG_String & Get_File_Name (void) const { return( m_File_Name ); }
115 const CSG_String & Get_Library_Name (void) const { return( m_Library_Name ); }
116 const CSG_String & Get_Description (void) const { return( m_Description ); }
117
118 virtual const CSG_String & Get_Info (int Type) const;
119 const CSG_String & Get_Name (void) const { return( Get_Info(TLB_INFO_Name ) ); }
120 const CSG_String & Get_Author (void) const { return( Get_Info(TLB_INFO_Author ) ); }
121 const CSG_String & Get_Version (void) const { return( Get_Info(TLB_INFO_Version ) ); }
122 const CSG_String & Get_Menu (void) const { return( Get_Info(TLB_INFO_Menu_Path ) ); }
123 const CSG_String & Get_Category (void) const { return( Get_Info(TLB_INFO_Category ) ); }
124
125 CSG_String Get_Summary (int Format = SG_SUMMARY_FMT_HTML, bool bInteractive = true) const;
126 bool Get_Summary (const CSG_String &Path) const;
127
128 virtual int Get_Count (void) const { return( m_pInterface ? m_pInterface->Get_Count() : 0 ); }
129
130 virtual CSG_Tool * Get_Tool (int Index, TSG_Tool_Type Type = TOOL_TYPE_Base) const;
131 virtual CSG_Tool * Get_Tool (const CSG_String &Name, TSG_Tool_Type Type = TOOL_TYPE_Base) const;
132 virtual CSG_Tool * Get_Tool (const char *Name, TSG_Tool_Type Type = TOOL_TYPE_Base) const;
133 virtual CSG_Tool * Get_Tool (const wchar_t *Name, TSG_Tool_Type Type = TOOL_TYPE_Base) const;
134
135 virtual CSG_Tool * Create_Tool (int Index, bool bWithGUI = false, bool bWithCMD = true);
136 virtual CSG_Tool * Create_Tool (const CSG_String &Name, bool bWithGUI = false, bool bWithCMD = true);
137 virtual CSG_Tool * Create_Tool (const char *Name, bool bWithGUI = false, bool bWithCMD = true);
138 virtual CSG_Tool * Create_Tool (const wchar_t *Name, bool bWithGUI = false, bool bWithCMD = true);
139
140 virtual bool Delete_Tool (CSG_Tool *pTool);
141 virtual bool Delete_Tools (void);
142
143 virtual CSG_String Get_File_Name (int i) const { return( "" ); }
144 virtual CSG_String Get_Menu (int i) const;
145
146 bool Load_Description (void);
147
148 const CSG_Table & Get_References_Table(void) const { return( m_References ); }
149 CSG_Strings Get_References (bool bHTML = true) const;
150 bool Del_References (void);
151 void Add_Reference (const CSG_String &Authors, const CSG_String &Date, const CSG_String &Title, const CSG_String &Source, const CSG_String &Link = "", const CSG_String &Link_Text = "");
152 void Add_Reference ( const CSG_String &Link , const CSG_String &Link_Text = "");
153
154
155protected:
156
157 CSG_Tool_Library(void);
158 CSG_Tool_Library(const CSG_String &File);
159 virtual ~CSG_Tool_Library(void);
160
161
163
164
165private:
166
167 bool _Destroy (void);
168
169
170 CSG_String m_Description;
171
172 CSG_Table m_References;
173
174 CSG_Tool_Library_Interface *m_pInterface;
175
176 class wxDynamicLibrary *m_pLibrary;
177
178};
179
180
182// //
183// //
184// //
186
187//---------------------------------------------------------
189{
190public:
192 virtual ~CSG_Tool_Library_Manager(void);
193
194 bool Destroy (void);
195
196 int Get_Count (void) const { return( m_nLibraries ); }
197 int Get_Tool_Count (void) const;
198
199 bool Add_Default_Libraries (bool bVerbose = false);
200
201 CSG_Tool_Library * Add_Library (const CSG_String &File);
202 CSG_Tool_Library * Add_Library (const char *File);
203 CSG_Tool_Library * Add_Library (const wchar_t *File);
204
205 int Add_Directory (const CSG_String &Directory, bool bOnlySubDirectories = false);
206 int Add_Directory (const char *Directory, bool bOnlySubDirectories = false);
207 int Add_Directory (const wchar_t *Directory, bool bOnlySubDirectories = false);
208
209 bool Del_Library (int i);
210 bool Del_Library (CSG_Tool_Library *pLibrary);
211
212 CSG_Tool_Library * Get_Library (int i ) const { return( i >= 0 && i < Get_Count() ? m_pLibraries[i] : NULL ); }
213 CSG_Tool_Library * Get_Library (CSG_Tool *pTool) const;
214 CSG_Tool_Library * Get_Library (const CSG_String &Name, bool bLibrary, ESG_Library_Type Type = ESG_Library_Type::Undefined) const;
215 CSG_Tool_Library * Get_Library (const char *Name, bool bLibrary, ESG_Library_Type Type = ESG_Library_Type::Undefined) const;
216 CSG_Tool_Library * Get_Library (const wchar_t *Name, bool bLibrary, ESG_Library_Type Type = ESG_Library_Type::Undefined) const;
217
218 bool is_Loaded (CSG_Tool_Library *pLibrary) const;
219
220 CSG_Tool * Get_Tool (const CSG_String &Library, int Index) const;
221 CSG_Tool * Get_Tool (const char *Library, int Index) const;
222 CSG_Tool * Get_Tool (const wchar_t *Library, int Index) const;
223 CSG_Tool * Get_Tool (const CSG_String &Library, const CSG_String &Name) const;
224 CSG_Tool * Get_Tool (const char *Library, const char *Name) const;
225 CSG_Tool * Get_Tool (const wchar_t *Library, const wchar_t *Name) const;
226
227 CSG_Tool * Create_Tool (const CSG_String &Library, int Index, bool bWithGUI = false, bool bWithCMD = true) const;
228 CSG_Tool * Create_Tool (const char *Library, int Index, bool bWithGUI = false, bool bWithCMD = true) const;
229 CSG_Tool * Create_Tool (const wchar_t *Library, int Index, bool bWithGUI = false, bool bWithCMD = true) const;
230 CSG_Tool * Create_Tool (const CSG_String &Library, const CSG_String &Name, bool bWithGUI = false, bool bWithCMD = true) const;
231 CSG_Tool * Create_Tool (const char *Library, const char *Name, bool bWithGUI = false, bool bWithCMD = true) const;
232 CSG_Tool * Create_Tool (const wchar_t *Library, const wchar_t *Name, bool bWithGUI = false, bool bWithCMD = true) const;
233 bool Delete_Tool (CSG_Tool *pTool) const;
234
235 CSG_String Get_Summary (int Format = SG_SUMMARY_FMT_HTML) const;
236 bool Get_Summary (const CSG_String &Path) const;
237
238 bool Create_Python_ToolBox (const CSG_String &Destination, bool bClean = true, bool bName = true, bool bSingleFile = false, CSG_Table *pDeprecated_Names = NULL) const;
239
240
241private:
242
243 int m_nLibraries;
244
245 CSG_Tool_Library **m_pLibraries;
246
247
248 bool _Add_Library (const CSG_String &Library);
249 bool _Add_Library_Chains (const CSG_String &Library, const CSG_String &Directory);
250
251 CSG_Tool_Library * _Add_Tool_Chain (const CSG_String &File, bool bReload = true);
252
253};
254
255//---------------------------------------------------------
257
258
260// //
261// //
262// //
264
265//---------------------------------------------------------
266#define SG_RUN_TOOL(bRetVal, LIBRARY, TOOL, CONDITION) {\
267 \
268 bRetVal = false;\
269 \
270 CSG_Tool *pTool = SG_Get_Tool_Library_Manager().Create_Tool(SG_T(LIBRARY), TOOL);\
271 \
272 if( pTool == NULL )\
273 {\
274 SG_UI_Msg_Add_Error(CSG_String::Format("%s [%s]", _TL("could not find tool"), SG_T(LIBRARY)));\
275 }\
276 else\
277 {\
278 SG_UI_Process_Set_Text(pTool->Get_Name());\
279 \
280 pTool->Settings_Push();\
281 \
282 if( !pTool->On_Before_Execution() || !(CONDITION) )\
283 {\
284 SG_UI_Msg_Add_Error(CSG_String::Format("%s [%s].[%s]", _TL("could not initialize tool"), SG_T(LIBRARY), pTool->Get_Name().c_str()));\
285 }\
286 else if( !pTool->Execute(false) )\
287 {\
288 SG_UI_Msg_Add_Error(CSG_String::Format("%s [%s].[%s]", _TL("could not execute tool" ), SG_T(LIBRARY), pTool->Get_Name().c_str()));\
289 }\
290 else\
291 {\
292 bRetVal = true;\
293 }\
294 \
295 SG_Get_Tool_Library_Manager().Delete_Tool(pTool);\
296 }\
297}
298
299#define SG_RUN_TOOL_ExitOnError(LIBRARY, TOOL, CONDITION) {\
300 \
301 bool bResult;\
302 \
303 SG_RUN_TOOL(bResult, LIBRARY, TOOL, CONDITION)\
304 \
305 if( !bResult )\
306 {\
307 return( false );\
308 }\
309}
310
311//---------------------------------------------------------
312#define SG_RUN_TOOL_KEEP_PARMS(bRetVal, LIBRARY, TOOL, PARMS, CONDITION) {\
313 \
314 bRetVal = false;\
315 \
316 CSG_Tool *pTool = SG_Get_Tool_Library_Manager().Create_Tool(SG_T(LIBRARY), TOOL);\
317 \
318 if( pTool == NULL )\
319 {\
320 SG_UI_Msg_Add_Error(CSG_String::Format("%s [%s]", _TL("could not find tool"), SG_T(LIBRARY)));\
321 }\
322 else\
323 {\
324 SG_UI_Process_Set_Text(pTool->Get_Name());\
325 \
326 pTool->Settings_Push();\
327 \
328 if( !pTool->On_Before_Execution() || !(CONDITION) )\
329 {\
330 SG_UI_Msg_Add_Error(CSG_String::Format("%s [%s].[%s]", _TL("could not initialize tool"), SG_T(LIBRARY), pTool->Get_Name().c_str()));\
331 }\
332 else if( !pTool->Execute(false) )\
333 {\
334 SG_UI_Msg_Add_Error(CSG_String::Format("%s [%s].[%s]", _TL("could not execute tool" ), SG_T(LIBRARY), pTool->Get_Name().c_str()));\
335 }\
336 else\
337 {\
338 bRetVal = true;\
339 \
340 PARMS.Set_Manager(NULL); PARMS.Assign_Parameters(pTool->Get_Parameters());\
341 }\
342 \
343 SG_Get_Tool_Library_Manager().Delete_Tool(pTool);\
344 }\
345}
346
347#define SG_RUN_TOOL_KEEP_PARMS_ExitOnError(LIBRARY, TOOL, PARMS, CONDITION) {\
348 \
349 bool bResult;\
350 \
351 SG_RUN_TOOL_KEEP_PARMS(bResult, LIBRARY, TOOL, PARMS, CONDITION)\
352 \
353 if( !bResult )\
354 {\
355 return( false );\
356 }\
357}
358
359//---------------------------------------------------------
360#define SG_TOOL_PARAMETER_SET(IDENTIFIER, VALUE) (pTool->Get_Parameters()->Get_Parameter(IDENTIFIER, true) && pTool->Set_Parameter(IDENTIFIER, VALUE))
361
362#define SG_TOOL_PARAMLIST_ADD(IDENTIFIER, VALUE) (\
363 pTool->Get_Parameters()->Get_Parameter(IDENTIFIER, true)\
364 && pTool->Get_Parameters()->Get_Parameter(IDENTIFIER)->asList()\
365 && pTool->Get_Parameters()->Get_Parameter(IDENTIFIER)->asList()->Add_Item(VALUE)\
366)
367
368#define SG_TOOL_SET_DATAOBJECT_LIST(IDENTIFIER, VALUE) (\
369 pTool->Get_Parameters()->Get_Parameter(IDENTIFIER, true)\
370 && pTool->Get_Parameters()->Get_Parameter(IDENTIFIER)->asList()\
371 && pTool->Get_Parameters()->Get_Parameter(IDENTIFIER)->asList()->Assign(VALUE)\
372)
373
374
376// //
377// //
378// //
380
381//---------------------------------------------------------
382#endif // #ifndef HEADER_INCLUDED__SAGA_API__tool_library_H
#define SAGA_API_DLL_EXPORT
Definition api_core.h:94
int Get_Count(void) const
CSG_Tool_Library * Get_Library(int i) const
const CSG_Table & Get_References_Table(void) const
CSG_String m_File_Name
const CSG_String & Get_Menu(void) const
friend class CSG_Tool_Library_Manager
const CSG_String & Get_Description(void) const
const CSG_String & Get_Library_Name(void) const
const CSG_String & Get_Name(void) const
const CSG_String & Get_File_Name(void) const
const CSG_String & Get_Author(void) const
virtual const CSG_String & Get_Info(int Type) const
bool is_Valid(void) const
const CSG_String & Get_Category(void) const
virtual ESG_Library_Type Get_Type(void) const
const CSG_String & Get_Version(void) const
virtual int Get_Count(void) const
virtual CSG_String Get_File_Name(int i) const
CSG_String m_Library_Name
@ SG_SUMMARY_FMT_HTML
Definition tool.h:94
@ TLB_INFO_Menu_Path
Definition tool.h:661
@ TLB_INFO_Name
Definition tool.h:657
@ TLB_INFO_Version
Definition tool.h:660
@ TLB_INFO_Category
Definition tool.h:662
@ TLB_INFO_Author
Definition tool.h:659
TSG_Tool_Type
Definition tool.h:101
@ TOOL_TYPE_Base
Definition tool.h:102
SAGA_API_DLL_EXPORT CSG_Tool_Library_Manager & SG_Get_Tool_Library_Manager(void)
ESG_Library_Type