⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 view_scatterplot.cpp

📁 这是一个GPS相关的程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:

///////////////////////////////////////////////////////////
//                                                       //
//                         SAGA                          //
//                                                       //
//      System for Automated Geoscientific Analyses      //
//                                                       //
//                    User Interface                     //
//                                                       //
//                    Program: SAGA                      //
//                                                       //
//-------------------------------------------------------//
//                                                       //
//                 VIEW_ScatterPlot.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 <wx/window.h>

#include <saga_api/saga_api.h>

#include "res_commands.h"
#include "res_controls.h"
#include "res_images.h"
#include "res_dialogs.h"

#include "helper.h"
#include "dc_helper.h"

#include "wksp.h"
#include "wksp_data_manager.h"

#include "wksp_grid.h"
#include "wksp_shapes.h"

#include "view_scatterplot.h"


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
void		Add_ScatterPlot(CSG_Grid *pGrid)
{
	CSG_Parameter	*pNode;
	CSG_Grid		*pGrid_Y;
	CSG_Shapes		*pShapes;

	//-----------------------------------------------------
	CSG_Parameters	Parameters(NULL, wxString::Format(wxT("%s: %s"), LNG("[CAP] Scatterplot"), pGrid->Get_Name()), LNG(""), NULL, true);

	Parameters.Add_Grid(
		NULL	, "GRID"	, LNG("[CAP] Grid")		, LNG(""),
		PARAMETER_INPUT_OPTIONAL
	);

	pNode	= Parameters.Add_Shapes(
		NULL	, "SHAPES"	, LNG("[CAP] Shapes")	, LNG(""),
		PARAMETER_INPUT_OPTIONAL
	);

	Parameters.Add_Table_Field(
		pNode	, "FIELD"	, LNG("[CAP] Attribute"), LNG("")
	);

	//-----------------------------------------------------
	if( DLG_Parameters(&Parameters) )
	{
		if( (pGrid_Y = Parameters("GRID")->asGrid()) != NULL )
		{
			new CVIEW_ScatterPlot(pGrid, pGrid_Y);
		}
		else if( (pShapes = Parameters("SHAPES")->asShapes()) != NULL )
		{
			new CVIEW_ScatterPlot(pGrid, pShapes, Parameters("FIELD")->asInt());
		}
	}
}

