SAGA API v9.10
Loading...
Searching...
No Matches
tool_library_interface.cpp
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_interface.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'. //
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#include "saga_api.h"
54
55
57// //
58// //
59// //
61
62//---------------------------------------------------------
64{
65 m_Fnc_Create_Tool = NULL;
66}
67
68//---------------------------------------------------------
73
74
76// //
78
79//---------------------------------------------------------
80bool CSG_Tool_Library_Interface::Create(const CSG_String &Version, const CSG_String &TLB_Path, TSG_PFNC_TLB_Get_Info Fnc_Info, TSG_PFNC_TLB_Create_Tool Fnc_Create_Tool)
81{
82 Destroy();
83
84 //-----------------------------------------------------
85 m_Info.Set_Count(TLB_INFO_Count);
86
87 for(int i=0; i<TLB_INFO_User; i++)
88 {
89 m_Info[i] = Fnc_Info(i);
90 }
91
92 CSG_String Library = SG_File_Get_Name(TLB_Path, false);
93
94 #if !defined(_SAGA_MSW)
95 if( Library.Find("lib") == 0 )
96 {
97 Library = Library.Right(Library.Length() - 3);
98 }
99 #endif
100
101 m_Info[TLB_INFO_Library ] = Library;
102 m_Info[TLB_INFO_SAGA_Version] = Version;
103 m_Info[TLB_INFO_File ] = SG_File_Get_Path_Absolute(TLB_Path);
104
105 if( Version.Cmp(SAGA_VERSION) )
106 {
107 SG_UI_Msg_Add_Error(CSG_String::Format("SAGA API %s: %s=%s, %s=%s", _TL("version mismatch"), _TL("current version"), SAGA_VERSION,
108 Library.c_str(), Version.c_str()
109 ));
110
111 return( false );
112 }
113
114 //-----------------------------------------------------
115 m_Fnc_Create_Tool = Fnc_Create_Tool;
116
117 CSG_Tool *pTool;
118
119 for(int ID=0; (pTool = m_Fnc_Create_Tool(ID)) != NULL; ID++)
120 {
121 if( pTool != TLB_INTERFACE_SKIP_TOOL )
122 {
123 if( SG_UI_Get_Application_Name().Cmp("saga_cmd") == 0 && pTool->is_Interactive() )
124 {
125 delete(pTool);
126 }
127 else
128 {
129 pTool->m_ID.Printf("%d", ID);
130 pTool->m_Library = m_Info[TLB_INFO_Library ];
131 pTool->m_Library_Menu = m_Info[TLB_INFO_Menu_Path];
132 pTool->m_File_Name = m_Info[TLB_INFO_File ];
133
134 m_Tools.Add(pTool);
135 }
136 }
137 }
138
139 return( Get_Count() > 0 );
140}
141
142//---------------------------------------------------------
144{
145 Delete_Tools();
146
147 for(size_t i=0; i<m_Tools.Get_uSize(); i++)
148 {
149 delete((CSG_Tool *)m_Tools[i]);
150 }
151
152 m_Tools.Destroy();
153
154 return( true );
155}
156
157
159// //
161
162//---------------------------------------------------------
164{
165 return( m_Info[ID] );
166}
167
168
170// //
172
173//---------------------------------------------------------
175{
176 return( (int)m_Tools.Get_Size() );
177}
178
179//---------------------------------------------------------
181{
182 if( i >= 0 && i < Get_Count() )
183 {
184 return( (CSG_Tool *)m_Tools[i] );
185 }
186
187 return( NULL );
188}
189
190
192// //
194
195//---------------------------------------------------------
196CSG_Tool * CSG_Tool_Library_Interface::Create_Tool(int ID, bool bWithGUI, bool bWithCMD)
197{
198 CSG_Tool *pTool = m_Fnc_Create_Tool ? m_Fnc_Create_Tool(ID) : NULL;
199
200 if( pTool && pTool != TLB_INTERFACE_SKIP_TOOL )
201 {
202 pTool->m_ID.Printf("%d", ID);
203 pTool->m_Library = m_Info[TLB_INFO_Library ];
204 pTool->m_Library_Menu = m_Info[TLB_INFO_Menu_Path];
205 pTool->m_File_Name = m_Info[TLB_INFO_File ];
206 pTool->m_bGUI = bWithGUI && pTool->m_bGUI;
207 pTool->m_bCMD = bWithCMD && pTool->m_bCMD;
208
209 m_xTools.Add(pTool);
210
211 return( pTool );
212 }
213
214 return( NULL );
215}
216
217//---------------------------------------------------------
219{
220 for(size_t i=0; i<m_xTools.Get_uSize(); i++)
221 {
222 if( pTool == m_xTools.Get(i) && m_xTools.Del(i) )
223 {
224 delete(pTool);
225
226 return( true );
227 }
228 }
229
230 return( false );
231}
232
233//---------------------------------------------------------
235{
236 for(size_t i=0; i<m_xTools.Get_uSize(); i++)
237 {
238 delete((CSG_Tool *)m_xTools[i]);
239 }
240
241 m_xTools.Destroy();
242
243 return( true );
244}
245
246
248// //
249// //
250// //
252
253//---------------------------------------------------------
void SG_UI_Msg_Add_Error(const char *Message)
CSG_String SG_UI_Get_Application_Name(void)
Definition api_core.cpp:378
SAGA_API_DLL_EXPORT CSG_String SG_File_Get_Path_Absolute(const CSG_String &full_Path)
SAGA_API_DLL_EXPORT CSG_String SG_File_Get_Name(const CSG_String &full_Path, bool bExtension)
#define _TL(s)
Definition api_core.h:1568
int Cmp(const CSG_String &String) const
static CSG_String Format(const char *Format,...)
const SG_Char * c_str(void) const
int Printf(const char *Format,...)
CSG_Tool * Create_Tool(int i, bool bWithGUI=false, bool bWithCMD=true)
const CSG_String & Get_Info(int ID)
bool Create(const CSG_String &Version, const CSG_String &TLB_Path, TSG_PFNC_TLB_Get_Info Fnc_Info, TSG_PFNC_TLB_Create_Tool Fnc_Create_Tool)
virtual bool is_Interactive(void) const
Definition tool.h:223
#define SAGA_VERSION
Definition saga_api.h:90
CSG_Tool *(* TSG_PFNC_TLB_Create_Tool)(int i)
Definition tool.h:652
@ TLB_INFO_Library
Definition tool.h:645
@ TLB_INFO_SAGA_Version
Definition tool.h:646
@ TLB_INFO_Menu_Path
Definition tool.h:641
@ TLB_INFO_User
Definition tool.h:643
@ TLB_INFO_File
Definition tool.h:644
@ TLB_INFO_Count
Definition tool.h:647
#define TLB_INTERFACE_SKIP_TOOL
Definition tool.h:696
CSG_String(* TSG_PFNC_TLB_Get_Info)(int i)
Definition tool.h:653