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

📄 view_table_diagram.cpp

📁 这是一个GPS相关的程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
				LNG("Bars"),
				LNG("Lines and Points"),
				LNG("Lines"),
				LNG("Points")
			), 1
		);

		m_pFont	= m_Parameters.Add_Font(
			pNode, "_DIAGRAM_FONT"		, LNG("[CAP] Font"),
			LNG("")
		)->asFont();

		m_Parameters.Add_Value(
			pNode, "_DIAGRAM_LEGEND"	, LNG("[CAP] Legend"),
			LNG(""),
			PARAMETER_TYPE_Bool, true
		);

		sFields_Num.Append(LNG("[CAP] [none]"));
		sFields_Num.Append(wxT("|"));

		m_Parameters.Add_Choice(
			pNode, "_DIAGRAM_XFIELD"	, LNG("[CAP] X Axis"),
			LNG(""),
			sFields_Num, m_pTable->Get_Field_Count() + 1
		);

		sFields_All.Append(LNG("[CAP] [none]"));
		sFields_All.Append(wxT("|"));

		m_Parameters.Add_Choice(
			pNode, "_DIAGRAM_LABEL"		, LNG("[CAP] X Label"),
			LNG(""),
			sFields_All, m_pTable->Get_Field_Count() + 1
		);

		_Set_Fields();
	}
}


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

//---------------------------------------------------------
void CVIEW_Table_Diagram::On_Parameters(wxCommandEvent &event)
{
	_DLG_Parameters();
}

//---------------------------------------------------------
bool CVIEW_Table_Diagram::_DLG_Parameters(void)
{
	if( DLG_Parameters(&m_Parameters) )
	{
		return( _Set_Fields() );
	}

	return( false );
}


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

//---------------------------------------------------------
void CVIEW_Table_Diagram::Draw(wxDC &dc, wxRect rDraw)
{
	if( m_pFont )
	{
		dc.SetFont(*m_pFont);
	}

	_Draw_Diagram(dc, rDraw);
}

//---------------------------------------------------------
void CVIEW_Table_Diagram::_Draw_Diagram(wxDC &dc, wxRect rDC)
{
	if( m_nFields > 0 && m_zMax > m_zMin )
	{
		bool	bLegend	= m_Parameters("_DIAGRAM_LEGEND")->asBool();
		int		iField;
		double	dx, dy;
		wxRect	r;

		r	= bLegend
			? wxRect(	wxPoint(rDC.GetLeft()  +  80, rDC.GetTop()    + 10),
						wxPoint(rDC.GetRight() - 100, rDC.GetBottom() - 40))
			: wxRect(	wxPoint(rDC.GetLeft()  +  80, rDC.GetTop()    + 10),
						wxPoint(rDC.GetRight() -  10, rDC.GetBottom() - 40));

		dx	= m_xField < 0
			? (double)r.GetWidth()	/ (double)m_pTable->Get_Record_Count()
			: (double)r.GetWidth()	/ (m_xMax - m_xMin);
		dy	= (double)r.GetHeight()	/ (m_zMax - m_zMin);

		//-------------------------------------------------
		if( dx > 0.0 && dy > 0.0 )
		{
			_Draw_Frame(dc, r, dx, dy);

			for(iField=0; iField<m_nFields; iField++)
			{
				switch( m_Parameters("_DIAGRAM_TYPE")->asInt() )
				{
				default:
				case 0:	_Draw_Bars(dc, r, dx, dy, iField);					break;
				case 1:	_Draw_Line(dc, r, dx, dy, iField, true ,  true);	break;
				case 2:	_Draw_Line(dc, r, dx, dy, iField, true , false);	break;
				case 3:	_Draw_Line(dc, r, dx, dy, iField, false,  true);	break;
				}
			}

			if( bLegend )
			{
				r	= wxRect(	wxPoint(r  .GetRight(), rDC.GetTop()),
								wxPoint(rDC.GetRight(), rDC.GetBottom()));

				_Draw_Legend(dc, r);
			}
		}
		else
		{
			Draw_Text(dc, TEXTALIGN_CENTER, rDC.GetLeft() + rDC.GetWidth() / 2, rDC.GetTop() + rDC.GetHeight() / 2,
				LNG("[ERR] Invalid display size!")
			);
		}
	}
	else
	{
		Draw_Text(dc, TEXTALIGN_CENTER, rDC.GetLeft() + rDC.GetWidth() / 2, rDC.GetTop() + rDC.GetHeight() / 2,
			LNG("[ERR] Invalid data set!")
		);
	}
}

