SAGA API Version 9.13
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() && bHTML )
545 {
546 Editors = CSG_String::Format("<hr><small><small>%s: <i>%s</i>.</small></small>", _TL("Description editor(s)"), Editors.c_str());
547 }
548
549 return( Editors );
550}
551
552
554// //
555// //
556// //
558
559//---------------------------------------------------------
560bool CSG_Tool::Execute(bool bAddHistory)
561{
562 #define ADD_MESSAGE_EXECUTION(Text, Style) { SG_UI_Msg_Add(Text, true, Style); if( has_GUI() ) { SG_UI_Msg_Add_Execution(Text, true, Style); } }
563
564 //-----------------------------------------------------
565 if( m_bExecutes )
566 {
567 return( false );
568 }
569
570 m_bExecutes = true;
571
572 m_bError_Ignore = false;
573
574 bool bResult = false;
575
576 m_Execution_Info.Clear();
577
578 History_Supplement.Destroy();
579
580 //-----------------------------------------------------
581 if( Parameters.Get_Manager() == &SG_Get_Data_Manager() )
582 {
583 ADD_MESSAGE_EXECUTION(CSG_String::Format("[%s] %s...", Get_Name().c_str(), _TL("Execution started")), SG_UI_MSG_STYLE_SUCCESS);
584 }
585
587
588 if( Parameters.DataObjects_Create() == false )
589 {
590 _Synchronize_DataObjects(); // not all, but some objects might have been created!
591
592 ADD_MESSAGE_EXECUTION(CSG_String::Format("[%s] %s", Get_Name().c_str(), _TL("Execution failed")), SG_UI_MSG_STYLE_FAILURE);
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: SG_UI_Process_Set_Okay(false); break;
1033 case 1: m_bError_Ignore = true; break;
1034 }
1035 }
1036
1037 return( SG_UI_Process_Get_Okay(false) );
1038}
1039
1040//---------------------------------------------------------
1041bool CSG_Tool::Error_Fmt(const char *Format, ...)
1042{
1043 wxString _s; va_list argptr;
1044
1045#ifdef _SAGA_LINUX
1046 // workaround as we only use wide characters
1047 // since wx 2.9.4 so interpret strings as multibyte
1048 wxString _Format(Format); _Format.Replace("%s", "%ls"); va_start(argptr, _Format);
1049 _s.PrintfV(_Format, argptr);
1050#else
1051 va_start(argptr, Format);
1052 _s.PrintfV(Format, argptr);
1053#endif
1054
1055 va_end(argptr);
1056
1057 CSG_String s(&_s);
1058
1059 return( Error_Set(s) );
1060}
1061
1062//---------------------------------------------------------
1063bool CSG_Tool::Error_Fmt(const wchar_t *Format, ...)
1064{
1065 wxString _s; va_list argptr;
1066
1067#ifdef _SAGA_LINUX
1068 // workaround as we only use wide characters
1069 // since wx 2.9.4 so interpret strings as multibyte
1070 wxString _Format(Format); _Format.Replace("%s", "%ls"); va_start(argptr, _Format);
1071 _s.PrintfV(_Format, argptr);
1072#else
1073 va_start(argptr, Format);
1074 _s.PrintfV(Format, argptr);
1075#endif
1076
1077 va_end(argptr);
1078
1079 CSG_String s(&_s);
1080
1081 return( Error_Set(s) );
1082}
1083
1084
1086// //
1087// DataObjects / GUI Interaction //
1088// //
1090
1091//---------------------------------------------------------
1092bool CSG_Tool::DataObject_Add(CSG_Data_Object *pDataObject, bool bShow)
1093{
1094 if( Parameters.Get_Manager() )
1095 {
1096 Parameters.Get_Manager()->Add(pDataObject);
1097 }
1098
1099 if( Parameters.Get_Manager() == &SG_Get_Data_Manager() ) // prevent that local data manager send their data objects to gui
1100 {
1102 }
1103
1104 return( true );
1105}
1106
1107//---------------------------------------------------------
1109{
1110 for(int i=0; i<Parameters.Get_Count(); i++)
1111 {
1112 if( Parameters(i)->is_Output() )
1113 {
1114 if( Parameters(i)->is_DataObject() )
1115 {
1116 DataObject_Update(Parameters(i)->asDataObject(), false);
1117 }
1118 else if( Parameters(i)->is_DataObject_List() )
1119 {
1120 for(int j=0; j<Parameters(i)->asList()->Get_Item_Count(); j++)
1121 {
1122 DataObject_Update(Parameters(i)->asList()->Get_Item(j), false);
1123 }
1124 }
1125 }
1126 }
1127
1128 return( true );
1129}
1130
1131
1133// //
1134// Static Data Message/Progress Functions //
1135// //
1137
1138//---------------------------------------------------------
1140{
1141 return( SG_UI_Process_Get_Okay(bBlink) );
1142}
1143
1144//---------------------------------------------------------
1146{
1148}
1149
1150//---------------------------------------------------------
1151void CSG_Tool::Process_Set_Text(const char *Format, ...)
1152{
1153 wxString _s; va_list argptr;
1154
1155 #ifdef _SAGA_LINUX
1156 // workaround as we only use wide characters
1157 // since wx 2.9.4 so interpret strings as multibyte
1158 wxString _Format(Format); _Format.Replace("%s", "%ls"); va_start(argptr, _Format);
1159 _s.PrintfV(_Format, argptr);
1160 #else
1161 va_start(argptr, Format);
1162 _s.PrintfV(Format, argptr);
1163 #endif
1164
1165 va_end(argptr);
1166
1167 CSG_String s(&_s);
1168
1170}
1171
1172//---------------------------------------------------------
1173void CSG_Tool::Process_Set_Text(const wchar_t *Format, ...)
1174{
1175 wxString _s; va_list argptr;
1176
1177 #ifdef _SAGA_LINUX
1178 // workaround as we only use wide characters
1179 // since wx 2.9.4 so interpret strings as multibyte
1180 wxString _Format(Format); _Format.Replace("%s", "%ls"); va_start(argptr, _Format);
1181 _s.PrintfV(_Format, argptr);
1182 #else
1183 va_start(argptr, Format);
1184 _s.PrintfV(Format, argptr);
1185 #endif
1186
1187 va_end(argptr);
1188
1189 CSG_String s(&_s);
1190
1192}
1193
1194//---------------------------------------------------------
1195void CSG_Tool::Message_Add(const CSG_String &Text, bool bNewLine)
1196{
1197 SG_UI_Msg_Add_Execution(Text, bNewLine);
1198
1199 if( bNewLine )
1200 {
1201 m_Execution_Info += "\n";
1202 }
1203
1204 m_Execution_Info += Text;
1205}
1206
1207//---------------------------------------------------------
1208void CSG_Tool::Message_Fmt(const char *Format, ...)
1209{
1210 wxString _s; va_list argptr;
1211
1212 #ifdef _SAGA_LINUX
1213 // workaround as we only use wide characters
1214 // since wx 2.9.4 so interpret strings as multibyte
1215 wxString _Format(Format); _Format.Replace("%s", "%ls"); va_start(argptr, _Format);
1216 _s.PrintfV(_Format, argptr);
1217 #else
1218 va_start(argptr, Format);
1219 _s.PrintfV(Format, argptr);
1220 #endif
1221
1222 va_end(argptr);
1223
1224 CSG_String s(&_s);
1225
1226 Message_Add(s, false);
1227}
1228
1229//---------------------------------------------------------
1230void CSG_Tool::Message_Fmt(const wchar_t *Format, ...)
1231{
1232 wxString _s; va_list argptr;
1233
1234 #ifdef _SAGA_LINUX
1235 // workaround as we only use wide characters
1236 // since wx 2.9.4 so interpret strings as multibyte
1237 wxString _Format(Format); _Format.Replace("%s", "%ls"); va_start(argptr, _Format);
1238 _s.PrintfV(_Format, argptr);
1239 #else
1240 va_start(argptr, Format);
1241 _s.PrintfV(Format, argptr);
1242 #endif
1243
1244 va_end(argptr);
1245
1246 CSG_String s(&_s);
1247
1248 Message_Add(s, false);
1249}
1250
1251
1253// //
1254// Static Data Object Property Functions //
1255// //
1257
1258//---------------------------------------------------------
1260{
1261 return( SG_UI_DataObject_Update(pDataObject, Show, NULL) );
1262}
1263
1264bool CSG_Tool::DataObject_Update(CSG_Data_Object *pDataObject, double Minimum, double Maximum, int Show)
1265{
1267
1268 return( DataObject_Get_Parameters(pDataObject, P)
1269 && P.Set_Parameter("STRETCH_DEFAULT" , 3 ) // manual
1270 && P.Set_Parameter("METRIC_ZRANGE.MIN", Minimum)
1271 && P.Set_Parameter("METRIC_ZRANGE.MAX", Maximum)
1272 && SG_UI_DataObject_Update(pDataObject, Show, &P)
1273 );
1274}
1275
1276//---------------------------------------------------------
1278{
1279 return( SG_UI_DataObject_Colors_Get(pDataObject, &Colors) );
1280}
1281
1283{
1284 CSG_Colors c; return( c.Create(Colors) && SG_UI_DataObject_Colors_Set(pDataObject, &c) );
1285}
1286
1287bool CSG_Tool::DataObject_Set_Colors(CSG_Data_Object *pDataObject, int nColors, int Colors, bool bRevert)
1288{
1289 CSG_Colors c; return( c.Set_Predefined(Colors, bRevert, nColors) && SG_UI_DataObject_Colors_Set(pDataObject, &c) );
1290}
1291
1292bool CSG_Tool::DataObject_Set_Colors(CSG_Data_Object *pDataObject, const CSG_String &Colors, int nColors, bool bRevert)
1293{
1294 CSG_Colors c; return( c.Set_Predefined(Colors, bRevert, nColors) && SG_UI_DataObject_Colors_Set(pDataObject, &c) );
1295}
1296
1297//---------------------------------------------------------
1302
1307
1309{
1310 if( pDataObject == pCopy )
1311 {
1312 return( true );
1313 }
1314
1316
1317 if( DataObject_Get_Parameters(pCopy, P) )
1318 {
1319 P.Del_Parameter("OBJECT_NODATA" );
1320 P.Del_Parameter("OBJECT_Z_FACTOR");
1321 P.Del_Parameter("OBJECT_Z_OFFSET");
1322
1323 return( DataObject_Set_Parameters(pDataObject, P) );
1324 }
1325
1326 return( false );
1327}
1328
1329//---------------------------------------------------------
1331{
1332 static CSG_Parameters P;
1333
1334 return( DataObject_Get_Parameters(pDataObject, P) ? P(ID) : NULL );
1335}
1336
1338{
1340
1341 return( P._Add(pParameter) != NULL && DataObject_Set_Parameters(pDataObject, P) );
1342}
1343
1345{
1346 CSG_Parameter *pParameter = DataObject_Get_Parameter(pCopy, ID);
1347
1348 return( DataObject_Set_Parameter(pDataObject, pParameter) );
1349}
1350
1351bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, int Value)
1352{
1354
1355 if( DataObject_Get_Parameters(pDataObject, P) && P(ID) )
1356 {
1357 return( P(ID)->Set_Value(Value) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1358 }
1359
1360 return( false );
1361}
1362
1363bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, double Value)
1364{
1366
1367 if( DataObject_Get_Parameters(pDataObject, P) && P(ID) )
1368 {
1369 return( P(ID)->Set_Value(Value) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1370 }
1371
1372 return( false );
1373}
1374
1375bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, void *Value)
1376{
1378
1379 if( DataObject_Get_Parameters(pDataObject, P) && P(ID) )
1380 {
1381 return( P(ID)->Set_Value(Value) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1382 }
1383
1384 return( false );
1385}
1386
1387bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, const SG_Char *Value)
1388{
1390
1391 if( DataObject_Get_Parameters(pDataObject, P) && P(ID) )
1392 {
1393 return( P(ID)->Set_Value(Value) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1394 }
1395
1396 return( false );
1397}
1398
1399bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, double loVal, double hiVal) // Range Parameter
1400{
1402
1403 if( DataObject_Get_Parameters(pDataObject, P) && P(ID) && P(ID)->Get_Type() == PARAMETER_TYPE_Range )
1404 {
1405 return( P(ID)->asRange()->Set_Range(loVal, hiVal) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1406 }
1407
1408 return( false );
1409}
1410
1411
1413// //
1415
1416//---------------------------------------------------------
1417#define INIT_STRETCH_OPTIONS(method) { if( !pDataObject || (pDataObject->asTable(true) && (Field < 0 || Field >= pDataObject->asTable(true)->Get_Field_Count())) ) { return( false ); }\
1418 if( Colors >= 0 ) { DataObject_Set_Colors(pDataObject, -1, Colors); }\
1419 DataObject_Set_Parameter(pDataObject, "COLORS_TYPE" , 3); /* graduated colors */\
1420 DataObject_Set_Parameter(pDataObject, "STRETCH_DEFAULT" , method);\
1421 DataObject_Set_Parameter(pDataObject, "METRIC_SCALE_MODE", Interval_Mode);\
1422 DataObject_Set_Parameter(pDataObject, "METRIC_SCALE_LOG" , Interval_Log );\
1423 if( pDataObject->asTable(true) )\
1424 { DataObject_Set_Parameter(pDataObject, "METRIC_FIELD" , Field);\
1425 DataObject_Set_Parameter(pDataObject, "METRIC_MORMAL", pDataObject->asTable(true)->Get_Field_Count());\
1426 }\
1427}
1428
1429//---------------------------------------------------------
1430bool 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)
1431{
1433
1434 DataObject_Set_Parameter(pDataObject, "STRETCH_LINEAR.MIN", Minimum);
1435 DataObject_Set_Parameter(pDataObject, "STRETCH_LINEAR.MAX", Maximum);
1436
1437 return( bUpdateNow ? DataObject_Update(pDataObject) : true );
1438}
1439
1440//---------------------------------------------------------
1441bool 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)
1442{
1444
1445 DataObject_Set_Parameter(pDataObject, "STRETCH_STDDEV" , StdDev );
1446 DataObject_Set_Parameter(pDataObject, "STRETCH_INRANGE", bKeepInRange);
1447 DataObject_Update(pDataObject);
1448
1449 return( bUpdateNow ? DataObject_Update(pDataObject) : true );
1450}
1451
1452//---------------------------------------------------------
1453bool 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)
1454{
1456
1457 DataObject_Set_Parameter(pDataObject, "STRETCH_PCTL.MIN", Minimum);
1458 DataObject_Set_Parameter(pDataObject, "STRETCH_PCTL.MAX", Maximum);
1459
1460 return( bUpdateNow ? DataObject_Update(pDataObject) : true );
1461}
1462
1463//---------------------------------------------------------
1464bool 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)
1465{
1467
1468 DataObject_Set_Parameter(pDataObject, "METRIC_ZRANGE.MIN", Minimum);
1469 DataObject_Set_Parameter(pDataObject, "METRIC_ZRANGE.MAX", Maximum);
1470
1471 return( bUpdateNow ? DataObject_Update(pDataObject) : true );
1472}
1473
1474
1476// //
1478
1479//---------------------------------------------------------
1480#define INIT_CLASSIFY_OPTIONS(method) if( !pDataObject || (pDataObject->asTable(true) && (Field < 0 || Field >= pDataObject->asTable(true)->Get_Field_Count())) ) { return( false ); }\
1481 CSG_MetaData Options; Options.Add_Child("METHOD", method); Options.Add_Child("COLORS", Colors); Options.Add_Child("FIELD", Field);
1482
1483//---------------------------------------------------------
1484bool CSG_Tool::DataObject_Classify_Unique(CSG_Data_Object *pDataObject, int Field, int maxClasses, int Colors)
1485{
1487
1488 Options.Add_Child("MAXCLASSES", maxClasses);
1489
1490 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1491}
1492
1493//---------------------------------------------------------
1494bool CSG_Tool::DataObject_Classify_Equal(CSG_Data_Object *pDataObject, int Field, int Classes, int Colors)
1495{
1497
1498 Options.Add_Child("CLASSES", Classes);
1499
1500 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1501}
1502
1503//---------------------------------------------------------
1504bool CSG_Tool::DataObject_Classify_Defined(CSG_Data_Object *pDataObject, int Field, double Interval, bool bOffset, double Offset, int Colors)
1505{
1507
1508 Options.Add_Child("INTERVAL", Interval); if( bOffset ) { Options.Add_Child("OFFSET", Offset); }
1509
1510 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1511}
1512
1513//---------------------------------------------------------
1514bool CSG_Tool::DataObject_Classify_Quantile(CSG_Data_Object *pDataObject, int Field, int Classes, bool bHistogram, int Colors)
1515{
1517
1518 Options.Add_Child("CLASSES", Classes); Options.Add_Child("HISTOGRAM", bHistogram ? 1 : 0);
1519
1520 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1521}
1522
1523//---------------------------------------------------------
1524bool CSG_Tool::DataObject_Classify_Geometric(CSG_Data_Object *pDataObject, int Field, int Classes, bool bIncreasing, int Colors)
1525{
1527
1528 Options.Add_Child("CLASSES", Classes); Options.Add_Child("INCREASING", bIncreasing ? 1 : 0);
1529
1530 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1531}
1532
1533//---------------------------------------------------------
1534bool CSG_Tool::DataObject_Classify_Natural(CSG_Data_Object *pDataObject, int Field, int Classes, int Colors)
1535{
1537
1538 Options.Add_Child("CLASSES", Classes);
1539
1540 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1541}
1542
1543//---------------------------------------------------------
1544bool CSG_Tool::DataObject_Classify_StdDev(CSG_Data_Object *pDataObject, int Field, double StdDev, double StdDev_Max, int Colors)
1545{
1547
1548 Options.Add_Child("STDDEV", StdDev); Options.Add_Child("STDDEV_MAX", StdDev_Max);
1549
1550 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1551}
1552
1553
1555// //
1556// //
1557// //
1559
1560//---------------------------------------------------------
1564//---------------------------------------------------------
1565CSG_Parameter * CSG_Tool::Get_Parameter(const char *ID) const { return( Get_Parameter(CSG_String(ID)) ); }
1566CSG_Parameter * CSG_Tool::Get_Parameter(const wchar_t *ID) const { return( Get_Parameter(CSG_String(ID)) ); }
1568{
1569 CSG_Parameter *pParameter = Parameters(ID);
1570
1571 for(int i=0; !pParameter && i<Get_Parameters_Count(); i++)
1572 {
1573 pParameter = Get_Parameters(i)->Get_Parameter(ID);
1574 }
1575
1576 return( pParameter );
1577}
1578
1579//---------------------------------------------------------
1583//---------------------------------------------------------
1584bool CSG_Tool::Set_Parameter(const CSG_String &ID, CSG_Parameter *pValue) { return( Parameters.Set_Parameter(ID, pValue) ); }
1585bool CSG_Tool::Set_Parameter(const char *ID, CSG_Parameter *pValue) { return( Parameters.Set_Parameter(ID, pValue) ); }
1586bool CSG_Tool::Set_Parameter(const wchar_t *ID, CSG_Parameter *pValue) { return( Parameters.Set_Parameter(ID, pValue) ); }
1587
1588//---------------------------------------------------------
1592//---------------------------------------------------------
1593bool CSG_Tool::Set_Parameter(const CSG_String &ID, int Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1594bool CSG_Tool::Set_Parameter(const char *ID, int Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1595bool CSG_Tool::Set_Parameter(const wchar_t *ID, int Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1596
1597//---------------------------------------------------------
1601//---------------------------------------------------------
1602bool CSG_Tool::Set_Parameter(const CSG_String &ID, double Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1603bool CSG_Tool::Set_Parameter(const char *ID, double Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1604bool CSG_Tool::Set_Parameter(const wchar_t *ID, double Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1605
1606//---------------------------------------------------------
1610//---------------------------------------------------------
1611bool CSG_Tool::Set_Parameter(const CSG_String &ID, void *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1612bool CSG_Tool::Set_Parameter(const char *ID, void *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1613bool CSG_Tool::Set_Parameter(const wchar_t *ID, void *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1614
1615//---------------------------------------------------------
1619//---------------------------------------------------------
1620bool CSG_Tool::Set_Parameter(const CSG_String &ID, const CSG_String &Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1621bool CSG_Tool::Set_Parameter(const char *ID, const CSG_String &Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1622bool CSG_Tool::Set_Parameter(const wchar_t *ID, const CSG_String &Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1623
1624//---------------------------------------------------------
1628//---------------------------------------------------------
1629bool CSG_Tool::Set_Parameter(const CSG_String &ID, const char *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1630bool CSG_Tool::Set_Parameter(const char *ID, const char *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1631bool CSG_Tool::Set_Parameter(const wchar_t *ID, const char *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1632
1633//---------------------------------------------------------
1637//---------------------------------------------------------
1638bool CSG_Tool::Set_Parameter(const CSG_String &ID, const wchar_t *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1639bool CSG_Tool::Set_Parameter(const char *ID, const wchar_t *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1640bool CSG_Tool::Set_Parameter(const wchar_t *ID, const wchar_t *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1641
1642
1644// //
1645// //
1646// //
1648
1649//---------------------------------------------------------
1655bool CSG_Tool::Reset(bool bManager)
1656{
1658
1659 if( bManager )
1660 {
1661 Reset_Manager();
1662 }
1663
1664 for(int i=0; i<Get_Parameters_Count(); i++)
1665 {
1667 }
1668
1669 return( Parameters.Restore_Defaults(true) );
1670}
1671
1672//---------------------------------------------------------
1678{
1679 return( Set_Manager(&SG_Get_Data_Manager()) );
1680}
1681
1682//---------------------------------------------------------
1688{
1689 for(int i=0; i<Get_Parameters_Count(); i++)
1690 {
1692 }
1693
1694 return( Parameters.Reset_Grid_System() );
1695}
1696
1697//---------------------------------------------------------
1703{
1704 return( Parameters.Set_Grid_System(System) );
1705}
1706
1707//---------------------------------------------------------
1713{
1714 return( Parameters.Get_Grid_System() );
1715}
1716
1717
1719// //
1720// //
1721// //
1723
1724//---------------------------------------------------------
1726{
1727 _Update_Parameter_States(&Parameters);
1728
1729 for(int i=0; i<Get_Parameters_Count(); i++)
1730 {
1731 _Update_Parameter_States(Get_Parameters(i));
1732 }
1733
1734 return( true );
1735}
1736
1737//---------------------------------------------------------
1738void CSG_Tool::_Update_Parameter_States(CSG_Parameters *pParameters)
1739{
1740 if( pParameters )
1741 {
1742 for(int i=0; i<pParameters->Get_Count(); i++)
1743 {
1744 CSG_Parameter *pParameter = pParameters->Get_Parameter(i);
1745
1746 if( pParameter->Get_Type() == PARAMETER_TYPE_Parameters )
1747 {
1748 _Update_Parameter_States(pParameter->asParameters());
1749 }
1750 else
1751 {
1752 On_Parameters_Enable(pParameters, pParameter);
1753 }
1754 }
1755 }
1756}
1757
1758
1760// //
1761// Script //
1762// //
1764
1765//---------------------------------------------------------
1766CSG_String CSG_Tool::Get_Script(Script_Format Format, bool bHeader, int Arguments, bool bWrapArgs)
1767{
1768 switch( Format )
1769 {
1770 case Script_Format::CMD_Shell : return( _Get_Script_CMD ( bHeader, Arguments > 0, bWrapArgs, false ) );
1771 case Script_Format::CMD_Batch : return( _Get_Script_CMD ( bHeader, Arguments > 0, bWrapArgs, true ) );
1772 case Script_Format::CMD_Usage : return( _Get_Script_CMD_Usage ( ) );
1773
1774 case Script_Format::Toolchain : return( CSG_Tool_Chain::Get_Script(this, bHeader, Arguments > 0 ) );
1775
1776 case Script_Format::Python : return( _Get_Script_Python ( bHeader, Arguments > 0 ) );
1777
1778 case Script_Format::Python_Wrapper_Func_Name : return( _Get_Script_Python_Wrap ( bHeader, true , false, 1, bWrapArgs ) );
1779 case Script_Format::Python_Wrapper_Func_ID : return( _Get_Script_Python_Wrap ( bHeader, false, false, 1, bWrapArgs ) );
1780
1781 case Script_Format::Python_Wrapper_Call_Name : return( _Get_Script_Python_Wrap ( bHeader, true , true , Arguments, bWrapArgs ) );
1782 case Script_Format::Python_Wrapper_Call_ID : return( _Get_Script_Python_Wrap ( bHeader, false, true , Arguments, bWrapArgs ) );
1783
1784 case Script_Format::Markdown_Table : return( _Get_Script_Markdown ( bHeader, Arguments ) );
1785 }
1786
1787 return( "" );
1788}
1789
1790
1792// //
1794
1795//---------------------------------------------------------
1796CSG_String CSG_Tool::_Get_Script_CMD(bool bHeader, bool bAllArguments, bool bWrapArgs, bool bBatch)
1797{
1798 CSG_String Script;
1799
1800 if( bHeader )
1801 {
1802 if( bBatch ) // DOS/Windows Batch Script
1803 {
1804 Script += "@ECHO OFF\n\n";
1805 Script += "PUSHD %~dp0\n\n";
1806 Script += "REM SET SAGA_TLB=C:\\MyTools\n\n";
1807 Script += "SET SAGA_CMD=" + SG_UI_Get_Application_Path(true) + "saga_cmd.exe\n\n";
1808 Script += "REM Tool: " + Get_Name() + "\n\n";
1809 Script += "%SAGA_CMD%";
1810 }
1811 else // Bash Shell Script
1812 {
1813 Script += "#!/bin/bash\n\n";
1814 Script += "# export SAGA_TLB=~/mytools\n\n";
1815 Script += "# tool: " + Get_Name() + "\n\n";
1816 Script += "saga_cmd";
1817 }
1818 }
1819 else
1820 {
1821 Script += "saga_cmd";
1822 }
1823
1824 //-----------------------------------------------------
1825 Script += Get_Library().Contains(" ") // white space? use quotation marks!
1826 ? " \"" + Get_Library() + "\""
1827 : " " + Get_Library();
1828
1829 Script += Get_ID().Contains (" ") // white space? use quotation marks!
1830 ? " \"" + Get_ID () + "\""
1831 : " " + Get_ID ();
1832
1833 _Get_Script_CMD(Script, Get_Parameters(), bAllArguments, bWrapArgs, bBatch);
1834
1835 for(int i=0; i<Get_Parameters_Count(); i++)
1836 {
1837 _Get_Script_CMD(Script, Get_Parameters(i), bAllArguments, bWrapArgs, bBatch);
1838 }
1839
1840 //-----------------------------------------------------
1841 if( bHeader )
1842 {
1843 Script += bBatch ? "\n\nPAUSE\n" : "\n";
1844 }
1845
1846 return( Script );
1847}
1848
1849//---------------------------------------------------------
1850void CSG_Tool::_Get_Script_CMD(CSG_String &Script, CSG_Parameters *pParameters, bool bAllArguments, bool bWrapArgs, bool bBatch)
1851{
1852 #define GET_ID1(p) (p->Get_Parameters()->Get_Identifier().Length() > 0 \
1853 ? CSG_String::Format("%s_%s", p->Get_Parameters()->Get_Identifier().c_str(), p->Get_Identifier()) \
1854 : CSG_String::Format(p->Get_Identifier())).c_str()
1855
1856 #define GET_ID2(p, s) CSG_String::Format("%s_%s", GET_ID1(p), s).c_str()
1857
1858 const char *Prefix = !bWrapArgs ? " -" : bBatch ? " ^\n -" : " \\\n -";
1859 const char *StrFmt = bBatch ? "%s=\"%s\"" : "%s=\\\"\"%s\"\\\"";
1860
1861 //-----------------------------------------------------
1862 for(int iParameter=0; iParameter<pParameters->Get_Count(); iParameter++)
1863 {
1864 CSG_Parameter *p = pParameters->Get_Parameter(iParameter);
1865
1866 if( !bAllArguments && (!p->is_Enabled(false) || p->is_Information() || !p->do_UseInCMD()) )
1867 {
1868 continue;
1869 }
1870
1871 switch( p->Get_Type() )
1872 {
1873 default:
1874 break;
1875
1876 case PARAMETER_TYPE_Bool :
1877 Script += Prefix + CSG_String::Format("%s=%d", GET_ID1(p), p->asBool() ? 1 : 0);
1878 break;
1879
1880 case PARAMETER_TYPE_Int :
1884 Script += Prefix + CSG_String::Format("%s=%d", GET_ID1(p), p->asInt());
1885 break;
1886
1889 if( p->asString() && *p->asString() )
1890 {
1891 Script += Prefix + CSG_String::Format(StrFmt, GET_ID1(p), p->asString());
1892 }
1893 break;
1894
1896 Script += Prefix + CSG_String::Format("%s=\"%s\"", GET_ID1(p), SG_Color_To_Text(p->asColor()).c_str());
1897 break;
1898
1901 Script += Prefix + CSG_String::Format("%s=%g", GET_ID1(p), p->asDouble());
1902 break;
1903
1905 Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T("MIN")), p->asRange()->Get_Min());
1906 Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T("MAX")), p->asRange()->Get_Max());
1907 break;
1908
1910 if( ((CSG_Parameter_String *)p)->is_Password() )
1911 {
1912 Script += Prefix + CSG_String::Format("%s=\"***\"", GET_ID1(p));
1913 break;
1914 }
1915
1916 case PARAMETER_TYPE_Date :
1917 case PARAMETER_TYPE_Text :
1919 Script += Prefix + CSG_String::Format(StrFmt, GET_ID1(p), p->asString());
1920 break;
1921
1923 Script += Prefix + CSG_String::Format(StrFmt, GET_ID1(p), p->asString());
1924 break;
1925
1927 if( p->Get_Children_Count() == 0 )
1928 {
1929 Script += Prefix + CSG_String::Format("%s=%d", GET_ID2(p, SG_T("NX")), p->asGrid_System()->Get_NX ());
1930 Script += Prefix + CSG_String::Format("%s=%d", GET_ID2(p, SG_T("NY")), p->asGrid_System()->Get_NY ());
1931 Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T( "X")), p->asGrid_System()->Get_XMin ());
1932 Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T( "Y")), p->asGrid_System()->Get_YMin ());
1933 Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T( "D")), p->asGrid_System()->Get_Cellsize());
1934 }
1935 break;
1936
1938 case PARAMETER_TYPE_Grid :
1942 case PARAMETER_TYPE_TIN :
1944 if( p->is_Input() )
1945 {
1946 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"));
1947 }
1948 else
1949 {
1950 CSG_String File(p->Get_Name());
1951
1952 switch( p->Get_DataObject_Type() )
1953 {
1954 case SG_DATAOBJECT_TYPE_Grid : File += ".sg-grd-z"; break;
1955 case SG_DATAOBJECT_TYPE_Grids : File += ".sg-gds-z"; break;
1956 case SG_DATAOBJECT_TYPE_Table : File += ".txt" ; break;
1957 case SG_DATAOBJECT_TYPE_Shapes : File += ".geojson" ; break;
1958 case SG_DATAOBJECT_TYPE_PointCloud: File += ".sg-pts-z"; break;
1959 case SG_DATAOBJECT_TYPE_TIN : File += ".geojson" ; break;
1960 default : File += ".dat" ; break;
1961 }
1962
1963 Script += Prefix + CSG_String::Format(StrFmt, GET_ID1(p), File.c_str());
1964 }
1965 break;
1966
1973 if( p->is_Input() )
1974 {
1975 Script += Prefix + CSG_String::Format("%s=", GET_ID1(p));
1976
1977 if( p->asList()->Get_Item_Count() == 0 )
1978 {
1979 Script += "file(s)";
1980 }
1981 else
1982 {
1983 Script += SG_File_Exists(p->asList()->Get_Item(0)->Get_File_Name())
1984 ? p->asList()->Get_Item(0)->Get_File_Name() : _TL("memory");
1985
1986 for(int iObject=1; iObject<p->asList()->Get_Item_Count(); iObject++)
1987 {
1988 Script += ";";
1989 Script += SG_File_Exists(p->asList()->Get_Item(iObject)->Get_File_Name())
1990 ? p->asList()->Get_Item(iObject)->Get_File_Name() : _TL("memory");
1991 }
1992 }
1993 }
1994 else
1995 {
1996 Script += Prefix + CSG_String::Format(StrFmt, GET_ID1(p), p->Get_Name());
1997 }
1998 break;
1999 }
2000 }
2001}
2002
2003
2005// //
2007
2008//---------------------------------------------------------
2009CSG_String CSG_Tool::_Get_Script_CMD_Usage(void)
2010{
2011 wxCmdLineParser Parser; Parser.SetSwitchChars("-");
2012
2013 _Get_Script_CMD_Usage(Get_Parameters(), Parser);
2014
2015 for(int i=0; i<Get_Parameters_Count(); i++)
2016 {
2017 _Get_Script_CMD_Usage(Get_Parameters(i), Parser);
2018 }
2019
2020 wxString Usage = wxString::Format("\nUsage: saga_cmd %s %s %s", Get_Library().c_str(), Get_ID().c_str(),
2021 Parser.GetUsageString().AfterFirst(' ').AfterFirst(' ')
2022 );
2023
2024 CSG_String _Usage(&Usage);
2025
2026 return( _Usage );
2027}
2028
2029//---------------------------------------------------------
2030void CSG_Tool::_Get_Script_CMD_Usage(CSG_Parameters *pParameters, wxCmdLineParser &Parser)
2031{
2032 for(int i=0; i<pParameters->Get_Count(); i++)
2033 {
2034 CSG_Parameter *pParameter = pParameters->Get_Parameter(i);
2035
2036 //-------------------------------------------------
2037 if( pParameter->is_DataObject() ) // reset data object parameters, avoids problems when tool is called more than once without un-/reloading
2038 {
2039 pParameter->Set_Value(DATAOBJECT_NOTSET);
2040 }
2041 else if( pParameter->is_DataObject_List() )
2042 {
2043 pParameter->asList()->Del_Items();
2044 }
2045
2046 //-------------------------------------------------
2047 if( pParameter->do_UseInCMD() == false )
2048 {
2049 continue;
2050 }
2051
2052 wxString Description = pParameter->Get_Description(
2054 ).c_str();
2055
2056 Description.Replace("\xb", ""); // unicode problem: quick'n'dirty bug fix, to be replaced
2057
2058 wxString ID(pParameter->Get_CmdID().c_str());
2059
2060 if( pParameter->is_Input() || pParameter->is_Output() )
2061 {
2062 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_NEEDS_SEPARATOR|wxCMD_LINE_PARAM_OPTIONAL);
2063 }
2064
2065 //-------------------------------------------------
2066 else if( pParameter->is_Option() && !pParameter->is_Information() )
2067 {
2068 switch( pParameter->Get_Type() )
2069 {
2071 _Get_Script_CMD_Usage(pParameter->asParameters(), Parser);
2072 break;
2073
2074 case PARAMETER_TYPE_Bool :
2075 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2076 break;
2077
2078 case PARAMETER_TYPE_Int :
2079 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
2080 break;
2081
2087 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2088 break;
2089
2092 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2093 break;
2094
2095 case PARAMETER_TYPE_Date :
2096 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_DATE , wxCMD_LINE_PARAM_OPTIONAL);
2097 break;
2098
2100 Parser.AddOption(ID + "_MIN", wxEmptyString, Description, wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2101 Parser.AddOption(ID + "_MAX", wxEmptyString, Description, wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2102 break;
2103
2105 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2106 break;
2107
2109 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2110 break;
2111
2113 case PARAMETER_TYPE_Text :
2115 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2116 break;
2117
2119 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2120 break;
2121
2123 if( pParameter->Get_Children_Count() == 0 )
2124 {
2125 Parser.AddOption(ID + "_D" , wxEmptyString, _TL("Cell Size" ), wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2126 Parser.AddOption(ID + "_X" , wxEmptyString, _TL("Lower Left Center Cell X-Coordinate"), wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2127 Parser.AddOption(ID + "_Y" , wxEmptyString, _TL("Lower Left Center Cell Y-Coordinate"), wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2128 Parser.AddOption(ID + "_NX" , wxEmptyString, _TL("Number of Columns" ), wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
2129 Parser.AddOption(ID + "_NY" , wxEmptyString, _TL("Number of Rows" ), wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
2130 Parser.AddOption(ID + "_FILE", wxEmptyString, _TL("Grid File" ), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2131 }
2132 break;
2133
2134 default:
2135 break;
2136 }
2137 }
2138 }
2139}
2140
2141
2143// //
2145
2146//---------------------------------------------------------
2147CSG_String CSG_Tool::_Get_Script_Python(bool bHeader, bool bAllArguments)
2148{
2149 CSG_String Script, Name(Get_Name());
2150
2151 Name.Replace(" ", "_");
2152 Name.Replace("(", "");
2153 Name.Replace(")", "");
2154 Name.Replace("[", "");
2155 Name.Replace("]", "");
2156 Name.Replace(".", "");
2157 Name.Replace(",", "");
2158 Name.Replace("/", "");
2159 Name.Replace("-", "");
2160
2161 //-----------------------------------------------------
2162 if( bHeader )
2163 {
2164 Script += "#! /usr/bin/env python\n";
2165 Script += "\n";
2166 Script += "#_________________________________________\n";
2167 Script += "##########################################\n";
2168 Script += "\n";
2169#ifdef _SAGA_MSW
2170 CSG_String AppPath = SG_UI_Get_Application_Path(true); AppPath.Replace("\\", "/");
2171 Script += "# Initialize the environment...\n";
2172 Script += "\n";
2173 Script += "# Windows: Let the 'SAGA_PATH' environment variable point to\n";
2174 Script += "# the SAGA installation folder before importing 'saga_api'!\n";
2175 Script += "# This can be defined globally in the Windows system or\n";
2176 Script += "# user environment variable settings, in the 'PySAGA/__init__.py'\n";
2177 Script += "# file, or in the individual Python script itself. To do the latter\n";
2178 Script += "# just uncomment the following line and adjust the path accordingly:\n";
2179 Script += "###import os; os.environ['SAGA_PATH'] = '" + AppPath + "'\n";
2180 Script += "\n";
2181 Script += "# Windows: The most convenient way to make PySAGA available to all your\n";
2182 Script += "# Python scripts is to copy the PySAGA folder to the 'Lib/site-packages/'\n";
2183 Script += "# folder of your Python installation. If don't want to do this or if you\n";
2184 Script += "# don't have the rights to do so, you can also copy it to the folder with\n";
2185 Script += "# the Python scripts in which you want to use PySAGA, or alternatively\n";
2186 Script += "# you can add the path containing the PySAGA folder (e.g. the path to your\n";
2187 Script += "# SAGA installation) to the PYTHONPATH environment variable. To do this\n";
2188 Script += "# from within your script you can also take the following command (just\n";
2189 Script += "# uncomment the following line and adjust the path accordingly):\n";
2190 Script += "###import sys; sys.path.insert(1, '" + AppPath + "')\n";
2191 Script += "\n";
2192#endif // _SAGA_MSW
2193 Script += "# Import saga_api from PySAGA:\n";
2194 Script += "from PySAGA import saga_api\n";
2195 Script += "\n";
2196 Script += "\n";
2197 Script += "#_________________________________________\n";
2198 Script += "##########################################\n";
2199 Script += "def Run_" + Name + "(Results):\n";
2200 }
2201
2202 //-----------------------------------------------------
2203 if( bHeader ) Script += " # Get the tool:\n";
2204 Script += " Tool = saga_api.SG_Get_Tool_Library_Manager().Get_Tool('" + Get_Library() + "', '" + Get_ID() + "')\n";
2205 Script += " if not Tool:\n";
2206 Script += " saga_api.SG_UI_Msg_Add_Error('Failed to request tool: " + Get_Name() + "')\n";
2207 Script += " return False\n";
2208 Script += "\n";
2209 if( bHeader ) Script += " # Set the parameter interface:\n";
2210 Script += " Tool.Reset()\n";
2211
2212 //-------------------------------------------------
2213 _Get_Script_Python(Script, Get_Parameters(), bAllArguments);
2214
2215 for(int iParameters=0; iParameters<Get_Parameters_Count(); iParameters++)
2216 {
2217 _Get_Script_Python(Script, Get_Parameters(iParameters), bAllArguments, Get_Parameters(iParameters)->Get_Identifier());
2218 }
2219
2220 //-------------------------------------------------
2221 Script += "\n";
2222 if( bHeader ) Script += " # Execute the tool:\n";
2223 Script += " if not Tool.Execute():\n";
2224 Script += " saga_api.SG_UI_Msg_Add_Error('failed to execute tool: ' + Tool.Get_Name().c_str())\n";
2225 Script += " return False\n";
2226 Script += "\n";
2227 if( bHeader ) Script += " # Request the results:\n";
2228
2229 for(int iParameter=0; iParameter<Get_Parameters()->Get_Count(); iParameter++)
2230 {
2231 CSG_Parameter *p = Get_Parameters()->Get_Parameter(iParameter);
2232
2233 if( p->is_Output() )
2234 {
2235 CSG_String id(p->Get_Identifier()), type, ext;
2236
2237 switch( p->Get_DataObject_Type() )
2238 {
2239 case SG_DATAOBJECT_TYPE_Grid : type = "Grid" ; ext = "sg-grd-z"; break;
2240 case SG_DATAOBJECT_TYPE_Grids : type = "Grids" ; ext = "sg-gds-z"; break;
2241 case SG_DATAOBJECT_TYPE_Table : type = "Table" ; ext = "txt" ; break;
2242 case SG_DATAOBJECT_TYPE_Shapes : type = "Shapes" ; ext = "geojson" ; break;
2243 case SG_DATAOBJECT_TYPE_PointCloud: type = "PointCloud"; ext = "sg-pts-z"; break;
2244 case SG_DATAOBJECT_TYPE_TIN : type = "TIN" ; ext = "geojson" ; break;
2245 default : type = "" ; ext = "" ; break;
2246 }
2247
2248 if( p->is_DataObject() )
2249 {
2250 Script += " Data = Tool.Get_Parameter('" + id + "').as" + type + "()\n";
2251
2252 if( bHeader )
2253 {
2254 Script += " Data.Save('{:s}/{:s}.{:s}'.format(Results, Data.Get_Name(), '" + ext + "'))\n\n";
2255 }
2256 }
2257 else if( p->is_DataObject_List() )
2258 {
2259 Script += " List = Tool.Get_Parameter('" + id + "').as" + type + "List()\n";
2260 Script += " for i in range(0, List.Get_Item_Count()):\n";
2261
2262 if( bHeader )
2263 {
2264 Script += " List.Get_Item(i).Save('{:s}/{:s}_{:d}.{:s}'.format(Results, List.Get_Name(), i, '" + ext + "'))\n\n";
2265 }
2266 else
2267 {
2268 Script += " Data = List.Get_Item(i)\n";
2269 }
2270 }
2271 }
2272 }
2273
2274 //-----------------------------------------------------
2275 if( bHeader )
2276 {
2277 Script += "\n";
2278 Script += " return True\n";
2279 Script += "\n";
2280 Script += "\n";
2281 Script += "#_________________________________________\n";
2282 Script += "##########################################\n";
2283 Script += "print('This is a simple template for using a SAGA tool through Python.')\n";
2284 Script += "print('Please edit the script to make it work properly before using it!')\n";
2285 Script += "\n";
2286 Script += "# Run_" + Name + "('.')\n";
2287 Script += "\n";
2288 Script += "# job is done, free memory resources:\n";
2289 Script += "saga_api.SG_Get_Data_Manager().Delete()\n";
2290 }
2291
2292 return( Script );
2293}
2294
2295//---------------------------------------------------------
2296void CSG_Tool::_Get_Script_Python(CSG_String &Script, CSG_Parameters *pParameters, bool bAllArguments, const CSG_String &Prefix)
2297{
2298 for(int iParameter=0; iParameter<pParameters->Get_Count(); iParameter++)
2299 {
2300 CSG_Parameter *p = pParameters->Get_Parameter(iParameter);
2301
2302 if( !bAllArguments && (!p->is_Enabled(false) || p->is_Information() || !p->do_UseInCMD()) )
2303 {
2304 continue;
2305 }
2306
2307 CSG_String ID(p->Get_Identifier());
2308
2309 if( !Prefix.is_Empty() )
2310 {
2311 ID.Prepend(Prefix + ".");
2312 }
2313
2314 switch( p->Get_Type() )
2315 {
2316 default:
2317 break;
2318
2319 case PARAMETER_TYPE_Bool :
2320 Script += CSG_String::Format(" Tool.Set_Parameter('%s', %s)\n", ID.c_str(), p->asBool() ? SG_T("True") : SG_T("False"));
2321 break;
2322
2323 case PARAMETER_TYPE_Int :
2324 Script += CSG_String::Format(" Tool.Set_Parameter('%s', %d)\n", ID.c_str(), p->asInt());
2325 break;
2326
2329 Script += CSG_String::Format(" Tool.Set_Parameter('%s', %d) # '%s'\n", ID.c_str(), p->asInt(), p->asString());
2330 break;
2331
2335 Script += CSG_String::Format(" Tool.Set_Parameter('%s', '%s')\n", ID.c_str(), p->asString());
2336 break;
2337
2339 Script += CSG_String::Format(" Tool.Set_Parameter('%s', '%s')\n", ID.c_str(), SG_Color_To_Text(p->asColor()).c_str());
2340 break;
2341
2344 Script += CSG_String::Format(" Tool.Set_Parameter('%s', %g)\n", ID.c_str(), p->asDouble());
2345 break;
2346
2348 Script += CSG_String::Format(" Tool.Set_Parameter('%s.MIN', %g)\n", ID.c_str(), p->asRange()->Get_Min());
2349 Script += CSG_String::Format(" Tool.Set_Parameter('%s.MAX', %g)\n", ID.c_str(), p->asRange()->Get_Max());
2350 break;
2351
2353 if( ((CSG_Parameter_String *)p)->is_Password() )
2354 {
2355 Script += CSG_String::Format(" Tool.Set_Parameter('%s', '***')\n", ID.c_str());
2356 break;
2357 }
2358
2359 case PARAMETER_TYPE_Date :
2360 case PARAMETER_TYPE_Text :
2362 Script += CSG_String::Format(" Tool.Set_Parameter('%s', '%s')\n", ID.c_str(), p->asString());
2363 break;
2364
2366 Script += CSG_String::Format(" Tool.Set_Parameter('%s', saga_api.SG_Create_Table('table.txt'))\n", ID.c_str());
2367 break;
2368
2370 if( p->Get_Children_Count() == 0 )
2371 {
2372 Script += CSG_String::Format(" Tool.Set_Parameter('%s', saga_api.CSG_Grid_System(%g, %g, %g, %d, %d))\n", ID.c_str(),
2375 p->asGrid_System()->Get_NX (), p->asGrid_System()->Get_NY ()
2376 );
2377 }
2378 break;
2379
2380 case PARAMETER_TYPE_Grid :
2384 case PARAMETER_TYPE_TIN :
2386 if( p->is_Input() )
2387 {
2388 Script += CSG_String::Format(" Tool.Set_Parameter('%s', saga_api.SG_Get_Data_Manager().Add('%s input file%s'))\n", ID.c_str(),
2389 SG_Get_DataObject_Name(p->Get_DataObject_Type()).c_str(), p->is_Optional() ? SG_T(", optional") : SG_T("")
2390 );
2391 }
2392 else if( p->is_Output() && p->is_Optional() )
2393 {
2394 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());
2395 }
2396 break;
2397
2404 if( p->is_Input() )
2405 {
2406 Script += CSG_String::Format(" Tool.Get_Parameter('%s').asList().Add_Item('%s input list%s')\n", ID.c_str(),
2407 SG_Get_DataObject_Name(p->Get_DataObject_Type()).c_str(), p->is_Optional() ? SG_T(", optional") : SG_T("")
2408 );
2409 }
2410 break;
2411
2413 _Get_Script_Python(Script, p->asParameters(), bAllArguments, ID);
2414 break;
2415 }
2416 }
2417}
2418
2419
2421// //
2423
2424//---------------------------------------------------------
2425CSG_String CSG_Tool::_Get_Script_Python_Wrap(bool bHeader, bool bName, bool bCall, int AllArguments, bool bWrapArgs)
2426{
2427 CSG_String Arguments, Description, Code;
2428
2429 if( AllArguments >= 0 ) // if( AllArguments < 0 ) => skip arguments list
2430 {
2431 for(int i=0; i<Parameters.Get_Count(); i++) // add input that is not optional in 1st place
2432 {
2433 _Get_Script_Python_Wrap(Parameters[i], PARAMETER_INPUT , Arguments, Description, Code, bCall && bHeader, AllArguments == 0, bWrapArgs);
2434 }
2435
2436 for(int i=0; i<Parameters.Get_Count(); i++) // add optional input in 2nd place
2437 {
2438 _Get_Script_Python_Wrap(Parameters[i], PARAMETER_INPUT_OPTIONAL, Arguments, Description, Code, bCall && bHeader, AllArguments == 0, bWrapArgs);
2439 }
2440
2441 for(int i=0; i<Parameters.Get_Count(); i++) // add output
2442 {
2443 _Get_Script_Python_Wrap(Parameters[i], PARAMETER_OUTPUT , Arguments, Description, Code, bCall && bHeader, AllArguments == 0, bWrapArgs);
2444 }
2445
2446 for(int i=0; i<Parameters.Get_Count(); i++) // add options
2447 {
2448 _Get_Script_Python_Wrap(Parameters[i], 0 , Arguments, Description, Code, bCall , AllArguments == 0, bWrapArgs);
2449 }
2450 }
2451
2452 //---------------------------------------------------------
2453 CSG_String Name, Expected(Get_Name()); Expected.Replace("'", "\\'");
2454
2455 if( bName )
2456 {
2457 Name = Get_Name();
2458
2459 if( isdigit(Name[0]) ) // ...in case first letter is a numeric character, what is not allowed for Python function names!
2460 {
2461 Name.Prepend("_");
2462 }
2463
2464 Name.Replace(" ", "_");
2465 Name.Replace("(", "");
2466 Name.Replace(")", "");
2467 Name.Replace("[", "");
2468 Name.Replace("]", "");
2469 Name.Replace(".", "");
2470 Name.Replace(",", "");
2471 Name.Replace("/", "");
2472 Name.Replace("-", "");
2473 Name.Replace("'", "");
2474 Name.Replace("&", "and");
2475 }
2476 else
2477 {
2478 Name = "run_tool_" + Get_Library() + "_" + Get_ID();
2479
2480 Name.Replace(" ", "_");
2481 }
2482
2483 //---------------------------------------------------------
2484 CSG_String Script;
2485
2486 if( bCall )
2487 {
2488 if( bHeader )
2489 {
2490 Script += "from PySAGA.tools import " + Get_Library() + "\n\n";
2491
2492 if( !Code.is_Empty() )
2493 {
2494 Script += Code + "\n";
2495 }
2496 }
2497
2498 Script += Get_Library() + '.' + Name + "(" + Arguments + ")\n";
2499 }
2500 else
2501 {
2503
2504 if( bHeader )
2505 {
2506 Script += "#! /usr/bin/env python\n";
2507 Script += "from PySAGA.helper import Tool_Wrapper\n\n";
2508 }
2509
2510 Script += "def " + Name + "(" + Arguments + ", Verbose=2):\n";
2511 Script += " '''\n";
2512 Script += " " + Get_Name() + "\n";
2513 Script += " ----------\n";
2514 Script += " [" + Get_Library() + "." + Get_ID() + "]\\n\n";
2515 for(int i=0; i<_Description.Get_Count(); i++)
2516 {
2517 _Description[i].Trim_Both(); Script += " " + _Description[i] + "\\n\n";
2518 }
2519 Script += " Arguments\n";
2520 Script += " ----------\n";
2521 Script += Description + "\n";
2522 Script += " - Verbose [`integer number`] : Verbosity level, 0=silent, 1=tool name and success notification, 2=complete tool output.\\n\n";
2523 Script += " Returns\n";
2524 Script += " ----------\n";
2525 Script += " `boolean` : `True` on success, `False` on failure.\n";
2526 Script += " '''\n";
2527 Script += " Tool = Tool_Wrapper('" + Get_Library() + "', '" + Get_ID() + "', '" + Expected + "')\n";
2528 Script += " if Tool.is_Okay():\n";
2529 Script += Code;
2530 Script += " return Tool.Execute(Verbose)\n";
2531 Script += " return False\n\n";
2532 }
2533
2534 return( Script );
2535}
2536
2537//---------------------------------------------------------
2538bool 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)
2539{
2540 if( Parameter.do_UseInCMD() == false
2541 || Parameter.is_Information()
2542 || Parameter.Get_Type() == PARAMETER_TYPE_Node
2543 || Parameter.Cmp_Identifier("PARAMETERS_GRID_SYSTEM") )
2544 {
2545 return( false );
2546 }
2547
2548 if( bCall && !Parameter.is_Enabled() && !(Parameter.is_Output() && Parameter.Get_Parent() && Parameter.Get_Parent()->Cmp_Identifier("TARGET_SYSTEM")) )
2549 {
2550 return( false );
2551 }
2552
2553 //-----------------------------------------------------
2554 CSG_String ID(Parameter.Get_Identifier());
2555
2556 if( !Prefix.is_Empty() )
2557 {
2558 ID.Prepend(Prefix + ".");
2559 }
2560
2561 CSG_String Argument(ID);
2562
2563 if( Argument[0] >= '0' && Argument[0] <= '9' )
2564 {
2565 Argument.Prepend('_');
2566 }
2567
2568 Argument.Replace(".", "_");
2569 Argument.Replace("|", "_");
2570 Argument.Replace(" ", "_");
2571
2572 if( Argument.Length() > 2 )
2573 {
2574 Argument.Make_Upper();
2575 }
2576
2577 //-----------------------------------------------------
2578 if( Parameter.asParameters() ) // PARAMETER_TYPE_Parameters
2579 {
2580 bool bResult = false;
2581
2582 for(int i=0; i<(*Parameter.asParameters()).Get_Count(); i++)
2583 {
2584 if( _Get_Script_Python_Wrap((*Parameter.asParameters())[i], Constraint, Arguments, Description, Code, bCall, bOnlyNonDefaults, bWrapArgs, ID) )
2585 {
2586 bResult = true;
2587 }
2588 }
2589
2590 return( bResult );
2591 }
2592
2593 //-----------------------------------------------------
2594 if( Parameter.is_Input () && !Parameter.is_Optional() && Constraint != PARAMETER_INPUT ) { return( false ); }
2595 if( Parameter.is_Input () && Parameter.is_Optional() && Constraint != PARAMETER_INPUT_OPTIONAL ) { return( false ); }
2596 if( Parameter.is_Output() && Constraint != PARAMETER_OUTPUT ) { return( false ); }
2597 if( Parameter.is_Option() && Constraint != 0 ) { return( false ); }
2598
2599 //-----------------------------------------------------
2600 if( bCall )
2601 {
2602 CSG_String Value;
2603
2604 if( Parameter.is_DataObject() )
2605 {
2606 Value = Parameter.Get_Identifier(); Value.Make_Lower();
2607
2608 if( Parameter.is_Input() )
2609 {
2610 if( (bOnlyNonDefaults && !Parameter.asDataObject()) && Parameter.is_Optional() ) // don't add optional input that has not been set
2611 {
2612 return( false );
2613 }
2614
2615 CSG_String File(Parameter.asDataObject() && Parameter.asDataObject()->Get_File_Name(false)
2616 ? Parameter.asDataObject()->Get_File_Name(false) : SG_T("data object file")
2617 ); File.Replace("\\", "/");
2618
2619 Code += Value + " = saga_api.SG_Get_Data_Manager().Add_" + SG_Get_DataObject_Class_Name(Parameter.Get_DataObject_Type()).AfterFirst('_') + "('" + File + "') # input data object\n";
2620 }
2621 else // if( Parameter.is_Output() )
2622 {
2623 if( (bOnlyNonDefaults && !Parameter.asDataObject()) && Parameter.is_Optional() ) // don't add optional output that has not been requested
2624 {
2625 return( false );
2626 }
2627
2628 Code += Value + " = saga_api.SG_Get_Data_Manager().Add_" + SG_Get_DataObject_Class_Name(Parameter.Get_DataObject_Type()).AfterFirst('_') + "() # output data object\n";
2629 }
2630 }
2631 else if( Parameter.is_DataObject_List() )
2632 {
2633 Value = Parameter.Get_Identifier(); Value.Make_Lower();
2634
2635 if( Parameter.is_Input() )
2636 {
2637 if( (bOnlyNonDefaults && Parameter.asList()->Get_Item_Count() < 1) && Parameter.is_Optional() ) // don't add optional input that has not been set
2638 {
2639 return( false );
2640 }
2641
2642 Code += Value + " = [] # Python list with input data objects of type 'saga_api." + SG_Get_DataObject_Class_Name(Parameter.Get_DataObject_Type()) + "'\n";
2643 }
2644 else // if( Parameter.is_Output() )
2645 {
2646 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";
2647 }
2648 }
2649 else if( Parameter.is_Option() )
2650 {
2651 if( bOnlyNonDefaults && Parameter.is_Default() )
2652 {
2653 return( false );
2654 }
2655
2656 switch( Parameter.Get_Type() )
2657 {
2658 case PARAMETER_TYPE_Bool : Value = Parameter.asBool() ? "True" : "False"; break;
2659
2660 case PARAMETER_TYPE_Int : Value.Printf("%d", Parameter.asInt()); break;
2661
2663 case PARAMETER_TYPE_Degree : Value.Printf("%f", Parameter.asDouble()); break;
2664
2665 case PARAMETER_TYPE_Color : Value = SG_Color_To_Text(Parameter.asColor()); break;
2666
2668 case PARAMETER_TYPE_Text :
2669 case PARAMETER_TYPE_Date :
2676 case PARAMETER_TYPE_FilePath : Value.Printf("'%s'", Parameter.asString()); break;
2677
2679 if( !Parameter.Cmp_Identifier("TARGET_SYSTEM") )
2680 {
2681 return( false );
2682 }
2683
2684 Value.Printf("'%s'", Parameter.asGrid_System()->asString());
2685 break;
2686
2687 default : return( false );
2688 }
2689 }
2690
2691 if( !Value.is_Empty() )
2692 {
2693 if( bWrapArgs )
2694 {
2695 Arguments += !Arguments.is_Empty() ? ",\n " : "\n ";
2696 }
2697 else if( !Arguments.is_Empty() )
2698 {
2699 Arguments += ", ";
2700 }
2701
2702 Arguments += Argument + "=" + Value;
2703 }
2704
2705 return( true );
2706 }
2707
2708 //-----------------------------------------------------
2709 if( bWrapArgs )
2710 {
2711 Arguments += !Arguments.is_Empty() ? ",\n " : "\n ";
2712 }
2713 else if( !Arguments.is_Empty() )
2714 {
2715 Arguments += ", ";
2716 }
2717
2718 Arguments += Argument + "=None";
2719
2720 //-----------------------------------------------------
2721 Code += " ";
2722
2723 if( Parameter.is_Input () ) { Code += "Tool.Set_Input "; }
2724 if( Parameter.is_Output() ) { Code += "Tool.Set_Output"; }
2725 if( Parameter.is_Option() ) { Code += "Tool.Set_Option"; }
2726
2727 Code += CSG_String::Format("('%s', %s)\n", ID.c_str(), Argument.c_str());
2728
2729 //-----------------------------------------------------
2730 Description += " - " + Argument + " [`";
2731
2732 if( Parameter.is_Input() )
2733 {
2734 Description += Parameter.is_Optional() ? "optional input " : "input ";
2735 }
2736 else if( Parameter.is_Output() )
2737 {
2738 Description += "output ";
2739 }
2740
2741 Description += Parameter.Get_Type_Name() + "`] : " + Parameter.Get_Name();
2742
2744
2745 if( !s.is_Empty() )
2746 {
2747 Description += ". " + s;
2748 }
2749
2750 Description += "\n";
2751
2752 return( true );
2753}
2754
2756// //
2758
2759//---------------------------------------------------------
2760CSG_String CSG_Tool::_Get_Script_Markdown(bool bHeader, int iArguments)
2761{
2762 CSG_String Script;
2763
2764 if( bHeader )
2765 {
2766 CSG_String Menu = Get_MenuPath(true); Menu.Replace("|", " &rarr; ");
2767 CSG_Tool_Library *pLibrary = SG_Get_Tool_Library_Manager().Get_Library(this);
2768 CSG_String Category = pLibrary->Get_Category() + " &rarr; " + pLibrary->Get_Name();
2769
2770 Script += CSG_String::Format("**Tool:** %s \n", Get_Name().c_str());
2771 Script += CSG_String::Format("**Geoprocessing** &rarr; *%s*&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp; **Tools** &rarr; *%s*\n\n", Menu.c_str(), Category.c_str());
2772 }
2773
2774 Script += "|**Parameter**|**Setting**|\n";
2775 Script += "|---|---|\n";
2776
2777 //-------------------------------------------------
2778 _Get_Script_Markdown(Script, Get_Parameters(), iArguments);
2779
2780 Script.Replace("\n\n", "\n");
2781
2782 return( Script );
2783}
2784
2785
2786//---------------------------------------------------------
2787void CSG_Tool::_Get_Script_Markdown(CSG_String &Script, CSG_Parameters *pParameters, int iArguments, const CSG_String &Prefix)
2788{
2789 #define WRITE_CHILD(pChild, Prefix) Script += CSG_String::Format("|%s%s||\n", Prefix.c_str(), pChild->Get_Name().c_str());\
2790 for (int i=0; i<pChild->Get_Children_Count(); i++)\
2791 {\
2792 Script += CSG_String::Format("%s\n", pChild->Get_Child(i)->Get_Content().c_str());\
2793 }
2794
2795 CSG_MetaData Properties;
2796
2797 for(int iParameter=0; iParameter<pParameters->Get_Count(); iParameter++)
2798 {
2799 _Format_Markdown(pParameters->Get_Parameter(iParameter), Script, Properties, iArguments, Prefix);
2800 }
2801
2802 if( CSG_MetaData *pChild = Properties.Get_Child(_TL("Data Objects")) ) { WRITE_CHILD(pChild, Prefix); }
2803
2804 for (int i=0; i<Properties.Get_Children_Count(); i++)
2805 {
2806 CSG_MetaData *pChild = Properties.Get_Child(i);
2807
2808 if( pChild->Get_Name().Cmp(_TL("Data Objects")) && pChild->Get_Name().Cmp(_TL("Options")) )
2809 {
2810 WRITE_CHILD(pChild, Prefix);
2811 }
2812 }
2813
2814 if( CSG_MetaData *pChild = Properties.Get_Child(_TL("Options")) ) { WRITE_CHILD(pChild, Prefix); }
2815}
2816
2817
2818//---------------------------------------------------------
2819void CSG_Tool::_Format_Markdown(CSG_Parameter *p, CSG_String &Script, CSG_MetaData &Properties, int iArguments, CSG_String Prefix)
2820{
2821 #define CHECK_OBJECTS_NODE() pChild = Properties.Get_Child(_TL("Options"));\
2822 if( !pChild )\
2823 {\
2824 pChild = Properties.Add_Child(_TL("Options"));\
2825 }\
2826 \
2827 pRoot = pChild;
2828
2829 #define CHECK_DATA_NODE(Name) pChild = Properties.Get_Child(Name);\
2830 if( !pChild )\
2831 {\
2832 CSG_MetaData *pData = Properties.Get_Child(_TL("Data Objects"));\
2833 if( !pData )\
2834 {\
2835 Properties.Add_Child(_TL("Data Objects"));\
2836 }\
2837 pChild = Properties.Add_Child(Name);\
2838 }\
2839 \
2840 pRoot = pChild;
2841
2842 #define GET_PARENT_NODE(prt) bool bFound = false;\
2843 for (int i=0; i<Properties.Get_Children_Count(); i++)\
2844 {\
2845 CSG_MetaData *pDatatype = Properties.Get_Child(i);\
2846 for (int j=0; j<Properties.Get_Children_Count(); j++)\
2847 {\
2848 pParent = pDatatype->Get_Child(prt);\
2849 if( pParent )\
2850 {\
2851 bFound = true;\
2852 break;\
2853 }\
2854 }\
2855 if( bFound )\
2856 {\
2857 break;\
2858 }\
2859 }
2860
2861 #define FORMAT_DATASET() if( p->is_Input() )\
2862 {\
2863 CSG_String Input = p->is_Optional() ? ">" : ">>";\
2864 CSG_String s = p->asString();\
2865 if( s.Contains(_TL("not set")) || s.Contains(_TL("No objects")) ) { Bold = ""; }\
2866 s.Replace("<", "\\<");\
2867 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());\
2868 }\
2869 else if( p->is_Output() )\
2870 {\
2871 CSG_String Output = p->is_Optional() ? "\\<" : "<<";\
2872 CSG_String s = p->asString();\
2873 if( !p->is_Optional() && s.Contains(_TL("create")) ) { Bold = ""; }\
2874 else if( p->is_Optional() && (s.Contains(_TL("not set")) || s.Contains(_TL("No objects"))) ) { Bold = ""; }\
2875 s.Replace("<", "\\<");\
2876 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());\
2877 }
2878
2879 if( iArguments == 0 && !p->do_UseInCMD() )
2880 {
2881 return;
2882 }
2883 else if( iArguments == 1 && !p->do_UseInGUI() )
2884 {
2885 return;
2886 }
2887
2888 if( !p->is_Enabled(false) )
2889 {
2890 return;
2891 }
2892
2893 CSG_String Name(p->Get_Name());
2894
2895 CSG_String Bold;
2896
2897 if( !p->is_Default() )
2898 {
2899 Bold = "**";
2900 }
2901
2902 CSG_String Space = Prefix;
2903
2904 if( p->Get_Parent() != NULL )
2905 {
2906 Space += "&nbsp;&nbsp;&nbsp;";
2907 }
2908
2909 CSG_String Parameter;
2910 CSG_MetaData *pRoot = NULL, *pChild;
2911
2912 switch( p->Get_Type() )
2913 {
2914 default:
2915 break;
2916
2918 {
2919 if( p->Get_Parent() )
2920 {
2922 }
2923 else if( p->Get_Children_Count() == 0 )
2924 {
2925 CHECK_DATA_NODE(_TL("Grids"));
2926 }
2927 else for (int i=0; i<p->Get_Children_Count() && !pRoot; i++)
2928 {
2931 || p->Get_Child(i)->is_Input() )
2932 {
2933 CHECK_DATA_NODE(_TL("Grids"));
2934 }
2935 }
2936
2937 CSG_String s = p->asString();
2938 if( s.Contains(_TL("not set")) )
2939 {
2940 s.Replace("<", "\\<");
2941 Parameter += CSG_String::Format("|%s%s|%s|", Space.c_str(), Name.c_str(), s.c_str());
2942 }
2943 else
2944 {
2945 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(),
2947 p->asGrid_System()->Get_NX (), p->asGrid_System()->Get_NY (),
2949 Bold.c_str()
2950 );
2951 }
2952 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
2953 break;
2954 }
2955
2958 if( p->is_Input() )
2959 {
2960 if( !p->Get_Parent() || (p->Get_Parent()->Get_Type() == PARAMETER_TYPE_Grid_System && !p->Get_Parent()->Get_Parent()) )
2961 {
2962 CHECK_DATA_NODE(_TL("Grids"));
2963 }
2964 else
2965 {
2967 }
2969 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
2970 }
2971 break;
2972
2973 case PARAMETER_TYPE_Grid :
2975 if( !p->Get_Parent() || (p->Get_Parent()->Get_Type() == PARAMETER_TYPE_Grid_System && !p->Get_Parent()->Get_Parent()) )
2976 {
2977 CHECK_DATA_NODE(_TL("Grids"));
2978 }
2979 else
2980 {
2982 }
2984 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
2985 break;
2986
2988 if( p->is_Input() )
2989 {
2990 if( !p->Get_Parent() )
2991 {
2992 CHECK_DATA_NODE(_TL("Tables"));
2993 }
2994 else
2995 {
2997 }
2999 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3000 }
3001 break;
3002
3004 if( !p->Get_Parent() )
3005 {
3006 CHECK_DATA_NODE(_TL("Tables"));
3007 }
3008 else
3009 {
3011 }
3013 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3014 break;
3015
3017 if( p->is_Input() )
3018 {
3019 if( !p->Get_Parent() )
3020 {
3021 CHECK_DATA_NODE(_TL("Shapes"));
3022 }
3023 else
3024 {
3026 }
3028 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3029 }
3030 break;
3031
3033 if( !p->Get_Parent() )
3034 {
3035 CHECK_DATA_NODE(_TL("Shapes"));
3036 }
3037 else
3038 {
3040 }
3042 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3043 break;
3044
3046 if( p->is_Input() )
3047 {
3048 if( !p->Get_Parent() )
3049 {
3050 CHECK_DATA_NODE(_TL("TIN"));
3051 }
3052 else
3053 {
3055 }
3057 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3058 }
3059 break;
3060
3061 case PARAMETER_TYPE_TIN :
3062 if( !p->Get_Parent() )
3063 {
3064 CHECK_DATA_NODE(_TL("TIN"));
3065 }
3066 else
3067 {
3069 }
3071 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3072 break;
3073
3075 if( p->is_Input() )
3076 {
3077 if( !p->Get_Parent() )
3078 {
3079 CHECK_DATA_NODE(_TL("Point Clouds"));
3080 }
3081 else
3082 {
3084 }
3086 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3087 }
3088 break;
3089
3091 if( !p->Get_Parent() )
3092 {
3093 CHECK_DATA_NODE(_TL("Point Clouds"));
3094 }
3095 else
3096 {
3098 }
3100 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3101 break;
3102
3103 case PARAMETER_TYPE_Node :
3105 Parameter = CSG_String::Format("|%s%s||", Space.c_str(), Name.c_str());
3106 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3107 break;
3108
3109 case PARAMETER_TYPE_Bool :
3111 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());
3112 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3113 break;
3114
3115 case PARAMETER_TYPE_Int :
3117 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());
3118 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3119 break;
3120
3123 {
3125 CSG_String s = p->asString();
3126 if( s.Contains(_TL("no choice available")) ) { Bold = ""; }
3127 s.Replace("<", "\\<");
3128 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());
3129 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3130 break;
3131 }
3132
3134 {
3135 CSG_String s = p->asString();
3136 if( s.Contains(_TL("no attributes")) ) { Bold = ""; }
3137 s.Replace("<", "\\<");
3138 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());
3139 if( p->Get_Parent() != NULL && (p->Get_Parent()->is_DataObject() || p->Get_Parent()->is_DataObject_List()) )
3140 {
3141 CSG_MetaData *pParent = NULL;
3143 if( pParent )
3144 {
3145 CSG_String c = pParent->Get_Content();
3146 c += SG_T("\n") + Parameter;
3147 pParent->Set_Content(c);
3148 }
3149 }
3150 else
3151 {
3153 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3154 }
3155 break;
3156 }
3157
3160 {
3161 CSG_String s = p->asString();
3162 s.Replace("<", "\\<");
3163 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());
3164 if( p->Get_Parent() != NULL && (p->Get_Parent()->is_DataObject() || p->Get_Parent()->is_DataObject_List()) )
3165 {
3166 CSG_MetaData *pParent = NULL;
3168 if( pParent )
3169 {
3170 CSG_String c = pParent->Get_Content();
3171 c += SG_T("\n") + Parameter;
3172 pParent->Set_Content(c);
3173 }
3174 }
3175 else
3176 {
3178 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3179 }
3180 break;
3181 }
3182
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(), SG_Color_To_Text(p->asColor()).c_str(), Bold.c_str());
3186 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3187 break;
3188
3192 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());
3193 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3194 break;
3195
3198 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());
3199 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3200 break;
3201
3203 if( ((CSG_Parameter_String *)p)->is_Password() )
3204 {
3206 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());
3207 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3208 break;
3209 }
3210
3211 case PARAMETER_TYPE_Date :
3212 case PARAMETER_TYPE_Text :
3214 {
3216 CSG_String s = p->asString();
3217 s.Replace("\\", "/");
3218 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());
3219 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3220 break;
3221 }
3222
3225 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());
3226 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3227 break;
3228
3231 Parameter = CSG_String::Format("|%s%s||\n", Space.c_str(), Name.c_str());
3232 CSG_String Prefix = Space + "&nbsp;&nbsp;&nbsp;";
3233 _Get_Script_Markdown(Parameter, p->asParameters(), iArguments, Prefix);
3234 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3235 break;
3236 }
3237
3238 return;
3239}
3240
3242// //
3243// //
3244// //
3246
3247//---------------------------------------------------------
3249{
3250 CSG_MetaData History;
3251
3252 History.Set_Name(SG_META_HISTORY);
3253 History.Add_Property("saga-version", SAGA_VERSION);
3254
3255 if( Depth )
3256 {
3257 CSG_MetaData *pTool = History.Add_Child("TOOL");
3258
3259 pTool->Add_Property("library", Get_Library());
3260 pTool->Add_Property("id" , Get_ID ());
3261 pTool->Add_Property("name" , Get_Name ());
3262
3263 Parameters.Set_History(*pTool);
3264
3266
3267 CSG_MetaData *pOutput = pTool->Add_Child("OUTPUT");
3268 pOutput->Add_Property("type", "");
3269 pOutput->Add_Property("id" , "");
3270 pOutput->Add_Property("name", "");
3271
3272 pTool->Del_Children(Depth, SG_T("TOOL"));
3273 }
3274
3275 return( History );
3276}
3277
3278//---------------------------------------------------------
3279bool CSG_Tool::Set_History(CSG_Data_Object *pDataObject, int Depth)
3280{
3281 if( pDataObject )
3282 {
3283 CSG_MetaData History(Get_History(Depth));
3284
3285 CSG_MetaData *pOutput = History("TOOL") ? History["TOOL"]("OUTPUT") : NULL;
3286
3287 if( pOutput )
3288 {
3289 pOutput->Set_Property("name", pDataObject->Get_Name());
3290 }
3291
3292 pDataObject->Get_History() = History;
3293
3294 return( true );
3295 }
3296
3297 return( false );
3298}
3299
3300//---------------------------------------------------------
3301void CSG_Tool::_Set_Output_History(void)
3302{
3304
3305 for(int j=-1; j<Get_Parameters_Count(); j++)
3306 {
3307 CSG_Parameters *pParameters = j < 0 ? &Parameters : Get_Parameters(j);
3308
3309 for(int i=0; i<pParameters->Get_Count(); i++)
3310 {
3311 CSG_Parameter *pParameter = pParameters->Get_Parameter(i);
3312
3313 if( pParameter->is_Output() )//&& (pParameter->is_Enabled() || !has_GUI()) )
3314 {
3315 DataObject_Set_History(pParameter, &History);
3316 }
3317 }
3318 }
3319}
3320
3321//---------------------------------------------------------
3323{
3324 if( !pParameter && !((pParameter->is_DataObject() && pParameter->asDataObject()) || !(pParameter->is_DataObject_List() && pParameter->asList()->Get_Item_Count() > 0)) )
3325 {
3326 return( false );
3327 }
3328
3329 //-----------------------------------------------------
3330 CSG_MetaData History;
3331
3332 if( !pHistory )
3333 {
3334 History = Get_History(SG_Get_History_Depth()); pHistory = &History;
3335 }
3336
3337 //-----------------------------------------------------
3338 CSG_MetaData *pOutput = pHistory->Get_Child("TOOL") ? pHistory->Get_Child("TOOL")->Get_Child("OUTPUT") : NULL;
3339
3340 if( pOutput )
3341 {
3342 pOutput->Set_Property("type", pParameter->Get_Type_Identifier());
3343 pOutput->Set_Property("id" , pParameter->Get_Identifier ());
3344 pOutput->Set_Property("name", pParameter->Get_Name ());
3345 }
3346
3347 //-----------------------------------------------------
3348 if( pParameter->is_DataObject() && pParameter->asDataObject() )
3349 {
3350 if( pOutput )
3351 {
3352 pOutput->Set_Content(pParameter->asDataObject()->Get_Name());
3353 }
3354
3355 pParameter->asDataObject()->Get_History().Assign(*pHistory);
3356 }
3357
3358 //-----------------------------------------------------
3359 else if( pParameter->is_DataObject_List() )
3360 {
3361 for(int j=0; j<pParameter->asList()->Get_Item_Count(); j++)
3362 {
3363 if( pOutput )
3364 {
3365 pOutput->Set_Content(pParameter->asList()->Get_Item(j)->Get_Name());
3366 }
3367
3368 pParameter->asList()->Get_Item(j)->Get_History().Assign(*pHistory);
3369 }
3370 }
3371
3372 //-----------------------------------------------------
3373 return( true );
3374}
3375
3376
3378// //
3379// //
3380// //
3382
3383//---------------------------------------------------------
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)
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)
void SG_UI_StatusBar_Set_Text(const CSG_String &Text)
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:1635
@ SG_UI_MSG_STYLE_SUCCESS
Definition api_core.h:1634
@ SG_UI_MSG_STYLE_BOLD
Definition api_core.h:1632
@ SG_UI_MSG_STYLE_NORMAL
Definition api_core.h:1631
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:1648
@ SG_UI_DATAOBJECT_UPDATE
Definition api_core.h:1647
SAGA_API_DLL_EXPORT bool SG_Dir_Exists(const CSG_String &Directory)
Definition api_file.cpp:976
@ SG_DATATYPE_String
Definition api_core.h:1055
#define SG_Char
Definition api_core.h:536
#define _TL(s)
Definition api_core.h:1618
@ SG_FILE_ENCODING_UTF8
Definition api_core.h:552
@ SG_FILE_R
Definition api_core.h:1160
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:600
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:138
bool Assign(const CSG_MetaData &MetaData, bool bAddChildren=true)
Definition metadata.cpp:780
bool Del_Children(int Depth=0, const SG_Char *Name=NULL)
Definition metadata.cpp:381
int Get_Children_Count(void) const
Definition metadata.h:154
CSG_MetaData * Get_Child(int Index) const
Definition metadata.h:155
bool Set_Property(const CSG_String &Name, const CSG_String &Value, bool bAddIfNotExists=true)
Definition metadata.cpp:638
bool Add_Children(const CSG_MetaData &MetaData)
Definition metadata.cpp:359
const CSG_String & Get_Content(void) const
Definition metadata.h:139
void Set_Name(const CSG_String &Name)
Definition metadata.h:136
void Set_Content(const CSG_String &Content)
Definition metadata.h:146
CSG_MetaData * Add_Child(void)
Definition metadata.cpp:166
bool Add_Property(const CSG_String &Name, const CSG_String &Value)
Definition metadata.cpp:582
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:725
bool Set_Value(int Field, const CSG_String &Value)
bool Create(void)
Definition table.cpp:153
sLong Get_Count(void) const
Definition table.h:410
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:412
int Get_Field_Count(void) const
Definition table.h:371
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:1687
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:1702
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:1712
CSG_MetaData Get_History(int Depth=-1)
Definition tool.cpp:3248
bool Settings_Pop(void)
Definition tool.cpp:938
static bool Process_Get_Okay(bool bBlink=false)
Definition tool.cpp:1139
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:1725
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:1544
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:1514
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:1766
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:1282
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:1330
static bool DataObject_Classify_Unique(CSG_Data_Object *pDataObject, int Field=-1, int Classes_Max=1024, int Colors=-1)
Definition tool.cpp:1484
static void Process_Set_Text(const CSG_String &Text)
Definition tool.cpp:1145
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:1584
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:1524
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:1567
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:1298
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:1259
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:1655
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:1303
bool DataObject_Update_All(void)
Definition tool.cpp:1108
void Set_Callback(bool bActive=true)
Definition tool.cpp:863
bool Reset_Manager(void)
Definition tool.cpp:1677
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:1453
bool Set_History(CSG_Data_Object *pDataObject, int Depth=-1)
Definition tool.cpp:3279
bool Execute(bool bAddHistory=false)
Definition tool.cpp:560
static bool DataObject_Get_Colors(CSG_Data_Object *pDataObject, CSG_Colors &Colors)
Definition tool.cpp:1277
void Message_Fmt(const char *Format,...)
Definition tool.cpp:1208
static bool DataObject_Set_Parameter(CSG_Data_Object *pDataObject, CSG_Parameter *pParameter)
Definition tool.cpp:1337
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:1464
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:1430
static bool DataObject_Classify_Natural(CSG_Data_Object *pDataObject, int Field=-1, int Classes=10, int Colors=-1)
Definition tool.cpp:1534
static bool DataObject_Classify_Equal(CSG_Data_Object *pDataObject, int Field=-1, int Classes=10, int Colors=-1)
Definition tool.cpp:1494
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:1441
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:3322
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:1041
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:1195
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:1504
bool DataObject_Add(CSG_Data_Object *pDataObject, bool bUpdate=false)
Definition tool.cpp:1092
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:1480
#define WRITE_CHILD(pChild, Prefix)
#define INIT_STRETCH_OPTIONS(method)
Definition tool.cpp:1417
#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)