Click here to Skip to main content
15,886,067 members
Articles / Desktop Programming / MFC

Plot Graphic Library

Rate me:
Please Sign up or sign in to vote.
4.95/5 (70 votes)
7 May 2003LGPL36 min read 1.4M   51.3K   383  
A library to plot data (lines, maps...) in MFC projects
In this article, you will see a library called PGL that encapsulates plot capabilities in a MFC project for VC6 and VC7. It can easily plot data generated in a project without the need of any external software.
// PGLLineVer.cpp: implementation of the CPGLLineVer class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "PGL/pgl.h"
#include "PGL/PGLLineVer.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif



IMPLEMENT_SERIAL(CPGLLineVer, CPGLLine,1);

void CPGLLineVer::Serialize(CArchive &archive)
{
    // call base class function first
    // base class is CObject in this case
    CPGLLine::Serialize( archive );

    // now do the stuff for our specific class
    if( archive.IsStoring() )
	{
		archive>>m_dX;
	}
    else
	{
		archive>>m_dX;
	}
}

#ifdef _DEBUG
void CPGLLineVer::Dump( CDumpContext& dc ) const
{
    // call base class function first
    CPGLLine::Dump( dc );
}
void CPGLLineVer::AssertValid() const
{
    // call inherited AssertValid first
    CPGLLine::AssertValid();

} 
#endif


//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CPGLLineVer::CPGLLineVer()
: CPGLLine()
{
	m_dX = 0;
	m_tCaption.SetAngle(90);
}

CPGLLineVer::CPGLLineVer(const CPGLLineVer& lv)
: CPGLLine(lv)
{
	m_dX = lv.m_dX;
	m_tCaption = lv.m_tCaption;
}

CPGLLineVer& CPGLLineVer::operator =(const CPGLLineVer& lv)
{
	if (this != &lv)
	{
		this->CPGLLineVer::operator =(lv);
		m_dX = lv.m_dX;
	}
	return *this;
}

CPGLLineVer::~CPGLLineVer()
{
}

double* CPGLLineVer::GetExtent(CPGLView* pView)
{
	if (NeedUpdateExtent())
		UpdateExtent(pView);

	return CPGLLine::GetExtent(pView);
}

void CPGLLineVer::UpdateExtent(CPGLView* pView)
{
	// Calling base class function
	CPGLLine::UpdateExtent(pView);

	m_extent[0]=m_extent[1]=m_dX;
	m_extent[2]=m_extent[3]=0;
}


void CPGLLineVer::PlotGfx(gfxinterface::CGfxInterface& gfx)
{
	if (!IsVisible())
		return;

	// calling base class plot
	CPGLObject::PlotGfx(gfx);
	
	gfx.AddComment("--- CPGLLineVer ---");	

	// Sets dash...
	SetDashGfx(gfx);	
	// set line width
	gfx.SetLineWidth(GetLineWidth());	
	gfx.DrawLine(m_dX, gfx.GetWorldBottom(), m_dX, gfx.GetWorldTop());

	// setting caption position
	float pos[2];
	pos[0]=m_dX+gfx.BBToWorldAbsx(GetLineWidth()+5);
	pos[1]=gfx.GetWorldClipTop();
	pos[1]+=gfx.BBToWorldAbsy(5);
	m_tCaption.SetPosition(pos);
	m_tCaption.PlotGfx(gfx);
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Engineer
United States United States
Jonathan de Halleux is Civil Engineer in Applied Mathematics. He finished his PhD in 2004 in the rainy country of Belgium. After 2 years in the Common Language Runtime (i.e. .net), he is now working at Microsoft Research on Pex (http://research.microsoft.com/pex).

Comments and Discussions