//---------------------------------------------------------
void CVIEW_Table_Diagram::_Draw_Frame(wxDC &dc, wxRect r, double dx, double dy)
{
	const int	dyFont		= 12,
				Precision	= 3;

	int			ix, iRecord, iStep, nSteps, iLabel;
	double		z, dz, dzStep;
	wxFont		Font;
	wxString	sLabel;

	//-----------------------------------------------------
	Draw_Edge(dc, EDGE_STYLE_SIMPLE, r);

	//-----------------------------------------------------
	Font	= dc.GetFont();
	Font.SetPointSize((int)(0.7 * dyFont));
	dc.SetFont(Font);

	if( m_xField < 0 )
	{
		iLabel	= m_Parameters("_DIAGRAM_LABEL")->asInt();	if( iLabel >= m_pTable->Get_Field_Count() )	iLabel	= -1;
		iStep	= dx > dyFont ? 1 : (int)(1 + (dyFont + 5) / dx);

		for(iRecord=0; iRecord<m_pTable->Get_Record_Count(); iRecord+=iStep)
		{
			ix	= r.GetLeft() + (int)(dx * iRecord);

			dc.DrawLine(ix, r.GetBottom(), ix, r.GetBottom() + 5);

			if( iLabel >= 0 )
			{
				sLabel.Printf(m_pTable->Get_Record_byIndex(iRecord)->asString(iLabel));
			}
			else
			{
				sLabel.Printf(wxT("%d"), iRecord);
			}

			Draw_Text(dc, TEXTALIGN_CENTERRIGHT, ix, r.GetBottom() + 7, 45.0, sLabel);
		}
	}
	else
	{
		nSteps		= r.GetWidth()			/ (dyFont + 5);
		dzStep		= (double)r.GetWidth()	/ nSteps;
		dz			= (m_xMax - m_xMin)		/ nSteps;

		for(iStep=0, z=m_xMin; iStep<=nSteps; iStep++, z+=dz)
		{
			ix		= r.GetLeft()	+ (int)(dzStep * iStep);

			dc.DrawLine(ix, r.GetBottom(), ix, r.GetBottom() + 5);

			sLabel.Printf(wxT("%.*f"), Precision, z);

			Draw_Text(dc, TEXTALIGN_CENTERRIGHT, ix, r.GetBottom() + 7, 45.0, sLabel);
		}
	}

	//-----------------------------------------------------
	nSteps		= r.GetHeight()			/ (dyFont + 5);
	dzStep		= (double)r.GetHeight()	/ nSteps;
	dz			= (m_zMax - m_zMin)		/ nSteps;

	for(iStep=0, z=m_zMin; iStep<=nSteps; iStep++, z+=dz)
	{
		ix		= r.GetBottom()	- (int)(dzStep * iStep);

		dc.DrawLine(r.GetLeft(), ix, r.GetLeft() - 5, ix);

		Draw_Text(dc, TEXTALIGN_TOPRIGHT, r.GetLeft() - 7, ix - dyFont / 2, wxString::Format(wxT("%.*f"), Precision, z));
	}
}

//---------------------------------------------------------
void CVIEW_Table_Diagram::_Draw_Legend(wxDC &dc, wxRect r)
{
	const int	dyFont	= 12,
				dyBox	= dyFont + 4;

	int		iField;
	wxRect	rBox;
	wxBrush	Brush;
	wxFont	Font;

	//-----------------------------------------------------
	iField	= r.GetTop() + (r.GetHeight() / 2);
	r		= wxRect(
				wxPoint(r.GetLeft() + 5, iField - (m_nFields * dyBox) / 2),
				wxPoint(r.GetRight()   , iField + (m_nFields * dyBox) / 2)
			);

	rBox	= wxRect(r.GetLeft(), r.GetTop(), 20, dyBox);

	Font	= dc.GetFont();
	Font.SetPointSize(dyFont);
	dc.SetFont(Font);

	//-----------------------------------------------------
	for(iField=0; iField<m_nFields; iField++)
	{
		rBox.SetY(r.GetTop() + iField * dyBox);

		Brush	= dc.GetBrush();
		Brush.SetColour(Get_Color_asWX(m_Colors.Get_Color(m_Fields[iField])));
		dc.SetBrush(Brush);
		dc.DrawRectangle(rBox.GetX(), rBox.GetY(), rBox.GetWidth(), rBox.GetHeight());

		dc.DrawText(m_pTable->Get_Field_Name(m_Fields[iField]), rBox.GetRight() + 5, rBox.GetTop());
	}
}


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

