📄 parameters_properties.cpp
字号:
///////////////////////////////////////////////////////////
// //
// SAGA //
// //
// System for Automated Geoscientific Analyses //
// //
// User Interface //
// //
// Program: SAGA //
// //
//-------------------------------------------------------//
// //
// Parameters_Properties.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 <saga_api/saga_api.h>
#include "res_dialogs.h"
#include "helper.h"
#include "dc_helper.h"
#include "wksp_data_manager.h"
#include "wksp_grid_manager.h"
#include "wksp_grid_system.h"
#include "wksp_grid.h"
#include "wksp_table_manager.h"
#include "wksp_table.h"
#include "wksp_shapes_manager.h"
#include "wksp_shapes_type.h"
#include "wksp_shapes.h"
#include "wksp_tin_manager.h"
#include "wksp_tin.h"
#include "parameters_properties.h"
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
#define GET_DATAOBJECT_LABEL(p) (p->is_Option() ? wxString::Format(p->Get_Name()) : wxString::Format(wxT("%s %s"), p->is_Input() ? (p->is_Optional() ? wxT(">") : wxT(">>")) : (p->is_Optional() ? wxT("<") : wxT("<<")), p->Get_Name()))
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
CParameters_PG_Choice::CParameters_PG_Choice(CSG_Parameter *pParameter)
: wxEnumPropertyClass(GET_DATAOBJECT_LABEL(pParameter), pParameter->Get_Identifier(), NULL)
{
m_pParameter = pParameter;
_Create();
}
//---------------------------------------------------------
CParameters_PG_Choice::~CParameters_PG_Choice(void)
{
_Destroy();
}
//---------------------------------------------------------
void CParameters_PG_Choice::_Create(void)
{
_Destroy();
if( m_pParameter )
{
switch( m_pParameter->Get_Type() )
{
default: m_index = 0; break;
case PARAMETER_TYPE_Choice: m_index = _Set_Choice(); break;
case PARAMETER_TYPE_Grid_System: m_index = _Set_Grid_System(); break;
case PARAMETER_TYPE_Table_Field: m_index = _Set_Table_Field(); break;
case PARAMETER_TYPE_Grid: m_index = _Set_Grid(); break;
case PARAMETER_TYPE_Table: m_index = _Set_Table(); break;
case PARAMETER_TYPE_Shapes: m_index = _Set_Shapes(); break;
case PARAMETER_TYPE_TIN: m_index = _Set_TIN(); break;
}
}
}
//---------------------------------------------------------
void CParameters_PG_Choice::_Destroy(void)
{
wxPGChoices choices;
m_choices.Assign(choices);
m_index = 0;
}
//---------------------------------------------------------
const wxChar * CParameters_PG_Choice::GetClassName(void) const
{
return( wxT("CParameters_PG_Choice") );
}
//---------------------------------------------------------
void CParameters_PG_Choice::_Append(const wxChar *Label, long Value)
{
m_choices.Add(Label, Value);
}
void CParameters_PG_Choice::_Append(const wxChar *Label, void *Value)
{
_Append(Label, (long)Value);
}
void CParameters_PG_Choice::_Append(const wxChar *Label)
{
m_choices.Add(Label);
}
//---------------------------------------------------------
bool CParameters_PG_Choice::Update(void)
{
_Create();
return( true );
}
//---------------------------------------------------------
int CParameters_PG_Choice::_Set_Choice(void)
{
for(int i=0; i<m_pParameter->asChoice()->Get_Count(); i++)
{
_Append(m_pParameter->asChoice()->Get_Item(i), i);
}
return( m_pParameter->asInt() );
}
//---------------------------------------------------------
int CParameters_PG_Choice::_Set_Table_Field(void)
{
CSG_Parameter *pParent;
CSG_Table *pTable;
if( (pParent = m_pParameter->Get_Parent()) != NULL)
{
switch( pParent->Get_Type() )
{
default: pTable = NULL; break;
case PARAMETER_TYPE_Table: pTable = pParent->asTable(); break;
case PARAMETER_TYPE_Shapes: pTable = pParent->asShapes() ? &pParent->asShapes()->Get_Table() : NULL; break;
case PARAMETER_TYPE_TIN: pTable = pParent->asTIN() ? &pParent->asTIN() ->Get_Table() : NULL; break;
}
if( pTable )
{
for(int i=0; i<pTable->Get_Field_Count(); i++)
{
_Append(pTable->Get_Field_Name(i));
}
if( m_pParameter->is_Optional() || pTable->Get_Field_Count() == 0 )
{
_Append( LNG("[VAL] [not set]") );
}
return( m_pParameter->asInt() >= 0 ? m_pParameter->asInt() : m_choices.GetCount() - 1);
}
}
_Append( LNG("[VAL] [not set]") );
return( m_choices.GetCount() - 1 );
}
//---------------------------------------------------------
int CParameters_PG_Choice::_Set_Table(void)
{
CWKSP_Table_Manager *pTables;
if( (pTables = g_pData->Get_Tables()) != NULL )
{
for(int i=0; i<pTables->Get_Count(); i++)
{
_Append(pTables->Get_Table(i)->Get_Name(), pTables->Get_Table(i)->Get_Table());
}
}
return( _DataObject_Init() );
}
//---------------------------------------------------------
int CParameters_PG_Choice::_Set_Shapes(void)
{
int i, j, Shape_Type;
CWKSP_Shapes_Manager *pManager;
CWKSP_Shapes_Type *pShapes;
if( (pManager = g_pData->Get_Shapes()) != NULL )
{
Shape_Type = ((CSG_Parameter_Shapes *)m_pParameter->Get_Data())->Get_Shape_Type();
for(i=0; i<pManager->Get_Count(); i++)
{
pShapes = (CWKSP_Shapes_Type *)pManager->Get_Item(i);
if( Shape_Type == SHAPE_TYPE_Undefined || Shape_Type == pShapes->Get_Shapes_Type() )
{
for(j=0; j<pShapes->Get_Count(); j++)
{
_Append(pShapes->Get_Shapes(j)->Get_Name(), pShapes->Get_Shapes(j)->Get_Shapes());
}
}
}
}
return( _DataObject_Init() );
}
//---------------------------------------------------------
int CParameters_PG_Choice::_Set_TIN(void)
{
CWKSP_TIN_Manager *pTINs;
if( (pTINs = g_pData->Get_TINs()) != NULL )
{
for(int i=0; i<pTINs->Get_Count(); i++)
{
_Append(pTINs->Get_TIN(i)->Get_Name(), pTINs->Get_TIN(i)->Get_TIN());
}
}
return( _DataObject_Init() );
}
//---------------------------------------------------------
int CParameters_PG_Choice::_Set_Grid_System(void)
{
int i;
CWKSP_Grid_Manager *pSystems;
if( (pSystems = g_pData->Get_Grids()) != NULL )
{
if( pSystems->Get_Count() > 0 )
{
for(i=0; i<pSystems->Get_Count(); i++)
{
_Append(pSystems->Get_System(i)->Get_Name(), pSystems->Get_System(i)->Get_System());
}
}
_Append( LNG("[VAL] [not set]"), (void *)NULL );
g_pData->Check_Parameter(m_pParameter);
for(i=0; i<(int)m_choices.GetCount()-1; i++)
{
if( m_pParameter->asGrid_System()->is_Equal(*((CSG_Grid_System *)m_choices.GetValue(i))) )
{
return( i );
}
}
return( m_choices.GetCount() - 1 );
}
_Append( LNG("[VAL] [no choice available]"), (void *)NULL );
return( m_choices.GetCount() - 1 );
}
//---------------------------------------------------------
int CParameters_PG_Choice::_Set_Grid(void)
{
int i;
CSG_Parameter *pParent;
CWKSP_Grid_Manager *pManager;
CWKSP_Grid_System *pSystem;
pSystem = NULL;
pManager = g_pData->Get_Grids();
pParent = m_pParameter->Get_Parent();
if( pManager && pParent && pParent->Get_Type() == PARAMETER_TYPE_Grid_System && pParent->asGrid_System()->is_Valid() )
{
for(i=0; i<pManager->Get_Count() && !pSystem; i++)
{
if( pParent->asGrid_System()->is_Equal(*pManager->Get_System(i)->Get_System()) )
{
pSystem = pManager->Get_System(i);
}
}
}
if( pSystem )
{
for(i=0; i<pSystem->Get_Count(); i++)
{
_Append(pSystem->Get_Grid(i)->Get_Name(), pSystem->Get_Grid(i)->Get_Grid());
}
}
return( _DataObject_Init() );
}
//---------------------------------------------------------
int CParameters_PG_Choice::_DataObject_Init(void)
{
if( m_pParameter->is_Output() )
{
_Append(LNG("[VAL] [create]"), DATAOBJECT_CREATE);
}
if( !m_pParameter->is_Output() || (m_pParameter->is_Output() && m_pParameter->is_Optional()) )
{
_Append(LNG("[VAL] [not set]"), DATAOBJECT_NOTSET);
}
g_pData->Check_Parameter(m_pParameter);
for(int i=0; i<(int)m_choices.GetCount(); i++)
{
if( m_pParameter->asDataObject() == (void *)m_choices.GetValue(i) )
{
return( i );
}
}
return( m_choices.GetCount() - 1 );
}
//---------------------------------------------------------
bool CParameters_PG_Choice::OnEvent(wxPropertyGrid *pPG, wxWindow *pPGCtrl, wxEvent &event)
{
if( event.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED )
{
if( m_pParameter && m_choices.IsOk() && m_index >= 0 && m_index < (int)m_choices.GetCount() )
{
switch( m_pParameter->Get_Type() )
{
default:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -