SAGA API  v9.6
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 //---------------------------------------------------------
74 // //
76 // //
77 // //
79 
80 //---------------------------------------------------------
81 #include "tool.h"
82 
83 
85 // //
86 // //
87 // //
89 
90 //---------------------------------------------------------
91 enum class ESG_Library_Type
92 {
93  Library, Chain, Undefined
94 };
95 
96 
98 // //
99 // //
100 // //
102 
103 //---------------------------------------------------------
105 {
107 
108 public:
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 ) ); }
119  CSG_String Get_Description (void) const { return( Get_Info(TLB_INFO_Description) ); }
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 
152 protected:
153 
154  CSG_Tool_Library(void);
155  CSG_Tool_Library(const CSG_String &File);
156  virtual ~CSG_Tool_Library(void);
157 
158 
160 
161 
162 private:
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 {
185 public:
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 
235 private:
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
CSG_Tool_Library_Interface
Definition: tool.h:642
CSG_Tool_Library::Get_File_Name
virtual CSG_String Get_File_Name(int i) const
Definition: tool_library.h:143
CSG_Tool_Library_Manager::Get_Tool
CSG_Tool * Get_Tool(const CSG_String &Library, int Index) const
Definition: tool_library.cpp:800
CSG_Tool_Library
Definition: tool_library.h:105
TLB_INFO_Version
@ TLB_INFO_Version
Definition: tool.h:625
CSG_Tool_Library::Get_Name
CSG_String Get_Name(void) const
Definition: tool_library.h:118
TLB_INFO_Category
@ TLB_INFO_Category
Definition: tool.h:627
CSG_Tool
Definition: tool.h:151
SG_Get_Tool_Library_Manager
SAGA_API_DLL_EXPORT CSG_Tool_Library_Manager & SG_Get_Tool_Library_Manager(void)
Definition: tool_library.cpp:286
SG_SUMMARY_FMT_HTML
@ SG_SUMMARY_FMT_HTML
Definition: tool.h:94
CSG_Tool_Library::Get_Type
virtual ESG_Library_Type Get_Type(void) const
Definition: tool_library.h:110
TSG_Tool_Type
TSG_Tool_Type
Definition: tool.h:101
TLB_INFO_Name
@ TLB_INFO_Name
Definition: tool.h:622
ESG_CRS_Type::Geographic
@ Geographic
CSG_Tool_Library_Manager::Delete_Tool
bool Delete_Tool(CSG_Tool *pTool) const
Definition: tool_library.cpp:865
tool.h
CSG_Tool_Library::Get_Version
CSG_String Get_Version(void) const
Definition: tool_library.h:121
CSG_Tool_Library_Manager::Get_Summary
CSG_String Get_Summary(int Format=SG_SUMMARY_FMT_HTML) const
Definition: tool_summary.cpp:791
TLB_INFO_Description
@ TLB_INFO_Description
Definition: tool.h:623
CSG_Tool_Library::Get_Author
CSG_String Get_Author(void) const
Definition: tool_library.h:120
CSG_Tool_Library::Get_File_Name
const CSG_String & Get_File_Name(void) const
Definition: tool_library.h:114
CSG_Tool_Library_Manager::Get_Count
int Get_Count(void) const
Definition: tool_library.h:191
CSG_Tool_Library::Get_Count
virtual int Get_Count(void) const
Definition: tool_library.h:128
CSG_Tool_Library::Get_Description
CSG_String Get_Description(void) const
Definition: tool_library.h:119
CSG_Tool_Library::Get_Library_Name
const CSG_String & Get_Library_Name(void) const
Definition: tool_library.h:115
CSG_Tool_Library::m_Library_Name
CSG_String m_Library_Name
Definition: tool_library.h:159
SAGA_API_DLL_EXPORT
#define SAGA_API_DLL_EXPORT
Definition: api_core.h:94
CSG_Tool_Library::Get_Menu
CSG_String Get_Menu(void) const
Definition: tool_library.h:122
CSG_Strings
Definition: api_core.h:699
TLB_INFO_Author
@ TLB_INFO_Author
Definition: tool.h:624
CSG_Tool_Library_Manager::Create_Tool
CSG_Tool * Create_Tool(const CSG_String &Library, int Index, bool bWithGUI=false, bool bWithCMD=true) const
Definition: tool_library.cpp:836
ESG_Library_Type::Library
@ Library
CSG_Tool_Library::Get_References
const CSG_Strings & Get_References(void) const
Definition: tool_library.h:149
SG_Char
#define SG_Char
Definition: api_core.h:536
CSG_String
Definition: api_core.h:563
CSG_Tool_Library::is_Valid
bool is_Valid(void) const
Definition: tool_library.h:112
TOOL_TYPE_Base
@ TOOL_TYPE_Base
Definition: tool.h:102
ESG_Library_Type
ESG_Library_Type
Definition: tool_library.h:92
CSG_Tool_Library_Manager::Get_Library
CSG_Tool_Library * Get_Library(int i) const
Definition: tool_library.h:207
CSG_Tool_Library::Get_Category
CSG_String Get_Category(void) const
Definition: tool_library.h:123
CSG_Tool_Library_Manager
Definition: tool_library.h:184
TLB_INFO_Menu_Path
@ TLB_INFO_Menu_Path
Definition: tool.h:626