📄 parameters_control.cpp
字号:
///////////////////////////////////////////////////////////
// //
// SAGA //
// //
// System for Automated Geoscientific Analyses //
// //
// User Interface //
// //
// Program: SAGA //
// //
//-------------------------------------------------------//
// //
// Parameters_Control.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 "res_controls.h"
#include "helper.h"
#include "wksp_data_manager.h"
#include "parameters_control.h"
#include "parameters_properties.h"
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
IMPLEMENT_CLASS(CParameters_Control, wxPanel)
//---------------------------------------------------------
BEGIN_EVENT_TABLE(CParameters_Control, wxPanel)
EVT_SIZE (CParameters_Control::On_Size)
EVT_PG_CHANGED (ID_WND_PARM_PG_ACTIVE, CParameters_Control::On_PG_Changed)
EVT_PG_CHANGED (ID_WND_PARM_PG_DIALOG, CParameters_Control::On_PG_Changed)
END_EVENT_TABLE()
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
CParameters_Control::CParameters_Control(wxWindow *pParent, bool bDialog)
: wxPanel(pParent, -1, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxCLIP_CHILDREN)
{
#ifdef _SAGA_LINUX
m_pPG = new wxPropertyGrid(this, bDialog ? ID_WND_PARM_PG_DIALOG : ID_WND_PARM_PG_ACTIVE, wxDefaultPosition, wxDefaultSize,
wxPG_BOLD_MODIFIED
|wxPG_SPLITTER_AUTO_CENTER
// |wxPG_AUTO_SORT
// |wxPG_HIDE_MARGIN
// |wxPG_STATIC_SPLITTER
// |wxPG_HIDE_CATEGORIES
// |wxPG_LIMITED_EDITING
|wxTAB_TRAVERSAL
// |wxPG_TOOLBAR
|wxPG_DESCRIPTION
// |wxPG_COMPACTOR
);
#else
m_pPGM = new wxPropertyGridManager(this, bDialog ? ID_WND_PARM_PG_DIALOG : ID_WND_PARM_PG_ACTIVE, wxDefaultPosition, wxDefaultSize,
wxPG_BOLD_MODIFIED
|wxPG_SPLITTER_AUTO_CENTER
// |wxPG_AUTO_SORT
// |wxPG_HIDE_MARGIN
// |wxPG_STATIC_SPLITTER
// |wxPG_HIDE_CATEGORIES
// |wxPG_LIMITED_EDITING
|wxTAB_TRAVERSAL
// |wxPG_TOOLBAR
|wxPG_DESCRIPTION
// |wxPG_COMPACTOR
);
m_pPG = m_pPGM->GetGrid();
// m_pPGM->SetExtraStyle(wxPG_EX_HELP_AS_TOOLTIPS);
m_pPGM->SetDescBoxHeight(bDialog ? 100 : 50);
#endif
m_pParameters = new CSG_Parameters();
m_pOriginal = NULL;
Set_Parameters(NULL);
}
//---------------------------------------------------------
CParameters_Control::~CParameters_Control(void)
{
delete(m_pParameters);
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CParameters_Control::On_Size(wxSizeEvent &event)
{
#ifdef _SAGA_LINUX
m_pPG ->SetSize(wxRect(0, 0, GetSize().x, GetSize().y));
#else
m_pPGM->SetSize(wxRect(0, 0, GetSize().x, GetSize().y));
#endif
m_pPG->CenterSplitter(true);
}
//---------------------------------------------------------
void CParameters_Control::On_PG_Changed(wxPropertyGridEvent &event)
{
_Set_Parameter(event.GetPropertyName());
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool CParameters_Control::Save_Changes(bool bSilent)
{
if( m_pOriginal && m_bModified && (bSilent || DLG_Message_Confirm(LNG("[DLG] Save changes?"), wxString::Format(wxT("%s: %s"), LNG("[CAP] Parameters"), m_pParameters->Get_Name()))) )
{
m_pOriginal->Assign_Values(m_pParameters);
m_bModified = false;
m_pPG->ClearModifiedStatus();
return( true );
}
return( false );
}
//---------------------------------------------------------
bool CParameters_Control::Restore(void)
{
if( m_pOriginal && m_bModified )
{
Set_Parameters(m_pOriginal);
return( true );
}
return( false );
}
//---------------------------------------------------------
bool CParameters_Control::Load(void)
{
bool bResult = false;
CSG_File Stream;
wxString File_Path;
if( DLG_Open(File_Path, ID_DLG_PARAMETERS_OPEN) && Stream.Open( CSG_String( File_Path.mb_str() ), SG_FILE_R, true) )
{
if( m_pParameters->Serialize(Stream, false) )
{
// m_pPG->Freeze();
m_pPG->Clear();
_Add_Properties(m_pParameters);
// m_pPG->Thaw();
m_pPG->Refresh();
m_bModified = true;
bResult = true;
}
else
{
DLG_Message_Show(LNG("Parameters file could not be imported."), LNG("Load Parameters"));
}
}
return( bResult );
}
//---------------------------------------------------------
bool CParameters_Control::Save(void)
{
bool bResult = false;
CSG_File Stream;
wxString File_Path;
if( DLG_Save(File_Path, ID_DLG_PARAMETERS_SAVE) && Stream.Open( CSG_String( File_Path.mb_str() ), SG_FILE_W, true) )
{
if( m_pParameters->Serialize(Stream, true) )
{
bResult = true;
}
else
{
DLG_Message_Show(LNG("Parameters file could not be exported."), LNG("Save Parameters"));
}
}
return( bResult );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool CParameters_Control::Set_Parameters(CSG_Parameters *pParameters)
{
if( m_pParameters == pParameters )
{
_Update_Parameters();
return( true );
}
// m_pPG->Freeze();
m_pPG->Clear();
m_bModified = false;
//-----------------------------------------------------
if( (m_pOriginal = pParameters) != NULL )
{
m_pParameters->Assign(m_pOriginal);
m_pParameters->Set_Callback(true);
_Add_Properties(m_pParameters);
}
else
{
m_pPG->Append(wxPropertyCategory(LNG("[TXT] No parameters available."), wxPG_LABEL));
}
//-----------------------------------------------------
// m_pPG->Thaw();
m_pPG->Refresh();
return( true );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
#define CHECK_LIST_OUTPUT(p) if( p->is_Output() ) { pRoot = NULL; break; }
//---------------------------------------------------------
#define CHECK_DATA_NODE(pNode, Name, ID) if( !pNode )\
{\
pNode = wxPropertyCategory(Name, ID);\
if( !pData )\
m_pPG->Append(pData = wxPropertyCategory(LNG("[PRM] Data Objects"), wxT("_DATAOBJECT_DATAOBJECTS")));\
_Add_Property(pNode, pData);\
}\
pRoot = pNode;
//---------------------------------------------------------
void CParameters_Control::_Add_Properties(CSG_Parameters *pParameters)
{
wxPGProperty *pGrids, *pShapes, *pTables, *pTINs, *pOptions, *pData, *pRoot;
pData = NULL;
pGrids = NULL;
pShapes = NULL;
pTables = NULL;
pTINs = NULL;
pOptions = NULL;
for(int i=0; i<pParameters->Get_Count(); i++)
{
if( pParameters->Get_Parameter(i)->Get_Parent() == NULL )
{
switch( pParameters->Get_Parameter(i)->Get_Type() )
{
case PARAMETER_TYPE_DataObject_Output:
pRoot = NULL;
break;
case PARAMETER_TYPE_Grid_System:
if(1|| pParameters->Get_Parameter(i)->Get_Children_Count() > 0 )
{
CHECK_DATA_NODE( pGrids, LNG("[PRM] Grids"), wxT("_DATAOBJECT_GRIDS") );
}
else
{
pRoot = NULL;
}
break;
case PARAMETER_TYPE_Grid_List:
CHECK_LIST_OUTPUT(pParameters->Get_Parameter(i));
case PARAMETER_TYPE_Grid:
CHECK_DATA_NODE(pGrids , LNG("[PRM] Grids") , wxT("_DATAOBJECT_GRIDS"));
break;
case PARAMETER_TYPE_Table_List:
CHECK_LIST_OUTPUT(pParameters->Get_Parameter(i));
case PARAMETER_TYPE_Table:
CHECK_DATA_NODE(pTables , LNG("[PRM] Tables"), wxT("_DATAOBJECT_TABLES"));
break;
case PARAMETER_TYPE_Shapes_List:
CHECK_LIST_OUTPUT(pParameters->Get_Parameter(i));
case PARAMETER_TYPE_Shapes:
CHECK_DATA_NODE(pShapes , LNG("[PRM] Shapes"), wxT("_DATAOBJECT_SHAPES"));
break;
case PARAMETER_TYPE_TIN_List:
CHECK_LIST_OUTPUT(pParameters->Get_Parameter(i));
case PARAMETER_TYPE_TIN:
CHECK_DATA_NODE(pTINs , LNG("[PRM] TIN"), wxT("_DATAOBJECT_TINS"));
break;
default:
if( !pOptions )
{
pOptions = wxPropertyCategory(LNG("[PRM] Options"), wxT("_DATAOBJECT_OPTIONS"));
m_pPG->Append(pOptions);
}
pRoot = pOptions;
break;
}
if( pRoot )
{
_Add_Property(pParameters->Get_Parameter(i), pRoot);
}
}
}
}
//---------------------------------------------------------
wxPGProperty * CParameters_Control::_Add_Property(wxPGProperty *pProperty, wxPGProperty *pParent)
{
wxPGId Id;
if( pParent )
{
Id = m_pPG->Insert(pParent->GetId(), -1, pProperty);
}
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -