Click here to Skip to main content
15,885,278 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.
// PGLGraphDlg.cpp : implementation file
//

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

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

/////////////////////////////////////////////////////////////////////////////
// CPGLGraphDlg dialog
void CPGLGraphDlg::Serialize(CArchive &archive)
{
	ASSERT_VALID(m_pGraph);

	if (archive.IsStoring())
	{
		// the mouse stuff
		archive << m_iMouseMode;
	}
	else
	{
		// the mouse stuff
		archive >> m_iMouseMode;
		m_mouse=CPGLMouse();
	}

	// serializing the graph
	m_pGraph->Serialize(archive);

	// updating graph if loading...
	if (archive.IsLoading())
	{
		// updating viewport dimensions...
		CPGLView* pView=m_pGraph->GetView();
		// redimensionning window
		CRect rect;
		GetWindowRect(&rect);
		MoveWindow(rect.left,rect.top,pView->GetWidth(), pView->GetHeight());
		InvalidateRect(NULL,FALSE);
	}
}


CPGLGraphDlg::CPGLGraphDlg(CWnd* pParent /*=NULL*/, CPGLGraph* _pGraph)
	: CDialog(CPGLGraphDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPGLGraphDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_pGraph=_pGraph;
	m_iMouseMode=PGL_MODE_TOOLS_SELECTION;
}


CPGLGraphDlg::~CPGLGraphDlg()
{
    if (m_pGraph)
		delete m_pGraph;
}

void CPGLGraphDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPGLGraphDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPGLGraphDlg, CDialog)
	//{{AFX_MSG_MAP(CPGLGraphDlg)
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPGLGraphDlg message handlers

void CPGLGraphDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	if (m_pGraph)
		m_pGraph->Delete();
	
}

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