57#include <wx/cmdline.h>
72 m_bError_Ignore =
false;
84 m_References.Set_Name(
_TL(
"References"));
92 m_Editors .Set_Name(
_TL(
"References"));
116 m_bError_Ignore =
false;
137 return( m_File_Name );
183 if( bNewLine ) { Description +=
"\n"; }
196 m_Dynamic_Description = String;
201 if( bNewLine ) { m_Dynamic_Description +=
"\n"; }
203 m_Dynamic_Description += String;
208 return( m_Dynamic_Description );
228 if( Menu[i].
Length() > 1 && Menu[i][1] ==
':' )
230 if( Menu[i][0] ==
'A' || Menu[i][0] ==
'a' )
232 Menu[i] = Menu[i].AfterFirst(
':');
237 Menu[i] = Menu[i].AfterFirst(
':');
240 if( !m_Library_Menu.is_Empty() )
242 if( Menu[i].is_Empty() )
244 Menu[i] = m_Library_Menu;
248 Menu[i] = m_Library_Menu +
"|" + Menu[i];
305 m_References.Sort(0);
323 return( m_References.Del_Records() );
334 for(
int i=0; i<m_References.Get_Count(); i++)
337 Authors(m_References[i].asString(0)),
338 Date (m_References[i].asString(1)),
339 Title (m_References[i].asString(2)),
340 Source (m_References[i].asString(3)),
341 Link (m_References[i].asString(4)),
342 LinkTxt(m_References[i].asString(5));
344 if( !Authors.is_Empty() )
346 if( Date.is_Empty() ) { Date =
"n.d."; }
348 Reference += bHTML ?
"<b>" + Authors +
" (" + Date +
"):</b>" : Authors +
" (" + Date +
"):";
350 else if( !Date.is_Empty() )
352 Reference += bHTML ?
"<b>(" + Date +
"):</b>" :
"(" + Date +
"):";
355 if( !Title.is_Empty() )
357 if( Title[Title.Length() - 1] !=
'.' ) { Title +=
'.'; }
359 if( !Reference.
is_Empty() ) { Reference +=
" "; }
361 Reference += bHTML ?
"<i>" + Title +
"</i>" : Title;
364 if( !Source.is_Empty() )
366 if( Source[Source.Length() - 1] !=
'.' ) { Source +=
'.'; }
368 if( !Reference.
is_Empty() ) { Reference +=
" "; }
373 if( !Link.is_Empty() )
375 if( !Reference.
is_Empty() ) { Reference +=
" "; }
377 Reference += bHTML ?
"<a href=\"" + Link +
"\">" + (LinkTxt.
is_Empty() ? Link : LinkTxt) +
"</a>" :
"[" + LinkTxt +
"](" + Link +
")";
382 References += Reference;
386 return( References );
416 for(
int i=0; i<pParameters->
Get_Count(); i++)
426 CSG_Table_Record &Record = *Table.
Add_Record();
448 m_Description_Source = Source;
455 return( m_Description_Source );
476 m_References.Del_Records();
484 Add_Reference(Table[i].asString(0), Table[i].asString(1), Table[i].asString(2), Table[i].asString(3), Table[i].asString(4), Table[i].asString(5));
498 pParameter->
Set_Name (Table[i].asString(1));
504 m_Editors.Del_Records();
529 for(
sLong i=0; i<m_Editors.Get_Count(); i++)
531 if( !m_Editors[i].is_NoData(0) )
533 if( !Editors.
is_Empty() ) { Editors +=
", "; }
535 Editors += m_Editors[i].asString(0);
537 if( !m_Editors[i].is_NoData(1) )
546 Editors =
CSG_String::Format(bHTML ?
"<hr><small><small>%s: <i>%s</i>.</small></small>" :
"\n___\n%s: %s\n",
547 _TL(
"Description editor(s)"), Editors.
c_str()
564 #define ADD_MESSAGE_EXECUTION(Text, Style) { SG_UI_Msg_Add(Text, true, Style); if( has_GUI() ) { SG_UI_Msg_Add_Execution(Text, true, Style); } }
574 m_bError_Ignore =
false;
576 bool bResult =
false;
578 m_Execution_Info.
Clear();
590 if(
Parameters.DataObjects_Create() ==
false )
592 _Synchronize_DataObjects();
603#define _TOOL_EXCEPTION
612#ifdef _TOOL_EXCEPTION
614 catch(
const std::exception &Exception)
628 _Synchronize_DataObjects();
637 if( bResult && bAddHistory )
639 _Set_Output_History();
669 _TL(
"execution time"), Time.
c_str()),
681 bResult ?
_TL(
"Execution succeeded") :
_TL(
"Execution failed"), Time.
c_str()),
707bool CSG_Tool::_Synchronize_DataObjects(
void)
803 pParameters->
Create(
this, Name, Description, Identifier);
805 pParameters->m_pTool =
this;
807 m_pParameters.Add(pParameters);
809 return( pParameters );
849 return( pParameters ?
Dlg_Parameters(*pParameters, Caption) :
false );
907 pManager->
Delete(bDetachData);
960 m_bShow_Progress = bOn;
966 return(
Set_Progress((
double)Position / (
double)Range) );
972 return(
Set_Progress((
double)Position / (
double)Range) );
1026 m_Execution_Info +=
"\n____\n" + Text;
1037 m_bError_Ignore =
true;
1055 wxString _Format(Format); _Format.Replace(
"%s",
"%ls");
1056 va_start(argptr, _Format);
1057 _s.PrintfV(_Format, argptr);
1059 va_start(argptr, Format);
1060 _s.PrintfV(Format, argptr);
1080 wxString _Format(Format); _Format.Replace(
"%s",
"%ls");
1081 va_start(argptr, _Format);
1082 _s.PrintfV(_Format, argptr);
1084 va_start(argptr, Format);
1085 _s.PrintfV(Format, argptr);
1129 else if(
Parameters(i)->is_DataObject_List() )
1131 for(
int j=0; j<
Parameters(i)->asList()->Get_Item_Count(); j++)
1171 wxString _Format(Format); _Format.Replace(
"%s",
"%ls");
1172 va_start(argptr, _Format);
1173 _s.PrintfV(_Format, argptr);
1175 va_start(argptr, Format);
1176 _s.PrintfV(Format, argptr);
1196 wxString _Format(Format); _Format.Replace(
"%s",
"%ls");
1197 va_start(argptr, _Format);
1198 _s.PrintfV(_Format, argptr);
1200 va_start(argptr, Format);
1201 _s.PrintfV(Format, argptr);
1218 m_Execution_Info +=
"\n";
1221 m_Execution_Info += Text;
1234 wxString _Format(Format); _Format.Replace(
"%s",
"%ls");
1235 va_start(argptr, _Format);
1236 _s.PrintfV(_Format, argptr);
1238 va_start(argptr, Format);
1239 _s.PrintfV(Format, argptr);
1259 wxString _Format(Format); _Format.Replace(
"%s",
"%ls");
1260 va_start(argptr, _Format);
1261 _s.PrintfV(_Format, argptr);
1263 va_start(argptr, Format);
1264 _s.PrintfV(Format, argptr);
1333 if( pDataObject == pCopy )
1440#define INIT_STRETCH_OPTIONS(method) { if( !pDataObject || (pDataObject->asTable(true) && (Field < 0 || Field >= pDataObject->asTable(true)->Get_Field_Count())) ) { return( false ); }\
1441 if( Colors >= 0 ) { DataObject_Set_Colors(pDataObject, -1, Colors); }\
1442 DataObject_Set_Parameter(pDataObject, "COLORS_TYPE" , 3); \
1443 DataObject_Set_Parameter(pDataObject, "STRETCH_DEFAULT" , method);\
1444 DataObject_Set_Parameter(pDataObject, "METRIC_SCALE_MODE", Interval_Mode);\
1445 DataObject_Set_Parameter(pDataObject, "METRIC_SCALE_LOG" , Interval_Log );\
1446 if( pDataObject->asTable(true) )\
1447 { DataObject_Set_Parameter(pDataObject, "METRIC_FIELD" , Field);\
1448 DataObject_Set_Parameter(pDataObject, "METRIC_MORMAL", pDataObject->asTable(true)->Get_Field_Count());\
1503#define INIT_CLASSIFY_OPTIONS(method) if( !pDataObject || (pDataObject->asTable(true) && (Field < 0 || Field >= pDataObject->asTable(true)->Get_Field_Count())) ) { return( false ); }\
1504 CSG_MetaData Options; Options.Add_Child("METHOD", method); Options.Add_Child("COLORS", Colors); Options.Add_Child("FIELD", Field);
1511 Options.Add_Child(
"MAXCLASSES", maxClasses);
1521 Options.Add_Child(
"CLASSES", Classes);
1531 Options.Add_Child(
"INTERVAL", Interval);
if( bOffset ) { Options.Add_Child(
"OFFSET", Offset); }
1541 Options.Add_Child(
"CLASSES", Classes); Options.Add_Child(
"HISTOGRAM", bHistogram ? 1 : 0);
1551 Options.Add_Child(
"CLASSES", Classes); Options.Add_Child(
"INCREASING", bIncreasing ? 1 : 0);
1561 Options.Add_Child(
"CLASSES", Classes);
1571 Options.Add_Child(
"STDDEV", StdDev); Options.Add_Child(
"STDDEV_MAX", StdDev_Max);
1599 return( pParameter );
1727 return(
Parameters.Set_Grid_System(System) );
1761void CSG_Tool::_Update_Parameter_States(
CSG_Parameters *pParameters)
1765 for(
int i=0; i<pParameters->
Get_Count(); i++)
1819CSG_String CSG_Tool::_Get_Script_CMD(
bool bHeader,
bool bAllArguments,
bool bWrapArgs,
bool bBatch)
1827 Script +=
"@ECHO OFF\n\n";
1828 Script +=
"PUSHD %~dp0\n\n";
1829 Script +=
"REM SET SAGA_TLB=C:\\MyTools\n\n";
1831 Script +=
"REM Tool: " +
Get_Name() +
"\n\n";
1832 Script +=
"%SAGA_CMD%";
1836 Script +=
"#!/bin/bash\n\n";
1837 Script +=
"# export SAGA_TLB=~/mytools\n\n";
1838 Script +=
"# tool: " +
Get_Name() +
"\n\n";
1839 Script +=
"saga_cmd";
1844 Script +=
"saga_cmd";
1853 ?
" \"" +
Get_ID () +
"\""
1856 _Get_Script_CMD(Script,
Get_Parameters(), bAllArguments, bWrapArgs, bBatch);
1860 _Get_Script_CMD(Script,
Get_Parameters(i), bAllArguments, bWrapArgs, bBatch);
1866 Script += bBatch ?
"\n\nPAUSE\n" :
"\n";
1873void CSG_Tool::_Get_Script_CMD(
CSG_String &Script,
CSG_Parameters *pParameters,
bool bAllArguments,
bool bWrapArgs,
bool bBatch)
1875 #define GET_ID1(p) (p->Get_Parameters()->Get_Identifier().Length() > 0 \
1876 ? CSG_String::Format("%s_%s", p->Get_Parameters()->Get_Identifier().c_str(), p->Get_Identifier()) \
1877 : CSG_String::Format(p->Get_Identifier())).c_str()
1879 #define GET_ID2(p, s) CSG_String::Format("%s_%s", GET_ID1(p), s).c_str()
1881 const char *Prefix = !bWrapArgs ?
" -" : bBatch ?
" ^\n -" :
" \\\n -";
1882 const char *StrFmt = bBatch ?
"%s=\"%s\"" :
"%s=\\\"\"%s\"\\\"";
1885 for(
int iParameter=0; iParameter<pParameters->
Get_Count(); iParameter++)
1933 if( ((CSG_Parameter_String *)p)->is_Password() )
1983 default : File +=
".dat" ;
break;
2002 Script +=
"file(s)";
2009 for(
int iObject=1; iObject<p->
asList()->Get_Item_Count(); iObject++)
2032CSG_String CSG_Tool::_Get_Script_CMD_Usage(
void)
2034 wxCmdLineParser Parser; Parser.SetSwitchChars(
"-");
2043 wxString Usage = wxString::Format(
"\nUsage: saga_cmd %s %s %s",
Get_Library().c_str(),
Get_ID().c_str(),
2047 CSG_String _Usage(&Usage);
2053void CSG_Tool::_Get_Script_CMD_Usage(
CSG_Parameters *pParameters, wxCmdLineParser &Parser)
2055 for(
int i=0; i<pParameters->
Get_Count(); i++)
2079 Description.Replace(
"\xb",
"");
2085 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_NEEDS_SEPARATOR|wxCMD_LINE_PARAM_OPTIONAL);
2094 _Get_Script_CMD_Usage(pParameter->
asParameters(), Parser);
2098 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2102 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
2110 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2115 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2119 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_DATE , wxCMD_LINE_PARAM_OPTIONAL);
2123 Parser.AddOption(ID +
"_MIN", wxEmptyString, Description, wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2124 Parser.AddOption(ID +
"_MAX", wxEmptyString, Description, wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2128 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2132 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2138 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2142 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2148 Parser.AddOption(ID +
"_D" , wxEmptyString,
_TL(
"Cell Size" ), wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2149 Parser.AddOption(ID +
"_X" , wxEmptyString,
_TL(
"Lower Left Center Cell X-Coordinate"), wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2150 Parser.AddOption(ID +
"_Y" , wxEmptyString,
_TL(
"Lower Left Center Cell Y-Coordinate"), wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2151 Parser.AddOption(ID +
"_NX" , wxEmptyString,
_TL(
"Number of Columns" ), wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
2152 Parser.AddOption(ID +
"_NY" , wxEmptyString,
_TL(
"Number of Rows" ), wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
2153 Parser.AddOption(ID +
"_FILE", wxEmptyString,
_TL(
"Grid File" ), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2170CSG_String CSG_Tool::_Get_Script_Python(
bool bHeader,
bool bAllArguments)
2172 CSG_String Script, Name(
Get_Name());
2174 Name.Replace(
" ",
"_");
2175 Name.Replace(
"(",
"");
2176 Name.Replace(
")",
"");
2177 Name.Replace(
"[",
"");
2178 Name.Replace(
"]",
"");
2179 Name.Replace(
".",
"");
2180 Name.Replace(
",",
"");
2181 Name.Replace(
"/",
"");
2182 Name.Replace(
"-",
"");
2187 Script +=
"#! /usr/bin/env python\n";
2189 Script +=
"#_________________________________________\n";
2190 Script +=
"##########################################\n";
2194 Script +=
"# Initialize the environment...\n";
2196 Script +=
"# Windows: Let the 'SAGA_PATH' environment variable point to\n";
2197 Script +=
"# the SAGA installation folder before importing 'saga_api'!\n";
2198 Script +=
"# This can be defined globally in the Windows system or\n";
2199 Script +=
"# user environment variable settings, in the 'PySAGA/__init__.py'\n";
2200 Script +=
"# file, or in the individual Python script itself. To do the latter\n";
2201 Script +=
"# just uncomment the following line and adjust the path accordingly:\n";
2202 Script +=
"###import os; os.environ['SAGA_PATH'] = '" + AppPath +
"'\n";
2204 Script +=
"# Windows: The most convenient way to make PySAGA available to all your\n";
2205 Script +=
"# Python scripts is to copy the PySAGA folder to the 'Lib/site-packages/'\n";
2206 Script +=
"# folder of your Python installation. If don't want to do this or if you\n";
2207 Script +=
"# don't have the rights to do so, you can also copy it to the folder with\n";
2208 Script +=
"# the Python scripts in which you want to use PySAGA, or alternatively\n";
2209 Script +=
"# you can add the path containing the PySAGA folder (e.g. the path to your\n";
2210 Script +=
"# SAGA installation) to the PYTHONPATH environment variable. To do this\n";
2211 Script +=
"# from within your script you can also take the following command (just\n";
2212 Script +=
"# uncomment the following line and adjust the path accordingly):\n";
2213 Script +=
"###import sys; sys.path.insert(1, '" + AppPath +
"')\n";
2216 Script +=
"# Import saga_api from PySAGA:\n";
2217 Script +=
"from PySAGA import saga_api\n";
2220 Script +=
"#_________________________________________\n";
2221 Script +=
"##########################################\n";
2222 Script +=
"def Run_" + Name +
"(Results):\n";
2226 if( bHeader ) Script +=
" # Get the tool:\n";
2227 Script +=
" Tool = saga_api.SG_Get_Tool_Library_Manager().Get_Tool('" +
Get_Library() +
"', '" +
Get_ID() +
"')\n";
2228 Script +=
" if not Tool:\n";
2229 Script +=
" saga_api.SG_UI_Msg_Add_Error('Failed to request tool: " +
Get_Name() +
"')\n";
2230 Script +=
" return False\n";
2232 if( bHeader ) Script +=
" # Set the parameter interface:\n";
2233 Script +=
" Tool.Reset()\n";
2245 if( bHeader ) Script +=
" # Execute the tool:\n";
2246 Script +=
" if not Tool.Execute():\n";
2247 Script +=
" saga_api.SG_UI_Msg_Add_Error('failed to execute tool: ' + Tool.Get_Name().c_str())\n";
2248 Script +=
" return False\n";
2250 if( bHeader ) Script +=
" # Request the results:\n";
2268 default : type =
"" ; ext =
"" ;
break;
2273 Script +=
" Data = Tool.Get_Parameter('" +
id +
"').as" + type +
"()\n";
2277 Script +=
" Data.Save('{:s}/{:s}.{:s}'.format(Results, Data.Get_Name(), '" + ext +
"'))\n\n";
2282 Script +=
" List = Tool.Get_Parameter('" +
id +
"').as" + type +
"List()\n";
2283 Script +=
" for i in range(0, List.Get_Item_Count()):\n";
2287 Script +=
" List.Get_Item(i).Save('{:s}/{:s}_{:d}.{:s}'.format(Results, List.Get_Name(), i, '" + ext +
"'))\n\n";
2291 Script +=
" Data = List.Get_Item(i)\n";
2300 Script +=
" # job is done, free memory resources:\n";
2301 Script +=
" saga_api.SG_Get_Data_Manager().Delete_All()\n";
2303 Script +=
" return True\n";
2306 Script +=
"#_________________________________________\n";
2307 Script +=
"##########################################\n";
2308 Script +=
"print('This is a simple template for using a SAGA tool through Python.')\n";
2309 Script +=
"print('Please edit the script to make it work properly before using it!')\n";
2311 Script +=
"# Run_" + Name +
"('.')\n";
2320 for(
int iParameter=0; iParameter<pParameters->
Get_Count(); iParameter++)
2333 ID.Prepend(Prefix +
".");
2375 if( ((CSG_Parameter_String *)p)->is_Password() )
2388 Script +=
CSG_String::Format(
" Tool.Set_Parameter('%s', saga_api.SG_Create_Table('table.txt'))\n", ID.c_str());
2394 Script +=
CSG_String::Format(
" Tool.Set_Parameter('%s', saga_api.CSG_Grid_System(%g, %g, %g, %d, %d))\n", ID.c_str(),
2410 Script +=
CSG_String::Format(
" Tool.Set_Parameter('%s', saga_api.SG_Get_Data_Manager().Add('%s input file%s'))\n", ID.c_str(),
2416 Script +=
CSG_String::Format(
" Tool.Set_Parameter('%s', saga_api.SG_Get_Create_Pointer()) # optional output, remove this line, if you don't want to create it\n", ID.c_str());
2428 Script +=
CSG_String::Format(
" Tool.Get_Parameter('%s').asList().Add_Item('%s input list%s')\n", ID.c_str(),
2435 _Get_Script_Python(Script, p->
asParameters(), bAllArguments, ID);
2447CSG_String CSG_Tool::_Get_Script_Python_Wrap(
bool bHeader,
bool bName,
bool bCall,
int AllArguments,
bool bWrapArgs)
2449 CSG_String Arguments, Description, Code;
2451 if( AllArguments >= 0 )
2455 _Get_Script_Python_Wrap(
Parameters[i],
PARAMETER_INPUT , Arguments, Description, Code, bCall && bHeader, AllArguments == 0, bWrapArgs);
2465 _Get_Script_Python_Wrap(
Parameters[i],
PARAMETER_OUTPUT , Arguments, Description, Code, bCall && bHeader, AllArguments == 0, bWrapArgs);
2470 _Get_Script_Python_Wrap(
Parameters[i], 0 , Arguments, Description, Code, bCall , AllArguments == 0, bWrapArgs);
2475 CSG_String Name, Expected(
Get_Name()); Expected.Replace(
"'",
"\\'");
2481 if( isdigit(Name[0]) )
2512 Script +=
"from PySAGA.tools import " +
Get_Library() +
"\n\n";
2516 Script += Code +
"\n";
2520 Script +=
Get_Library() +
'.' + Name +
"(" + Arguments +
")\n";
2528 Script +=
"#! /usr/bin/env python\n";
2529 Script +=
"from PySAGA.helper import Tool_Wrapper\n\n";
2532 Script +=
"def " + Name +
"(" + Arguments +
", Verbose=2):\n";
2535 Script +=
" ----------\n";
2537 for(
int i=0; i<_Description.
Get_Count(); i++)
2539 _Description[i].Trim_Both(); Script +=
" " + _Description[i] +
"\\n\n";
2541 Script +=
" Arguments\n";
2542 Script +=
" ----------\n";
2543 Script += Description +
"\n";
2544 Script +=
" - Verbose [`integer number`] : Verbosity level, 0=silent, 1=tool name and success notification, 2=complete tool output.\\n\n";
2545 Script +=
" Returns\n";
2546 Script +=
" ----------\n";
2547 Script +=
" `boolean` : `True` on success, `False` on failure.\n";
2549 Script +=
" Tool = Tool_Wrapper('" +
Get_Library() +
"', '" +
Get_ID() +
"', '" + Expected +
"')\n";
2550 Script +=
" if Tool.is_Okay():\n";
2552 Script +=
" return Tool.Execute(Verbose)\n";
2553 Script +=
" return False\n\n";
2580 ID.Prepend(Prefix +
".");
2583 CSG_String Argument(ID);
2585 if( Argument[0] >=
'0' && Argument[0] <=
'9' )
2587 Argument.Prepend(
'_');
2590 Argument.Replace(
".",
"_");
2591 Argument.Replace(
"|",
"_");
2592 Argument.Replace(
" ",
"_");
2594 if( Argument.Length() > 2 )
2596 Argument.Make_Upper();
2602 bool bResult =
false;
2604 for(
int i=0; i<(*Parameter.
asParameters()).Get_Count(); i++)
2606 if( _Get_Script_Python_Wrap((*Parameter.
asParameters())[i], Constraint, Arguments, Description, Code, bCall, bOnlyNonDefaults, bWrapArgs, ID) )
2619 if( Parameter.
is_Option() && Constraint != 0 ) {
return(
false ); }
2639 ); File.Replace(
"\\",
"/");
2673 if( bOnlyNonDefaults && Parameter.
is_Default() )
2709 default :
return(
false );
2717 Arguments += !Arguments.
is_Empty() ?
",\n " :
"\n ";
2724 Arguments += Argument +
"=" + Value;
2733 Arguments += !Arguments.
is_Empty() ?
",\n " :
"\n ";
2740 Arguments += Argument +
"=None";
2745 if( Parameter.
is_Input () ) { Code +=
"Tool.Set_Input "; }
2746 if( Parameter.
is_Output() ) { Code +=
"Tool.Set_Output"; }
2747 if( Parameter.
is_Option() ) { Code +=
"Tool.Set_Option"; }
2752 Description +=
" - " + Argument +
" [`";
2756 Description += Parameter.
is_Optional() ?
"optional input " :
"input ";
2760 Description +=
"output ";
2769 Description +=
". " + s;
2772 Description +=
"\n";
2782CSG_String CSG_Tool::_Get_Script_Markdown(
bool bHeader,
int iArguments)
2793 Script +=
CSG_String::Format(
"**Geoprocessing** → *%s* // **Tools** → *%s*\n\n", Menu.
c_str(), Category.
c_str());
2796 Script +=
"|**Parameter**|**Setting**|\n";
2797 Script +=
"|---|---|\n";
2811 #define WRITE_CHILD(pChild, Prefix) Script += CSG_String::Format("|%s%s||\n", Prefix.c_str(), pChild->Get_Name().c_str());\
2812 for (int i=0; i<pChild->Get_Children_Count(); i++)\
2814 Script += CSG_String::Format("%s\n", pChild->Get_Child(i)->Get_Content().c_str());\
2817 CSG_MetaData Properties;
2819 for(
int iParameter=0; iParameter<pParameters->
Get_Count(); iParameter++)
2821 _Format_Markdown(pParameters->
Get_Parameter(iParameter), Script, Properties, iArguments, Prefix);
2828 CSG_MetaData *pChild = Properties.
Get_Child(i);
2843 #define CHECK_OBJECTS_NODE() pChild = Properties.Get_Child(_TL("Options"));\
2846 pChild = Properties.Add_Child(_TL("Options"));\
2851 #define CHECK_DATA_NODE(Name) pChild = Properties.Get_Child(Name);\
2854 CSG_MetaData *pData = Properties.Get_Child(_TL("Data Objects"));\
2857 Properties.Add_Child(_TL("Data Objects"));\
2859 pChild = Properties.Add_Child(Name);\
2864 #define GET_PARENT_NODE(prt) bool bFound = false;\
2865 for (int i=0; i<Properties.Get_Children_Count(); i++)\
2867 CSG_MetaData *pDatatype = Properties.Get_Child(i);\
2868 for (int j=0; j<Properties.Get_Children_Count(); j++)\
2870 pParent = pDatatype->Get_Child(prt);\
2883 #define FORMAT_DATASET() if( p->is_Input() )\
2885 CSG_String Input = p->is_Optional() ? ">" : ">>";\
2886 CSG_String s = p->asString();\
2887 if( s.Contains(_TL("not set")) || s.Contains(_TL("No objects")) ) { Bold = ""; }\
2888 s.Replace("<", "\\<");\
2889 Parameter = CSG_String::Format("|%s%s %s%s%s|%s%s%s|", Space.c_str(), Input.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), s.c_str(), Bold.c_str());\
2891 else if( p->is_Output() )\
2893 CSG_String Output = p->is_Optional() ? "\\<" : "<<";\
2894 CSG_String s = p->asString();\
2895 if( !p->is_Optional() && s.Contains(_TL("create")) ) { Bold = ""; }\
2896 else if( p->is_Optional() && (s.Contains(_TL("not set")) || s.Contains(_TL("No objects"))) ) { Bold = ""; }\
2897 s.Replace("<", "\\<");\
2898 Parameter = CSG_String::Format("|%s%s %s%s%s|%s%s%s|", Space.c_str(), Output.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), s.c_str(), Bold.c_str());\
2924 CSG_String Space = Prefix;
2928 Space +=
" ";
2931 CSG_String Parameter;
2932 CSG_MetaData *pRoot = NULL, *pChild;
3148 if( s.
Contains(
_TL(
"no choice available")) ) { Bold =
""; }
3158 if( s.
Contains(
_TL(
"no attributes")) ) { Bold =
""; }
3163 CSG_MetaData *pParent = NULL;
3168 c +=
SG_T(
"\n") + Parameter;
3188 CSG_MetaData *pParent = NULL;
3193 c +=
SG_T(
"\n") + Parameter;
3225 if( ((CSG_Parameter_String *)p)->is_Password() )
3254 CSG_String Prefix = Space +
" ";
3255 _Get_Script_Markdown(Parameter, p->
asParameters(), iArguments, Prefix);
3307 CSG_MetaData *pOutput = History(
"TOOL") ? History[
"TOOL"](
"OUTPUT") : NULL;
3323void CSG_Tool::_Set_Output_History(
void)
3331 for(
int i=0; i<pParameters->
Get_Count(); i++)
3383 for(
int j=0; j<pParameter->
asList()->Get_Item_Count(); j++)
bool SG_UI_DataObject_Update(CSG_Data_Object *pDataObject, int Show, CSG_Parameters *pParameters)
void SG_UI_Msg_Add_Error(const char *Message)
int SG_UI_Dlg_Error(const CSG_String &Message, const CSG_String &Caption)
bool SG_UI_Stop_Execution(bool bDialog)
bool SG_UI_Process_Get_Okay(bool bBlink)
bool SG_UI_Dlg_Parameters(CSG_Parameters *pParameters, const CSG_String &Caption)
bool SG_UI_DataObject_Colors_Get(CSG_Data_Object *pDataObject, CSG_Colors *pColors)
void SG_UI_Msg_Add(const char *Message, bool bNewLine, TSG_UI_MSG_STYLE Style)
bool SG_UI_DataObject_Params_Get(CSG_Data_Object *pDataObject, CSG_Parameters *pParameters)
void SG_UI_Process_Set_Text(const CSG_String &Text)
bool SG_UI_Process_Set_Ready(void)
bool SG_UI_Process_Set_Progress(int Position, int Range)
bool SG_UI_DataObject_Add(CSG_Data_Object *pDataObject, int Show)
void SG_UI_Msg_Add_Execution(const char *Message, bool bNewLine, TSG_UI_MSG_STYLE Style)
bool SG_UI_Process_Set_Okay(bool bOkay)
bool SG_UI_DataObject_Params_Set(CSG_Data_Object *pDataObject, CSG_Parameters *pParameters)
void SG_UI_Dlg_Message(const CSG_String &Message, const CSG_String &Caption)
void SG_UI_ProgressAndMsg_Lock(bool bOn)
bool SG_UI_DataObject_Colors_Set(CSG_Data_Object *pDataObject, CSG_Colors *pColors)
bool SG_UI_Dlg_Continue(const CSG_String &Message, const CSG_String &Caption)
bool SG_UI_DataObject_Classify(CSG_Data_Object *pDataObject, const CSG_MetaData &Options)
CSG_String SG_Color_To_Text(long Color, bool bHexadecimal)
CSG_String SG_UI_Get_Application_Name(void)
CSG_String SG_UI_Get_Application_Path(bool bPathOnly)
SAGA_API_DLL_EXPORT bool SG_File_Exists(const CSG_String &FileName)
@ SG_UI_MSG_STYLE_FAILURE
@ SG_UI_MSG_STYLE_SUCCESS
SAGA_API_DLL_EXPORT CSG_String SG_File_Make_Path(const CSG_String &Directory, const CSG_String &Name)
SAGA_API_DLL_EXPORT CSG_Strings SG_String_Tokenize(const CSG_String &String, const CSG_String &Delimiters=SG_DEFAULT_DELIMITERS, TSG_String_Tokenizer_Mode Mode=SG_TOKEN_DEFAULT)
@ SG_UI_DATAOBJECT_SHOW_MAP
@ SG_UI_DATAOBJECT_UPDATE
SAGA_API_DLL_EXPORT bool SG_Dir_Exists(const CSG_String &Directory)
bool Set_Predefined(int Index, bool bRevert=false, int nColors=0)
bool Delete(CSG_Data_Object *pObject, bool bDetach=false)
const SG_Char * Get_Name(void) const
const SG_Char * Get_File_Name(bool bNative=true) const
CSG_MetaData & Get_History(void)
static CSG_DateTime Now(void)
virtual bool Open(const SG_Char *FileName, int Mode=SG_FILE_R, bool bBinary=true, int Encoding=SG_FILE_ENCODING_ANSI)
size_t Read(void *Buffer, size_t Size, size_t Count=1) const
double Get_XMin(bool bCells=false) const
double Get_YMin(bool bCells=false) const
double Get_Cellsize(void) const
const SG_Char * asString(void)
virtual bool Del_Items(void)
CSG_Data_Object * Get_Item(int Index) const
int Get_Item_Count(void) const
double Get_Max(void) const
double Get_Min(void) const
CSG_String Get_CmdID(void) const
const SG_Char * Get_Identifier(void) const
bool is_DataObject(void) const
class CSG_Parameters * asParameters(void) const
bool Set_Name(const CSG_String &Name)
CSG_String Get_Type_Identifier(void) const
CSG_String Get_Type_Name(void) const
bool is_Optional(void) const
TSG_Data_Object_Type Get_DataObject_Type(void) const
bool Set_Description(const CSG_String &Description)
int Get_Children_Count(void) const
double asDouble(void) const
CSG_Parameter * Get_Parent(void) const
virtual TSG_Parameter_Type Get_Type(void) const =0
bool is_Input(void) const
CSG_Parameters * Get_Parameters(void) const
const SG_Char * Get_Name(void) const
bool is_Enabled(bool bCheckEnv=true) const
bool is_Option(void) const
virtual bool Set_Value(int Value)
class CSG_Parameter_List * asList(void) const
CSG_Grid_System * asGrid_System(void) const
CSG_Data_Object * asDataObject(void) const
class CSG_Parameter_Range * asRange(void) const
CSG_Parameter * Get_Child(int iChild) const
bool is_Output(void) const
virtual bool is_Default(void) const
bool is_Information(void) const
bool do_UseInCMD(void) const
const SG_Char * asString(void) const
bool Cmp_Identifier(const CSG_String &Identifier) const
const SG_Char * Get_Description(void) const
bool do_UseInGUI(void) const
bool is_DataObject_List(void) const
bool is_Managed(void) const
bool Set_Callback(bool bActive=true)
bool Reset_Grid_System(void)
int Get_Count(void) const
void Set_Manager(class CSG_Data_Manager *pManager)
class CSG_Tool * Get_Tool(void) const
bool Set_History(CSG_MetaData &History, bool bOptions=true, bool bDataObjects=true)
CSG_Parameter * Get_Parameter(int i) const
bool Create(const CSG_Parameters &Parameters)
bool Restore_Defaults(bool bClearData=false)
bool Push(class CSG_Data_Manager *pManager=NULL, bool bRestoreDefaults=true)
TSG_PFNC_Parameter_Changed Set_Callback_On_Parameter_Changed(TSG_PFNC_Parameter_Changed pCallback)
bool Del_Parameter(int i)
bool Set_Parameter(const CSG_String &ID, CSG_Parameter *pValue)
CSG_String AfterFirst(char Character) const
int Cmp(const CSG_String &String) const
size_t Replace(const CSG_String &Old, const CSG_String &New, bool bReplaceAll=true)
static CSG_String Format(const char *Format,...)
const SG_Char * c_str(void) const
CSG_String & Make_Lower(void)
int Printf(const char *Format,...)
bool is_Empty(void) const
bool Contains(const CSG_String &String) const
CSG_String & Prepend(const CSG_String &String)
int Get_Count(void) const
bool Set_Value(int Field, const CSG_String &Value)
sLong Get_Count(void) const
virtual CSG_Table_Record * Add_Record(CSG_Table_Record *pCopy=NULL)
virtual CSG_Table_Record * Get_Record(sLong Index) const
int Get_Field_Count(void) const
virtual bool Add_Field(const CSG_String &Name, TSG_Data_Type Type, int Position=-1)
virtual bool Set_Field_Type(int Field, TSG_Data_Type Type)
static CSG_String Html_Absolute_Image_Paths(const CSG_String &Text, const CSG_String &Path, bool bAltAsText=false)
static CSG_String Markdown_to_Html(const CSG_String &Text, bool bSimple=true)
static CSG_String Html_to_SimpleText(const CSG_String &Text)
CSG_String Format(const CSG_String &format="") const
int Get_Minutes(void) const
sLong Get_Milliseconds(void) const
sLong Get_Seconds(void) const
int Get_Hours(void) const
CSG_Data_Manager & SG_Get_Data_Manager(void)
int SG_Get_History_Depth(void)
CSG_String SG_Get_DataObject_Name(TSG_Data_Object_Type Type)
CSG_String SG_Get_DataObject_Class_Name(TSG_Data_Object_Type Type)
@ SG_DATAOBJECT_TYPE_PointCloud
@ SG_DATAOBJECT_TYPE_Grids
@ SG_DATAOBJECT_TYPE_Shapes
@ SG_DATAOBJECT_TYPE_Grid
@ SG_DATAOBJECT_TYPE_Table
#define DATAOBJECT_NOTSET
#define PARAMETER_CHECK_ENABLE
#define PARAMETER_DESCRIPTION_PROPERTIES
#define PARAMETER_CHECK_VALUES
#define PARAMETER_INPUT_OPTIONAL
#define PARAMETER_DESCRIPTION_TYPE
#define PARAMETER_DESCRIPTION_NAME
@ PARAMETER_TYPE_FixedTable
@ PARAMETER_TYPE_Grid_List
@ PARAMETER_TYPE_Table_Fields
@ PARAMETER_TYPE_DataObject_Output
@ PARAMETER_TYPE_Table_List
@ PARAMETER_TYPE_TIN_List
@ PARAMETER_TYPE_Grid_System
@ PARAMETER_TYPE_PointCloud_List
@ PARAMETER_TYPE_Data_Type
@ PARAMETER_TYPE_Shapes_List
@ PARAMETER_TYPE_PointCloud
@ PARAMETER_TYPE_Table_Field
@ PARAMETER_TYPE_Parameters
@ PARAMETER_TYPE_FilePath
@ PARAMETER_TYPE_Grids_List
#define PARAMETER_DESCRIPTION_TEXT