📄 module.cpp
字号:
///////////////////////////////////////////////////////////
// //
// SAGA //
// //
// System for Automated Geoscientific Analyses //
// //
// Application Programming Interface //
// //
// Library: SAGA_API //
// //
//-------------------------------------------------------//
// //
// module.cpp //
// //
// Copyright (C) 2005 by Olaf Conrad //
// //
//-------------------------------------------------------//
// //
// This file is part of 'SAGA - System for Automated //
// Geoscientific Analyses'. //
// //
// This library is free software; you can redistribute //
// it and/or modify it under the terms of the GNU Lesser //
// General Public License as published by the Free //
// Software Foundation, version 2.1 of the License. //
// //
// This library 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 Lesser General Public //
// License for more details. //
// //
// You should have received a copy of the GNU Lesser //
// 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 "module.h"
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
CSG_Module::CSG_Module(void)
{
m_bError_Ignore = false;
m_bExecutes = false;
m_Garbage = NULL;
m_nGarbage = 0;
m_pParameters = NULL;
m_npParameters = 0;
Parameters.Create(this, SG_T(""), SG_T(""));
Parameters.Set_Callback_On_Parameter_Changed(&_On_Parameter_Changed);
Set_Managed (false);
Set_Show_Progress (true);
}
//---------------------------------------------------------
CSG_Module::~CSG_Module(void)
{
if( m_pParameters )
{
for(int i=0; i<m_npParameters; i++)
{
delete(m_pParameters[i]);
}
SG_Free(m_pParameters);
}
Destroy();
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CSG_Module::Destroy(void)
{
m_bError_Ignore = false;
History_Supplement.Destroy();
Garbage_Clear();
if( m_bManaged )
{
SG_UI_Process_Set_Okay();
}
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CSG_Module::Set_Name(const SG_Char *String)
{
Parameters.Set_Name(String);
}
const SG_Char * CSG_Module::Get_Name(void)
{
return( Parameters.Get_Name() );
}
//---------------------------------------------------------
void CSG_Module::Set_Description(const SG_Char *String)
{
Parameters.Set_Description(String);
}
const SG_Char * CSG_Module::Get_Description(void)
{
return( Parameters.Get_Description() );
}
//---------------------------------------------------------
void CSG_Module::Set_Author(const SG_Char *String)
{
if( String )
{
m_Author.Printf(String);
}
else
{
m_Author.Clear();
}
}
const SG_Char * CSG_Module::Get_Author(void)
{
return( m_Author.c_str() );
}
//---------------------------------------------------------
void CSG_Module::Set_Translation(CSG_Translator &Translator)
{
Parameters.Set_Translation(Translator);
for(int i=0; i<m_npParameters; i++)
{
m_pParameters[i]->Set_Translation(Translator);
}
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool CSG_Module::Execute(void)
{
bool bResult = false;
///////////////////////////////////////////////////////////
#if !defined(_DEBUG) && defined(_SAGA_VC)
#define _MODULE_EXCEPTION
_try
{
#endif
///////////////////////////////////////////////////////////
if( m_bExecutes == false )
{
m_bExecutes = true;
if( Parameters.DataObjects_Check() )
{
Destroy();
Parameters.DataObjects_Create();
Parameters.Msg_String(false);
if( (bResult = On_Execute()) == true )
{
_Set_Output_History();
}
if( !Process_Get_Okay(false) )
{
SG_UI_Msg_Add(LNG("[MSG] Execution has been stopped by user!"), true);
}
Destroy();
Parameters.DataObjects_Synchronize();
}
m_bExecutes = false;
}
///////////////////////////////////////////////////////////
#ifdef _MODULE_EXCEPTION
}
_except(1)
{
Message_Add(Get_Name());
Message_Add(LNG("[ERR] Access Violation"));
Message_Dlg(LNG("[ERR] Access Violation"));
}
#endif
///////////////////////////////////////////////////////////
return( bResult );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CSG_Module::Set_Managed(bool bOn)
{
m_bManaged = Parameters.m_bManaged = bOn;
for(int i=0; i<m_npParameters; i++)
{
m_pParameters[i]->m_bManaged = bOn;
}
}
//---------------------------------------------------------
void CSG_Module::Set_Show_Progress(bool bOn)
{
m_bShow_Progress = bOn;
}
///////////////////////////////////////////////////////////
// //
// Parameters //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
int CSG_Module::_On_Parameter_Changed(CSG_Parameter *pParameter)
{
if( pParameter && pParameter->Get_Owner() && pParameter->Get_Owner()->Get_Owner() )
{
return( ((CSG_Module *)pParameter->Get_Owner()->Get_Owner())->
On_Parameter_Changed(pParameter->Get_Owner(), pParameter)
);
}
return( 0 );
}
//---------------------------------------------------------
int CSG_Module::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
{
return( true );
}
///////////////////////////////////////////////////////////
// //
// Extra Parameters //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
CSG_Parameters * CSG_Module::Add_Parameters(const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description)
{
CSG_Parameters *pParameters;
m_pParameters = (CSG_Parameters **)SG_Realloc(m_pParameters, (m_npParameters + 1) * sizeof(CSG_Parameters *));
pParameters = m_pParameters[m_npParameters++] = new CSG_Parameters();
pParameters->Create(this, Name, Description, Identifier);
pParameters->Set_Callback_On_Parameter_Changed(&_On_Parameter_Changed);
return( pParameters );
}
//---------------------------------------------------------
CSG_Parameters * CSG_Module::Get_Parameters(const SG_Char *Identifier)
{
CSG_String sIdentifier(Identifier);
for(int i=0; i<m_npParameters; i++)
{
if( !sIdentifier.Cmp(m_pParameters[i]->Get_Identifier()) )
{
return( m_pParameters[i] );
}
}
return( NULL );
}
//---------------------------------------------------------
bool CSG_Module::Dlg_Parameters(const SG_Char *Identifier)
{
if( !m_bManaged || Dlg_Parameters(Get_Parameters(Identifier), Get_Name()) )
{
Get_Parameters(Identifier)->Set_History(History_Supplement);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -