SAGA API Version 9.14
Loading...
Searching...
No Matches
api_config.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// api_config.cpp //
15// //
16// Copyright (C) 2026 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 Hamburg //
44// Germany //
45// //
46// e-mail: oconrad@saga-gis.org //
47// //
49
50//---------------------------------------------------------
51//#include <wx/string.h>
52//#include <wx/config.h>
53
54#include "api_config.h"
55
56#include <wx/wx.h>
57#include <wx/config.h>
58#include <wx/utils.h>
59#include <wx/colour.h>
60
61
63// //
64// //
65// //
67
68//---------------------------------------------------------
69static bool SG_Config_bSave = true;
70
71//---------------------------------------------------------
72bool SG_Config_Do_Save(bool bOn)
73{
74 if( SG_Config_bSave != bOn )
75 {
76 SG_Config_bSave = bOn;
77
78 if( SG_Config_bSave )
79 {
80 wxConfigBase::Get()->Flush();
81 }
82 }
83
84 return( SG_Config_bSave );
85}
86
87//---------------------------------------------------------
89{
90 return( wxConfigBase::Get()->Flush() );
91}
92
93//---------------------------------------------------------
94bool SG_Config_Read(const CSG_String &Group, const CSG_String &Entry, CSG_String &Value)
95{
96 wxConfigBase *pConfig = wxConfigBase::Get();
97
98 pConfig->SetPath(wxString::Format("/%s", Group.c_str()));
99
100 return( pConfig->Read(Entry.wx_str(), &Value.wx_str()) );
101}
102
103//---------------------------------------------------------
104bool SG_Config_Read(const CSG_String &Group, const CSG_String &Entry, long &Value)
105{
106 wxConfigBase *pConfig = wxConfigBase::Get();
107
108 pConfig->SetPath(wxString::Format("/%s", Group.c_str()));
109
110 return( pConfig->Read(Entry.wx_str(), &Value) );
111}
112
113//---------------------------------------------------------
114bool SG_Config_Read(const CSG_String &Group, const CSG_String &Entry, double &Value)
115{
116 wxConfigBase *pConfig = wxConfigBase::Get();
117
118 pConfig->SetPath(wxString::Format("/%s", Group.c_str()));
119
120 return( pConfig->Read(Entry.wx_str(), &Value) );
121}
122
123//---------------------------------------------------------
124bool SG_Config_Read(const CSG_String &Group, const CSG_String &Entry, bool &Value)
125{
126 wxConfigBase *pConfig = wxConfigBase::Get();
127
128 pConfig->SetPath(wxString::Format("/%s", Group.c_str()));
129
130 return( pConfig->Read(Entry.wx_str(), &Value) );
131}
132
133//---------------------------------------------------------
134bool SG_Config_Write(const CSG_String &Group, const CSG_String &Entry, const CSG_String &Value)
135{
136 if( SG_Config_bSave )
137 {
138 wxConfigBase *pConfig = wxConfigBase::Get();
139
140 pConfig->SetPath(wxString::Format("/%s", Group.c_str()));
141
142 return( pConfig->Write(Entry.wx_str(), Value.wx_str()) ? pConfig->Flush() : false );
143 }
144
145 return( true );
146}
147
148bool SG_Config_Write(const CSG_String &Group, const CSG_String &Entry, const char *Value)
149{
150 return( SG_Config_Write(Group, Entry, CSG_String(Value)) );
151}
152
153bool SG_Config_Write(const CSG_String &Group, const CSG_String &Entry, const wchar_t *Value)
154{
155 return( SG_Config_Write(Group, Entry, CSG_String(Value)) );
156}
157
158//---------------------------------------------------------
159bool SG_Config_Write(const CSG_String &Group, const CSG_String &Entry, long Value)
160{
161 if( SG_Config_bSave )
162 {
163 wxConfigBase *pConfig = wxConfigBase::Get();
164
165 pConfig->SetPath(wxString::Format("/%s", Group.c_str()));
166
167 return( pConfig->Write(Entry.wx_str(), Value) ? pConfig->Flush() : false );
168 }
169
170 return( true );
171}
172
173//---------------------------------------------------------
174bool SG_Config_Write(const CSG_String &Group, const CSG_String &Entry, double Value)
175{
176 if( SG_Config_bSave )
177 {
178 wxConfigBase *pConfig = wxConfigBase::Get();
179
180 pConfig->SetPath(wxString::Format("/%s", Group.c_str()));
181
182 return( pConfig->Write(Entry.wx_str(), Value) ? pConfig->Flush() : false );
183 }
184
185 return( true );
186}
187
188//---------------------------------------------------------
189bool SG_Config_Write(const CSG_String &Group, const CSG_String &Entry, bool Value)
190{
191 if( SG_Config_bSave )
192 {
193 wxConfigBase *pConfig = wxConfigBase::Get();
194
195 pConfig->SetPath(wxString::Format("/%s", Group.c_str()));
196
197 return( pConfig->Write(Entry.wx_str(), Value) ? pConfig->Flush() : false );
198 }
199
200 return( true );
201}
202
203//---------------------------------------------------------
204bool SG_Config_Delete(const CSG_String &Group)
205{
206 if( SG_Config_bSave )
207 {
208 wxConfigBase *pConfig = wxConfigBase::Get();
209
210 pConfig->SetPath("/");
211
212 return( pConfig->DeleteGroup(Group.wx_str()) ? pConfig->Flush() : false );
213 }
214
215 return( true );
216}
217
218bool SG_Config_Delete(const CSG_String &Group, const CSG_String &Entry)
219{
220 if( SG_Config_bSave )
221 {
222 wxConfigBase *pConfig = wxConfigBase::Get();
223
224 pConfig->SetPath(wxString::Format("/%s", Group.c_str()));
225
226 return( pConfig->DeleteEntry(Entry.wx_str()) ? pConfig->Flush() : false );
227 }
228
229 return( true );
230}
231
232//---------------------------------------------------------
234{
235 long l; double d; wxString s; CSG_String Entry(pParameter->Get_Identifier());
236
237 wxConfigBase *pConfig = wxConfigBase::Get();
238
239 switch( pParameter->Get_Type() )
240 {
242 case PARAMETER_TYPE_Int :
246 return( pConfig->Read(Entry.wx_str(), &l) && pParameter->Set_Value((int)l) );
247
250 return( pConfig->Read(Entry.wx_str(), &d) && pParameter->Set_Value(d) );
251
257 return( pConfig->Read(Entry.wx_str(), &s) && pParameter->Set_Value((const SG_Char *)s) );
258
260 return(
261 pConfig->Read(Entry.wx_str() + "_LO", &d) && pParameter->asRange()->Set_Min(d)
262 && pConfig->Read(Entry.wx_str() + "_HI", &d) && pParameter->asRange()->Set_Max(d)
263 );
264
266 return(
267 pConfig->Read(Entry.wx_str() + "_FONT" , &s) && pParameter->Set_Value((const SG_Char *)s)
268 && pConfig->Read(Entry.wx_str() + "_COLOR", &l) && pParameter->Set_Value((int)l)
269 );
270
272 return( pConfig->Read(Entry.wx_str(), &s) && pParameter->asColors()->from_Text(&s) );
273
275 return( SG_Config_Read(Entry + "/" + pParameter->Get_Identifier(), *pParameter->asParameters()) );
276
277 default:
278 return( false );
279 }
280}
281
282//---------------------------------------------------------
283bool SG_Config_Read(const CSG_String &Group, CSG_Parameters &Parameters)
284{
285 wxConfigBase *pConfig = wxConfigBase::Get();
286
287 pConfig->SetPath(wxString::Format("/%s", Group.c_str()));
288
289 for(int i=0; i<Parameters.Get_Count(); i++)
290 {
291 SG_Config_Read(Parameters(i));
292 }
293
294 return( pConfig->Flush() );
295}
296
297//---------------------------------------------------------
299{
300 if( SG_Config_bSave )
301 {
302 wxConfigBase *pConfig = wxConfigBase::Get();
303
304 CSG_String Entry(pParameter->Get_Identifier());
305
306 switch( pParameter->Get_Type() )
307 {
309 case PARAMETER_TYPE_Int :
313 return( pConfig->Write(Entry.wx_str(), pParameter->asInt()) );
314
317 return( pConfig->Write(Entry.wx_str(), pParameter->asDouble()) );
318
324 return( pConfig->Write(Entry.wx_str(), pParameter->asString()) );
325
327 return(
328 pConfig->Write(Entry.wx_str() + "_LO", pParameter->asRange()->Get_Min())
329 && pConfig->Write(Entry.wx_str() + "_HI", pParameter->asRange()->Get_Max())
330 );
331
333 return(
334 pConfig->Write(Entry.wx_str() + "_FONT" , (const SG_Char *)pParameter->asPointer())
335 && pConfig->Write(Entry.wx_str() + "_COLOR", pParameter->asInt())
336 );
337
339 {
340 CSG_String s;
341
342 return( pParameter->asColors()->to_Text(s) && pConfig->Write(Entry.wx_str(), s.c_str()) );
343 }
344
346 return( SG_Config_Write(Entry + "/" + pParameter->Get_Identifier(), *pParameter->asParameters()) );
347
348 default:
349 return( false );
350 }
351 }
352
353 return( true );
354}
355
356//---------------------------------------------------------
357bool SG_Config_Write(const CSG_String &Group, const CSG_Parameters &Parameters)
358{
359 if( SG_Config_bSave )
360 {
361 wxConfigBase *pConfig = wxConfigBase::Get();
362
363 pConfig->SetPath(wxString::Format("/%s", Group.c_str()));
364
365 for(int i=0; i<Parameters.Get_Count(); i++)
366 {
367 SG_Config_Write(Parameters(i));
368 }
369
370 return( pConfig->Flush() );
371 }
372
373 return( true );
374}
375
376
378// //
379// //
380// //
382
383//---------------------------------------------------------
bool SG_Config_Write(const CSG_String &Group, const CSG_String &Entry, const CSG_String &Value)
bool SG_Config_Read(const CSG_String &Group, const CSG_String &Entry, CSG_String &Value)
bool SG_Config_Do_Save(bool bOn)
bool SG_Config_Flush(void)
static bool SG_Config_bSave
bool SG_Config_Delete(const CSG_String &Group)
#define SG_Char
Definition api_core.h:536
bool from_Text(const CSG_String &String)
bool to_Text(CSG_String &String)
double Get_Max(void) const
double Get_Min(void) const
bool Set_Max(double Max)
bool Set_Min(double Min)
const SG_Char * Get_Identifier(void) const
class CSG_Parameters * asParameters(void) const
void * asPointer(void) const
Definition parameters.h:291
double asDouble(void) const
Definition parameters.h:289
virtual TSG_Parameter_Type Get_Type(void) const =0
CSG_Colors * asColors(void) const
virtual bool Set_Value(int Value)
class CSG_Parameter_Range * asRange(void) const
const SG_Char * asString(void) const
Definition parameters.h:290
int asInt(void) const
Definition parameters.h:287
int Get_Count(void) const
const SG_Char * c_str(void) const
const class wxString & wx_str(void) const
Definition api_core.h:595
@ PARAMETER_TYPE_Degree
Definition parameters.h:129
@ PARAMETER_TYPE_Text
Definition parameters.h:136
@ PARAMETER_TYPE_Int
Definition parameters.h:127
@ PARAMETER_TYPE_Color
Definition parameters.h:140
@ PARAMETER_TYPE_Colors
Definition parameters.h:141
@ PARAMETER_TYPE_Double
Definition parameters.h:128
@ PARAMETER_TYPE_Font
Definition parameters.h:139
@ PARAMETER_TYPE_Date
Definition parameters.h:130
@ PARAMETER_TYPE_Choices
Definition parameters.h:134
@ PARAMETER_TYPE_Data_Type
Definition parameters.h:132
@ PARAMETER_TYPE_Range
Definition parameters.h:131
@ PARAMETER_TYPE_Parameters
Definition parameters.h:164
@ PARAMETER_TYPE_FilePath
Definition parameters.h:137
@ PARAMETER_TYPE_Bool
Definition parameters.h:126
@ PARAMETER_TYPE_String
Definition parameters.h:135
@ PARAMETER_TYPE_Choice
Definition parameters.h:133