#include "stdafx.h"
#include "testpgl.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
ON_COMMAND(ID_GRAPH_GENERATEGRAPH, OnGraphGenerategraph)
ON_COMMAND(ID_GRAPH_SHOW, OnGraphShow)
ON_COMMAND(ID_TEST_CHANGEMENU, OnTestChangemenu)
ON_COMMAND(ID_TEST_STARTANIMATION, OnTestStartanimation)
ON_COMMAND(ID_TEST_STOPANIMATION, OnTestStopanimation)
ON_COMMAND(ID_EXAMPLES_SIMPLELINE, OnExamplesSimpleline)
ON_COMMAND(ID_EXAMPLES_SIMPLELINEWITHLEVELOFDETAIL, OnExamplesSimplelinewithlevelofdetail)
ON_COMMAND(ID_EXAMPLES_CUSTOMIZINGTHEAXIS, OnExamplesCustomizingtheaxis)
ON_COMMAND(ID_EXAMPLES_SUBPLOTTING, OnExamplesSubplotting)
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR,
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
CMainFrame::CMainFrame()
{
CoInitialize(NULL);
}
CMainFrame::~CMainFrame()
{
CoUninitialize();
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1;
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1;
}
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
return TRUE;
}
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif
void CMainFrame::OnGraphGenerategraph()
{
CPGLGraph* pGraph = ((CTestpglApp*)AfxGetApp())->GenerateGraph();
pGraph->ZoomAll(TRUE);
((CPGLGraphView*)GetActiveView())->SetGraph(pGraph );
GetActiveView()->InvalidateRect(NULL,FALSE);
}
void CMainFrame::OnGraphShow()
{
CPGLGraph* pGraph = ((CTestpglApp*)AfxGetApp())->GenerateGraph();
pGraph->ZoomAll(TRUE);
CPGLGraphBitDlg graphdlg(this, pGraph);
graphdlg.DoModal();
}
void CMainFrame::OnTestChangemenu()
{
CPGLGraphView* pGraphView = (CPGLGraphView*)GetActiveView();
CMenu* pNewMenu = pGraphView->LoadMenu();
SetMenu(NULL);
::DestroyMenu(m_hMenuDefault);
SetMenu(pNewMenu);
m_hMenuDefault = pNewMenu->GetSafeHmenu();
}
void CMainFrame::OnTestStartanimation()
{
CPGLGraphView* pGraphView = (CPGLGraphView*)GetActiveView();
CPGLGraph* pGraph = pGraphView->GetGraph();
if (!pGraph)
return;
((CTestpglApp*)AfxGetApp())->SetIdleView(GetActiveView());
((CTestpglApp*)AfxGetApp())->SetAnimatedLine(pGraph);
InvalidateRect(NULL,FALSE);
}
void CMainFrame::OnTestStopanimation()
{
((CTestpglApp*)AfxGetApp())->SetIdleView(NULL);
((CTestpglApp*)AfxGetApp())->SetAnimatedLine(NULL);
InvalidateRect(NULL,FALSE);
}
void CMainFrame::GetExample1(CPGLRegion* pGraph)
{
ASSERT_VALID(pGraph);
int nPoints = 60;
double* pX=new double[nPoints];
double* pY=new double[nPoints];
for (UINT i=0;i<nPoints;i++)
{
pX[i]=i;
pY[i]=sin(i/(double)nPoints*2*3.14)*1.1;
}
CPGLLine2D* pLine = new CPGLLine2D();
pLine->SetDatas( nPoints , pX , pY );
pLine->SetLineWidth(2);
pGraph->AddObject(pLine);
}
void CMainFrame::GetExample2(CPGLRegion* pGraph)
{
ASSERT_VALID(pGraph);
GetExample1(pGraph);
int nPoints = 60;
double* pX=new double[nPoints];
double* pY=new double[nPoints];
for (UINT i=0;i<nPoints;i++)
{
pX[i]=i;
pY[i]=sin(i/(double)nPoints*2*3.14)*1.1;
}
CPGLLine2DLOD* pLineLOD = new CPGLLine2DLOD();
pLineLOD->SetDatas( nPoints , pX , pY );
pLineLOD->GetHull().ShrinkNorm(0.1,0.0);
pLineLOD->SetLineWidth(2);
pLineLOD->SetColor(0,0,1);
pLineLOD->SetPointType(PGL_POINT_SQUARE);
pLineLOD->SetPointWidth(4);
pGraph->AddObject(pLineLOD);
CString str;
str.Format("Approximated curve: %d points", pLineLOD->GetHull().GetKeySize());
pGraph->GetAxe()->SetTitle(str);
}
void CMainFrame::GetExample3(CPGLRegion* pGraph)
{
ASSERT_VALID(pGraph);
GetExample2(pGraph);
CPGLAxe2D* pAxis = pGraph->GetAxe();
CString str;
str.Format("A modified title");
pAxis->SetTitle(str);
pAxis->GetTitle()->SetColor(0,0.5f,0);
pAxis->SetShowGrid(1,FALSE);
pAxis->GetRightLabel()->Show();
pAxis->GetRightLabel()->SetString("This is the right label");
pAxis->GetRightNumber()->Show();
pAxis->SetTopSecondTicksNb(5);
pAxis->SetTimeLabel(TRUE);
pAxis->SetTimeLabelFormat(COleDateTime(2000,1,1,12,0,0) ,
COleDateTimeSpan(0,0,30,0) ,
"%H:%M" );
pAxis->GetBottomLabel()->Show(FALSE);
pAxis->GetLeftLabel()->Show(FALSE);
}
void CMainFrame::GetExample4(CPGLRegion* pGraph)
{
ASSERT_VALID(pGraph);
int m=2;
int n=2;
CPGLRegion* pChildRegion;
pGraph->Divide(m,n);
pChildRegion = pGraph->GetChild(0*n+0);
GetExample1(pChildRegion);
pChildRegion = pGraph->GetChild(1*n+0);
GetExample2(pChildRegion);
pChildRegion = pGraph->GetChild(0*n+1);
GetExample3(pChildRegion);
pChildRegion = pGraph->GetChild(1*n+1);
pChildRegion->GetAxe()->Hide();
pGraph->ZoomAll(TRUE);
}
void CMainFrame::OnExamplesSimpleline()
{
CPGLGraph* pGraph = new CPGLGraph;
GetExample1(pGraph);
pGraph->ZoomAll();
CPGLGraphBitDlg graphdlg(this, pGraph);
graphdlg.DoModal();
}
void CMainFrame::OnExamplesSimplelinewithlevelofdetail()
{
CPGLGraph* pGraph = new CPGLGraph;
GetExample2(pGraph);
pGraph->ZoomAll();
CPGLGraphBitDlg graphdlg(this, pGraph);
graphdlg.DoModal();
}
void CMainFrame::OnExamplesCustomizingtheaxis()
{
CPGLGraph* pGraph = new CPGLGraph;
GetExample3(pGraph);
pGraph->ZoomAll();
CPGLGraphBitDlg graphdlg(this, pGraph);
graphdlg.DoModal();
}
void CMainFrame::OnExamplesSubplotting()
{
CPGLGraph* pGraph = new CPGLGraph;
GetExample4(pGraph);
CPGLRegion* pChildRegion = pGraph->GetChild(pGraph->GetNChilds()-1);
ASSERT_VALID(pChildRegion);
GetExample4(pChildRegion);
pGraph->ZoomAll();
CPGLGraphBitDlg graphdlg(this, pGraph);
graphdlg.DoModal();
}