SAGA API v9.10
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
117 virtual CSG_String Get_Info (int Type) const;
118 CSG_String Get_Name (void) const { return( Get_Info(TLB_INFO_Name ) ); }
120 CSG_String Get_Author (void) const { return( Get_Info(TLB_INFO_Author ) ); }
121 CSG_String Get_Version (void) const { return( Get_Info(TLB_INFO_Version ) ); }
122 CSG_String Get_Menu (void) const { return( Get_Info(TLB_INFO_Menu_Path ) ); }
123 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 void Add_Reference (const CSG_String &Authors, const CSG_String &Year, const CSG_String &Title, const CSG_String &Where, const SG_Char *Link = NULL, const SG_Char *Link_Text = NULL);
147 void Add_Reference (const CSG_String &Link, const SG_Char *Link_Text = NULL);
148 void Del_References (void);
149 const CSG_Strings & Get_References (void) const { return( m_References ); }
150
151
152protected:
153
154 CSG_Tool_Library(void);
155 CSG_Tool_Library(const CSG_String &File);
156 virtual ~CSG_Tool_Library(void);
157
158
160
161
162private:
163
164 bool _Destroy (void);
165
166
167 CSG_Strings m_References;
168
169 CSG_Tool_Library_Interface *m_pInterface;
170
171 class wxDynamicLibrary *m_pLibrary;
172
173};
174
175
177// //
178// //
179// //
181
182//---------------------------------------------------------
184{
185public:
187 virtual ~CSG_Tool_Library_Manager(void);
188
189 bool Destroy (void);
190
191 int Get_Count (void) const { return( m_nLibraries ); }
192 int Get_Tool_Count (void) const;
193
194 bool Add_Default_Libraries (bool bVerbose = false);
195
196 CSG_Tool_Library * Add_Library (const CSG_String &File);
197 CSG_Tool_Library * Add_Library (const char *File);
198 CSG_Tool_Library * Add_Library (const wchar_t *File);
199
200 int Add_Directory (const CSG_String &Directory, bool bOnlySubDirectories = false);
201 int Add_Directory (const char *Directory, bool bOnlySubDirectories = false);
202 int Add_Directory (const wchar_t *Directory, bool bOnlySubDirectories = false);
203
204 bool Del_Library (int i);
205 bool Del_Library (CSG_Tool_Library *pLibrary);
206
207 CSG_Tool_Library * Get_Library (int i) const { return( i >= 0 && i < Get_Count() ? m_pLibraries[i] : NULL ); }
208 CSG_Tool_Library * Get_Library (const CSG_String &Name, bool bLibrary, ESG_Library_Type Type = ESG_Library_Type::Undefined) const;
209 CSG_Tool_Library * Get_Library (const char *Name, bool bLibrary, ESG_Library_Type Type = ESG_Library_Type::Undefined) const;
210 CSG_Tool_Library * Get_Library (const wchar_t *Name, bool bLibrary, ESG_Library_Type Type = ESG_Library_Type::Undefined) const;
211
212 bool is_Loaded (CSG_Tool_Library *pLibrary) const;
213
214 CSG_Tool * Get_Tool (const CSG_String &Library, int Index) const;
215 CSG_Tool * Get_Tool (const char *Library, int Index) const;
216 CSG_Tool * Get_Tool (const wchar_t *Library, int Index) const;
217 CSG_Tool * Get_Tool (const CSG_String &Library, const CSG_String &Name) const;
218 CSG_Tool * Get_Tool (const char *Library, const char *Name) const;
219 CSG_Tool * Get_Tool (const wchar_t *Library, const wchar_t *Name) const;
220
221 CSG_Tool * Create_Tool (const CSG_String &Library, int Index, bool bWithGUI = false, bool bWithCMD = true) const;
222 CSG_Tool * Create_Tool (const char *Library, int Index, bool bWithGUI = false, bool bWithCMD = true) const;
223 CSG_Tool * Create_Tool (const wchar_t *Library, int Index, bool bWithGUI = false, bool bWithCMD = true) const;
224 CSG_Tool * Create_Tool (const CSG_String &Library, const CSG_String &Name, bool bWithGUI = false, bool bWithCMD = true) const;
225 CSG_Tool * Create_Tool (const char *Library, const char *Name, bool bWithGUI = false, bool bWithCMD = true) const;
226 CSG_Tool * Create_Tool (const wchar_t *Library, const wchar_t *Name, bool bWithGUI = false, bool bWithCMD = true) const;
227 bool Delete_Tool (CSG_Tool *pTool) const;
228
229 CSG_String Get_Summary (int Format = SG_SUMMARY_FMT_HTML) const;
230 bool Get_Summary (const CSG_String &Path) const;
231
232 bool Create_Python_ToolBox (const CSG_String &Destination, bool bClean = true, bool bName = true, bool bSingleFile = false) const;
233
234
235private:
236
237 int m_nLibraries;
238
239 CSG_Tool_Library **m_pLibraries;
240
241
242 bool _Add_Library (const CSG_String &Library);
243 bool _Add_Library_Chains (const CSG_String &Library, const CSG_String &Directory);
244
245 CSG_Tool_Library * _Add_Tool_Chain (const CSG_String &File, bool bReload = true);
246
247};
248
249//---------------------------------------------------------
251
252
254// //
255// //
256// //
258
259//---------------------------------------------------------
260#define SG_RUN_TOOL(bRetVal, LIBRARY, TOOL, CONDITION) {\
261 \
262 bRetVal = false;\
263 \
264 CSG_Tool *pTool = SG_Get_Tool_Library_Manager().Create_Tool(SG_T(LIBRARY), TOOL);\
265 \
266 if( pTool == NULL )\
267 {\
268 SG_UI_Msg_Add_Error(CSG_String::Format("%s [%s]", _TL("could not find tool"), SG_T(LIBRARY)));\
269 }\
270 else\
271 {\
272 SG_UI_Process_Set_Text(pTool->Get_Name());\
273 \
274 pTool->Settings_Push();\
275 \
276 if( !pTool->On_Before_Execution() || !(CONDITION) )\
277 {\
278 SG_UI_Msg_Add_Error(CSG_String::Format("%s [%s].[%s]", _TL("could not initialize tool"), SG_T(LIBRARY), pTool->Get_Name().c_str()));\
279 }\
280 else if( !pTool->Execute(false) )\
281 {\
282 SG_UI_Msg_Add_Error(CSG_String::Format("%s [%s].[%s]", _TL("could not execute tool" ), SG_T(LIBRARY), pTool->Get_Name().c_str()));\
283 }\
284 else\
285 {\
286 bRetVal = true;\
287 }\
288 \
289 SG_Get_Tool_Library_Manager().Delete_Tool(pTool);\
290 }\
291}
292
293#define SG_RUN_TOOL_ExitOnError(LIBRARY, TOOL, CONDITION) {\
294 \
295 bool bResult;\
296 \
297 SG_RUN_TOOL(bResult, LIBRARY, TOOL, CONDITION)\
298 \
299 if( !bResult )\
300 {\
301 return( false );\
302 }\
303}
304
305//---------------------------------------------------------
306#define SG_RUN_TOOL_KEEP_PARMS(bRetVal, LIBRARY, TOOL, PARMS, CONDITION) {\
307 \
308 bRetVal = false;\
309 \
310 CSG_Tool *pTool = SG_Get_Tool_Library_Manager().Create_Tool(SG_T(LIBRARY), TOOL);\
311 \
312 if( pTool == NULL )\
313 {\
314 SG_UI_Msg_Add_Error(CSG_String::Format("%s [%s]", _TL("could not find tool"), SG_T(LIBRARY)));\
315 }\
316 else\
317 {\
318 SG_UI_Process_Set_Text(pTool->Get_Name());\
319 \
320 pTool->Settings_Push();\
321 \
322 if( !pTool->On_Before_Execution() || !(CONDITION) )\
323 {\
324 SG_UI_Msg_Add_Error(CSG_String::Format("%s [%s].[%s]", _TL("could not initialize tool"), SG_T(LIBRARY), pTool->Get_Name().c_str()));\
325 }\
326 else if( !pTool->Execute(false) )\
327 {\
328 SG_UI_Msg_Add_Error(CSG_String::Format("%s [%s].[%s]", _TL("could not execute tool" ), SG_T(LIBRARY), pTool->Get_Name().c_str()));\
329 }\
330 else\
331 {\
332 bRetVal = true;\
333 \
334 PARMS.Set_Manager(NULL); PARMS.Assign_Parameters(pTool->Get_Parameters());\
335 }\
336 \
337 SG_Get_Tool_Library_Manager().Delete_Tool(pTool);\
338 }\
339}
340
341#define SG_RUN_TOOL_KEEP_PARMS_ExitOnError(LIBRARY, TOOL, PARMS, CONDITION) {\
342 \
343 bool bResult;\
344 \
345 SG_RUN_TOOL_KEEP_PARMS(bResult, LIBRARY, TOOL, PARMS, CONDITION)\
346 \
347 if( !bResult )\
348 {\
349 return( false );\
350 }\
351}
352
353//---------------------------------------------------------
354#define SG_TOOL_PARAMETER_SET(IDENTIFIER, VALUE) (pTool->Get_Parameters()->Get_Parameter(IDENTIFIER, true) && pTool->Set_Parameter(IDENTIFIER, VALUE))
355
356#define SG_TOOL_PARAMLIST_ADD(IDENTIFIER, VALUE) (\
357 pTool->Get_Parameters()->Get_Parameter(IDENTIFIER, true)\
358 && pTool->Get_Parameters()->Get_Parameter(IDENTIFIER)->asList()\
359 && pTool->Get_Parameters()->Get_Parameter(IDENTIFIER)->asList()->Add_Item(VALUE)\
360)
361
362#define SG_TOOL_SET_DATAOBJECT_LIST(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()->Assign(VALUE)\
366)
367
368
370// //
371// //
372// //
374
375//---------------------------------------------------------
376#endif // #ifndef HEADER_INCLUDED__SAGA_API__tool_library_H
#define SAGA_API_DLL_EXPORT
Definition api_core.h:94
#define SG_Char
Definition api_core.h:536
int Get_Count(void) const
CSG_Tool_Library * Get_Library(int i) const
CSG_String m_File_Name
friend class CSG_Tool_Library_Manager
CSG_String Get_Author(void) const
CSG_String Get_Menu(void) const
const CSG_String & Get_Library_Name(void) const
CSG_String Get_Description(void) const
virtual CSG_String Get_Info(int Type) const
const CSG_Strings & Get_References(void) const
const CSG_String & Get_File_Name(void) const
CSG_String Get_Version(void) const
bool is_Valid(void) const
virtual ESG_Library_Type Get_Type(void) const
virtual int Get_Count(void) const
CSG_String Get_Category(void) const
virtual CSG_String Get_File_Name(int i) const
CSG_String m_Library_Name
CSG_String Get_Name(void) const
@ SG_SUMMARY_FMT_HTML
Definition tool.h:94
@ TLB_INFO_Menu_Path
Definition tool.h:641
@ TLB_INFO_Name
Definition tool.h:637
@ TLB_INFO_Version
Definition tool.h:640
@ TLB_INFO_Category
Definition tool.h:642
@ TLB_INFO_Description
Definition tool.h:638
@ TLB_INFO_Author
Definition tool.h:639
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