SAGA API  v9.6
tool.cpp
Go to the documentation of this file.
1 
3 // //
4 // SAGA //
5 // //
6 // System for Automated Geoscientific Analyses //
7 // //
8 // Application Programming Interface //
9 // //
10 // Library: SAGA_API //
11 // //
12 //-------------------------------------------------------//
13 // //
14 // tool.cpp //
15 // //
16 // Copyright (C) 2005 by Olaf Conrad //
17 // //
18 //-------------------------------------------------------//
19 // //
20 // This file is part of 'SAGA - System for Automated //
21 // Geoscientific Analyses'. //
22 // //
23 // This library is free software; you can redistribute //
24 // it and/or modify it under the terms of the GNU Lesser //
25 // General Public License as published by the Free //
26 // Software Foundation, either version 2.1 of the //
27 // License, or (at your option) any later version. //
28 // //
29 // This library is distributed in the hope that it will //
30 // be useful, but WITHOUT ANY WARRANTY; without even the //
31 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
32 // PARTICULAR PURPOSE. See the GNU Lesser General Public //
33 // License for more details. //
34 // //
35 // You should have received a copy of the GNU Lesser //
36 // General Public License along with this program; if //
37 // not, see <http://www.gnu.org/licenses/>. //
38 // //
39 //-------------------------------------------------------//
40 // //
41 // contact: Olaf Conrad //
42 // Institute of Geography //
43 // University of Goettingen //
44 // Germany //
45 // //
46 // e-mail: oconrad@saga-gis.org //
47 // //
49 
50 //---------------------------------------------------------
51 #include "saga_api.h"
52 #include "data_manager.h"
53 #include "tool.h"
54 #include "tool_chain.h"
55 
56 #include <wx/string.h>
57 #include <wx/cmdline.h>
58 
59 
61 // //
62 // //
63 // //
65 
66 //---------------------------------------------------------
68 {
69  m_ID = "-1";
70  m_Version = "1.0";
71 
72  m_bError_Ignore = false;
73  m_bExecutes = false;
74 
75  m_bGUI = SG_UI_Get_Application_Name().Cmp("saga_gui") == 0;
76  m_bCMD = SG_UI_Get_Application_Name().Cmp("saga_cmd") == 0;
77 
78  Parameters.Create(this, SG_T("Tool"));
80  Parameters.Set_Tool(this);
81 
82  Set_Show_Progress(true);
83 }
84 
85 //---------------------------------------------------------
87 {
88  for(int i=0; i<Get_Parameters_Count(); i++)
89  {
90  delete(Get_Parameters(i));
91  }
92 
93  Destroy();
94 }
95 
96 
98 // //
100 
101 //---------------------------------------------------------
103 {
104  m_bError_Ignore = false;
105 
107 }
108 
109 
111 // //
113 
114 //---------------------------------------------------------
116 {
117  return( m_Library );
118 }
119 
120 //---------------------------------------------------------
122 {
123  return( m_File_Name );
124 }
125 
126 //---------------------------------------------------------
127 void CSG_Tool::Set_Name(const CSG_String &String)
128 {
129  Parameters.Set_Name(String);
130 }
131 
132 const CSG_String & CSG_Tool::Get_Name(void) const
133 {
134  return( Parameters.Get_Name() );
135 }
136 
137 //---------------------------------------------------------
138 void CSG_Tool::Set_Author(const CSG_String &String)
139 {
140  m_Author = String;
141 }
142 
143 const CSG_String & CSG_Tool::Get_Author(void) const
144 {
145  return( m_Author );
146 }
147 
148 //---------------------------------------------------------
150 {
151  m_Version = String;
152 }
153 
155 {
156  return( m_Version );
157 }
158 
159 //---------------------------------------------------------
161 {
162  Parameters.Set_Description(String);
163 }
164 
166 {
168 }
169 
170 //---------------------------------------------------------
171 void CSG_Tool::Add_Reference(const CSG_String &Authors, const CSG_String &Year, const CSG_String &Title, const CSG_String &Where, const SG_Char *Link, const SG_Char *Link_Text)
172 {
173  Parameters.Add_Reference(Authors, Year, Title, Where, Link, Link_Text);
174 }
175 
176 void CSG_Tool::Add_Reference(const CSG_String &Link, const SG_Char *Link_Text)
177 {
178  Parameters.Add_Reference(Link, Link_Text);
179 }
180 
182 {
183  return( Parameters.Get_References() );
184 }
185 
186 //---------------------------------------------------------
188 {
189  if( !bSolved )
190  {
191  return( Get_MenuPath() );
192  }
193 
194  CSG_Strings Menu = SG_String_Tokenize(Get_MenuPath(), ";"); if( !Menu.Get_Count() ) { Menu += ""; }
195 
196  for(int i=0; i<Menu.Get_Count(); i++)
197  {
198  if( Menu[i].Length() > 1 && Menu[i][1] == ':' )
199  {
200  if( Menu[i][0] == 'A' || Menu[i][0] == 'a' ) // absolute menu path, overwrites library's default menu path
201  {
202  Menu[i] = Menu[i].AfterFirst(':');
203 
204  continue;
205  }
206 
207  Menu[i] = Menu[i].AfterFirst(':'); // Menu[0] == 'R' || Menu[0] == 'r' // menu path explicitly declared as relative to library's default menu path
208  }
209 
210  if( !m_Library_Menu.is_Empty() )
211  {
212  if( Menu[i].is_Empty() )
213  {
214  Menu[i] = m_Library_Menu;
215  }
216  else
217  {
218  Menu[i] = m_Library_Menu + "|" + Menu[i];
219  }
220  }
221  }
222 
223  CSG_String Menus;
224 
225  for(int i=0; i<Menu.Get_Count(); i++)
226  {
227  if( i > 0 )
228  {
229  Menus += ";";
230  }
231 
232  Menus += Menu[i];
233  }
234 
235  return( Menus );
236 }
237 
238 //---------------------------------------------------------
239 bool CSG_Tool::has_GUI(void) const
240 {
241  return( m_bGUI );
242 }
243 
244 //---------------------------------------------------------
245 bool CSG_Tool::has_CMD(void) const
246 {
247  return( m_bCMD );
248 }
249 
250 
252 // //
253 // //
254 // //
256 
257 //---------------------------------------------------------
258 bool CSG_Tool::Execute(bool bAddHistory)
259 {
260  #define ADD_MESSAGE_EXECUTION(Text, Style) { SG_UI_Msg_Add(Text, true, Style); if( has_GUI() ) { SG_UI_Msg_Add_Execution(Text, true, Style); } }
261 
262  //-----------------------------------------------------
263  if( m_bExecutes )
264  {
265  return( false );
266  }
267 
268  m_bExecutes = true;
269 
270  m_bError_Ignore = false;
271 
272  bool bResult = false;
273 
274  m_Execution_Info.Clear();
275 
277 
278  //-----------------------------------------------------
280  {
281  ADD_MESSAGE_EXECUTION(CSG_String::Format("[%s] %s...", Get_Name().c_str(), _TL("Execution started")), SG_UI_MSG_STYLE_SUCCESS);
282  }
283 
285 
286  if( Parameters.DataObjects_Create() == false )
287  {
288  _Synchronize_DataObjects(); // not all, but some objects might have been created!
289  }
290  else
291  {
292  Parameters.Msg_String(false);
293 
294  // SG_UI_Process_Set_Busy(true, CSG_String::Format("%s: %s...", _TL("Executing"), Get_Name().c_str()));
295  CSG_DateTime Started(CSG_DateTime::Now());
296 
298 //#if !defined(_DEBUG)
299 #define _TOOL_EXCEPTION
300  try
301  {
302 //#endif
304 
305  bResult = On_Execute();
306 
308 #ifdef _TOOL_EXCEPTION
309  } // try
310  catch(const std::exception &Exception)
311  {
312  Message_Dlg(Exception.what() , CSG_String::Format("%s | %s", Get_Name().c_str(), _TL("Access violation!")));
313  }
314  catch(...)
315  {
316  Message_Dlg(_TL("unspecified exception"), CSG_String::Format("%s | %s", Get_Name().c_str(), _TL("Access violation!")));
317  }
318  #endif
319 
321  CSG_TimeSpan Span = CSG_DateTime::Now() - Started;
322  // SG_UI_Process_Set_Busy(false);
323 
324  _Synchronize_DataObjects();
325 
326  if( !Process_Get_Okay(false) )
327  {
328  SG_UI_Msg_Add(_TL("Execution has been stopped by user!"), true, SG_UI_MSG_STYLE_BOLD);
329 
330  bResult = false;
331  }
332 
333  if( bResult && bAddHistory )
334  {
335  _Set_Output_History();
336  }
337 
338  //-------------------------------------------------
339  if( is_Interactive() )
340  {
341  if( bResult )
342  {
343  CSG_String Text(CSG_String::Format("\n%s...", _TL("Interactive tool started and is waiting for user input.")));
344 
345  SG_UI_Msg_Add (Text, false, SG_UI_MSG_STYLE_BOLD);
347  }
348  else
349  {
350  ADD_MESSAGE_EXECUTION(_TL("Interactive tool initialization failed."), SG_UI_MSG_STYLE_FAILURE);
351  }
352  }
353  else
354  {
355  CSG_String Time =
356  Span.Get_Hours () >= 1 ? (Span.Format("%Hh %Mm %Ss"))
357  : Span.Get_Minutes () >= 1 ? (Span.Format( "%Mm %Ss"))
358  : Span.Get_Seconds () >= 1 ? (Span.Format( "%Ss"))
359  : Span.Get_Milliseconds() >= 1 ? (Span.Format("%l ") + _TL("milliseconds"))
360  : CSG_String(_TL("less than 1 millisecond"));
361 
363  {
364  SG_UI_Msg_Add_Execution(CSG_String::Format("\n[%s] %s: %s", Get_Name().c_str(),
365  _TL("execution time"), Time.c_str()),
367  );
368  }
369  else
370  {
371  SG_UI_Msg_Add_Execution(CSG_String::Format("\n__________\n%s %s: %lld %s (%s)\n", _TL("total"),
372  _TL("execution time"), Span.Get_Milliseconds(), _TL("milliseconds"), Time.c_str()),
373  false, SG_UI_MSG_STYLE_BOLD
374  );
375 
376  ADD_MESSAGE_EXECUTION(CSG_String::Format("[%s] %s (%s)", Get_Name().c_str(),
377  bResult ? _TL("Execution succeeded") : _TL("Execution failed"), Time.c_str()),
379  );
380  }
381  }
382  }
383 
384  //-----------------------------------------------------
386 
387  m_bExecutes = false;
388 
391 
392  return( bResult );
393 }
394 
395 
397 // //
398 // //
399 // //
401 
402 //---------------------------------------------------------
403 bool CSG_Tool::_Synchronize_DataObjects(void)
404 {
405  Parameters.DataObjects_Synchronize();
406 
407  for(int i=0; i<Get_Parameters_Count(); i++)
408  {
409  Get_Parameters(i)->DataObjects_Synchronize();
410  }
411 
412  CSG_Projection Projection;
413 
414  if( do_Sync_Projections() && Get_Projection(Projection) )
415  {
416  Parameters.DataObjects_Set_Projection(Projection);
417 
418  for(int i=0; i<Get_Parameters_Count(); i++)
419  {
420  Get_Parameters(i)->DataObjects_Set_Projection(Projection);
421  }
422 
423  return( true );
424  }
425 
426  return( false );
427 }
428 
429 //---------------------------------------------------------
431 {
432  Projection.Destroy();
433 
434  Parameters.DataObjects_Get_Projection(Projection);
435 
436  for(int i=0; i<Get_Parameters_Count() && !Projection.is_Okay(); i++)
437  {
438  Get_Parameters(i)->DataObjects_Get_Projection(Projection);
439  }
440 
441  return( Projection.is_Okay() );
442 }
443 
444 
446 // //
447 // Parameters //
448 // //
450 
451 //---------------------------------------------------------
453 {
454  CSG_Parameters *pParameters = pParameter ? pParameter ->Get_Parameters() : NULL;
455  CSG_Tool *pTool = pParameters ? pParameters->Get_Tool () : NULL;
456 
457  if( pTool )
458  {
459  if( Flags & PARAMETER_CHECK_VALUES )
460  {
461  pTool->On_Parameter_Changed(pParameters, pParameter);
462  }
463 
464  if( Flags & PARAMETER_CHECK_ENABLE )
465  {
466  pTool->On_Parameters_Enable(pParameters, pParameter);
467  }
468 
469  return( 1 );
470  }
471 
472  return( 0 );
473 }
474 
475 //---------------------------------------------------------
477 {
478  return( 1 );
479 }
480 
481 //---------------------------------------------------------
483 {
484  return( 1 );
485 }
486 
487 
489 // //
490 // Extra Parameters //
491 // //
493 
494 //---------------------------------------------------------
495 CSG_Parameters * CSG_Tool::Add_Parameters(const CSG_String &Identifier, const CSG_String &Name, const CSG_String &Description)
496 {
497  CSG_Parameters *pParameters = new CSG_Parameters(); // (Name, Description, Identifier);
498 
499  pParameters->Create(this, Name, Description, Identifier);
501  pParameters->m_pTool = this;
502 
503  m_pParameters.Add(pParameters);
504 
505  return( pParameters );
506 }
507 
508 //---------------------------------------------------------
510 {
511  for(int i=0; i<Get_Parameters_Count(); i++)
512  {
513  if( Get_Parameters(i)->Cmp_Identifier(Identifier) )
514  {
515  return( Get_Parameters(i) );
516  }
517  }
518 
519  return( NULL );
520 }
521 
522 //---------------------------------------------------------
523 bool CSG_Tool::Dlg_Parameters(const CSG_String &Identifier)
524 {
525  CSG_Parameters *pParameters = Get_Parameters(Identifier);
526 
527  if( pParameters && (!pParameters->is_Managed() || Dlg_Parameters(pParameters, Get_Name())) )
528  {
529  pParameters->Set_History(History_Supplement);
530 
531  return( true );
532  }
533 
534  return( false );
535 }
536 
537 
539 // //
541 
542 //---------------------------------------------------------
543 bool CSG_Tool::Dlg_Parameters(CSG_Parameters *pParameters, const CSG_String &Caption)
544 {
545  return( pParameters ? Dlg_Parameters(*pParameters, Caption) : false );
546 }
547 
548 bool CSG_Tool::Dlg_Parameters(CSG_Parameters &Parameters, const CSG_String &Caption)
549 {
550  return( SG_UI_Dlg_Parameters(&Parameters, Caption.is_Empty() ? Get_Name() : Caption) );
551 }
552 
553 
555 // //
557 
558 //---------------------------------------------------------
559 void CSG_Tool::Set_Callback(bool bActive)
560 {
561  Parameters.Set_Callback(bActive);
562 
563  for(int i=0; i<Get_Parameters_Count(); i++)
564  {
565  Get_Parameters(i)->Set_Callback(bActive);
566  }
567 }
568 
569 //---------------------------------------------------------
571 {
572  Parameters.Set_Manager(pManager);
573 
574  for(int i=0; i<Get_Parameters_Count(); i++)
575  {
576  Get_Parameters(i)->Set_Manager(pManager);
577  }
578 
579  return( true );
580 }
581 
582 //---------------------------------------------------------
584 {
585  return( Parameters.Get_Manager() );
586 }
587 
588 //---------------------------------------------------------
590 {
592 
593  return( Get_Manager() );
594 }
595 
596 //---------------------------------------------------------
597 bool CSG_Tool::Delete_Manager(bool bDetachData, bool bReset)
598 {
599  CSG_Data_Manager *pManager = Get_Manager();
600 
601  if( pManager && pManager != &SG_Get_Data_Manager() )
602  {
603  pManager->Delete(bDetachData);
604 
605  delete(pManager);
606 
607  return( bReset ? Set_Manager(&SG_Get_Data_Manager()) : Set_Manager(NULL) );
608  }
609 
610  return( false );
611 }
612 
613 
615 // //
616 // //
617 // //
619 
620 //---------------------------------------------------------
622 {
623  Parameters.Push(pManager);
624 
625  for(int i=0; i<Get_Parameters_Count(); i++)
626  {
627  Get_Parameters(i)->Push(pManager);
628  }
629 
630  return( true );
631 }
632 
633 //---------------------------------------------------------
635 {
636  Parameters.Pop();
637 
638  for(int i=0; i<Get_Parameters_Count(); i++)
639  {
640  Get_Parameters(i)->Pop();
641  }
642 
643  return( true );
644 }
645 
646 
648 // //
649 // Progress //
650 // //
652 
653 //---------------------------------------------------------
655 {
656  m_bShow_Progress = bOn;
657 }
658 
659 //---------------------------------------------------------
660 bool CSG_Tool::Set_Progress(int Position, int Range) const
661 {
662  return( Set_Progress((double)Position / (double)Range) );
663 }
664 
665 //---------------------------------------------------------
666 bool CSG_Tool::Set_Progress(sLong Position, sLong Range) const
667 {
668  return( Set_Progress((double)Position / (double)Range) );
669 }
670 
671 //---------------------------------------------------------
672 bool CSG_Tool::Set_Progress(double Position, double Range) const
673 {
674  return( m_bShow_Progress ? SG_UI_Process_Set_Progress(Position, Range) : Process_Get_Okay(false) );
675 }
676 
677 //---------------------------------------------------------
678 bool CSG_Tool::Stop_Execution(bool bDialog)
679 {
680  m_bExecutes = false;
681 
682  return( SG_UI_Stop_Execution(bDialog) );
683 }
684 
685 
687 // //
688 // Message //
689 // //
691 
692 //---------------------------------------------------------
693 void CSG_Tool::Message_Dlg(const CSG_String &Text, const SG_Char *Caption)
694 {
695  SG_UI_Dlg_Message(Text, Caption && Caption[0] != '\0' ? Caption : Get_Name().c_str());
696 }
697 
698 //---------------------------------------------------------
699 bool CSG_Tool::Message_Dlg_Confirm(const CSG_String &Text, const SG_Char *Caption)
700 {
701  return( SG_UI_Dlg_Continue(Text, Caption && Caption[0] != '\0' ? Caption : Get_Name().c_str()) );
702 }
703 
704 //---------------------------------------------------------
706 {
707  switch( Error_ID )
708  {
709  default:
710  return( Error_Set(_TL("Unknown Error")) );
711 
713  return( Error_Set(_TL("Calculation Error")) );
714  }
715 }
716 
717 //---------------------------------------------------------
719 {
720  SG_UI_Msg_Add_Error(Text);
721 
722  m_Execution_Info += "\n____\n" + Text;
723 
724  if( SG_UI_Process_Get_Okay(false) && !m_bError_Ignore )
725  {
726  switch( SG_UI_Dlg_Error(Text, CSG_String::Format("%s: %s?", _TL("Error"), _TL("Ignore"))) )
727  {
728  default:
729  SG_UI_Process_Set_Okay(false);
730  break;
731 
732  case 1:
733  m_bError_Ignore = true;
734  break;
735  }
736  }
737 
738  return( SG_UI_Process_Get_Okay(false) );
739 }
740 
741 //---------------------------------------------------------
742 bool CSG_Tool::Error_Fmt(const char *Format, ...)
743 {
744  wxString _s;
745 
746  va_list argptr;
747 
748 #ifdef _SAGA_LINUX
749  // workaround as we only use wide characters
750  // since wx 2.9.4 so interpret strings as multibyte
751  wxString _Format(Format); _Format.Replace("%s", "%ls");
752  va_start(argptr, _Format);
753  _s.PrintfV(_Format, argptr);
754 #else
755  va_start(argptr, Format);
756  _s.PrintfV(Format, argptr);
757 #endif
758 
759  va_end(argptr);
760 
761  CSG_String s(&_s);
762 
763  return( Error_Set(s) );
764 }
765 
766 //---------------------------------------------------------
767 bool CSG_Tool::Error_Fmt(const wchar_t *Format, ...)
768 {
769  wxString _s;
770 
771  va_list argptr;
772 
773 #ifdef _SAGA_LINUX
774  // workaround as we only use wide characters
775  // since wx 2.9.4 so interpret strings as multibyte
776  wxString _Format(Format); _Format.Replace("%s", "%ls");
777  va_start(argptr, _Format);
778  _s.PrintfV(_Format, argptr);
779 #else
780  va_start(argptr, Format);
781  _s.PrintfV(Format, argptr);
782 #endif
783 
784  va_end(argptr);
785 
786  CSG_String s(&_s);
787 
788  return( Error_Set(s) );
789 }
790 
791 
793 // //
794 // DataObjects / GUI Interaction //
795 // //
797 
798 //---------------------------------------------------------
799 bool CSG_Tool::DataObject_Add(CSG_Data_Object *pDataObject, bool bShow)
800 {
801  if( Parameters.Get_Manager() )
802  {
803  Parameters.Get_Manager()->Add(pDataObject);
804  }
805 
806  if( Parameters.Get_Manager() == &SG_Get_Data_Manager() ) // prevent that local data manager send their data objects to gui
807  {
809  }
810 
811  return( true );
812 }
813 
814 //---------------------------------------------------------
816 {
817  for(int i=0; i<Parameters.Get_Count(); i++)
818  {
819  if( Parameters(i)->is_Output() )
820  {
821  if( Parameters(i)->is_DataObject() )
822  {
823  DataObject_Update(Parameters(i)->asDataObject(), false);
824  }
825  else if( Parameters(i)->is_DataObject_List() )
826  {
827  for(int j=0; j<Parameters(i)->asList()->Get_Item_Count(); j++)
828  {
829  DataObject_Update(Parameters(i)->asList()->Get_Item(j), false);
830  }
831  }
832  }
833  }
834 }
835 
836 
838 // //
839 // Static Data Message/Progress Functions //
840 // //
842 
843 //---------------------------------------------------------
844 bool CSG_Tool::Process_Get_Okay(bool bBlink)
845 {
846  return( SG_UI_Process_Get_Okay(bBlink) );
847 }
848 
849 //---------------------------------------------------------
851 {
853 }
854 
855 //---------------------------------------------------------
856 void CSG_Tool::Process_Set_Text(const char *Format, ...)
857 {
858  wxString _s;
859 
860  va_list argptr;
861 
862  #ifdef _SAGA_LINUX
863  // workaround as we only use wide characters
864  // since wx 2.9.4 so interpret strings as multibyte
865  wxString _Format(Format); _Format.Replace("%s", "%ls");
866  va_start(argptr, _Format);
867  _s.PrintfV(_Format, argptr);
868  #else
869  va_start(argptr, Format);
870  _s.PrintfV(Format, argptr);
871  #endif
872 
873  va_end(argptr);
874 
875  CSG_String s(&_s);
876 
878 }
879 
880 //---------------------------------------------------------
881 void CSG_Tool::Process_Set_Text(const wchar_t *Format, ...)
882 {
883  wxString _s;
884 
885  va_list argptr;
886 
887  #ifdef _SAGA_LINUX
888  // workaround as we only use wide characters
889  // since wx 2.9.4 so interpret strings as multibyte
890  wxString _Format(Format); _Format.Replace("%s", "%ls");
891  va_start(argptr, _Format);
892  _s.PrintfV(_Format, argptr);
893  #else
894  va_start(argptr, Format);
895  _s.PrintfV(Format, argptr);
896  #endif
897 
898  va_end(argptr);
899 
900  CSG_String s(&_s);
901 
903 }
904 
905 //---------------------------------------------------------
906 void CSG_Tool::Message_Add(const CSG_String &Text, bool bNewLine)
907 {
908  SG_UI_Msg_Add_Execution(Text, bNewLine);
909 
910  if( bNewLine )
911  {
912  m_Execution_Info += "\n";
913  }
914 
915  m_Execution_Info += Text;
916 }
917 
918 //---------------------------------------------------------
919 void CSG_Tool::Message_Fmt(const char *Format, ...)
920 {
921  wxString _s;
922 
923  va_list argptr;
924 
925  #ifdef _SAGA_LINUX
926  // workaround as we only use wide characters
927  // since wx 2.9.4 so interpret strings as multibyte
928  wxString _Format(Format); _Format.Replace("%s", "%ls");
929  va_start(argptr, _Format);
930  _s.PrintfV(_Format, argptr);
931  #else
932  va_start(argptr, Format);
933  _s.PrintfV(Format, argptr);
934  #endif
935 
936  va_end(argptr);
937 
938  CSG_String s(&_s);
939 
940  Message_Add(s, false);
941 }
942 
943 //---------------------------------------------------------
944 void CSG_Tool::Message_Fmt(const wchar_t *Format, ...)
945 {
946  wxString _s;
947 
948  va_list argptr;
949 
950  #ifdef _SAGA_LINUX
951  // workaround as we only use wide characters
952  // since wx 2.9.4 so interpret strings as multibyte
953  wxString _Format(Format); _Format.Replace("%s", "%ls");
954  va_start(argptr, _Format);
955  _s.PrintfV(_Format, argptr);
956  #else
957  va_start(argptr, Format);
958  _s.PrintfV(Format, argptr);
959  #endif
960 
961  va_end(argptr);
962 
963  CSG_String s(&_s);
964 
965  Message_Add(s, false);
966 }
967 
968 
970 // //
971 // Static Data Object Property Functions //
972 // //
974 
975 //---------------------------------------------------------
976 bool CSG_Tool::DataObject_Update(CSG_Data_Object *pDataObject, int Show)
977 {
978  return( SG_UI_DataObject_Update(pDataObject, Show, NULL) );
979 }
980 
981 bool CSG_Tool::DataObject_Update(CSG_Data_Object *pDataObject, double Minimum, double Maximum, int Show)
982 {
983  CSG_Parameters P;
984 
985  return( DataObject_Get_Parameters(pDataObject, P)
986  && P.Set_Parameter("STRETCH_UPDATE" , false ) // internal update flag
987  && P.Set_Parameter("STRETCH_DEFAULT" , 3 ) // manual
988  && P.Set_Parameter("METRIC_ZRANGE.MIN", Minimum)
989  && P.Set_Parameter("METRIC_ZRANGE.MAX", Maximum)
990  && SG_UI_DataObject_Update(pDataObject, Show, &P)
991  );
992 }
993 
994 //---------------------------------------------------------
996 {
997  return( SG_UI_DataObject_Colors_Get(pDataObject, &Colors) );
998 }
999 
1001 {
1002  CSG_Colors c(Colors);
1003 
1004  return( SG_UI_DataObject_Colors_Set(pDataObject, &c) );
1005 }
1006 
1007 bool CSG_Tool::DataObject_Set_Colors(CSG_Data_Object *pDataObject, int nColors, int Palette, bool bRevert)
1008 {
1009  CSG_Colors c(nColors, Palette, bRevert);
1010 
1011  return( SG_UI_DataObject_Colors_Set(pDataObject, &c) );
1012 }
1013 
1014 //---------------------------------------------------------
1016 {
1017  return( SG_UI_DataObject_Params_Get(pDataObject, &Parameters) );
1018 }
1019 
1021 {
1022  return( SG_UI_DataObject_Params_Set(pDataObject, &Parameters) );
1023 }
1024 
1026 {
1027  if( pDataObject == pCopy )
1028  {
1029  return( true );
1030  }
1031 
1032  CSG_Parameters P;
1033 
1034  if( DataObject_Get_Parameters(pCopy, P) )
1035  {
1036  P.Del_Parameter("OBJECT_NODATA" );
1037  P.Del_Parameter("OBJECT_Z_FACTOR");
1038  P.Del_Parameter("OBJECT_Z_OFFSET");
1039 
1040  return( DataObject_Set_Parameters(pDataObject, P) );
1041  }
1042 
1043  return( false );
1044 }
1045 
1046 //---------------------------------------------------------
1048 {
1049  static CSG_Parameters P;
1050 
1051  return( DataObject_Get_Parameters(pDataObject, P) ? P(ID) : NULL );
1052 }
1053 
1055 {
1056  CSG_Parameters P;
1057 
1058  return( P._Add(pParameter) != NULL && DataObject_Set_Parameters(pDataObject, P) );
1059 }
1060 
1062 {
1063  CSG_Parameter *pParameter = DataObject_Get_Parameter(pCopy, ID);
1064 
1065  return( DataObject_Set_Parameter(pDataObject, pParameter) );
1066 }
1067 
1068 bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, int Value)
1069 {
1070  CSG_Parameters P;
1071 
1072  if( DataObject_Get_Parameters(pDataObject, P) && P(ID) )
1073  {
1074  return( P(ID)->Set_Value(Value) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1075  }
1076 
1077  return( false );
1078 }
1079 
1080 bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, double Value)
1081 {
1082  CSG_Parameters P;
1083 
1084  if( DataObject_Get_Parameters(pDataObject, P) && P(ID) )
1085  {
1086  return( P(ID)->Set_Value(Value) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1087  }
1088 
1089  return( false );
1090 }
1091 
1092 bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, void *Value)
1093 {
1094  CSG_Parameters P;
1095 
1096  if( DataObject_Get_Parameters(pDataObject, P) && P(ID) )
1097  {
1098  return( P(ID)->Set_Value(Value) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1099  }
1100 
1101  return( false );
1102 }
1103 
1104 bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, const SG_Char *Value)
1105 {
1106  CSG_Parameters P;
1107 
1108  if( DataObject_Get_Parameters(pDataObject, P) && P(ID) )
1109  {
1110  return( P(ID)->Set_Value(Value) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1111  }
1112 
1113  return( false );
1114 }
1115 
1116 bool CSG_Tool::DataObject_Set_Parameter (CSG_Data_Object *pDataObject, const CSG_String &ID, double loVal, double hiVal) // Range Parameter
1117 {
1118  CSG_Parameters P;
1119 
1120  if( DataObject_Get_Parameters(pDataObject, P) && P(ID) && P(ID)->Get_Type() == PARAMETER_TYPE_Range )
1121  {
1122  return( P(ID)->asRange()->Set_Range(loVal, hiVal) && DataObject_Set_Parameter(pDataObject, P(ID)) );
1123  }
1124 
1125  return( false );
1126 }
1127 
1128 
1130 // //
1131 // //
1132 // //
1134 
1135 //---------------------------------------------------------
1139 //---------------------------------------------------------
1140 bool CSG_Tool::Set_Parameter(const CSG_String &ID, CSG_Parameter *pValue) { return( Parameters.Set_Parameter(ID, pValue) ); }
1141 bool CSG_Tool::Set_Parameter(const char *ID, CSG_Parameter *pValue) { return( Parameters.Set_Parameter(ID, pValue) ); }
1142 bool CSG_Tool::Set_Parameter(const wchar_t *ID, CSG_Parameter *pValue) { return( Parameters.Set_Parameter(ID, pValue) ); }
1143 
1144 //---------------------------------------------------------
1148 //---------------------------------------------------------
1149 bool CSG_Tool::Set_Parameter(const CSG_String &ID, int Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1150 bool CSG_Tool::Set_Parameter(const char *ID, int Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1151 bool CSG_Tool::Set_Parameter(const wchar_t *ID, int Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1152 
1153 //---------------------------------------------------------
1157 //---------------------------------------------------------
1158 bool CSG_Tool::Set_Parameter(const CSG_String &ID, double Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1159 bool CSG_Tool::Set_Parameter(const char *ID, double Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1160 bool CSG_Tool::Set_Parameter(const wchar_t *ID, double Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1161 
1162 //---------------------------------------------------------
1166 //---------------------------------------------------------
1167 bool CSG_Tool::Set_Parameter(const CSG_String &ID, void *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1168 bool CSG_Tool::Set_Parameter(const char *ID, void *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1169 bool CSG_Tool::Set_Parameter(const wchar_t *ID, void *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1170 
1171 //---------------------------------------------------------
1175 //---------------------------------------------------------
1176 bool CSG_Tool::Set_Parameter(const CSG_String &ID, const CSG_String &Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1177 bool CSG_Tool::Set_Parameter(const char *ID, const CSG_String &Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1178 bool CSG_Tool::Set_Parameter(const wchar_t *ID, const CSG_String &Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1179 
1180 //---------------------------------------------------------
1184 //---------------------------------------------------------
1185 bool CSG_Tool::Set_Parameter(const CSG_String &ID, const char *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1186 bool CSG_Tool::Set_Parameter(const char *ID, const char *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1187 bool CSG_Tool::Set_Parameter(const wchar_t *ID, const char *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1188 
1189 //---------------------------------------------------------
1193 //---------------------------------------------------------
1194 bool CSG_Tool::Set_Parameter(const CSG_String &ID, const wchar_t *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1195 bool CSG_Tool::Set_Parameter(const char *ID, const wchar_t *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1196 bool CSG_Tool::Set_Parameter(const wchar_t *ID, const wchar_t *Value, int Type) { return( Parameters.Set_Parameter(ID, Value, Type) ); }
1197 
1198 
1200 // //
1201 // //
1202 // //
1204 
1205 //---------------------------------------------------------
1211 bool CSG_Tool::Reset(bool bManager)
1212 {
1214 
1215  if( bManager )
1216  {
1217  Reset_Manager();
1218  }
1219 
1220  for(int i=0; i<Get_Parameters_Count(); i++)
1221  {
1222  Get_Parameters(i)->Restore_Defaults(true);
1223  }
1224 
1225  return( Parameters.Restore_Defaults(true) );
1226 }
1227 
1228 //---------------------------------------------------------
1234 {
1235  return( Set_Manager(&SG_Get_Data_Manager()) );
1236 }
1237 
1238 //---------------------------------------------------------
1244 {
1245  for(int i=0; i<Get_Parameters_Count(); i++)
1246  {
1248  }
1249 
1250  return( Parameters.Reset_Grid_System() );
1251 }
1252 
1253 //---------------------------------------------------------
1259 {
1260  return( Parameters.Set_Grid_System(System) );
1261 }
1262 
1263 //---------------------------------------------------------
1269 {
1270  return( Parameters.Get_Grid_System() );
1271 }
1272 
1273 
1275 // //
1276 // //
1277 // //
1279 
1280 //---------------------------------------------------------
1282 {
1283  _Update_Parameter_States(&Parameters);
1284 
1285  for(int i=0; i<Get_Parameters_Count(); i++)
1286  {
1287  _Update_Parameter_States(Get_Parameters(i));
1288  }
1289 
1290  return( true );
1291 }
1292 
1293 //---------------------------------------------------------
1294 void CSG_Tool::_Update_Parameter_States(CSG_Parameters *pParameters)
1295 {
1296  if( pParameters )
1297  {
1298  for(int i=0; i<pParameters->Get_Count(); i++)
1299  {
1300  CSG_Parameter *pParameter = pParameters->Get_Parameter(i);
1301 
1302  if( pParameter->Get_Type() == PARAMETER_TYPE_Parameters )
1303  {
1304  _Update_Parameter_States(pParameter->asParameters());
1305  }
1306  else
1307  {
1308  On_Parameters_Enable(pParameters, pParameter);
1309  }
1310  }
1311  }
1312 }
1313 
1314 
1316 // //
1317 // Script //
1318 // //
1320 
1321 //---------------------------------------------------------
1322 CSG_String CSG_Tool::Get_Script(TSG_Tool_Script_Type Type, bool bHeader, bool bAllParameters)
1323 {
1324  switch( Type )
1325  {
1326  case TOOL_SCRIPT_CMD_SHELL : return( _Get_Script_CMD ( bHeader, bAllParameters, Type) );
1327  case TOOL_SCRIPT_CMD_BATCH : return( _Get_Script_CMD ( bHeader, bAllParameters, Type) );
1328  case TOOL_SCRIPT_CMD_USAGE : return( _Get_Script_CMD_Usage ( ) );
1329  case TOOL_SCRIPT_CHAIN : return( CSG_Tool_Chain::Get_Script(this, bHeader, bAllParameters ) );
1330  case TOOL_SCRIPT_PYTHON : return( _Get_Script_Python ( bHeader, bAllParameters ) );
1331  case TOOL_SCRIPT_PYTHON_WRAP_NAME : return( _Get_Script_Python_Wrap ( bHeader, true , false, false ) );
1332  case TOOL_SCRIPT_PYTHON_WRAP_NAME_CALL : return( _Get_Script_Python_Wrap ( bHeader, true , true , true ) );
1333  case TOOL_SCRIPT_PYTHON_WRAP_NAME_CALL_FULL: return( _Get_Script_Python_Wrap ( bHeader, true , true , false ) );
1334  case TOOL_SCRIPT_PYTHON_WRAP_ID : return( _Get_Script_Python_Wrap ( bHeader, false, false, false ) );
1335  case TOOL_SCRIPT_PYTHON_WRAP_ID_CALL : return( _Get_Script_Python_Wrap ( bHeader, false, true , false ) );
1336  }
1337 
1338  return( "" );
1339 }
1340 
1341 
1343 // //
1345 
1346 //---------------------------------------------------------
1347 CSG_String CSG_Tool::_Get_Script_CMD(bool bHeader, bool bAllParameters, TSG_Tool_Script_Type Type)
1348 {
1349  CSG_String Script;
1350 
1351  if( bHeader )
1352  {
1353  switch( Type )
1354  {
1355  case TOOL_SCRIPT_CMD_BATCH: // DOS/Windows Batch Script
1356  Script += "@ECHO OFF\n\n";
1357  Script += "PUSHD %~dp0\n\n";
1358  Script += "REM SET SAGA_TLB=C:\\MyTools\n\n";
1359  Script += "SET SAGA_CMD=" + SG_UI_Get_Application_Path(true) + "saga_cmd.exe\n\n";
1360  Script += "REM Tool: " + Get_Name() + "\n\n";
1361  Script += "%SAGA_CMD%";
1362  break;
1363 
1364  default : // Bash Shell Script
1365  Script += "#!/bin/bash\n\n";
1366  Script += "# export SAGA_TLB=/home/myhome/mytools\n\n";
1367  Script += "# tool: " + Get_Name() + "\n\n";
1368  Script += "saga_cmd";
1369  break;
1370  }
1371  }
1372  else
1373  {
1374  Script += "saga_cmd";
1375  }
1376 
1377  //-----------------------------------------------------
1378  Script += Get_Library().Contains(" ") // white space? use quotation marks!
1379  ? " \"" + Get_Library() + "\""
1380  : " " + Get_Library();
1381 
1382  Script += Get_ID().Contains (" ") // white space? use quotation marks!
1383  ? " \"" + Get_ID () + "\""
1384  : " " + Get_ID ();
1385 
1386  _Get_Script_CMD(Script, Get_Parameters(), bAllParameters, Type);
1387 
1388  for(int i=0; i<Get_Parameters_Count(); i++)
1389  {
1390  _Get_Script_CMD(Script, Get_Parameters(i), bAllParameters, Type);
1391  }
1392 
1393  //-----------------------------------------------------
1394  if( bHeader && Type == TOOL_SCRIPT_CMD_BATCH )
1395  {
1396  Script += "\n\nPAUSE\n";
1397  }
1398 
1399  return( Script );
1400 }
1401 
1402 //---------------------------------------------------------
1403 void CSG_Tool::_Get_Script_CMD(CSG_String &Script, CSG_Parameters *pParameters, bool bAllParameters, TSG_Tool_Script_Type Type)
1404 {
1405  #define GET_ID1(p) (p->Get_Parameters()->Get_Identifier().Length() > 0 \
1406  ? CSG_String::Format("%s_%s", p->Get_Parameters()->Get_Identifier().c_str(), p->Get_Identifier()) \
1407  : CSG_String::Format(p->Get_Identifier())).c_str()
1408 
1409  #define GET_ID2(p, s) CSG_String::Format("%s_%s", GET_ID1(p), s).c_str()
1410 
1411  CSG_String Prefix;
1412 
1413  switch( Type )
1414  {
1415  case TOOL_SCRIPT_CMD_BATCH: Prefix = " ^\n -" ; break;
1416  default : Prefix = " \\\n -"; break;
1417  }
1418 
1419  //-----------------------------------------------------
1420  for(int iParameter=0; iParameter<pParameters->Get_Count(); iParameter++)
1421  {
1422  CSG_Parameter *p = pParameters->Get_Parameter(iParameter);
1423 
1424  if( !bAllParameters && (!p->is_Enabled(false) || p->is_Information() || !p->do_UseInCMD()) )
1425  {
1426  continue;
1427  }
1428 
1429  switch( p->Get_Type() )
1430  {
1431  default:
1432  break;
1433 
1434  case PARAMETER_TYPE_Bool :
1435  Script += Prefix + CSG_String::Format("%s=%d", GET_ID1(p), p->asBool() ? 1 : 0);
1436  break;
1437 
1438  case PARAMETER_TYPE_Int :
1440  case PARAMETER_TYPE_Choice :
1442  Script += Prefix + CSG_String::Format("%s=%d", GET_ID1(p), p->asInt());
1443  break;
1444 
1445  case PARAMETER_TYPE_Choices :
1447  if( p->asString() && *p->asString() )
1448  Script += Prefix + CSG_String::Format("%s=%s", GET_ID1(p), p->asString());
1449  break;
1450 
1451  case PARAMETER_TYPE_Color :
1452  Script += Prefix + CSG_String::Format("%s=\"%s\"", GET_ID1(p), SG_Color_To_Text(p->asColor()).c_str());
1453  break;
1454 
1455  case PARAMETER_TYPE_Double :
1456  case PARAMETER_TYPE_Degree :
1457  Script += Prefix + CSG_String::Format("%s=%g", GET_ID1(p), p->asDouble());
1458  break;
1459 
1460  case PARAMETER_TYPE_Range :
1461  Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T("MIN")), p->asRange()->Get_Min());
1462  Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T("MAX")), p->asRange()->Get_Max());
1463  break;
1464 
1465  case PARAMETER_TYPE_String :
1466  if( ((CSG_Parameter_String *)p)->is_Password() )
1467  {
1468  Script += Prefix + CSG_String::Format("%s=\"***\"", GET_ID1(p));
1469  break;
1470  }
1471 
1472  case PARAMETER_TYPE_Date :
1473  case PARAMETER_TYPE_Text :
1475  Script += Prefix + CSG_String::Format("%s=\"%s\"", GET_ID1(p), p->asString());
1476  break;
1477 
1479  Script += Prefix + CSG_String::Format("%s=%s", GET_ID1(p), p->asString());
1480  break;
1481 
1483  if( p->Get_Children_Count() == 0 )
1484  {
1485  Script += Prefix + CSG_String::Format("%s=%d", GET_ID2(p, SG_T("NX")), p->asGrid_System()->Get_NX());
1486  Script += Prefix + CSG_String::Format("%s=%d", GET_ID2(p, SG_T("NY")), p->asGrid_System()->Get_NY());
1487  Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T( "X")), p->asGrid_System()->Get_XMin());
1488  Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T( "Y")), p->asGrid_System()->Get_YMin());
1489  Script += Prefix + CSG_String::Format("%s=%g", GET_ID2(p, SG_T( "D")), p->asGrid_System()->Get_Cellsize());
1490  }
1491  break;
1492 
1494  case PARAMETER_TYPE_Grid :
1495  case PARAMETER_TYPE_Grids :
1496  case PARAMETER_TYPE_Table :
1497  case PARAMETER_TYPE_Shapes :
1498  case PARAMETER_TYPE_TIN :
1500  if( p->is_Input() )
1501  {
1502  Script += Prefix + CSG_String::Format("%s=\"%s\"", GET_ID1(p), SG_Get_Data_Manager().Exists(p->asDataObject()) && p->asDataObject()->Get_File_Name() ? p->asDataObject()->Get_File_Name() : SG_T("input file"));
1503  }
1504  else
1505  {
1506  CSG_String ext;
1507 
1508  switch( p->Get_DataObject_Type() )
1509  {
1510  case SG_DATAOBJECT_TYPE_Grid : ext = "sg-grd-z"; break;
1511  case SG_DATAOBJECT_TYPE_Grids : ext = "sg-gds-z"; break;
1512  case SG_DATAOBJECT_TYPE_Table : ext = "txt" ; break;
1513  case SG_DATAOBJECT_TYPE_Shapes : ext = "geojson" ; break;
1514  case SG_DATAOBJECT_TYPE_PointCloud: ext = "sg-pts-z"; break;
1515  case SG_DATAOBJECT_TYPE_TIN : ext = "geojson" ; break;
1516  default : ext = "dat" ; break;
1517  }
1518 
1519  Script += Prefix + CSG_String::Format("%s=\"%s.%s\"", GET_ID1(p), p->Get_Name(), ext.c_str());
1520  }
1521  break;
1522 
1529  if( p->is_Input() )
1530  {
1531  Script += Prefix + CSG_String::Format("%s=", GET_ID1(p));
1532 
1533  if( p->asList()->Get_Item_Count() == 0 )
1534  {
1535  Script += "file(s)";
1536  }
1537  else
1538  {
1539  Script += SG_File_Exists(p->asList()->Get_Item(0)->Get_File_Name())
1540  ? p->asList()->Get_Item(0)->Get_File_Name() : _TL("memory");
1541 
1542  for(int iObject=1; iObject<p->asList()->Get_Item_Count(); iObject++)
1543  {
1544  Script += ";";
1545  Script += SG_File_Exists(p->asList()->Get_Item(iObject)->Get_File_Name())
1546  ? p->asList()->Get_Item(iObject)->Get_File_Name() : _TL("memory");
1547  }
1548  }
1549  }
1550  else
1551  {
1552  Script += Prefix + CSG_String::Format("%s=\"%s\"", GET_ID1(p), p->Get_Name());
1553  }
1554  break;
1555  }
1556  }
1557 }
1558 
1559 
1561 // //
1563 
1564 //---------------------------------------------------------
1565 CSG_String CSG_Tool::_Get_Script_CMD_Usage(void)
1566 {
1567  wxCmdLineParser Parser; Parser.SetSwitchChars("-");
1568 
1569  _Get_Script_CMD_Usage(Get_Parameters(), Parser);
1570 
1571  for(int i=0; i<Get_Parameters_Count(); i++)
1572  {
1573  _Get_Script_CMD_Usage(Get_Parameters(i), Parser);
1574  }
1575 
1576  wxString Usage = wxString::Format("\nUsage: saga_cmd %s %s %s", Get_Library().c_str(), Get_ID().c_str(),
1577  Parser.GetUsageString().AfterFirst(' ').AfterFirst(' ')
1578  );
1579 
1580  CSG_String _Usage(&Usage);
1581 
1582  return( _Usage );
1583 }
1584 
1585 //---------------------------------------------------------
1586 void CSG_Tool::_Get_Script_CMD_Usage(CSG_Parameters *pParameters, wxCmdLineParser &Parser)
1587 {
1588  for(int i=0; i<pParameters->Get_Count(); i++)
1589  {
1590  CSG_Parameter *pParameter = pParameters->Get_Parameter(i);
1591 
1592  //-------------------------------------------------
1593  if( pParameter->is_DataObject() ) // reset data object parameters, avoids problems when tool is called more than once without un-/reloading
1594  {
1595  pParameter->Set_Value(DATAOBJECT_NOTSET);
1596  }
1597  else if( pParameter->is_DataObject_List() )
1598  {
1599  pParameter->asList()->Del_Items();
1600  }
1601 
1602  //-------------------------------------------------
1603  if( pParameter->do_UseInCMD() == false )
1604  {
1605  continue;
1606  }
1607 
1608  wxString Description = pParameter->Get_Description(
1610  ).c_str();
1611 
1612  Description.Replace("\xb", ""); // unicode problem: quick'n'dirty bug fix, to be replaced
1613 
1614  wxString ID(pParameter->Get_CmdID().c_str());
1615 
1616  if( pParameter->is_Input() || pParameter->is_Output() )
1617  {
1618  Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_NEEDS_SEPARATOR|wxCMD_LINE_PARAM_OPTIONAL);
1619  }
1620 
1621  //-------------------------------------------------
1622  else if( pParameter->is_Option() && !pParameter->is_Information() )
1623  {
1624  switch( pParameter->Get_Type() )
1625  {
1627  _Get_Script_CMD_Usage(pParameter->asParameters(), Parser);
1628  break;
1629 
1630  case PARAMETER_TYPE_Bool :
1631  Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
1632  break;
1633 
1634  case PARAMETER_TYPE_Int :
1635  Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
1636  break;
1637 
1639  case PARAMETER_TYPE_Choice :
1640  case PARAMETER_TYPE_Choices :
1643  Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
1644  break;
1645 
1646  case PARAMETER_TYPE_Double :
1647  case PARAMETER_TYPE_Degree :
1648  Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
1649  break;
1650 
1651  case PARAMETER_TYPE_Date :
1652  Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_DATE , wxCMD_LINE_PARAM_OPTIONAL);
1653  break;
1654 
1655  case PARAMETER_TYPE_Range :
1656  Parser.AddOption(ID + "_MIN", wxEmptyString, Description, wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
1657  Parser.AddOption(ID + "_MAX", wxEmptyString, Description, wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
1658  break;
1659 
1660  case PARAMETER_TYPE_Color :
1661  Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
1662  break;
1663 
1664  case PARAMETER_TYPE_Colors :
1665  Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
1666  break;
1667 
1668  case PARAMETER_TYPE_String :
1669  case PARAMETER_TYPE_Text :
1671  Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
1672  break;
1673 
1675  Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
1676  break;
1677 
1679  if( pParameter->Get_Children_Count() == 0 )
1680  {
1681  Parser.AddOption(ID + "_D" , wxEmptyString, _TL("Cell Size" ), wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
1682  Parser.AddOption(ID + "_X" , wxEmptyString, _TL("Lower Left Center Cell X-Coordinate"), wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
1683  Parser.AddOption(ID + "_Y" , wxEmptyString, _TL("Lower Left Center Cell Y-Coordinate"), wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
1684  Parser.AddOption(ID + "_NX" , wxEmptyString, _TL("Number of Columns" ), wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
1685  Parser.AddOption(ID + "_NY" , wxEmptyString, _TL("Number of Rows" ), wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
1686  Parser.AddOption(ID + "_FILE", wxEmptyString, _TL("Grid File" ), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
1687  }
1688  break;
1689 
1690  default:
1691  break;
1692  }
1693  }
1694  }
1695 }
1696 
1697 
1699 // //
1701 
1702 //---------------------------------------------------------
1703 CSG_String CSG_Tool::_Get_Script_Python(bool bHeader, bool bAllParameters)
1704 {
1705  CSG_String Script, Name(Get_Name());
1706 
1707  Name.Replace(" ", "_");
1708  Name.Replace("(", "");
1709  Name.Replace(")", "");
1710  Name.Replace("[", "");
1711  Name.Replace("]", "");
1712  Name.Replace(".", "");
1713  Name.Replace(",", "");
1714  Name.Replace("/", "");
1715  Name.Replace("-", "");
1716 
1717  //-----------------------------------------------------
1718  if( bHeader )
1719  {
1720  Script += "#! /usr/bin/env python\n";
1721  Script += "\n";
1722  Script += "#_________________________________________\n";
1723  Script += "##########################################\n";
1724  Script += "\n";
1725 #ifdef _SAGA_MSW
1726  CSG_String AppPath = SG_UI_Get_Application_Path(true); AppPath.Replace("\\", "/");
1727  Script += "# Initialize the environment...\n";
1728  Script += "\n";
1729  Script += "# Windows: Let the 'SAGA_PATH' environment variable point to\n";
1730  Script += "# the SAGA installation folder before importing 'saga_api'!\n";
1731  Script += "# This can be defined globally in the Windows system or\n";
1732  Script += "# user environment variable settings, in the 'PySAGA/__init__.py'\n";
1733  Script += "# file, or in the individual Python script itself. To do the latter\n";
1734  Script += "# just uncomment the following line and adjust the path accordingly:\n";
1735  Script += "###import os; os.environ['SAGA_PATH'] = '" + AppPath + "'\n";
1736  Script += "\n";
1737  Script += "# Windows: The most convenient way to make PySAGA available to all your\n";
1738  Script += "# Python scripts is to copy the PySAGA folder to the 'Lib/site-packages/'\n";
1739  Script += "# folder of your Python installation. If don't want to do this or if you\n";
1740  Script += "# don't have the rights to do so, you can also copy it to the folder with\n";
1741  Script += "# the Python scripts in which you want to use PySAGA, or alternatively\n";
1742  Script += "# you can add the path containing the PySAGA folder (e.g. the path to your\n";
1743  Script += "# SAGA installation) to the PYTHONPATH environment variable. To do this\n";
1744  Script += "# from within your script you can also take the following command (just\n";
1745  Script += "# uncomment the following line and adjust the path accordingly):\n";
1746  Script += "###import sys; sys.path.insert(1, '" + AppPath + "')\n";
1747  Script += "\n";
1748 #endif // _SAGA_MSW
1749  Script += "# Import saga_api from PySAGA:\n";
1750  Script += "from PySAGA import saga_api\n";
1751  Script += "\n";
1752  Script += "\n";
1753  Script += "#_________________________________________\n";
1754  Script += "##########################################\n";
1755  Script += "def Run_" + Name + "(Results):\n";
1756  }
1757 
1758  //-----------------------------------------------------
1759  if( bHeader ) Script += " # Get the tool:\n";
1760  Script += " Tool = saga_api.SG_Get_Tool_Library_Manager().Get_Tool('" + Get_Library() + "', '" + Get_ID() + "')\n";
1761  Script += " if not Tool:\n";
1762  Script += " saga_api.SG_UI_Msg_Add_Error('Failed to request tool: " + Get_Name() + "')\n";
1763  Script += " return False\n";
1764  Script += "\n";
1765  if( bHeader ) Script += " # Set the parameter interface:\n";
1766  Script += " Tool.Reset()\n";
1767 
1768  //-------------------------------------------------
1769  _Get_Script_Python(Script, Get_Parameters(), bAllParameters);
1770 
1771  for(int iParameters=0; iParameters<Get_Parameters_Count(); iParameters++)
1772  {
1773  _Get_Script_Python(Script, Get_Parameters(iParameters), bAllParameters, Get_Parameters(iParameters)->Get_Identifier());
1774  }
1775 
1776  //-------------------------------------------------
1777  Script += "\n";
1778  if( bHeader ) Script += " # Execute the tool:\n";
1779  Script += " if not Tool.Execute():\n";
1780  Script += " saga_api.SG_UI_Msg_Add_Error('failed to execute tool: ' + Tool.Get_Name().c_str())\n";
1781  Script += " return False\n";
1782  Script += "\n";
1783  if( bHeader ) Script += " # Request the results:\n";
1784 
1785  for(int iParameter=0; iParameter<Get_Parameters()->Get_Count(); iParameter++)
1786  {
1787  CSG_Parameter *p = Get_Parameters()->Get_Parameter(iParameter);
1788 
1789  if( p->is_Output() )
1790  {
1791  CSG_String id(p->Get_Identifier()), type, ext;
1792 
1793  switch( p->Get_DataObject_Type() )
1794  {
1795  case SG_DATAOBJECT_TYPE_Grid : type = "Grid" ; ext = "sg-grd-z"; break;
1796  case SG_DATAOBJECT_TYPE_Grids : type = "Grids" ; ext = "sg-gds-z"; break;
1797  case SG_DATAOBJECT_TYPE_Table : type = "Table" ; ext = "txt" ; break;
1798  case SG_DATAOBJECT_TYPE_Shapes : type = "Shapes" ; ext = "geojson" ; break;
1799  case SG_DATAOBJECT_TYPE_PointCloud: type = "PointCloud"; ext = "sg-pts-z"; break;
1800  case SG_DATAOBJECT_TYPE_TIN : type = "TIN" ; ext = "geojson" ; break;
1801  default : type = "" ; ext = "" ; break;
1802  }
1803 
1804  if( p->is_DataObject() )
1805  {
1806  Script += " Data = Tool.Get_Parameter('" + id + "').as" + type + "()\n";
1807 
1808  if( bHeader )
1809  {
1810  Script += " Data.Save('{:s}/{:s}.{:s}'.format(Results, Data.Get_Name(), '" + ext + "'))\n\n";
1811  }
1812  }
1813  else if( p->is_DataObject_List() )
1814  {
1815  Script += " List = Tool.Get_Parameter('" + id + "').as" + type + "List()\n";
1816  Script += " for i in range(0, List.Get_Item_Count()):\n";
1817 
1818  if( bHeader )
1819  {
1820  Script += " List.Get_Item(i).Save('{:s}/{:s}_{:d}.{:s}'.format(Results, List.Get_Name(), i, '" + ext + "'))\n\n";
1821  }
1822  else
1823  {
1824  Script += " Data = List.Get_Item(i)\n";
1825  }
1826  }
1827  }
1828  }
1829 
1830  //-----------------------------------------------------
1831  if( bHeader )
1832  {
1833  Script += " # job is done, free memory resources:\n";
1834  Script += " saga_api.SG_Get_Data_Manager().Delete_All()\n";
1835  Script += "\n";
1836  Script += " return True\n";
1837  Script += "\n";
1838  Script += "\n";
1839  Script += "#_________________________________________\n";
1840  Script += "##########################################\n";
1841  Script += "print('This is a simple template for using a SAGA tool through Python.')\n";
1842  Script += "print('Please edit the script to make it work properly before using it!')\n";
1843  Script += "\n";
1844  Script += "# Run_" + Name + "('.')\n";
1845  }
1846 
1847  return( Script );
1848 }
1849 
1850 //---------------------------------------------------------
1851 void CSG_Tool::_Get_Script_Python(CSG_String &Script, CSG_Parameters *pParameters, bool bAllParameters, const CSG_String &Prefix)
1852 {
1853  for(int iParameter=0; iParameter<pParameters->Get_Count(); iParameter++)
1854  {
1855  CSG_Parameter *p = pParameters->Get_Parameter(iParameter);
1856 
1857  if( !bAllParameters && (!p->is_Enabled(false) || p->is_Information() || !p->do_UseInCMD()) )
1858  {
1859  continue;
1860  }
1861 
1862  CSG_String ID(p->Get_Identifier());
1863 
1864  if( !Prefix.is_Empty() )
1865  {
1866  ID.Prepend(Prefix + ".");
1867  }
1868 
1869  switch( p->Get_Type() )
1870  {
1871  default:
1872  break;
1873 
1874  case PARAMETER_TYPE_Bool :
1875  Script += CSG_String::Format(" Tool.Set_Parameter('%s', %s)\n", ID.c_str(), p->asBool() ? SG_T("True") : SG_T("False"));
1876  break;
1877 
1878  case PARAMETER_TYPE_Int :
1879  Script += CSG_String::Format(" Tool.Set_Parameter('%s', %d)\n", ID.c_str(), p->asInt());
1880  break;
1881 
1883  case PARAMETER_TYPE_Choice :
1884  Script += CSG_String::Format(" Tool.Set_Parameter('%s', %d) # '%s'\n", ID.c_str(), p->asInt(), p->asString());
1885  break;
1886 
1887  case PARAMETER_TYPE_Choices :
1890  Script += CSG_String::Format(" Tool.Set_Parameter('%s', '%s')\n", ID.c_str(), p->asString());
1891  break;
1892 
1893  case PARAMETER_TYPE_Color :
1894  Script += CSG_String::Format(" Tool.Set_Parameter('%s', '%s')\n", ID.c_str(), SG_Color_To_Text(p->asColor()).c_str());
1895  break;
1896 
1897  case PARAMETER_TYPE_Double :
1898  case PARAMETER_TYPE_Degree :
1899  Script += CSG_String::Format(" Tool.Set_Parameter('%s', %g)\n", ID.c_str(), p->asDouble());
1900  break;
1901 
1902  case PARAMETER_TYPE_Range :
1903  Script += CSG_String::Format(" Tool.Set_Parameter('%s.MIN', %g)\n", ID.c_str(), p->asRange()->Get_Min());
1904  Script += CSG_String::Format(" Tool.Set_Parameter('%s.MAX', %g)\n", ID.c_str(), p->asRange()->Get_Max());
1905  break;
1906 
1907  case PARAMETER_TYPE_String :
1908  if( ((CSG_Parameter_String *)p)->is_Password() )
1909  {
1910  Script += CSG_String::Format(" Tool.Set_Parameter('%s', '***')\n", ID.c_str());
1911  break;
1912  }
1913 
1914  case PARAMETER_TYPE_Date :
1915  case PARAMETER_TYPE_Text :
1917  Script += CSG_String::Format(" Tool.Set_Parameter('%s', '%s')\n", ID.c_str(), p->asString());
1918  break;
1919 
1921  Script += CSG_String::Format(" Tool.Set_Parameter('%s', saga_api.SG_Create_Table('table.txt'))\n", ID.c_str());
1922  break;
1923 
1925  if( p->Get_Children_Count() == 0 )
1926  {
1927  Script += CSG_String::Format(" Tool.Set_Parameter('%s', saga_api.CSG_Grid_System(%g, %g, %g, %d, %d))\n", ID.c_str(),
1928  p->asGrid_System()->Get_Cellsize(),
1929  p->asGrid_System()->Get_XMin(), p->asGrid_System()->Get_YMin(),
1930  p->asGrid_System()->Get_NX (), p->asGrid_System()->Get_NY ()
1931  );
1932  }
1933  break;
1934 
1935  case PARAMETER_TYPE_Grid :
1936  case PARAMETER_TYPE_Grids :
1937  case PARAMETER_TYPE_Table :
1938  case PARAMETER_TYPE_Shapes :
1939  case PARAMETER_TYPE_TIN :
1941  if( p->is_Input() )
1942  {
1943  Script += CSG_String::Format(" Tool.Set_Parameter('%s', saga_api.SG_Get_Data_Manager().Add('%s input file%s'))\n", ID.c_str(),
1944  SG_Get_DataObject_Name(p->Get_DataObject_Type()).c_str(), p->is_Optional() ? SG_T(", optional") : SG_T("")
1945  );
1946  }
1947  else if( p->is_Output() && p->is_Optional() )
1948  {
1949  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());
1950  }
1951  break;
1952 
1959  if( p->is_Input() )
1960  {
1961  Script += CSG_String::Format(" Tool.Get_Parameter('%s').asList().Add_Item('%s input list%s')\n", ID.c_str(),
1962  SG_Get_DataObject_Name(p->Get_DataObject_Type()).c_str(), p->is_Optional() ? SG_T(", optional") : SG_T("")
1963  );
1964  }
1965  break;
1966 
1968  _Get_Script_Python(Script, p->asParameters(), bAllParameters, ID);
1969  break;
1970  }
1971  }
1972 }
1973 
1974 
1976 // //
1978 
1979 //---------------------------------------------------------
1980 CSG_String CSG_Tool::_Get_Script_Python_Wrap(bool bHeader, bool bName, bool bCall, bool bOnlyNonDefaults)
1981 {
1982  CSG_String Arguments, Description, Code;
1983 
1984  for(int i=0; i<Parameters.Get_Count(); i++) // add input that is not optional in 1st place
1985  {
1986  _Get_Script_Python_Wrap(Parameters[i], PARAMETER_INPUT , Arguments, Description, Code, bCall && bHeader, bOnlyNonDefaults);
1987  }
1988 
1989  for(int i=0; i<Parameters.Get_Count(); i++) // add optional input in 2nd place
1990  {
1991  _Get_Script_Python_Wrap(Parameters[i], PARAMETER_INPUT_OPTIONAL, Arguments, Description, Code, bCall && bHeader, bOnlyNonDefaults);
1992  }
1993 
1994  for(int i=0; i<Parameters.Get_Count(); i++) // add output
1995  {
1996  _Get_Script_Python_Wrap(Parameters[i], PARAMETER_OUTPUT , Arguments, Description, Code, bCall && bHeader, bOnlyNonDefaults);
1997  }
1998 
1999  for(int i=0; i<Parameters.Get_Count(); i++) // add options
2000  {
2001  _Get_Script_Python_Wrap(Parameters[i], 0 , Arguments, Description, Code, bCall && bHeader, bOnlyNonDefaults);
2002  }
2003 
2004  //---------------------------------------------------------
2005  CSG_String Name, Expected(Get_Name()); Expected.Replace("'", "\\'");
2006 
2007  if( bName )
2008  {
2009  Name = Get_Name();
2010 
2011  if( isdigit(Name[0]) ) // ...in case first letter is a numeric character, what is not allowed for Python function names!
2012  {
2013  Name.Prepend("_");
2014  }
2015 
2016  Name.Replace(" ", "_");
2017  Name.Replace("(", "");
2018  Name.Replace(")", "");
2019  Name.Replace("[", "");
2020  Name.Replace("]", "");
2021  Name.Replace(".", "");
2022  Name.Replace(",", "");
2023  Name.Replace("/", "");
2024  Name.Replace("-", "");
2025  Name.Replace("'", "");
2026  Name.Replace("&", "and");
2027  }
2028  else
2029  {
2030  Name = "run_tool_" + Get_Library() + "_" + Get_ID();
2031 
2032  Name.Replace(" ", "_");
2033  }
2034 
2036 
2037  //---------------------------------------------------------
2038  CSG_String Script;
2039 
2040  if( bCall )
2041  {
2042  Script += "from PySAGA.tools import " + Get_Library() + "\n\n";
2043 
2044  if( bHeader )
2045  {
2046  Script += Code + "\n";
2047  }
2048 
2049  Script += Get_Library() + '.' + Name + "(" + Arguments + ")\n";
2050  }
2051  else
2052  {
2053  if( bHeader )
2054  {
2055  Script += "#! /usr/bin/env python\n";
2056  Script += "from PySAGA.helper import Tool_Wrapper\n\n";
2057  }
2058 
2059  Script += "def " + Name + "(" + Arguments + ", Verbose=2):\n";
2060  Script += " '''\n";
2061  Script += " " + Get_Name() + "\n";
2062  Script += " ----------\n";
2063  Script += " [" + Get_Library() + "." + Get_ID() + "]\\n\n";
2064  for(int i=0; i<_Description.Get_Count(); i++)
2065  {
2066  _Description[i].Trim_Both(); Script += " " + _Description[i] + "\\n\n";
2067  }
2068  Script += " Arguments\n";
2069  Script += " ----------\n";
2070  Script += Description + "\n";
2071  Script += " - Verbose [`integer number`] : Verbosity level, 0=silent, 1=tool name and success notification, 2=complete tool output.\\n\n";
2072  Script += " Returns\n";
2073  Script += " ----------\n";
2074  Script += " `boolean` : `True` on success, `False` on failure.\n";
2075  Script += " '''\n";
2076  Script += " Tool = Tool_Wrapper('" + Get_Library() + "', '" + Get_ID() + "', '" + Expected + "')\n";
2077  Script += " if Tool.is_Okay():\n";
2078  Script += Code;
2079  Script += " return Tool.Execute(Verbose)\n";
2080  Script += " return False\n\n";
2081  }
2082 
2083  return( Script );
2084 }
2085 
2086 //---------------------------------------------------------
2087 bool 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, const CSG_String &Prefix)
2088 {
2089  if( Parameter.do_UseInCMD() == false
2090  || Parameter.is_Information()
2091  || Parameter.Get_Type() == PARAMETER_TYPE_Node
2092  || Parameter.Cmp_Identifier("PARAMETERS_GRID_SYSTEM") )
2093  {
2094  return( false );
2095  }
2096 
2097  if( bCall && !Parameter.is_Enabled() )
2098  {
2099  return( false );
2100  }
2101 
2102  //-----------------------------------------------------
2103  CSG_String ID(Parameter.Get_Identifier());
2104 
2105  if( !Prefix.is_Empty() )
2106  {
2107  ID.Prepend(Prefix + ".");
2108  }
2109 
2110  CSG_String Argument(ID);
2111 
2112  if( Argument[0] >= '0' && Argument[0] <= '9' )
2113  {
2114  Argument.Prepend('_');
2115  }
2116 
2117  Argument.Replace(".", "_");
2118  Argument.Replace("|", "_");
2119  Argument.Replace(" ", "_");
2120 
2121  if( Argument.Length() > 2 )
2122  {
2123  Argument.Make_Upper();
2124  }
2125 
2126  //-----------------------------------------------------
2127  if( Parameter.asParameters() ) // PARAMETER_TYPE_Parameters
2128  {
2129  bool bResult = false;
2130 
2131  for(int i=0; i<(*Parameter.asParameters()).Get_Count(); i++)
2132  {
2133  if( _Get_Script_Python_Wrap((*Parameter.asParameters())[i], Constraint, Arguments, Description, Code, bCall, bOnlyNonDefaults, ID) )
2134  {
2135  bResult = true;
2136  }
2137  }
2138 
2139  return( bResult );
2140  }
2141 
2142  //-----------------------------------------------------
2143  if( Parameter.is_Input () && !Parameter.is_Optional() && Constraint != PARAMETER_INPUT ) { return( false ); }
2144  if( Parameter.is_Input () && Parameter.is_Optional() && Constraint != PARAMETER_INPUT_OPTIONAL ) { return( false ); }
2145  if( Parameter.is_Output() && Constraint != PARAMETER_OUTPUT ) { return( false ); }
2146  if( Parameter.is_Option() && Constraint != 0 ) { return( false ); }
2147 
2148  //-----------------------------------------------------
2149  if( bCall )
2150  {
2151  CSG_String Value;
2152 
2153  if( Parameter.is_DataObject() )
2154  {
2155  Value = Parameter.Get_Identifier(); Value.Make_Lower();
2156 
2157  if( Parameter.is_Input() )
2158  {
2159  if( !Parameter.asDataObject() && Parameter.is_Optional() ) // don't add optional input that has not been set
2160  {
2161  return( false );
2162  }
2163 
2164  CSG_String File(Parameter.asDataObject() && Parameter.asDataObject()->Get_File_Name()
2165  ? Parameter.asDataObject()->Get_File_Name() : SG_T("data object file")
2166  ); File.Replace("\\", "/");
2167 
2168  Code += Value + " = saga_api.SG_Get_Data_Manager().Add_" + SG_Get_DataObject_Class_Name(Parameter.Get_DataObject_Type()).AfterFirst('_') + "('" + File + "') # input data object\n";
2169  }
2170  else // if( Parameter.is_Output() )
2171  {
2172  if( !Parameter.asDataObject() && Parameter.is_Optional() ) // don't add optional output that has not been requested
2173  {
2174  return( false );
2175  }
2176 
2177  Code += Value + " = saga_api.SG_Get_Data_Manager().Add_" + SG_Get_DataObject_Class_Name(Parameter.Get_DataObject_Type()).AfterFirst('_') + "() # output data object\n";
2178  }
2179  }
2180  else if( Parameter.is_DataObject_List() )
2181  {
2182  Value = Parameter.Get_Identifier(); Value.Make_Lower();
2183 
2184  if( Parameter.is_Input() )
2185  {
2186  if( Parameter.asList()->Get_Item_Count() < 1 && Parameter.is_Optional() ) // don't add optional input that has not been set
2187  {
2188  return( false );
2189  }
2190 
2191  Code += Value + " = [] # Python list with input data objects of type 'saga_api." + SG_Get_DataObject_Class_Name(Parameter.Get_DataObject_Type()) + "'\n";
2192  }
2193  else // if( Parameter.is_Output() )
2194  {
2195  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";
2196  }
2197  }
2198  else if( Parameter.is_Option() )
2199  {
2200  if( bOnlyNonDefaults && Parameter.is_Default() )
2201  {
2202  return( false );
2203  }
2204 
2205  switch( Parameter.Get_Type() )
2206  {
2207  case PARAMETER_TYPE_Bool : Value = Parameter.asBool() ? "True" : "False"; break;
2208 
2209  case PARAMETER_TYPE_Int : Value.Printf("%d", Parameter.asInt()); break;
2210 
2211  case PARAMETER_TYPE_Double :
2212  case PARAMETER_TYPE_Degree : Value.Printf("%f", Parameter.asDouble()); break;
2213 
2214  case PARAMETER_TYPE_Color : Value = SG_Color_To_Text(Parameter.asColor()); break;
2215 
2216  case PARAMETER_TYPE_String :
2217  case PARAMETER_TYPE_Text :
2218  case PARAMETER_TYPE_Date :
2219  case PARAMETER_TYPE_Range :
2221  case PARAMETER_TYPE_Choice :
2222  case PARAMETER_TYPE_Choices :
2225  case PARAMETER_TYPE_FilePath : Value.Printf("'%s'", Parameter.asString()); break;
2226 
2227  default : return( false );
2228  }
2229  }
2230 
2231  if( !Value.is_Empty() )
2232  {
2233  if( !Arguments.is_Empty() )
2234  {
2235  Arguments += ", ";
2236  }
2237 
2238  Arguments += Argument + "=" + Value;
2239  }
2240 
2241  return( true );
2242  }
2243 
2244  //-----------------------------------------------------
2245  if( !Arguments.is_Empty() )
2246  {
2247  Arguments += ", ";
2248  }
2249 
2250  Arguments += Argument + "=None";
2251 
2252  //-----------------------------------------------------
2253  Code += " ";
2254 
2255  if( Parameter.is_Input () ) { Code += "Tool.Set_Input "; }
2256  if( Parameter.is_Output() ) { Code += "Tool.Set_Output"; }
2257  if( Parameter.is_Option() ) { Code += "Tool.Set_Option"; }
2258 
2259  Code += CSG_String::Format("('%s', %s)\n", ID.c_str(), Argument.c_str());
2260 
2261  //-----------------------------------------------------
2262  Description += " - " + Argument + " [`";
2263 
2264  if( Parameter.is_Input() )
2265  {
2266  Description += Parameter.is_Optional() ? "optional input " : "input ";
2267  }
2268  else if( Parameter.is_Output() )
2269  {
2270  Description += "output ";
2271  }
2272 
2273  Description += Parameter.Get_Type_Name() + "`] : " + Parameter.Get_Name();
2274 
2276 
2277  if( !s.is_Empty() )
2278  {
2279  Description += ". " + s;
2280  }
2281 
2282  Description += "\n";
2283 
2284  return( true );
2285 }
2286 
2287 
2289 // //
2290 // History //
2291 // //
2293 
2294 //---------------------------------------------------------
2295 CSG_MetaData CSG_Tool::_Get_Output_History(void)
2296 {
2297  CSG_MetaData History;
2298 
2299  History.Set_Name(SG_META_HISTORY);
2300  History.Add_Property("saga-version", SAGA_VERSION);
2301 
2302  if( SG_Get_History_Depth() )
2303  {
2304  CSG_MetaData *pTool = History.Add_Child("TOOL");
2305 
2306  pTool->Add_Property("library", Get_Library());
2307  pTool->Add_Property("id" , Get_ID ());
2308  pTool->Add_Property("name" , Get_Name ());
2309 
2310  Parameters.Set_History(*pTool);
2311 
2313 
2314  CSG_MetaData *pOutput = pTool->Add_Child("OUTPUT");
2315  pOutput->Add_Property("type", "");
2316  pOutput->Add_Property("id" , "");
2317  pOutput->Add_Property("name", "");
2318 
2319  pTool->Del_Children(SG_Get_History_Depth(), SG_T("TOOL"));
2320  }
2321 
2322  return( History );
2323 }
2324 
2325 //---------------------------------------------------------
2326 void CSG_Tool::_Set_Output_History(void)
2327 {
2328  CSG_MetaData History(_Get_Output_History());
2329 
2330  //-----------------------------------------------------
2331  for(int j=-1; j<Get_Parameters_Count(); j++)
2332  {
2333  CSG_Parameters *pParameters = j < 0 ? &Parameters : Get_Parameters(j);
2334 
2335  for(int i=0; i<pParameters->Get_Count(); i++)
2336  {
2337  CSG_Parameter *pParameter = pParameters->Get_Parameter(i);
2338 
2339  if( pParameter->is_Output() )//&& (pParameter->is_Enabled() || !has_GUI()) )
2340  {
2341  DataObject_Set_History(pParameter, &History);
2342  }
2343  }
2344  }
2345 }
2346 
2347 //---------------------------------------------------------
2349 {
2350  if( !pParameter )
2351  {
2352  return( false );
2353  }
2354 
2355  //-----------------------------------------------------
2356  CSG_MetaData History;
2357 
2358  if( !pHistory )
2359  {
2360  History = _Get_Output_History();
2361 
2362  pHistory = &History;
2363  }
2364 
2365  //-----------------------------------------------------
2366  CSG_MetaData *pOutput = pHistory->Get_Child("TOOL") ? pHistory->Get_Child("TOOL")->Get_Child("OUTPUT") : NULL;
2367 
2368  if( pOutput )
2369  {
2370  pOutput->Set_Property("type", pParameter->Get_Type_Identifier());
2371  pOutput->Set_Property("id" , pParameter->Get_Identifier ());
2372  pOutput->Set_Property("name", pParameter->Get_Name ());
2373  }
2374 
2375  //-----------------------------------------------------
2376  if( pParameter->is_DataObject() )
2377  {
2378  if( pParameter->asDataObject() )
2379  {
2380  if( pOutput )
2381  {
2382  pOutput->Set_Content(pParameter->asDataObject()->Get_Name());
2383  }
2384 
2385  pParameter->asDataObject()->Get_History().Assign(*pHistory);
2386 
2387  return( true );
2388  }
2389  }
2390 
2391  //-----------------------------------------------------
2392  else if( pParameter->is_DataObject_List() )
2393  {
2394  for(int j=0; j<pParameter->asList()->Get_Item_Count(); j++)
2395  {
2396  if( pOutput )
2397  {
2398  pOutput->Set_Content(pParameter->asList()->Get_Item(j)->Get_Name());
2399  }
2400 
2401  pParameter->asList()->Get_Item(j)->Get_History().Assign(*pHistory);
2402  }
2403 
2404  return( true );
2405  }
2406 
2407  //-----------------------------------------------------
2408  return( false );
2409 }
2410 
2411 
2413 // //
2414 // //
2415 // //
2417 
2418 //---------------------------------------------------------
CSG_MetaData::Destroy
void Destroy(void)
Definition: metadata.cpp:140
CSG_Parameter::Set_Value
virtual bool Set_Value(int Value)
Definition: parameter.cpp:799
CSG_Parameters::Get_Description
const CSG_String & Get_Description(void) const
Definition: parameters.h:1735
PARAMETER_TYPE_Double
@ PARAMETER_TYPE_Double
Definition: parameters.h:127
CSG_Parameters::Get_Parameter
CSG_Parameter * Get_Parameter(int i) const
Definition: parameters.h:1752
PARAMETER_TYPE_FilePath
@ PARAMETER_TYPE_FilePath
Definition: parameters.h:136
CSG_Parameters::Get_Grid_System
CSG_Grid_System * Get_Grid_System(void) const
Definition: parameters.h:1895
PARAMETER_TYPE_Degree
@ PARAMETER_TYPE_Degree
Definition: parameters.h:128
GET_ID1
#define GET_ID1(p)
CSG_Tool::Reset_Manager
bool Reset_Manager(void)
Definition: tool.cpp:1233
CSG_Tool::Parameters
CSG_Parameters Parameters
Definition: tool.h:257
SG_T
#define SG_T(s)
Definition: api_core.h:537
CSG_Tool::Get_Projection
bool Get_Projection(CSG_Projection &Projection) const
Definition: tool.cpp:430
CSG_String::Printf
int Printf(const char *Format,...)
Definition: api_string.cpp:308
CSG_Tool_Chain::Get_Script
static CSG_String Get_Script(CSG_Tool *pTool, bool bHeader, bool bAllParameters=true)
CSG_Grid_System::Get_Cellsize
double Get_Cellsize(void) const
Definition: grid.h:231
_TL
#define _TL(s)
Definition: api_core.h:1489
CSG_String::Make_Lower
CSG_String & Make_Lower(void)
Definition: api_string.cpp:543
CSG_Tool::DataObject_Update
static bool DataObject_Update(CSG_Data_Object *pDataObject, int Show=SG_UI_DATAOBJECT_UPDATE)
Definition: tool.cpp:976
CSG_Tool::DataObject_Set_Parameter
static bool DataObject_Set_Parameter(CSG_Data_Object *pDataObject, CSG_Parameter *pParameter)
Definition: tool.cpp:1054
SG_UI_DataObject_Params_Set
bool SG_UI_DataObject_Params_Set(CSG_Data_Object *pDataObject, CSG_Parameters *pParameters)
Definition: api_callback.cpp:722
SAGA_VERSION
#define SAGA_VERSION
Definition: saga_api.h:90
PARAMETER_TYPE_Table_Fields
@ PARAMETER_TYPE_Table_Fields
Definition: parameters.h:145
CSG_Data_Object::Get_History
CSG_MetaData & Get_History(void)
Definition: dataobject.h:236
CSG_Tool::Add_Parameters
CSG_Parameters * Add_Parameters(const CSG_String &Identifier, const CSG_String &Name, const CSG_String &Description)
Definition: tool.cpp:495
SG_HTML_Tag_Replacer
SAGA_API_DLL_EXPORT CSG_String SG_HTML_Tag_Replacer(const CSG_String &Text)
Definition: api_string.cpp:1389
TOOL_SCRIPT_CHAIN
@ TOOL_SCRIPT_CHAIN
Definition: tool.h:124
CSG_Tool::History_Supplement
CSG_MetaData History_Supplement
Definition: tool.h:259
SG_UI_Dlg_Continue
bool SG_UI_Dlg_Continue(const CSG_String &Message, const CSG_String &Caption)
Definition: api_callback.cpp:386
CSG_DateTime::Now
static CSG_DateTime Now(void)
Definition: datetime.cpp:581
CSG_Tool::Message_Add
void Message_Add(const CSG_String &Text, bool bNewLine=true)
Definition: tool.cpp:906
CSG_Parameter_Range::Get_Max
double Get_Max(void) const
Definition: parameter_data.cpp:832
CSG_Tool::Set_Show_Progress
void Set_Show_Progress(bool bOn=true)
Definition: tool.cpp:654
CSG_TimeSpan::Get_Hours
int Get_Hours(void) const
Definition: datetime.h:161
CSG_Parameters::Set_Grid_System
bool Set_Grid_System(const CSG_Grid_System &System)
Definition: parameters.cpp:2081
CSG_Parameters::Reset_Grid_System
bool Reset_Grid_System(void)
Definition: parameters.cpp:2092
CSG_Parameter::Get_Identifier
const SG_Char * Get_Identifier(void) const
Definition: parameter.cpp:547
CSG_Parameter::asInt
int asInt(void) const
Definition: parameters.h:282
CSG_Parameters::Get_Manager
class CSG_Data_Manager * Get_Manager(void) const
Definition: parameters.h:1715
PARAMETER_TYPE_Node
@ PARAMETER_TYPE_Node
Definition: parameters.h:123
CSG_Parameter::Get_Type_Name
CSG_String Get_Type_Name(void) const
Definition: parameter.cpp:129
CSG_Parameter::asString
const SG_Char * asString(void) const
Definition: parameters.h:285
CSG_MetaData::Set_Content
void Set_Content(const CSG_String &Content)
Definition: metadata.h:139
CSG_Grid_System::Get_XMin
double Get_XMin(bool bCells=false) const
Definition: grid.h:240
CSG_Tool::Create_Manager
class CSG_Data_Manager * Create_Manager(void)
Definition: tool.cpp:589
data_manager.h
SG_UI_MSG_STYLE_NORMAL
@ SG_UI_MSG_STYLE_NORMAL
Definition: api_core.h:1502
SG_UI_MSG_STYLE_SUCCESS
@ SG_UI_MSG_STYLE_SUCCESS
Definition: api_core.h:1505
PARAMETER_TYPE_Grids_List
@ PARAMETER_TYPE_Grids_List
Definition: parameters.h:155
SG_UI_Get_Application_Name
CSG_String SG_UI_Get_Application_Name(void)
Definition: api_core.cpp:378
PARAMETER_TYPE_String
@ PARAMETER_TYPE_String
Definition: parameters.h:134
CSG_Grid_System
Definition: grid.h:200
SG_Get_DataObject_Name
CSG_String SG_Get_DataObject_Name(TSG_Data_Object_Type Type)
Definition: dataobject.cpp:86
PARAMETER_TYPE_Int
@ PARAMETER_TYPE_Int
Definition: parameters.h:126
CSG_Parameter_List::Get_Item
CSG_Data_Object * Get_Item(int Index) const
Definition: parameters.h:1373
CSG_Tool::Set_Version
void Set_Version(const CSG_String &String)
Definition: tool.cpp:149
CSG_Parameter::asColor
long asColor(void) const
Definition: parameters.h:283
SG_UI_Msg_Add_Execution
void SG_UI_Msg_Add_Execution(const char *Message, bool bNewLine, TSG_UI_MSG_STYLE Style)
Definition: api_callback.cpp:529
SG_UI_Process_Get_Okay
bool SG_UI_Process_Get_Okay(bool bBlink)
Definition: api_callback.cpp:207
CSG_MetaData::Set_Property
bool Set_Property(const CSG_String &Name, const CSG_String &Value, bool bAddIfNotExists=true)
Definition: metadata.cpp:615
SG_UI_Process_Set_Okay
bool SG_UI_Process_Set_Okay(bool bOkay)
Definition: api_callback.cpp:229
CSG_Parameter::is_Input
bool is_Input(void) const
Definition: parameters.h:232
CSG_Tool::Dlg_Parameters
bool Dlg_Parameters(const CSG_String &Identifier)
Definition: tool.cpp:523
tool_chain.h
TOOL_SCRIPT_CMD_SHELL
@ TOOL_SCRIPT_CMD_SHELL
Definition: tool.h:121
CSG_Projection::is_Okay
bool is_Okay(void) const
Definition: geo_tools.h:857
CSG_Parameters::is_Managed
bool is_Managed(void) const
Definition: parameters.h:1892
saga_api.h
PARAMETER_TYPE_TIN
@ PARAMETER_TYPE_TIN
Definition: parameters.h:152
CSG_Tool::Reset
bool Reset(bool bManager=true)
Definition: tool.cpp:1211
SG_UI_Stop_Execution
bool SG_UI_Stop_Execution(bool bDialog)
Definition: api_callback.cpp:348
CSG_Tool
Definition: tool.h:151
CSG_TimeSpan::Get_Milliseconds
sLong Get_Milliseconds(void) const
Definition: datetime.h:164
CSG_Tool::DataObject_Set_History
bool DataObject_Set_History(CSG_Parameter *pParameter, CSG_MetaData *pHistory=NULL)
Definition: tool.cpp:2348
CSG_Data_Object::Get_Name
const SG_Char * Get_Name(void) const
Definition: dataobject.cpp:349
CSG_Tool::Execute
bool Execute(bool bAddHistory=false)
Definition: tool.cpp:258
CSG_Parameter::Get_Description
const SG_Char * Get_Description(void) const
Definition: parameter.cpp:602
SG_Get_Data_Manager
CSG_Data_Manager & SG_Get_Data_Manager(void)
Definition: data_manager.cpp:65
CSG_Tool::Add_Reference
void Add_Reference(const CSG_String &Authors, const CSG_String &Year, const CSG_String &Title, const CSG_String &Where, const SG_Char *Link=NULL, const SG_Char *Link_Text=NULL)
Definition: tool.cpp:171
CSG_Parameters::Cmp_Identifier
bool Cmp_Identifier(const CSG_String &Identifier) const
Definition: parameters.cpp:331
SG_DATAOBJECT_TYPE_Grids
@ SG_DATAOBJECT_TYPE_Grids
Definition: dataobject.h:119
CSG_Tool::~CSG_Tool
virtual ~CSG_Tool(void)
Definition: tool.cpp:86
CSG_Tool::Error_Set
bool Error_Set(TSG_Tool_Error Error_ID=TOOL_ERROR_Unknown)
Definition: tool.cpp:705
CSG_Parameter::do_UseInCMD
bool do_UseInCMD(void) const
Definition: parameter.cpp:172
PARAMETER_TYPE_FixedTable
@ PARAMETER_TYPE_FixedTable
Definition: parameters.h:141
CSG_Tool::Get_Name
const CSG_String & Get_Name(void) const
Definition: tool.cpp:132
TOOL_SCRIPT_PYTHON_WRAP_NAME_CALL
@ TOOL_SCRIPT_PYTHON_WRAP_NAME_CALL
Definition: tool.h:127
CSG_Parameter::asDataObject
CSG_Data_Object * asDataObject(void) const
Definition: parameter.cpp:1041
CSG_Tool::do_Sync_Projections
virtual bool do_Sync_Projections(void) const
Definition: tool.h:232
CSG_MetaData::Get_Child
CSG_MetaData * Get_Child(int Index) const
Definition: metadata.h:148
CSG_TimeSpan
Definition: datetime.h:91
CSG_Tool::Get_References
const CSG_Strings & Get_References(void) const
Definition: tool.cpp:181
TOOL_SCRIPT_PYTHON_WRAP_ID_CALL
@ TOOL_SCRIPT_PYTHON_WRAP_ID_CALL
Definition: tool.h:130
PARAMETER_TYPE_PointCloud
@ PARAMETER_TYPE_PointCloud
Definition: parameters.h:147
CSG_String::Prepend
CSG_String & Prepend(const CSG_String &String)
Definition: api_string.cpp:347
CSG_Parameters::Push
bool Push(class CSG_Data_Manager *pManager=NULL, bool bRestoreDefaults=true)
Definition: parameters.cpp:262
CSG_String::Replace
size_t Replace(const CSG_String &sOld, const CSG_String &sNew, bool bReplaceAll=true)
Definition: api_string.cpp:563
CSG_Parameter::Get_Parameters
CSG_Parameters * Get_Parameters(void) const
Definition: parameter.cpp:100
CSG_Projection::Destroy
void Destroy(void)
Definition: projections.cpp:201
CSG_Parameters::Pop
bool Pop(void)
Definition: parameters.cpp:285
CSG_Tool::Set_Author
void Set_Author(const CSG_String &String)
Definition: tool.cpp:138
CSG_String::Cmp
int Cmp(const CSG_String &String) const
Definition: api_string.cpp:515
CSG_Tool::Get_Parameters_Count
int Get_Parameters_Count(void) const
Definition: tool.h:183
tool.h
PARAMETER_INPUT_OPTIONAL
#define PARAMETER_INPUT_OPTIONAL
Definition: parameters.h:102
CSG_Tool::Get_Manager
class CSG_Data_Manager * Get_Manager(void) const
Definition: tool.cpp:583
CSG_Tool::Get_Version
const CSG_String & Get_Version(void) const
Definition: tool.cpp:154
CSG_Parameters::Msg_String
bool Msg_String(bool bOptionsOnly)
Definition: parameters.cpp:1942
PARAMETER_TYPE_Shapes_List
@ PARAMETER_TYPE_Shapes_List
Definition: parameters.h:157
CSG_Tool::DataObject_Get_Parameter
static CSG_Parameter * DataObject_Get_Parameter(CSG_Data_Object *pDataObject, const CSG_String &ID)
Definition: tool.cpp:1047
PARAMETER_TYPE_Grids
@ PARAMETER_TYPE_Grids
Definition: parameters.h:149
CSG_Parameter::Get_Type
virtual TSG_Parameter_Type Get_Type(void) const =0
CSG_Tool::Set_Parameter
bool Set_Parameter(const CSG_String &ID, CSG_Parameter *pValue)
Definition: tool.cpp:1140
CSG_Tool::Stop_Execution
bool Stop_Execution(bool bDialog=true)
Definition: tool.cpp:678
SG_UI_MSG_STYLE_FAILURE
@ SG_UI_MSG_STYLE_FAILURE
Definition: api_core.h:1506
SG_UI_DATAOBJECT_UPDATE
@ SG_UI_DATAOBJECT_UPDATE
Definition: api_core.h:1518
CSG_Parameter::is_DataObject_List
bool is_DataObject_List(void) const
Definition: parameter.cpp:295
GET_ID2
#define GET_ID2(p, s)
PARAMETER_TYPE_Choices
@ PARAMETER_TYPE_Choices
Definition: parameters.h:133
CSG_Tool::DataObject_Set_Parameters
static bool DataObject_Set_Parameters(CSG_Data_Object *pDataObject, CSG_Parameters &Parameters)
Definition: tool.cpp:1020
PARAMETER_TYPE_Data_Type
@ PARAMETER_TYPE_Data_Type
Definition: parameters.h:131
CSG_Parameter_List::Del_Items
virtual bool Del_Items(void)
Definition: parameter_data.cpp:3074
SG_File_Exists
SAGA_API_DLL_EXPORT bool SG_File_Exists(const CSG_String &FileName)
Definition: api_file.cpp:850
PARAMETER_TYPE_Colors
@ PARAMETER_TYPE_Colors
Definition: parameters.h:140
CSG_Parameters::Set_Name
void Set_Name(const CSG_String &Name)
Definition: parameters.cpp:341
SG_UI_Dlg_Message
void SG_UI_Dlg_Message(const CSG_String &Message, const CSG_String &Caption)
Definition: api_callback.cpp:368
CSG_Data_Object
Definition: dataobject.h:180
CSG_Parameter
Definition: parameters.h:207
TOOL_SCRIPT_PYTHON_WRAP_NAME_CALL_FULL
@ TOOL_SCRIPT_PYTHON_WRAP_NAME_CALL_FULL
Definition: tool.h:128
TSG_Tool_Error
TSG_Tool_Error
Definition: tool.h:112
CSG_TimeSpan::Format
CSG_String Format(const CSG_String &format="") const
Definition: datetime.cpp:65
CSG_Tool::DataObject_Add
bool DataObject_Add(CSG_Data_Object *pDataObject, bool bUpdate=false)
Definition: tool.cpp:799
PARAMETER_TYPE_Table
@ PARAMETER_TYPE_Table
Definition: parameters.h:150
PARAMETER_TYPE_Bool
@ PARAMETER_TYPE_Bool
Definition: parameters.h:125
CSG_Parameters::Get_Count
int Get_Count(void) const
Definition: parameters.h:1725
CSG_Parameters::Restore_Defaults
bool Restore_Defaults(bool bClearData=false)
Definition: parameters.cpp:1478
CSG_Tool::Get_Parameters
CSG_Parameters * Get_Parameters(void)
Definition: tool.h:181
PARAMETER_TYPE_Table_Field
@ PARAMETER_TYPE_Table_Field
Definition: parameters.h:144
CSG_Tool::Process_Get_Okay
static bool Process_Get_Okay(bool bBlink=false)
Definition: tool.cpp:844
CSG_Parameter::is_Enabled
bool is_Enabled(bool bCheckEnv=true) const
Definition: parameter.cpp:209
CSG_MetaData::Del_Children
bool Del_Children(int Depth=0, const SG_Char *Name=NULL)
Definition: metadata.cpp:381
SG_META_HISTORY
#define SG_META_HISTORY
Definition: dataobject.h:93
PARAMETER_TYPE_Choice
@ PARAMETER_TYPE_Choice
Definition: parameters.h:132
CSG_Parameter::asParameters
class CSG_Parameters * asParameters(void) const
Definition: parameter.cpp:1038
SG_UI_Dlg_Parameters
bool SG_UI_Dlg_Parameters(CSG_Parameters *pParameters, const CSG_String &Caption)
Definition: api_callback.cpp:448
CSG_Parameters::Get_Tool
class CSG_Tool * Get_Tool(void) const
Definition: parameters.h:1712
SG_UI_DataObject_Update
bool SG_UI_DataObject_Update(CSG_Data_Object *pDataObject, int Show, CSG_Parameters *pParameters)
Definition: api_callback.cpp:636
CSG_Parameters::Add_Reference
void Add_Reference(const CSG_String &Authors, const CSG_String &Year, const CSG_String &Title, const CSG_String &Where, const SG_Char *Link=NULL, const SG_Char *Link_Text=NULL)
Definition: parameters.cpp:361
CSG_Tool::Get_MenuPath
virtual CSG_String Get_MenuPath(void)
Definition: tool.h:178
sLong
signed long long sLong
Definition: api_core.h:158
CSG_Tool::Get_Library
const CSG_String & Get_Library(void) const
Definition: tool.cpp:115
CSG_Tool::DataObject_Get_Colors
static bool DataObject_Get_Colors(CSG_Data_Object *pDataObject, CSG_Colors &Colors)
Definition: tool.cpp:995
SG_UI_DataObject_Add
bool SG_UI_DataObject_Add(CSG_Data_Object *pDataObject, int Show)
Definition: api_callback.cpp:610
CSG_MetaData::Add_Property
bool Add_Property(const CSG_String &Name, const CSG_String &Value)
Definition: metadata.cpp:559
CSG_Tool::Destroy
virtual void Destroy(void)
Definition: tool.cpp:102
SG_UI_DataObject_Colors_Set
bool SG_UI_DataObject_Colors_Set(CSG_Data_Object *pDataObject, CSG_Colors *pColors)
Definition: api_callback.cpp:696
CSG_Tool::DataObject_Get_Parameters
static bool DataObject_Get_Parameters(CSG_Data_Object *pDataObject, CSG_Parameters &Parameters)
Definition: tool.cpp:1015
CSG_Tool::Get_Script
CSG_String Get_Script(TSG_Tool_Script_Type Type, bool bHeader=true, bool bAllParameters=false)
Definition: tool.cpp:1322
CSG_Tool::Set_Callback
void Set_Callback(bool bActive=true)
Definition: tool.cpp:559
PARAMETER_DESCRIPTION_TYPE
#define PARAMETER_DESCRIPTION_TYPE
Definition: parameters.h:107
TOOL_SCRIPT_CMD_BATCH
@ TOOL_SCRIPT_CMD_BATCH
Definition: tool.h:122
CSG_Tool::Message_Dlg
void Message_Dlg(const CSG_String &Text, const SG_Char *Caption=NULL)
Definition: tool.cpp:693
CSG_Tool::_On_Parameter_Changed
static int _On_Parameter_Changed(CSG_Parameter *pParameter, int Flags)
Definition: tool.cpp:452
SG_UI_Process_Set_Text
void SG_UI_Process_Set_Text(const CSG_String &Text)
Definition: api_callback.cpp:323
PARAMETER_TYPE_Grid
@ PARAMETER_TYPE_Grid
Definition: parameters.h:148
CSG_Parameter::Get_CmdID
CSG_String Get_CmdID(void) const
Definition: parameter.cpp:563
CSG_Tool::DataObject_Update_All
void DataObject_Update_All(void)
Definition: tool.cpp:815
SG_String_Tokenize
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)
Definition: api_string.cpp:1540
TOOL_SCRIPT_PYTHON
@ TOOL_SCRIPT_PYTHON
Definition: tool.h:125
PARAMETER_TYPE_Date
@ PARAMETER_TYPE_Date
Definition: parameters.h:129
CSG_Tool::Message_Dlg_Confirm
bool Message_Dlg_Confirm(const CSG_String &Text, const SG_Char *Caption=NULL)
Definition: tool.cpp:699
CSG_Data_Object::Get_File_Name
const SG_Char * Get_File_Name(bool bNative=true) const
Definition: dataobject.cpp:390
SG_Color_To_Text
CSG_String SG_Color_To_Text(long Color, bool bHexadecimal)
Definition: api_colors.cpp:144
CSG_Tool::Get_ID
const CSG_String & Get_ID(void) const
Definition: tool.h:166
CSG_Parameters::Get_References
const CSG_Strings & Get_References(void) const
Definition: parameters.h:1740
PARAMETER_TYPE_Grid_List
@ PARAMETER_TYPE_Grid_List
Definition: parameters.h:154
CSG_Tool::Process_Set_Text
static void Process_Set_Text(const CSG_String &Text)
Definition: tool.cpp:850
CSG_Data_Manager::Delete
bool Delete(CSG_Data_Object *pObject, bool bDetach=false)
Definition: data_manager.cpp:623
SG_UI_MSG_STYLE_BOLD
@ SG_UI_MSG_STYLE_BOLD
Definition: api_core.h:1503
CSG_Parameter::is_Optional
bool is_Optional(void) const
Definition: parameters.h:234
SG_DATAOBJECT_TYPE_TIN
@ SG_DATAOBJECT_TYPE_TIN
Definition: dataobject.h:122
CSG_Parameters::Create
bool Create(const CSG_Parameters &Parameters)
Definition: parameters.cpp:124
CSG_Strings
Definition: api_core.h:699
CSG_Tool::has_CMD
bool has_CMD(void) const
Definition: tool.cpp:245
CSG_Tool::Update_Parameter_States
bool Update_Parameter_States(void)
Definition: tool.cpp:1281
CSG_Tool::On_Execute
virtual bool On_Execute(void)=0
TOOL_ERROR_Calculation
@ TOOL_ERROR_Calculation
Definition: tool.h:114
CSG_DateTime
Definition: datetime.h:183
SG_DATAOBJECT_TYPE_Grid
@ SG_DATAOBJECT_TYPE_Grid
Definition: dataobject.h:118
CSG_Parameters::Del_Parameter
bool Del_Parameter(int i)
Definition: parameters.cpp:1248
CSG_Data_Manager::Add
CSG_Data_Object * Add(CSG_Data_Object *pObject)
Definition: data_manager.cpp:310
CSG_Tool::Get_File_Name
const CSG_String & Get_File_Name(void) const
Definition: tool.cpp:121
CSG_Tool::On_Parameter_Changed
virtual int On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
Definition: tool.cpp:476
CSG_Grid_System::Get_NY
int Get_NY(void) const
Definition: grid.h:235
CSG_Parameter::is_Output
bool is_Output(void) const
Definition: parameters.h:233
CSG_MetaData::Add_Children
bool Add_Children(const CSG_MetaData &MetaData)
Definition: metadata.cpp:359
CSG_Tool::Set_Name
void Set_Name(const CSG_String &String)
Definition: tool.cpp:127
CSG_MetaData::Assign
bool Assign(const CSG_MetaData &MetaData, bool bAddChildren=true)
Definition: metadata.cpp:757
ADD_MESSAGE_EXECUTION
#define ADD_MESSAGE_EXECUTION(Text, Style)
CSG_Tool::Set_Description
void Set_Description(const CSG_String &String)
Definition: tool.cpp:160
CSG_String::Format
static CSG_String Format(const char *Format,...)
Definition: api_string.cpp:270
CSG_TimeSpan::Get_Minutes
int Get_Minutes(void) const
Definition: datetime.h:162
CSG_Parameter_List::Get_Item_Count
int Get_Item_Count(void) const
Definition: parameters.h:1372
SG_UI_DataObject_Colors_Get
bool SG_UI_DataObject_Colors_Get(CSG_Data_Object *pDataObject, CSG_Colors *pColors)
Definition: api_callback.cpp:683
CSG_Projection
Definition: geo_tools.h:824
CSG_Tool::has_GUI
bool has_GUI(void) const
Definition: tool.cpp:239
CSG_Tool::Reset_Grid_System
bool Reset_Grid_System(void)
Definition: tool.cpp:1243
SG_UI_Dlg_Error
int SG_UI_Dlg_Error(const CSG_String &Message, const CSG_String &Caption)
Definition: api_callback.cpp:402
SG_DATAOBJECT_TYPE_Shapes
@ SG_DATAOBJECT_TYPE_Shapes
Definition: dataobject.h:121
CSG_String::AfterFirst
CSG_String AfterFirst(char Character) const
Definition: api_string.cpp:644
CSG_String::Clear
void Clear(void)
Definition: api_string.cpp:259
CSG_Parameter::Get_Children_Count
int Get_Children_Count(void) const
Definition: parameters.h:255
TOOL_SCRIPT_PYTHON_WRAP_NAME
@ TOOL_SCRIPT_PYTHON_WRAP_NAME
Definition: tool.h:126
CSG_Parameter::is_DataObject
bool is_DataObject(void) const
Definition: parameter.cpp:276
SG_UI_DataObject_Params_Get
bool SG_UI_DataObject_Params_Get(CSG_Data_Object *pDataObject, CSG_Parameters *pParameters)
Definition: api_callback.cpp:709
CSG_TimeSpan::Get_Seconds
sLong Get_Seconds(void) const
Definition: datetime.h:163
SG_Char
#define SG_Char
Definition: api_core.h:536
CSG_Parameters::Set_Description
void Set_Description(const CSG_String &Description)
Definition: parameters.cpp:351
CSG_String::Contains
bool Contains(const CSG_String &String) const
Definition: api_string.cpp:633
CSG_Tool::DataObject_Set_Colors
static bool DataObject_Set_Colors(CSG_Data_Object *pDataObject, const CSG_Colors &Colors)
Definition: tool.cpp:1000
SG_UI_DATAOBJECT_SHOW_MAP
@ SG_UI_DATAOBJECT_SHOW_MAP
Definition: api_core.h:1519
CSG_String
Definition: api_core.h:563
CSG_Parameters::Set_Tool
void Set_Tool(class CSG_Tool *pTool)
Definition: parameters.cpp:202
SG_UI_Get_Application_Path
CSG_String SG_UI_Get_Application_Path(bool bPathOnly)
Definition: api_core.cpp:356
CSG_Tool::Get_Author
const CSG_String & Get_Author(void) const
Definition: tool.cpp:143
CSG_Tool::Set_Manager
bool Set_Manager(class CSG_Data_Manager *pManager)
Definition: tool.cpp:570
SG_DATAOBJECT_TYPE_Table
@ SG_DATAOBJECT_TYPE_Table
Definition: dataobject.h:120
CSG_Data_Manager
Definition: data_manager.h:129
CSG_MetaData
Definition: metadata.h:88
CSG_Tool::Settings_Pop
bool Settings_Pop(void)
Definition: tool.cpp:634
CSG_Parameter_String
Definition: parameters.h:800
SG_Get_History_Depth
int SG_Get_History_Depth(void)
Definition: dataobject.cpp:159
CSG_Tool::Settings_Push
bool Settings_Push(class CSG_Data_Manager *pManager=NULL)
Definition: tool.cpp:621
CSG_String::is_Empty
bool is_Empty(void) const
Definition: api_string.cpp:178
SG_UI_Process_Set_Progress
bool SG_UI_Process_Set_Progress(int Position, int Range)
Definition: api_callback.cpp:255
PARAMETER_DESCRIPTION_TEXT
#define PARAMETER_DESCRIPTION_TEXT
Definition: parameters.h:110
CSG_Parameter::asDouble
double asDouble(void) const
Definition: parameters.h:284
PARAMETER_TYPE_Grid_System
@ PARAMETER_TYPE_Grid_System
Definition: parameters.h:143
CSG_Tool::Get_Description
const CSG_String & Get_Description(void) const
Definition: tool.cpp:165
PARAMETER_TYPE_PointCloud_List
@ PARAMETER_TYPE_PointCloud_List
Definition: parameters.h:159
CSG_Tool::is_Interactive
virtual bool is_Interactive(void) const
Definition: tool.h:239
TOOL_SCRIPT_PYTHON_WRAP_ID
@ TOOL_SCRIPT_PYTHON_WRAP_ID
Definition: tool.h:129
CSG_Tool::Set_Progress
virtual bool Set_Progress(int Position, int Range) const
Definition: tool.cpp:660
CSG_Tool::Delete_Manager
bool Delete_Manager(bool bDetachData=false, bool bReset=true)
Definition: tool.cpp:597
PARAMETER_TYPE_Table_List
@ PARAMETER_TYPE_Table_List
Definition: parameters.h:156
CSG_Array_Pointer::Add
bool Add(void *Value)
Definition: api_memory.cpp:485
CSG_Parameter::asRange
class CSG_Parameter_Range * asRange(void) const
Definition: parameter.cpp:1110
CSG_Tool::CSG_Tool
CSG_Tool(void)
Definition: tool.cpp:67
CSG_MetaData::Set_Name
void Set_Name(const CSG_String &Name)
Definition: metadata.h:129
TOOL_SCRIPT_CMD_USAGE
@ TOOL_SCRIPT_CMD_USAGE
Definition: tool.h:123
CSG_Parameters::Set_Manager
void Set_Manager(class CSG_Data_Manager *pManager)
Definition: parameters.cpp:223
PARAMETER_TYPE_DataObject_Output
@ PARAMETER_TYPE_DataObject_Output
Definition: parameters.h:161
CSG_Parameters::Set_Parameter
bool Set_Parameter(const CSG_String &ID, CSG_Parameter *pValue)
Definition: parameters.cpp:1405
CSG_Grid_System::Get_NX
int Get_NX(void) const
Definition: grid.h:234
TSG_Tool_Script_Type
TSG_Tool_Script_Type
Definition: tool.h:120
PARAMETER_DESCRIPTION_PROPERTIES
#define PARAMETER_DESCRIPTION_PROPERTIES
Definition: parameters.h:109
PARAMETER_CHECK_VALUES
#define PARAMETER_CHECK_VALUES
Definition: parameters.h:189
CSG_Parameters::Get_Name
const CSG_String & Get_Name(void) const
Definition: parameters.h:1732
CSG_String::c_str
const SG_Char * c_str(void) const
Definition: api_string.cpp:236
CSG_Parameters::Set_Callback_On_Parameter_Changed
TSG_PFNC_Parameter_Changed Set_Callback_On_Parameter_Changed(TSG_PFNC_Parameter_Changed pCallback)
Definition: parameters.cpp:1342
SG_UI_Process_Set_Ready
bool SG_UI_Process_Set_Ready(void)
Definition: api_callback.cpp:305
CSG_Strings::Get_Count
int Get_Count(void) const
Definition: api_core.h:712
PARAMETER_CHECK_ENABLE
#define PARAMETER_CHECK_ENABLE
Definition: parameters.h:190
CSG_Parameters
Definition: parameters.h:1690
CSG_Parameter::Get_DataObject_Type
TSG_Data_Object_Type Get_DataObject_Type(void) const
Definition: parameter.cpp:519
CSG_Parameter_Range::Get_Min
double Get_Min(void) const
Definition: parameter_data.cpp:814
CSG_MetaData::Add_Child
CSG_MetaData * Add_Child(void)
Definition: metadata.cpp:166
SG_UI_Msg_Add_Error
void SG_UI_Msg_Add_Error(const char *Message)
Definition: api_callback.cpp:556
CSG_Parameter::Cmp_Identifier
bool Cmp_Identifier(const CSG_String &Identifier) const
Definition: parameter.cpp:553
CSG_Parameter::asGrid_System
CSG_Grid_System * asGrid_System(void) const
Definition: parameter.cpp:1037
CSG_Tool::Error_Fmt
bool Error_Fmt(const char *Format,...)
Definition: tool.cpp:742
CSG_Tool::Get_Type
virtual TSG_Tool_Type Get_Type(void) const
Definition: tool.h:164
CSG_Tool::Message_Fmt
void Message_Fmt(const char *Format,...)
Definition: tool.cpp:919
CSG_Parameter::Get_Name
const SG_Char * Get_Name(void) const
Definition: parameter.cpp:589
CSG_Parameter::is_Default
virtual bool is_Default(void) const
Definition: parameter.cpp:935
PARAMETER_TYPE_Range
@ PARAMETER_TYPE_Range
Definition: parameters.h:130
CSG_Parameter::is_Option
bool is_Option(void) const
Definition: parameter.cpp:239
PARAMETER_OUTPUT
#define PARAMETER_OUTPUT
Definition: parameters.h:95
CSG_Tool::Set_Grid_System
bool Set_Grid_System(const CSG_Grid_System &System)
Definition: tool.cpp:1258
PARAMETER_TYPE_TIN_List
@ PARAMETER_TYPE_TIN_List
Definition: parameters.h:158
CSG_Grid_System::Get_YMin
double Get_YMin(bool bCells=false) const
Definition: grid.h:244
PARAMETER_TYPE_Parameters
@ PARAMETER_TYPE_Parameters
Definition: parameters.h:163
CSG_Parameter::asList
class CSG_Parameter_List * asList(void) const
Definition: parameter.cpp:1115
PARAMETER_TYPE_Color
@ PARAMETER_TYPE_Color
Definition: parameters.h:139
PARAMETER_TYPE_Shapes
@ PARAMETER_TYPE_Shapes
Definition: parameters.h:151
SG_Get_DataObject_Class_Name
CSG_String SG_Get_DataObject_Class_Name(TSG_Data_Object_Type Type)
Definition: dataobject.cpp:101
SG_DATAOBJECT_TYPE_PointCloud
@ SG_DATAOBJECT_TYPE_PointCloud
Definition: dataobject.h:123
CSG_Tool::On_Parameters_Enable
virtual int On_Parameters_Enable(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
Definition: tool.cpp:482
CSG_Parameters::Set_History
bool Set_History(CSG_MetaData &History, bool bOptions=true, bool bDataObjects=true)
Definition: parameters.cpp:1967
CSG_Parameters::Set_Callback
bool Set_Callback(bool bActive=true)
Definition: parameters.cpp:1363
CSG_Parameter::is_Information
bool is_Information(void) const
Definition: parameters.h:235
PARAMETER_INPUT
#define PARAMETER_INPUT
Definition: parameters.h:94
PARAMETER_DESCRIPTION_NAME
#define PARAMETER_DESCRIPTION_NAME
Definition: parameters.h:106
CSG_Parameter::Get_Type_Identifier
CSG_String Get_Type_Identifier(void) const
Definition: parameter.cpp:123
CSG_Colors
Definition: api_core.h:1338
CSG_Parameter::asBool
bool asBool(void) const
Definition: parameters.h:281
SG_UI_Msg_Add
void SG_UI_Msg_Add(const char *Message, bool bNewLine, TSG_UI_MSG_STYLE Style)
Definition: api_callback.cpp:502
CSG_Tool::Get_Grid_System
CSG_Grid_System * Get_Grid_System(void) const
Definition: tool.cpp:1268
DATAOBJECT_NOTSET
#define DATAOBJECT_NOTSET
Definition: dataobject.h:129
PARAMETER_TYPE_Text
@ PARAMETER_TYPE_Text
Definition: parameters.h:135