//---------------------------------------------------------
void		Add_ScatterPlot(CSG_Table *pTable)
{
	int			i;
	wxString	sChoices;

	CSG_Parameters	Parameters(NULL, wxString::Format(wxT("%s: %s"), LNG("[CAP] Scatterplot"), pTable->Get_Name()), LNG(""));

	for(i=0; i<pTable->Get_Field_Count(); i++)
	{
		sChoices.Append(wxString::Format(wxT("%s|"), pTable->Get_Field_Name(i)));
	}

	Parameters.Add_Choice(
		NULL, "FIELD_A", wxT("X"), wxT(""), sChoices
	);

	Parameters.Add_Choice(
		NULL, "FIELD_B", wxT("Y"), wxT(""), sChoices
	);

	if( DLG_Parameters(&Parameters) )
	{
		new CVIEW_ScatterPlot(pTable, Parameters("FIELD_A")->asInt(), Parameters("FIELD_B")->asInt());
	}
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
IMPLEMENT_CLASS(CVIEW_ScatterPlot, CVIEW_Base);

//---------------------------------------------------------
BEGIN_EVENT_TABLE(CVIEW_ScatterPlot, CVIEW_Base)
	EVT_PAINT			(CVIEW_ScatterPlot::On_Paint)
	EVT_SIZE			(CVIEW_ScatterPlot::On_Size)

	EVT_MENU			(ID_CMD_SCATTERPLOT_PARAMETERS	, CVIEW_ScatterPlot::On_Parameters)
	EVT_MENU			(ID_CMD_SCATTERPLOT_UPDATE		, CVIEW_ScatterPlot::On_Update)
END_EVENT_TABLE()


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
CVIEW_ScatterPlot::CVIEW_ScatterPlot(CSG_Grid *pGrid_X, CSG_Grid *pGrid_Y)
	: CVIEW_Base(ID_VIEW_SCATTERPLOT, LNG("[CAP] Scatterplot"), ID_IMG_WND_SCATTERPLOT, CVIEW_ScatterPlot::_Create_Menu(), LNG("[CAP] Scatterplot"))
{
	_On_Construction();

	m_Method	= 0;
	m_pGrid_X	= pGrid_X;
	m_pGrid_Y	= pGrid_Y;

	_Initialize_Grids(pGrid_X, pGrid_Y);
}

//---------------------------------------------------------
CVIEW_ScatterPlot::CVIEW_ScatterPlot(CSG_Grid *pGrid_X, CSG_Shapes *pShapes_Y, int Field)
	: CVIEW_Base(ID_VIEW_SCATTERPLOT, LNG("[CAP] Scatterplot"), ID_IMG_WND_SCATTERPLOT, CVIEW_ScatterPlot::_Create_Menu(), LNG("[CAP] Scatterplot"))
{
	_On_Construction();

	m_Method	= 1;
	m_pGrid_X	= pGrid_X;
	m_pShapes	= pShapes_Y;
	m_xField	= Field;

	_Initialize_Shapes(pGrid_X, pShapes_Y, Field);
}

//---------------------------------------------------------
CVIEW_ScatterPlot::CVIEW_ScatterPlot(CSG_Table *pTable, int Field_X, int Field_Y)
	: CVIEW_Base(ID_VIEW_SCATTERPLOT, LNG("[CAP] Scatterplot"), ID_IMG_WND_SCATTERPLOT, CVIEW_ScatterPlot::_Create_Menu(), LNG("[CAP] Scatterplot"))
{
	_On_Construction();

	m_Method	= 2;
	m_pTable	= pTable;
	m_xField	= Field_X;
	m_yField	= Field_Y;

	_Initialize_Table(pTable, Field_X, Field_Y);
}

//---------------------------------------------------------
CVIEW_ScatterPlot::~CVIEW_ScatterPlot(void)
{
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
wxMenu * CVIEW_ScatterPlot::_Create_Menu(void)
{
	wxMenu	*pMenu	= new wxMenu();

	CMD_Menu_Add_Item(pMenu, false, ID_CMD_SCATTERPLOT_PARAMETERS);
	CMD_Menu_Add_Item(pMenu, false, ID_CMD_SCATTERPLOT_UPDATE);

	return( pMenu );
}

//---------------------------------------------------------
wxToolBarBase * CVIEW_ScatterPlot::_Create_ToolBar(void)
{
	wxToolBarBase	*pToolBar	= CMD_ToolBar_Create(ID_TB_VIEW_SCATTERPLOT);

	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_SCATTERPLOT_PARAMETERS);
	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_SCATTERPLOT_UPDATE);

	CMD_ToolBar_Add(pToolBar, LNG("[CAP] Scatterplot"));

	return( pToolBar );
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
#define CHECK_DATA(d)	if( d != NULL && !g_pData->Exists(d) )	d	= NULL;

//---------------------------------------------------------
void CVIEW_ScatterPlot::Update_ScatterPlot(void)
{
	CHECK_DATA(m_pGrid_X);
	CHECK_DATA(m_pGrid_Y);
	CHECK_DATA(m_pShapes);
	CHECK_DATA(m_pTable);

	switch( m_Method )
	{
	case 0:	_Initialize_Grids	(m_pGrid_X, m_pGrid_Y);				break;
	case 1:	_Initialize_Shapes	(m_pGrid_X, m_pShapes, m_xField);	break;
	case 2:	_Initialize_Table	(m_pTable, m_xField, m_yField);		break;
	}

	Refresh();
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
void CVIEW_ScatterPlot::_On_Construction(void)
{
	m_Method	= -1;
	m_pGrid_X	= NULL;
	m_pGrid_Y	= NULL;
	m_pShapes	= NULL;
	m_pTable	= NULL;
	m_xField	= 0;
	m_yField	= 0;

	SYS_Set_Color_BG_Window(this);

	m_Parameters.Add_Choice(
		NULL, "TYPE"		, LNG("[CAP] Regression Formula"),
		LNG(""),
		wxT("Y = a + b * X|")
		wxT("Y = a + b / X|")
		wxT("Y = a / (b - X)|")
		wxT("Y = a * X^b|")
		wxT("Y = a e^(b * X)|")
		wxT("Y = a + b * ln(X)|")
	);

	m_Parameters.Add_String(
		NULL, "INFO"		, LNG("[CAP] Regression Details"),
		LNG(""),
		LNG(""), true
	);

	m_Parameters.Add_Font(
		NULL, "FONT"		, LNG("[CAP] Font"),
		LNG("")
	);

	m_Parameters.Add_Value(
		NULL, "REGRESSION"	, LNG("[CAP] Show Regression Curve"),
		LNG(""),
		PARAMETER_TYPE_Bool, true
	);

	m_Parameters.Add_Choice(
		NULL, "METHOD"		, LNG("[CAP] Display Type"),
		LNG(""),
		wxString::Format(wxT("%s|%s|"),
			LNG("[CAP] Circles"),
			LNG("[CAP] Points")
		)
	);

	m_Parameters.Add_Value(
		NULL, "RESOLUTION"	, LNG("[CAP] Display Resolution"),
		LNG(""),
		PARAMETER_TYPE_Int, 1, 1, true
	);

	m_Parameters.Add_Colors(
		NULL, "COLORS"		, LNG("[CAP] Colors"),
		LNG("")
	);
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
void CVIEW_ScatterPlot::On_Parameters(wxCommandEvent &event)
{
	if( DLG_Parameters(&m_Parameters) )
	{
		if( m_Parameters("TYPE")->asInt() != m_Regression.Get_Type() )
		{
			m_Regression.Calculate((TSG_Regression_Type)m_Parameters("TYPE")->asInt());
		}

		Refresh();
	}
}

//---------------------------------------------------------
void CVIEW_ScatterPlot::On_Update(wxCommandEvent &event)
{
	Update_ScatterPlot();
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
void CVIEW_ScatterPlot::On_Size(wxSizeEvent &event)
{
	Refresh();

	event.Skip();
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
void CVIEW_ScatterPlot::On_Paint(wxPaintEvent &event)
{
	wxPaintDC	dc(this);
	wxRect		r(wxPoint(0, 0), GetClientSize());

	Draw_Edge(dc, EDGE_STYLE_SUNKEN, r);

	Draw(dc, r);
}

//---------------------------------------------------------
void CVIEW_ScatterPlot::Draw(wxDC &dc, wxRect r)
{
	double	dx, dy;

	r	= _Draw_Get_rDiagram(r);

	dc.SetFont				(*m_Parameters("FONT")->asFont());
	dc.SetTextForeground	( m_Parameters("FONT")->asColor());

	if( m_Regression.Get_Count() > 1 )
	{
		dx	= (r.GetWidth()  - 1.0) / (m_Regression.Get_xMax() - m_Regression.Get_xMin());
		dy	= (r.GetHeight() - 1.0) / (m_Regression.Get_yMax() - m_Regression.Get_yMin());

		//-------------------------------------------------
		if( m_Parameters("METHOD")->asInt() == 1 )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -