📄 parameter_data.cpp
字号:
///////////////////////////////////////////////////////////
// //
// SAGA //
// //
// System for Automated Geoscientific Analyses //
// //
// Application Programming Interface //
// //
// Library: SAGA_API //
// //
//-------------------------------------------------------//
// //
// parameter_data.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 <string.h>
#include "parameters.h"
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
#define ENTRY_TEXT_END SG_T("[TEXT_ENTRY_END]")
#define ENTRY_DATAOBJECT_CREATE SG_T("[ENTRY_DATAOBJECT_CREATE]")
#define ENTRY_DATAOBJECTLIST_END SG_T("[ENTRY_DATAOBJECTLIST_END]")
///////////////////////////////////////////////////////////
// //
// Base Class //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
CSG_Parameter_Data::CSG_Parameter_Data(CSG_Parameter *pOwner, long Constraint)
{
m_pOwner = pOwner;
m_Constraint = Constraint;
}
//---------------------------------------------------------
CSG_Parameter_Data::~CSG_Parameter_Data(void)
{
}
//---------------------------------------------------------
const SG_Char * CSG_Parameter_Data::Get_Type_Name(void)
{
switch( Get_Type() )
{
default: return( LNG("[PRM] Parameter") );
case PARAMETER_TYPE_Node: return( LNG("[PRM] Node") );
case PARAMETER_TYPE_Bool: return( LNG("[PRM] Boolean") );
case PARAMETER_TYPE_Int: return( LNG("[PRM] Integer") );
case PARAMETER_TYPE_Double: return( LNG("[PRM] Floating point") );
case PARAMETER_TYPE_Degree: return( LNG("[PRM] Degree") );
case PARAMETER_TYPE_Range: return( LNG("[PRM] Value range") );
case PARAMETER_TYPE_Choice: return( LNG("[PRM] Choice") );
case PARAMETER_TYPE_String: return( LNG("[PRM] Text") );
case PARAMETER_TYPE_Text: return( LNG("[PRM] Long text") );
case PARAMETER_TYPE_FilePath: return( LNG("[PRM] File path") );
case PARAMETER_TYPE_Font: return( LNG("[PRM] Font") );
case PARAMETER_TYPE_Color: return( LNG("[PRM] Color") );
case PARAMETER_TYPE_Colors: return( LNG("[PRM] Colors") );
case PARAMETER_TYPE_FixedTable: return( LNG("[PRM] Static table") );
case PARAMETER_TYPE_Grid_System: return( LNG("[PRM] Grid system") );
case PARAMETER_TYPE_Table_Field: return( LNG("[PRM] Table field") );
case PARAMETER_TYPE_DataObject_Output: return( LNG("[PRM] Data Object") );
case PARAMETER_TYPE_Grid: return( LNG("[PRM] Grid") );
case PARAMETER_TYPE_Table: return( LNG("[PRM] Table") );
case PARAMETER_TYPE_Shapes: return( LNG("[PRM] Shapes") );
case PARAMETER_TYPE_TIN: return( LNG("[PRM] TIN") );
case PARAMETER_TYPE_Grid_List: return( LNG("[PRM] Grid list") );
case PARAMETER_TYPE_Table_List: return( LNG("[PRM] Table list") );
case PARAMETER_TYPE_Shapes_List: return( LNG("[PRM] Shapes list") );
case PARAMETER_TYPE_TIN_List: return( LNG("[PRM] TIN list") );
case PARAMETER_TYPE_Parameters: return( LNG("[PRM] Parameters") );
}
}
//---------------------------------------------------------
bool CSG_Parameter_Data::Set_Value(int Value)
{
return( false );
}
bool CSG_Parameter_Data::Set_Value(double Value)
{
return( false );
}
bool CSG_Parameter_Data::Set_Value(void *Value)
{
return( false );
}
//---------------------------------------------------------
int CSG_Parameter_Data::asInt(void)
{
return( 0 );
}
double CSG_Parameter_Data::asDouble(void)
{
return( 0.0 );
}
void * CSG_Parameter_Data::asPointer(void)
{
return( NULL );
}
const SG_Char * CSG_Parameter_Data::asString(void)
{
return( NULL );
}
//---------------------------------------------------------
bool CSG_Parameter_Data::Assign(CSG_Parameter_Data *pSource)
{
if( pSource && Get_Type() == pSource->Get_Type() )
{
On_Assign(pSource);
return( true );
}
return( false );
}
void CSG_Parameter_Data::On_Assign(CSG_Parameter_Data *pSource)
{}
//---------------------------------------------------------
bool CSG_Parameter_Data::Serialize(CSG_File &Stream, bool bSave)
{
return( On_Serialize(Stream, bSave) );
}
bool CSG_Parameter_Data::On_Serialize(CSG_File &Stream, bool bSave)
{
return( true );
}
///////////////////////////////////////////////////////////
// //
// Node //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
CSG_Parameter_Node::CSG_Parameter_Node(CSG_Parameter *pOwner, long Constraint)
: CSG_Parameter_Data(pOwner, Constraint)
{}
CSG_Parameter_Node::~CSG_Parameter_Node(void)
{}
///////////////////////////////////////////////////////////
// //
// Bool //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
CSG_Parameter_Bool::CSG_Parameter_Bool(CSG_Parameter *pOwner, long Constraint)
: CSG_Parameter_Data(pOwner, Constraint)
{
m_Value = false;
}
CSG_Parameter_Bool::~CSG_Parameter_Bool(void)
{}
//---------------------------------------------------------
bool CSG_Parameter_Bool::Set_Value(int Value)
{
bool bValue = Value != 0 ? true : false;
if( m_Value != bValue )
{
m_Value = bValue;
return( true );
}
return( false );
}
bool CSG_Parameter_Bool::Set_Value(double Value)
{
return( Set_Value((int)Value) );
}
//---------------------------------------------------------
const SG_Char * CSG_Parameter_Bool::asString(void)
{
return( m_Value ? LNG("[VAL] yes") : LNG("[VAL] no") );
}
//---------------------------------------------------------
void CSG_Parameter_Bool::On_Assign(CSG_Parameter_Data *pSource)
{
m_Value = ((CSG_Parameter_Bool *)pSource)->m_Value;
}
//---------------------------------------------------------
bool CSG_Parameter_Bool::On_Serialize(CSG_File &Stream, bool bSave)
{
int i;
if( bSave )
{
i = m_Value;
Stream.Printf(SG_T("%d\n"), i);
}
else
{
SG_FILE_SCANF(Stream.Get_Stream(), SG_T("%d"), &i);
m_Value = i != 0;
}
return( true );
}
///////////////////////////////////////////////////////////
// //
// Value //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
CSG_Parameter_Value::CSG_Parameter_Value(CSG_Parameter *pOwner, long Constraint)
: CSG_Parameter_Data(pOwner, Constraint)
{
m_Minimum = 0.0;
m_bMinimum = false;
m_Maximum = 0.0;
m_bMaximum = false;
}
CSG_Parameter_Value::~CSG_Parameter_Value(void)
{}
//---------------------------------------------------------
bool CSG_Parameter_Value::Set_Range(double Minimum, double Maximum)
{
if( 1 )
{
m_Minimum = Minimum;
m_Maximum = Maximum;
switch( Get_Type() )
{
default:
return( false );
case PARAMETER_TYPE_Int:
Set_Value(asInt());
break;
case PARAMETER_TYPE_Double:
case PARAMETER_TYPE_Degree:
Set_Value(asDouble());
break;
}
return( true );
}
return( false );
}
//---------------------------------------------------------
void CSG_Parameter_Value::Set_Minimum(double Minimum, bool bOn)
{
if( bOn == false || (m_bMaximum && Minimum >= m_Maximum) )
{
m_bMinimum = false;
}
else
{
m_bMinimum = true;
Set_Range(Minimum, m_Maximum);
}
}
void CSG_Parameter_Value::Set_Maximum(double Maximum, bool bOn)
{
if( bOn == false || (m_bMaximum && Maximum <= m_Minimum) )
{
m_bMaximum = false;
}
else
{
m_bMaximum = true;
Set_Range(m_Minimum, Maximum);
}
}
//---------------------------------------------------------
void CSG_Parameter_Value::On_Assign(CSG_Parameter_Data *pSource)
{
m_Minimum = ((CSG_Parameter_Value *)pSource)->m_Minimum;
m_bMinimum = ((CSG_Parameter_Value *)pSource)->m_bMinimum;
m_Maximum = ((CSG_Parameter_Value *)pSource)->m_Maximum;
m_bMaximum = ((CSG_Parameter_Value *)pSource)->m_bMaximum;
}
///////////////////////////////////////////////////////////
// //
// Int //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
CSG_Parameter_Int::CSG_Parameter_Int(CSG_Parameter *pOwner, long Constraint)
: CSG_Parameter_Value(pOwner, Constraint)
{
m_Value = 0;
}
CSG_Parameter_Int::~CSG_Parameter_Int(void)
{}
//---------------------------------------------------------
bool CSG_Parameter_Int::Set_Value(int Value)
{
if( m_bMinimum && Value < m_Minimum )
{
return( Set_Value((int)m_Minimum) );
}
if( m_bMaximum && Value > m_Maximum )
{
return( Set_Value((int)m_Maximum) );
}
if( m_Value != Value )
{
m_Value = Value;
return( true );
}
return( false );
}
bool CSG_Parameter_Int::Set_Value(double Value)
{
return( Set_Value((int)Value) );
}
bool CSG_Parameter_Int::Set_Value(void *Value)
{
int val;
if( Value )
{
m_String.Printf((SG_Char *)Value);
if( m_String.asInt(val) )
{
return( Set_Value(val) );
}
}
return( false );
}
//---------------------------------------------------------
const SG_Char * CSG_Parameter_Int::asString(void)
{
m_String.Printf(SG_T("%d"), m_Value);
return( m_String );
}
//---------------------------------------------------------
void CSG_Parameter_Int::On_Assign(CSG_Parameter_Data *pSource)
{
CSG_Parameter_Value::On_Assign(pSource);
Set_Value(((CSG_Parameter_Value *)pSource)->asInt());
}
//---------------------------------------------------------
bool CSG_Parameter_Int::On_Serialize(CSG_File &Stream, bool bSave)
{
if( bSave )
{
Stream.Printf(SG_T("%d\n"), m_Value);
}
else
{
SG_FILE_SCANF(Stream.Get_Stream(), SG_T("%d"), &m_Value);
Set_Value(m_Value);
}
return( true );
}
///////////////////////////////////////////////////////////
// //
// Double //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
CSG_Parameter_Double::CSG_Parameter_Double(CSG_Parameter *pOwner, long Constraint)
: CSG_Parameter_Value(pOwner, Constraint)
{
m_Value = 0.0;
}
CSG_Parameter_Double::~CSG_Parameter_Double(void)
{}
//---------------------------------------------------------
bool CSG_Parameter_Double::Set_Value(int Value)
{
return( Set_Value((double)Value) );
}
bool CSG_Parameter_Double::Set_Value(double Value)
{
if( m_bMinimum && Value < m_Minimum )
{
return( Set_Value(m_Minimum) );
}
if( m_bMaximum && Value > m_Maximum )
{
return( Set_Value(m_Maximum) );
}
if( m_Value != Value )
{
m_Value = Value;
return( true );
}
return( false );
}
bool CSG_Parameter_Double::Set_Value(void *Value)
{
double val;
if( Value )
{
m_String.Printf((SG_Char *)Value);
if( m_String.asDouble(val) )
{
return( Set_Value(val) );
}
}
return( false );
}
//---------------------------------------------------------
const SG_Char * CSG_Parameter_Double::asString(void)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -