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(
"<hr><small><small>%s: <i>%s</i>.</small></small>",
_TL(
"Description editor(s)"), Editors.
c_str());
562 #define ADD_MESSAGE_EXECUTION(Text, Style) { SG_UI_Msg_Add(Text, true, Style); if( has_GUI() ) { SG_UI_Msg_Add_Execution(Text, true, Style); } }
572 m_bError_Ignore =
false;
574 bool bResult =
false;
576 m_Execution_Info.
Clear();
588 if(
Parameters.DataObjects_Create() ==
false )
590 _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;
1033 case 1: m_bError_Ignore =
true;
break;
1043 wxString _s; va_list argptr;
1048 wxString _Format(Format); _Format.Replace(
"%s",
"%ls"); va_start(argptr, _Format);
1049 _s.PrintfV(_Format, argptr);
1051 va_start(argptr, Format);
1052 _s.PrintfV(Format, argptr);
1065 wxString _s; va_list argptr;
1070 wxString _Format(Format); _Format.Replace(
"%s",
"%ls"); va_start(argptr, _Format);
1071 _s.PrintfV(_Format, argptr);
1073 va_start(argptr, Format);
1074 _s.PrintfV(Format, argptr);
1120 else if(
Parameters(i)->is_DataObject_List() )
1122 for(
int j=0; j<
Parameters(i)->asList()->Get_Item_Count(); j++)
1155 wxString _s; va_list argptr;
1160 wxString _Format(Format); _Format.Replace(
"%s",
"%ls"); va_start(argptr, _Format);
1161 _s.PrintfV(_Format, argptr);
1163 va_start(argptr, Format);
1164 _s.PrintfV(Format, argptr);
1177 wxString _s; va_list argptr;
1182 wxString _Format(Format); _Format.Replace(
"%s",
"%ls"); va_start(argptr, _Format);
1183 _s.PrintfV(_Format, argptr);
1185 va_start(argptr, Format);
1186 _s.PrintfV(Format, argptr);
1203 m_Execution_Info +=
"\n";
1206 m_Execution_Info += Text;
1212 wxString _s; va_list argptr;
1217 wxString _Format(Format); _Format.Replace(
"%s",
"%ls"); va_start(argptr, _Format);
1218 _s.PrintfV(_Format, argptr);
1220 va_start(argptr, Format);
1221 _s.PrintfV(Format, argptr);
1234 wxString _s; va_list argptr;
1239 wxString _Format(Format); _Format.Replace(
"%s",
"%ls"); va_start(argptr, _Format);
1240 _s.PrintfV(_Format, argptr);
1242 va_start(argptr, Format);
1243 _s.PrintfV(Format, argptr);
1304 return( pParameter ? pParameter->
asTable() : NULL );
1311 return( pLUT && LUT.
Create(*pLUT) );
1385 if( pDataObject == pCopy )
1492#define INIT_STRETCH_OPTIONS(method) { if( !pDataObject || (pDataObject->asTable(true) && (Field < 0 || Field >= pDataObject->asTable(true)->Get_Field_Count())) ) { return( false ); }\
1493 if( Colors >= 0 ) { DataObject_Set_Colors(pDataObject, -1, Colors); }\
1494 DataObject_Set_Parameter(pDataObject, "COLOR_SYMBOLS" , 3); \
1495 DataObject_Set_Parameter(pDataObject, "STRETCH" , method);\
1496 DataObject_Set_Parameter(pDataObject, "STRETCH_INTERVALS" , Interval_Mode);\
1497 DataObject_Set_Parameter(pDataObject, "STRETCH_INTERVALS_LOG", Interval_Log );\
1498 if( pDataObject->asTable(true) )\
1499 { DataObject_Set_Parameter(pDataObject, "STRETCH_FIELD" , Field);\
1500 DataObject_Set_Parameter(pDataObject, "STRETCH_NORMALIZE", pDataObject->asTable(true)->Get_Field_Count());\
1555#define INIT_CLASSIFY_OPTIONS(method) if( !pDataObject || (pDataObject->asTable(true) && (Field < 0 || Field >= pDataObject->asTable(true)->Get_Field_Count())) ) { return( false ); }\
1556 CSG_MetaData Options; Options.Add_Child("METHOD", method); Options.Add_Child("COLORS", Colors); Options.Add_Child("FIELD", Field);
1563 Options.Add_Child(
"MAXCLASSES", maxClasses);
1573 Options.Add_Child(
"CLASSES", Classes);
1583 Options.Add_Child(
"INTERVAL", Interval);
if( bOffset ) { Options.Add_Child(
"OFFSET", Offset); }
1593 Options.Add_Child(
"CLASSES", Classes); Options.Add_Child(
"HISTOGRAM", bHistogram ? 1 : 0);
1603 Options.Add_Child(
"CLASSES", Classes); Options.Add_Child(
"INCREASING", bIncreasing ? 1 : 0);
1613 Options.Add_Child(
"CLASSES", Classes);
1623 Options.Add_Child(
"STDDEV", StdDev); Options.Add_Child(
"STDDEV_MAX", StdDev_Max);
1651 return( pParameter );
1789 return(
Parameters.Set_Grid_System(System) );
1823void CSG_Tool::_Update_Parameter_States(
CSG_Parameters *pParameters)
1827 for(
int i=0; i<pParameters->
Get_Count(); i++)
1881CSG_String CSG_Tool::_Get_Script_CMD(
bool bHeader,
bool bAllArguments,
bool bWrapArgs,
bool bBatch)
1889 Script +=
"@ECHO OFF\n\n";
1890 Script +=
"PUSHD %~dp0\n\n";
1891 Script +=
"REM SET SAGA_TLB=C:\\MyTools\n\n";
1893 Script +=
"REM Tool: " +
Get_Name() +
"\n\n";
1894 Script +=
"%SAGA_CMD%";
1898 Script +=
"#!/bin/bash\n\n";
1899 Script +=
"# export SAGA_TLB=~/mytools\n\n";
1900 Script +=
"# tool: " +
Get_Name() +
"\n\n";
1901 Script +=
"saga_cmd";
1906 Script +=
"saga_cmd";
1915 ?
" \"" +
Get_ID () +
"\""
1918 _Get_Script_CMD(Script,
Get_Parameters(), bAllArguments, bWrapArgs, bBatch);
1922 _Get_Script_CMD(Script,
Get_Parameters(i), bAllArguments, bWrapArgs, bBatch);
1928 Script += bBatch ?
"\n\nPAUSE\n" :
"\n";
1935void CSG_Tool::_Get_Script_CMD(
CSG_String &Script,
CSG_Parameters *pParameters,
bool bAllArguments,
bool bWrapArgs,
bool bBatch)
1937 #define GET_ID1(p) (p->Get_Parameters()->Get_Identifier().Length() > 0 \
1938 ? CSG_String::Format("%s_%s", p->Get_Parameters()->Get_Identifier().c_str(), p->Get_Identifier()) \
1939 : CSG_String::Format(p->Get_Identifier())).c_str()
1941 #define GET_ID2(p, s) CSG_String::Format("%s_%s", GET_ID1(p), s).c_str()
1943 const char *Prefix = !bWrapArgs ?
" -" : bBatch ?
" ^\n -" :
" \\\n -";
1944 const char *StrFmt = bBatch ?
"%s=\"%s\"" :
"%s=\\\"\"%s\"\\\"";
1947 for(
int iParameter=0; iParameter<pParameters->
Get_Count(); iParameter++)
1995 if( ((CSG_Parameter_String *)p)->is_Password() )
2045 default : File +=
".dat" ;
break;
2064 Script +=
"file(s)";
2071 for(
int iObject=1; iObject<p->
asList()->Get_Item_Count(); iObject++)
2094CSG_String CSG_Tool::_Get_Script_CMD_Usage(
void)
2096 wxCmdLineParser Parser; Parser.SetSwitchChars(
"-");
2105 wxString Usage = wxString::Format(
"\nUsage: saga_cmd %s %s %s",
Get_Library().c_str(),
Get_ID().c_str(),
2109 CSG_String _Usage(&Usage);
2115void CSG_Tool::_Get_Script_CMD_Usage(
CSG_Parameters *pParameters, wxCmdLineParser &Parser)
2117 for(
int i=0; i<pParameters->
Get_Count(); i++)
2141 Description.Replace(
"\xb",
"");
2147 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_NEEDS_SEPARATOR|wxCMD_LINE_PARAM_OPTIONAL);
2156 _Get_Script_CMD_Usage(pParameter->
asParameters(), Parser);
2160 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2164 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
2172 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2177 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2181 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_DATE , wxCMD_LINE_PARAM_OPTIONAL);
2185 Parser.AddOption(ID +
"_MIN", wxEmptyString, Description, wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2186 Parser.AddOption(ID +
"_MAX", wxEmptyString, Description, wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2190 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2194 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2200 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2204 Parser.AddOption(ID, wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2210 Parser.AddOption(ID +
"_D" , wxEmptyString,
_TL(
"Cell Size" ), wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2211 Parser.AddOption(ID +
"_X" , wxEmptyString,
_TL(
"Lower Left Center Cell X-Coordinate"), wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2212 Parser.AddOption(ID +
"_Y" , wxEmptyString,
_TL(
"Lower Left Center Cell Y-Coordinate"), wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL);
2213 Parser.AddOption(ID +
"_NX" , wxEmptyString,
_TL(
"Number of Columns" ), wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
2214 Parser.AddOption(ID +
"_NY" , wxEmptyString,
_TL(
"Number of Rows" ), wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
2215 Parser.AddOption(ID +
"_FILE", wxEmptyString,
_TL(
"Grid File" ), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
2232CSG_String CSG_Tool::_Get_Script_Python(
bool bHeader,
bool bAllArguments)
2234 CSG_String Script, Name(
Get_Name());
2236 Name.Replace(
" ",
"_");
2237 Name.Replace(
"(",
"");
2238 Name.Replace(
")",
"");
2239 Name.Replace(
"[",
"");
2240 Name.Replace(
"]",
"");
2241 Name.Replace(
".",
"");
2242 Name.Replace(
",",
"");
2243 Name.Replace(
"/",
"");
2244 Name.Replace(
"-",
"");
2249 Script +=
"#! /usr/bin/env python\n";
2251 Script +=
"#_________________________________________\n";
2252 Script +=
"##########################################\n";
2256 Script +=
"# Initialize the environment...\n";
2258 Script +=
"# Windows: Let the 'SAGA_PATH' environment variable point to\n";
2259 Script +=
"# the SAGA installation folder before importing 'saga_api'!\n";
2260 Script +=
"# This can be defined globally in the Windows system or\n";
2261 Script +=
"# user environment variable settings, in the 'PySAGA/__init__.py'\n";
2262 Script +=
"# file, or in the individual Python script itself. To do the latter\n";
2263 Script +=
"# just uncomment the following line and adjust the path accordingly:\n";
2264 Script +=
"###import os; os.environ['SAGA_PATH'] = '" + AppPath +
"'\n";
2266 Script +=
"# Windows: The most convenient way to make PySAGA available to all your\n";
2267 Script +=
"# Python scripts is to copy the PySAGA folder to the 'Lib/site-packages/'\n";
2268 Script +=
"# folder of your Python installation. If don't want to do this or if you\n";
2269 Script +=
"# don't have the rights to do so, you can also copy it to the folder with\n";
2270 Script +=
"# the Python scripts in which you want to use PySAGA, or alternatively\n";
2271 Script +=
"# you can add the path containing the PySAGA folder (e.g. the path to your\n";
2272 Script +=
"# SAGA installation) to the PYTHONPATH environment variable. To do this\n";
2273 Script +=
"# from within your script you can also take the following command (just\n";
2274 Script +=
"# uncomment the following line and adjust the path accordingly):\n";
2275 Script +=
"###import sys; sys.path.insert(1, '" + AppPath +
"')\n";
2278 Script +=
"# Import saga_api from PySAGA:\n";
2279 Script +=
"from PySAGA import saga_api\n";
2282 Script +=
"#_________________________________________\n";
2283 Script +=
"##########################################\n";
2284 Script +=
"def Run_" + Name +
"(Results):\n";
2288 if( bHeader ) Script +=
" # Get the tool:\n";
2289 Script +=
" Tool = saga_api.SG_Get_Tool_Library_Manager().Get_Tool('" +
Get_Library() +
"', '" +
Get_ID() +
"')\n";
2290 Script +=
" if not Tool:\n";
2291 Script +=
" saga_api.SG_UI_Msg_Add_Error('Failed to request tool: " +
Get_Name() +
"')\n";
2292 Script +=
" return False\n";
2294 if( bHeader ) Script +=
" # Set the parameter interface:\n";
2295 Script +=
" Tool.Reset()\n";
2307 if( bHeader ) Script +=
" # Execute the tool:\n";
2308 Script +=
" if not Tool.Execute():\n";
2309 Script +=
" saga_api.SG_UI_Msg_Add_Error('failed to execute tool: ' + Tool.Get_Name().c_str())\n";
2310 Script +=
" return False\n";
2312 if( bHeader ) Script +=
" # Request the results:\n";
2330 default : type =
"" ; ext =
"" ;
break;
2335 Script +=
" Data = Tool.Get_Parameter('" +
id +
"').as" + type +
"()\n";
2339 Script +=
" Data.Save('{:s}/{:s}.{:s}'.format(Results, Data.Get_Name(), '" + ext +
"'))\n\n";
2344 Script +=
" List = Tool.Get_Parameter('" +
id +
"').as" + type +
"List()\n";
2345 Script +=
" for i in range(0, List.Get_Item_Count()):\n";
2349 Script +=
" List.Get_Item(i).Save('{:s}/{:s}_{:d}.{:s}'.format(Results, List.Get_Name(), i, '" + ext +
"'))\n\n";
2353 Script +=
" Data = List.Get_Item(i)\n";
2363 Script +=
" return True\n";
2366 Script +=
"#_________________________________________\n";
2367 Script +=
"##########################################\n";
2368 Script +=
"print('This is a simple template for using a SAGA tool through Python.')\n";
2369 Script +=
"print('Please edit the script to make it work properly before using it!')\n";
2371 Script +=
"# Run_" + Name +
"('.')\n";
2373 Script +=
"# job is done, free memory resources:\n";
2374 Script +=
"saga_api.SG_Get_Data_Manager().Delete()\n";
2383 for(
int iParameter=0; iParameter<pParameters->
Get_Count(); iParameter++)
2396 ID.Prepend(Prefix +
".");
2438 if( ((CSG_Parameter_String *)p)->is_Password() )
2451 Script +=
CSG_String::Format(
" Tool.Set_Parameter('%s', saga_api.SG_Create_Table('table.txt'))\n", ID.c_str());
2457 Script +=
CSG_String::Format(
" Tool.Set_Parameter('%s', saga_api.CSG_Grid_System(%g, %g, %g, %d, %d))\n", ID.c_str(),
2473 Script +=
CSG_String::Format(
" Tool.Set_Parameter('%s', saga_api.SG_Get_Data_Manager().Add('%s input file%s'))\n", ID.c_str(),
2479 Script +=
CSG_String::Format(
" Tool.Set_Parameter('%s', saga_api.SG_Get_Create_Pointer()) # optional output, remove this line, if you don't want to create it\n", ID.c_str());
2491 Script +=
CSG_String::Format(
" Tool.Get_Parameter('%s').asList().Add_Item('%s input list%s')\n", ID.c_str(),
2498 _Get_Script_Python(Script, p->
asParameters(), bAllArguments, ID);
2510CSG_String CSG_Tool::_Get_Script_Python_Wrap(
bool bHeader,
bool bName,
bool bCall,
int AllArguments,
bool bWrapArgs)
2512 CSG_String Arguments, Description, Code;
2514 if( AllArguments >= 0 )
2518 _Get_Script_Python_Wrap(
Parameters[i],
PARAMETER_INPUT , Arguments, Description, Code, bCall && bHeader, AllArguments == 0, bWrapArgs);
2528 _Get_Script_Python_Wrap(
Parameters[i],
PARAMETER_OUTPUT , Arguments, Description, Code, bCall && bHeader, AllArguments == 0, bWrapArgs);
2533 _Get_Script_Python_Wrap(
Parameters[i], 0 , Arguments, Description, Code, bCall , AllArguments == 0, bWrapArgs);
2538 CSG_String Name, Expected(
Get_Name()); Expected.Replace(
"'",
"\\'");
2544 if( isdigit(Name[0]) )
2575 Script +=
"from PySAGA.tools import " +
Get_Library() +
"\n\n";
2579 Script += Code +
"\n";
2583 Script +=
Get_Library() +
'.' + Name +
"(" + Arguments +
")\n";
2591 Script +=
"#! /usr/bin/env python\n";
2592 Script +=
"from PySAGA.helper import Tool_Wrapper\n\n";
2595 Script +=
"def " + Name +
"(" + Arguments +
", Verbose=2):\n";
2598 Script +=
" ----------\n";
2600 for(
int i=0; i<_Description.
Get_Count(); i++)
2602 _Description[i].Trim_Both(); Script +=
" " + _Description[i] +
"\\n\n";
2604 Script +=
" Arguments\n";
2605 Script +=
" ----------\n";
2606 Script += Description +
"\n";
2607 Script +=
" - Verbose [`integer number`] : Verbosity level, 0=silent, 1=tool name and success notification, 2=complete tool output.\\n\n";
2608 Script +=
" Returns\n";
2609 Script +=
" ----------\n";
2610 Script +=
" `boolean` : `True` on success, `False` on failure.\n";
2612 Script +=
" Tool = Tool_Wrapper('" +
Get_Library() +
"', '" +
Get_ID() +
"', '" + Expected +
"')\n";
2613 Script +=
" if Tool.is_Okay():\n";
2615 Script +=
" return Tool.Execute(Verbose)\n";
2616 Script +=
" return False\n\n";
2643 ID.Prepend(Prefix +
".");
2646 CSG_String Argument(ID);
2648 if( Argument[0] >=
'0' && Argument[0] <=
'9' )
2650 Argument.Prepend(
'_');
2653 Argument.Replace(
".",
"_");
2654 Argument.Replace(
"|",
"_");
2655 Argument.Replace(
" ",
"_");
2657 if( Argument.Length() > 2 )
2659 Argument.Make_Upper();
2665 bool bResult =
false;
2667 for(
int i=0; i<(*Parameter.
asParameters()).Get_Count(); i++)
2669 if( _Get_Script_Python_Wrap((*Parameter.
asParameters())[i], Constraint, Arguments, Description, Code, bCall, bOnlyNonDefaults, bWrapArgs, ID) )
2682 if( Parameter.
is_Option() && Constraint != 0 ) {
return(
false ); }
2702 ); File.Replace(
"\\",
"/");
2736 if( bOnlyNonDefaults && Parameter.
is_Default() )
2772 default :
return(
false );
2780 Arguments += !Arguments.
is_Empty() ?
",\n " :
"\n ";
2787 Arguments += Argument +
"=" + Value;
2796 Arguments += !Arguments.
is_Empty() ?
",\n " :
"\n ";
2803 Arguments += Argument +
"=None";
2808 if( Parameter.
is_Input () ) { Code +=
"Tool.Set_Input "; }
2809 if( Parameter.
is_Output() ) { Code +=
"Tool.Set_Output"; }
2810 if( Parameter.
is_Option() ) { Code +=
"Tool.Set_Option"; }
2815 Description +=
" - " + Argument +
" [`";
2819 Description += Parameter.
is_Optional() ?
"optional input " :
"input ";
2823 Description +=
"output ";
2832 Description +=
". " + s;
2835 Description +=
"\n";
2845CSG_String CSG_Tool::_Get_Script_Markdown(
bool bHeader,
int iArguments)
2856 Script +=
CSG_String::Format(
"**Geoprocessing** → *%s* // **Tools** → *%s*\n\n", Menu.
c_str(), Category.
c_str());
2859 Script +=
"|**Parameter**|**Setting**|\n";
2860 Script +=
"|---|---|\n";
2874 #define WRITE_CHILD(pChild, Prefix) Script += CSG_String::Format("|%s%s||\n", Prefix.c_str(), pChild->Get_Name().c_str());\
2875 for (int i=0; i<pChild->Get_Children_Count(); i++)\
2877 Script += CSG_String::Format("%s\n", pChild->Get_Child(i)->Get_Content().c_str());\
2880 CSG_MetaData Properties;
2882 for(
int iParameter=0; iParameter<pParameters->
Get_Count(); iParameter++)
2884 _Format_Markdown(pParameters->
Get_Parameter(iParameter), Script, Properties, iArguments, Prefix);
2891 CSG_MetaData *pChild = Properties.
Get_Child(i);
2906 #define CHECK_OBJECTS_NODE() pChild = Properties.Get_Child(_TL("Options"));\
2909 pChild = Properties.Add_Child(_TL("Options"));\
2914 #define CHECK_DATA_NODE(Name) pChild = Properties.Get_Child(Name);\
2917 CSG_MetaData *pData = Properties.Get_Child(_TL("Data Objects"));\
2920 Properties.Add_Child(_TL("Data Objects"));\
2922 pChild = Properties.Add_Child(Name);\
2927 #define GET_PARENT_NODE(prt) bool bFound = false;\
2928 for (int i=0; i<Properties.Get_Children_Count(); i++)\
2930 CSG_MetaData *pDatatype = Properties.Get_Child(i);\
2931 for (int j=0; j<Properties.Get_Children_Count(); j++)\
2933 pParent = pDatatype->Get_Child(prt);\
2946 #define FORMAT_DATASET() if( p->is_Input() )\
2948 CSG_String Input = p->is_Optional() ? ">" : ">>";\
2949 CSG_String s = p->asString();\
2950 if( s.Contains(_TL("not set")) || s.Contains(_TL("No objects")) ) { Bold = ""; }\
2951 s.Replace("<", "\\<");\
2952 Parameter = CSG_String::Format("|%s%s %s%s%s|%s%s%s|", Space.c_str(), Input.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), s.c_str(), Bold.c_str());\
2954 else if( p->is_Output() )\
2956 CSG_String Output = p->is_Optional() ? "\\<" : "<<";\
2957 CSG_String s = p->asString();\
2958 if( !p->is_Optional() && s.Contains(_TL("create")) ) { Bold = ""; }\
2959 else if( p->is_Optional() && (s.Contains(_TL("not set")) || s.Contains(_TL("No objects"))) ) { Bold = ""; }\
2960 s.Replace("<", "\\<");\
2961 Parameter = CSG_String::Format("|%s%s %s%s%s|%s%s%s|", Space.c_str(), Output.c_str(), Bold.c_str(), Name.c_str(), Bold.c_str(), Bold.c_str(), s.c_str(), Bold.c_str());\
2987 CSG_String Space = Prefix;
2991 Space +=
" ";
2994 CSG_String Parameter;
2995 CSG_MetaData *pRoot = NULL, *pChild;
3211 if( s.
Contains(
_TL(
"no choice available")) ) { Bold =
""; }
3221 if( s.
Contains(
_TL(
"no attributes")) ) { Bold =
""; }
3226 CSG_MetaData *pParent = NULL;
3231 c +=
SG_T(
"\n") + Parameter;
3251 CSG_MetaData *pParent = NULL;
3256 c +=
SG_T(
"\n") + Parameter;
3288 if( ((CSG_Parameter_String *)p)->is_Password() )
3317 CSG_String Prefix = Space +
" ";
3318 _Get_Script_Markdown(Parameter, p->
asParameters(), iArguments, Prefix);
3370 CSG_MetaData *pOutput = History(
"TOOL") ? History[
"TOOL"](
"OUTPUT") : NULL;
3386void CSG_Tool::_Set_Output_History(
void)
3394 for(
int i=0; i<pParameters->
Get_Count(); i++)
3446 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)
bool SG_UI_Process_Set_Ready(void)
bool SG_UI_Process_Set_Progress(int Position, int Range)
bool SG_UI_DataObject_Add(CSG_Data_Object *pDataObject, int Show)
void SG_UI_Msg_Add_Execution(const char *Message, bool bNewLine, TSG_UI_MSG_STYLE Style)
bool SG_UI_Process_Set_Okay(bool bOkay)
void SG_UI_StatusBar_Set_Text(const CSG_String &Text)
bool SG_UI_DataObject_Params_Set(CSG_Data_Object *pDataObject, CSG_Parameters *pParameters)
void SG_UI_Dlg_Message(const CSG_String &Message, const CSG_String &Caption)
void SG_UI_ProgressAndMsg_Lock(bool bOn)
bool SG_UI_DataObject_Colors_Set(CSG_Data_Object *pDataObject, CSG_Colors *pColors)
bool SG_UI_Dlg_Continue(const CSG_String &Message, const CSG_String &Caption)
bool SG_UI_DataObject_Classify(CSG_Data_Object *pDataObject, const CSG_MetaData &Options)
CSG_String SG_Color_To_Text(long Color, bool bHexadecimal)
SAGA_API_DLL_EXPORT bool SG_File_Exists(const CSG_String &FileName)
@ SG_UI_MSG_STYLE_FAILURE
@ 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
class CSG_PointCloud * asPointCloud(bool bPolymorph=false) const
CSG_MetaData & Get_History(void)
static CSG_DateTime Now(void)
static const CSG_String & Get_Application_Name(void)
static const CSG_String & Get_Application_Path(bool bPathOnly)
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
const SG_Char * asString(void) const
double Get_Cellsize(void) const
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
CSG_Table * asTable(void) 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)
bool Assign_Values(const CSG_Table &Table)
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