📄 parameter_data.cpp
字号:
m_String.Printf(SG_T("%lf"), m_Value);
return( m_String );
}
//---------------------------------------------------------
void CSG_Parameter_Double::On_Assign(CSG_Parameter_Data *pSource)
{
CSG_Parameter_Value::On_Assign(pSource);
Set_Value(((CSG_Parameter_Value *)pSource)->asDouble());
}
//---------------------------------------------------------
bool CSG_Parameter_Double::On_Serialize(CSG_File &Stream, bool bSave)
{
if( bSave )
{
Stream.Printf(SG_T("%lf\n"), m_Value);
}
else
{
SG_FILE_SCANF(Stream.Get_Stream(), SG_T("%lf"), &m_Value);
Set_Value(m_Value);
}
return( true );
}
///////////////////////////////////////////////////////////
// //
// Degree //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
CSG_Parameter_Degree::CSG_Parameter_Degree(CSG_Parameter *pOwner, long Constraint)
: CSG_Parameter_Double(pOwner, Constraint)
{}
CSG_Parameter_Degree::~CSG_Parameter_Degree(void)
{}
//---------------------------------------------------------
bool CSG_Parameter_Degree::Set_Value(void *Value)
{
return( CSG_Parameter_Double::Set_Value(SG_Degree_To_Double((const SG_Char *)Value)) );
}
//---------------------------------------------------------
const SG_Char * CSG_Parameter_Degree::asString(void)
{
m_String = SG_Double_To_Degree(asDouble());
return( m_String );
}
///////////////////////////////////////////////////////////
// //
// Range //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
CSG_Parameter_Range::CSG_Parameter_Range(CSG_Parameter *pOwner, long Constraint)
: CSG_Parameter_Data(pOwner, Constraint)
{
pRange = new CSG_Parameters;
if( (m_Constraint & PARAMETER_INFORMATION) != 0 )
{
pLo = pRange->Add_Info_Value(m_pOwner, SG_T("MIN"), SG_T("Minimum"), m_pOwner->Get_Description(), PARAMETER_TYPE_Double);
pHi = pRange->Add_Info_Value(m_pOwner, SG_T("MAX"), SG_T("Maximum"), m_pOwner->Get_Description(), PARAMETER_TYPE_Double);
}
else
{
pLo = pRange->Add_Value (m_pOwner, SG_T("MIN"), SG_T("Minimum"), m_pOwner->Get_Description(), PARAMETER_TYPE_Double);
pHi = pRange->Add_Value (m_pOwner, SG_T("MAX"), SG_T("Maximum"), m_pOwner->Get_Description(), PARAMETER_TYPE_Double);
}
}
CSG_Parameter_Range::~CSG_Parameter_Range(void)
{
delete(pRange);
}
//---------------------------------------------------------
const SG_Char * CSG_Parameter_Range::asString(void)
{
m_String.Printf(SG_T("[%lf] - [%lf]"),
Get_LoParm()->asDouble(),
Get_HiParm()->asDouble()
);
return( m_String );
}
//---------------------------------------------------------
bool CSG_Parameter_Range::Set_Range(double loVal, double hiVal)
{
bool bResult;
if( loVal > hiVal )
{
bResult = pLo->Set_Value(hiVal);
bResult |= pHi->Set_Value(loVal);
}
else
{
bResult = pLo->Set_Value(loVal);
bResult |= pHi->Set_Value(hiVal);
}
return( bResult );
}
//---------------------------------------------------------
bool CSG_Parameter_Range::Set_LoVal(double newValue)
{
return( pLo->Set_Value(newValue) );
}
double CSG_Parameter_Range::Get_LoVal(void)
{
return( pLo->asDouble() );
}
//---------------------------------------------------------
bool CSG_Parameter_Range::Set_HiVal(double newValue)
{
return( pHi->Set_Value(newValue) );
}
double CSG_Parameter_Range::Get_HiVal(void)
{
return( pHi->asDouble() );
}
//---------------------------------------------------------
void CSG_Parameter_Range::On_Assign(CSG_Parameter_Data *pSource)
{
pLo->Assign(((CSG_Parameter_Range *)pSource)->pLo);
pHi->Assign(((CSG_Parameter_Range *)pSource)->pHi);
}
//---------------------------------------------------------
bool CSG_Parameter_Range::On_Serialize(CSG_File &Stream, bool bSave)
{
double loVal, hiVal;
if( bSave )
{
Stream.Printf(SG_T("%lf %lf\n"), Get_LoVal(), Get_HiVal());
return( true );
}
else
{
SG_FILE_SCANF(Stream.Get_Stream(), SG_T("%lf %lf"), &loVal, &hiVal);
return( Set_Range(loVal, hiVal) );
}
}
///////////////////////////////////////////////////////////
// //
// Choice //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
CSG_Parameter_Choice::CSG_Parameter_Choice(CSG_Parameter *pOwner, long Constraint)
: CSG_Parameter_Int(pOwner, Constraint)
{
Items = NULL;
nItems = 0;
}
CSG_Parameter_Choice::~CSG_Parameter_Choice(void)
{
Del_Items();
}
//---------------------------------------------------------
const SG_Char * CSG_Parameter_Choice::asString(void)
{
if( m_Value >= 0 && m_Value < nItems )
{
return( Items[m_Value]->c_str() );
}
return( LNG("[VAL] [no choice available]") );
}
//---------------------------------------------------------
void CSG_Parameter_Choice::Del_Items(void)
{
int i;
if( nItems > 0 )
{
for(i=0; i<nItems; i++)
{
delete(Items[i]);
}
SG_Free(Items);
nItems = 0;
Items = NULL;
}
m_Value = 0;
}
//---------------------------------------------------------
void CSG_Parameter_Choice::Set_Items(const SG_Char *String)
{
const SG_Char *s;
int n;
CSG_String sItem;
Del_Items();
//-----------------------------------------------------
s = String;
while( s && *s > 0 )
{
sItem = s;
sItem = sItem.BeforeFirst('|');
n = sItem.Length();
Items = (CSG_String **)SG_Realloc(Items, (nItems + 1) * sizeof(CSG_String *));
Items[nItems] = new CSG_String(sItem);
nItems++;
s += n + 1;
}
//-----------------------------------------------------
if( nItems == 0 )
{
nItems = 1;
Items = (CSG_String **)SG_Malloc(nItems * sizeof(CSG_String *));
Items[0] = new CSG_String(LNG("[VAL] [not set]"));
}
Set_Minimum(0, true);
Set_Maximum(nItems - 1, true);
}
//---------------------------------------------------------
const SG_Char * CSG_Parameter_Choice::Get_Item(int Index)
{
if( Index >= 0 && Index < nItems )
{
return( Items[Index]->c_str() );
}
return( NULL );
}
//---------------------------------------------------------
void CSG_Parameter_Choice::On_Assign(CSG_Parameter_Data *pSource)
{
int i;
Del_Items();
if( ((CSG_Parameter_Choice *)pSource)->nItems > 0 )
{
nItems = ((CSG_Parameter_Choice *)pSource)->nItems;
Items = (CSG_String **)SG_Malloc(nItems * sizeof(CSG_String *));
for(i=0; i<nItems; i++)
{
Items[i] = new CSG_String(((CSG_Parameter_Choice *)pSource)->Items[i]->c_str());
}
}
CSG_Parameter_Int::On_Assign(pSource);
}
///////////////////////////////////////////////////////////
// //
// String //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
CSG_Parameter_String::CSG_Parameter_String(CSG_Parameter *pOwner, long Constraint)
: CSG_Parameter_Data(pOwner, Constraint)
{
bPassword = false;
}
CSG_Parameter_String::~CSG_Parameter_String(void)
{}
//---------------------------------------------------------
bool CSG_Parameter_String::is_Valid(void)
{
return( m_String.Length() > 0 );
}
//---------------------------------------------------------
bool CSG_Parameter_String::is_Password(void)
{
return( bPassword );
}
void CSG_Parameter_String::Set_Password(bool bOn)
{
bPassword = bOn;
}
//---------------------------------------------------------
bool CSG_Parameter_String::Set_Value(void *Value)
{
if( Value )
{
if( m_String.Cmp((SG_Char *)Value) )
{
m_String.Printf((SG_Char *)Value);
return( true );
}
}
else if( m_String.Length() > 0 )
{
m_String.Clear();
return( true );
}
return( false );
}
//---------------------------------------------------------
const SG_Char * CSG_Parameter_String::asString(void)
{
return( m_String );
}
//---------------------------------------------------------
void CSG_Parameter_String::On_Assign(CSG_Parameter_Data *pSource)
{
m_String.Printf(((CSG_Parameter_String *)pSource)->m_String.c_str());
bPassword = ((CSG_Parameter_String *)pSource)->bPassword;
}
//---------------------------------------------------------
bool CSG_Parameter_String::On_Serialize(CSG_File &Stream, bool bSave)
{
if( bSave )
{
if( is_Valid() )
{
Stream.Printf(SG_T("%s\n"), m_String.c_str());
}
else
{
Stream.Printf(SG_T("\n"));
}
}
else
{
return( Stream.Read_Line(m_String) );
}
return( true );
}
///////////////////////////////////////////////////////////
// //
// Text //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
CSG_Parameter_Text::CSG_Parameter_Text(CSG_Parameter *pOwner, long Constraint)
: CSG_Parameter_String(pOwner, Constraint)
{}
CSG_Parameter_Text::~CSG_Parameter_Text(void)
{}
//---------------------------------------------------------
bool CSG_Parameter_Text::On_Serialize(CSG_File &Stream, bool bSave)
{
if( bSave )
{
if( is_Valid() )
{
Stream.Printf(SG_T("%s\n"), m_String.c_str());
}
Stream.Printf(SG_T("%s\n"), ENTRY_TEXT_END);
}
else
{
CSG_String sLine;
m_String.Clear();
while( Stream.Read_Line(sLine) && sLine.Cmp(ENTRY_TEXT_END) )
{
if( m_String.Length() > 0 )
{
m_String.Append(SG_T("\n"));
}
m_String.Append(sLine);
}
}
return( true );
}
///////////////////////////////////////////////////////////
// //
// FilePath //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
CSG_Parameter_File_Name::CSG_Parameter_File_Name(CSG_Parameter *pOwner, long Constraint)
: CSG_Parameter_String(pOwner, Constraint)
{
m_Filter = LNG("[FIL] All Files|*.*");
m_bSave = false;
m_bMultiple = false;
m_bDirectory = false;
}
CSG_Parameter_File_Name::~CSG_Parameter_File_Name(void)
{
}
//---------------------------------------------------------
void CSG_Parameter_File_Name::Set_Filter(const SG_Char *Filter)
{
if( Filter )
{
m_Filter = Filter;
}
else
{
m_Filter.Printf(LNG("[FIL] All Files|*.*"));
}
}
const SG_Char * CSG_Parameter_File_Name::Get_Filter(void)
{
return( m_Filter.c_str() );
}
//---------------------------------------------------------
void CSG_Parameter_File_Name::Set_Flag_Save(bool bFlag)
{
m_bSave = bFlag;
}
void CSG_Parameter_File_Name::Set_Flag_Multiple(bool bFlag)
{
m_bMultiple = bFlag;
}
void CSG_Parameter_File_Name::Set_Flag_Directory(bool bFlag)
{
m_bDirectory = bFlag;
}
//---------------------------------------------------------
bool CSG_Parameter_File_Name::Get_FilePaths(CSG_Strings &FilePaths)
{
FilePaths.Clear();
if( m_String.Length() > 0 )
{
if( m_String[0] != '\"' )
{
FilePaths.Add(m_String);
}
else
{
CSG_String s(m_String), sTmp;
while( s.Length() > 2 )
{
sTmp = s.AfterFirst('\"');
s = sTmp;
FilePaths.Add(s.BeforeFirst('\"'));
}
}
}
return( FilePaths.Get_Count() > 0 );
}
//---------------------------------------------------------
void CSG_Parameter_File_Name::On_Assign(CSG_Parameter_Data *pSource)
{
CSG_Parameter_String::On_Assign(pSource);
Set_Filter(((CSG_Parameter_File_Name *)pSource)->m_Filter.c_str());
m_bSave = ((CSG_Parameter_File_Name *)pSource)->m_bSave;
m_bMultiple = ((CSG_Parameter_File_Name *)pSource)->m_bMultiple;
m_bDirectory = ((CSG_Parameter_File_Name *)pSource)->m_bDirectory;
}
///////////////////////////////////////////////////////////
// //
// Font //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
#include <wx/font.h>
//---------------------------------------------------------
CSG_Parameter_Font::CSG_Parameter_Font(CSG_Parameter *pOwner, long Constraint)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -