📄 saga_cmd.cpp
字号:
///////////////////////////////////////////////////////////
// //
// SAGA //
// //
// System for Automated Geoscientific Analyses //
// //
// Command Line Interface //
// //
// Program: SAGA_CMD //
// //
//-------------------------------------------------------//
// //
// SAGA_CMD.cpp //
// //
// Copyright (C) 2005 by Olaf Conrad //
// //
//-------------------------------------------------------//
// //
// This file is part of 'SAGA - System for Automated //
// Geoscientific Analyses'. SAGA is free software; you //
// can redistribute it and/or modify it under the terms //
// of the GNU General Public License as published by the //
// Free Software Foundation; version 2 of the License. //
// //
// SAGA is distributed in the hope that it will be //
// useful, but WITHOUT ANY WARRANTY; without even the //
// implied warranty of MERCHANTABILITY or FITNESS FOR A //
// PARTICULAR PURPOSE. See the GNU General Public //
// License for more details. //
// //
// You should have received a copy of the GNU General //
// Public License along with this program; if not, //
// write to the Free Software Foundation, Inc., //
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, //
// USA. //
// //
//-------------------------------------------------------//
// //
// contact: Olaf Conrad //
// Institute of Geography //
// University of Goettingen //
// Goldschmidtstr. 5 //
// 37077 Goettingen //
// Germany //
// //
// e-mail: oconrad@saga-gis.org //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
#include <wx/app.h>
#include <wx/utils.h>
#include <wx/dir.h>
#include <saga_api/saga_api.h>
#include "callback.h"
#include "module_library.h"
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
#define SAGA_CMD_VERSION SG_T("2.0")
#define SAGA_ENV_LIBPATH SG_T("SAGA_MLB")
#define SYS_ENV_PATH SG_T("PATH")
#define OPT_CREATE_BATCH SG_T("-create_batch")
#define OPT_SILENT SG_T("-silent")
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool Execute (const SG_Char *MLB_Path, const SG_Char *FileName, const SG_Char *ModuleName, int argc, char *argv[]);
void Error_Library (const SG_Char *MLB_Path);
void Error_Module (const SG_Char *MLB_Path, const SG_Char *FileName);
void Print_Logo (const SG_Char *MLB_Path);
void Print_Execution (const SG_Char *MLB_Path, const SG_Char *FileName, const SG_Char *ModuleName);
void Print_Help (void);
void Create_Example (void);
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
int main (int argc, char *argv[])
{
//---------------------------------------------------------
#if !defined(_DEBUG) && defined(_SAGA_VC)
#define _MODULE_EXCEPTION
_try
{
#endif
//---------------------------------------------------------
bool bResult = false;
if( wxInitialize() )
{
wxString MLB_Path, ENV_Path;
MLB_Path = wxGetenv(SAGA_ENV_LIBPATH) ? wxGetenv(SAGA_ENV_LIBPATH) : wxGetCwd();
if( wxGetEnv(SYS_ENV_PATH, &ENV_Path) && ENV_Path.Length() > 0 )
{
wxSetEnv(SYS_ENV_PATH, wxString::Format(wxT("%s;%s"), ENV_Path.c_str(), MLB_Path.c_str()));
}
else
{
wxSetEnv(SYS_ENV_PATH, MLB_Path);
}
Print_Logo(MLB_Path);
SG_Set_UI_Callback(Get_Callback());
SG_Get_Translator()->Create(SG_File_Make_Path(wxGetCwd(), SG_T("saga"), SG_T("lng")), false);
//-------------------------------------------------
switch( argc )
{
case 1:
Error_Library (MLB_Path);
break;
case 2:
Error_Module (MLB_Path, SG_STR_MBTOSG(argv[1]));
break;
default:
bResult = Execute (MLB_Path, SG_STR_MBTOSG(argv[1]), SG_STR_MBTOSG(argv[2]), argc, argv);
break;
}
//-------------------------------------------------
if( ENV_Path.Length() > 0 )
{
wxSetEnv(SYS_ENV_PATH, ENV_Path);
}
else
{
wxUnsetEnv(SYS_ENV_PATH);
}
wxBell();
wxUninitialize();
}
//---------------------------------------------------------
#ifdef _DEBUG
Get_Pause();
#endif
#ifdef _MODULE_EXCEPTION
}
_except(1)
{
Print_Error(LNG("access violation"));
}
#endif
//---------------------------------------------------------
return( bResult ? 0 : 1 );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool Execute(const SG_Char *MLB_Path, const SG_Char *FileName, const SG_Char *ModuleName, int argc, char *argv[])
{
bool bResult = false;
int i;
CModule_Library Library;
if( !Library.Create(FileName, MLB_Path) )
{
Error_Library(MLB_Path);
}
else if( !Library.Select(ModuleName) )
{
Library.Destroy();
Print_Error(LNG("module not found"), ModuleName);
Error_Module(MLB_Path, FileName);
}
else if( Library.Get_Selected()->is_Interactive() )
{
Library.Destroy();
Print_Error(LNG("cannot execute interactive module"), ModuleName);
Error_Module(MLB_Path, FileName);
}
else
{
Print_Execution(MLB_Path, FileName, Library.Get_Selected()->Get_Name());
if( argc > 3 && !SG_STR_CMP(OPT_SILENT, SG_STR_MBTOSG(argv[3])) )
{
i = 3;
Set_Silent(true);
}
else
{
i = 2;
}
Set_Library(&Library);
bResult = Library.Execute(argc - i, argv + i);
Set_Library(NULL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -