SAGA API Version 9.12
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 pTool->Load_Description();
135
136 m_Tools.Add(pTool);
137 }
138 }
139 }
140
141 return( Get_Count() > 0 );
142}
143
144//---------------------------------------------------------
146{
147 Delete_Tools();
148
149 for(size_t i=0; i<m_Tools.Get_uSize(); i++)
150 {
151 delete((CSG_Tool *)m_Tools[i]);
152 }
153
154 m_Tools.Destroy();
155
156 return( true );
157}
158
159
161// //
163
164//---------------------------------------------------------
166{
167 return( m_Info[ID] );
168}
169
170
172// //
174
175//---------------------------------------------------------
177{
178 return( (int)m_Tools.Get_Size() );
179}
180
181//---------------------------------------------------------
183{
184 if( i >= 0 && i < Get_Count() )
185 {
186 return( (CSG_Tool *)m_Tools[i] );
187 }
188
189 return( NULL );
190}
191
192
194// //
196
197//---------------------------------------------------------
198CSG_Tool * CSG_Tool_Library_Interface::Create_Tool(int ID, bool bWithGUI, bool bWithCMD)
199{
200 CSG_Tool *pTool = m_Fnc_Create_Tool ? m_Fnc_Create_Tool(ID) : NULL;
201
202 if( pTool && pTool != TLB_INTERFACE_SKIP_TOOL )
203 {
204 pTool->m_ID.Printf("%d", ID);
205 pTool->m_Library = m_Info[TLB_INFO_Library ];
206 pTool->m_Library_Menu = m_Info[TLB_INFO_Menu_Path];
207 pTool->m_File_Name = m_Info[TLB_INFO_File ];
208 pTool->m_bGUI = bWithGUI && pTool->m_bGUI;
209 pTool->m_bCMD = bWithCMD && pTool->m_bCMD;
210
211 pTool->Load_Description();
212
213 m_xTools.Add(pTool);
214
215 return( pTool );
216 }
217
218 return( NULL );
219}
220
221//---------------------------------------------------------
223{
224 for(size_t i=0; i<m_xTools.Get_uSize(); i++)
225 {
226 if( pTool == m_xTools.Get(i) && m_xTools.Del(i) )
227 {
228 delete(pTool);
229
230 return( true );
231 }
232 }
233
234 return( false );
235}
236
237//---------------------------------------------------------
239{
240 for(size_t i=0; i<m_xTools.Get_uSize(); i++)
241 {
242 delete((CSG_Tool *)m_xTools[i]);
243 }
244
245 m_xTools.Destroy();
246
247 return( true );
248}
249
250
252// //
253// //
254// //
256
257//---------------------------------------------------------
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, const CSG_String &CWD="")
SAGA_API_DLL_EXPORT CSG_String SG_File_Get_Name(const CSG_String &full_Path, bool bExtension)
#define _TL(s)
Definition api_core.h:1610
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)
bool Load_Description(void)
Definition tool.cpp:459
virtual bool is_Interactive(void) const
Definition tool.h:233
#define SAGA_VERSION
CSG_Tool *(* TSG_PFNC_TLB_Create_Tool)(int i)
Definition tool.h:672
@ TLB_INFO_Library
Definition tool.h:665
@ TLB_INFO_SAGA_Version
Definition tool.h:666
@ TLB_INFO_Menu_Path
Definition tool.h:661
@ TLB_INFO_User
Definition tool.h:663
@ TLB_INFO_File
Definition tool.h:664
@ TLB_INFO_Count
Definition tool.h:667
#define TLB_INTERFACE_SKIP_TOOL
Definition tool.h:716
CSG_String(* TSG_PFNC_TLB_Get_Info)(int i)
Definition tool.h:673