SAGA API Version 9.12
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 m_References.Set_Name(_TL("References"));
85 m_References.Add_Field("Authors" , SG_DATATYPE_String);
86 m_References.Add_Field("Date" , SG_DATATYPE_String);
87 m_References.Add_Field("Title" , SG_DATATYPE_String);
88 m_References.Add_Field("Source" , SG_DATATYPE_String);
89 m_References.Add_Field("Link" , SG_DATATYPE_String);
90 m_References.Add_Field("LinkText" , SG_DATATYPE_String);
91
92 m_Editors .Set_Name(_TL("References"));
93 m_Editors .Add_Field("Editors" , SG_DATATYPE_String);
94 m_Editors .Add_Field("Comment" , SG_DATATYPE_String);
95}
96
97//---------------------------------------------------------
99{
100 for(int i=0; i<Get_Parameters_Count(); i++)
101 {
102 delete(Get_Parameters(i));
103 }
104
105 Destroy();
106}
107
108
110// //
112
113//---------------------------------------------------------
115{
116 m_bError_Ignore = false;
117
118 History_Supplement.Destroy();
119
121}
122
123
125// //
127
128//---------------------------------------------------------
130{
131 return( m_Library );
132}
133
134//---------------------------------------------------------
136{
137 return( m_File_Name );
138}
139
140//---------------------------------------------------------
142{
143 Parameters.Set_Name(String);
144}
145
147{
148 return( Parameters.Get_Name() );
149}
150
151//---------------------------------------------------------
153{
154 m_Author = String;
155}
156
158{
159 return( m_Author );
160}
161
162//---------------------------------------------------------
164{
165 m_Version = String;
166}
167
169{
170 return( m_Version );
171}
172
173//---------------------------------------------------------
175{
176 Parameters.Set_Description(String);
177}
178
179void CSG_Tool::Add_Description(const CSG_String &String, bool bNewLine)
180{
181 CSG_String Description(Get_Description());
182
183 if( bNewLine ) { Description += "\n"; }
184
185 Set_Description(Description + String);
186}
187
189{
190 return( Parameters.Get_Description().is_Empty() ? Get_Name() : Parameters.Get_Description() );
191}
192
193//---------------------------------------------------------
195{
196 m_Dynamic_Description = String;
197}
198
199void CSG_Tool::Add_Dynamic_Description(const CSG_String &String, bool bNewLine)
200{
201 if( bNewLine ) { m_Dynamic_Description += "\n"; }
202
203 m_Dynamic_Description += String;
204}
205
207{
208 return( m_Dynamic_Description );
209}
210
211
213// //
215
216//---------------------------------------------------------
218{
219 if( !bSolved )
220 {
221 return( Get_MenuPath() );
222 }
223
224 CSG_Strings Menu = SG_String_Tokenize(Get_MenuPath(), ";"); if( !Menu.Get_Count() ) { Menu += ""; }
225
226 for(int i=0; i<Menu.Get_Count(); i++)
227 {
228 if( Menu[i].Length() > 1 && Menu[i][1] == ':' )
229 {
230 if( Menu[i][0] == 'A' || Menu[i][0] == 'a' ) // absolute menu path, overwrites library's default menu path
231 {
232 Menu[i] = Menu[i].AfterFirst(':');
233
234 continue;
235 }
236
237 Menu[i] = Menu[i].AfterFirst(':'); // Menu[0] == 'R' || Menu[0] == 'r' // menu path explicitly declared as relative to library's default menu path
238 }
239
240 if( !m_Library_Menu.is_Empty() )
241 {
242 if( Menu[i].is_Empty() )
243 {
244 Menu[i] = m_Library_Menu;
245 }
246 else
247 {
248 Menu[i] = m_Library_Menu + "|" + Menu[i];
249 }
250 }
251 }
252
253 CSG_String Menus;
254
255 for(int i=0; i<Menu.Get_Count(); i++)
256 {
257 if( i > 0 )
258 {
259 Menus += ";";
260 }
261
262 Menus += Menu[i];
263 }
264
265 return( Menus );
266}
267
268
270// //
272
273//---------------------------------------------------------
274bool CSG_Tool::has_GUI(void) const
275{
276 return( m_bGUI );
277}
278
279//---------------------------------------------------------
280bool CSG_Tool::has_CMD(void) const
281{
282 return( m_bCMD );
283}
284
285
287// //
289
290//---------------------------------------------------------
294void CSG_Tool::Add_Reference(const CSG_String &Authors, const CSG_String &Date, const CSG_String &Title, const CSG_String &Source, const CSG_String &Link, const CSG_String &LinkText)
295{
296 CSG_Table_Record &Reference = *m_References.Add_Record();
297
298 Reference.Set_Value(0, Authors );
299 Reference.Set_Value(1, Date );
300 Reference.Set_Value(2, Title );
301 Reference.Set_Value(3, Source );
302 Reference.Set_Value(4, Link );
303 Reference.Set_Value(5, LinkText);
304
305 m_References.Sort(0);
306}
307
308//---------------------------------------------------------
312void CSG_Tool::Add_Reference(const CSG_String &Link, const CSG_String &Link_Text)
313{
314 Add_Reference("", "", "", "", Link, Link_Text);
315}
316
317//---------------------------------------------------------
322{
323 return( m_References.Del_Records() );
324}
325
326//---------------------------------------------------------
331{
332 CSG_Strings References;
333
334 for(int i=0; i<m_References.Get_Count(); i++)
335 {
336 CSG_String Reference,
337 Authors(m_References[i].asString(0)),
338 Date (m_References[i].asString(1)),
339 Title (m_References[i].asString(2)),
340 Source (m_References[i].asString(3)),
341 Link (m_References[i].asString(4)),
342 LinkTxt(m_References[i].asString(5));
343
344 if( !Authors.is_Empty() )
345 {
346 if( Date.is_Empty() ) { Date = "n.d."; }
347
348 Reference += bHTML ? "<b>" + Authors + " (" + Date + "):</b>" : Authors + " (" + Date + "):";
349 }
350 else if( !Date.is_Empty() ) // date only
351 {
352 Reference += bHTML ? "<b>(" + Date + "):</b>" : "(" + Date + "):";
353 }
354
355 if( !Title.is_Empty() ) // title
356 {
357 if( Title[Title.Length() - 1] != '.' ) { Title += '.'; }
358
359 if( !Reference.is_Empty() ) { Reference += " "; }
360
361 Reference += bHTML ? "<i>" + Title + "</i>" : Title;
362 }
363
364 if( !Source.is_Empty() ) // title
365 {
366 if( Source[Source.Length() - 1] != '.' ) { Source += '.'; }
367
368 if( !Reference.is_Empty() ) { Reference += " "; }
369
370 Reference += Source;
371 }
372
373 if( !Link.is_Empty() )
374 {
375 if( !Reference.is_Empty() ) { Reference += " "; }
376
377 Reference += bHTML ? "<a href=\"" + Link + "\">" + (LinkTxt.is_Empty() ? Link : LinkTxt) + "</a>" : "[" + LinkTxt + "](" + Link + ")";
378 }
379
380 if( !Reference.is_Empty() )
381 {
382 References += Reference;
383 }
384 }
385
386 return( References );
387}
388
389
391// //
393
394//---------------------------------------------------------
396{
397 CSG_Table Table;
398
399 Table.Add_Field("Id" , SG_DATATYPE_String);
400 Table.Add_Field("Name" , SG_DATATYPE_String);
401 Table.Add_Field("Description", SG_DATATYPE_String);
402
403 _Add_Parameters(Table, &Parameters);
404
405 for(int i=0; i<Get_Parameters_Count(); i++)
406 {
407 _Add_Parameters(Table, Get_Parameters(i), Get_Parameters(i)->Get_Identifier() + ".");
408 }
409
410 return( Table );
411}
412
413//---------------------------------------------------------
414bool CSG_Tool::_Add_Parameters(CSG_Table &Table, const CSG_Parameters *pParameters, const CSG_String &IDprefix) const
415{
416 for(int i=0; i<pParameters->Get_Count(); i++)
417 {
418 CSG_Parameter &P = *pParameters->Get_Parameter(i);
419
420 if( P.asParameters() )
421 {
422 _Add_Parameters(Table, P.asParameters(), IDprefix + P.Get_Identifier() + ".");
423 }
424 else
425 {
426 CSG_Table_Record &Record = *Table.Add_Record();
427
428 Record.Set_Value(0, IDprefix + P.Get_Identifier ());
429 Record.Set_Value(1, P.Get_Name ());
430 Record.Set_Value(2, P.Get_Description());
431 }
432 }
433
434 return( true );
435}
436
437
439// //
441
442//---------------------------------------------------------
443CSG_String CSG_Tool::m_Description_Source;
444
445//---------------------------------------------------------
447{
448 m_Description_Source = Source;
449
450 return( true );
451}
452
454{
455 return( m_Description_Source );
456}
457
458//---------------------------------------------------------
460{
462
463 if( SG_Dir_Exists(Folder) )
464 {
465 CSG_String Name(Get_Library() + "_" + Get_ID()), Description; CSG_File Stream; CSG_Table Table;
466
467 if( Stream.Open(SG_File_Make_Path(Folder, Name, "txt"), SG_FILE_R, true, SG_FILE_ENCODING_UTF8) && Stream.Read(Description) > 0 )
468 {
469 Description = CSG_Text_Format_Converter::Markdown_to_Html(Description, true);
470
472 }
473
475
476 m_References.Del_Records();
477
478 if( Table.Create(SG_File_Make_Path(Folder, Name + "_references", "txt")) && Table.Get_Field_Count() == 6 )
479 {
480 for(int i=0; i<Table.Get_Field_Count(); i++) { Table.Set_Field_Type(i, SG_DATATYPE_String); }
481
482 for(sLong i=0; i<Table.Get_Count(); i++)
483 {
484 Add_Reference(Table[i].asString(0), Table[i].asString(1), Table[i].asString(2), Table[i].asString(3), Table[i].asString(4), Table[i].asString(5));
485 }
486 }
487
488 if( Table.Create(SG_File_Make_Path(Folder, Name + "_parameters", "txt")) && Table.Get_Field_Count() == 3 )
489 {
490 for(int i=0; i<Table.Get_Field_Count(); i++) { Table.Set_Field_Type(i, SG_DATATYPE_String); }
491
492 for(sLong i=0; i<Table.Get_Count(); i++)
493 {
494 CSG_Parameter *pParameter = Get_Parameter(Table[i].asString(0));
495
496 if( pParameter )
497 {
498 pParameter->Set_Name (Table[i].asString(1));
499 pParameter->Set_Description(Table[i].asString(2));
500 }
501 }
502 }
503
504 m_Editors.Del_Records();
505
506 if( Table.Create(SG_File_Make_Path(Folder, Name + "_editors" , "txt")) && Table.Get_Field_Count() == 2 )
507 {
508 for(int i=0; i<Table.Get_Field_Count(); i++) { Table.Set_Field_Type(i, SG_DATATYPE_String); }
509
510 for(sLong i=0; i<Table.Get_Count(); i++)
511 {
512 m_Editors.Add_Record(Table.Get_Record(i));
513 }
514 }
515
517
518 return( true );
519 }
520
521 return( false );
522}
523
524//---------------------------------------------------------
526{
527 CSG_String Editors;
528
529 for(sLong i=0; i<m_Editors.Get_Count(); i++)
530 {
531 if( !m_Editors[i].is_NoData(0) )
532 {
533 if( !Editors.is_Empty() ) { Editors += ", "; }
534
535 Editors += m_Editors[i].asString(0);
536
537 if( !m_Editors[i].is_NoData(1) )
538 {
539 Editors += CSG_String::Format(" (%s)", m_Editors[i].asString(1));
540 }
541 }
542 }
543
544 if( !Editors.is_Empty() )
545 {
546 Editors = CSG_String::Format(bHTML ? "<hr><small><small>%s: <i>%s</i>.</small></small>" : "\n___\n%s: %s\n",
547 _TL("Description editor(s)"), Editors.c_str()
548 );
549 }
550
551 return( Editors );
552}
553
554
556// //
557// //
558// //
560
561//---------------------------------------------------------
562bool CSG_Tool::Execute(bool bAddHistory)
563{
564 #define ADD_MESSAGE_EXECUTION(Text, Style) { SG_UI_Msg_Add(Text, true, Style); if( has_GUI() ) { SG_UI_Msg_Add_Execution(Text, true, Style); } }
565
566 //-----------------------------------------------------
567 if( m_bExecutes )
568 {
569 return( false );
570 }
571
572 m_bExecutes = true;
573
574 m_bError_Ignore = false;
575
576 bool bResult = false;
577
578 m_Execution_Info.Clear();
579
580 History_Supplement.Destroy();
581
582 //-----------------------------------------------------
583 if( Parameters.Get_Manager() == &SG_Get_Data_Manager() )
584 {
585 ADD_MESSAGE_EXECUTION(CSG_String::Format("[%s] %s...", Get_Name().c_str(), _TL("Execution started")), SG_UI_MSG_STYLE_SUCCESS);
586 }
587
589
590 if( Parameters.DataObjects_Create() == false )
591 {
592 _Synchronize_DataObjects(); // not all, but some objects might have been created!
593 }
594 else
595 {
596 Parameters.Msg_String(false);
597
598 // SG_UI_Process_Set_Busy(true, CSG_String::Format("%s: %s...", _TL("Executing"), Get_Name().c_str()));
600
602//#if !defined(_DEBUG)
603#define _TOOL_EXCEPTION
604 try
605 {
606//#endif
608
609 bResult = On_Execute();
610
612#ifdef _TOOL_EXCEPTION
613 } // try
614 catch(const std::exception &Exception)
615 {
616 Message_Dlg(Exception.what() , CSG_String::Format("%s | %s", Get_Name().c_str(), _TL("Access violation!")));
617 }
618 catch(...)
619 {
620 Message_Dlg(_TL("unspecified exception"), CSG_String::Format("%s | %s", Get_Name().c_str(), _TL("Access violation!")));
621 }
622 #endif
624
625 CSG_TimeSpan Span = CSG_DateTime::Now() - Started;
626 // SG_UI_Process_Set_Busy(false);
627
628 _Synchronize_DataObjects();
629
630 if( !Process_Get_Okay(false) )
631 {
632 SG_UI_Msg_Add(_TL("Execution has been stopped by user!"), true, SG_UI_MSG_STYLE_BOLD);
633
634 bResult = false;
635 }
636
637 if( bResult && bAddHistory )
638 {
639 _Set_Output_History();
640 }
641
642 //-------------------------------------------------
643 if( is_Interactive() )
644 {
645 if( bResult )
646 {
647 CSG_String Text(CSG_String::Format("\n%s...", _TL("Interactive tool started and is waiting for user input.")));
648
649 SG_UI_Msg_Add (Text, false, SG_UI_MSG_STYLE_BOLD);
651 }
652 else
653 {
654 ADD_MESSAGE_EXECUTION(_TL("Interactive tool initialization failed."), SG_UI_MSG_STYLE_FAILURE);
655 }
656 }
657 else
658 {
659 CSG_String Time =
660 Span.Get_Hours () >= 1 ? (Span.Format("%Hh %Mm %Ss"))
661 : Span.Get_Minutes () >= 1 ? (Span.Format( "%Mm %Ss"))
662 : Span.Get_Seconds () >= 1 ? (Span.Format( "%Ss"))
663 : Span.Get_Milliseconds() >= 1 ? (Span.Format("%l ") + _TL("milliseconds"))
664 : CSG_String(_TL("less than 1 millisecond"));
665
666 if( Parameters.Get_Manager() != &SG_Get_Data_Manager() )
667 {
668 SG_UI_Msg_Add_Execution(CSG_String::Format("\n[%s] %s: %s", Get_Name().c_str(),
669 _TL("execution time"), Time.c_str()),
671 );
672 }
673 else
674 {
675 SG_UI_Msg_Add_Execution(CSG_String::Format("\n__________\n%s %s: %lld %s (%s)\n", _TL("total"),
676 _TL("execution time"), Span.Get_Milliseconds(), _TL("milliseconds"), Time.c_str()),
678 );
679
680 ADD_MESSAGE_EXECUTION(CSG_String::Format("[%s] %s (%s)", Get_Name().c_str(),
681 bResult ? _TL("Execution succeeded") : _TL("Execution failed"), Time.c_str()),
683 );
684 }
685 }
686 }
687
688 //-----------------------------------------------------
689 History_Supplement.Destroy();
690
691 m_bExecutes = false;
692
695
696 return( bResult );
697}
698
699
701// //
702// //
703// //
705
706//---------------------------------------------------------
707bool CSG_Tool::_Synchronize_DataObjects(void)
708{
709 Parameters.DataObjects_Synchronize();
710
711 for(int i=0; i<Get_Parameters_Count(); i++)
712 {
713 Get_Parameters(i)->DataObjects_Synchronize();
714 }
715
716 CSG_Projection Projection;
717
719 {
720 Parameters.DataObjects_Set_Projection(Projection);
721
722 for(int i=0; i<Get_Parameters_Count(); i++)
723 {
724 Get_Parameters(i)->DataObjects_Set_Projection(Projection);
725 }
726
727 return( true );
728 }
729
730 return( false );
731}
732
733//---------------------------------------------------------
735{
736 Projection.Destroy();
737
738 Parameters.DataObjects_Get_Projection(Projection);
739
740 for(int i=0; i<Get_Parameters_Count() && !Projection.is_Okay(); i++)
741 {
742 Get_Parameters(i)->DataObjects_Get_Projection(Projection);
743 }
744
745 return( Projection.is_Okay() );
746}
747
748
750// //
751// Parameters //
752// //
754
755//---------------------------------------------------------
757{
758 CSG_Parameters *pParameters = pParameter ? pParameter ->Get_Parameters() : NULL;
759 CSG_Tool *pTool = pParameters ? pParameters->Get_Tool () : NULL;
760
761 if( pTool )
762 {
763 if( Flags & PARAMETER_CHECK_VALUES )
764 {
765 pTool->On_Parameter_Changed(pParameters, pParameter);
766 }
767
768 if( Flags & PARAMETER_CHECK_ENABLE )
769 {
770 pTool->On_Parameters_Enable(pParameters, pParameter);
771 }
772
773 return( 1 );
774 }
775
776 return( 0 );
777}
778
779//---------------------------------------------------------
781{
782 return( 1 );
783}
784
785//---------------------------------------------------------
787{
788 return( 1 );
789}
790
791
793// //
794// Extra Parameters //
795// //
797
798//---------------------------------------------------------
799CSG_Parameters * CSG_Tool::Add_Parameters(const CSG_String &Identifier, const CSG_String &Name, const CSG_String &Description)
800{
801 CSG_Parameters *pParameters = new CSG_Parameters(); // (Name, Description, Identifier);
802
803 pParameters->Create(this, Name, Description, Identifier);
805 pParameters->m_pTool = this;
806
807 m_pParameters.Add(pParameters);
808
809 return( pParameters );
810}
811
812//---------------------------------------------------------
814{
815 for(int i=0; i<Get_Parameters_Count(); i++)
816 {
817 if( Get_Parameters(i)->Cmp_Identifier(Identifier) )
818 {
819 return( Get_Parameters(i) );
820 }
821 }
822
823 return( NULL );
824}
825
826//---------------------------------------------------------
828{
829 CSG_Parameters *pParameters = Get_Parameters(Identifier);
830
831 if( pParameters && (!pParameters->is_Managed() || Dlg_Parameters(pParameters, Get_Name())) )
832 {
833 pParameters->Set_History(History_Supplement);
834
835 return( true );
836 }
837
838 return( false );
839}
840
841
843// //
845
846//---------------------------------------------------------
847bool CSG_Tool::Dlg_Parameters(CSG_Parameters *pParameters, const CSG_String &Caption)
848{
849 return( pParameters ? Dlg_Parameters(*pParameters, Caption) : false );
850}
851
853{
854 return( SG_UI_Dlg_Parameters(&Parameters, Caption.is_Empty() ? Get_Name() : Caption) );
855}
856
857
859// //
861
862//---------------------------------------------------------
863void CSG_Tool::Set_Callback(bool bActive)
864{
865 Parameters.Set_Callback(bActive);
866
867 for(int i=0; i<Get_Parameters_Count(); i++)
868 {
869 Get_Parameters(i)->Set_Callback(bActive);
870 }
871}
872
873//---------------------------------------------------------
875{
876 Parameters.Set_Manager(pManager);
877
878 for(int i=0; i<Get_Parameters_Count(); i++)
879 {
880 Get_Parameters(i)->Set_Manager(pManager);
881 }
882
883 return( true );
884}
885
886//---------------------------------------------------------
888{
889 return( Parameters.Get_Manager() );
890}
891
892//---------------------------------------------------------
894{
896
897 return( Get_Manager() );
898}
899
900//---------------------------------------------------------
901bool CSG_Tool::Delete_Manager(bool bDetachData, bool bReset)
902{
903 CSG_Data_Manager *pManager = Get_Manager();
904
905 if( pManager && pManager != &SG_Get_Data_Manager() )
906 {
907 pManager->Delete(bDetachData);
908
909 delete(pManager);
910
911 return( bReset ? Set_Manager(&SG_Get_Data_Manager()) : Set_Manager(NULL) );
912 }
913
914 return( false );
915}
916
917
919// //
920// //
921// //
923
924//---------------------------------------------------------
926{
927 Parameters.Push(pManager);
928
929 for(int i=0; i<Get_Parameters_Count(); i++)
930 {
931 Get_Parameters(i)->Push(pManager);
932 }
933
934 return( true );
935}
936
937//---------------------------------------------------------
939{
940 Parameters.Pop();
941
942 for(int i=0; i<Get_Parameters_Count(); i++)
943 {
944 Get_Parameters(i)->Pop();
945 }
946
947 return( true );
948}
949
950
952// //
953// Progress //
954// //
956
957//---------------------------------------------------------
959{
960 m_bShow_Progress = bOn;
961}
962
963//---------------------------------------------------------
964bool CSG_Tool::Set_Progress(int Position, int Range) const
965{
966 return( Set_Progress((double)Position / (double)Range) );
967}
968
969//---------------------------------------------------------
970bool CSG_Tool::Set_Progress(sLong Position, sLong Range) const
971{
972 return( Set_Progress((double)Position / (double)Range) );
973}
974
975//---------------------------------------------------------
976bool CSG_Tool::Set_Progress(double Position, double Range) const
977{
978 return( m_bShow_Progress ? SG_UI_Process_Set_Progress(Position, Range) : Process_Get_Okay(false) );
979}
980
981//---------------------------------------------------------
982bool CSG_Tool::Stop_Execution(bool bDialog)
983{
984 m_bExecutes = false;
985
986 return( SG_UI_Stop_Execution(bDialog) );
987}
988
989
991// //
992// Message //
993// //
995
996//---------------------------------------------------------
997void CSG_Tool::Message_Dlg(const CSG_String &Text, const SG_Char *Caption)
998{
999 SG_UI_Dlg_Message(Text, Caption && Caption[0] != '\0' ? Caption : Get_Name().c_str());
1000}
1001
1002//---------------------------------------------------------
1003bool CSG_Tool::Message_Dlg_Confirm(const CSG_String &Text, const SG_Char *Caption)
1004{
1005 return( SG_UI_Dlg_Continue(Text, Caption && Caption[0] != '\0' ? Caption : Get_Name().c_str()) );
1006}
1007
1008//---------------------------------------------------------
1010{
1011 switch( Error_ID )
1012 {
1013 default:
1014 return( Error_Set(_TL("Unknown Error")) );
1015
1017 return( Error_Set(_TL("Calculation Error")) );
1018 }
1019}
1020
1021//---------------------------------------------------------
1023{
1024 SG_UI_Msg_Add_Error(Text);
1025
1026 m_Execution_Info += "\n____\n" + Text;
1027
1028 if( SG_UI_Process_Get_Okay(false) && !m_bError_Ignore )
1029 {
1030 switch( SG_UI_Dlg_Error(Text, CSG_String::Format("%s: %s?", _TL("Error"), _TL("Ignore"))) )
1031 {
1032 default:
1034 break;
1035
1036 case 1:
1037 m_bError_Ignore = true;
1038 break;
1039 }
1040 }
1041
1042 return( SG_UI_Process_Get_Okay(false) );
1043}
1044
1045//---------------------------------------------------------
1046bool CSG_Tool::Error_Fmt(const char *Format, ...)
1047{
1048 wxString _s;
1049
1050 va_list argptr;
1051
1052#ifdef _SAGA_LINUX
1053 // workaround as we only use wide characters
1054 // since wx 2.9.4 so interpret strings as multibyte
1055 wxString _Format(Format); _Format.Replace("%s", "%ls");
1056 va_start(argptr, _Format);
1057 _s.PrintfV(_Format, argptr);
1058#else
1059 va_start(argptr, Format);
1060 _s.PrintfV(Format, argptr);
1061#endif
1062
1063 va_end(argptr);
1064
1065 CSG_String s(&_s);
1066
1067 return( Error_Set(s) );
1068}
1069
1070//---------------------------------------------------------
1071bool CSG_Tool::Error_Fmt(const wchar_t *Format, ...)
1072{
1073 wxString _s;
1074
1075 va_list argptr;
1076
1077#ifdef _SAGA_LINUX
1078 // workaround as we only use wide characters
1079 // since wx 2.9.4 so interpret strings as multibyte
1080 wxString _Format(Format); _Format.Replace("%s", "%ls");
1081 va_start(argptr, _Format);
1082 _s.PrintfV(_Format, argptr);
1083#else
1084 va_start(argptr, Format);
1085 _s.PrintfV(Format, argptr);
1086#endif
1087
1088 va_end(argptr);
1089
1090 CSG_String s(&_s);
1091
1092 return( Error_Set(s) );
1093}
1094
1095
1097// //
1098// DataObjects / GUI Interaction //
1099// //
1101
1102//---------------------------------------------------------
1103bool CSG_Tool::DataObject_Add(CSG_Data_Object *pDataObject, bool bShow)
1104{
1105 if( Parameters.Get_Manager() )
1106 {
1107 Parameters.Get_Manager()->Add(pDataObject);
1108 }
1109
1110 if( Parameters.Get_Manager() == &SG_Get_Data_Manager() ) // prevent that local data manager send their data objects to gui
1111 {
1113 }
1114
1115 return( true );
1116}
1117
1118//---------------------------------------------------------
1120{
1121 for(int i=0; i<Parameters.Get_Count(); i++)
1122 {
1123 if( Parameters(i)->is_Output() )
1124 {
1125 if( Parameters(i)->is_DataObject() )
1126 {
1127 DataObject_Update(Parameters(i)->asDataObject(), false);
1128 }
1129 else if( Parameters(i)->is_DataObject_List() )
1130 {
1131 for(int j=0; j<Parameters(i)->asList()->Get_Item_Count(); j++)
1132 {
1133 DataObject_Update(Parameters(i)->asList()->Get_Item(j), false);
1134 }
1135 }
1136 }
1137 }
1138
1139 return( true );
1140}
1141
1142
1144// //
1145// Static Data Message/Progress Functions //
1146// //
1148
1149//---------------------------------------------------------
1151{
1152 return( SG_UI_Process_Get_Okay(bBlink) );
1153}
1154
1155//---------------------------------------------------------
1157{
1159}
1160
1161//---------------------------------------------------------
1162void CSG_Tool::Process_Set_Text(const char *Format, ...)
1163{
1164 wxString _s;
1165
1166 va_list argptr;
1167
1168 #ifdef _SAGA_LINUX
1169 // workaround as we only use wide characters
1170 // since wx 2.9.4 so interpret strings as multibyte
1171 wxString _Format(Format); _Format.Replace("%s", "%ls");
1172 va_start(argptr, _Format);
1173 _s.PrintfV(_Format, argptr);
1174 #else
1175 va_start(argptr, Format);
1176 _s.PrintfV(Format, argptr);
1177 #endif
1178
1179 va_end(argptr);
1180
1181 CSG_String s(&_s);
1182
1184}
1185
1186//---------------------------------------------------------
1187void CSG_Tool::Process_Set_Text(const wchar_t *Format, ...)
1188{
1189 wxString _s;
1190
1191 va_list argptr;
1192
1193 #ifdef _SAGA_LINUX
1194 // workaround as we only use wide characters
1195 // since wx 2.9.4 so interpret strings as multibyte
1196 wxString _Format(Format); _Format.Replace("%s", "%ls");
1197 va_start(argptr, _Format);
1198 _s.PrintfV(_Format, argptr);
1199 #else
1200 va_start(argptr, Format);
1201 _s.PrintfV(Format, argptr);
1202 #endif
1203
1204 va_end(argptr);
1205
1206 CSG_String s(&_s);
1207
1209}
1210
1211//---------------------------------------------------------
1212void CSG_Tool::Message_Add(const CSG_String &Text, bool bNewLine)
1213{
1214 SG_UI_Msg_Add_Execution(Text, bNewLine);
1215
1216 if( bNewLine )
1217 {
1218 m_Execution_Info += "\n";
1219 }
1220
1221 m_Execution_Info += Text;
1222}
1223
1224//---------------------------------------------------------
1225void CSG_Tool::Message_Fmt(const char *Format, ...)
1226{
1227 wxString _s;
1228
1229 va_list argptr;
1230
1231 #ifdef _SAGA_LINUX
1232 // workaround as we only use wide characters
1233 // since wx 2.9.4 so interpret strings as multibyte
1234 wxString _Format(Format); _Format.Replace("%s", "%ls");
1235 va_start(argptr, _Format);
1236 _s.PrintfV(_Format, argptr);
1237 #else
1238 va_start(argptr, Format);
1239 _s.PrintfV(Format, argptr);
1240 #endif
1241
1242 va_end(argptr);
1243
1244 CSG_String s(&_s);
1245
1246 Message_Add(s, false);
1247}
1248
1249//---------------------------------------------------------
1250void CSG_Tool::Message_Fmt(const wchar_t *Format, ...)
1251{
1252 wxString _s;
1253
1254 va_list argptr;
1255
1256 #ifdef _SAGA_LINUX
1257 // workaround as we only use wide characters
1258 // since wx 2.9.4 so interpret strings as multibyte
1259 wxString _Format(Format); _Format.Replace("%s", "%ls");
1260 va_start(argptr, _Format);
1261 _s.PrintfV(_Format, argptr);
1262 #else
1263 va_start(argptr, Format);
1264 _s.PrintfV(Format, argptr);
1265 #endif
1266
1267 va_end(argptr);
1268
1269 CSG_String s(&_s);
1270
1271 Message_Add(s, false);
1272}
1273
1274
1276// //
1277// Static Data Object Property Functions //
1278// //
1280
1281//---------------------------------------------------------
1283{
1284 return( SG_UI_DataObject_Update(pDataObject, Show, NULL) );
1285}
1286
1287bool CSG_Tool::DataObject_Update(CSG_Data_Object *pDataObject, double Minimum, double Maximum, int Show)
1288{
1290
1291 return( DataObject_Get_Parameters(pDataObject, P)
1292 && P.Set_Parameter("STRETCH_DEFAULT" , 3 ) // manual
1293 && P.Set_Parameter("METRIC_ZRANGE.MIN", Minimum)
1294 && P.Set_Parameter("METRIC_ZRANGE.MAX", Maximum)
1295 && SG_UI_DataObject_Update(pDataObject, Show, &P)
1296 );
1297}
1298
1299//---------------------------------------------------------
1301{
1302 return( SG_UI_DataObject_Colors_Get(pDataObject, &Colors) );
1303}
1304
1306{
1307 CSG_Colors c; return( c.Create(Colors) && SG_UI_DataObject_Colors_Set(pDataObject, &c) );
1308}
1309
1310bool CSG_Tool::DataObject_Set_Colors(CSG_Data_Object *pDataObject, int nColors, int Colors, bool bRevert)
1311{
1312 CSG_Colors c; return( c.Set_Predefined(Colors, bRevert, nColors) && SG_UI_DataObject_Colors_Set(pDataObject, &c) );
1313}
1314
1315bool CSG_Tool::DataObject_Set_Colors(CSG_Data_Object *pDataObject, const CSG_String &Colors, int nColors, bool bRevert)
1316{
1317 CSG_Colors c; return( c.Set_Predefined(Colors, bRevert, nColors) && SG_UI_DataObject_Colors_Set(pDataObject, &c) );
1318}
1319
1320//---------------------------------------------------------
1325
1330
1332{
1333 if( pDataObject == pCopy )
1334 {
1335 return( true );
1336 }
1337
1339
1340 if( DataObject_Get_Parameters(pCopy, P) )
1341 {
1342 P.Del_Parameter("OBJECT_NODATA" );
1343 P.Del_Parameter("OBJECT_Z_FACTOR");
1344 P.Del_Parameter("OBJECT_Z_OFFSET");
1345
1346 return( DataObject_Set_Parameters(pDataObject, P) );
1347 }
1348
1349 return( false );
1350}
1351
1352//---------------------------------------------------------
1354{
1355 static CSG_Parameters P;
1356
1357 return( DataObject_Get_Parameters(pDataObject, P) ? P(ID) : NULL );
1358}
1359
1361{
1363
1364 return( P._Add(pParameter) != NULL && DataObject_Set_Parameters(pDataObject, P) );
1365}
1366
1368{
1369 CSG_Parameter *pParameter = DataObject_Get_Parameter(pCopy, ID);
1370
1371 return( DataObject_Set_Parameter(pDataObject, pParameter) );
1372}
1373
1374bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, int Value)
1375{
1377
1378 if( DataObject_Get_Parameters(pDataObject, P) && P(ID) )
1379 {
1380 return( P(ID)->Set_Value(Value) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1381 }
1382
1383 return( false );
1384}
1385
1386bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, double Value)
1387{
1389
1390 if( DataObject_Get_Parameters(pDataObject, P) && P(ID) )
1391 {
1392 return( P(ID)->Set_Value(Value) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1393 }
1394
1395 return( false );
1396}
1397
1398bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, void *Value)
1399{
1401
1402 if( DataObject_Get_Parameters(pDataObject, P) && P(ID) )
1403 {
1404 return( P(ID)->Set_Value(Value) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1405 }
1406
1407 return( false );
1408}
1409
1410bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, const SG_Char *Value)
1411{
1413
1414 if( DataObject_Get_Parameters(pDataObject, P) && P(ID) )
1415 {
1416 return( P(ID)->Set_Value(Value) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1417 }
1418
1419 return( false );
1420}
1421
1422bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, double loVal, double hiVal) // Range Parameter
1423{
1425
1426 if( DataObject_Get_Parameters(pDataObject, P) && P(ID) && P(ID)->Get_Type() == PARAMETER_TYPE_Range )
1427 {
1428 return( P(ID)->asRange()->Set_Range(loVal, hiVal) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1429 }
1430
1431 return( false );
1432}
1433
1434
1436// //
1438
1439//---------------------------------------------------------
1440#define INIT_STRETCH_OPTIONS(method) { if( !pDataObject || (pDataObject->asTable(true) && (Field < 0 || Field >= pDataObject->asTable(true)->Get_Field_Count())) ) { return( false ); }\
1441 if( Colors >= 0 ) { DataObject_Set_Colors(pDataObject, -1, Colors); }\
1442 DataObject_Set_Parameter(pDataObject, "COLORS_TYPE" , 3); /* graduated colors */\
1443 DataObject_Set_Parameter(pDataObject, "STRETCH_DEFAULT" , method);\
1444 DataObject_Set_Parameter(pDataObject, "METRIC_SCALE_MODE", Interval_Mode);\
1445 DataObject_Set_Parameter(pDataObject, "METRIC_SCALE_LOG" , Interval_Log );\
1446 if( pDataObject->asTable(true) )\
1447 { DataObject_Set_Parameter(pDataObject, "METRIC_FIELD" , Field);\
1448 DataObject_Set_Parameter(pDataObject, "METRIC_MORMAL", pDataObject->asTable(true)->Get_Field_Count());\
1449 }\
1450}
1451
1452//---------------------------------------------------------
1453bool 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)
1454{
1456
1457 DataObject_Set_Parameter(pDataObject, "STRETCH_LINEAR.MIN", Minimum);
1458 DataObject_Set_Parameter(pDataObject, "STRETCH_LINEAR.MAX", Maximum);
1459
1460 return( bUpdateNow ? DataObject_Update(pDataObject) : true );
1461}
1462
1463//---------------------------------------------------------
1464bool 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)
1465{
1467
1468 DataObject_Set_Parameter(pDataObject, "STRETCH_STDDEV" , StdDev );
1469 DataObject_Set_Parameter(pDataObject, "STRETCH_INRANGE", bKeepInRange);
1470 DataObject_Update(pDataObject);
1471
1472 return( bUpdateNow ? DataObject_Update(pDataObject) : true );
1473}
1474
1475//---------------------------------------------------------
1476bool 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)
1477{
1479
1480 DataObject_Set_Parameter(pDataObject, "STRETCH_PCTL.MIN", Minimum);
1481 DataObject_Set_Parameter(pDataObject, "STRETCH_PCTL.MAX", Maximum);
1482
1483 return( bUpdateNow ? DataObject_Update(pDataObject) : true );
1484}
1485
1486//---------------------------------------------------------
1487bool 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)
1488{
1490
1491 DataObject_Set_Parameter(pDataObject, "METRIC_ZRANGE.MIN", Minimum);
1492 DataObject_Set_Parameter(pDataObject, "METRIC_ZRANGE.MAX", Maximum);
1493
1494 return( bUpdateNow ? DataObject_Update(pDataObject) : true );
1495}
1496
1497
1499// //
1501
1502//---------------------------------------------------------
1503#define INIT_CLASSIFY_OPTIONS(method) if( !pDataObject || (pDataObject->asTable(true) && (Field < 0 || Field >= pDataObject->asTable(true)->Get_Field_Count())) ) { return( false ); }\
1504 CSG_MetaData Options; Options.Add_Child("METHOD", method); Options.Add_Child("COLORS", Colors); Options.Add_Child("FIELD", Field);
1505
1506//---------------------------------------------------------
1507bool CSG_Tool::DataObject_Classify_Unique(CSG_Data_Object *pDataObject, int Field, int maxClasses, int Colors)
1508{
1510
1511 Options.Add_Child("MAXCLASSES", maxClasses);
1512
1513 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1514}
1515
1516//---------------------------------------------------------
1517bool CSG_Tool::DataObject_Classify_Equal(CSG_Data_Object *pDataObject, int Field, int Classes, int Colors)
1518{
1520
1521 Options.Add_Child("CLASSES", Classes);
1522
1523 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1524}
1525
1526//---------------------------------------------------------
1527bool CSG_Tool::DataObject_Classify_Defined(CSG_Data_Object *pDataObject, int Field, double Interval, bool bOffset, double Offset, int Colors)
1528{
1530
1531 Options.Add_Child("INTERVAL", Interval); if( bOffset ) { Options.Add_Child("OFFSET", Offset); }
1532
1533 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1534}
1535
1536//---------------------------------------------------------
1537bool CSG_Tool::DataObject_Classify_Quantile(CSG_Data_Object *pDataObject, int Field, int Classes, bool bHistogram, int Colors)
1538{
1540
1541 Options.Add_Child("CLASSES", Classes); Options.Add_Child("HISTOGRAM", bHistogram ? 1 : 0);
1542
1543 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1544}
1545
1546//---------------------------------------------------------
1547bool CSG_Tool::DataObject_Classify_Geometric(CSG_Data_Object *pDataObject, int Field, int Classes, bool bIncreasing, int Colors)
1548{
1550
1551 Options.Add_Child("CLASSES", Classes); Options.Add_Child("INCREASING", bIncreasing ? 1 : 0);
1552
1553 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1554}
1555
1556//---------------------------------------------------------
1557bool CSG_Tool::DataObject_Classify_Natural(CSG_Data_Object *pDataObject, int Field, int Classes, int Colors)
1558{
1560
1561 Options.Add_Child("CLASSES", Classes);
1562
1563 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1564}
1565
1566//---------------------------------------------------------
1567bool CSG_Tool::DataObject_Classify_StdDev(CSG_Data_Object *pDataObject, int Field, double StdDev, double StdDev_Max, int Colors)
1568{
1570
1571 Options.Add_Child("STDDEV", StdDev); Options.Add_Child("STDDEV_MAX", StdDev_Max);
1572
1573 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1574}
1575
1576
1578// //
1579// //
1580// //
1582
1583//---------------------------------------------------------
1587//---------------------------------------------------------
1588CSG_Parameter * CSG_Tool::Get_Parameter(const char *ID) const { return( Get_Parameter(CSG_String(ID)) ); }
1589CSG_Parameter * CSG_Tool::Get_Parameter(const wchar_t *ID) const { return( Get_Parameter(CSG_String(ID)) ); }
1591{
1592 CSG_Parameter *pParameter = Parameters(ID);
1593
1594 for(int i=0; !pParameter && i<Get_Parameters_Count(); i++)
1595 {
1596 pParameter = Get_Parameters(i)->Get_Parameter(ID);
1597 }
1598
1599 return( pParameter );
1600}
1601
1602//---------------------------------------------------------
1606//---------------------------------------------------------
1607bool CSG_Tool::Set_Parameter(const CSG_String &ID, CSG_Parameter *pValue) { return( Parameters.Set_Parameter(ID, pValue) ); }
1608bool CSG_Tool::Set_Parameter(const char *ID, CSG_Parameter *pValue) { return( Parameters.Set_Parameter(ID, pValue) ); }
1609bool CSG_Tool::Set_Parameter(const wchar_t *ID, CSG_Parameter *pValue) { return( Parameters.Set_Parameter(ID, pValue) ); }
1610
1611//---------------------------------------------------------
1615//---------------------------------------------------------
1616bool CSG_Tool::Set_Parameter(const CSG_String &ID, int Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1617bool CSG_Tool::Set_Parameter(const char *ID, int Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1618bool CSG_Tool::Set_Parameter(const wchar_t *ID, int Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1619
1620//---------------------------------------------------------
1624//---------------------------------------------------------
1625bool CSG_Tool::Set_Parameter(const CSG_String &ID, double Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1626bool CSG_Tool::Set_Parameter(const char *ID, double Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1627bool CSG_Tool::Set_Parameter(const wchar_t *ID, double Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1628
1629//---------------------------------------------------------
1633//---------------------------------------------------------
1634bool CSG_Tool::Set_Parameter(const CSG_String &ID, void *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1635bool CSG_Tool::Set_Parameter(const char *ID, void *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1636bool CSG_Tool::Set_Parameter(const wchar_t *ID, void *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1637
1638//---------------------------------------------------------
1642//---------------------------------------------------------
1643bool CSG_Tool::Set_Parameter(const CSG_String &ID, const CSG_String &Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1644bool CSG_Tool::Set_Parameter(const char *ID, const CSG_String &Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1645bool CSG_Tool::Set_Parameter(const wchar_t *ID, const CSG_String &Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1646
1647//---------------------------------------------------------
1651//---------------------------------------------------------
1652bool CSG_Tool::Set_Parameter(const CSG_String &ID, const char *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1653bool CSG_Tool::Set_Parameter(const char *ID, const char *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1654bool CSG_Tool::Set_Parameter(const wchar_t *ID, const char *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1655
1656//---------------------------------------------------------
1660//---------------------------------------------------------
1661bool CSG_Tool::Set_Parameter(const CSG_String &ID, const wchar_t *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1662bool CSG_Tool::Set_Parameter(const char *ID, const wchar_t *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1663bool CSG_Tool::Set_Parameter(const wchar_t *ID, const wchar_t *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1664
1665
1667// //
1668// //
1669// //
1671
1672//---------------------------------------------------------
1678bool CSG_Tool::Reset(bool bManager)
1679{
1681
1682 if( bManager )
1683 {
1684 Reset_Manager();
1685 }
1686
1687 for(int i=0; i<Get_Parameters_Count(); i++)
1688 {
1690 }
1691
1692 return( Parameters.Restore_Defaults(true) );
1693}
1694
1695//---------------------------------------------------------
1701{
1702 return( Set_Manager(&SG_Get_Data_Manager()) );
1703}
1704
1705//---------------------------------------------------------
1711{
1712 for(int i=0; i<Get_Parameters_Count(); i++)
1713 {
1715 }
1716
1717 return( Parameters.Reset_Grid_System() );
1718}
1719
1720//---------------------------------------------------------
1726{
1727 return( Parameters.Set_Grid_System(System) );
1728}
1729
1730//---------------------------------------------------------
1736{
1737 return( Parameters.Get_Grid_System() );
1738}
1739
1740
1742// //
1743// //
1744// //
1746
1747//---------------------------------------------------------
1749{
1750 _Update_Parameter_States(&Parameters);
1751
1752 for(int i=0; i<Get_Parameters_Count(); i++)
1753 {
1754 _Update_Parameter_States(Get_Parameters(i));
1755 }
1756
1757 return( true );
1758}
1759
1760//---------------------------------------------------------
1761void CSG_Tool::_Update_Parameter_States(CSG_Parameters *pParameters)
1762{
1763 if( pParameters )
1764 {
1765 for(int i=0; i<pParameters->Get_Count(); i++)
1766 {
1767 CSG_Parameter *pParameter = pParameters->Get_Parameter(i);
1768
1769 if( pParameter->Get_Type() == PARAMETER_TYPE_Parameters )
1770 {
1771 _Update_Parameter_States(pParameter->asParameters());
1772 }
1773 else
1774 {
1775 On_Parameters_Enable(pParameters, pParameter);
1776 }
1777 }
1778 }
1779}
1780
1781
1783// //
1784// Script //
1785// //
1787
1788//---------------------------------------------------------
1789CSG_String CSG_Tool::Get_Script(Script_Format Format, bool bHeader, int Arguments, bool bWrapArgs)
1790{
1791 switch( Format )
1792 {
1793 case Script_Format::CMD_Shell : return( _Get_Script_CMD ( bHeader, Arguments > 0, bWrapArgs, false ) );
1794 case Script_Format::CMD_Batch : return( _Get_Script_CMD ( bHeader, Arguments > 0, bWrapArgs, true ) );
1795 case Script_Format::CMD_Usage : return( _Get_Script_CMD_Usage ( ) );
1796
1797 case Script_Format::Toolchain : return( CSG_Tool_Chain::Get_Script(this, bHeader, Arguments > 0 ) );
1798
1799 case Script_Format::Python : return( _Get_Script_Python ( bHeader, Arguments > 0 ) );
1800
1801 case Script_Format::Python_Wrapper_Func_Name : return( _Get_Script_Python_Wrap ( bHeader, true , false, 1, bWrapArgs ) );
1802 case Script_Format::Python_Wrapper_Func_ID : return( _Get_Script_Python_Wrap ( bHeader, false, false, 1, bWrapArgs ) );
1803
1804 case Script_Format::Python_Wrapper_Call_Name : return( _Get_Script_Python_Wrap ( bHeader, true , true , Arguments, bWrapArgs ) );
1805 case Script_Format::Python_Wrapper_Call_ID : return( _Get_Script_Python_Wrap ( bHeader, false, true , Arguments, bWrapArgs ) );
1806
1807 case Script_Format::Markdown_Table : return( _Get_Script_Markdown ( bHeader, Arguments ) );
1808 }
1809
1810 return( "" );
1811}
1812
1813
1815// //
1817
1818//---------------------------------------------------------
1819CSG_String CSG_Tool::_Get_Script_CMD(bool bHeader, bool bAllArguments, bool bWrapArgs, bool bBatch)
1820{
1821 CSG_String Script;
1822
1823 if( bHeader )
1824 {
1825 if( bBatch ) // DOS/Windows Batch Script
1826 {
1827 Script += "@ECHO OFF\n\n";
1828 Script += "PUSHD %~dp0\n\n";
1829 Script += "REM SET SAGA_TLB=C:\\MyTools\n\n";
1830 Script += "SET SAGA_CMD=" + SG_UI_Get_Application_Path(true) + "saga_cmd.exe\n\n";
1831 Script += "REM Tool: " + Get_Name() + "\n\n";
1832 Script += "%SAGA_CMD%";
1833 }
1834 else // Bash Shell Script
1835 {
1836 Script += "#!/bin/bash\n\n";
1837 Script += "# export SAGA_TLB=~/mytools\n\n";
1838 Script += "# tool: " + Get_Name() + "\n\n";
1839 Script += "saga_cmd";
1840 }
1841 }
1842 else
1843 {
1844 Script += "saga_cmd";
1845 }
1846
1847 //-----------------------------------------------------
1848 Script += Get_Library().Contains(" ") // white space? use quotation marks!
1849 ? " \"" + Get_Library() + "\""
1850 : " " + Get_Library();
1851
1852 Script += Get_ID().Contains (" ") // white space? use quotation marks!
1853 ? " \"" + Get_ID () + "\""
1854 : " " + Get_ID ();
1855
1856 _Get_Script_CMD(Script, Get_Parameters(), bAllArguments, bWrapArgs, bBatch);
1857
1858 for(int i=0; i<Get_Parameters_Count(); i++)
1859 {
1860 _Get_Script_CMD(Script, Get_Parameters(i), bAllArguments, bWrapArgs, bBatch);
1861 }
1862
1863 //-----------------------------------------------------
1864 if( bHeader )
1865 {
1866 Script += bBatch ? "\n\nPAUSE\n" : "\n";
1867 }
1868
1869 return( Script );
1870}
1871
1872//---------------------------------------------------------
1873void CSG_Tool::_Get_Script_CMD(CSG_String &Script, CSG_Parameters *pParameters, bool bAllArguments, bool bWrapArgs, bool bBatch)
1874{
1875 #define GET_ID1(p) (p->Get_Parameters()->Get_Identifier().Length() > 0 \
1876 ? CSG_String::Format("%s_%s", p->Get_Parameters()->Get_Identifier().c_str(), p->Get_Identifier()) \
1877 : CSG_String::Format(p->Get_Identifier())).c_str()
1878
1879 #define GET_ID2(p, s) CSG_String::Format("%s_%s", GET_ID1(p), s).c_str()
1880
1881 const char *Prefix = !bWrapArgs ? " -" : bBatch ? " ^\n -" : " \\\n -";
1882 const char *StrFmt = bBatch ? "%s=\"%s\"" : "%s=\\\"\"%s\"\\\"";
1883
1884 //-----------------------------------------------------
1885 for(int iParameter=0; iParameter<pParameters->Get_Count(); iParameter++)
1886 {
1887 CSG_Parameter *p = pParameters->Get_Parameter(iParameter);
1888
1889 if( !bAllArguments && (!p->is_Enabled(false) || p->is_Information() || !p->do_UseInCMD()) )
1890 {
1891 continue;
1892 }
1893
1894 switch( p->Get_Type() )
1895 {
1896 default:
1897 break;
1898
1899 case PARAMETER_TYPE_Bool :
1900 Script += Prefix + CSG_String::Format("%s=%d", GET_ID1(p), p->asBool() ? 1 : 0);
1901 break;
1902
1903 case PARAMETER_TYPE_Int :
1907 Script += Prefix + CSG_String::Format("%s=%d", GET_ID1(p), p->asInt());
1908 break;
1909
1912 if( p->asString() && *p->asString() )
1913 {
1914 Script += Prefix + CSG_String::Format(StrFmt, GET_ID1(p), p->asString());
1915 }
1916 break;
1917
1919 Script += Prefix + CSG_String::Format("%s=\"%s\"", GET_ID1(p), SG_Color_To_Text(p->asColor()).c_str());
1920 break;
1921
1924 Script += Prefix + CSG_String::Format("%s=%g", GET_ID1(p), p->asDouble());
1925 break;
1926
1928 Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T("MIN")), p->asRange()->Get_Min());
1929 Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T("MAX")), p->asRange()->Get_Max());
1930 break;
1931
1933 if( ((CSG_Parameter_String *)p)->is_Password() )
1934 {
1935 Script += Prefix + CSG_String::Format("%s=\"***\"", GET_ID1(p));
1936 break;
1937 }
1938
1939 case PARAMETER_TYPE_Date :
1940 case PARAMETER_TYPE_Text :
1942 Script += Prefix + CSG_String::Format(StrFmt, GET_ID1(p), p->asString());
1943 break;
1944
1946 Script += Prefix + CSG_String::Format(StrFmt, GET_ID1(p), p->asString());
1947 break;
1948
1950 if( p->Get_Children_Count() == 0 )
1951 {
1952 Script += Prefix + CSG_String::Format("%s=%d", GET_ID2(p, SG_T("NX")), p->asGrid_System()->Get_NX ());
1953 Script += Prefix + CSG_String::Format("%s=%d", GET_ID2(p, SG_T("NY")), p->asGrid_System()->Get_NY ());
1954 Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T( "X")), p->asGrid_System()->Get_XMin ());
1955 Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T( "Y")), p->asGrid_System()->Get_YMin ());
1956 Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T( "D")), p->asGrid_System()->Get_Cellsize());
1957 }
1958 break;
1959
1961 case PARAMETER_TYPE_Grid :
1965 case PARAMETER_TYPE_TIN :
1967 if( p->is_Input() )
1968 {
1969 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"));
1970 }
1971 else
1972 {
1973 CSG_String File(p->Get_Name());
1974
1975 switch( p->Get_DataObject_Type() )
1976 {
1977 case SG_DATAOBJECT_TYPE_Grid : File += ".sg-grd-z"; break;
1978 case SG_DATAOBJECT_TYPE_Grids : File += ".sg-gds-z"; break;
1979 case SG_DATAOBJECT_TYPE_Table : File += ".txt" ; break;
1980 case SG_DATAOBJECT_TYPE_Shapes : File += ".geojson" ; break;
1981 case SG_DATAOBJECT_TYPE_PointCloud: File += ".sg-pts-z"; break;
1982 case SG_DATAOBJECT_TYPE_TIN : File += ".geojson" ; break;
1983 default : File += ".dat" ; break;
1984 }
1985
1986 Script += Prefix + CSG_String::Format(StrFmt, GET_ID1(p), File.c_str());
1987 }
1988 break;
1989
1996 if( p->is_Input() )
1997 {
1998 Script += Prefix + CSG_String::Format("%s=", GET_ID1(p));
1999
2000 if( p->asList()->Get_Item_Count() == 0 )
2001 {
2002 Script += "file(s)";
2003 }
2004 else
2005 {
2006 Script += SG_File_Exists(p->asList()->Get_Item(0)->Get_File_Name())
2007 ? p->asList()->Get_Item(0)->Get_File_Name() : _TL("memory");
2008
2009 for(int iObject=1; iObject<p->asList()->Get_Item_Count(); iObject++)
2010 {
2011 Script += ";";
2012 Script += SG_File_Exists(p->asList()->Get_Item(iObject)->Get_File_Name())
2013 ? p->asList()->Get_Item(iObject)->Get_File_Name() : _TL("memory");
2014 }
2015 }
2016 }
2017 else
2018 {
2019 Script += Prefix + CSG_String::Format(StrFmt, GET_ID1(p), p->Get_Name());
2020 }
2021 break;
2022 }
2023 }
2024}
2025
2026
2028// //
2030
2031//---------------------------------------------------------
2032CSG_String CSG_Tool::_Get_Script_CMD_Usage(void)
2033{
2034 wxCmdLineParser Parser; Parser.SetSwitchChars("-");
2035
2036 _Get_Script_CMD_Usage(Get_Parameters(), Parser);
2037
2038 for(int i=0; i<Get_Parameters_Count(); i++)
2039 {
2040 _Get_Script_CMD_Usage(Get_Parameters(i), Parser);
2041 }
2042
2043 wxString Usage = wxString::Format("\nUsage: saga_cmd %s %s %s", Get_Library().c_str(), Get_ID().c_str(),
2044 Parser.GetUsageString().AfterFirst(' ').AfterFirst(' ')
2045 );
2046
2047 CSG_String _Usage(&Usage);
2048
2049 return( _Usage );
2050}
2051
2052//---------------------------------------------------------
2053void CSG_Tool::_Get_Script_CMD_Usage(CSG_Parameters *pParameters, wxCmdLineParser &Parser)
2054{
2055 for(int i=0; i<pParameters->Get_Count(); i++)
2056 {
2057 CSG_Parameter *pParameter = pParameters->Get_Parameter(i);
2058
2059 //-------------------------------------------------
2060 if( pParameter->is_DataObject() ) // reset data object parameters, avoids problems when tool is called more than once without un-/reloading
2061 {
2062 pParameter->Set_Value(DATAOBJECT_NOTSET);
2063 }
2064 else if( pParameter->is_DataObject_List() )
2065 {
2066 pParameter->asList()->Del_Items();
2067 }
2068
2069 //-------------------------------------------------
2070 if( pParameter->do_UseInCMD() == false )
2071 {
2072 continue;
2073 }
2074
2075 wxString Description = pParameter->Get_Description(
2077 ).c_str();
2078
2079 Description.Replace("\xb", ""); // unicode problem: quick'n'dirty bug fix, to be replaced
2080
2081 wxString ID(pParameter->Get_CmdID().c_str());
2082
2083 if( pParameter->is_Input() || pParameter->is_Output() )
2084 {
2085 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_NEEDS_SEPARATOR|wxCMD_LINE_PARAM_OPTIONAL);
2086 }
2087
2088 //-------------------------------------------------
2089 else if( pParameter->is_Option() && !pParameter->is_Information() )
2090 {
2091 switch( pParameter->Get_Type() )
2092 {
2094 _Get_Script_CMD_Usage(pParameter->asParameters(), Parser);
2095 break;
2096
2097 case PARAMETER_TYPE_Bool :
2098 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2099 break;
2100
2101 case PARAMETER_TYPE_Int :
2102 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
2103 break;
2104
2110 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2111 break;
2112
2115 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2116 break;
2117
2118 case PARAMETER_TYPE_Date :
2119 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_DATE , wxCMD_LINE_PARAM_OPTIONAL);
2120 break;
2121
2123 Parser.AddOption(ID + "_MIN", wxEmptyString, Description, wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2124 Parser.AddOption(ID + "_MAX", wxEmptyString, Description, wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2125 break;
2126
2128 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2129 break;
2130
2132 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2133 break;
2134
2136 case PARAMETER_TYPE_Text :
2138 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2139 break;
2140
2142 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2143 break;
2144
2146 if( pParameter->Get_Children_Count() == 0 )
2147 {
2148 Parser.AddOption(ID + "_D" , wxEmptyString, _TL("Cell Size" ), wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2149 Parser.AddOption(ID + "_X" , wxEmptyString, _TL("Lower Left Center Cell X-Coordinate"), wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2150 Parser.AddOption(ID + "_Y" , wxEmptyString, _TL("Lower Left Center Cell Y-Coordinate"), wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2151 Parser.AddOption(ID + "_NX" , wxEmptyString, _TL("Number of Columns" ), wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
2152 Parser.AddOption(ID + "_NY" , wxEmptyString, _TL("Number of Rows" ), wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
2153 Parser.AddOption(ID + "_FILE", wxEmptyString, _TL("Grid File" ), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2154 }
2155 break;
2156
2157 default:
2158 break;
2159 }
2160 }
2161 }
2162}
2163
2164
2166// //
2168
2169//---------------------------------------------------------
2170CSG_String CSG_Tool::_Get_Script_Python(bool bHeader, bool bAllArguments)
2171{
2172 CSG_String Script, Name(Get_Name());
2173
2174 Name.Replace(" ", "_");
2175 Name.Replace("(", "");
2176 Name.Replace(")", "");
2177 Name.Replace("[", "");
2178 Name.Replace("]", "");
2179 Name.Replace(".", "");
2180 Name.Replace(",", "");
2181 Name.Replace("/", "");
2182 Name.Replace("-", "");
2183
2184 //-----------------------------------------------------
2185 if( bHeader )
2186 {
2187 Script += "#! /usr/bin/env python\n";
2188 Script += "\n";
2189 Script += "#_________________________________________\n";
2190 Script += "##########################################\n";
2191 Script += "\n";
2192#ifdef _SAGA_MSW
2193 CSG_String AppPath = SG_UI_Get_Application_Path(true); AppPath.Replace("\\", "/");
2194 Script += "# Initialize the environment...\n";
2195 Script += "\n";
2196 Script += "# Windows: Let the 'SAGA_PATH' environment variable point to\n";
2197 Script += "# the SAGA installation folder before importing 'saga_api'!\n";
2198 Script += "# This can be defined globally in the Windows system or\n";
2199 Script += "# user environment variable settings, in the 'PySAGA/__init__.py'\n";
2200 Script += "# file, or in the individual Python script itself. To do the latter\n";
2201 Script += "# just uncomment the following line and adjust the path accordingly:\n";
2202 Script += "###import os; os.environ['SAGA_PATH'] = '" + AppPath + "'\n";
2203 Script += "\n";
2204 Script += "# Windows: The most convenient way to make PySAGA available to all your\n";
2205 Script += "# Python scripts is to copy the PySAGA folder to the 'Lib/site-packages/'\n";
2206 Script += "# folder of your Python installation. If don't want to do this or if you\n";
2207 Script += "# don't have the rights to do so, you can also copy it to the folder with\n";
2208 Script += "# the Python scripts in which you want to use PySAGA, or alternatively\n";
2209 Script += "# you can add the path containing the PySAGA folder (e.g. the path to your\n";
2210 Script += "# SAGA installation) to the PYTHONPATH environment variable. To do this\n";
2211 Script += "# from within your script you can also take the following command (just\n";
2212 Script += "# uncomment the following line and adjust the path accordingly):\n";
2213 Script += "###import sys; sys.path.insert(1, '" + AppPath + "')\n";
2214 Script += "\n";
2215#endif // _SAGA_MSW
2216 Script += "# Import saga_api from PySAGA:\n";
2217 Script += "from PySAGA import saga_api\n";
2218 Script += "\n";
2219 Script += "\n";
2220 Script += "#_________________________________________\n";
2221 Script += "##########################################\n";
2222 Script += "def Run_" + Name + "(Results):\n";
2223 }
2224
2225 //-----------------------------------------------------
2226 if( bHeader ) Script += " # Get the tool:\n";
2227 Script += " Tool = saga_api.SG_Get_Tool_Library_Manager().Get_Tool('" + Get_Library() + "', '" + Get_ID() + "')\n";
2228 Script += " if not Tool:\n";
2229 Script += " saga_api.SG_UI_Msg_Add_Error('Failed to request tool: " + Get_Name() + "')\n";
2230 Script += " return False\n";
2231 Script += "\n";
2232 if( bHeader ) Script += " # Set the parameter interface:\n";
2233 Script += " Tool.Reset()\n";
2234
2235 //-------------------------------------------------
2236 _Get_Script_Python(Script, Get_Parameters(), bAllArguments);
2237
2238 for(int iParameters=0; iParameters<Get_Parameters_Count(); iParameters++)
2239 {
2240 _Get_Script_Python(Script, Get_Parameters(iParameters), bAllArguments, Get_Parameters(iParameters)->Get_Identifier());
2241 }
2242
2243 //-------------------------------------------------
2244 Script += "\n";
2245 if( bHeader ) Script += " # Execute the tool:\n";
2246 Script += " if not Tool.Execute():\n";
2247 Script += " saga_api.SG_UI_Msg_Add_Error('failed to execute tool: ' + Tool.Get_Name().c_str())\n";
2248 Script += " return False\n";
2249 Script += "\n";
2250 if( bHeader ) Script += " # Request the results:\n";
2251
2252 for(int iParameter=0; iParameter<Get_Parameters()->Get_Count(); iParameter++)
2253 {
2254 CSG_Parameter *p = Get_Parameters()->Get_Parameter(iParameter);
2255
2256 if( p->is_Output() )
2257 {
2258 CSG_String id(p->Get_Identifier()), type, ext;
2259
2260 switch( p->Get_DataObject_Type() )
2261 {
2262 case SG_DATAOBJECT_TYPE_Grid : type = "Grid" ; ext = "sg-grd-z"; break;
2263 case SG_DATAOBJECT_TYPE_Grids : type = "Grids" ; ext = "sg-gds-z"; break;
2264 case SG_DATAOBJECT_TYPE_Table : type = "Table" ; ext = "txt" ; break;
2265 case SG_DATAOBJECT_TYPE_Shapes : type = "Shapes" ; ext = "geojson" ; break;
2266 case SG_DATAOBJECT_TYPE_PointCloud: type = "PointCloud"; ext = "sg-pts-z"; break;
2267 case SG_DATAOBJECT_TYPE_TIN : type = "TIN" ; ext = "geojson" ; break;
2268 default : type = "" ; ext = "" ; break;
2269 }
2270
2271 if( p->is_DataObject() )
2272 {
2273 Script += " Data = Tool.Get_Parameter('" + id + "').as" + type + "()\n";
2274
2275 if( bHeader )
2276 {
2277 Script += " Data.Save('{:s}/{:s}.{:s}'.format(Results, Data.Get_Name(), '" + ext + "'))\n\n";
2278 }
2279 }
2280 else if( p->is_DataObject_List() )
2281 {
2282 Script += " List = Tool.Get_Parameter('" + id + "').as" + type + "List()\n";
2283 Script += " for i in range(0, List.Get_Item_Count()):\n";
2284
2285 if( bHeader )
2286 {
2287 Script += " List.Get_Item(i).Save('{:s}/{:s}_{:d}.{:s}'.format(Results, List.Get_Name(), i, '" + ext + "'))\n\n";
2288 }
2289 else
2290 {
2291 Script += " Data = List.Get_Item(i)\n";
2292 }
2293 }
2294 }
2295 }
2296
2297 //-----------------------------------------------------
2298 if( bHeader )
2299 {
2300 Script += " # job is done, free memory resources:\n";
2301 Script += " saga_api.SG_Get_Data_Manager().Delete_All()\n";
2302 Script += "\n";
2303 Script += " return True\n";
2304 Script += "\n";
2305 Script += "\n";
2306 Script += "#_________________________________________\n";
2307 Script += "##########################################\n";
2308 Script += "print('This is a simple template for using a SAGA tool through Python.')\n";
2309 Script += "print('Please edit the script to make it work properly before using it!')\n";
2310 Script += "\n";
2311 Script += "# Run_" + Name + "('.')\n";
2312 }
2313
2314 return( Script );
2315}
2316
2317//---------------------------------------------------------
2318void CSG_Tool::_Get_Script_Python(CSG_String &Script, CSG_Parameters *pParameters, bool bAllArguments, const CSG_String &Prefix)
2319{
2320 for(int iParameter=0; iParameter<pParameters->Get_Count(); iParameter++)
2321 {
2322 CSG_Parameter *p = pParameters->Get_Parameter(iParameter);
2323
2324 if( !bAllArguments && (!p->is_Enabled(false) || p->is_Information() || !p->do_UseInCMD()) )
2325 {
2326 continue;
2327 }
2328
2329 CSG_String ID(p->Get_Identifier());
2330
2331 if( !Prefix.is_Empty() )
2332 {
2333 ID.Prepend(Prefix + ".");
2334 }
2335
2336 switch( p->Get_Type() )
2337 {
2338 default:
2339 break;
2340
2341 case PARAMETER_TYPE_Bool :
2342 Script += CSG_String::Format(" Tool.Set_Parameter('%s', %s)\n", ID.c_str(), p->asBool() ? SG_T("True") : SG_T("False"));
2343 break;
2344
2345 case PARAMETER_TYPE_Int :
2346 Script += CSG_String::Format(" Tool.Set_Parameter('%s', %d)\n", ID.c_str(), p->asInt());
2347 break;
2348
2351 Script += CSG_String::Format(" Tool.Set_Parameter('%s', %d) # '%s'\n", ID.c_str(), p->asInt(), p->asString());
2352 break;
2353
2357 Script += CSG_String::Format(" Tool.Set_Parameter('%s', '%s')\n", ID.c_str(), p->asString());
2358 break;
2359
2361 Script += CSG_String::Format(" Tool.Set_Parameter('%s', '%s')\n", ID.c_str(), SG_Color_To_Text(p->asColor()).c_str());
2362 break;
2363
2366 Script += CSG_String::Format(" Tool.Set_Parameter('%s', %g)\n", ID.c_str(), p->asDouble());
2367 break;
2368
2370 Script += CSG_String::Format(" Tool.Set_Parameter('%s.MIN', %g)\n", ID.c_str(), p->asRange()->Get_Min());
2371 Script += CSG_String::Format(" Tool.Set_Parameter('%s.MAX', %g)\n", ID.c_str(), p->asRange()->Get_Max());
2372 break;
2373
2375 if( ((CSG_Parameter_String *)p)->is_Password() )
2376 {
2377 Script += CSG_String::Format(" Tool.Set_Parameter('%s', '***')\n", ID.c_str());
2378 break;
2379 }
2380
2381 case PARAMETER_TYPE_Date :
2382 case PARAMETER_TYPE_Text :
2384 Script += CSG_String::Format(" Tool.Set_Parameter('%s', '%s')\n", ID.c_str(), p->asString());
2385 break;
2386
2388 Script += CSG_String::Format(" Tool.Set_Parameter('%s', saga_api.SG_Create_Table('table.txt'))\n", ID.c_str());
2389 break;
2390
2392 if( p->Get_Children_Count() == 0 )
2393 {
2394 Script += CSG_String::Format(" Tool.Set_Parameter('%s', saga_api.CSG_Grid_System(%g, %g, %g, %d, %d))\n", ID.c_str(),
2397 p->asGrid_System()->Get_NX (), p->asGrid_System()->Get_NY ()
2398 );
2399 }
2400 break;
2401
2402 case PARAMETER_TYPE_Grid :
2406 case PARAMETER_TYPE_TIN :
2408 if( p->is_Input() )
2409 {
2410 Script += CSG_String::Format(" Tool.Set_Parameter('%s', saga_api.SG_Get_Data_Manager().Add('%s input file%s'))\n", ID.c_str(),
2411 SG_Get_DataObject_Name(p->Get_DataObject_Type()).c_str(), p->is_Optional() ? SG_T(", optional") : SG_T("")
2412 );
2413 }
2414 else if( p->is_Output() && p->is_Optional() )
2415 {
2416 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());
2417 }
2418 break;
2419
2426 if( p->is_Input() )
2427 {
2428 Script += CSG_String::Format(" Tool.Get_Parameter('%s').asList().Add_Item('%s input list%s')\n", ID.c_str(),
2429 SG_Get_DataObject_Name(p->Get_DataObject_Type()).c_str(), p->is_Optional() ? SG_T(", optional") : SG_T("")
2430 );
2431 }
2432 break;
2433
2435 _Get_Script_Python(Script, p->asParameters(), bAllArguments, ID);
2436 break;
2437 }
2438 }
2439}
2440
2441
2443// //
2445
2446//---------------------------------------------------------
2447CSG_String CSG_Tool::_Get_Script_Python_Wrap(bool bHeader, bool bName, bool bCall, int AllArguments, bool bWrapArgs)
2448{
2449 CSG_String Arguments, Description, Code;
2450
2451 if( AllArguments >= 0 ) // if( AllArguments < 0 ) => skip arguments list
2452 {
2453 for(int i=0; i<Parameters.Get_Count(); i++) // add input that is not optional in 1st place
2454 {
2455 _Get_Script_Python_Wrap(Parameters[i], PARAMETER_INPUT , Arguments, Description, Code, bCall && bHeader, AllArguments == 0, bWrapArgs);
2456 }
2457
2458 for(int i=0; i<Parameters.Get_Count(); i++) // add optional input in 2nd place
2459 {
2460 _Get_Script_Python_Wrap(Parameters[i], PARAMETER_INPUT_OPTIONAL, Arguments, Description, Code, bCall && bHeader, AllArguments == 0, bWrapArgs);
2461 }
2462
2463 for(int i=0; i<Parameters.Get_Count(); i++) // add output
2464 {
2465 _Get_Script_Python_Wrap(Parameters[i], PARAMETER_OUTPUT , Arguments, Description, Code, bCall && bHeader, AllArguments == 0, bWrapArgs);
2466 }
2467
2468 for(int i=0; i<Parameters.Get_Count(); i++) // add options
2469 {
2470 _Get_Script_Python_Wrap(Parameters[i], 0 , Arguments, Description, Code, bCall , AllArguments == 0, bWrapArgs);
2471 }
2472 }
2473
2474 //---------------------------------------------------------
2475 CSG_String Name, Expected(Get_Name()); Expected.Replace("'", "\\'");
2476
2477 if( bName )
2478 {
2479 Name = Get_Name();
2480
2481 if( isdigit(Name[0]) ) // ...in case first letter is a numeric character, what is not allowed for Python function names!
2482 {
2483 Name.Prepend("_");
2484 }
2485
2486 Name.Replace(" ", "_");
2487 Name.Replace("(", "");
2488 Name.Replace(")", "");
2489 Name.Replace("[", "");
2490 Name.Replace("]", "");
2491 Name.Replace(".", "");
2492 Name.Replace(",", "");
2493 Name.Replace("/", "");
2494 Name.Replace("-", "");
2495 Name.Replace("'", "");
2496 Name.Replace("&", "and");
2497 }
2498 else
2499 {
2500 Name = "run_tool_" + Get_Library() + "_" + Get_ID();
2501
2502 Name.Replace(" ", "_");
2503 }
2504
2505 //---------------------------------------------------------
2506 CSG_String Script;
2507
2508 if( bCall )
2509 {
2510 if( bHeader )
2511 {
2512 Script += "from PySAGA.tools import " + Get_Library() + "\n\n";
2513
2514 if( !Code.is_Empty() )
2515 {
2516 Script += Code + "\n";
2517 }
2518 }
2519
2520 Script += Get_Library() + '.' + Name + "(" + Arguments + ")\n";
2521 }
2522 else
2523 {
2525
2526 if( bHeader )
2527 {
2528 Script += "#! /usr/bin/env python\n";
2529 Script += "from PySAGA.helper import Tool_Wrapper\n\n";
2530 }
2531
2532 Script += "def " + Name + "(" + Arguments + ", Verbose=2):\n";
2533 Script += " '''\n";
2534 Script += " " + Get_Name() + "\n";
2535 Script += " ----------\n";
2536 Script += " [" + Get_Library() + "." + Get_ID() + "]\\n\n";
2537 for(int i=0; i<_Description.Get_Count(); i++)
2538 {
2539 _Description[i].Trim_Both(); Script += " " + _Description[i] + "\\n\n";
2540 }
2541 Script += " Arguments\n";
2542 Script += " ----------\n";
2543 Script += Description + "\n";
2544 Script += " - Verbose [`integer number`] : Verbosity level, 0=silent, 1=tool name and success notification, 2=complete tool output.\\n\n";
2545 Script += " Returns\n";
2546 Script += " ----------\n";
2547 Script += " `boolean` : `True` on success, `False` on failure.\n";
2548 Script += " '''\n";
2549 Script += " Tool = Tool_Wrapper('" + Get_Library() + "', '" + Get_ID() + "', '" + Expected + "')\n";
2550 Script += " if Tool.is_Okay():\n";
2551 Script += Code;
2552 Script += " return Tool.Execute(Verbose)\n";
2553 Script += " return False\n\n";
2554 }
2555
2556 return( Script );
2557}
2558
2559//---------------------------------------------------------
2560bool 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)
2561{
2562 if( Parameter.do_UseInCMD() == false
2563 || Parameter.is_Information()
2564 || Parameter.Get_Type() == PARAMETER_TYPE_Node
2565 || Parameter.Cmp_Identifier("PARAMETERS_GRID_SYSTEM") )
2566 {
2567 return( false );
2568 }
2569
2570 if( bCall && !Parameter.is_Enabled() && !(Parameter.is_Output() && Parameter.Get_Parent() && Parameter.Get_Parent()->Cmp_Identifier("TARGET_SYSTEM")) )
2571 {
2572 return( false );
2573 }
2574
2575 //-----------------------------------------------------
2576 CSG_String ID(Parameter.Get_Identifier());
2577
2578 if( !Prefix.is_Empty() )
2579 {
2580 ID.Prepend(Prefix + ".");
2581 }
2582
2583 CSG_String Argument(ID);
2584
2585 if( Argument[0] >= '0' && Argument[0] <= '9' )
2586 {
2587 Argument.Prepend('_');
2588 }
2589
2590 Argument.Replace(".", "_");
2591 Argument.Replace("|", "_");
2592 Argument.Replace(" ", "_");
2593
2594 if( Argument.Length() > 2 )
2595 {
2596 Argument.Make_Upper();
2597 }
2598
2599 //-----------------------------------------------------
2600 if( Parameter.asParameters() ) // PARAMETER_TYPE_Parameters
2601 {
2602 bool bResult = false;
2603
2604 for(int i=0; i<(*Parameter.asParameters()).Get_Count(); i++)
2605 {
2606 if( _Get_Script_Python_Wrap((*Parameter.asParameters())[i], Constraint, Arguments, Description, Code, bCall, bOnlyNonDefaults, bWrapArgs, ID) )
2607 {
2608 bResult = true;
2609 }
2610 }
2611
2612 return( bResult );
2613 }
2614
2615 //-----------------------------------------------------
2616 if( Parameter.is_Input () && !Parameter.is_Optional() && Constraint != PARAMETER_INPUT ) { return( false ); }
2617 if( Parameter.is_Input () && Parameter.is_Optional() && Constraint != PARAMETER_INPUT_OPTIONAL ) { return( false ); }
2618 if( Parameter.is_Output() && Constraint != PARAMETER_OUTPUT ) { return( false ); }
2619 if( Parameter.is_Option() && Constraint != 0 ) { return( false ); }
2620
2621 //-----------------------------------------------------
2622 if( bCall )
2623 {
2624 CSG_String Value;
2625
2626 if( Parameter.is_DataObject() )
2627 {
2628 Value = Parameter.Get_Identifier(); Value.Make_Lower();
2629
2630 if( Parameter.is_Input() )
2631 {
2632 if( (bOnlyNonDefaults && !Parameter.asDataObject()) && Parameter.is_Optional() ) // don't add optional input that has not been set
2633 {
2634 return( false );
2635 }
2636
2637 CSG_String File(Parameter.asDataObject() && Parameter.asDataObject()->Get_File_Name(false)
2638 ? Parameter.asDataObject()->Get_File_Name(false) : SG_T("data object file")
2639 ); File.Replace("\\", "/");
2640
2641 Code += Value + " = saga_api.SG_Get_Data_Manager().Add_" + SG_Get_DataObject_Class_Name(Parameter.Get_DataObject_Type()).AfterFirst('_') + "('" + File + "') # input data object\n";
2642 }
2643 else // if( Parameter.is_Output() )
2644 {
2645 if( (bOnlyNonDefaults && !Parameter.asDataObject()) && Parameter.is_Optional() ) // don't add optional output that has not been requested
2646 {
2647 return( false );
2648 }
2649
2650 Code += Value + " = saga_api.SG_Get_Data_Manager().Add_" + SG_Get_DataObject_Class_Name(Parameter.Get_DataObject_Type()).AfterFirst('_') + "() # output data object\n";
2651 }
2652 }
2653 else if( Parameter.is_DataObject_List() )
2654 {
2655 Value = Parameter.Get_Identifier(); Value.Make_Lower();
2656
2657 if( Parameter.is_Input() )
2658 {
2659 if( (bOnlyNonDefaults && Parameter.asList()->Get_Item_Count() < 1) && Parameter.is_Optional() ) // don't add optional input that has not been set
2660 {
2661 return( false );
2662 }
2663
2664 Code += Value + " = [] # Python list with input data objects of type 'saga_api." + SG_Get_DataObject_Class_Name(Parameter.Get_DataObject_Type()) + "'\n";
2665 }
2666 else // if( Parameter.is_Output() )
2667 {
2668 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";
2669 }
2670 }
2671 else if( Parameter.is_Option() )
2672 {
2673 if( bOnlyNonDefaults && Parameter.is_Default() )
2674 {
2675 return( false );
2676 }
2677
2678 switch( Parameter.Get_Type() )
2679 {
2680 case PARAMETER_TYPE_Bool : Value = Parameter.asBool() ? "True" : "False"; break;
2681
2682 case PARAMETER_TYPE_Int : Value.Printf("%d", Parameter.asInt()); break;
2683
2685 case PARAMETER_TYPE_Degree : Value.Printf("%f", Parameter.asDouble()); break;
2686
2687 case PARAMETER_TYPE_Color : Value = SG_Color_To_Text(Parameter.asColor()); break;
2688
2690 case PARAMETER_TYPE_Text :
2691 case PARAMETER_TYPE_Date :
2698 case PARAMETER_TYPE_FilePath : Value.Printf("'%s'", Parameter.asString()); break;
2699
2701 if( !Parameter.Cmp_Identifier("TARGET_SYSTEM") )
2702 {
2703 return( false );
2704 }
2705
2706 Value.Printf("'%s'", Parameter.asGrid_System()->asString());
2707 break;
2708
2709 default : return( false );
2710 }
2711 }
2712
2713 if( !Value.is_Empty() )
2714 {
2715 if( bWrapArgs )
2716 {
2717 Arguments += !Arguments.is_Empty() ? ",\n " : "\n ";
2718 }
2719 else if( !Arguments.is_Empty() )
2720 {
2721 Arguments += ", ";
2722 }
2723
2724 Arguments += Argument + "=" + Value;
2725 }
2726
2727 return( true );
2728 }
2729
2730 //-----------------------------------------------------
2731 if( bWrapArgs )
2732 {
2733 Arguments += !Arguments.is_Empty() ? ",\n " : "\n ";
2734 }
2735 else if( !Arguments.is_Empty() )
2736 {
2737 Arguments += ", ";
2738 }
2739
2740 Arguments += Argument + "=None";
2741
2742 //-----------------------------------------------------
2743 Code += " ";
2744
2745 if( Parameter.is_Input () ) { Code += "Tool.Set_Input "; }
2746 if( Parameter.is_Output() ) { Code += "Tool.Set_Output"; }
2747 if( Parameter.is_Option() ) { Code += "Tool.Set_Option"; }
2748
2749 Code += CSG_String::Format("('%s', %s)\n", ID.c_str(), Argument.c_str());
2750
2751 //-----------------------------------------------------
2752 Description += " - " + Argument + " [`";
2753
2754 if( Parameter.is_Input() )
2755 {
2756 Description += Parameter.is_Optional() ? "optional input " : "input ";
2757 }
2758 else if( Parameter.is_Output() )
2759 {
2760 Description += "output ";
2761 }
2762
2763 Description += Parameter.Get_Type_Name() + "`] : " + Parameter.Get_Name();
2764
2766
2767 if( !s.is_Empty() )
2768 {
2769 Description += ". " + s;
2770 }
2771
2772 Description += "\n";
2773
2774 return( true );
2775}
2776
2778// //
2780
2781//---------------------------------------------------------
2782CSG_String CSG_Tool::_Get_Script_Markdown(bool bHeader, int iArguments)
2783{
2784 CSG_String Script;
2785
2786 if( bHeader )
2787 {
2788 CSG_String Menu = Get_MenuPath(true); Menu.Replace("|", " &rarr; ");
2789 CSG_Tool_Library *pLibrary = SG_Get_Tool_Library_Manager().Get_Library(this);
2790 CSG_String Category = pLibrary->Get_Category() + " &rarr; " + pLibrary->Get_Name();
2791
2792 Script += CSG_String::Format("**Tool:** %s \n", Get_Name().c_str());
2793 Script += CSG_String::Format("**Geoprocessing** &rarr; *%s*&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp; **Tools** &rarr; *%s*\n\n", Menu.c_str(), Category.c_str());
2794 }
2795
2796 Script += "|**Parameter**|**Setting**|\n";
2797 Script += "|---|---|\n";
2798
2799 //-------------------------------------------------
2800 _Get_Script_Markdown(Script, Get_Parameters(), iArguments);
2801
2802 Script.Replace("\n\n", "\n");
2803
2804 return( Script );
2805}
2806
2807
2808//---------------------------------------------------------
2809void CSG_Tool::_Get_Script_Markdown(CSG_String &Script, CSG_Parameters *pParameters, int iArguments, const CSG_String &Prefix)
2810{
2811 #define WRITE_CHILD(pChild, Prefix) Script += CSG_String::Format("|%s%s||\n", Prefix.c_str(), pChild->Get_Name().c_str());\
2812 for (int i=0; i<pChild->Get_Children_Count(); i++)\
2813 {\
2814 Script += CSG_String::Format("%s\n", pChild->Get_Child(i)->Get_Content().c_str());\
2815 }
2816
2817 CSG_MetaData Properties;
2818
2819 for(int iParameter=0; iParameter<pParameters->Get_Count(); iParameter++)
2820 {
2821 _Format_Markdown(pParameters->Get_Parameter(iParameter), Script, Properties, iArguments, Prefix);
2822 }
2823
2824 if( CSG_MetaData *pChild = Properties.Get_Child(_TL("Data Objects")) ) { WRITE_CHILD(pChild, Prefix); }
2825
2826 for (int i=0; i<Properties.Get_Children_Count(); i++)
2827 {
2828 CSG_MetaData *pChild = Properties.Get_Child(i);
2829
2830 if( pChild->Get_Name().Cmp(_TL("Data Objects")) && pChild->Get_Name().Cmp(_TL("Options")) )
2831 {
2832 WRITE_CHILD(pChild, Prefix);
2833 }
2834 }
2835
2836 if( CSG_MetaData *pChild = Properties.Get_Child(_TL("Options")) ) { WRITE_CHILD(pChild, Prefix); }
2837}
2838
2839
2840//---------------------------------------------------------
2841void CSG_Tool::_Format_Markdown(CSG_Parameter *p, CSG_String &Script, CSG_MetaData &Properties, int iArguments, CSG_String Prefix)
2842{
2843 #define CHECK_OBJECTS_NODE() pChild = Properties.Get_Child(_TL("Options"));\
2844 if( !pChild )\
2845 {\
2846 pChild = Properties.Add_Child(_TL("Options"));\
2847 }\
2848 \
2849 pRoot = pChild;
2850
2851 #define CHECK_DATA_NODE(Name) pChild = Properties.Get_Child(Name);\
2852 if( !pChild )\
2853 {\
2854 CSG_MetaData *pData = Properties.Get_Child(_TL("Data Objects"));\
2855 if( !pData )\
2856 {\
2857 Properties.Add_Child(_TL("Data Objects"));\
2858 }\
2859 pChild = Properties.Add_Child(Name);\
2860 }\
2861 \
2862 pRoot = pChild;
2863
2864 #define GET_PARENT_NODE(prt) bool bFound = false;\
2865 for (int i=0; i<Properties.Get_Children_Count(); i++)\
2866 {\
2867 CSG_MetaData *pDatatype = Properties.Get_Child(i);\
2868 for (int j=0; j<Properties.Get_Children_Count(); j++)\
2869 {\
2870 pParent = pDatatype->Get_Child(prt);\
2871 if( pParent )\
2872 {\
2873 bFound = true;\
2874 break;\
2875 }\
2876 }\
2877 if( bFound )\
2878 {\
2879 break;\
2880 }\
2881 }
2882
2883 #define FORMAT_DATASET() if( p->is_Input() )\
2884 {\
2885 CSG_String Input = p->is_Optional() ? ">" : ">>";\
2886 CSG_String s = p->asString();\
2887 if( s.Contains(_TL("not set")) || s.Contains(_TL("No objects")) ) { Bold = ""; }\
2888 s.Replace("<", "\\<");\
2889 Parameter = CSG_String::Format("|%s%s %s%s%s|%s%s%s|", Space.c_str(), Input.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), s.c_str(), Bold.c_str());\
2890 }\
2891 else if( p->is_Output() )\
2892 {\
2893 CSG_String Output = p->is_Optional() ? "\\<" : "<<";\
2894 CSG_String s = p->asString();\
2895 if( !p->is_Optional() && s.Contains(_TL("create")) ) { Bold = ""; }\
2896 else if( p->is_Optional() && (s.Contains(_TL("not set")) || s.Contains(_TL("No objects"))) ) { Bold = ""; }\
2897 s.Replace("<", "\\<");\
2898 Parameter = CSG_String::Format("|%s%s %s%s%s|%s%s%s|", Space.c_str(), Output.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), s.c_str(), Bold.c_str());\
2899 }
2900
2901 if( iArguments == 0 && !p->do_UseInCMD() )
2902 {
2903 return;
2904 }
2905 else if( iArguments == 1 && !p->do_UseInGUI() )
2906 {
2907 return;
2908 }
2909
2910 if( !p->is_Enabled(false) )
2911 {
2912 return;
2913 }
2914
2915 CSG_String Name(p->Get_Name());
2916
2917 CSG_String Bold;
2918
2919 if( !p->is_Default() )
2920 {
2921 Bold = "**";
2922 }
2923
2924 CSG_String Space = Prefix;
2925
2926 if( p->Get_Parent() != NULL )
2927 {
2928 Space += "&nbsp;&nbsp;&nbsp;";
2929 }
2930
2931 CSG_String Parameter;
2932 CSG_MetaData *pRoot = NULL, *pChild;
2933
2934 switch( p->Get_Type() )
2935 {
2936 default:
2937 break;
2938
2940 {
2941 if( p->Get_Parent() )
2942 {
2944 }
2945 else if( p->Get_Children_Count() == 0 )
2946 {
2947 CHECK_DATA_NODE(_TL("Grids"));
2948 }
2949 else for (int i=0; i<p->Get_Children_Count() && !pRoot; i++)
2950 {
2953 || p->Get_Child(i)->is_Input() )
2954 {
2955 CHECK_DATA_NODE(_TL("Grids"));
2956 }
2957 }
2958
2959 CSG_String s = p->asString();
2960 if( s.Contains(_TL("not set")) )
2961 {
2962 s.Replace("<", "\\<");
2963 Parameter += CSG_String::Format("|%s%s|%s|", Space.c_str(), Name.c_str(), s.c_str());
2964 }
2965 else
2966 {
2967 Parameter += CSG_String::Format("|%s%s%s%s|%s%g; %dx, %dy; %.0f...x %.0f...y%s|", Space.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(),
2969 p->asGrid_System()->Get_NX (), p->asGrid_System()->Get_NY (),
2971 Bold.c_str()
2972 );
2973 }
2974 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
2975 break;
2976 }
2977
2980 if( p->is_Input() )
2981 {
2982 if( !p->Get_Parent() || (p->Get_Parent()->Get_Type() == PARAMETER_TYPE_Grid_System && !p->Get_Parent()->Get_Parent()) )
2983 {
2984 CHECK_DATA_NODE(_TL("Grids"));
2985 }
2986 else
2987 {
2989 }
2991 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
2992 }
2993 break;
2994
2995 case PARAMETER_TYPE_Grid :
2997 if( !p->Get_Parent() || (p->Get_Parent()->Get_Type() == PARAMETER_TYPE_Grid_System && !p->Get_Parent()->Get_Parent()) )
2998 {
2999 CHECK_DATA_NODE(_TL("Grids"));
3000 }
3001 else
3002 {
3004 }
3006 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3007 break;
3008
3010 if( p->is_Input() )
3011 {
3012 if( !p->Get_Parent() )
3013 {
3014 CHECK_DATA_NODE(_TL("Tables"));
3015 }
3016 else
3017 {
3019 }
3021 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3022 }
3023 break;
3024
3026 if( !p->Get_Parent() )
3027 {
3028 CHECK_DATA_NODE(_TL("Tables"));
3029 }
3030 else
3031 {
3033 }
3035 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3036 break;
3037
3039 if( p->is_Input() )
3040 {
3041 if( !p->Get_Parent() )
3042 {
3043 CHECK_DATA_NODE(_TL("Shapes"));
3044 }
3045 else
3046 {
3048 }
3050 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3051 }
3052 break;
3053
3055 if( !p->Get_Parent() )
3056 {
3057 CHECK_DATA_NODE(_TL("Shapes"));
3058 }
3059 else
3060 {
3062 }
3064 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3065 break;
3066
3068 if( p->is_Input() )
3069 {
3070 if( !p->Get_Parent() )
3071 {
3072 CHECK_DATA_NODE(_TL("TIN"));
3073 }
3074 else
3075 {
3077 }
3079 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3080 }
3081 break;
3082
3083 case PARAMETER_TYPE_TIN :
3084 if( !p->Get_Parent() )
3085 {
3086 CHECK_DATA_NODE(_TL("TIN"));
3087 }
3088 else
3089 {
3091 }
3093 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3094 break;
3095
3097 if( p->is_Input() )
3098 {
3099 if( !p->Get_Parent() )
3100 {
3101 CHECK_DATA_NODE(_TL("Point Clouds"));
3102 }
3103 else
3104 {
3106 }
3108 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3109 }
3110 break;
3111
3113 if( !p->Get_Parent() )
3114 {
3115 CHECK_DATA_NODE(_TL("Point Clouds"));
3116 }
3117 else
3118 {
3120 }
3122 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3123 break;
3124
3125 case PARAMETER_TYPE_Node :
3127 Parameter = CSG_String::Format("|%s%s||", Space.c_str(), Name.c_str());
3128 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3129 break;
3130
3131 case PARAMETER_TYPE_Bool :
3133 Parameter = CSG_String::Format("|%s%s%s%s|%s%s%s|", 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());
3134 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3135 break;
3136
3137 case PARAMETER_TYPE_Int :
3139 Parameter = CSG_String::Format("|%s%s%s%s|%s%d%s|", Space.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), p->asInt(), Bold.c_str());
3140 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3141 break;
3142
3145 {
3147 CSG_String s = p->asString();
3148 if( s.Contains(_TL("no choice available")) ) { Bold = ""; }
3149 s.Replace("<", "\\<");
3150 Parameter = CSG_String::Format("|%s%s%s%s|%s%s%s|", Space.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), s.c_str(), Bold.c_str());
3151 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3152 break;
3153 }
3154
3156 {
3157 CSG_String s = p->asString();
3158 if( s.Contains(_TL("no attributes")) ) { Bold = ""; }
3159 s.Replace("<", "\\<");
3160 Parameter = CSG_String::Format("|%s%s%s%s|%s%s%s|", Space.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), s.c_str(), Bold.c_str());
3161 if( p->Get_Parent() != NULL && (p->Get_Parent()->is_DataObject() || p->Get_Parent()->is_DataObject_List()) )
3162 {
3163 CSG_MetaData *pParent = NULL;
3165 if( pParent )
3166 {
3167 CSG_String c = pParent->Get_Content();
3168 c += SG_T("\n") + Parameter;
3169 pParent->Set_Content(c);
3170 }
3171 }
3172 else
3173 {
3175 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3176 }
3177 break;
3178 }
3179
3182 {
3183 CSG_String s = p->asString();
3184 s.Replace("<", "\\<");
3185 Parameter = CSG_String::Format("|%s%s%s%s|%s%s%s|", Space.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), s.c_str(), Bold.c_str());
3186 if( p->Get_Parent() != NULL && (p->Get_Parent()->is_DataObject() || p->Get_Parent()->is_DataObject_List()) )
3187 {
3188 CSG_MetaData *pParent = NULL;
3190 if( pParent )
3191 {
3192 CSG_String c = pParent->Get_Content();
3193 c += SG_T("\n") + Parameter;
3194 pParent->Set_Content(c);
3195 }
3196 }
3197 else
3198 {
3200 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3201 }
3202 break;
3203 }
3204
3207 Parameter = CSG_String::Format("|%s%s%s%s|%s%s%s|", 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());
3208 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3209 break;
3210
3214 Parameter = CSG_String::Format("|%s%s%s%s|%s%g%s|", Space.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), p->asDouble(), Bold.c_str());
3215 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3216 break;
3217
3220 Parameter = CSG_String::Format("|%s%s%s%s|%s%g;%g%s|", 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());
3221 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3222 break;
3223
3225 if( ((CSG_Parameter_String *)p)->is_Password() )
3226 {
3228 Parameter = CSG_String::Format("|%s%s%s%s|%s***%s|", Space.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), Bold.c_str());
3229 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3230 break;
3231 }
3232
3233 case PARAMETER_TYPE_Date :
3234 case PARAMETER_TYPE_Text :
3236 {
3238 CSG_String s = p->asString();
3239 s.Replace("\\", "/");
3240 Parameter = CSG_String::Format("|%s%s%s%s|%s%s%s|", Space.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), s.c_str(), Bold.c_str());
3241 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3242 break;
3243 }
3244
3247 Parameter = CSG_String::Format("|%s%s%s%s|%s%s%s|", Space.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), p->asString(), Bold.c_str());
3248 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3249 break;
3250
3253 Parameter = CSG_String::Format("|%s%s||\n", Space.c_str(), Name.c_str());
3254 CSG_String Prefix = Space + "&nbsp;&nbsp;&nbsp;";
3255 _Get_Script_Markdown(Parameter, p->asParameters(), iArguments, Prefix);
3256 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3257 break;
3258 }
3259
3260 return;
3261}
3262
3264// //
3265// //
3266// //
3268
3269//---------------------------------------------------------
3271{
3272 CSG_MetaData History;
3273
3274 History.Set_Name(SG_META_HISTORY);
3275 History.Add_Property("saga-version", SAGA_VERSION);
3276
3277 if( Depth )
3278 {
3279 CSG_MetaData *pTool = History.Add_Child("TOOL");
3280
3281 pTool->Add_Property("library", Get_Library());
3282 pTool->Add_Property("id" , Get_ID ());
3283 pTool->Add_Property("name" , Get_Name ());
3284
3285 Parameters.Set_History(*pTool);
3286
3288
3289 CSG_MetaData *pOutput = pTool->Add_Child("OUTPUT");
3290 pOutput->Add_Property("type", "");
3291 pOutput->Add_Property("id" , "");
3292 pOutput->Add_Property("name", "");
3293
3294 pTool->Del_Children(Depth, SG_T("TOOL"));
3295 }
3296
3297 return( History );
3298}
3299
3300//---------------------------------------------------------
3301bool CSG_Tool::Set_History(CSG_Data_Object *pDataObject, int Depth)
3302{
3303 if( pDataObject )
3304 {
3305 CSG_MetaData History(Get_History(Depth));
3306
3307 CSG_MetaData *pOutput = History("TOOL") ? History["TOOL"]("OUTPUT") : NULL;
3308
3309 if( pOutput )
3310 {
3311 pOutput->Set_Property("name", pDataObject->Get_Name());
3312 }
3313
3314 pDataObject->Get_History() = History;
3315
3316 return( true );
3317 }
3318
3319 return( false );
3320}
3321
3322//---------------------------------------------------------
3323void CSG_Tool::_Set_Output_History(void)
3324{
3326
3327 for(int j=-1; j<Get_Parameters_Count(); j++)
3328 {
3329 CSG_Parameters *pParameters = j < 0 ? &Parameters : Get_Parameters(j);
3330
3331 for(int i=0; i<pParameters->Get_Count(); i++)
3332 {
3333 CSG_Parameter *pParameter = pParameters->Get_Parameter(i);
3334
3335 if( pParameter->is_Output() )//&& (pParameter->is_Enabled() || !has_GUI()) )
3336 {
3337 DataObject_Set_History(pParameter, &History);
3338 }
3339 }
3340 }
3341}
3342
3343//---------------------------------------------------------
3345{
3346 if( !pParameter && !((pParameter->is_DataObject() && pParameter->asDataObject()) || !(pParameter->is_DataObject_List() && pParameter->asList()->Get_Item_Count() > 0)) )
3347 {
3348 return( false );
3349 }
3350
3351 //-----------------------------------------------------
3352 CSG_MetaData History;
3353
3354 if( !pHistory )
3355 {
3356 History = Get_History(SG_Get_History_Depth()); pHistory = &History;
3357 }
3358
3359 //-----------------------------------------------------
3360 CSG_MetaData *pOutput = pHistory->Get_Child("TOOL") ? pHistory->Get_Child("TOOL")->Get_Child("OUTPUT") : NULL;
3361
3362 if( pOutput )
3363 {
3364 pOutput->Set_Property("type", pParameter->Get_Type_Identifier());
3365 pOutput->Set_Property("id" , pParameter->Get_Identifier ());
3366 pOutput->Set_Property("name", pParameter->Get_Name ());
3367 }
3368
3369 //-----------------------------------------------------
3370 if( pParameter->is_DataObject() && pParameter->asDataObject() )
3371 {
3372 if( pOutput )
3373 {
3374 pOutput->Set_Content(pParameter->asDataObject()->Get_Name());
3375 }
3376
3377 pParameter->asDataObject()->Get_History().Assign(*pHistory);
3378 }
3379
3380 //-----------------------------------------------------
3381 else if( pParameter->is_DataObject_List() )
3382 {
3383 for(int j=0; j<pParameter->asList()->Get_Item_Count(); j++)
3384 {
3385 if( pOutput )
3386 {
3387 pOutput->Set_Content(pParameter->asList()->Get_Item(j)->Get_Name());
3388 }
3389
3390 pParameter->asList()->Get_Item(j)->Get_History().Assign(*pHistory);
3391 }
3392 }
3393
3394 //-----------------------------------------------------
3395 return( true );
3396}
3397
3398
3400// //
3401// //
3402// //
3404
3405//---------------------------------------------------------
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)
void SG_UI_ProgressAndMsg_Lock(bool bOn)
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:1627
@ SG_UI_MSG_STYLE_SUCCESS
Definition api_core.h:1626
@ SG_UI_MSG_STYLE_BOLD
Definition api_core.h:1624
@ SG_UI_MSG_STYLE_NORMAL
Definition api_core.h:1623
signed long long sLong
Definition api_core.h:158
#define SG_T(s)
Definition api_core.h:537
SAGA_API_DLL_EXPORT CSG_String SG_File_Make_Path(const CSG_String &Directory, const CSG_String &Name)
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:1640
@ SG_UI_DATAOBJECT_UPDATE
Definition api_core.h:1639
SAGA_API_DLL_EXPORT bool SG_Dir_Exists(const CSG_String &Directory)
Definition api_file.cpp:976
@ SG_DATATYPE_String
Definition api_core.h:1048
#define SG_Char
Definition api_core.h:536
#define _TL(s)
Definition api_core.h:1610
@ SG_FILE_ENCODING_UTF8
Definition api_core.h:552
@ SG_FILE_R
Definition api_core.h:1153
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:239
static CSG_DateTime Now(void)
Definition datetime.cpp:585
virtual bool Open(const SG_Char *FileName, int Mode=SG_FILE_R, bool bBinary=true, int Encoding=SG_FILE_ENCODING_ANSI)
Definition api_file.cpp:113
size_t Read(void *Buffer, size_t Size, size_t Count=1) const
Definition api_file.cpp:338
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
const CSG_String & Get_Name(void) const
Definition metadata.h:132
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
int Get_Children_Count(void) const
Definition metadata.h:148
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
const CSG_String & Get_Content(void) const
Definition metadata.h:133
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
bool Set_Name(const CSG_String &Name)
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
bool Set_Description(const CSG_String &Description)
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
CSG_Parameter * Get_Child(int iChild) const
Definition parameters.h:260
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:719
bool Set_Value(int Field, const CSG_String &Value)
bool Create(void)
Definition table.cpp:153
sLong Get_Count(void) const
Definition table.h:400
virtual CSG_Table_Record * Add_Record(CSG_Table_Record *pCopy=NULL)
Definition table.cpp:823
virtual CSG_Table_Record * Get_Record(sLong Index) const
Definition table.h:402
int Get_Field_Count(void) const
Definition table.h:361
virtual bool Add_Field(const CSG_String &Name, TSG_Data_Type Type, int Position=-1)
Definition table.cpp:479
virtual bool Set_Field_Type(int Field, TSG_Data_Type Type)
Definition table.cpp:610
static CSG_String Html_Absolute_Image_Paths(const CSG_String &Text, const CSG_String &Path, bool bAltAsText=false)
static CSG_String Markdown_to_Html(const CSG_String &Text, bool bSimple=true)
static CSG_String Html_to_SimpleText(const CSG_String &Text)
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
const CSG_String & Get_Name(void) const
const CSG_String & Get_Category(void) const
bool Reset_Grid_System(void)
Definition tool.cpp:1710
bool Message_Dlg_Confirm(const CSG_String &Text, const SG_Char *Caption=NULL)
Definition tool.cpp:1003
const CSG_String & Get_Library(void) const
Definition tool.cpp:129
bool Dlg_Parameters(const CSG_String &Identifier)
Definition tool.cpp:827
bool Del_References(void)
Definition tool.cpp:321
const CSG_String & Get_File_Name(void) const
Definition tool.cpp:135
bool Set_Grid_System(const CSG_Grid_System &System)
Definition tool.cpp:1725
int Get_Parameters_Count(void) const
Definition tool.h:177
bool Set_Manager(class CSG_Data_Manager *pManager)
Definition tool.cpp:874
CSG_Grid_System * Get_Grid_System(void) const
Definition tool.cpp:1735
CSG_MetaData Get_History(int Depth=-1)
Definition tool.cpp:3270
bool Settings_Pop(void)
Definition tool.cpp:938
static bool Process_Get_Okay(bool bBlink=false)
Definition tool.cpp:1150
bool Stop_Execution(bool bDialog=true)
Definition tool.cpp:982
class CSG_Data_Manager * Get_Manager(void) const
Definition tool.cpp:887
bool has_GUI(void) const
Definition tool.cpp:274
const CSG_String & Get_Author(void) const
Definition tool.cpp:157
bool Update_Parameter_States(void)
Definition tool.cpp:1748
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:1567
bool Load_Description(void)
Definition tool.cpp:459
virtual bool is_Interactive(void) const
Definition tool.h:233
static bool DataObject_Classify_Quantile(CSG_Data_Object *pDataObject, int Field=-1, int Classes=10, bool bHistogram=true, int Colors=-1)
Definition tool.cpp:1537
CSG_Parameters * Get_Parameters(void)
Definition tool.h:175
CSG_String Get_Script(Script_Format Format, bool bHeader=true, int Arguments=0, bool bWrapArgs=true)
Definition tool.cpp:1789
void Add_Reference(const CSG_String &Authors, const CSG_String &Date, const CSG_String &Title, const CSG_String &Source, const CSG_String &Link="", const CSG_String &Link_Text="")
Definition tool.cpp:294
CSG_Parameters * Add_Parameters(const CSG_String &Identifier, const CSG_String &Name, const CSG_String &Description)
Definition tool.cpp:799
static bool DataObject_Set_Colors(CSG_Data_Object *pDataObject, const CSG_Colors &Colors)
Definition tool.cpp:1305
const CSG_String & Get_Name(void) const
Definition tool.cpp:146
static CSG_Parameter * DataObject_Get_Parameter(CSG_Data_Object *pDataObject, const CSG_String &ID)
Definition tool.cpp:1353
static bool DataObject_Classify_Unique(CSG_Data_Object *pDataObject, int Field=-1, int Classes_Max=1024, int Colors=-1)
Definition tool.cpp:1507
static void Process_Set_Text(const CSG_String &Text)
Definition tool.cpp:1156
bool Settings_Push(class CSG_Data_Manager *pManager=NULL)
Definition tool.cpp:925
bool Set_Parameter(const CSG_String &ID, CSG_Parameter *pValue)
Definition tool.cpp:1607
virtual void Destroy(void)
Definition tool.cpp:114
static bool DataObject_Classify_Geometric(CSG_Data_Object *pDataObject, int Field=-1, int Classes=10, bool bIncreasing=true, int Colors=-1)
Definition tool.cpp:1547
CSG_Table Get_Parameters_Table(void) const
Definition tool.cpp:395
virtual bool On_Execute(void)=0
CSG_MetaData History_Supplement
Definition tool.h:268
CSG_Parameter * Get_Parameter(const CSG_String &ID) const
Definition tool.cpp:1590
bool has_CMD(void) const
Definition tool.cpp:280
static int _On_Parameter_Changed(CSG_Parameter *pParameter, int Flags)
Definition tool.cpp:756
void Add_Description(const CSG_String &String, bool bNewLine=true)
Definition tool.cpp:179
virtual ~CSG_Tool(void)
Definition tool.cpp:98
CSG_Parameters Parameters
Definition tool.h:266
void Set_Show_Progress(bool bOn=true)
Definition tool.cpp:958
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:1321
CSG_String Get_Description_Editors(bool bHTML=true)
Definition tool.cpp:525
virtual bool do_Sync_Projections(void) const
Definition tool.h:226
static bool DataObject_Update(CSG_Data_Object *pDataObject, int Show=SG_UI_DATAOBJECT_UPDATE)
Definition tool.cpp:1282
void Add_Dynamic_Description(const CSG_String &String, bool bNewLine=true)
Definition tool.cpp:199
virtual bool Set_Progress(int Position, int Range) const
Definition tool.cpp:964
CSG_Tool(void)
Definition tool.cpp:67
bool Reset(bool bManager=true)
Definition tool.cpp:1678
virtual CSG_String Get_MenuPath(void)
Definition tool.h:167
void Set_Description(const CSG_String &String)
Definition tool.cpp:174
static bool DataObject_Set_Parameters(CSG_Data_Object *pDataObject, CSG_Parameters &Parameters)
Definition tool.cpp:1326
bool DataObject_Update_All(void)
Definition tool.cpp:1119
void Set_Callback(bool bActive=true)
Definition tool.cpp:863
bool Reset_Manager(void)
Definition tool.cpp:1700
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:1476
bool Set_History(CSG_Data_Object *pDataObject, int Depth=-1)
Definition tool.cpp:3301
bool Execute(bool bAddHistory=false)
Definition tool.cpp:562
static bool DataObject_Get_Colors(CSG_Data_Object *pDataObject, CSG_Colors &Colors)
Definition tool.cpp:1300
void Message_Fmt(const char *Format,...)
Definition tool.cpp:1225
static bool DataObject_Set_Parameter(CSG_Data_Object *pDataObject, CSG_Parameter *pParameter)
Definition tool.cpp:1360
void Set_Author(const CSG_String &String)
Definition tool.cpp:152
static bool Set_Description_Source(const CSG_String &Source="")
Definition tool.cpp:446
const CSG_String & Get_Version(void) const
Definition tool.cpp:168
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:1487
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:1453
static bool DataObject_Classify_Natural(CSG_Data_Object *pDataObject, int Field=-1, int Classes=10, int Colors=-1)
Definition tool.cpp:1557
static bool DataObject_Classify_Equal(CSG_Data_Object *pDataObject, int Field=-1, int Classes=10, int Colors=-1)
Definition tool.cpp:1517
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:1464
const CSG_String & Get_Description(void) const
Definition tool.cpp:188
bool DataObject_Set_History(CSG_Parameter *pParameter, CSG_MetaData *pHistory=NULL)
Definition tool.cpp:3344
const CSG_String & Get_ID(void) const
Definition tool.h:150
CSG_Strings Get_References(bool bHTML=true) const
Definition tool.cpp:330
bool Error_Set(TSG_Tool_Error Error_ID=TOOL_ERROR_Unknown)
Definition tool.cpp:1009
bool Error_Fmt(const char *Format,...)
Definition tool.cpp:1046
Script_Format
Definition tool.h:252
virtual int On_Parameters_Enable(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
Definition tool.cpp:786
bool Get_Projection(CSG_Projection &Projection) const
Definition tool.cpp:734
const CSG_String & Get_Dynamic_Description(void) const
Definition tool.cpp:206
virtual int On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
Definition tool.cpp:780
void Message_Add(const CSG_String &Text, bool bNewLine=true)
Definition tool.cpp:1212
void Set_Dynamic_Description(const CSG_String &String)
Definition tool.cpp:194
void Set_Version(const CSG_String &String)
Definition tool.cpp:163
void Message_Dlg(const CSG_String &Text, const SG_Char *Caption=NULL)
Definition tool.cpp:997
class CSG_Data_Manager * Create_Manager(void)
Definition tool.cpp:893
static const CSG_String & Get_Description_Source(void)
Definition tool.cpp:453
void Set_Name(const CSG_String &String)
Definition tool.cpp:141
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:1527
bool DataObject_Add(CSG_Data_Object *pDataObject, bool bUpdate=false)
Definition tool.cpp:1103
bool Delete_Manager(bool bDetachData=false, bool bReset=true)
Definition tool.cpp:901
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
#define GET_ID2(p, s)
#define INIT_CLASSIFY_OPTIONS(method)
Definition tool.cpp:1503
#define WRITE_CHILD(pChild, Prefix)
#define INIT_STRETCH_OPTIONS(method)
Definition tool.cpp:1440
#define CHECK_OBJECTS_NODE()
#define FORMAT_DATASET()
#define ADD_MESSAGE_EXECUTION(Text, Style)
#define GET_PARENT_NODE(prt)
#define CHECK_DATA_NODE(Name)
#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)