SAGA API v9.10
Loading...
Searching...
No Matches
tool.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.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// Germany //
45// //
46// e-mail: oconrad@saga-gis.org //
47// //
49
50//---------------------------------------------------------
51#include "saga_api.h"
52#include "data_manager.h"
53#include "tool.h"
54#include "tool_chain.h"
55
56#include <wx/string.h>
57#include <wx/cmdline.h>
58
59
61// //
62// //
63// //
65
66//---------------------------------------------------------
68{
69 m_ID = "-1";
70 m_Version = "1.0";
71
72 m_bError_Ignore = false;
73 m_bExecutes = false;
74
75 m_bGUI = SG_UI_Get_Application_Name().Cmp("saga_gui") == 0;
76 m_bCMD = SG_UI_Get_Application_Name().Cmp("saga_cmd") == 0;
77
78 Parameters.Create(this, SG_T("Tool"));
79 Parameters.Set_Callback_On_Parameter_Changed(&_On_Parameter_Changed);
80 Parameters.Set_Tool(this);
81
83}
84
85//---------------------------------------------------------
87{
88 for(int i=0; i<Get_Parameters_Count(); i++)
89 {
90 delete(Get_Parameters(i));
91 }
92
93 Destroy();
94}
95
96
98// //
100
101//---------------------------------------------------------
103{
104 m_bError_Ignore = false;
105
106 History_Supplement.Destroy();
107}
108
109
111// //
113
114//---------------------------------------------------------
116{
117 return( m_Library );
118}
119
120//---------------------------------------------------------
122{
123 return( m_File_Name );
124}
125
126//---------------------------------------------------------
128{
129 Parameters.Set_Name(String);
130}
131
133{
134 return( Parameters.Get_Name() );
135}
136
137//---------------------------------------------------------
139{
140 m_Author = String;
141}
142
144{
145 return( m_Author );
146}
147
148//---------------------------------------------------------
150{
151 m_Version = String;
152}
153
155{
156 return( m_Version );
157}
158
159//---------------------------------------------------------
161{
162 Parameters.Set_Description(String);
163}
164
166{
167 return( Parameters.Get_Description().is_Empty() ? Get_Name() : Parameters.Get_Description() );
168}
169
170//---------------------------------------------------------
171void CSG_Tool::Add_Reference(const CSG_String &Authors, const CSG_String &Year, const CSG_String &Title, const CSG_String &Where, const SG_Char *Link, const SG_Char *Link_Text)
172{
173 Parameters.Add_Reference(Authors, Year, Title, Where, Link, Link_Text);
174}
175
176void CSG_Tool::Add_Reference(const CSG_String &Link, const SG_Char *Link_Text)
177{
178 Parameters.Add_Reference(Link, Link_Text);
179}
180
182{
183 return( Parameters.Get_References() );
184}
185
186//---------------------------------------------------------
188{
189 if( !bSolved )
190 {
191 return( Get_MenuPath() );
192 }
193
194 CSG_Strings Menu = SG_String_Tokenize(Get_MenuPath(), ";"); if( !Menu.Get_Count() ) { Menu += ""; }
195
196 for(int i=0; i<Menu.Get_Count(); i++)
197 {
198 if( Menu[i].Length() > 1 && Menu[i][1] == ':' )
199 {
200 if( Menu[i][0] == 'A' || Menu[i][0] == 'a' ) // absolute menu path, overwrites library's default menu path
201 {
202 Menu[i] = Menu[i].AfterFirst(':');
203
204 continue;
205 }
206
207 Menu[i] = Menu[i].AfterFirst(':'); // Menu[0] == 'R' || Menu[0] == 'r' // menu path explicitly declared as relative to library's default menu path
208 }
209
210 if( !m_Library_Menu.is_Empty() )
211 {
212 if( Menu[i].is_Empty() )
213 {
214 Menu[i] = m_Library_Menu;
215 }
216 else
217 {
218 Menu[i] = m_Library_Menu + "|" + Menu[i];
219 }
220 }
221 }
222
223 CSG_String Menus;
224
225 for(int i=0; i<Menu.Get_Count(); i++)
226 {
227 if( i > 0 )
228 {
229 Menus += ";";
230 }
231
232 Menus += Menu[i];
233 }
234
235 return( Menus );
236}
237
238//---------------------------------------------------------
239bool CSG_Tool::has_GUI(void) const
240{
241 return( m_bGUI );
242}
243
244//---------------------------------------------------------
245bool CSG_Tool::has_CMD(void) const
246{
247 return( m_bCMD );
248}
249
250
252// //
253// //
254// //
256
257//---------------------------------------------------------
258bool CSG_Tool::Execute(bool bAddHistory)
259{
260 #define ADD_MESSAGE_EXECUTION(Text, Style) { SG_UI_Msg_Add(Text, true, Style); if( has_GUI() ) { SG_UI_Msg_Add_Execution(Text, true, Style); } }
261
262 //-----------------------------------------------------
263 if( m_bExecutes )
264 {
265 return( false );
266 }
267
268 m_bExecutes = true;
269
270 m_bError_Ignore = false;
271
272 bool bResult = false;
273
274 m_Execution_Info.Clear();
275
276 History_Supplement.Destroy();
277
278 //-----------------------------------------------------
279 if( Parameters.Get_Manager() == &SG_Get_Data_Manager() )
280 {
281 ADD_MESSAGE_EXECUTION(CSG_String::Format("[%s] %s...", Get_Name().c_str(), _TL("Execution started")), SG_UI_MSG_STYLE_SUCCESS);
282 }
283
285
286 if( Parameters.DataObjects_Create() == false )
287 {
288 _Synchronize_DataObjects(); // not all, but some objects might have been created!
289 }
290 else
291 {
292 Parameters.Msg_String(false);
293
294 // SG_UI_Process_Set_Busy(true, CSG_String::Format("%s: %s...", _TL("Executing"), Get_Name().c_str()));
296
298//#if !defined(_DEBUG)
299#define _TOOL_EXCEPTION
300 try
301 {
302//#endif
304
305 bResult = On_Execute();
306
308#ifdef _TOOL_EXCEPTION
309 } // try
310 catch(const std::exception &Exception)
311 {
312 Message_Dlg(Exception.what() , CSG_String::Format("%s | %s", Get_Name().c_str(), _TL("Access violation!")));
313 }
314 catch(...)
315 {
316 Message_Dlg(_TL("unspecified exception"), CSG_String::Format("%s | %s", Get_Name().c_str(), _TL("Access violation!")));
317 }
318 #endif
320
321 CSG_TimeSpan Span = CSG_DateTime::Now() - Started;
322 // SG_UI_Process_Set_Busy(false);
323
324 _Synchronize_DataObjects();
325
326 if( !Process_Get_Okay(false) )
327 {
328 SG_UI_Msg_Add(_TL("Execution has been stopped by user!"), true, SG_UI_MSG_STYLE_BOLD);
329
330 bResult = false;
331 }
332
333 if( bResult && bAddHistory )
334 {
335 _Set_Output_History();
336 }
337
338 //-------------------------------------------------
339 if( is_Interactive() )
340 {
341 if( bResult )
342 {
343 CSG_String Text(CSG_String::Format("\n%s...", _TL("Interactive tool started and is waiting for user input.")));
344
345 SG_UI_Msg_Add (Text, false, SG_UI_MSG_STYLE_BOLD);
347 }
348 else
349 {
350 ADD_MESSAGE_EXECUTION(_TL("Interactive tool initialization failed."), SG_UI_MSG_STYLE_FAILURE);
351 }
352 }
353 else
354 {
355 CSG_String Time =
356 Span.Get_Hours () >= 1 ? (Span.Format("%Hh %Mm %Ss"))
357 : Span.Get_Minutes () >= 1 ? (Span.Format( "%Mm %Ss"))
358 : Span.Get_Seconds () >= 1 ? (Span.Format( "%Ss"))
359 : Span.Get_Milliseconds() >= 1 ? (Span.Format("%l ") + _TL("milliseconds"))
360 : CSG_String(_TL("less than 1 millisecond"));
361
362 if( Parameters.Get_Manager() != &SG_Get_Data_Manager() )
363 {
364 SG_UI_Msg_Add_Execution(CSG_String::Format("\n[%s] %s: %s", Get_Name().c_str(),
365 _TL("execution time"), Time.c_str()),
367 );
368 }
369 else
370 {
371 SG_UI_Msg_Add_Execution(CSG_String::Format("\n__________\n%s %s: %lld %s (%s)\n", _TL("total"),
372 _TL("execution time"), Span.Get_Milliseconds(), _TL("milliseconds"), Time.c_str()),
374 );
375
376 ADD_MESSAGE_EXECUTION(CSG_String::Format("[%s] %s (%s)", Get_Name().c_str(),
377 bResult ? _TL("Execution succeeded") : _TL("Execution failed"), Time.c_str()),
379 );
380 }
381 }
382 }
383
384 //-----------------------------------------------------
385 History_Supplement.Destroy();
386
387 m_bExecutes = false;
388
391
392 return( bResult );
393}
394
395
397// //
398// //
399// //
401
402//---------------------------------------------------------
403bool CSG_Tool::_Synchronize_DataObjects(void)
404{
405 Parameters.DataObjects_Synchronize();
406
407 for(int i=0; i<Get_Parameters_Count(); i++)
408 {
409 Get_Parameters(i)->DataObjects_Synchronize();
410 }
411
412 CSG_Projection Projection;
413
415 {
416 Parameters.DataObjects_Set_Projection(Projection);
417
418 for(int i=0; i<Get_Parameters_Count(); i++)
419 {
420 Get_Parameters(i)->DataObjects_Set_Projection(Projection);
421 }
422
423 return( true );
424 }
425
426 return( false );
427}
428
429//---------------------------------------------------------
431{
432 Projection.Destroy();
433
434 Parameters.DataObjects_Get_Projection(Projection);
435
436 for(int i=0; i<Get_Parameters_Count() && !Projection.is_Okay(); i++)
437 {
438 Get_Parameters(i)->DataObjects_Get_Projection(Projection);
439 }
440
441 return( Projection.is_Okay() );
442}
443
444
446// //
447// Parameters //
448// //
450
451//---------------------------------------------------------
453{
454 CSG_Parameters *pParameters = pParameter ? pParameter ->Get_Parameters() : NULL;
455 CSG_Tool *pTool = pParameters ? pParameters->Get_Tool () : NULL;
456
457 if( pTool )
458 {
459 if( Flags & PARAMETER_CHECK_VALUES )
460 {
461 pTool->On_Parameter_Changed(pParameters, pParameter);
462 }
463
464 if( Flags & PARAMETER_CHECK_ENABLE )
465 {
466 pTool->On_Parameters_Enable(pParameters, pParameter);
467 }
468
469 return( 1 );
470 }
471
472 return( 0 );
473}
474
475//---------------------------------------------------------
477{
478 return( 1 );
479}
480
481//---------------------------------------------------------
483{
484 return( 1 );
485}
486
487
489// //
490// Extra Parameters //
491// //
493
494//---------------------------------------------------------
495CSG_Parameters * CSG_Tool::Add_Parameters(const CSG_String &Identifier, const CSG_String &Name, const CSG_String &Description)
496{
497 CSG_Parameters *pParameters = new CSG_Parameters(); // (Name, Description, Identifier);
498
499 pParameters->Create(this, Name, Description, Identifier);
501 pParameters->m_pTool = this;
502
503 m_pParameters.Add(pParameters);
504
505 return( pParameters );
506}
507
508//---------------------------------------------------------
510{
511 for(int i=0; i<Get_Parameters_Count(); i++)
512 {
513 if( Get_Parameters(i)->Cmp_Identifier(Identifier) )
514 {
515 return( Get_Parameters(i) );
516 }
517 }
518
519 return( NULL );
520}
521
522//---------------------------------------------------------
524{
525 CSG_Parameters *pParameters = Get_Parameters(Identifier);
526
527 if( pParameters && (!pParameters->is_Managed() || Dlg_Parameters(pParameters, Get_Name())) )
528 {
529 pParameters->Set_History(History_Supplement);
530
531 return( true );
532 }
533
534 return( false );
535}
536
537
539// //
541
542//---------------------------------------------------------
543bool CSG_Tool::Dlg_Parameters(CSG_Parameters *pParameters, const CSG_String &Caption)
544{
545 return( pParameters ? Dlg_Parameters(*pParameters, Caption) : false );
546}
547
549{
550 return( SG_UI_Dlg_Parameters(&Parameters, Caption.is_Empty() ? Get_Name() : Caption) );
551}
552
553
555// //
557
558//---------------------------------------------------------
559void CSG_Tool::Set_Callback(bool bActive)
560{
561 Parameters.Set_Callback(bActive);
562
563 for(int i=0; i<Get_Parameters_Count(); i++)
564 {
565 Get_Parameters(i)->Set_Callback(bActive);
566 }
567}
568
569//---------------------------------------------------------
571{
572 Parameters.Set_Manager(pManager);
573
574 for(int i=0; i<Get_Parameters_Count(); i++)
575 {
576 Get_Parameters(i)->Set_Manager(pManager);
577 }
578
579 return( true );
580}
581
582//---------------------------------------------------------
584{
585 return( Parameters.Get_Manager() );
586}
587
588//---------------------------------------------------------
590{
592
593 return( Get_Manager() );
594}
595
596//---------------------------------------------------------
597bool CSG_Tool::Delete_Manager(bool bDetachData, bool bReset)
598{
599 CSG_Data_Manager *pManager = Get_Manager();
600
601 if( pManager && pManager != &SG_Get_Data_Manager() )
602 {
603 pManager->Delete(bDetachData);
604
605 delete(pManager);
606
607 return( bReset ? Set_Manager(&SG_Get_Data_Manager()) : Set_Manager(NULL) );
608 }
609
610 return( false );
611}
612
613
615// //
616// //
617// //
619
620//---------------------------------------------------------
622{
623 Parameters.Push(pManager);
624
625 for(int i=0; i<Get_Parameters_Count(); i++)
626 {
627 Get_Parameters(i)->Push(pManager);
628 }
629
630 return( true );
631}
632
633//---------------------------------------------------------
635{
636 Parameters.Pop();
637
638 for(int i=0; i<Get_Parameters_Count(); i++)
639 {
640 Get_Parameters(i)->Pop();
641 }
642
643 return( true );
644}
645
646
648// //
649// Progress //
650// //
652
653//---------------------------------------------------------
655{
656 m_bShow_Progress = bOn;
657}
658
659//---------------------------------------------------------
660bool CSG_Tool::Set_Progress(int Position, int Range) const
661{
662 return( Set_Progress((double)Position / (double)Range) );
663}
664
665//---------------------------------------------------------
666bool CSG_Tool::Set_Progress(sLong Position, sLong Range) const
667{
668 return( Set_Progress((double)Position / (double)Range) );
669}
670
671//---------------------------------------------------------
672bool CSG_Tool::Set_Progress(double Position, double Range) const
673{
674 return( m_bShow_Progress ? SG_UI_Process_Set_Progress(Position, Range) : Process_Get_Okay(false) );
675}
676
677//---------------------------------------------------------
678bool CSG_Tool::Stop_Execution(bool bDialog)
679{
680 m_bExecutes = false;
681
682 return( SG_UI_Stop_Execution(bDialog) );
683}
684
685
687// //
688// Message //
689// //
691
692//---------------------------------------------------------
693void CSG_Tool::Message_Dlg(const CSG_String &Text, const SG_Char *Caption)
694{
695 SG_UI_Dlg_Message(Text, Caption && Caption[0] != '\0' ? Caption : Get_Name().c_str());
696}
697
698//---------------------------------------------------------
699bool CSG_Tool::Message_Dlg_Confirm(const CSG_String &Text, const SG_Char *Caption)
700{
701 return( SG_UI_Dlg_Continue(Text, Caption && Caption[0] != '\0' ? Caption : Get_Name().c_str()) );
702}
703
704//---------------------------------------------------------
706{
707 switch( Error_ID )
708 {
709 default:
710 return( Error_Set(_TL("Unknown Error")) );
711
713 return( Error_Set(_TL("Calculation Error")) );
714 }
715}
716
717//---------------------------------------------------------
719{
721
722 m_Execution_Info += "\n____\n" + Text;
723
724 if( SG_UI_Process_Get_Okay(false) && !m_bError_Ignore )
725 {
726 switch( SG_UI_Dlg_Error(Text, CSG_String::Format("%s: %s?", _TL("Error"), _TL("Ignore"))) )
727 {
728 default:
730 break;
731
732 case 1:
733 m_bError_Ignore = true;
734 break;
735 }
736 }
737
738 return( SG_UI_Process_Get_Okay(false) );
739}
740
741//---------------------------------------------------------
742bool CSG_Tool::Error_Fmt(const char *Format, ...)
743{
744 wxString _s;
745
746 va_list argptr;
747
748#ifdef _SAGA_LINUX
749 // workaround as we only use wide characters
750 // since wx 2.9.4 so interpret strings as multibyte
751 wxString _Format(Format); _Format.Replace("%s", "%ls");
752 va_start(argptr, _Format);
753 _s.PrintfV(_Format, argptr);
754#else
755 va_start(argptr, Format);
756 _s.PrintfV(Format, argptr);
757#endif
758
759 va_end(argptr);
760
761 CSG_String s(&_s);
762
763 return( Error_Set(s) );
764}
765
766//---------------------------------------------------------
767bool CSG_Tool::Error_Fmt(const wchar_t *Format, ...)
768{
769 wxString _s;
770
771 va_list argptr;
772
773#ifdef _SAGA_LINUX
774 // workaround as we only use wide characters
775 // since wx 2.9.4 so interpret strings as multibyte
776 wxString _Format(Format); _Format.Replace("%s", "%ls");
777 va_start(argptr, _Format);
778 _s.PrintfV(_Format, argptr);
779#else
780 va_start(argptr, Format);
781 _s.PrintfV(Format, argptr);
782#endif
783
784 va_end(argptr);
785
786 CSG_String s(&_s);
787
788 return( Error_Set(s) );
789}
790
791
793// //
794// DataObjects / GUI Interaction //
795// //
797
798//---------------------------------------------------------
799bool CSG_Tool::DataObject_Add(CSG_Data_Object *pDataObject, bool bShow)
800{
801 if( Parameters.Get_Manager() )
802 {
803 Parameters.Get_Manager()->Add(pDataObject);
804 }
805
806 if( Parameters.Get_Manager() == &SG_Get_Data_Manager() ) // prevent that local data manager send their data objects to gui
807 {
809 }
810
811 return( true );
812}
813
814//---------------------------------------------------------
816{
817 for(int i=0; i<Parameters.Get_Count(); i++)
818 {
819 if( Parameters(i)->is_Output() )
820 {
821 if( Parameters(i)->is_DataObject() )
822 {
823 DataObject_Update(Parameters(i)->asDataObject(), false);
824 }
825 else if( Parameters(i)->is_DataObject_List() )
826 {
827 for(int j=0; j<Parameters(i)->asList()->Get_Item_Count(); j++)
828 {
829 DataObject_Update(Parameters(i)->asList()->Get_Item(j), false);
830 }
831 }
832 }
833 }
834
835 return( true );
836}
837
838
840// //
841// Static Data Message/Progress Functions //
842// //
844
845//---------------------------------------------------------
847{
848 return( SG_UI_Process_Get_Okay(bBlink) );
849}
850
851//---------------------------------------------------------
853{
855}
856
857//---------------------------------------------------------
858void CSG_Tool::Process_Set_Text(const char *Format, ...)
859{
860 wxString _s;
861
862 va_list argptr;
863
864 #ifdef _SAGA_LINUX
865 // workaround as we only use wide characters
866 // since wx 2.9.4 so interpret strings as multibyte
867 wxString _Format(Format); _Format.Replace("%s", "%ls");
868 va_start(argptr, _Format);
869 _s.PrintfV(_Format, argptr);
870 #else
871 va_start(argptr, Format);
872 _s.PrintfV(Format, argptr);
873 #endif
874
875 va_end(argptr);
876
877 CSG_String s(&_s);
878
880}
881
882//---------------------------------------------------------
883void CSG_Tool::Process_Set_Text(const wchar_t *Format, ...)
884{
885 wxString _s;
886
887 va_list argptr;
888
889 #ifdef _SAGA_LINUX
890 // workaround as we only use wide characters
891 // since wx 2.9.4 so interpret strings as multibyte
892 wxString _Format(Format); _Format.Replace("%s", "%ls");
893 va_start(argptr, _Format);
894 _s.PrintfV(_Format, argptr);
895 #else
896 va_start(argptr, Format);
897 _s.PrintfV(Format, argptr);
898 #endif
899
900 va_end(argptr);
901
902 CSG_String s(&_s);
903
905}
906
907//---------------------------------------------------------
908void CSG_Tool::Message_Add(const CSG_String &Text, bool bNewLine)
909{
910 SG_UI_Msg_Add_Execution(Text, bNewLine);
911
912 if( bNewLine )
913 {
914 m_Execution_Info += "\n";
915 }
916
917 m_Execution_Info += Text;
918}
919
920//---------------------------------------------------------
921void CSG_Tool::Message_Fmt(const char *Format, ...)
922{
923 wxString _s;
924
925 va_list argptr;
926
927 #ifdef _SAGA_LINUX
928 // workaround as we only use wide characters
929 // since wx 2.9.4 so interpret strings as multibyte
930 wxString _Format(Format); _Format.Replace("%s", "%ls");
931 va_start(argptr, _Format);
932 _s.PrintfV(_Format, argptr);
933 #else
934 va_start(argptr, Format);
935 _s.PrintfV(Format, argptr);
936 #endif
937
938 va_end(argptr);
939
940 CSG_String s(&_s);
941
942 Message_Add(s, false);
943}
944
945//---------------------------------------------------------
946void CSG_Tool::Message_Fmt(const wchar_t *Format, ...)
947{
948 wxString _s;
949
950 va_list argptr;
951
952 #ifdef _SAGA_LINUX
953 // workaround as we only use wide characters
954 // since wx 2.9.4 so interpret strings as multibyte
955 wxString _Format(Format); _Format.Replace("%s", "%ls");
956 va_start(argptr, _Format);
957 _s.PrintfV(_Format, argptr);
958 #else
959 va_start(argptr, Format);
960 _s.PrintfV(Format, argptr);
961 #endif
962
963 va_end(argptr);
964
965 CSG_String s(&_s);
966
967 Message_Add(s, false);
968}
969
970
972// //
973// Static Data Object Property Functions //
974// //
976
977//---------------------------------------------------------
979{
980 return( SG_UI_DataObject_Update(pDataObject, Show, NULL) );
981}
982
983bool CSG_Tool::DataObject_Update(CSG_Data_Object *pDataObject, double Minimum, double Maximum, int Show)
984{
986
987 return( DataObject_Get_Parameters(pDataObject, P)
988 && P.Set_Parameter("STRETCH_DEFAULT" , 3 ) // manual
989 && P.Set_Parameter("METRIC_ZRANGE.MIN", Minimum)
990 && P.Set_Parameter("METRIC_ZRANGE.MAX", Maximum)
991 && SG_UI_DataObject_Update(pDataObject, Show, &P)
992 );
993}
994
995//---------------------------------------------------------
997{
998 return( SG_UI_DataObject_Colors_Get(pDataObject, &Colors) );
999}
1000
1002{
1003 CSG_Colors c; return( c.Create(Colors) && SG_UI_DataObject_Colors_Set(pDataObject, &c) );
1004}
1005
1006bool CSG_Tool::DataObject_Set_Colors(CSG_Data_Object *pDataObject, int nColors, int Colors, bool bRevert)
1007{
1008 CSG_Colors c; return( c.Set_Predefined(Colors, bRevert, nColors) && SG_UI_DataObject_Colors_Set(pDataObject, &c) );
1009}
1010
1011bool CSG_Tool::DataObject_Set_Colors(CSG_Data_Object *pDataObject, const CSG_String &Colors, int nColors, bool bRevert)
1012{
1013 CSG_Colors c; return( c.Set_Predefined(Colors, bRevert, nColors) && SG_UI_DataObject_Colors_Set(pDataObject, &c) );
1014}
1015
1016//---------------------------------------------------------
1021
1026
1028{
1029 if( pDataObject == pCopy )
1030 {
1031 return( true );
1032 }
1033
1035
1036 if( DataObject_Get_Parameters(pCopy, P) )
1037 {
1038 P.Del_Parameter("OBJECT_NODATA" );
1039 P.Del_Parameter("OBJECT_Z_FACTOR");
1040 P.Del_Parameter("OBJECT_Z_OFFSET");
1041
1042 return( DataObject_Set_Parameters(pDataObject, P) );
1043 }
1044
1045 return( false );
1046}
1047
1048//---------------------------------------------------------
1050{
1051 static CSG_Parameters P;
1052
1053 return( DataObject_Get_Parameters(pDataObject, P) ? P(ID) : NULL );
1054}
1055
1057{
1059
1060 return( P._Add(pParameter) != NULL && DataObject_Set_Parameters(pDataObject, P) );
1061}
1062
1064{
1065 CSG_Parameter *pParameter = DataObject_Get_Parameter(pCopy, ID);
1066
1067 return( DataObject_Set_Parameter(pDataObject, pParameter) );
1068}
1069
1070bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, int Value)
1071{
1073
1074 if( DataObject_Get_Parameters(pDataObject, P) && P(ID) )
1075 {
1076 return( P(ID)->Set_Value(Value) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1077 }
1078
1079 return( false );
1080}
1081
1082bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, double Value)
1083{
1085
1086 if( DataObject_Get_Parameters(pDataObject, P) && P(ID) )
1087 {
1088 return( P(ID)->Set_Value(Value) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1089 }
1090
1091 return( false );
1092}
1093
1094bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, void *Value)
1095{
1097
1098 if( DataObject_Get_Parameters(pDataObject, P) && P(ID) )
1099 {
1100 return( P(ID)->Set_Value(Value) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1101 }
1102
1103 return( false );
1104}
1105
1106bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, const SG_Char *Value)
1107{
1109
1110 if( DataObject_Get_Parameters(pDataObject, P) && P(ID) )
1111 {
1112 return( P(ID)->Set_Value(Value) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1113 }
1114
1115 return( false );
1116}
1117
1118bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, double loVal, double hiVal) // Range Parameter
1119{
1121
1122 if( DataObject_Get_Parameters(pDataObject, P) && P(ID) && P(ID)->Get_Type() == PARAMETER_TYPE_Range )
1123 {
1124 return( P(ID)->asRange()->Set_Range(loVal, hiVal) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1125 }
1126
1127 return( false );
1128}
1129
1130
1132// //
1134
1135//---------------------------------------------------------
1136#define INIT_STRETCH_OPTIONS(method) { if( !pDataObject || (pDataObject->asTable(true) && (Field < 0 || Field >= pDataObject->asTable(true)->Get_Field_Count())) ) { return( false ); }\
1137 if( Colors >= 0 ) { DataObject_Set_Colors(pDataObject, -1, Colors); }\
1138 DataObject_Set_Parameter(pDataObject, "COLORS_TYPE" , 3); /* graduated colors */\
1139 DataObject_Set_Parameter(pDataObject, "STRETCH_DEFAULT" , method);\
1140 DataObject_Set_Parameter(pDataObject, "METRIC_SCALE_MODE", Interval_Mode);\
1141 DataObject_Set_Parameter(pDataObject, "METRIC_SCALE_LOG" , Interval_Log );\
1142 if( pDataObject->asTable(true) )\
1143 { DataObject_Set_Parameter(pDataObject, "METRIC_FIELD" , Field);\
1144 DataObject_Set_Parameter(pDataObject, "METRIC_MORMAL", pDataObject->asTable(true)->Get_Field_Count());\
1145 }\
1146}
1147
1148//---------------------------------------------------------
1149bool CSG_Tool::DataObject_Set_Stretch_Linear(CSG_Data_Object *pDataObject, int Field, double Minimum, double Maximum, int Interval_Mode, double Interval_Log, int Colors, bool bUpdateNow)
1150{
1152
1153 DataObject_Set_Parameter(pDataObject, "STRETCH_LINEAR.MIN", Minimum);
1154 DataObject_Set_Parameter(pDataObject, "STRETCH_LINEAR.MAX", Maximum);
1155
1156 return( bUpdateNow ? DataObject_Update(pDataObject) : true );
1157}
1158
1159//---------------------------------------------------------
1160bool CSG_Tool::DataObject_Set_Stretch_StdDev(CSG_Data_Object *pDataObject, int Field, double StdDev, bool bKeepInRange, int Interval_Mode, double Interval_Log, int Colors, bool bUpdateNow)
1161{
1163
1164 DataObject_Set_Parameter(pDataObject, "STRETCH_STDDEV" , StdDev );
1165 DataObject_Set_Parameter(pDataObject, "STRETCH_INRANGE", bKeepInRange);
1166 DataObject_Update(pDataObject);
1167
1168 return( bUpdateNow ? DataObject_Update(pDataObject) : true );
1169}
1170
1171//---------------------------------------------------------
1172bool CSG_Tool::DataObject_Set_Stretch_Percentile(CSG_Data_Object *pDataObject, int Field, double Minimum, double Maximum, int Interval_Mode, double Interval_Log, int Colors, bool bUpdateNow)
1173{
1175
1176 DataObject_Set_Parameter(pDataObject, "STRETCH_PCTL.MIN", Minimum);
1177 DataObject_Set_Parameter(pDataObject, "STRETCH_PCTL.MAX", Maximum);
1178
1179 return( bUpdateNow ? DataObject_Update(pDataObject) : true );
1180}
1181
1182//---------------------------------------------------------
1183bool CSG_Tool::DataObject_Set_Stretch(CSG_Data_Object *pDataObject, int Field, double Minimum, double Maximum, int Interval_Mode, double Interval_Log, int Colors, bool bUpdateNow)
1184{
1186
1187 DataObject_Set_Parameter(pDataObject, "METRIC_ZRANGE.MIN", Minimum);
1188 DataObject_Set_Parameter(pDataObject, "METRIC_ZRANGE.MAX", Maximum);
1189
1190 return( bUpdateNow ? DataObject_Update(pDataObject) : true );
1191}
1192
1193
1195// //
1197
1198//---------------------------------------------------------
1199#define INIT_CLASSIFY_OPTIONS(method) if( !pDataObject || (pDataObject->asTable(true) && (Field < 0 || Field >= pDataObject->asTable(true)->Get_Field_Count())) ) { return( false ); }\
1200 CSG_MetaData Options; Options.Add_Child("METHOD", method); Options.Add_Child("COLORS", Colors); Options.Add_Child("FIELD", Field);
1201
1202//---------------------------------------------------------
1203bool CSG_Tool::DataObject_Classify_Unique(CSG_Data_Object *pDataObject, int Field, int maxClasses, int Colors)
1204{
1206
1207 Options.Add_Child("MAXCLASSES", maxClasses);
1208
1209 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1210}
1211
1212//---------------------------------------------------------
1213bool CSG_Tool::DataObject_Classify_Equal(CSG_Data_Object *pDataObject, int Field, int Classes, int Colors)
1214{
1216
1217 Options.Add_Child("CLASSES", Classes);
1218
1219 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1220}
1221
1222//---------------------------------------------------------
1223bool CSG_Tool::DataObject_Classify_Defined(CSG_Data_Object *pDataObject, int Field, double Interval, bool bOffset, double Offset, int Colors)
1224{
1226
1227 Options.Add_Child("INTERVAL", Interval); if( bOffset ) { Options.Add_Child("OFFSET", Offset); }
1228
1229 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1230}
1231
1232//---------------------------------------------------------
1233bool CSG_Tool::DataObject_Classify_Quantile(CSG_Data_Object *pDataObject, int Field, int Classes, bool bHistogram, int Colors)
1234{
1236
1237 Options.Add_Child("CLASSES", Classes); Options.Add_Child("HISTOGRAM", bHistogram ? 1 : 0);
1238
1239 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1240}
1241
1242//---------------------------------------------------------
1243bool CSG_Tool::DataObject_Classify_Geometric(CSG_Data_Object *pDataObject, int Field, int Classes, bool bIncreasing, int Colors)
1244{
1246
1247 Options.Add_Child("CLASSES", Classes); Options.Add_Child("INCREASING", bIncreasing ? 1 : 0);
1248
1249 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1250}
1251
1252//---------------------------------------------------------
1253bool CSG_Tool::DataObject_Classify_Natural(CSG_Data_Object *pDataObject, int Field, int Classes, int Colors)
1254{
1256
1257 Options.Add_Child("CLASSES", Classes);
1258
1259 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1260}
1261
1262//---------------------------------------------------------
1263bool CSG_Tool::DataObject_Classify_StdDev(CSG_Data_Object *pDataObject, int Field, double StdDev, double StdDev_Max, int Colors)
1264{
1266
1267 Options.Add_Child("STDDEV", StdDev); Options.Add_Child("STDDEV_MAX", StdDev_Max);
1268
1269 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1270}
1271
1272
1274// //
1275// //
1276// //
1278
1279//---------------------------------------------------------
1283//---------------------------------------------------------
1284bool CSG_Tool::Set_Parameter(const CSG_String &ID, CSG_Parameter *pValue) { return( Parameters.Set_Parameter(ID, pValue) ); }
1285bool CSG_Tool::Set_Parameter(const char *ID, CSG_Parameter *pValue) { return( Parameters.Set_Parameter(ID, pValue) ); }
1286bool CSG_Tool::Set_Parameter(const wchar_t *ID, CSG_Parameter *pValue) { return( Parameters.Set_Parameter(ID, pValue) ); }
1287
1288//---------------------------------------------------------
1292//---------------------------------------------------------
1293bool CSG_Tool::Set_Parameter(const CSG_String &ID, int Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1294bool CSG_Tool::Set_Parameter(const char *ID, int Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1295bool CSG_Tool::Set_Parameter(const wchar_t *ID, int Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1296
1297//---------------------------------------------------------
1301//---------------------------------------------------------
1302bool CSG_Tool::Set_Parameter(const CSG_String &ID, double Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1303bool CSG_Tool::Set_Parameter(const char *ID, double Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1304bool CSG_Tool::Set_Parameter(const wchar_t *ID, double Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1305
1306//---------------------------------------------------------
1310//---------------------------------------------------------
1311bool CSG_Tool::Set_Parameter(const CSG_String &ID, void *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1312bool CSG_Tool::Set_Parameter(const char *ID, void *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1313bool CSG_Tool::Set_Parameter(const wchar_t *ID, void *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1314
1315//---------------------------------------------------------
1319//---------------------------------------------------------
1320bool CSG_Tool::Set_Parameter(const CSG_String &ID, const CSG_String &Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1321bool CSG_Tool::Set_Parameter(const char *ID, const CSG_String &Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1322bool CSG_Tool::Set_Parameter(const wchar_t *ID, const CSG_String &Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1323
1324//---------------------------------------------------------
1328//---------------------------------------------------------
1329bool CSG_Tool::Set_Parameter(const CSG_String &ID, const char *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1330bool CSG_Tool::Set_Parameter(const char *ID, const char *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1331bool CSG_Tool::Set_Parameter(const wchar_t *ID, const char *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1332
1333//---------------------------------------------------------
1337//---------------------------------------------------------
1338bool CSG_Tool::Set_Parameter(const CSG_String &ID, const wchar_t *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1339bool CSG_Tool::Set_Parameter(const char *ID, const wchar_t *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1340bool CSG_Tool::Set_Parameter(const wchar_t *ID, const wchar_t *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1341
1342
1344// //
1345// //
1346// //
1348
1349//---------------------------------------------------------
1355bool CSG_Tool::Reset(bool bManager)
1356{
1358
1359 if( bManager )
1360 {
1361 Reset_Manager();
1362 }
1363
1364 for(int i=0; i<Get_Parameters_Count(); i++)
1365 {
1367 }
1368
1369 return( Parameters.Restore_Defaults(true) );
1370}
1371
1372//---------------------------------------------------------
1378{
1379 return( Set_Manager(&SG_Get_Data_Manager()) );
1380}
1381
1382//---------------------------------------------------------
1388{
1389 for(int i=0; i<Get_Parameters_Count(); i++)
1390 {
1392 }
1393
1394 return( Parameters.Reset_Grid_System() );
1395}
1396
1397//---------------------------------------------------------
1403{
1404 return( Parameters.Set_Grid_System(System) );
1405}
1406
1407//---------------------------------------------------------
1413{
1414 return( Parameters.Get_Grid_System() );
1415}
1416
1417
1419// //
1420// //
1421// //
1423
1424//---------------------------------------------------------
1426{
1427 _Update_Parameter_States(&Parameters);
1428
1429 for(int i=0; i<Get_Parameters_Count(); i++)
1430 {
1431 _Update_Parameter_States(Get_Parameters(i));
1432 }
1433
1434 return( true );
1435}
1436
1437//---------------------------------------------------------
1438void CSG_Tool::_Update_Parameter_States(CSG_Parameters *pParameters)
1439{
1440 if( pParameters )
1441 {
1442 for(int i=0; i<pParameters->Get_Count(); i++)
1443 {
1444 CSG_Parameter *pParameter = pParameters->Get_Parameter(i);
1445
1446 if( pParameter->Get_Type() == PARAMETER_TYPE_Parameters )
1447 {
1448 _Update_Parameter_States(pParameter->asParameters());
1449 }
1450 else
1451 {
1452 On_Parameters_Enable(pParameters, pParameter);
1453 }
1454 }
1455 }
1456}
1457
1458
1460// //
1461// Script //
1462// //
1464
1465//---------------------------------------------------------
1466CSG_String CSG_Tool::Get_Script(Script_Format Format, bool bHeader, int Arguments, bool bWrapArgs)
1467{
1468 switch( Format )
1469 {
1470 case Script_Format::CMD_Shell : return( _Get_Script_CMD ( bHeader, Arguments > 0, bWrapArgs, false ) );
1471 case Script_Format::CMD_Batch : return( _Get_Script_CMD ( bHeader, Arguments > 0, bWrapArgs, true ) );
1472 case Script_Format::CMD_Usage : return( _Get_Script_CMD_Usage ( ) );
1473
1474 case Script_Format::Toolchain : return( CSG_Tool_Chain::Get_Script(this, bHeader, Arguments > 0 ) );
1475
1476 case Script_Format::Python : return( _Get_Script_Python ( bHeader, Arguments > 0 ) );
1477
1478 case Script_Format::Python_Wrapper_Func_Name : return( _Get_Script_Python_Wrap ( bHeader, true , false, 1, bWrapArgs ) );
1479 case Script_Format::Python_Wrapper_Func_ID : return( _Get_Script_Python_Wrap ( bHeader, false, false, 1, bWrapArgs ) );
1480
1481 case Script_Format::Python_Wrapper_Call_Name : return( _Get_Script_Python_Wrap ( bHeader, true , true , Arguments, bWrapArgs ) );
1482 case Script_Format::Python_Wrapper_Call_ID : return( _Get_Script_Python_Wrap ( bHeader, false, true , Arguments, bWrapArgs ) );
1483
1484 case Script_Format::Markdown_Table : return( _Get_Script_Markdown ( bHeader, Arguments ) );
1485 }
1486
1487 return( "" );
1488}
1489
1490
1492// //
1494
1495//---------------------------------------------------------
1496CSG_String CSG_Tool::_Get_Script_CMD(bool bHeader, bool bAllArguments, bool bWrapArgs, bool bBatch)
1497{
1498 CSG_String Script;
1499
1500 if( bHeader )
1501 {
1502 if( bBatch ) // DOS/Windows Batch Script
1503 {
1504 Script += "@ECHO OFF\n\n";
1505 Script += "PUSHD %~dp0\n\n";
1506 Script += "REM SET SAGA_TLB=C:\\MyTools\n\n";
1507 Script += "SET SAGA_CMD=" + SG_UI_Get_Application_Path(true) + "saga_cmd.exe\n\n";
1508 Script += "REM Tool: " + Get_Name() + "\n\n";
1509 Script += "%SAGA_CMD%";
1510 }
1511 else // Bash Shell Script
1512 {
1513 Script += "#!/bin/bash\n\n";
1514 Script += "# export SAGA_TLB=~/mytools\n\n";
1515 Script += "# tool: " + Get_Name() + "\n\n";
1516 Script += "saga_cmd";
1517 }
1518 }
1519 else
1520 {
1521 Script += "saga_cmd";
1522 }
1523
1524 //-----------------------------------------------------
1525 Script += Get_Library().Contains(" ") // white space? use quotation marks!
1526 ? " \"" + Get_Library() + "\""
1527 : " " + Get_Library();
1528
1529 Script += Get_ID().Contains (" ") // white space? use quotation marks!
1530 ? " \"" + Get_ID () + "\""
1531 : " " + Get_ID ();
1532
1533 _Get_Script_CMD(Script, Get_Parameters(), bAllArguments, bWrapArgs, bBatch);
1534
1535 for(int i=0; i<Get_Parameters_Count(); i++)
1536 {
1537 _Get_Script_CMD(Script, Get_Parameters(i), bAllArguments, bWrapArgs, bBatch);
1538 }
1539
1540 //-----------------------------------------------------
1541 if( bHeader )
1542 {
1543 Script += bBatch ? "\n\nPAUSE\n" : "\n";
1544 }
1545
1546 return( Script );
1547}
1548
1549//---------------------------------------------------------
1550void CSG_Tool::_Get_Script_CMD(CSG_String &Script, CSG_Parameters *pParameters, bool bAllArguments, bool bWrapArgs, bool bBatch)
1551{
1552 #define GET_ID1(p) (p->Get_Parameters()->Get_Identifier().Length() > 0 \
1553 ? CSG_String::Format("%s_%s", p->Get_Parameters()->Get_Identifier().c_str(), p->Get_Identifier()) \
1554 : CSG_String::Format(p->Get_Identifier())).c_str()
1555
1556 #define GET_ID2(p, s) CSG_String::Format("%s_%s", GET_ID1(p), s).c_str()
1557
1558 const char *Prefix = !bWrapArgs ? " -" : bBatch ? " ^\n -" : " \\\n -";
1559 const char *StrFmt = bBatch ? "%s=\"%s\"" : "%s=\\\"\"%s\"\\\"";
1560
1561 //-----------------------------------------------------
1562 for(int iParameter=0; iParameter<pParameters->Get_Count(); iParameter++)
1563 {
1564 CSG_Parameter *p = pParameters->Get_Parameter(iParameter);
1565
1566 if( !bAllArguments && (!p->is_Enabled(false) || p->is_Information() || !p->do_UseInCMD()) )
1567 {
1568 continue;
1569 }
1570
1571 switch( p->Get_Type() )
1572 {
1573 default:
1574 break;
1575
1576 case PARAMETER_TYPE_Bool :
1577 Script += Prefix + CSG_String::Format("%s=%d", GET_ID1(p), p->asBool() ? 1 : 0);
1578 break;
1579
1580 case PARAMETER_TYPE_Int :
1584 Script += Prefix + CSG_String::Format("%s=%d", GET_ID1(p), p->asInt());
1585 break;
1586
1589 if( p->asString() && *p->asString() )
1590 {
1591 Script += Prefix + CSG_String::Format(StrFmt, GET_ID1(p), p->asString());
1592 }
1593 break;
1594
1596 Script += Prefix + CSG_String::Format("%s=\"%s\"", GET_ID1(p), SG_Color_To_Text(p->asColor()).c_str());
1597 break;
1598
1601 Script += Prefix + CSG_String::Format("%s=%g", GET_ID1(p), p->asDouble());
1602 break;
1603
1605 Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T("MIN")), p->asRange()->Get_Min());
1606 Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T("MAX")), p->asRange()->Get_Max());
1607 break;
1608
1610 if( ((CSG_Parameter_String *)p)->is_Password() )
1611 {
1612 Script += Prefix + CSG_String::Format("%s=\"***\"", GET_ID1(p));
1613 break;
1614 }
1615
1616 case PARAMETER_TYPE_Date :
1617 case PARAMETER_TYPE_Text :
1619 Script += Prefix + CSG_String::Format(StrFmt, GET_ID1(p), p->asString());
1620 break;
1621
1623 Script += Prefix + CSG_String::Format(StrFmt, GET_ID1(p), p->asString());
1624 break;
1625
1627 if( p->Get_Children_Count() == 0 )
1628 {
1629 Script += Prefix + CSG_String::Format("%s=%d", GET_ID2(p, SG_T("NX")), p->asGrid_System()->Get_NX ());
1630 Script += Prefix + CSG_String::Format("%s=%d", GET_ID2(p, SG_T("NY")), p->asGrid_System()->Get_NY ());
1631 Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T( "X")), p->asGrid_System()->Get_XMin ());
1632 Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T( "Y")), p->asGrid_System()->Get_YMin ());
1633 Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T( "D")), p->asGrid_System()->Get_Cellsize());
1634 }
1635 break;
1636
1638 case PARAMETER_TYPE_Grid :
1642 case PARAMETER_TYPE_TIN :
1644 if( p->is_Input() )
1645 {
1646 Script += Prefix + CSG_String::Format(StrFmt, GET_ID1(p), SG_Get_Data_Manager().Exists(p->asDataObject()) && p->asDataObject()->Get_File_Name() ? p->asDataObject()->Get_File_Name() : SG_T("input file"));
1647 }
1648 else
1649 {
1650 CSG_String File(p->Get_Name());
1651
1652 switch( p->Get_DataObject_Type() )
1653 {
1654 case SG_DATAOBJECT_TYPE_Grid : File += ".sg-grd-z"; break;
1655 case SG_DATAOBJECT_TYPE_Grids : File += ".sg-gds-z"; break;
1656 case SG_DATAOBJECT_TYPE_Table : File += ".txt" ; break;
1657 case SG_DATAOBJECT_TYPE_Shapes : File += ".geojson" ; break;
1658 case SG_DATAOBJECT_TYPE_PointCloud: File += ".sg-pts-z"; break;
1659 case SG_DATAOBJECT_TYPE_TIN : File += ".geojson" ; break;
1660 default : File += ".dat" ; break;
1661 }
1662
1663 Script += Prefix + CSG_String::Format(StrFmt, GET_ID1(p), File.c_str());
1664 }
1665 break;
1666
1673 if( p->is_Input() )
1674 {
1675 Script += Prefix + CSG_String::Format("%s=", GET_ID1(p));
1676
1677 if( p->asList()->Get_Item_Count() == 0 )
1678 {
1679 Script += "file(s)";
1680 }
1681 else
1682 {
1683 Script += SG_File_Exists(p->asList()->Get_Item(0)->Get_File_Name())
1684 ? p->asList()->Get_Item(0)->Get_File_Name() : _TL("memory");
1685
1686 for(int iObject=1; iObject<p->asList()->Get_Item_Count(); iObject++)
1687 {
1688 Script += ";";
1689 Script += SG_File_Exists(p->asList()->Get_Item(iObject)->Get_File_Name())
1690 ? p->asList()->Get_Item(iObject)->Get_File_Name() : _TL("memory");
1691 }
1692 }
1693 }
1694 else
1695 {
1696 Script += Prefix + CSG_String::Format(StrFmt, GET_ID1(p), p->Get_Name());
1697 }
1698 break;
1699 }
1700 }
1701}
1702
1703
1705// //
1707
1708//---------------------------------------------------------
1709CSG_String CSG_Tool::_Get_Script_CMD_Usage(void)
1710{
1711 wxCmdLineParser Parser; Parser.SetSwitchChars("-");
1712
1713 _Get_Script_CMD_Usage(Get_Parameters(), Parser);
1714
1715 for(int i=0; i<Get_Parameters_Count(); i++)
1716 {
1717 _Get_Script_CMD_Usage(Get_Parameters(i), Parser);
1718 }
1719
1720 wxString Usage = wxString::Format("\nUsage: saga_cmd %s %s %s", Get_Library().c_str(), Get_ID().c_str(),
1721 Parser.GetUsageString().AfterFirst(' ').AfterFirst(' ')
1722 );
1723
1724 CSG_String _Usage(&Usage);
1725
1726 return( _Usage );
1727}
1728
1729//---------------------------------------------------------
1730void CSG_Tool::_Get_Script_CMD_Usage(CSG_Parameters *pParameters, wxCmdLineParser &Parser)
1731{
1732 for(int i=0; i<pParameters->Get_Count(); i++)
1733 {
1734 CSG_Parameter *pParameter = pParameters->Get_Parameter(i);
1735
1736 //-------------------------------------------------
1737 if( pParameter->is_DataObject() ) // reset data object parameters, avoids problems when tool is called more than once without un-/reloading
1738 {
1739 pParameter->Set_Value(DATAOBJECT_NOTSET);
1740 }
1741 else if( pParameter->is_DataObject_List() )
1742 {
1743 pParameter->asList()->Del_Items();
1744 }
1745
1746 //-------------------------------------------------
1747 if( pParameter->do_UseInCMD() == false )
1748 {
1749 continue;
1750 }
1751
1752 wxString Description = pParameter->Get_Description(
1754 ).c_str();
1755
1756 Description.Replace("\xb", ""); // unicode problem: quick'n'dirty bug fix, to be replaced
1757
1758 wxString ID(pParameter->Get_CmdID().c_str());
1759
1760 if( pParameter->is_Input() || pParameter->is_Output() )
1761 {
1762 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_NEEDS_SEPARATOR|wxCMD_LINE_PARAM_OPTIONAL);
1763 }
1764
1765 //-------------------------------------------------
1766 else if( pParameter->is_Option() && !pParameter->is_Information() )
1767 {
1768 switch( pParameter->Get_Type() )
1769 {
1771 _Get_Script_CMD_Usage(pParameter->asParameters(), Parser);
1772 break;
1773
1774 case PARAMETER_TYPE_Bool :
1775 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
1776 break;
1777
1778 case PARAMETER_TYPE_Int :
1779 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
1780 break;
1781
1787 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
1788 break;
1789
1792 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
1793 break;
1794
1795 case PARAMETER_TYPE_Date :
1796 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_DATE , wxCMD_LINE_PARAM_OPTIONAL);
1797 break;
1798
1800 Parser.AddOption(ID + "_MIN", wxEmptyString, Description, wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
1801 Parser.AddOption(ID + "_MAX", wxEmptyString, Description, wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
1802 break;
1803
1805 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
1806 break;
1807
1809 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
1810 break;
1811
1813 case PARAMETER_TYPE_Text :
1815 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
1816 break;
1817
1819 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
1820 break;
1821
1823 if( pParameter->Get_Children_Count() == 0 )
1824 {
1825 Parser.AddOption(ID + "_D" , wxEmptyString, _TL("Cell Size" ), wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
1826 Parser.AddOption(ID + "_X" , wxEmptyString, _TL("Lower Left Center Cell X-Coordinate"), wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
1827 Parser.AddOption(ID + "_Y" , wxEmptyString, _TL("Lower Left Center Cell Y-Coordinate"), wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
1828 Parser.AddOption(ID + "_NX" , wxEmptyString, _TL("Number of Columns" ), wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
1829 Parser.AddOption(ID + "_NY" , wxEmptyString, _TL("Number of Rows" ), wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
1830 Parser.AddOption(ID + "_FILE", wxEmptyString, _TL("Grid File" ), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
1831 }
1832 break;
1833
1834 default:
1835 break;
1836 }
1837 }
1838 }
1839}
1840
1841
1843// //
1845
1846//---------------------------------------------------------
1847CSG_String CSG_Tool::_Get_Script_Python(bool bHeader, bool bAllArguments)
1848{
1849 CSG_String Script, Name(Get_Name());
1850
1851 Name.Replace(" ", "_");
1852 Name.Replace("(", "");
1853 Name.Replace(")", "");
1854 Name.Replace("[", "");
1855 Name.Replace("]", "");
1856 Name.Replace(".", "");
1857 Name.Replace(",", "");
1858 Name.Replace("/", "");
1859 Name.Replace("-", "");
1860
1861 //-----------------------------------------------------
1862 if( bHeader )
1863 {
1864 Script += "#! /usr/bin/env python\n";
1865 Script += "\n";
1866 Script += "#_________________________________________\n";
1867 Script += "##########################################\n";
1868 Script += "\n";
1869#ifdef _SAGA_MSW
1870 CSG_String AppPath = SG_UI_Get_Application_Path(true); AppPath.Replace("\\", "/");
1871 Script += "# Initialize the environment...\n";
1872 Script += "\n";
1873 Script += "# Windows: Let the 'SAGA_PATH' environment variable point to\n";
1874 Script += "# the SAGA installation folder before importing 'saga_api'!\n";
1875 Script += "# This can be defined globally in the Windows system or\n";
1876 Script += "# user environment variable settings, in the 'PySAGA/__init__.py'\n";
1877 Script += "# file, or in the individual Python script itself. To do the latter\n";
1878 Script += "# just uncomment the following line and adjust the path accordingly:\n";
1879 Script += "###import os; os.environ['SAGA_PATH'] = '" + AppPath + "'\n";
1880 Script += "\n";
1881 Script += "# Windows: The most convenient way to make PySAGA available to all your\n";
1882 Script += "# Python scripts is to copy the PySAGA folder to the 'Lib/site-packages/'\n";
1883 Script += "# folder of your Python installation. If don't want to do this or if you\n";
1884 Script += "# don't have the rights to do so, you can also copy it to the folder with\n";
1885 Script += "# the Python scripts in which you want to use PySAGA, or alternatively\n";
1886 Script += "# you can add the path containing the PySAGA folder (e.g. the path to your\n";
1887 Script += "# SAGA installation) to the PYTHONPATH environment variable. To do this\n";
1888 Script += "# from within your script you can also take the following command (just\n";
1889 Script += "# uncomment the following line and adjust the path accordingly):\n";
1890 Script += "###import sys; sys.path.insert(1, '" + AppPath + "')\n";
1891 Script += "\n";
1892#endif // _SAGA_MSW
1893 Script += "# Import saga_api from PySAGA:\n";
1894 Script += "from PySAGA import saga_api\n";
1895 Script += "\n";
1896 Script += "\n";
1897 Script += "#_________________________________________\n";
1898 Script += "##########################################\n";
1899 Script += "def Run_" + Name + "(Results):\n";
1900 }
1901
1902 //-----------------------------------------------------
1903 if( bHeader ) Script += " # Get the tool:\n";
1904 Script += " Tool = saga_api.SG_Get_Tool_Library_Manager().Get_Tool('" + Get_Library() + "', '" + Get_ID() + "')\n";
1905 Script += " if not Tool:\n";
1906 Script += " saga_api.SG_UI_Msg_Add_Error('Failed to request tool: " + Get_Name() + "')\n";
1907 Script += " return False\n";
1908 Script += "\n";
1909 if( bHeader ) Script += " # Set the parameter interface:\n";
1910 Script += " Tool.Reset()\n";
1911
1912 //-------------------------------------------------
1913 _Get_Script_Python(Script, Get_Parameters(), bAllArguments);
1914
1915 for(int iParameters=0; iParameters<Get_Parameters_Count(); iParameters++)
1916 {
1917 _Get_Script_Python(Script, Get_Parameters(iParameters), bAllArguments, Get_Parameters(iParameters)->Get_Identifier());
1918 }
1919
1920 //-------------------------------------------------
1921 Script += "\n";
1922 if( bHeader ) Script += " # Execute the tool:\n";
1923 Script += " if not Tool.Execute():\n";
1924 Script += " saga_api.SG_UI_Msg_Add_Error('failed to execute tool: ' + Tool.Get_Name().c_str())\n";
1925 Script += " return False\n";
1926 Script += "\n";
1927 if( bHeader ) Script += " # Request the results:\n";
1928
1929 for(int iParameter=0; iParameter<Get_Parameters()->Get_Count(); iParameter++)
1930 {
1931 CSG_Parameter *p = Get_Parameters()->Get_Parameter(iParameter);
1932
1933 if( p->is_Output() )
1934 {
1935 CSG_String id(p->Get_Identifier()), type, ext;
1936
1937 switch( p->Get_DataObject_Type() )
1938 {
1939 case SG_DATAOBJECT_TYPE_Grid : type = "Grid" ; ext = "sg-grd-z"; break;
1940 case SG_DATAOBJECT_TYPE_Grids : type = "Grids" ; ext = "sg-gds-z"; break;
1941 case SG_DATAOBJECT_TYPE_Table : type = "Table" ; ext = "txt" ; break;
1942 case SG_DATAOBJECT_TYPE_Shapes : type = "Shapes" ; ext = "geojson" ; break;
1943 case SG_DATAOBJECT_TYPE_PointCloud: type = "PointCloud"; ext = "sg-pts-z"; break;
1944 case SG_DATAOBJECT_TYPE_TIN : type = "TIN" ; ext = "geojson" ; break;
1945 default : type = "" ; ext = "" ; break;
1946 }
1947
1948 if( p->is_DataObject() )
1949 {
1950 Script += " Data = Tool.Get_Parameter('" + id + "').as" + type + "()\n";
1951
1952 if( bHeader )
1953 {
1954 Script += " Data.Save('{:s}/{:s}.{:s}'.format(Results, Data.Get_Name(), '" + ext + "'))\n\n";
1955 }
1956 }
1957 else if( p->is_DataObject_List() )
1958 {
1959 Script += " List = Tool.Get_Parameter('" + id + "').as" + type + "List()\n";
1960 Script += " for i in range(0, List.Get_Item_Count()):\n";
1961
1962 if( bHeader )
1963 {
1964 Script += " List.Get_Item(i).Save('{:s}/{:s}_{:d}.{:s}'.format(Results, List.Get_Name(), i, '" + ext + "'))\n\n";
1965 }
1966 else
1967 {
1968 Script += " Data = List.Get_Item(i)\n";
1969 }
1970 }
1971 }
1972 }
1973
1974 //-----------------------------------------------------
1975 if( bHeader )
1976 {
1977 Script += " # job is done, free memory resources:\n";
1978 Script += " saga_api.SG_Get_Data_Manager().Delete_All()\n";
1979 Script += "\n";
1980 Script += " return True\n";
1981 Script += "\n";
1982 Script += "\n";
1983 Script += "#_________________________________________\n";
1984 Script += "##########################################\n";
1985 Script += "print('This is a simple template for using a SAGA tool through Python.')\n";
1986 Script += "print('Please edit the script to make it work properly before using it!')\n";
1987 Script += "\n";
1988 Script += "# Run_" + Name + "('.')\n";
1989 }
1990
1991 return( Script );
1992}
1993
1994//---------------------------------------------------------
1995void CSG_Tool::_Get_Script_Python(CSG_String &Script, CSG_Parameters *pParameters, bool bAllArguments, const CSG_String &Prefix)
1996{
1997 for(int iParameter=0; iParameter<pParameters->Get_Count(); iParameter++)
1998 {
1999 CSG_Parameter *p = pParameters->Get_Parameter(iParameter);
2000
2001 if( !bAllArguments && (!p->is_Enabled(false) || p->is_Information() || !p->do_UseInCMD()) )
2002 {
2003 continue;
2004 }
2005
2006 CSG_String ID(p->Get_Identifier());
2007
2008 if( !Prefix.is_Empty() )
2009 {
2010 ID.Prepend(Prefix + ".");
2011 }
2012
2013 switch( p->Get_Type() )
2014 {
2015 default:
2016 break;
2017
2018 case PARAMETER_TYPE_Bool :
2019 Script += CSG_String::Format(" Tool.Set_Parameter('%s', %s)\n", ID.c_str(), p->asBool() ? SG_T("True") : SG_T("False"));
2020 break;
2021
2022 case PARAMETER_TYPE_Int :
2023 Script += CSG_String::Format(" Tool.Set_Parameter('%s', %d)\n", ID.c_str(), p->asInt());
2024 break;
2025
2028 Script += CSG_String::Format(" Tool.Set_Parameter('%s', %d) # '%s'\n", ID.c_str(), p->asInt(), p->asString());
2029 break;
2030
2034 Script += CSG_String::Format(" Tool.Set_Parameter('%s', '%s')\n", ID.c_str(), p->asString());
2035 break;
2036
2038 Script += CSG_String::Format(" Tool.Set_Parameter('%s', '%s')\n", ID.c_str(), SG_Color_To_Text(p->asColor()).c_str());
2039 break;
2040
2043 Script += CSG_String::Format(" Tool.Set_Parameter('%s', %g)\n", ID.c_str(), p->asDouble());
2044 break;
2045
2047 Script += CSG_String::Format(" Tool.Set_Parameter('%s.MIN', %g)\n", ID.c_str(), p->asRange()->Get_Min());
2048 Script += CSG_String::Format(" Tool.Set_Parameter('%s.MAX', %g)\n", ID.c_str(), p->asRange()->Get_Max());
2049 break;
2050
2052 if( ((CSG_Parameter_String *)p)->is_Password() )
2053 {
2054 Script += CSG_String::Format(" Tool.Set_Parameter('%s', '***')\n", ID.c_str());
2055 break;
2056 }
2057
2058 case PARAMETER_TYPE_Date :
2059 case PARAMETER_TYPE_Text :
2061 Script += CSG_String::Format(" Tool.Set_Parameter('%s', '%s')\n", ID.c_str(), p->asString());
2062 break;
2063
2065 Script += CSG_String::Format(" Tool.Set_Parameter('%s', saga_api.SG_Create_Table('table.txt'))\n", ID.c_str());
2066 break;
2067
2069 if( p->Get_Children_Count() == 0 )
2070 {
2071 Script += CSG_String::Format(" Tool.Set_Parameter('%s', saga_api.CSG_Grid_System(%g, %g, %g, %d, %d))\n", ID.c_str(),
2074 p->asGrid_System()->Get_NX (), p->asGrid_System()->Get_NY ()
2075 );
2076 }
2077 break;
2078
2079 case PARAMETER_TYPE_Grid :
2083 case PARAMETER_TYPE_TIN :
2085 if( p->is_Input() )
2086 {
2087 Script += CSG_String::Format(" Tool.Set_Parameter('%s', saga_api.SG_Get_Data_Manager().Add('%s input file%s'))\n", ID.c_str(),
2088 SG_Get_DataObject_Name(p->Get_DataObject_Type()).c_str(), p->is_Optional() ? SG_T(", optional") : SG_T("")
2089 );
2090 }
2091 else if( p->is_Output() && p->is_Optional() )
2092 {
2093 Script += CSG_String::Format(" Tool.Set_Parameter('%s', saga_api.SG_Get_Create_Pointer()) # optional output, remove this line, if you don't want to create it\n", ID.c_str());
2094 }
2095 break;
2096
2103 if( p->is_Input() )
2104 {
2105 Script += CSG_String::Format(" Tool.Get_Parameter('%s').asList().Add_Item('%s input list%s')\n", ID.c_str(),
2106 SG_Get_DataObject_Name(p->Get_DataObject_Type()).c_str(), p->is_Optional() ? SG_T(", optional") : SG_T("")
2107 );
2108 }
2109 break;
2110
2112 _Get_Script_Python(Script, p->asParameters(), bAllArguments, ID);
2113 break;
2114 }
2115 }
2116}
2117
2118
2120// //
2122
2123//---------------------------------------------------------
2124CSG_String CSG_Tool::_Get_Script_Python_Wrap(bool bHeader, bool bName, bool bCall, int AllArguments, bool bWrapArgs)
2125{
2126 CSG_String Arguments, Description, Code;
2127
2128 if( AllArguments >= 0 ) // if( AllArguments < 0 ) => skip arguments list
2129 {
2130 for(int i=0; i<Parameters.Get_Count(); i++) // add input that is not optional in 1st place
2131 {
2132 _Get_Script_Python_Wrap(Parameters[i], PARAMETER_INPUT , Arguments, Description, Code, bCall && bHeader, AllArguments == 0, bWrapArgs);
2133 }
2134
2135 for(int i=0; i<Parameters.Get_Count(); i++) // add optional input in 2nd place
2136 {
2137 _Get_Script_Python_Wrap(Parameters[i], PARAMETER_INPUT_OPTIONAL, Arguments, Description, Code, bCall && bHeader, AllArguments == 0, bWrapArgs);
2138 }
2139
2140 for(int i=0; i<Parameters.Get_Count(); i++) // add output
2141 {
2142 _Get_Script_Python_Wrap(Parameters[i], PARAMETER_OUTPUT , Arguments, Description, Code, bCall && bHeader, AllArguments == 0, bWrapArgs);
2143 }
2144
2145 for(int i=0; i<Parameters.Get_Count(); i++) // add options
2146 {
2147 _Get_Script_Python_Wrap(Parameters[i], 0 , Arguments, Description, Code, bCall , AllArguments == 0, bWrapArgs);
2148 }
2149 }
2150
2151 //---------------------------------------------------------
2152 CSG_String Name, Expected(Get_Name()); Expected.Replace("'", "\\'");
2153
2154 if( bName )
2155 {
2156 Name = Get_Name();
2157
2158 if( isdigit(Name[0]) ) // ...in case first letter is a numeric character, what is not allowed for Python function names!
2159 {
2160 Name.Prepend("_");
2161 }
2162
2163 Name.Replace(" ", "_");
2164 Name.Replace("(", "");
2165 Name.Replace(")", "");
2166 Name.Replace("[", "");
2167 Name.Replace("]", "");
2168 Name.Replace(".", "");
2169 Name.Replace(",", "");
2170 Name.Replace("/", "");
2171 Name.Replace("-", "");
2172 Name.Replace("'", "");
2173 Name.Replace("&", "and");
2174 }
2175 else
2176 {
2177 Name = "run_tool_" + Get_Library() + "_" + Get_ID();
2178
2179 Name.Replace(" ", "_");
2180 }
2181
2182 //---------------------------------------------------------
2183 CSG_String Script;
2184
2185 if( bCall )
2186 {
2187 if( bHeader )
2188 {
2189 Script += "from PySAGA.tools import " + Get_Library() + "\n\n";
2190
2191 if( !Code.is_Empty() )
2192 {
2193 Script += Code + "\n";
2194 }
2195 }
2196
2197 Script += Get_Library() + '.' + Name + "(" + Arguments + ")\n";
2198 }
2199 else
2200 {
2201 CSG_Strings _Description = SG_String_Tokenize(SG_HTML_Tag_Replacer(Get_Description()), "\n");
2202
2203 if( bHeader )
2204 {
2205 Script += "#! /usr/bin/env python\n";
2206 Script += "from PySAGA.helper import Tool_Wrapper\n\n";
2207 }
2208
2209 Script += "def " + Name + "(" + Arguments + ", Verbose=2):\n";
2210 Script += " '''\n";
2211 Script += " " + Get_Name() + "\n";
2212 Script += " ----------\n";
2213 Script += " [" + Get_Library() + "." + Get_ID() + "]\\n\n";
2214 for(int i=0; i<_Description.Get_Count(); i++)
2215 {
2216 _Description[i].Trim_Both(); Script += " " + _Description[i] + "\\n\n";
2217 }
2218 Script += " Arguments\n";
2219 Script += " ----------\n";
2220 Script += Description + "\n";
2221 Script += " - Verbose [`integer number`] : Verbosity level, 0=silent, 1=tool name and success notification, 2=complete tool output.\\n\n";
2222 Script += " Returns\n";
2223 Script += " ----------\n";
2224 Script += " `boolean` : `True` on success, `False` on failure.\n";
2225 Script += " '''\n";
2226 Script += " Tool = Tool_Wrapper('" + Get_Library() + "', '" + Get_ID() + "', '" + Expected + "')\n";
2227 Script += " if Tool.is_Okay():\n";
2228 Script += Code;
2229 Script += " return Tool.Execute(Verbose)\n";
2230 Script += " return False\n\n";
2231 }
2232
2233 return( Script );
2234}
2235
2236//---------------------------------------------------------
2237bool CSG_Tool::_Get_Script_Python_Wrap(const CSG_Parameter &Parameter, int Constraint, CSG_String &Arguments, CSG_String &Description, CSG_String &Code, bool bCall, bool bOnlyNonDefaults, bool bWrapArgs, const CSG_String &Prefix)
2238{
2239 if( Parameter.do_UseInCMD() == false
2240 || Parameter.is_Information()
2241 || Parameter.Get_Type() == PARAMETER_TYPE_Node
2242 || Parameter.Cmp_Identifier("PARAMETERS_GRID_SYSTEM") )
2243 {
2244 return( false );
2245 }
2246
2247 if( bCall && !Parameter.is_Enabled() && !(Parameter.is_Output() && Parameter.Get_Parent() && Parameter.Get_Parent()->Cmp_Identifier("TARGET_SYSTEM")) )
2248 {
2249 return( false );
2250 }
2251
2252 //-----------------------------------------------------
2253 CSG_String ID(Parameter.Get_Identifier());
2254
2255 if( !Prefix.is_Empty() )
2256 {
2257 ID.Prepend(Prefix + ".");
2258 }
2259
2260 CSG_String Argument(ID);
2261
2262 if( Argument[0] >= '0' && Argument[0] <= '9' )
2263 {
2264 Argument.Prepend('_');
2265 }
2266
2267 Argument.Replace(".", "_");
2268 Argument.Replace("|", "_");
2269 Argument.Replace(" ", "_");
2270
2271 if( Argument.Length() > 2 )
2272 {
2273 Argument.Make_Upper();
2274 }
2275
2276 //-----------------------------------------------------
2277 if( Parameter.asParameters() ) // PARAMETER_TYPE_Parameters
2278 {
2279 bool bResult = false;
2280
2281 for(int i=0; i<(*Parameter.asParameters()).Get_Count(); i++)
2282 {
2283 if( _Get_Script_Python_Wrap((*Parameter.asParameters())[i], Constraint, Arguments, Description, Code, bCall, bOnlyNonDefaults, bWrapArgs, ID) )
2284 {
2285 bResult = true;
2286 }
2287 }
2288
2289 return( bResult );
2290 }
2291
2292 //-----------------------------------------------------
2293 if( Parameter.is_Input () && !Parameter.is_Optional() && Constraint != PARAMETER_INPUT ) { return( false ); }
2294 if( Parameter.is_Input () && Parameter.is_Optional() && Constraint != PARAMETER_INPUT_OPTIONAL ) { return( false ); }
2295 if( Parameter.is_Output() && Constraint != PARAMETER_OUTPUT ) { return( false ); }
2296 if( Parameter.is_Option() && Constraint != 0 ) { return( false ); }
2297
2298 //-----------------------------------------------------
2299 if( bCall )
2300 {
2301 CSG_String Value;
2302
2303 if( Parameter.is_DataObject() )
2304 {
2305 Value = Parameter.Get_Identifier(); Value.Make_Lower();
2306
2307 if( Parameter.is_Input() )
2308 {
2309 if( (bOnlyNonDefaults && !Parameter.asDataObject()) && Parameter.is_Optional() ) // don't add optional input that has not been set
2310 {
2311 return( false );
2312 }
2313
2314 CSG_String File(Parameter.asDataObject() && Parameter.asDataObject()->Get_File_Name(false)
2315 ? Parameter.asDataObject()->Get_File_Name(false) : SG_T("data object file")
2316 ); File.Replace("\\", "/");
2317
2318 Code += Value + " = saga_api.SG_Get_Data_Manager().Add_" + SG_Get_DataObject_Class_Name(Parameter.Get_DataObject_Type()).AfterFirst('_') + "('" + File + "') # input data object\n";
2319 }
2320 else // if( Parameter.is_Output() )
2321 {
2322 if( (bOnlyNonDefaults && !Parameter.asDataObject()) && Parameter.is_Optional() ) // don't add optional output that has not been requested
2323 {
2324 return( false );
2325 }
2326
2327 Code += Value + " = saga_api.SG_Get_Data_Manager().Add_" + SG_Get_DataObject_Class_Name(Parameter.Get_DataObject_Type()).AfterFirst('_') + "() # output data object\n";
2328 }
2329 }
2330 else if( Parameter.is_DataObject_List() )
2331 {
2332 Value = Parameter.Get_Identifier(); Value.Make_Lower();
2333
2334 if( Parameter.is_Input() )
2335 {
2336 if( (bOnlyNonDefaults && Parameter.asList()->Get_Item_Count() < 1) && Parameter.is_Optional() ) // don't add optional input that has not been set
2337 {
2338 return( false );
2339 }
2340
2341 Code += Value + " = [] # Python list with input data objects of type 'saga_api." + SG_Get_DataObject_Class_Name(Parameter.Get_DataObject_Type()) + "'\n";
2342 }
2343 else // if( Parameter.is_Output() )
2344 {
2345 Code += Value + " = [] # Python list, will become filled after successful execution with output data objects of type 'saga_api." + SG_Get_DataObject_Class_Name(Parameter.Get_DataObject_Type()) + "'\n";
2346 }
2347 }
2348 else if( Parameter.is_Option() )
2349 {
2350 if( bOnlyNonDefaults && Parameter.is_Default() )
2351 {
2352 return( false );
2353 }
2354
2355 switch( Parameter.Get_Type() )
2356 {
2357 case PARAMETER_TYPE_Bool : Value = Parameter.asBool() ? "True" : "False"; break;
2358
2359 case PARAMETER_TYPE_Int : Value.Printf("%d", Parameter.asInt()); break;
2360
2362 case PARAMETER_TYPE_Degree : Value.Printf("%f", Parameter.asDouble()); break;
2363
2364 case PARAMETER_TYPE_Color : Value = SG_Color_To_Text(Parameter.asColor()); break;
2365
2367 case PARAMETER_TYPE_Text :
2368 case PARAMETER_TYPE_Date :
2375 case PARAMETER_TYPE_FilePath : Value.Printf("'%s'", Parameter.asString()); break;
2376
2378 if( !Parameter.Cmp_Identifier("TARGET_SYSTEM") )
2379 {
2380 return( false );
2381 }
2382
2383 Value.Printf("'%s'", Parameter.asGrid_System()->asString());
2384 break;
2385
2386 default : return( false );
2387 }
2388 }
2389
2390 if( !Value.is_Empty() )
2391 {
2392 if( bWrapArgs )
2393 {
2394 Arguments += !Arguments.is_Empty() ? ",\n " : "\n ";
2395 }
2396 else if( !Arguments.is_Empty() )
2397 {
2398 Arguments += ", ";
2399 }
2400
2401 Arguments += Argument + "=" + Value;
2402 }
2403
2404 return( true );
2405 }
2406
2407 //-----------------------------------------------------
2408 if( bWrapArgs )
2409 {
2410 Arguments += !Arguments.is_Empty() ? ",\n " : "\n ";
2411 }
2412 else if( !Arguments.is_Empty() )
2413 {
2414 Arguments += ", ";
2415 }
2416
2417 Arguments += Argument + "=None";
2418
2419 //-----------------------------------------------------
2420 Code += " ";
2421
2422 if( Parameter.is_Input () ) { Code += "Tool.Set_Input "; }
2423 if( Parameter.is_Output() ) { Code += "Tool.Set_Output"; }
2424 if( Parameter.is_Option() ) { Code += "Tool.Set_Option"; }
2425
2426 Code += CSG_String::Format("('%s', %s)\n", ID.c_str(), Argument.c_str());
2427
2428 //-----------------------------------------------------
2429 Description += " - " + Argument + " [`";
2430
2431 if( Parameter.is_Input() )
2432 {
2433 Description += Parameter.is_Optional() ? "optional input " : "input ";
2434 }
2435 else if( Parameter.is_Output() )
2436 {
2437 Description += "output ";
2438 }
2439
2440 Description += Parameter.Get_Type_Name() + "`] : " + Parameter.Get_Name();
2441
2443
2444 if( !s.is_Empty() )
2445 {
2446 Description += ". " + s;
2447 }
2448
2449 Description += "\n";
2450
2451 return( true );
2452}
2453
2455// //
2457
2458//---------------------------------------------------------
2459CSG_String CSG_Tool::_Get_Script_Markdown(bool bHeader, int iArguments)
2460{
2461 CSG_String Script;
2462
2463 if( bHeader )
2464 {
2465 CSG_String Menu = Get_MenuPath(true); Menu.Replace("|", " &rarr; ");
2466 CSG_String Category = SG_Get_Tool_Library_Manager().Get_Library(Get_Library(), true)->Get_Category();
2467 Category += CSG_String::Format(" &rarr; %s", Get_Library().c_str());
2468
2469 Script += CSG_String::Format("**Tool:** %s \n", Get_Name().c_str());
2470 Script += CSG_String::Format("**Menu:** *%s*&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp; **Category:** *%s*\n\n", Menu.c_str(), Category.c_str());
2471 }
2472
2473 Script += "|**Parameter**|**Setting**|\n";
2474 Script += "|---|---|\n";
2475
2476 //-------------------------------------------------
2477 _Get_Script_Markdown(Script, Get_Parameters(), iArguments);
2478
2479 for(int iParameters=0; iParameters<Get_Parameters_Count(); iParameters++)
2480 {
2481 _Get_Script_Markdown(Script, Get_Parameters(iParameters), iArguments, Get_Parameters(iParameters)->Get_Identifier());
2482 }
2483
2484 return( Script );
2485}
2486
2487
2488//---------------------------------------------------------
2489void CSG_Tool::_Get_Script_Markdown(CSG_String &Script, CSG_Parameters *pParameters, int iArguments, const CSG_String &Prefix)
2490{
2491 for(int iParameter=0; iParameter<pParameters->Get_Count(); iParameter++)
2492 {
2493 CSG_Parameter *p = pParameters->Get_Parameter(iParameter);
2494
2495 if( iArguments == 0 && !p->do_UseInCMD() )
2496 {
2497 continue;
2498 }
2499 else if( iArguments == 1 && !p->do_UseInGUI() )
2500 {
2501 continue;
2502 }
2503
2504 if( !p->is_Enabled(false) )
2505 {
2506 continue;
2507 }
2508
2509 CSG_String Name(p->Get_Name());
2510
2511 if( !Prefix.is_Empty() )
2512 {
2513 Name.Prepend(Prefix);
2514 }
2515
2516 CSG_String Bold;
2517
2518 if( !p->is_Default() )
2519 {
2520 Bold = "**";
2521 }
2522
2523 CSG_String Space;
2524
2525 if( p->Get_Parent() != NULL && p->Get_Parent()->Get_Type() != PARAMETER_TYPE_Node )
2526 {
2527 Space = "&nbsp;&nbsp;&nbsp;";
2528 }
2529
2530 switch( p->Get_Type() )
2531 {
2532 default:
2533 break;
2534
2535 case PARAMETER_TYPE_Node :
2536 Script += CSG_String::Format("|%s**%s**||\n", Space.c_str(), Name.c_str());
2537 break;
2538
2539 case PARAMETER_TYPE_Bool :
2540 Script += CSG_String::Format("|%s%s%s%s|%s%s%s|\n", Space.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), p->asBool() ? SG_T("&#x1f5f9;") : SG_T("&#x2610;"), Bold.c_str());
2541 break;
2542
2543 case PARAMETER_TYPE_Int :
2544 Script += CSG_String::Format("|%s%s%s%s|%s%d%s|\n", Space.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), p->asInt(), Bold.c_str());
2545 break;
2546
2549 {
2550 CSG_String s = p->asString();
2551 if( s.Contains("no choice available") ) { Bold = ""; }
2552 s.Replace("<", "\\<");
2553 Script += CSG_String::Format("|%s%s%s%s|%s%s%s|\n", Space.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), s.c_str(), Bold.c_str());
2554 break;
2555 }
2556
2558 {
2559 CSG_String s = p->asString();
2560 if( s.Contains("no attributes") ) { Bold = ""; }
2561 s.Replace("<", "\\<");
2562 Script += CSG_String::Format("|%s%s%s%s|%s%s%s|\n", Space.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), s.c_str(), Bold.c_str());
2563 break;
2564 }
2565
2568 {
2569 CSG_String s = p->asString();
2570 s.Replace("<", "\\<");
2571 Script += CSG_String::Format("|%s%s%s%s|%s%s%s|\n", Space.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), s.c_str(), Bold.c_str());
2572 break;
2573 }
2574
2576 Script += CSG_String::Format("|%s%s%s%s|%s%s%s|\n", Space.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), SG_Color_To_Text(p->asColor()).c_str(), Bold.c_str());
2577 break;
2578
2581 Script += CSG_String::Format("|%s%s%s%s|%s%g%s|\n", Space.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), p->asDouble(), Bold.c_str());
2582 break;
2583
2585 Script += CSG_String::Format("|%s%s%s%s|%s%g;%g%s|\n", Space.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), p->asRange()->Get_Min(), p->asRange()->Get_Max(), Bold.c_str());
2586 break;
2587
2589 if( ((CSG_Parameter_String *)p)->is_Password() )
2590 {
2591 Script += CSG_String::Format("|%s%s%s%s|%s***%s|\n", Space.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), Bold.c_str());
2592 break;
2593 }
2594
2595 case PARAMETER_TYPE_Date :
2596 case PARAMETER_TYPE_Text :
2598 {
2599 CSG_String s = p->asString();
2600 s.Replace("\\", "/");
2601 Script += CSG_String::Format("|%s%s%s%s|%s%s%s|\n", Space.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), s.c_str(), Bold.c_str());
2602 break;
2603 }
2604
2606 Script += CSG_String::Format("|%s%s%s%s|%s%s%s|\n", Space.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), p->asString(), Bold.c_str());
2607 break;
2608
2610 {
2611 CSG_String s = p->asString();
2612 if( s.Contains("not set") )
2613 {
2614 s.Replace("<", "\\<");
2615 Script += CSG_String::Format("|%s%s|%s|\n", Space.c_str(), Name.c_str(), s.c_str());
2616 }
2617 else
2618 {
2619 Script += CSG_String::Format("|%s%s%s%s|%s%g; %dx, %dy; %.0f...x %.0f...y%s|\n", Space.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(),
2621 p->asGrid_System()->Get_NX (), p->asGrid_System()->Get_NY (),
2623 Bold.c_str()
2624 );
2625 }
2626 break;
2627 }
2628
2629 case PARAMETER_TYPE_Grid :
2633 case PARAMETER_TYPE_TIN :
2635 if( p->is_Input() )
2636 {
2637 CSG_String Input = p->is_Optional() ? ">" : ">>";
2638 CSG_String s = p->asString();
2639 if( s.Contains("not set") ) { Bold = ""; }
2640 s.Replace("<", "\\<");
2641 Script += CSG_String::Format("|%s%s %s%s%s|%s%s%s|\n", Space.c_str(), Input.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), s.c_str(), Bold.c_str());
2642 }
2643 else if( p->is_Output() )
2644 {
2645 CSG_String Output = p->is_Optional() ? "\\<" : "<<";
2646 CSG_String s = p->asString();
2647 if( !p->is_Optional() && s.Contains("create") ) { Bold = ""; }
2648 else if( p->is_Optional() && s.Contains("not set") ) { Bold = ""; }
2649 s.Replace("<", "\\<");
2650 Script += CSG_String::Format("|%s%s %s%s%s|%s%s%s|\n", Space.c_str(), Output.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), s.c_str(), Bold.c_str());
2651 }
2652 break;
2653
2660 if( p->is_Input() )
2661 {
2662 Script += CSG_String::Format("|%s%s%s|%s%s%s|\n", Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), p->asString(), Bold.c_str());
2663 }
2664 break;
2665
2667 Script += CSG_String::Format("|%s%s%s%s||\n", Space.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str());
2668 CSG_String Prefix = "&nbsp;&nbsp;&nbsp;&rarr; ";
2669 _Get_Script_Markdown(Script, p->asParameters(), iArguments, Prefix);
2670 break;
2671 }
2672 }
2673}
2674
2675
2677// //
2678// //
2679// //
2681
2682//---------------------------------------------------------
2684{
2685 CSG_MetaData History;
2686
2687 History.Set_Name(SG_META_HISTORY);
2688 History.Add_Property("saga-version", SAGA_VERSION);
2689
2690 if( Depth )
2691 {
2692 CSG_MetaData *pTool = History.Add_Child("TOOL");
2693
2694 pTool->Add_Property("library", Get_Library());
2695 pTool->Add_Property("id" , Get_ID ());
2696 pTool->Add_Property("name" , Get_Name ());
2697
2698 Parameters.Set_History(*pTool);
2699
2701
2702 CSG_MetaData *pOutput = pTool->Add_Child("OUTPUT");
2703 pOutput->Add_Property("type", "");
2704 pOutput->Add_Property("id" , "");
2705 pOutput->Add_Property("name", "");
2706
2707 pTool->Del_Children(Depth, SG_T("TOOL"));
2708 }
2709
2710 return( History );
2711}
2712
2713//---------------------------------------------------------
2714bool CSG_Tool::Set_History(CSG_Data_Object *pDataObject, int Depth)
2715{
2716 if( pDataObject )
2717 {
2718 CSG_MetaData History(Get_History(Depth));
2719
2720 CSG_MetaData *pOutput = History("TOOL") ? History["TOOL"]("OUTPUT") : NULL;
2721
2722 if( pOutput )
2723 {
2724 pOutput->Set_Property("name", pDataObject->Get_Name());
2725 }
2726
2727 pDataObject->Get_History() = History;
2728
2729 return( true );
2730 }
2731
2732 return( false );
2733}
2734
2735//---------------------------------------------------------
2736void CSG_Tool::_Set_Output_History(void)
2737{
2739
2740 for(int j=-1; j<Get_Parameters_Count(); j++)
2741 {
2742 CSG_Parameters *pParameters = j < 0 ? &Parameters : Get_Parameters(j);
2743
2744 for(int i=0; i<pParameters->Get_Count(); i++)
2745 {
2746 CSG_Parameter *pParameter = pParameters->Get_Parameter(i);
2747
2748 if( pParameter->is_Output() )//&& (pParameter->is_Enabled() || !has_GUI()) )
2749 {
2750 DataObject_Set_History(pParameter, &History);
2751 }
2752 }
2753 }
2754}
2755
2756//---------------------------------------------------------
2758{
2759 if( !pParameter && !((pParameter->is_DataObject() && pParameter->asDataObject()) || !(pParameter->is_DataObject_List() && pParameter->asList()->Get_Item_Count() > 0)) )
2760 {
2761 return( false );
2762 }
2763
2764 //-----------------------------------------------------
2765 CSG_MetaData History;
2766
2767 if( !pHistory )
2768 {
2769 History = Get_History(SG_Get_History_Depth()); pHistory = &History;
2770 }
2771
2772 //-----------------------------------------------------
2773 CSG_MetaData *pOutput = pHistory->Get_Child("TOOL") ? pHistory->Get_Child("TOOL")->Get_Child("OUTPUT") : NULL;
2774
2775 if( pOutput )
2776 {
2777 pOutput->Set_Property("type", pParameter->Get_Type_Identifier());
2778 pOutput->Set_Property("id" , pParameter->Get_Identifier ());
2779 pOutput->Set_Property("name", pParameter->Get_Name ());
2780 }
2781
2782 //-----------------------------------------------------
2783 if( pParameter->is_DataObject() && pParameter->asDataObject() )
2784 {
2785 if( pOutput )
2786 {
2787 pOutput->Set_Content(pParameter->asDataObject()->Get_Name());
2788 }
2789
2790 pParameter->asDataObject()->Get_History().Assign(*pHistory);
2791 }
2792
2793 //-----------------------------------------------------
2794 else if( pParameter->is_DataObject_List() )
2795 {
2796 for(int j=0; j<pParameter->asList()->Get_Item_Count(); j++)
2797 {
2798 if( pOutput )
2799 {
2800 pOutput->Set_Content(pParameter->asList()->Get_Item(j)->Get_Name());
2801 }
2802
2803 pParameter->asList()->Get_Item(j)->Get_History().Assign(*pHistory);
2804 }
2805 }
2806
2807 //-----------------------------------------------------
2808 return( true );
2809}
2810
2811
2813// //
2814// //
2815// //
2817
2818//---------------------------------------------------------
bool SG_UI_DataObject_Update(CSG_Data_Object *pDataObject, int Show, CSG_Parameters *pParameters)
void SG_UI_Msg_Add_Error(const char *Message)
int SG_UI_Dlg_Error(const CSG_String &Message, const CSG_String &Caption)
bool SG_UI_Stop_Execution(bool bDialog)
bool SG_UI_Process_Get_Okay(bool bBlink)
bool SG_UI_Dlg_Parameters(CSG_Parameters *pParameters, const CSG_String &Caption)
bool SG_UI_DataObject_Colors_Get(CSG_Data_Object *pDataObject, CSG_Colors *pColors)
void SG_UI_Msg_Add(const char *Message, bool bNewLine, TSG_UI_MSG_STYLE Style)
bool SG_UI_DataObject_Params_Get(CSG_Data_Object *pDataObject, CSG_Parameters *pParameters)
void SG_UI_Process_Set_Text(const CSG_String &Text)
bool SG_UI_Process_Set_Ready(void)
bool SG_UI_Process_Set_Progress(int Position, int Range)
bool SG_UI_DataObject_Add(CSG_Data_Object *pDataObject, int Show)
void SG_UI_Msg_Add_Execution(const char *Message, bool bNewLine, TSG_UI_MSG_STYLE Style)
bool SG_UI_Process_Set_Okay(bool bOkay)
bool SG_UI_DataObject_Params_Set(CSG_Data_Object *pDataObject, CSG_Parameters *pParameters)
void SG_UI_Dlg_Message(const CSG_String &Message, const CSG_String &Caption)
bool SG_UI_DataObject_Colors_Set(CSG_Data_Object *pDataObject, CSG_Colors *pColors)
bool SG_UI_Dlg_Continue(const CSG_String &Message, const CSG_String &Caption)
bool SG_UI_DataObject_Classify(CSG_Data_Object *pDataObject, const CSG_MetaData &Options)
CSG_String SG_Color_To_Text(long Color, bool bHexadecimal)
CSG_String SG_UI_Get_Application_Name(void)
Definition api_core.cpp:378
CSG_String SG_UI_Get_Application_Path(bool bPathOnly)
Definition api_core.cpp:356
SAGA_API_DLL_EXPORT bool SG_File_Exists(const CSG_String &FileName)
@ SG_UI_MSG_STYLE_FAILURE
Definition api_core.h:1585
@ SG_UI_MSG_STYLE_SUCCESS
Definition api_core.h:1584
@ SG_UI_MSG_STYLE_BOLD
Definition api_core.h:1582
@ SG_UI_MSG_STYLE_NORMAL
Definition api_core.h:1581
SAGA_API_DLL_EXPORT CSG_String SG_HTML_Tag_Replacer(const CSG_String &Text)
signed long long sLong
Definition api_core.h:158
#define SG_T(s)
Definition api_core.h:537
SAGA_API_DLL_EXPORT CSG_Strings SG_String_Tokenize(const CSG_String &String, const CSG_String &Delimiters=SG_DEFAULT_DELIMITERS, TSG_String_Tokenizer_Mode Mode=SG_TOKEN_DEFAULT)
@ SG_UI_DATAOBJECT_SHOW_MAP
Definition api_core.h:1598
@ SG_UI_DATAOBJECT_UPDATE
Definition api_core.h:1597
#define SG_Char
Definition api_core.h:536
#define _TL(s)
Definition api_core.h:1568
bool Create(void)
bool Set_Predefined(int Index, bool bRevert=false, int nColors=0)
bool Delete(CSG_Data_Object *pObject, bool bDetach=false)
const SG_Char * Get_Name(void) const
const SG_Char * Get_File_Name(bool bNative=true) const
CSG_MetaData & Get_History(void)
Definition dataobject.h:236
static CSG_DateTime Now(void)
Definition datetime.cpp:585
double Get_XMin(bool bCells=false) const
Definition grid.h:264
double Get_YMin(bool bCells=false) const
Definition grid.h:268
double Get_Cellsize(void) const
Definition grid.h:255
int Get_NX(void) const
Definition grid.h:258
const SG_Char * asString(void)
int Get_NY(void) const
Definition grid.h:259
bool Assign(const CSG_MetaData &MetaData, bool bAddChildren=true)
Definition metadata.cpp:757
bool Del_Children(int Depth=0, const SG_Char *Name=NULL)
Definition metadata.cpp:381
CSG_MetaData * Get_Child(int Index) const
Definition metadata.h:149
bool Set_Property(const CSG_String &Name, const CSG_String &Value, bool bAddIfNotExists=true)
Definition metadata.cpp:615
bool Add_Children(const CSG_MetaData &MetaData)
Definition metadata.cpp:359
void Set_Name(const CSG_String &Name)
Definition metadata.h:130
void Set_Content(const CSG_String &Content)
Definition metadata.h:140
CSG_MetaData * Add_Child(void)
Definition metadata.cpp:166
bool Add_Property(const CSG_String &Name, const CSG_String &Value)
Definition metadata.cpp:559
virtual bool Del_Items(void)
CSG_Data_Object * Get_Item(int Index) const
int Get_Item_Count(void) const
double Get_Max(void) const
double Get_Min(void) const
CSG_String Get_CmdID(void) const
const SG_Char * Get_Identifier(void) const
bool is_DataObject(void) const
class CSG_Parameters * asParameters(void) const
CSG_String Get_Type_Identifier(void) const
CSG_String Get_Type_Name(void) const
bool is_Optional(void) const
Definition parameters.h:238
TSG_Data_Object_Type Get_DataObject_Type(void) const
int Get_Children_Count(void) const
Definition parameters.h:259
double asDouble(void) const
Definition parameters.h:289
CSG_Parameter * Get_Parent(void) const
virtual TSG_Parameter_Type Get_Type(void) const =0
bool asBool(void) const
Definition parameters.h:286
bool is_Input(void) const
Definition parameters.h:236
CSG_Parameters * Get_Parameters(void) const
const SG_Char * Get_Name(void) const
bool is_Enabled(bool bCheckEnv=true) const
bool is_Option(void) const
virtual bool Set_Value(int Value)
class CSG_Parameter_List * asList(void) const
CSG_Grid_System * asGrid_System(void) const
CSG_Data_Object * asDataObject(void) const
class CSG_Parameter_Range * asRange(void) const
bool is_Output(void) const
Definition parameters.h:237
virtual bool is_Default(void) const
bool is_Information(void) const
Definition parameters.h:239
bool do_UseInCMD(void) const
const SG_Char * asString(void) const
Definition parameters.h:290
bool Cmp_Identifier(const CSG_String &Identifier) const
long asColor(void) const
Definition parameters.h:288
const SG_Char * Get_Description(void) const
bool do_UseInGUI(void) const
bool is_DataObject_List(void) const
int asInt(void) const
Definition parameters.h:287
bool is_Managed(void) const
bool Set_Callback(bool bActive=true)
bool Reset_Grid_System(void)
int Get_Count(void) const
void Set_Manager(class CSG_Data_Manager *pManager)
class CSG_Tool * Get_Tool(void) const
bool Set_History(CSG_MetaData &History, bool bOptions=true, bool bDataObjects=true)
CSG_Parameter * Get_Parameter(int i) const
bool Create(const CSG_Parameters &Parameters)
bool Restore_Defaults(bool bClearData=false)
bool Push(class CSG_Data_Manager *pManager=NULL, bool bRestoreDefaults=true)
TSG_PFNC_Parameter_Changed Set_Callback_On_Parameter_Changed(TSG_PFNC_Parameter_Changed pCallback)
bool Del_Parameter(int i)
bool Set_Parameter(const CSG_String &ID, CSG_Parameter *pValue)
bool Pop(void)
CSG_String AfterFirst(char Character) const
int Cmp(const CSG_String &String) const
void Clear(void)
size_t Replace(const CSG_String &Old, const CSG_String &New, bool bReplaceAll=true)
static CSG_String Format(const char *Format,...)
const SG_Char * c_str(void) const
CSG_String & Make_Lower(void)
int Printf(const char *Format,...)
bool is_Empty(void) const
bool Contains(const CSG_String &String) const
CSG_String & Prepend(const CSG_String &String)
int Get_Count(void) const
Definition api_core.h:714
CSG_String Format(const CSG_String &format="") const
Definition datetime.cpp:65
int Get_Minutes(void) const
Definition datetime.h:162
sLong Get_Milliseconds(void) const
Definition datetime.h:164
sLong Get_Seconds(void) const
Definition datetime.h:163
int Get_Hours(void) const
Definition datetime.h:161
static CSG_String Get_Script(CSG_Tool *pTool, bool bHeader, bool bAllParameters=true)
CSG_Tool_Library * Get_Library(int i) const
CSG_String Get_Category(void) const
bool Reset_Grid_System(void)
Definition tool.cpp:1387
bool Message_Dlg_Confirm(const CSG_String &Text, const SG_Char *Caption=NULL)
Definition tool.cpp:699
const CSG_String & Get_Library(void) const
Definition tool.cpp:115
bool Dlg_Parameters(const CSG_String &Identifier)
Definition tool.cpp:523
const CSG_String & Get_File_Name(void) const
Definition tool.cpp:121
bool Set_Grid_System(const CSG_Grid_System &System)
Definition tool.cpp:1402
int Get_Parameters_Count(void) const
Definition tool.h:167
bool Set_Manager(class CSG_Data_Manager *pManager)
Definition tool.cpp:570
CSG_Grid_System * Get_Grid_System(void) const
Definition tool.cpp:1412
CSG_MetaData Get_History(int Depth=-1)
Definition tool.cpp:2683
bool Settings_Pop(void)
Definition tool.cpp:634
static bool Process_Get_Okay(bool bBlink=false)
Definition tool.cpp:846
bool Stop_Execution(bool bDialog=true)
Definition tool.cpp:678
class CSG_Data_Manager * Get_Manager(void) const
Definition tool.cpp:583
bool has_GUI(void) const
Definition tool.cpp:239
const CSG_String & Get_Author(void) const
Definition tool.cpp:143
bool Update_Parameter_States(void)
Definition tool.cpp:1425
static bool DataObject_Classify_StdDev(CSG_Data_Object *pDataObject, int Field=-1, double StdDev=0.5, double StdDev_Max=4.5, int Colors=-1)
Definition tool.cpp:1263
virtual bool is_Interactive(void) const
Definition tool.h:223
static bool DataObject_Classify_Quantile(CSG_Data_Object *pDataObject, int Field=-1, int Classes=10, bool bHistogram=true, int Colors=-1)
Definition tool.cpp:1233
CSG_Parameters * Get_Parameters(void)
Definition tool.h:165
CSG_String Get_Script(Script_Format Format, bool bHeader=true, int Arguments=0, bool bWrapArgs=true)
Definition tool.cpp:1466
CSG_Parameters * Add_Parameters(const CSG_String &Identifier, const CSG_String &Name, const CSG_String &Description)
Definition tool.cpp:495
static bool DataObject_Set_Colors(CSG_Data_Object *pDataObject, const CSG_Colors &Colors)
Definition tool.cpp:1001
const CSG_String & Get_Name(void) const
Definition tool.cpp:132
static CSG_Parameter * DataObject_Get_Parameter(CSG_Data_Object *pDataObject, const CSG_String &ID)
Definition tool.cpp:1049
static bool DataObject_Classify_Unique(CSG_Data_Object *pDataObject, int Field=-1, int Classes_Max=1024, int Colors=-1)
Definition tool.cpp:1203
static void Process_Set_Text(const CSG_String &Text)
Definition tool.cpp:852
bool Settings_Push(class CSG_Data_Manager *pManager=NULL)
Definition tool.cpp:621
bool Set_Parameter(const CSG_String &ID, CSG_Parameter *pValue)
Definition tool.cpp:1284
virtual void Destroy(void)
Definition tool.cpp:102
static bool DataObject_Classify_Geometric(CSG_Data_Object *pDataObject, int Field=-1, int Classes=10, bool bIncreasing=true, int Colors=-1)
Definition tool.cpp:1243
virtual bool On_Execute(void)=0
const CSG_Strings & Get_References(void) const
Definition tool.cpp:181
CSG_MetaData History_Supplement
Definition tool.h:258
bool has_CMD(void) const
Definition tool.cpp:245
static int _On_Parameter_Changed(CSG_Parameter *pParameter, int Flags)
Definition tool.cpp:452
virtual ~CSG_Tool(void)
Definition tool.cpp:86
CSG_Parameters Parameters
Definition tool.h:256
void Set_Show_Progress(bool bOn=true)
Definition tool.cpp:654
virtual TSG_Tool_Type Get_Type(void) const
Definition tool.h:148
static bool DataObject_Get_Parameters(CSG_Data_Object *pDataObject, CSG_Parameters &Parameters)
Definition tool.cpp:1017
virtual bool do_Sync_Projections(void) const
Definition tool.h:216
static bool DataObject_Update(CSG_Data_Object *pDataObject, int Show=SG_UI_DATAOBJECT_UPDATE)
Definition tool.cpp:978
virtual bool Set_Progress(int Position, int Range) const
Definition tool.cpp:660
CSG_Tool(void)
Definition tool.cpp:67
bool Reset(bool bManager=true)
Definition tool.cpp:1355
virtual CSG_String Get_MenuPath(void)
Definition tool.h:162
void Set_Description(const CSG_String &String)
Definition tool.cpp:160
static bool DataObject_Set_Parameters(CSG_Data_Object *pDataObject, CSG_Parameters &Parameters)
Definition tool.cpp:1022
bool DataObject_Update_All(void)
Definition tool.cpp:815
void Set_Callback(bool bActive=true)
Definition tool.cpp:559
bool Reset_Manager(void)
Definition tool.cpp:1377
static bool DataObject_Set_Stretch_Percentile(CSG_Data_Object *pDataObject, int Field=-1, double Minimum=2., double Maximum=98., int Interval_Mode=0, double Interval_Log=1., int Colors=-1, bool bUpdateNow=false)
Definition tool.cpp:1172
bool Set_History(CSG_Data_Object *pDataObject, int Depth=-1)
Definition tool.cpp:2714
bool Execute(bool bAddHistory=false)
Definition tool.cpp:258
static bool DataObject_Get_Colors(CSG_Data_Object *pDataObject, CSG_Colors &Colors)
Definition tool.cpp:996
void Message_Fmt(const char *Format,...)
Definition tool.cpp:921
static bool DataObject_Set_Parameter(CSG_Data_Object *pDataObject, CSG_Parameter *pParameter)
Definition tool.cpp:1056
void Set_Author(const CSG_String &String)
Definition tool.cpp:138
const CSG_String & Get_Version(void) const
Definition tool.cpp:154
static bool DataObject_Set_Stretch(CSG_Data_Object *pDataObject, int Field, double Minimum, double Maximum, int Interval_Mode=0, double Interval_Log=1., int Colors=-1, bool bUpdateNow=false)
Definition tool.cpp:1183
static bool DataObject_Set_Stretch_Linear(CSG_Data_Object *pDataObject, int Field=-1, double Minimum=5., double Maximum=95., int Interval_Mode=0, double Interval_Log=1., int Colors=-1, bool bUpdateNow=false)
Definition tool.cpp:1149
static bool DataObject_Classify_Natural(CSG_Data_Object *pDataObject, int Field=-1, int Classes=10, int Colors=-1)
Definition tool.cpp:1253
static bool DataObject_Classify_Equal(CSG_Data_Object *pDataObject, int Field=-1, int Classes=10, int Colors=-1)
Definition tool.cpp:1213
static bool DataObject_Set_Stretch_StdDev(CSG_Data_Object *pDataObject, int Field=-1, double StdDev=2., bool bKeepInRange=false, int Interval_Mode=0, double Interval_Log=1., int Colors=-1, bool bUpdateNow=false)
Definition tool.cpp:1160
const CSG_String & Get_Description(void) const
Definition tool.cpp:165
bool DataObject_Set_History(CSG_Parameter *pParameter, CSG_MetaData *pHistory=NULL)
Definition tool.cpp:2757
const CSG_String & Get_ID(void) const
Definition tool.h:150
bool Error_Set(TSG_Tool_Error Error_ID=TOOL_ERROR_Unknown)
Definition tool.cpp:705
bool Error_Fmt(const char *Format,...)
Definition tool.cpp:742
Script_Format
Definition tool.h:242
virtual int On_Parameters_Enable(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
Definition tool.cpp:482
bool Get_Projection(CSG_Projection &Projection) const
Definition tool.cpp:430
virtual int On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
Definition tool.cpp:476
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)
Definition tool.cpp:171
void Message_Add(const CSG_String &Text, bool bNewLine=true)
Definition tool.cpp:908
void Set_Version(const CSG_String &String)
Definition tool.cpp:149
void Message_Dlg(const CSG_String &Text, const SG_Char *Caption=NULL)
Definition tool.cpp:693
class CSG_Data_Manager * Create_Manager(void)
Definition tool.cpp:589
void Set_Name(const CSG_String &String)
Definition tool.cpp:127
static bool DataObject_Classify_Defined(CSG_Data_Object *pDataObject, int Field, double Interval, bool bOffset=false, double Offset=0., int Colors=-1)
Definition tool.cpp:1223
bool DataObject_Add(CSG_Data_Object *pDataObject, bool bUpdate=false)
Definition tool.cpp:799
bool Delete_Manager(bool bDetachData=false, bool bReset=true)
Definition tool.cpp:597
CSG_Data_Manager & SG_Get_Data_Manager(void)
int SG_Get_History_Depth(void)
CSG_String SG_Get_DataObject_Name(TSG_Data_Object_Type Type)
CSG_String SG_Get_DataObject_Class_Name(TSG_Data_Object_Type Type)
@ SG_DATAOBJECT_TYPE_PointCloud
Definition dataobject.h:123
@ SG_DATAOBJECT_TYPE_Grids
Definition dataobject.h:119
@ SG_DATAOBJECT_TYPE_TIN
Definition dataobject.h:122
@ SG_DATAOBJECT_TYPE_Shapes
Definition dataobject.h:121
@ SG_DATAOBJECT_TYPE_Grid
Definition dataobject.h:118
@ SG_DATAOBJECT_TYPE_Table
Definition dataobject.h:120
#define DATAOBJECT_NOTSET
Definition dataobject.h:129
#define SG_META_HISTORY
Definition dataobject.h:93
#define PARAMETER_CHECK_ENABLE
Definition parameters.h:191
#define PARAMETER_DESCRIPTION_PROPERTIES
Definition parameters.h:110
#define PARAMETER_CHECK_VALUES
Definition parameters.h:190
#define PARAMETER_INPUT_OPTIONAL
Definition parameters.h:103
#define PARAMETER_DESCRIPTION_TYPE
Definition parameters.h:108
#define PARAMETER_DESCRIPTION_NAME
Definition parameters.h:107
@ PARAMETER_TYPE_Degree
Definition parameters.h:129
@ PARAMETER_TYPE_FixedTable
Definition parameters.h:142
@ PARAMETER_TYPE_Node
Definition parameters.h:124
@ PARAMETER_TYPE_Grid
Definition parameters.h:149
@ PARAMETER_TYPE_Grid_List
Definition parameters.h:155
@ PARAMETER_TYPE_Text
Definition parameters.h:136
@ PARAMETER_TYPE_TIN
Definition parameters.h:153
@ PARAMETER_TYPE_Table
Definition parameters.h:151
@ PARAMETER_TYPE_Int
Definition parameters.h:127
@ PARAMETER_TYPE_Table_Fields
Definition parameters.h:146
@ PARAMETER_TYPE_Grids
Definition parameters.h:150
@ PARAMETER_TYPE_Color
Definition parameters.h:140
@ PARAMETER_TYPE_Colors
Definition parameters.h:141
@ PARAMETER_TYPE_DataObject_Output
Definition parameters.h:162
@ PARAMETER_TYPE_Table_List
Definition parameters.h:157
@ PARAMETER_TYPE_Double
Definition parameters.h:128
@ PARAMETER_TYPE_TIN_List
Definition parameters.h:159
@ PARAMETER_TYPE_Grid_System
Definition parameters.h:144
@ PARAMETER_TYPE_Date
Definition parameters.h:130
@ PARAMETER_TYPE_PointCloud_List
Definition parameters.h:160
@ PARAMETER_TYPE_Choices
Definition parameters.h:134
@ PARAMETER_TYPE_Data_Type
Definition parameters.h:132
@ PARAMETER_TYPE_Shapes
Definition parameters.h:152
@ PARAMETER_TYPE_Shapes_List
Definition parameters.h:158
@ PARAMETER_TYPE_Range
Definition parameters.h:131
@ PARAMETER_TYPE_PointCloud
Definition parameters.h:148
@ PARAMETER_TYPE_Table_Field
Definition parameters.h:145
@ PARAMETER_TYPE_Parameters
Definition parameters.h:164
@ PARAMETER_TYPE_FilePath
Definition parameters.h:137
@ PARAMETER_TYPE_Bool
Definition parameters.h:126
@ PARAMETER_TYPE_Grids_List
Definition parameters.h:156
@ PARAMETER_TYPE_String
Definition parameters.h:135
@ PARAMETER_TYPE_Choice
Definition parameters.h:133
#define PARAMETER_OUTPUT
Definition parameters.h:95
#define PARAMETER_DESCRIPTION_TEXT
Definition parameters.h:111
#define PARAMETER_INPUT
Definition parameters.h:94
#define SAGA_VERSION
Definition saga_api.h:90
#define GET_ID2(p, s)
#define INIT_CLASSIFY_OPTIONS(method)
Definition tool.cpp:1199
#define INIT_STRETCH_OPTIONS(method)
Definition tool.cpp:1136
#define ADD_MESSAGE_EXECUTION(Text, Style)
#define GET_ID1(p)
TSG_Tool_Error
Definition tool.h:112
@ TOOL_ERROR_Calculation
Definition tool.h:114
CSG_Tool_Library_Manager & SG_Get_Tool_Library_Manager(void)