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