//---------------------------------------------------------
void CVIEW_Table_Diagram::_Draw_Line(wxDC &dc, wxRect r, double dx, double dy, int iField, bool bLine, bool bPoint)
{
	int		iRecord, ix, iy, jx, jy;
	wxPen	Pen;
	wxBrush	Brush;

	iField	= m_Fields[iField];

	Pen		= wxPen  (Get_Color_asWX(m_Colors.Get_Color(iField)), 0, wxSOLID);
	dc.SetPen(Pen);

	Brush	= wxBrush(Get_Color_asWX(m_Colors.Get_Color(iField)), wxSOLID);
	dc.SetBrush(Brush);

	if( bLine && m_pTable->Get_Record_Count() > 1 )
	{
		ix	= m_xField < 0
			? r.GetLeft()	+ 0
			: r.GetLeft()	+ (int)(dx * (m_pTable->Get_Record_byIndex(0)->asDouble(m_xField) - m_xMin));
		iy	= r.GetBottom()	- (int)(dy * (m_pTable->Get_Record_byIndex(0)->asDouble(  iField) - m_zMin));

		for(iRecord=1; iRecord<m_pTable->Get_Record_Count(); iRecord++)
		{
			jx	= ix;
			jy	= iy;
			ix	= m_xField < 0
				? r.GetLeft()	+ (int)(dx * iRecord)
				: r.GetLeft()	+ (int)(dx * (m_pTable->Get_Record_byIndex(iRecord)->asDouble(m_xField) - m_xMin));
			iy	= r.GetBottom()	- (int)(dy * (m_pTable->Get_Record_byIndex(iRecord)->asDouble(  iField) - m_zMin));

			dc.DrawLine(jx, jy, ix, iy);
		}
	}

	if( bPoint )
	{
		for(iRecord=0; iRecord<m_pTable->Get_Record_Count(); iRecord++)
		{
			ix	= m_xField < 0
				? r.GetLeft()	+ (int)(dx * iRecord)
				: r.GetLeft()	+ (int)(dx * (m_pTable->Get_Record_byIndex(iRecord)->asDouble(m_xField) - m_xMin));
			iy	= r.GetBottom()	- (int)(dy * (m_pTable->Get_Record_byIndex(iRecord)->asDouble(  iField) - m_zMin));

			dc.DrawCircle(ix, iy, 2);
		}
	}
}

//---------------------------------------------------------
void CVIEW_Table_Diagram::_Draw_Bars(wxDC &dc, wxRect r, double dx, double dy, int iField)
{
	int		iRecord, x, y, xa, xb, dxa, dxb;
	wxPen	Pen;

	dxb		= (int)(dx / m_nFields);
	dxa		= (int)(dx / m_nFields * iField);

	iField	= m_Fields[iField];

	Pen		= wxPen  (Get_Color_asWX(m_Colors.Get_Color(iField)), 0, wxSOLID);
	dc.SetPen(Pen);

	for(iRecord=0; iRecord<m_pTable->Get_Record_Count(); iRecord++)
	{
		xa	= dxa + r.GetLeft() + (int)(dx * iRecord);
		xb	= dxb + xa;

		y	= r.GetBottom()	- (int)(dy * (m_pTable->Get_Record_byIndex(iRecord)->asDouble(iField) - m_zMin));

		for(x=xa; x<=xb; x++)
		{
			dc.DrawLine(x, r.GetBottom(), x, y);
		}
	}
}


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

//---------------------------------------------------------

⌨️ 快捷键说明

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