// IsolNon.cpp : implementation file
//

#include "stdafx.h"
#include "BemIsol.h"
#include "BemIsolDoc.h"
#include "IsolNon.h"
#include "IsolAdd.h"

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

/////////////////////////////////////////////////////////////////////////////
// CIsolNon dialog


CIsolNon::CIsolNon(CWnd* pParent /*=NULL*/)
	: CDialog(CIsolNon::IDD, pParent)
{
	//{{AFX_DATA_INIT(CIsolNon)
	m_max = _T("");
	m_min = _T("");
	//}}AFX_DATA_INIT
}


void CIsolNon::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CIsolNon)
	DDX_Control(pDX, IDC_LIST1, m_list);
	DDX_Text(pDX, IDC_MAX, m_max);
	DDX_Text(pDX, IDC_MIN, m_min);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CIsolNon, CDialog)
	//{{AFX_MSG_MAP(CIsolNon)
	ON_BN_CLICKED(IDC_ADD_ISO, OnAddIso)
	ON_BN_CLICKED(IDC_DEL_ISO, OnDelIso)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CIsolNon message handlers

void CIsolNon::OnAddIso() 
{
	int j;
	CString msg;
	CIsolAdd isa;
	if (isa.DoModal()==IDOK)
	{
		j=m_list.GetCount();
		msg.Format("%3d - %12.4f",j+1,isa.m_isol);
		m_list.AddString(msg);
	}
}

void CIsolNon::OnDelIso() 
{
	int i;
	CString msg,msp;
	int ij=m_list.GetCurSel();
	if (ij!=LB_ERR)
	{
		m_list.DeleteString(ij);
		for (i=0;i<m_list.GetCount();i++)
		{
			m_list.GetText(i,msg);
			msp.Format("%3d",i+1);msp+=msg.Mid(3);
			m_list.DeleteString(i);
			m_list.InsertString(i,msp);
		}
	}
}

BOOL CIsolNon::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	int i;
	CString msg;
	m_list.ResetContent();
	for (i=0;i<pDoc->Isolin.GetSize();i++)
	{
		msg.Format("%3d - %12.4f",i+1,pDoc->Isolin[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 CIsolNon::OnOK() 
{
	int i;
	CString msg,msp;
	pDoc->Isolin.RemoveAll();
	for (i=0;i<m_list.GetCount();i++)
	{
		m_list.GetText(i,msg);
		msp=msg.Mid(6);
		pDoc->Isolin.Add(atof(msp));
	}
	
	CDialog::OnOK();
}
