// TimeInter.cpp : implementation file
//

#include "stdafx.h"
#include "UnsDis.h"
#include "UnsDisDoc.h"
#include "TimeInter.h"
#include "newtim.h"

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

/////////////////////////////////////////////////////////////////////////////
// CTimeInter dialog


CTimeInter::CTimeInter(CWnd* pParent /*=NULL*/)
	: CDialog(CTimeInter::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTimeInter)
	m_dtmax = 0.0f;
	m_maxit = 0;
	m_schem = 0.0f;
	m_tol = 0.0f;
	m_delt = 0.0f;
	//}}AFX_DATA_INIT
}


void CTimeInter::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTimeInter)
	DDX_Control(pDX, IDC_LIST1, m_list);
	DDX_Text(pDX, IDC_DTMAX, m_dtmax);
	DDX_Text(pDX, IDC_MAXIT, m_maxit);
	DDX_Text(pDX, IDC_SCHEMA, m_schem);
	DDX_Text(pDX, IDC_TOL, m_tol);
	DDX_Text(pDX, IDC_DELT, m_delt);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTimeInter, CDialog)
	//{{AFX_MSG_MAP(CTimeInter)
	ON_BN_CLICKED(IDC_ADD_TIME, OnAddTime)
	ON_BN_CLICKED(IDC_DEL_TIME, OnDelTime)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTimeInter message handlers

void CTimeInter::OnAddTime() 
{
	CNewTim nt;
	if (nt.DoModal()==IDOK)
	{
		CString msg;
		msg.Format ("%8.3f",nt.m_newt);
		m_list.AddString(msg);
	}
}

void CTimeInter::OnDelTime() 
{
	int i=m_list.GetCurSel();
	if (i!=LB_ERR)
	{
		m_list.DeleteString(i);
	}
}

BOOL CTimeInter::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	int i;
	CString msg;
	m_list.ResetContent();
	for (i=0;i<pDoc->Tim.GetSize();i++)
	{
		msg.Format("%8.3f",pDoc->Tim[i]);
		m_list.AddString(msg);
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CTimeInter::OnOK() 
{
	int i;
	pDoc->Tim.RemoveAll();
	for (i=0;i<m_list.GetCount();i++)
	{
		CString msg;
		m_list.GetText(i,msg);
		float t=atof(msg);
		pDoc->Tim.Add(t);
	}
	
	CDialog::OnOK();
}
