// PoissonView.cpp : implementation of the CPoissonView class
//

#include "stdafx.h"
#include "Poisson.h"

#include "PoissonDoc.h"
#include "PoissonView.h"
#include "PoissonSolver.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CPoissonView

IMPLEMENT_DYNCREATE(CPoissonView, CView)

BEGIN_MESSAGE_MAP(CPoissonView, CView)
	ON_COMMAND(ID_FILE_PROCESSGRADIENT, OnFileProcessgradient)
END_MESSAGE_MAP()

// CPoissonView construction/destruction

CPoissonView::CPoissonView()
{
	// TODO: add construction code here

}

CPoissonView::~CPoissonView()
{
}

BOOL CPoissonView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

// CPoissonView drawing

void CPoissonView::OnDraw(CDC* /*pDC*/)
{
	CPoissonDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	// TODO: add draw code for native data here
}


// CPoissonView diagnostics

#ifdef _DEBUG
void CPoissonView::AssertValid() const
{
	CView::AssertValid();
}

void CPoissonView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CPoissonDoc* CPoissonView::GetDocument() const // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPoissonDoc)));
	return (CPoissonDoc*)m_pDocument;
}
#endif //_DEBUG


// CPoissonView message handlers

void CPoissonView::OnFileProcessgradient()
{
	// TODO: Add your command handler code here
	CString str_filename;
	CFileDialog dlg(TRUE,"*.txt","*.txt");
	dlg.m_ofn.lpstrInitialDir = ".";
	if (dlg.DoModal() == IDOK) 	
		str_filename = dlg.GetFileName();

	char * char_filename = (char *) (LPCTSTR) str_filename;

	BeginWaitCursor();
	CPoissonSolver ps(char_filename);
	ps.ReconstructImg();
	EndWaitCursor();

	MessageBox("Finished Processing - see output (.pgm file)");

}
