SAGA API Version 9.14
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 = CSG_Environment::Get_Application_Name().Cmp("saga_gui") == 0;
76 m_bCMD = CSG_Environment::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 {
1101 SG_UI_DataObject_Add (pDataObject);
1102
1104 }
1105
1106 return( true );
1107}
1108
1109//---------------------------------------------------------
1111{
1112 for(int i=0; i<Parameters.Get_Count(); i++)
1113 {
1114 if( Parameters(i)->is_Output() )
1115 {
1116 if( Parameters(i)->is_DataObject() )
1117 {
1118 DataObject_Update(Parameters(i)->asDataObject(), false);
1119 }
1120 else if( Parameters(i)->is_DataObject_List() )
1121 {
1122 for(int j=0; j<Parameters(i)->asList()->Get_Item_Count(); j++)
1123 {
1124 DataObject_Update(Parameters(i)->asList()->Get_Item(j), false);
1125 }
1126 }
1127 }
1128 }
1129
1130 return( true );
1131}
1132
1133
1135// //
1136// Static Data Message/Progress Functions //
1137// //
1139
1140//---------------------------------------------------------
1142{
1143 return( SG_UI_Process_Get_Okay(bBlink) );
1144}
1145
1146//---------------------------------------------------------
1148{
1150}
1151
1152//---------------------------------------------------------
1153void CSG_Tool::Process_Set_Text(const char *Format, ...)
1154{
1155 wxString _s; va_list argptr;
1156
1157 #ifdef _SAGA_LINUX
1158 // workaround as we only use wide characters
1159 // since wx 2.9.4 so interpret strings as multibyte
1160 wxString _Format(Format); _Format.Replace("%s", "%ls"); va_start(argptr, _Format);
1161 _s.PrintfV(_Format, argptr);
1162 #else
1163 va_start(argptr, Format);
1164 _s.PrintfV(Format, argptr);
1165 #endif
1166
1167 va_end(argptr);
1168
1169 CSG_String s(&_s);
1170
1172}
1173
1174//---------------------------------------------------------
1175void CSG_Tool::Process_Set_Text(const wchar_t *Format, ...)
1176{
1177 wxString _s; va_list argptr;
1178
1179 #ifdef _SAGA_LINUX
1180 // workaround as we only use wide characters
1181 // since wx 2.9.4 so interpret strings as multibyte
1182 wxString _Format(Format); _Format.Replace("%s", "%ls"); va_start(argptr, _Format);
1183 _s.PrintfV(_Format, argptr);
1184 #else
1185 va_start(argptr, Format);
1186 _s.PrintfV(Format, argptr);
1187 #endif
1188
1189 va_end(argptr);
1190
1191 CSG_String s(&_s);
1192
1194}
1195
1196//---------------------------------------------------------
1197void CSG_Tool::Message_Add(const CSG_String &Text, bool bNewLine)
1198{
1199 SG_UI_Msg_Add_Execution(Text, bNewLine);
1200
1201 if( bNewLine )
1202 {
1203 m_Execution_Info += "\n";
1204 }
1205
1206 m_Execution_Info += Text;
1207}
1208
1209//---------------------------------------------------------
1210void CSG_Tool::Message_Fmt(const char *Format, ...)
1211{
1212 wxString _s; va_list argptr;
1213
1214 #ifdef _SAGA_LINUX
1215 // workaround as we only use wide characters
1216 // since wx 2.9.4 so interpret strings as multibyte
1217 wxString _Format(Format); _Format.Replace("%s", "%ls"); va_start(argptr, _Format);
1218 _s.PrintfV(_Format, argptr);
1219 #else
1220 va_start(argptr, Format);
1221 _s.PrintfV(Format, argptr);
1222 #endif
1223
1224 va_end(argptr);
1225
1226 CSG_String s(&_s);
1227
1228 Message_Add(s, false);
1229}
1230
1231//---------------------------------------------------------
1232void CSG_Tool::Message_Fmt(const wchar_t *Format, ...)
1233{
1234 wxString _s; va_list argptr;
1235
1236 #ifdef _SAGA_LINUX
1237 // workaround as we only use wide characters
1238 // since wx 2.9.4 so interpret strings as multibyte
1239 wxString _Format(Format); _Format.Replace("%s", "%ls"); va_start(argptr, _Format);
1240 _s.PrintfV(_Format, argptr);
1241 #else
1242 va_start(argptr, Format);
1243 _s.PrintfV(Format, argptr);
1244 #endif
1245
1246 va_end(argptr);
1247
1248 CSG_String s(&_s);
1249
1250 Message_Add(s, false);
1251}
1252
1253
1255// //
1256// Static Data Object Property Functions //
1257// //
1259
1260//---------------------------------------------------------
1262{
1263 return( SG_UI_DataObject_Update(pDataObject, Show, NULL) );
1264}
1265
1266bool CSG_Tool::DataObject_Update(CSG_Data_Object *pDataObject, double Minimum, double Maximum, int Show)
1267{
1269
1270 return( DataObject_Get_Parameters(pDataObject, P)
1271 && P.Set_Parameter("STRETCH" , 3 ) // manual
1272 && P.Set_Parameter("STRETCH_RANGE.MIN", Minimum)
1273 && P.Set_Parameter("STRETCH_RANGE.MAX", Maximum)
1274 && SG_UI_DataObject_Update(pDataObject, Show, &P)
1275 );
1276}
1277
1278//---------------------------------------------------------
1280{
1281 return( SG_UI_DataObject_Colors_Get(pDataObject, &Colors) );
1282}
1283
1285{
1286 CSG_Colors c; return( c.Create(Colors) && SG_UI_DataObject_Colors_Set(pDataObject, &c) );
1287}
1288
1289bool CSG_Tool::DataObject_Set_Colors(CSG_Data_Object *pDataObject, int nColors, int Colors, bool bRevert)
1290{
1291 CSG_Colors c; return( c.Set_Predefined(Colors, bRevert, nColors) && SG_UI_DataObject_Colors_Set(pDataObject, &c) );
1292}
1293
1294bool CSG_Tool::DataObject_Set_Colors(CSG_Data_Object *pDataObject, const CSG_String &Colors, int nColors, bool bRevert)
1295{
1296 CSG_Colors c; return( c.Set_Predefined(Colors, bRevert, nColors) && SG_UI_DataObject_Colors_Set(pDataObject, &c) );
1297}
1298
1299//---------------------------------------------------------
1301{
1302 CSG_Parameter *pParameter = DataObject_Get_Parameter(pDataObject, "CLASSIFIED_LUT");
1303
1304 return( pParameter ? pParameter->asTable() : NULL );
1305}
1306
1308{
1309 CSG_Table *pLUT = DataObject_Get_Classification(pDataObject);
1310
1311 return( pLUT && LUT.Create(*pLUT) );
1312}
1313
1314bool CSG_Tool::DataObject_Set_Classification(CSG_Data_Object *pDataObject, const CSG_Table &LUT, int Field, bool bSetClassify)
1315{
1316 CSG_Parameter *pParameter = DataObject_Get_Parameter(pDataObject, "CLASSIFIED_LUT");
1317
1318 if( pParameter && pParameter->asTable() && pParameter->asTable()->Assign_Values(LUT) )
1319 {
1320 DataObject_Set_Parameter(pDataObject, pParameter);
1321
1322 if( Field >= 0 )
1323 {
1324 DataObject_Set_Parameter(pDataObject, "CLASSIFIED_FIELD", Field);
1325 }
1326
1327 if( bSetClassify )
1328 {
1329 DataObject_Set_Parameter(pDataObject, "COLOR_SYMBOLS", 1); // Classification
1330 }
1331
1332 return( true );
1333 }
1334
1335 return( false );
1336}
1337
1338bool CSG_Tool::DataObject_Set_Classification(CSG_Data_Object *pDataObject, CSG_Table *pLUT, int Field, bool bSetClassify)
1339{
1340 return(pLUT && DataObject_Set_Classification(pDataObject, CSG_Table(*pLUT), Field, bSetClassify) );
1341}
1342
1343//---------------------------------------------------------
1345{
1346 CSG_Parameter *pParameter = DataObject_Get_Parameter(pDataObject, "COLOR_SYMBOLS");
1347
1348 if( pParameter && pParameter->asInt() >= (int)ESymbology::SINGLE && pParameter->asInt() < (int)ESymbology::UNDEFINED )
1349 {
1350 ESymbology Value = (ESymbology)pParameter->asInt();
1351
1352 if( pDataObject->asPointCloud() && Value == ESymbology::COMPOSITE ) { Value = ESymbology::RGB; } // point clouds have rgb option but skip the composite one!
1353
1354 return( Value );
1355 }
1356
1357 return( ESymbology::UNDEFINED );
1358}
1359
1361{
1362 if( pDataObject )
1363 {
1364 if( pDataObject->asPointCloud() && Symbology == ESymbology::RGB ) { Symbology = ESymbology::COMPOSITE; } // point clouds have rgb option but skip the composite one!
1365
1366 return( DataObject_Set_Parameter(pDataObject, "COLOR_SYMBOLS", (int)Symbology) );
1367 }
1368
1369 return( false );
1370}
1371
1372//---------------------------------------------------------
1377
1382
1384{
1385 if( pDataObject == pCopy )
1386 {
1387 return( true );
1388 }
1389
1391
1392 if( DataObject_Get_Parameters(pCopy, P) )
1393 {
1394 P.Del_Parameter("OBJECT_NODATA" );
1395 P.Del_Parameter("OBJECT_Z_FACTOR");
1396 P.Del_Parameter("OBJECT_Z_OFFSET");
1397
1398 return( DataObject_Set_Parameters(pDataObject, P) );
1399 }
1400
1401 return( false );
1402}
1403
1404//---------------------------------------------------------
1406{
1407 static CSG_Parameters P;
1408
1409 return( DataObject_Get_Parameters(pDataObject, P) ? P(ID) : NULL );
1410}
1411
1413{
1415
1416 return( P._Add(pParameter) != NULL && DataObject_Set_Parameters(pDataObject, P) );
1417}
1418
1420{
1421 CSG_Parameter *pParameter = DataObject_Get_Parameter(pCopy, ID);
1422
1423 return( DataObject_Set_Parameter(pDataObject, pParameter) );
1424}
1425
1426bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, int Value)
1427{
1429
1430 if( DataObject_Get_Parameters(pDataObject, P) && P(ID) )
1431 {
1432 return( P(ID)->Set_Value(Value) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1433 }
1434
1435 return( false );
1436}
1437
1438bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, double Value)
1439{
1441
1442 if( DataObject_Get_Parameters(pDataObject, P) && P(ID) )
1443 {
1444 return( P(ID)->Set_Value(Value) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1445 }
1446
1447 return( false );
1448}
1449
1450bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, void *Value)
1451{
1453
1454 if( DataObject_Get_Parameters(pDataObject, P) && P(ID) )
1455 {
1456 return( P(ID)->Set_Value(Value) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1457 }
1458
1459 return( false );
1460}
1461
1462bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, const SG_Char *Value)
1463{
1465
1466 if( DataObject_Get_Parameters(pDataObject, P) && P(ID) )
1467 {
1468 return( P(ID)->Set_Value(Value) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1469 }
1470
1471 return( false );
1472}
1473
1474bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, double loVal, double hiVal) // Range Parameter
1475{
1477
1478 if( DataObject_Get_Parameters(pDataObject, P) && P(ID) && P(ID)->Get_Type() == PARAMETER_TYPE_Range )
1479 {
1480 return( P(ID)->asRange()->Set_Range(loVal, hiVal) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1481 }
1482
1483 return( false );
1484}
1485
1486
1488// //
1490
1491//---------------------------------------------------------
1492#define INIT_STRETCH_OPTIONS(method) { if( !pDataObject || (pDataObject->asTable(true) && (Field < 0 || Field >= pDataObject->asTable(true)->Get_Field_Count())) ) { return( false ); }\
1493 if( Colors >= 0 ) { DataObject_Set_Colors(pDataObject, -1, Colors); }\
1494 DataObject_Set_Parameter(pDataObject, "COLOR_SYMBOLS" , 3); /* graduated colors */\
1495 DataObject_Set_Parameter(pDataObject, "STRETCH" , method);\
1496 DataObject_Set_Parameter(pDataObject, "STRETCH_INTERVALS" , Interval_Mode);\
1497 DataObject_Set_Parameter(pDataObject, "STRETCH_INTERVALS_LOG", Interval_Log );\
1498 if( pDataObject->asTable(true) )\
1499 { DataObject_Set_Parameter(pDataObject, "STRETCH_FIELD" , Field);\
1500 DataObject_Set_Parameter(pDataObject, "STRETCH_NORMALIZE", pDataObject->asTable(true)->Get_Field_Count());\
1501 }\
1502}
1503
1504//---------------------------------------------------------
1505bool 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)
1506{
1508
1509 DataObject_Set_Parameter(pDataObject, "STRETCH_LINEAR.MIN", Minimum);
1510 DataObject_Set_Parameter(pDataObject, "STRETCH_LINEAR.MAX", Maximum);
1511
1512 return( bUpdateNow ? DataObject_Update(pDataObject) : true );
1513}
1514
1515//---------------------------------------------------------
1516bool 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)
1517{
1519
1520 DataObject_Set_Parameter(pDataObject, "STRETCH_STDDEV" , StdDev );
1521 DataObject_Set_Parameter(pDataObject, "STRETCH_STDDEV_RANGE", bKeepInRange);
1522 DataObject_Update(pDataObject);
1523
1524 return( bUpdateNow ? DataObject_Update(pDataObject) : true );
1525}
1526
1527//---------------------------------------------------------
1528bool 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)
1529{
1531
1532 DataObject_Set_Parameter(pDataObject, "STRETCH_PERCENT.MIN", Minimum);
1533 DataObject_Set_Parameter(pDataObject, "STRETCH_PERCENT.MAX", Maximum);
1534
1535 return( bUpdateNow ? DataObject_Update(pDataObject) : true );
1536}
1537
1538//---------------------------------------------------------
1539bool 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)
1540{
1542
1543 DataObject_Set_Parameter(pDataObject, "STRETCH_RANGE.MIN", Minimum);
1544 DataObject_Set_Parameter(pDataObject, "STRETCH_RANGE.MAX", Maximum);
1545
1546 return( bUpdateNow ? DataObject_Update(pDataObject) : true );
1547}
1548
1549
1551// //
1553
1554//---------------------------------------------------------
1555#define INIT_CLASSIFY_OPTIONS(method) if( !pDataObject || (pDataObject->asTable(true) && (Field < 0 || Field >= pDataObject->asTable(true)->Get_Field_Count())) ) { return( false ); }\
1556 CSG_MetaData Options; Options.Add_Child("METHOD", method); Options.Add_Child("COLORS", Colors); Options.Add_Child("FIELD", Field);
1557
1558//---------------------------------------------------------
1559bool CSG_Tool::DataObject_Classify_Unique(CSG_Data_Object *pDataObject, int Field, int maxClasses, int Colors)
1560{
1562
1563 Options.Add_Child("MAXCLASSES", maxClasses);
1564
1565 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1566}
1567
1568//---------------------------------------------------------
1569bool CSG_Tool::DataObject_Classify_Equal(CSG_Data_Object *pDataObject, int Field, int Classes, int Colors)
1570{
1572
1573 Options.Add_Child("CLASSES", Classes);
1574
1575 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1576}
1577
1578//---------------------------------------------------------
1579bool CSG_Tool::DataObject_Classify_Defined(CSG_Data_Object *pDataObject, int Field, double Interval, bool bOffset, double Offset, int Colors)
1580{
1582
1583 Options.Add_Child("INTERVAL", Interval); if( bOffset ) { Options.Add_Child("OFFSET", Offset); }
1584
1585 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1586}
1587
1588//---------------------------------------------------------
1589bool CSG_Tool::DataObject_Classify_Quantile(CSG_Data_Object *pDataObject, int Field, int Classes, bool bHistogram, int Colors)
1590{
1592
1593 Options.Add_Child("CLASSES", Classes); Options.Add_Child("HISTOGRAM", bHistogram ? 1 : 0);
1594
1595 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1596}
1597
1598//---------------------------------------------------------
1599bool CSG_Tool::DataObject_Classify_Geometric(CSG_Data_Object *pDataObject, int Field, int Classes, bool bIncreasing, int Colors)
1600{
1602
1603 Options.Add_Child("CLASSES", Classes); Options.Add_Child("INCREASING", bIncreasing ? 1 : 0);
1604
1605 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1606}
1607
1608//---------------------------------------------------------
1609bool CSG_Tool::DataObject_Classify_Natural(CSG_Data_Object *pDataObject, int Field, int Classes, int Colors)
1610{
1612
1613 Options.Add_Child("CLASSES", Classes);
1614
1615 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1616}
1617
1618//---------------------------------------------------------
1619bool CSG_Tool::DataObject_Classify_StdDev(CSG_Data_Object *pDataObject, int Field, double StdDev, double StdDev_Max, int Colors)
1620{
1622
1623 Options.Add_Child("STDDEV", StdDev); Options.Add_Child("STDDEV_MAX", StdDev_Max);
1624
1625 return( SG_UI_DataObject_Classify(pDataObject, Options) );
1626}
1627
1628
1630// //
1631// //
1632// //
1634
1635//---------------------------------------------------------
1639//---------------------------------------------------------
1640CSG_Parameter * CSG_Tool::Get_Parameter(const char *ID) const { return( Get_Parameter(CSG_String(ID)) ); }
1641CSG_Parameter * CSG_Tool::Get_Parameter(const wchar_t *ID) const { return( Get_Parameter(CSG_String(ID)) ); }
1643{
1644 CSG_Parameter *pParameter = Parameters(ID);
1645
1646 for(int i=0; !pParameter && i<Get_Parameters_Count(); i++)
1647 {
1648 pParameter = Get_Parameters(i)->Get_Parameter(ID);
1649 }
1650
1651 return( pParameter );
1652}
1653
1654//---------------------------------------------------------
1658//---------------------------------------------------------
1659bool CSG_Tool::Set_Parameter(const CSG_String &ID, CSG_Parameter *pValue) { return( Parameters.Set_Parameter(ID, pValue) ); }
1660bool CSG_Tool::Set_Parameter(const char *ID, CSG_Parameter *pValue) { return( Parameters.Set_Parameter(ID, pValue) ); }
1661bool CSG_Tool::Set_Parameter(const wchar_t *ID, CSG_Parameter *pValue) { return( Parameters.Set_Parameter(ID, pValue) ); }
1662
1663//---------------------------------------------------------
1667//---------------------------------------------------------
1668bool CSG_Tool::Set_Parameter(const CSG_String &ID, int Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1669bool CSG_Tool::Set_Parameter(const char *ID, int Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1670bool CSG_Tool::Set_Parameter(const wchar_t *ID, int Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1671
1672//---------------------------------------------------------
1676//---------------------------------------------------------
1677bool CSG_Tool::Set_Parameter(const CSG_String &ID, double Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1678bool CSG_Tool::Set_Parameter(const char *ID, double Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1679bool CSG_Tool::Set_Parameter(const wchar_t *ID, double Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1680
1681//---------------------------------------------------------
1685//---------------------------------------------------------
1686bool CSG_Tool::Set_Parameter(const CSG_String &ID, void *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1687bool CSG_Tool::Set_Parameter(const char *ID, void *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1688bool CSG_Tool::Set_Parameter(const wchar_t *ID, void *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1689
1690//---------------------------------------------------------
1694//---------------------------------------------------------
1695bool CSG_Tool::Set_Parameter(const CSG_String &ID, const CSG_String &Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1696bool CSG_Tool::Set_Parameter(const char *ID, const CSG_String &Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1697bool CSG_Tool::Set_Parameter(const wchar_t *ID, const CSG_String &Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1698
1699//---------------------------------------------------------
1703//---------------------------------------------------------
1704bool CSG_Tool::Set_Parameter(const CSG_String &ID, const char *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1705bool CSG_Tool::Set_Parameter(const char *ID, const char *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1706bool CSG_Tool::Set_Parameter(const wchar_t *ID, const char *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1707
1708//---------------------------------------------------------
1712//---------------------------------------------------------
1713bool CSG_Tool::Set_Parameter(const CSG_String &ID, const wchar_t *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1714bool CSG_Tool::Set_Parameter(const char *ID, const wchar_t *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1715bool CSG_Tool::Set_Parameter(const wchar_t *ID, const wchar_t *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1716
1717//---------------------------------------------------------
1722//---------------------------------------------------------
1723bool CSG_Tool::Set_Parameter(const CSG_String &ID, const CSG_Grid_System &System) { return( Parameters.Set_Parameter(ID, System) ); }
1724bool CSG_Tool::Set_Parameter(const char *ID, const CSG_Grid_System &System) { return( Parameters.Set_Parameter(ID, System) ); }
1725bool CSG_Tool::Set_Parameter(const wchar_t *ID, const CSG_Grid_System &System) { return( Parameters.Set_Parameter(ID, System) ); }
1726
1727
1729// //
1730// //
1731// //
1733
1734//---------------------------------------------------------
1740bool CSG_Tool::Reset(bool bManager)
1741{
1743
1744 if( bManager )
1745 {
1746 Reset_Manager();
1747 }
1748
1749 for(int i=0; i<Get_Parameters_Count(); i++)
1750 {
1752 }
1753
1754 return( Parameters.Restore_Defaults(true) );
1755}
1756
1757//---------------------------------------------------------
1763{
1764 return( Set_Manager(&SG_Get_Data_Manager()) );
1765}
1766
1767//---------------------------------------------------------
1773{
1774 for(int i=0; i<Get_Parameters_Count(); i++)
1775 {
1777 }
1778
1779 return( Parameters.Reset_Grid_System() );
1780}
1781
1782//---------------------------------------------------------
1788{
1789 return( Parameters.Set_Grid_System(System) );
1790}
1791
1792//---------------------------------------------------------
1798{
1799 return( Parameters.Get_Grid_System() );
1800}
1801
1802
1804// //
1805// //
1806// //
1808
1809//---------------------------------------------------------
1811{
1812 _Update_Parameter_States(&Parameters);
1813
1814 for(int i=0; i<Get_Parameters_Count(); i++)
1815 {
1816 _Update_Parameter_States(Get_Parameters(i));
1817 }
1818
1819 return( true );
1820}
1821
1822//---------------------------------------------------------
1823void CSG_Tool::_Update_Parameter_States(CSG_Parameters *pParameters)
1824{
1825 if( pParameters )
1826 {
1827 for(int i=0; i<pParameters->Get_Count(); i++)
1828 {
1829 CSG_Parameter *pParameter = pParameters->Get_Parameter(i);
1830
1831 if( pParameter->Get_Type() == PARAMETER_TYPE_Parameters )
1832 {
1833 _Update_Parameter_States(pParameter->asParameters());
1834 }
1835 else
1836 {
1837 On_Parameters_Enable(pParameters, pParameter);
1838 }
1839 }
1840 }
1841}
1842
1843
1845// //
1846// Script //
1847// //
1849
1850//---------------------------------------------------------
1851CSG_String CSG_Tool::Get_Script(Script_Format Format, bool bHeader, int Arguments, bool bWrapArgs)
1852{
1853 switch( Format )
1854 {
1855 case Script_Format::CMD_Shell : return( _Get_Script_CMD ( bHeader, Arguments > 0, bWrapArgs, false ) );
1856 case Script_Format::CMD_Batch : return( _Get_Script_CMD ( bHeader, Arguments > 0, bWrapArgs, true ) );
1857 case Script_Format::CMD_Usage : return( _Get_Script_CMD_Usage ( ) );
1858
1859 case Script_Format::Toolchain : return( CSG_Tool_Chain::Get_Script(this, bHeader, Arguments > 0 ) );
1860
1861 case Script_Format::Python : return( _Get_Script_Python ( bHeader, Arguments > 0 ) );
1862
1863 case Script_Format::Python_Wrapper_Func_Name : return( _Get_Script_Python_Wrap ( bHeader, true , false, 1, bWrapArgs ) );
1864 case Script_Format::Python_Wrapper_Func_ID : return( _Get_Script_Python_Wrap ( bHeader, false, false, 1, bWrapArgs ) );
1865
1866 case Script_Format::Python_Wrapper_Call_Name : return( _Get_Script_Python_Wrap ( bHeader, true , true , Arguments, bWrapArgs ) );
1867 case Script_Format::Python_Wrapper_Call_ID : return( _Get_Script_Python_Wrap ( bHeader, false, true , Arguments, bWrapArgs ) );
1868
1869 case Script_Format::Markdown_Table : return( _Get_Script_Markdown ( bHeader, Arguments ) );
1870 }
1871
1872 return( "" );
1873}
1874
1875
1877// //
1879
1880//---------------------------------------------------------
1881CSG_String CSG_Tool::_Get_Script_CMD(bool bHeader, bool bAllArguments, bool bWrapArgs, bool bBatch)
1882{
1883 CSG_String Script;
1884
1885 if( bHeader )
1886 {
1887 if( bBatch ) // DOS/Windows Batch Script
1888 {
1889 Script += "@ECHO OFF\n\n";
1890 Script += "PUSHD %~dp0\n\n";
1891 Script += "REM SET SAGA_TLB=C:\\MyTools\n\n";
1892 Script += "SET SAGA_CMD=" + CSG_Environment::Get_Application_Path(true) + "\\saga_cmd.exe\n\n";
1893 Script += "REM Tool: " + Get_Name() + "\n\n";
1894 Script += "%SAGA_CMD%";
1895 }
1896 else // Bash Shell Script
1897 {
1898 Script += "#!/bin/bash\n\n";
1899 Script += "# export SAGA_TLB=~/mytools\n\n";
1900 Script += "# tool: " + Get_Name() + "\n\n";
1901 Script += "saga_cmd";
1902 }
1903 }
1904 else
1905 {
1906 Script += "saga_cmd";
1907 }
1908
1909 //-----------------------------------------------------
1910 Script += Get_Library().Contains(" ") // white space? use quotation marks!
1911 ? " \"" + Get_Library() + "\""
1912 : " " + Get_Library();
1913
1914 Script += Get_ID().Contains (" ") // white space? use quotation marks!
1915 ? " \"" + Get_ID () + "\""
1916 : " " + Get_ID ();
1917
1918 _Get_Script_CMD(Script, Get_Parameters(), bAllArguments, bWrapArgs, bBatch);
1919
1920 for(int i=0; i<Get_Parameters_Count(); i++)
1921 {
1922 _Get_Script_CMD(Script, Get_Parameters(i), bAllArguments, bWrapArgs, bBatch);
1923 }
1924
1925 //-----------------------------------------------------
1926 if( bHeader )
1927 {
1928 Script += bBatch ? "\n\nPAUSE\n" : "\n";
1929 }
1930
1931 return( Script );
1932}
1933
1934//---------------------------------------------------------
1935void CSG_Tool::_Get_Script_CMD(CSG_String &Script, CSG_Parameters *pParameters, bool bAllArguments, bool bWrapArgs, bool bBatch)
1936{
1937 #define GET_ID1(p) (p->Get_Parameters()->Get_Identifier().Length() > 0 \
1938 ? CSG_String::Format("%s_%s", p->Get_Parameters()->Get_Identifier().c_str(), p->Get_Identifier()) \
1939 : CSG_String::Format(p->Get_Identifier())).c_str()
1940
1941 #define GET_ID2(p, s) CSG_String::Format("%s_%s", GET_ID1(p), s).c_str()
1942
1943 const char *Prefix = !bWrapArgs ? " -" : bBatch ? " ^\n -" : " \\\n -";
1944 const char *StrFmt = bBatch ? "%s=\"%s\"" : "%s=\\\"\"%s\"\\\"";
1945
1946 //-----------------------------------------------------
1947 for(int iParameter=0; iParameter<pParameters->Get_Count(); iParameter++)
1948 {
1949 CSG_Parameter *p = pParameters->Get_Parameter(iParameter);
1950
1951 if( !bAllArguments && (!p->is_Enabled(false) || p->is_Information() || !p->do_UseInCMD()) )
1952 {
1953 continue;
1954 }
1955
1956 switch( p->Get_Type() )
1957 {
1958 default:
1959 break;
1960
1961 case PARAMETER_TYPE_Bool :
1962 Script += Prefix + CSG_String::Format("%s=%d", GET_ID1(p), p->asBool() ? 1 : 0);
1963 break;
1964
1965 case PARAMETER_TYPE_Int :
1969 Script += Prefix + CSG_String::Format("%s=%d", GET_ID1(p), p->asInt());
1970 break;
1971
1974 if( p->asString() && *p->asString() )
1975 {
1976 Script += Prefix + CSG_String::Format(StrFmt, GET_ID1(p), p->asString());
1977 }
1978 break;
1979
1981 Script += Prefix + CSG_String::Format("%s=\"%s\"", GET_ID1(p), SG_Color_To_Text(p->asColor()).c_str());
1982 break;
1983
1986 Script += Prefix + CSG_String::Format("%s=%g", GET_ID1(p), p->asDouble());
1987 break;
1988
1990 Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T("MIN")), p->asRange()->Get_Min());
1991 Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T("MAX")), p->asRange()->Get_Max());
1992 break;
1993
1995 if( ((CSG_Parameter_String *)p)->is_Password() )
1996 {
1997 Script += Prefix + CSG_String::Format("%s=\"***\"", GET_ID1(p));
1998 break;
1999 }
2000
2001 case PARAMETER_TYPE_Date :
2002 case PARAMETER_TYPE_Text :
2004 Script += Prefix + CSG_String::Format(StrFmt, GET_ID1(p), p->asString());
2005 break;
2006
2008 Script += Prefix + CSG_String::Format(StrFmt, GET_ID1(p), p->asString());
2009 break;
2010
2012 if( p->Get_Children_Count() == 0 )
2013 {
2014 Script += Prefix + CSG_String::Format("%s=%d", GET_ID2(p, SG_T("NX")), p->asGrid_System()->Get_NX ());
2015 Script += Prefix + CSG_String::Format("%s=%d", GET_ID2(p, SG_T("NY")), p->asGrid_System()->Get_NY ());
2016 Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T( "X")), p->asGrid_System()->Get_XMin ());
2017 Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T( "Y")), p->asGrid_System()->Get_YMin ());
2018 Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T( "D")), p->asGrid_System()->Get_Cellsize());
2019 }
2020 break;
2021
2023 case PARAMETER_TYPE_Grid :
2027 case PARAMETER_TYPE_TIN :
2029 if( p->is_Input() )
2030 {
2031 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"));
2032 }
2033 else
2034 {
2035 CSG_String File(p->Get_Name());
2036
2037 switch( p->Get_DataObject_Type() )
2038 {
2039 case SG_DATAOBJECT_TYPE_Grid : File += ".sg-grd-z"; break;
2040 case SG_DATAOBJECT_TYPE_Grids : File += ".sg-gds-z"; break;
2041 case SG_DATAOBJECT_TYPE_Table : File += ".txt" ; break;
2042 case SG_DATAOBJECT_TYPE_Shapes : File += ".geojson" ; break;
2043 case SG_DATAOBJECT_TYPE_PointCloud: File += ".sg-pts-z"; break;
2044 case SG_DATAOBJECT_TYPE_TIN : File += ".geojson" ; break;
2045 default : File += ".dat" ; break;
2046 }
2047
2048 Script += Prefix + CSG_String::Format(StrFmt, GET_ID1(p), File.c_str());
2049 }
2050 break;
2051
2058 if( p->is_Input() )
2059 {
2060 Script += Prefix + CSG_String::Format("%s=", GET_ID1(p));
2061
2062 if( p->asList()->Get_Item_Count() == 0 )
2063 {
2064 Script += "file(s)";
2065 }
2066 else
2067 {
2068 Script += SG_File_Exists(p->asList()->Get_Item(0)->Get_File_Name())
2069 ? p->asList()->Get_Item(0)->Get_File_Name() : _TL("memory");
2070
2071 for(int iObject=1; iObject<p->asList()->Get_Item_Count(); iObject++)
2072 {
2073 Script += ";";
2074 Script += SG_File_Exists(p->asList()->Get_Item(iObject)->Get_File_Name())
2075 ? p->asList()->Get_Item(iObject)->Get_File_Name() : _TL("memory");
2076 }
2077 }
2078 }
2079 else
2080 {
2081 Script += Prefix + CSG_String::Format(StrFmt, GET_ID1(p), p->Get_Name());
2082 }
2083 break;
2084 }
2085 }
2086}
2087
2088
2090// //
2092
2093//---------------------------------------------------------
2094CSG_String CSG_Tool::_Get_Script_CMD_Usage(void)
2095{
2096 wxCmdLineParser Parser; Parser.SetSwitchChars("-");
2097
2098 _Get_Script_CMD_Usage(Get_Parameters(), Parser);
2099
2100 for(int i=0; i<Get_Parameters_Count(); i++)
2101 {
2102 _Get_Script_CMD_Usage(Get_Parameters(i), Parser);
2103 }
2104
2105 wxString Usage = wxString::Format("\nUsage: saga_cmd %s %s %s", Get_Library().c_str(), Get_ID().c_str(),
2106 Parser.GetUsageString().AfterFirst(' ').AfterFirst(' ')
2107 );
2108
2109 CSG_String _Usage(&Usage);
2110
2111 return( _Usage );
2112}
2113
2114//---------------------------------------------------------
2115void CSG_Tool::_Get_Script_CMD_Usage(CSG_Parameters *pParameters, wxCmdLineParser &Parser)
2116{
2117 for(int i=0; i<pParameters->Get_Count(); i++)
2118 {
2119 CSG_Parameter *pParameter = pParameters->Get_Parameter(i);
2120
2121 //-------------------------------------------------
2122 if( pParameter->is_DataObject() ) // reset data object parameters, avoids problems when tool is called more than once without un-/reloading
2123 {
2124 pParameter->Set_Value(DATAOBJECT_NOTSET);
2125 }
2126 else if( pParameter->is_DataObject_List() )
2127 {
2128 pParameter->asList()->Del_Items();
2129 }
2130
2131 //-------------------------------------------------
2132 if( pParameter->do_UseInCMD() == false )
2133 {
2134 continue;
2135 }
2136
2137 wxString Description = pParameter->Get_Description(
2139 ).c_str();
2140
2141 Description.Replace("\xb", ""); // unicode problem: quick'n'dirty bug fix, to be replaced
2142
2143 wxString ID(pParameter->Get_CmdID().c_str());
2144
2145 if( pParameter->is_Input() || pParameter->is_Output() )
2146 {
2147 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_NEEDS_SEPARATOR|wxCMD_LINE_PARAM_OPTIONAL);
2148 }
2149
2150 //-------------------------------------------------
2151 else if( pParameter->is_Option() && !pParameter->is_Information() )
2152 {
2153 switch( pParameter->Get_Type() )
2154 {
2156 _Get_Script_CMD_Usage(pParameter->asParameters(), Parser);
2157 break;
2158
2159 case PARAMETER_TYPE_Bool :
2160 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2161 break;
2162
2163 case PARAMETER_TYPE_Int :
2164 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
2165 break;
2166
2172 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2173 break;
2174
2177 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2178 break;
2179
2180 case PARAMETER_TYPE_Date :
2181 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_DATE , wxCMD_LINE_PARAM_OPTIONAL);
2182 break;
2183
2185 Parser.AddOption(ID + "_MIN", wxEmptyString, Description, wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2186 Parser.AddOption(ID + "_MAX", wxEmptyString, Description, wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2187 break;
2188
2190 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2191 break;
2192
2194 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2195 break;
2196
2198 case PARAMETER_TYPE_Text :
2200 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2201 break;
2202
2204 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2205 break;
2206
2208 if( pParameter->Get_Children_Count() == 0 )
2209 {
2210 Parser.AddOption(ID + "_D" , wxEmptyString, _TL("Cell Size" ), wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2211 Parser.AddOption(ID + "_X" , wxEmptyString, _TL("Lower Left Center Cell X-Coordinate"), wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2212 Parser.AddOption(ID + "_Y" , wxEmptyString, _TL("Lower Left Center Cell Y-Coordinate"), wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2213 Parser.AddOption(ID + "_NX" , wxEmptyString, _TL("Number of Columns" ), wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
2214 Parser.AddOption(ID + "_NY" , wxEmptyString, _TL("Number of Rows" ), wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
2215 Parser.AddOption(ID + "_FILE", wxEmptyString, _TL("Grid File" ), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2216 }
2217 break;
2218
2219 default:
2220 break;
2221 }
2222 }
2223 }
2224}
2225
2226
2228// //
2230
2231//---------------------------------------------------------
2232CSG_String CSG_Tool::_Get_Script_Python(bool bHeader, bool bAllArguments)
2233{
2234 CSG_String Script, Name(Get_Name());
2235
2236 Name.Replace(" ", "_");
2237 Name.Replace("(", "");
2238 Name.Replace(")", "");
2239 Name.Replace("[", "");
2240 Name.Replace("]", "");
2241 Name.Replace(".", "");
2242 Name.Replace(",", "");
2243 Name.Replace("/", "");
2244 Name.Replace("-", "");
2245
2246 //-----------------------------------------------------
2247 if( bHeader )
2248 {
2249 Script += "#! /usr/bin/env python\n";
2250 Script += "\n";
2251 Script += "#_________________________________________\n";
2252 Script += "##########################################\n";
2253 Script += "\n";
2254#ifdef _SAGA_MSW
2255 CSG_String AppPath = CSG_Environment::Get_Application_Path(true); AppPath.Replace("\\", "/");
2256 Script += "# Initialize the environment...\n";
2257 Script += "\n";
2258 Script += "# Windows: Let the 'SAGA_PATH' environment variable point to\n";
2259 Script += "# the SAGA installation folder before importing 'saga_api'!\n";
2260 Script += "# This can be defined globally in the Windows system or\n";
2261 Script += "# user environment variable settings, in the 'PySAGA/__init__.py'\n";
2262 Script += "# file, or in the individual Python script itself. To do the latter\n";
2263 Script += "# just uncomment the following line and adjust the path accordingly:\n";
2264 Script += "###import os; os.environ['SAGA_PATH'] = '" + AppPath + "'\n";
2265 Script += "\n";
2266 Script += "# Windows: The most convenient way to make PySAGA available to all your\n";
2267 Script += "# Python scripts is to copy the PySAGA folder to the 'Lib/site-packages/'\n";
2268 Script += "# folder of your Python installation. If don't want to do this or if you\n";
2269 Script += "# don't have the rights to do so, you can also copy it to the folder with\n";
2270 Script += "# the Python scripts in which you want to use PySAGA, or alternatively\n";
2271 Script += "# you can add the path containing the PySAGA folder (e.g. the path to your\n";
2272 Script += "# SAGA installation) to the PYTHONPATH environment variable. To do this\n";
2273 Script += "# from within your script you can also take the following command (just\n";
2274 Script += "# uncomment the following line and adjust the path accordingly):\n";
2275 Script += "###import sys; sys.path.insert(1, '" + AppPath + "')\n";
2276 Script += "\n";
2277#endif // _SAGA_MSW
2278 Script += "# Import saga_api from PySAGA:\n";
2279 Script += "from PySAGA import saga_api\n";
2280 Script += "\n";
2281 Script += "\n";
2282 Script += "#_________________________________________\n";
2283 Script += "##########################################\n";
2284 Script += "def Run_" + Name + "(Results):\n";
2285 }
2286
2287 //-----------------------------------------------------
2288 if( bHeader ) Script += " # Get the tool:\n";
2289 Script += " Tool = saga_api.SG_Get_Tool_Library_Manager().Get_Tool('" + Get_Library() + "', '" + Get_ID() + "')\n";
2290 Script += " if not Tool:\n";
2291 Script += " saga_api.SG_UI_Msg_Add_Error('Failed to request tool: " + Get_Name() + "')\n";
2292 Script += " return False\n";
2293 Script += "\n";
2294 if( bHeader ) Script += " # Set the parameter interface:\n";
2295 Script += " Tool.Reset()\n";
2296
2297 //-------------------------------------------------
2298 _Get_Script_Python(Script, Get_Parameters(), bAllArguments);
2299
2300 for(int iParameters=0; iParameters<Get_Parameters_Count(); iParameters++)
2301 {
2302 _Get_Script_Python(Script, Get_Parameters(iParameters), bAllArguments, Get_Parameters(iParameters)->Get_Identifier());
2303 }
2304
2305 //-------------------------------------------------
2306 Script += "\n";
2307 if( bHeader ) Script += " # Execute the tool:\n";
2308 Script += " if not Tool.Execute():\n";
2309 Script += " saga_api.SG_UI_Msg_Add_Error('failed to execute tool: ' + Tool.Get_Name().c_str())\n";
2310 Script += " return False\n";
2311 Script += "\n";
2312 if( bHeader ) Script += " # Request the results:\n";
2313
2314 for(int iParameter=0; iParameter<Get_Parameters()->Get_Count(); iParameter++)
2315 {
2316 CSG_Parameter *p = Get_Parameters()->Get_Parameter(iParameter);
2317
2318 if( p->is_Output() )
2319 {
2320 CSG_String id(p->Get_Identifier()), type, ext;
2321
2322 switch( p->Get_DataObject_Type() )
2323 {
2324 case SG_DATAOBJECT_TYPE_Grid : type = "Grid" ; ext = "sg-grd-z"; break;
2325 case SG_DATAOBJECT_TYPE_Grids : type = "Grids" ; ext = "sg-gds-z"; break;
2326 case SG_DATAOBJECT_TYPE_Table : type = "Table" ; ext = "txt" ; break;
2327 case SG_DATAOBJECT_TYPE_Shapes : type = "Shapes" ; ext = "geojson" ; break;
2328 case SG_DATAOBJECT_TYPE_PointCloud: type = "PointCloud"; ext = "sg-pts-z"; break;
2329 case SG_DATAOBJECT_TYPE_TIN : type = "TIN" ; ext = "geojson" ; break;
2330 default : type = "" ; ext = "" ; break;
2331 }
2332
2333 if( p->is_DataObject() )
2334 {
2335 Script += " Data = Tool.Get_Parameter('" + id + "').as" + type + "()\n";
2336
2337 if( bHeader )
2338 {
2339 Script += " Data.Save('{:s}/{:s}.{:s}'.format(Results, Data.Get_Name(), '" + ext + "'))\n\n";
2340 }
2341 }
2342 else if( p->is_DataObject_List() )
2343 {
2344 Script += " List = Tool.Get_Parameter('" + id + "').as" + type + "List()\n";
2345 Script += " for i in range(0, List.Get_Item_Count()):\n";
2346
2347 if( bHeader )
2348 {
2349 Script += " List.Get_Item(i).Save('{:s}/{:s}_{:d}.{:s}'.format(Results, List.Get_Name(), i, '" + ext + "'))\n\n";
2350 }
2351 else
2352 {
2353 Script += " Data = List.Get_Item(i)\n";
2354 }
2355 }
2356 }
2357 }
2358
2359 //-----------------------------------------------------
2360 if( bHeader )
2361 {
2362 Script += "\n";
2363 Script += " return True\n";
2364 Script += "\n";
2365 Script += "\n";
2366 Script += "#_________________________________________\n";
2367 Script += "##########################################\n";
2368 Script += "print('This is a simple template for using a SAGA tool through Python.')\n";
2369 Script += "print('Please edit the script to make it work properly before using it!')\n";
2370 Script += "\n";
2371 Script += "# Run_" + Name + "('.')\n";
2372 Script += "\n";
2373 Script += "# job is done, free memory resources:\n";
2374 Script += "saga_api.SG_Get_Data_Manager().Delete()\n";
2375 }
2376
2377 return( Script );
2378}
2379
2380//---------------------------------------------------------
2381void CSG_Tool::_Get_Script_Python(CSG_String &Script, CSG_Parameters *pParameters, bool bAllArguments, const CSG_String &Prefix)
2382{
2383 for(int iParameter=0; iParameter<pParameters->Get_Count(); iParameter++)
2384 {
2385 CSG_Parameter *p = pParameters->Get_Parameter(iParameter);
2386
2387 if( !bAllArguments && (!p->is_Enabled(false) || p->is_Information() || !p->do_UseInCMD()) )
2388 {
2389 continue;
2390 }
2391
2392 CSG_String ID(p->Get_Identifier());
2393
2394 if( !Prefix.is_Empty() )
2395 {
2396 ID.Prepend(Prefix + ".");
2397 }
2398
2399 switch( p->Get_Type() )
2400 {
2401 default:
2402 break;
2403
2404 case PARAMETER_TYPE_Bool :
2405 Script += CSG_String::Format(" Tool.Set_Parameter('%s', %s)\n", ID.c_str(), p->asBool() ? SG_T("True") : SG_T("False"));
2406 break;
2407
2408 case PARAMETER_TYPE_Int :
2409 Script += CSG_String::Format(" Tool.Set_Parameter('%s', %d)\n", ID.c_str(), p->asInt());
2410 break;
2411
2414 Script += CSG_String::Format(" Tool.Set_Parameter('%s', %d) # '%s'\n", ID.c_str(), p->asInt(), p->asString());
2415 break;
2416
2420 Script += CSG_String::Format(" Tool.Set_Parameter('%s', '%s')\n", ID.c_str(), p->asString());
2421 break;
2422
2424 Script += CSG_String::Format(" Tool.Set_Parameter('%s', '%s')\n", ID.c_str(), SG_Color_To_Text(p->asColor()).c_str());
2425 break;
2426
2429 Script += CSG_String::Format(" Tool.Set_Parameter('%s', %g)\n", ID.c_str(), p->asDouble());
2430 break;
2431
2433 Script += CSG_String::Format(" Tool.Set_Parameter('%s.MIN', %g)\n", ID.c_str(), p->asRange()->Get_Min());
2434 Script += CSG_String::Format(" Tool.Set_Parameter('%s.MAX', %g)\n", ID.c_str(), p->asRange()->Get_Max());
2435 break;
2436
2438 if( ((CSG_Parameter_String *)p)->is_Password() )
2439 {
2440 Script += CSG_String::Format(" Tool.Set_Parameter('%s', '***')\n", ID.c_str());
2441 break;
2442 }
2443
2444 case PARAMETER_TYPE_Date :
2445 case PARAMETER_TYPE_Text :
2447 Script += CSG_String::Format(" Tool.Set_Parameter('%s', '%s')\n", ID.c_str(), p->asString());
2448 break;
2449
2451 Script += CSG_String::Format(" Tool.Set_Parameter('%s', saga_api.SG_Create_Table('table.txt'))\n", ID.c_str());
2452 break;
2453
2455 if( p->Get_Children_Count() == 0 )
2456 {
2457 Script += CSG_String::Format(" Tool.Set_Parameter('%s', saga_api.CSG_Grid_System(%g, %g, %g, %d, %d))\n", ID.c_str(),
2460 p->asGrid_System()->Get_NX (), p->asGrid_System()->Get_NY ()
2461 );
2462 }
2463 break;
2464
2465 case PARAMETER_TYPE_Grid :
2469 case PARAMETER_TYPE_TIN :
2471 if( p->is_Input() )
2472 {
2473 Script += CSG_String::Format(" Tool.Set_Parameter('%s', saga_api.SG_Get_Data_Manager().Add('%s input file%s'))\n", ID.c_str(),
2474 SG_Get_DataObject_Name(p->Get_DataObject_Type()).c_str(), p->is_Optional() ? SG_T(", optional") : SG_T("")
2475 );
2476 }
2477 else if( p->is_Output() && p->is_Optional() )
2478 {
2479 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());
2480 }
2481 break;
2482
2489 if( p->is_Input() )
2490 {
2491 Script += CSG_String::Format(" Tool.Get_Parameter('%s').asList().Add_Item('%s input list%s')\n", ID.c_str(),
2492 SG_Get_DataObject_Name(p->Get_DataObject_Type()).c_str(), p->is_Optional() ? SG_T(", optional") : SG_T("")
2493 );
2494 }
2495 break;
2496
2498 _Get_Script_Python(Script, p->asParameters(), bAllArguments, ID);
2499 break;
2500 }
2501 }
2502}
2503
2504
2506// //
2508
2509//---------------------------------------------------------
2510CSG_String CSG_Tool::_Get_Script_Python_Wrap(bool bHeader, bool bName, bool bCall, int AllArguments, bool bWrapArgs)
2511{
2512 CSG_String Arguments, Description, Code;
2513
2514 if( AllArguments >= 0 ) // if( AllArguments < 0 ) => skip arguments list
2515 {
2516 for(int i=0; i<Parameters.Get_Count(); i++) // add input that is not optional in 1st place
2517 {
2518 _Get_Script_Python_Wrap(Parameters[i], PARAMETER_INPUT , Arguments, Description, Code, bCall && bHeader, AllArguments == 0, bWrapArgs);
2519 }
2520
2521 for(int i=0; i<Parameters.Get_Count(); i++) // add optional input in 2nd place
2522 {
2523 _Get_Script_Python_Wrap(Parameters[i], PARAMETER_INPUT_OPTIONAL, Arguments, Description, Code, bCall && bHeader, AllArguments == 0, bWrapArgs);
2524 }
2525
2526 for(int i=0; i<Parameters.Get_Count(); i++) // add output
2527 {
2528 _Get_Script_Python_Wrap(Parameters[i], PARAMETER_OUTPUT , Arguments, Description, Code, bCall && bHeader, AllArguments == 0, bWrapArgs);
2529 }
2530
2531 for(int i=0; i<Parameters.Get_Count(); i++) // add options
2532 {
2533 _Get_Script_Python_Wrap(Parameters[i], 0 , Arguments, Description, Code, bCall , AllArguments == 0, bWrapArgs);
2534 }
2535 }
2536
2537 //---------------------------------------------------------
2538 CSG_String Name, Expected(Get_Name()); Expected.Replace("'", "\\'");
2539
2540 if( bName )
2541 {
2542 Name = Get_Name();
2543
2544 if( isdigit(Name[0]) ) // ...in case first letter is a numeric character, what is not allowed for Python function names!
2545 {
2546 Name.Prepend("_");
2547 }
2548
2549 Name.Replace(" ", "_");
2550 Name.Replace("(", "");
2551 Name.Replace(")", "");
2552 Name.Replace("[", "");
2553 Name.Replace("]", "");
2554 Name.Replace(".", "");
2555 Name.Replace(",", "");
2556 Name.Replace("/", "");
2557 Name.Replace("-", "");
2558 Name.Replace("'", "");
2559 Name.Replace("&", "and");
2560 }
2561 else
2562 {
2563 Name = "run_tool_" + Get_Library() + "_" + Get_ID();
2564
2565 Name.Replace(" ", "_");
2566 }
2567
2568 //---------------------------------------------------------
2569 CSG_String Script;
2570
2571 if( bCall )
2572 {
2573 if( bHeader )
2574 {
2575 Script += "from PySAGA.tools import " + Get_Library() + "\n\n";
2576
2577 if( !Code.is_Empty() )
2578 {
2579 Script += Code + "\n";
2580 }
2581 }
2582
2583 Script += Get_Library() + '.' + Name + "(" + Arguments + ")\n";
2584 }
2585 else
2586 {
2588
2589 if( bHeader )
2590 {
2591 Script += "#! /usr/bin/env python\n";
2592 Script += "from PySAGA.helper import Tool_Wrapper\n\n";
2593 }
2594
2595 Script += "def " + Name + "(" + Arguments + ", Verbose=2):\n";
2596 Script += " '''\n";
2597 Script += " " + Get_Name() + "\n";
2598 Script += " ----------\n";
2599 Script += " [" + Get_Library() + "." + Get_ID() + "]\\n\n";
2600 for(int i=0; i<_Description.Get_Count(); i++)
2601 {
2602 _Description[i].Trim_Both(); Script += " " + _Description[i] + "\\n\n";
2603 }
2604 Script += " Arguments\n";
2605 Script += " ----------\n";
2606 Script += Description + "\n";
2607 Script += " - Verbose [`integer number`] : Verbosity level, 0=silent, 1=tool name and success notification, 2=complete tool output.\\n\n";
2608 Script += " Returns\n";
2609 Script += " ----------\n";
2610 Script += " `boolean` : `True` on success, `False` on failure.\n";
2611 Script += " '''\n";
2612 Script += " Tool = Tool_Wrapper('" + Get_Library() + "', '" + Get_ID() + "', '" + Expected + "')\n";
2613 Script += " if Tool.is_Okay():\n";
2614 Script += Code;
2615 Script += " return Tool.Execute(Verbose)\n";
2616 Script += " return False\n\n";
2617 }
2618
2619 return( Script );
2620}
2621
2622//---------------------------------------------------------
2623bool 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)
2624{
2625 if( Parameter.do_UseInCMD() == false
2626 || Parameter.is_Information()
2627 || Parameter.Get_Type() == PARAMETER_TYPE_Node
2628 || Parameter.Cmp_Identifier("PARAMETERS_GRID_SYSTEM") )
2629 {
2630 return( false );
2631 }
2632
2633 if( bCall && !Parameter.is_Enabled() && !(Parameter.is_Output() && Parameter.Get_Parent() && Parameter.Get_Parent()->Cmp_Identifier("TARGET_SYSTEM")) )
2634 {
2635 return( false );
2636 }
2637
2638 //-----------------------------------------------------
2639 CSG_String ID(Parameter.Get_Identifier());
2640
2641 if( !Prefix.is_Empty() )
2642 {
2643 ID.Prepend(Prefix + ".");
2644 }
2645
2646 CSG_String Argument(ID);
2647
2648 if( Argument[0] >= '0' && Argument[0] <= '9' )
2649 {
2650 Argument.Prepend('_');
2651 }
2652
2653 Argument.Replace(".", "_");
2654 Argument.Replace("|", "_");
2655 Argument.Replace(" ", "_");
2656
2657 if( Argument.Length() > 2 )
2658 {
2659 Argument.Make_Upper();
2660 }
2661
2662 //-----------------------------------------------------
2663 if( Parameter.asParameters() ) // PARAMETER_TYPE_Parameters
2664 {
2665 bool bResult = false;
2666
2667 for(int i=0; i<(*Parameter.asParameters()).Get_Count(); i++)
2668 {
2669 if( _Get_Script_Python_Wrap((*Parameter.asParameters())[i], Constraint, Arguments, Description, Code, bCall, bOnlyNonDefaults, bWrapArgs, ID) )
2670 {
2671 bResult = true;
2672 }
2673 }
2674
2675 return( bResult );
2676 }
2677
2678 //-----------------------------------------------------
2679 if( Parameter.is_Input () && !Parameter.is_Optional() && Constraint != PARAMETER_INPUT ) { return( false ); }
2680 if( Parameter.is_Input () && Parameter.is_Optional() && Constraint != PARAMETER_INPUT_OPTIONAL ) { return( false ); }
2681 if( Parameter.is_Output() && Constraint != PARAMETER_OUTPUT ) { return( false ); }
2682 if( Parameter.is_Option() && Constraint != 0 ) { return( false ); }
2683
2684 //-----------------------------------------------------
2685 if( bCall )
2686 {
2687 CSG_String Value;
2688
2689 if( Parameter.is_DataObject() )
2690 {
2691 Value = Parameter.Get_Identifier(); Value.Make_Lower();
2692
2693 if( Parameter.is_Input() )
2694 {
2695 if( (bOnlyNonDefaults && !Parameter.asDataObject()) && Parameter.is_Optional() ) // don't add optional input that has not been set
2696 {
2697 return( false );
2698 }
2699
2700 CSG_String File(Parameter.asDataObject() && Parameter.asDataObject()->Get_File_Name(false)
2701 ? Parameter.asDataObject()->Get_File_Name(false) : SG_T("data object file")
2702 ); File.Replace("\\", "/");
2703
2704 Code += Value + " = saga_api.SG_Get_Data_Manager().Add_" + SG_Get_DataObject_Class_Name(Parameter.Get_DataObject_Type()).AfterFirst('_') + "('" + File + "') # input data object\n";
2705 }
2706 else // if( Parameter.is_Output() )
2707 {
2708 if( (bOnlyNonDefaults && !Parameter.asDataObject()) && Parameter.is_Optional() ) // don't add optional output that has not been requested
2709 {
2710 return( false );
2711 }
2712
2713 Code += Value + " = saga_api.SG_Get_Data_Manager().Add_" + SG_Get_DataObject_Class_Name(Parameter.Get_DataObject_Type()).AfterFirst('_') + "() # output data object\n";
2714 }
2715 }
2716 else if( Parameter.is_DataObject_List() )
2717 {
2718 Value = Parameter.Get_Identifier(); Value.Make_Lower();
2719
2720 if( Parameter.is_Input() )
2721 {
2722 if( (bOnlyNonDefaults && Parameter.asList()->Get_Item_Count() < 1) && Parameter.is_Optional() ) // don't add optional input that has not been set
2723 {
2724 return( false );
2725 }
2726
2727 Code += Value + " = [] # Python list with input data objects of type 'saga_api." + SG_Get_DataObject_Class_Name(Parameter.Get_DataObject_Type()) + "'\n";
2728 }
2729 else // if( Parameter.is_Output() )
2730 {
2731 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";
2732 }
2733 }
2734 else if( Parameter.is_Option() )
2735 {
2736 if( bOnlyNonDefaults && Parameter.is_Default() )
2737 {
2738 return( false );
2739 }
2740
2741 switch( Parameter.Get_Type() )
2742 {
2743 case PARAMETER_TYPE_Bool : Value = Parameter.asBool() ? "True" : "False"; break;
2744
2745 case PARAMETER_TYPE_Int : Value.Printf("%d", Parameter.asInt()); break;
2746
2748 case PARAMETER_TYPE_Degree : Value.Printf("%f", Parameter.asDouble()); break;
2749
2750 case PARAMETER_TYPE_Color : Value = SG_Color_To_Text(Parameter.asColor()); break;
2751
2753 case PARAMETER_TYPE_Text :
2754 case PARAMETER_TYPE_Date :
2761 case PARAMETER_TYPE_FilePath : Value.Printf("'%s'", Parameter.asString()); break;
2762
2764 if( !Parameter.Cmp_Identifier("TARGET_SYSTEM") )
2765 {
2766 return( false );
2767 }
2768
2769 Value.Printf("'%s'", Parameter.asGrid_System()->asString());
2770 break;
2771
2772 default : return( false );
2773 }
2774 }
2775
2776 if( !Value.is_Empty() )
2777 {
2778 if( bWrapArgs )
2779 {
2780 Arguments += !Arguments.is_Empty() ? ",\n " : "\n ";
2781 }
2782 else if( !Arguments.is_Empty() )
2783 {
2784 Arguments += ", ";
2785 }
2786
2787 Arguments += Argument + "=" + Value;
2788 }
2789
2790 return( true );
2791 }
2792
2793 //-----------------------------------------------------
2794 if( bWrapArgs )
2795 {
2796 Arguments += !Arguments.is_Empty() ? ",\n " : "\n ";
2797 }
2798 else if( !Arguments.is_Empty() )
2799 {
2800 Arguments += ", ";
2801 }
2802
2803 Arguments += Argument + "=None";
2804
2805 //-----------------------------------------------------
2806 Code += " ";
2807
2808 if( Parameter.is_Input () ) { Code += "Tool.Set_Input "; }
2809 if( Parameter.is_Output() ) { Code += "Tool.Set_Output"; }
2810 if( Parameter.is_Option() ) { Code += "Tool.Set_Option"; }
2811
2812 Code += CSG_String::Format("('%s', %s)\n", ID.c_str(), Argument.c_str());
2813
2814 //-----------------------------------------------------
2815 Description += " - " + Argument + " [`";
2816
2817 if( Parameter.is_Input() )
2818 {
2819 Description += Parameter.is_Optional() ? "optional input " : "input ";
2820 }
2821 else if( Parameter.is_Output() )
2822 {
2823 Description += "output ";
2824 }
2825
2826 Description += Parameter.Get_Type_Name() + "`] : " + Parameter.Get_Name();
2827
2829
2830 if( !s.is_Empty() )
2831 {
2832 Description += ". " + s;
2833 }
2834
2835 Description += "\n";
2836
2837 return( true );
2838}
2839
2841// //
2843
2844//---------------------------------------------------------
2845CSG_String CSG_Tool::_Get_Script_Markdown(bool bHeader, int iArguments)
2846{
2847 CSG_String Script;
2848
2849 if( bHeader )
2850 {
2851 CSG_String Menu = Get_MenuPath(true); Menu.Replace("|", " &rarr; ");
2852 CSG_Tool_Library *pLibrary = SG_Get_Tool_Library_Manager().Get_Library(this);
2853 CSG_String Category = pLibrary->Get_Category() + " &rarr; " + pLibrary->Get_Name();
2854
2855 Script += CSG_String::Format("**Tool:** %s \n", Get_Name().c_str());
2856 Script += CSG_String::Format("**Geoprocessing** &rarr; *%s*&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp; **Tools** &rarr; *%s*\n\n", Menu.c_str(), Category.c_str());
2857 }
2858
2859 Script += "|**Parameter**|**Setting**|\n";
2860 Script += "|---|---|\n";
2861
2862 //-------------------------------------------------
2863 _Get_Script_Markdown(Script, Get_Parameters(), iArguments);
2864
2865 Script.Replace("\n\n", "\n");
2866
2867 return( Script );
2868}
2869
2870
2871//---------------------------------------------------------
2872void CSG_Tool::_Get_Script_Markdown(CSG_String &Script, CSG_Parameters *pParameters, int iArguments, const CSG_String &Prefix)
2873{
2874 #define WRITE_CHILD(pChild, Prefix) Script += CSG_String::Format("|%s%s||\n", Prefix.c_str(), pChild->Get_Name().c_str());\
2875 for (int i=0; i<pChild->Get_Children_Count(); i++)\
2876 {\
2877 Script += CSG_String::Format("%s\n", pChild->Get_Child(i)->Get_Content().c_str());\
2878 }
2879
2880 CSG_MetaData Properties;
2881
2882 for(int iParameter=0; iParameter<pParameters->Get_Count(); iParameter++)
2883 {
2884 _Format_Markdown(pParameters->Get_Parameter(iParameter), Script, Properties, iArguments, Prefix);
2885 }
2886
2887 if( CSG_MetaData *pChild = Properties.Get_Child(_TL("Data Objects")) ) { WRITE_CHILD(pChild, Prefix); }
2888
2889 for (int i=0; i<Properties.Get_Children_Count(); i++)
2890 {
2891 CSG_MetaData *pChild = Properties.Get_Child(i);
2892
2893 if( pChild->Get_Name().Cmp(_TL("Data Objects")) && pChild->Get_Name().Cmp(_TL("Options")) )
2894 {
2895 WRITE_CHILD(pChild, Prefix);
2896 }
2897 }
2898
2899 if( CSG_MetaData *pChild = Properties.Get_Child(_TL("Options")) ) { WRITE_CHILD(pChild, Prefix); }
2900}
2901
2902
2903//---------------------------------------------------------
2904void CSG_Tool::_Format_Markdown(CSG_Parameter *p, CSG_String &Script, CSG_MetaData &Properties, int iArguments, CSG_String Prefix)
2905{
2906 #define CHECK_OBJECTS_NODE() pChild = Properties.Get_Child(_TL("Options"));\
2907 if( !pChild )\
2908 {\
2909 pChild = Properties.Add_Child(_TL("Options"));\
2910 }\
2911 \
2912 pRoot = pChild;
2913
2914 #define CHECK_DATA_NODE(Name) pChild = Properties.Get_Child(Name);\
2915 if( !pChild )\
2916 {\
2917 CSG_MetaData *pData = Properties.Get_Child(_TL("Data Objects"));\
2918 if( !pData )\
2919 {\
2920 Properties.Add_Child(_TL("Data Objects"));\
2921 }\
2922 pChild = Properties.Add_Child(Name);\
2923 }\
2924 \
2925 pRoot = pChild;
2926
2927 #define GET_PARENT_NODE(prt) bool bFound = false;\
2928 for (int i=0; i<Properties.Get_Children_Count(); i++)\
2929 {\
2930 CSG_MetaData *pDatatype = Properties.Get_Child(i);\
2931 for (int j=0; j<Properties.Get_Children_Count(); j++)\
2932 {\
2933 pParent = pDatatype->Get_Child(prt);\
2934 if( pParent )\
2935 {\
2936 bFound = true;\
2937 break;\
2938 }\
2939 }\
2940 if( bFound )\
2941 {\
2942 break;\
2943 }\
2944 }
2945
2946 #define FORMAT_DATASET() if( p->is_Input() )\
2947 {\
2948 CSG_String Input = p->is_Optional() ? ">" : ">>";\
2949 CSG_String s = p->asString();\
2950 if( s.Contains(_TL("not set")) || s.Contains(_TL("No objects")) ) { Bold = ""; }\
2951 s.Replace("<", "\\<");\
2952 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());\
2953 }\
2954 else if( p->is_Output() )\
2955 {\
2956 CSG_String Output = p->is_Optional() ? "\\<" : "<<";\
2957 CSG_String s = p->asString();\
2958 if( !p->is_Optional() && s.Contains(_TL("create")) ) { Bold = ""; }\
2959 else if( p->is_Optional() && (s.Contains(_TL("not set")) || s.Contains(_TL("No objects"))) ) { Bold = ""; }\
2960 s.Replace("<", "\\<");\
2961 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());\
2962 }
2963
2964 if( iArguments == 0 && !p->do_UseInCMD() )
2965 {
2966 return;
2967 }
2968 else if( iArguments == 1 && !p->do_UseInGUI() )
2969 {
2970 return;
2971 }
2972
2973 if( !p->is_Enabled(false) )
2974 {
2975 return;
2976 }
2977
2978 CSG_String Name(p->Get_Name());
2979
2980 CSG_String Bold;
2981
2982 if( !p->is_Default() )
2983 {
2984 Bold = "**";
2985 }
2986
2987 CSG_String Space = Prefix;
2988
2989 if( p->Get_Parent() != NULL )
2990 {
2991 Space += "&nbsp;&nbsp;&nbsp;";
2992 }
2993
2994 CSG_String Parameter;
2995 CSG_MetaData *pRoot = NULL, *pChild;
2996
2997 switch( p->Get_Type() )
2998 {
2999 default:
3000 break;
3001
3003 {
3004 if( p->Get_Parent() )
3005 {
3007 }
3008 else if( p->Get_Children_Count() == 0 )
3009 {
3010 CHECK_DATA_NODE(_TL("Grids"));
3011 }
3012 else for (int i=0; i<p->Get_Children_Count() && !pRoot; i++)
3013 {
3016 || p->Get_Child(i)->is_Input() )
3017 {
3018 CHECK_DATA_NODE(_TL("Grids"));
3019 }
3020 }
3021
3022 CSG_String s = p->asString();
3023 if( s.Contains(_TL("not set")) )
3024 {
3025 s.Replace("<", "\\<");
3026 Parameter += CSG_String::Format("|%s%s|%s|", Space.c_str(), Name.c_str(), s.c_str());
3027 }
3028 else
3029 {
3030 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(),
3032 p->asGrid_System()->Get_NX (), p->asGrid_System()->Get_NY (),
3034 Bold.c_str()
3035 );
3036 }
3037 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3038 break;
3039 }
3040
3043 if( p->is_Input() )
3044 {
3045 if( !p->Get_Parent() || (p->Get_Parent()->Get_Type() == PARAMETER_TYPE_Grid_System && !p->Get_Parent()->Get_Parent()) )
3046 {
3047 CHECK_DATA_NODE(_TL("Grids"));
3048 }
3049 else
3050 {
3052 }
3054 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3055 }
3056 break;
3057
3058 case PARAMETER_TYPE_Grid :
3060 if( !p->Get_Parent() || (p->Get_Parent()->Get_Type() == PARAMETER_TYPE_Grid_System && !p->Get_Parent()->Get_Parent()) )
3061 {
3062 CHECK_DATA_NODE(_TL("Grids"));
3063 }
3064 else
3065 {
3067 }
3069 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3070 break;
3071
3073 if( p->is_Input() )
3074 {
3075 if( !p->Get_Parent() )
3076 {
3077 CHECK_DATA_NODE(_TL("Tables"));
3078 }
3079 else
3080 {
3082 }
3084 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3085 }
3086 break;
3087
3089 if( !p->Get_Parent() )
3090 {
3091 CHECK_DATA_NODE(_TL("Tables"));
3092 }
3093 else
3094 {
3096 }
3098 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3099 break;
3100
3102 if( p->is_Input() )
3103 {
3104 if( !p->Get_Parent() )
3105 {
3106 CHECK_DATA_NODE(_TL("Shapes"));
3107 }
3108 else
3109 {
3111 }
3113 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3114 }
3115 break;
3116
3118 if( !p->Get_Parent() )
3119 {
3120 CHECK_DATA_NODE(_TL("Shapes"));
3121 }
3122 else
3123 {
3125 }
3127 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3128 break;
3129
3131 if( p->is_Input() )
3132 {
3133 if( !p->Get_Parent() )
3134 {
3135 CHECK_DATA_NODE(_TL("TIN"));
3136 }
3137 else
3138 {
3140 }
3142 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3143 }
3144 break;
3145
3146 case PARAMETER_TYPE_TIN :
3147 if( !p->Get_Parent() )
3148 {
3149 CHECK_DATA_NODE(_TL("TIN"));
3150 }
3151 else
3152 {
3154 }
3156 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3157 break;
3158
3160 if( p->is_Input() )
3161 {
3162 if( !p->Get_Parent() )
3163 {
3164 CHECK_DATA_NODE(_TL("Point Clouds"));
3165 }
3166 else
3167 {
3169 }
3171 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3172 }
3173 break;
3174
3176 if( !p->Get_Parent() )
3177 {
3178 CHECK_DATA_NODE(_TL("Point Clouds"));
3179 }
3180 else
3181 {
3183 }
3185 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3186 break;
3187
3188 case PARAMETER_TYPE_Node :
3190 Parameter = CSG_String::Format("|%s%s||", Space.c_str(), Name.c_str());
3191 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3192 break;
3193
3194 case PARAMETER_TYPE_Bool :
3196 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());
3197 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3198 break;
3199
3200 case PARAMETER_TYPE_Int :
3202 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());
3203 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3204 break;
3205
3208 {
3210 CSG_String s = p->asString();
3211 if( s.Contains(_TL("no choice available")) ) { Bold = ""; }
3212 s.Replace("<", "\\<");
3213 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());
3214 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3215 break;
3216 }
3217
3219 {
3220 CSG_String s = p->asString();
3221 if( s.Contains(_TL("no attributes")) ) { Bold = ""; }
3222 s.Replace("<", "\\<");
3223 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());
3224 if( p->Get_Parent() != NULL && (p->Get_Parent()->is_DataObject() || p->Get_Parent()->is_DataObject_List()) )
3225 {
3226 CSG_MetaData *pParent = NULL;
3228 if( pParent )
3229 {
3230 CSG_String c = pParent->Get_Content();
3231 c += SG_T("\n") + Parameter;
3232 pParent->Set_Content(c);
3233 }
3234 }
3235 else
3236 {
3238 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3239 }
3240 break;
3241 }
3242
3245 {
3246 CSG_String s = p->asString();
3247 s.Replace("<", "\\<");
3248 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());
3249 if( p->Get_Parent() != NULL && (p->Get_Parent()->is_DataObject() || p->Get_Parent()->is_DataObject_List()) )
3250 {
3251 CSG_MetaData *pParent = NULL;
3253 if( pParent )
3254 {
3255 CSG_String c = pParent->Get_Content();
3256 c += SG_T("\n") + Parameter;
3257 pParent->Set_Content(c);
3258 }
3259 }
3260 else
3261 {
3263 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3264 }
3265 break;
3266 }
3267
3270 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());
3271 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3272 break;
3273
3277 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());
3278 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3279 break;
3280
3283 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());
3284 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3285 break;
3286
3288 if( ((CSG_Parameter_String *)p)->is_Password() )
3289 {
3291 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());
3292 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3293 break;
3294 }
3295
3296 case PARAMETER_TYPE_Date :
3297 case PARAMETER_TYPE_Text :
3299 {
3301 CSG_String s = p->asString();
3302 s.Replace("\\", "/");
3303 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());
3304 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3305 break;
3306 }
3307
3310 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());
3311 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3312 break;
3313
3316 Parameter = CSG_String::Format("|%s%s||\n", Space.c_str(), Name.c_str());
3317 CSG_String Prefix = Space + "&nbsp;&nbsp;&nbsp;";
3318 _Get_Script_Markdown(Parameter, p->asParameters(), iArguments, Prefix);
3319 if( pRoot ) { pRoot->Add_Child(p->Get_Identifier(), Parameter); }
3320 break;
3321 }
3322
3323 return;
3324}
3325
3327// //
3328// //
3329// //
3331
3332//---------------------------------------------------------
3334{
3335 CSG_MetaData History;
3336
3337 History.Set_Name(SG_META_HISTORY);
3338 History.Add_Property("saga-version", SAGA_VERSION);
3339
3340 if( Depth )
3341 {
3342 CSG_MetaData *pTool = History.Add_Child("TOOL");
3343
3344 pTool->Add_Property("library", Get_Library());
3345 pTool->Add_Property("id" , Get_ID ());
3346 pTool->Add_Property("name" , Get_Name ());
3347
3348 Parameters.Set_History(*pTool);
3349
3351
3352 CSG_MetaData *pOutput = pTool->Add_Child("OUTPUT");
3353 pOutput->Add_Property("type", "");
3354 pOutput->Add_Property("id" , "");
3355 pOutput->Add_Property("name", "");
3356
3357 pTool->Del_Children(Depth, SG_T("TOOL"));
3358 }
3359
3360 return( History );
3361}
3362
3363//---------------------------------------------------------
3364bool CSG_Tool::Set_History(CSG_Data_Object *pDataObject, int Depth)
3365{
3366 if( pDataObject )
3367 {
3368 CSG_MetaData History(Get_History(Depth));
3369
3370 CSG_MetaData *pOutput = History("TOOL") ? History["TOOL"]("OUTPUT") : NULL;
3371
3372 if( pOutput )
3373 {
3374 pOutput->Set_Property("name", pDataObject->Get_Name());
3375 }
3376
3377 pDataObject->Get_History() = History;
3378
3379 return( true );
3380 }
3381
3382 return( false );
3383}
3384
3385//---------------------------------------------------------
3386void CSG_Tool::_Set_Output_History(void)
3387{
3389
3390 for(int j=-1; j<Get_Parameters_Count(); j++)
3391 {
3392 CSG_Parameters *pParameters = j < 0 ? &Parameters : Get_Parameters(j);
3393
3394 for(int i=0; i<pParameters->Get_Count(); i++)
3395 {
3396 CSG_Parameter *pParameter = pParameters->Get_Parameter(i);
3397
3398 if( pParameter->is_Output() )//&& (pParameter->is_Enabled() || !has_GUI()) )
3399 {
3400 DataObject_Set_History(pParameter, &History);
3401 }
3402 }
3403 }
3404}
3405
3406//---------------------------------------------------------
3408{
3409 if( !pParameter || !((pParameter->is_DataObject() && pParameter->asDataObject()) || !(pParameter->is_DataObject_List() && pParameter->asList()->Get_Item_Count() > 0)) )
3410 {
3411 return( false );
3412 }
3413
3414 //-----------------------------------------------------
3415 CSG_MetaData History;
3416
3417 if( !pHistory )
3418 {
3419 History = Get_History(SG_Get_History_Depth()); pHistory = &History;
3420 }
3421
3422 //-----------------------------------------------------
3423 CSG_MetaData *pOutput = pHistory->Get_Child("TOOL") ? pHistory->Get_Child("TOOL")->Get_Child("OUTPUT") : NULL;
3424
3425 if( pOutput )
3426 {
3427 pOutput->Set_Property("type", pParameter->Get_Type_Identifier());
3428 pOutput->Set_Property("id" , pParameter->Get_Identifier ());
3429 pOutput->Set_Property("name", pParameter->Get_Name ());
3430 }
3431
3432 //-----------------------------------------------------
3433 if( pParameter->is_DataObject() && pParameter->asDataObject() )
3434 {
3435 if( pOutput )
3436 {
3437 pOutput->Set_Content(pParameter->asDataObject()->Get_Name());
3438 }
3439
3440 pParameter->asDataObject()->Get_History().Assign(*pHistory);
3441 }
3442
3443 //-----------------------------------------------------
3444 else if( pParameter->is_DataObject_List() )
3445 {
3446 for(int j=0; j<pParameter->asList()->Get_Item_Count(); j++)
3447 {
3448 if( pOutput )
3449 {
3450 pOutput->Set_Content(pParameter->asList()->Get_Item(j)->Get_Name());
3451 }
3452
3453 pParameter->asList()->Get_Item(j)->Get_History().Assign(*pHistory);
3454 }
3455 }
3456
3457 //-----------------------------------------------------
3458 return( true );
3459}
3460
3461
3463// //
3464// //
3465// //
3467
3468//---------------------------------------------------------
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)
SAGA_API_DLL_EXPORT bool SG_File_Exists(const CSG_String &FileName)
@ SG_UI_MSG_STYLE_FAILURE
Definition api_core.h:1636
@ SG_UI_MSG_STYLE_SUCCESS
Definition api_core.h:1635
@ SG_UI_MSG_STYLE_BOLD
Definition api_core.h:1633
@ SG_UI_MSG_STYLE_NORMAL
Definition api_core.h:1632
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:1649
@ SG_UI_DATAOBJECT_UPDATE
Definition api_core.h:1648
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:1619
@ 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
class CSG_PointCloud * asPointCloud(bool bPolymorph=false) const
CSG_MetaData & Get_History(void)
Definition dataobject.h:239
static CSG_DateTime Now(void)
Definition datetime.cpp:600
static const CSG_String & Get_Application_Name(void)
Definition api_core.cpp:448
static const CSG_String & Get_Application_Path(bool bPathOnly)
Definition api_core.cpp:433
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
const SG_Char * asString(void) const
double Get_Cellsize(void) const
Definition grid.h:255
int Get_NX(void) const
Definition grid.h:258
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:783
bool Del_Children(int Depth=0, const SG_Char *Name=NULL)
Definition metadata.cpp:384
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:641
bool Add_Children(const CSG_MetaData &MetaData)
Definition metadata.cpp:362
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:169
bool Add_Property(const CSG_String &Name, const CSG_String &Value)
Definition metadata.cpp:585
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
CSG_Table * asTable(void) const
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
bool Assign_Values(const CSG_Table &Table)
Definition table.cpp:378
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:1772
bool Message_Dlg_Confirm(const CSG_String &Text, const SG_Char *Caption=NULL)
Definition tool.cpp:1003
static bool DataObject_Set_Classification(CSG_Data_Object *pDataObject, const CSG_Table &LUT, int Field=-1, bool bSetClassify=true)
Definition tool.cpp:1314
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:1787
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:1797
CSG_MetaData Get_History(int Depth=-1)
Definition tool.cpp:3333
bool DataObject_Add(CSG_Data_Object *pDataObject, bool bShow=false)
Definition tool.cpp:1092
bool Settings_Pop(void)
Definition tool.cpp:938
static bool Process_Get_Okay(bool bBlink=false)
Definition tool.cpp:1141
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:1810
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:1619
bool Load_Description(void)
Definition tool.cpp:459
virtual bool is_Interactive(void) const
Definition tool.h:236
static bool DataObject_Classify_Quantile(CSG_Data_Object *pDataObject, int Field=-1, int Classes=10, bool bHistogram=true, int Colors=-1)
Definition tool.cpp:1589
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:1851
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:1284
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:1405
static bool DataObject_Classify_Unique(CSG_Data_Object *pDataObject, int Field=-1, int Classes_Max=1024, int Colors=-1)
Definition tool.cpp:1559
static void Process_Set_Text(const CSG_String &Text)
Definition tool.cpp:1147
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:1659
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:1599
CSG_Table Get_Parameters_Table(void) const
Definition tool.cpp:395
virtual bool On_Execute(void)=0
static CSG_Table * DataObject_Get_Classification(CSG_Data_Object *pDataObject)
Definition tool.cpp:1300
CSG_MetaData History_Supplement
Definition tool.h:271
CSG_Parameter * Get_Parameter(const CSG_String &ID) const
Definition tool.cpp:1642
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:269
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:1373
CSG_String Get_Description_Editors(bool bHTML=true)
Definition tool.cpp:525
virtual bool do_Sync_Projections(void) const
Definition tool.h:229
static bool DataObject_Update(CSG_Data_Object *pDataObject, int Show=SG_UI_DATAOBJECT_UPDATE)
Definition tool.cpp:1261
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:1740
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:1378
bool DataObject_Update_All(void)
Definition tool.cpp:1110
void Set_Callback(bool bActive=true)
Definition tool.cpp:863
bool Reset_Manager(void)
Definition tool.cpp:1762
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:1528
bool Set_History(CSG_Data_Object *pDataObject, int Depth=-1)
Definition tool.cpp:3364
bool Execute(bool bAddHistory=false)
Definition tool.cpp:560
static ESymbology DataObject_Get_Symbology(CSG_Data_Object *pDataObject)
Definition tool.cpp:1344
static bool DataObject_Get_Colors(CSG_Data_Object *pDataObject, CSG_Colors &Colors)
Definition tool.cpp:1279
void Message_Fmt(const char *Format,...)
Definition tool.cpp:1210
static bool DataObject_Set_Parameter(CSG_Data_Object *pDataObject, CSG_Parameter *pParameter)
Definition tool.cpp:1412
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:1539
static bool DataObject_Set_Symbology(CSG_Data_Object *pDataObject, ESymbology Symbology)
Definition tool.cpp:1360
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:1505
static bool DataObject_Classify_Natural(CSG_Data_Object *pDataObject, int Field=-1, int Classes=10, int Colors=-1)
Definition tool.cpp:1609
static bool DataObject_Classify_Equal(CSG_Data_Object *pDataObject, int Field=-1, int Classes=10, int Colors=-1)
Definition tool.cpp:1569
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:1516
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:3407
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:255
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:1197
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
ESymbology
Definition tool.h:352
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:1579
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:1555
#define WRITE_CHILD(pChild, Prefix)
#define INIT_STRETCH_OPTIONS(method)
Definition tool.cpp:1492
#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)