// XyzPage.cpp : implementation file
//

#include "stdafx.h"
#include "..\at3ddll.h"
#include "MSVC_Test_At3dx_Dll.h"
#include "XyzPage.h"
#include "At3dData.h"

extern CAt3dData* at3dData;

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

/////////////////////////////////////////////////////////////////////////////
// CXyzPage property page

IMPLEMENT_DYNCREATE(CXyzPage, CPropertyPage)

CXyzPage::CXyzPage() : CPropertyPage(CXyzPage::IDD)
{
	//{{AFX_DATA_INIT(CXyzPage)
	m_XyzSkipDlg = FALSE;
	m_XyzType_Group = -1;
	m_XyzFileType_Group = -1;
	m_XyzByteOrder_Group = -1;
	m_XyzHasID = FALSE;
	m_XyzUseID = FALSE;
	m_XyzAxis_Group = -1;
	m_XyzStoredBy_Group = -1;
	m_XyzColumns = _T("");
	m_XyzRows = _T("");
	m_XyzFromColumn = _T("");
	m_XyzFromRow = _T("");
	m_XyzToColumn = _T("");
	m_XyzToRow = _T("");
	m_XyzUseNoData = FALSE;
	m_XyzNoDataValue = _T("");
	m_XyzNoDataReplaceValue = _T("");
	m_XyzNoDataReplace_Group = -1;
	m_XyzReadClip = FALSE;
	m_XyzSaveAsDXF = FALSE;
	m_XyzScaleFactorZ = _T("");
	m_XyzScaleZ = FALSE;
	m_XyzFloatType_Group = -1;
	//}}AFX_DATA_INIT
}

CXyzPage::~CXyzPage()
{
}

void CXyzPage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CXyzPage)
	DDX_Check(pDX, IDC_XYZSKIPDLG, m_XyzSkipDlg);
	DDX_Radio(pDX, IDC_XYZMESHTYPE, m_XyzType_Group);
	DDX_Radio(pDX, IDC_XYZASCIITYPE, m_XyzFileType_Group);
	DDX_Radio(pDX, IDC_XYZINTEL, m_XyzByteOrder_Group);
	DDX_Check(pDX, IDC_XYZHASID, m_XyzHasID);
	DDX_Check(pDX, IDC_XYZUSEID, m_XyzUseID);
	DDX_Radio(pDX, IDC_XYZAXIS1, m_XyzAxis_Group);
	DDX_Radio(pDX, IDC_XYZBYROW, m_XyzStoredBy_Group);
	DDX_Text(pDX, IDC_XYZCOLUMNS, m_XyzColumns);
	DDX_Text(pDX, IDC_XYZROWS, m_XyzRows);
	DDX_Text(pDX, IDC_XYZFROMCOLUMN, m_XyzFromColumn);
	DDX_Text(pDX, IDC_XYZFROMROW, m_XyzFromRow);
	DDX_Text(pDX, IDC_XYZTOCOLUMN, m_XyzToColumn);
	DDX_Text(pDX, IDC_XYZTOROW, m_XyzToRow);
	DDX_Check(pDX, IDC_XYZUSENODATA, m_XyzUseNoData);
	DDX_Text(pDX, IDC_XYZNODATAVALUE, m_XyzNoDataValue);
	DDX_Text(pDX, IDC_XYZNODATAREPLACEVALUE, m_XyzNoDataReplaceValue);
	DDX_Radio(pDX, IDC_XYZNODATAREPLACE1, m_XyzNoDataReplace_Group);
	DDX_Check(pDX, IDC_XYZREADCLIP, m_XyzReadClip);
	DDX_Check(pDX, IDC_XYZSAVEASDXF, m_XyzSaveAsDXF);
	DDX_Text(pDX, IDC_XYZSCALEFACTORZ, m_XyzScaleFactorZ);
	DDX_Check(pDX, IDC_XYZSCALEZ, m_XyzScaleZ);
	DDX_Radio(pDX, IDC_XYZFLOATTYPE, m_XyzFloatType_Group);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CXyzPage, CPropertyPage)
	//{{AFX_MSG_MAP(CXyzPage)
	ON_BN_CLICKED(IDC_XYZSKIPDLG, OnXyzskipdlg)
	ON_BN_CLICKED(IDC_XYZMESHTYPE, OnXyzmeshtype)
	ON_BN_CLICKED(IDC_XYZSCANTYPE, OnXyzscantype)
	ON_BN_CLICKED(IDC_XYZASCIITYPE, OnXyzasciitype)
	ON_BN_CLICKED(IDC_XYZBINARYTYPE, OnXyzbinarytype)
	ON_BN_CLICKED(IDC_XYZINTEL, OnXyzintel)
	ON_BN_CLICKED(IDC_XYZMOTOROLA, OnXyzmotorola)
	ON_BN_CLICKED(IDC_XYZFLOATTYPE, OnXyzfloattype)
	ON_BN_CLICKED(IDC_XYZDOUBLETYPE, OnXyzdoubletype)
	ON_BN_CLICKED(IDC_XYZBYROW, OnXyzbyrow)
	ON_BN_CLICKED(IDC_XYZBYCOLUMN, OnXyzbycolumn)
	ON_BN_CLICKED(IDC_XYZREADCLIP, OnXyzreadclip)
	ON_BN_CLICKED(IDC_XYZAXIS1, OnXyzaxis1)
	ON_BN_CLICKED(IDC_XYZAXIS2, OnXyzaxis2)
	ON_BN_CLICKED(IDC_XYZAXIS3, OnXyzaxis3)
	ON_BN_CLICKED(IDC_XYZSCALEZ, OnXyzscalez)
	ON_BN_CLICKED(IDC_XYZHASID, OnXyzhasid)
	ON_BN_CLICKED(IDC_XYZUSEID, OnXyzuseid)
	ON_BN_CLICKED(IDC_XYZSAVEASDXF, OnXyzsaveasdxf)
	ON_BN_CLICKED(IDC_XYZUSENODATA, OnXyzusenodata)
	ON_BN_CLICKED(IDC_XYZNODATAREPLACE1, OnXyznodatareplace1)
	ON_BN_CLICKED(IDC_XYZNODATAREPLACE2, OnXyznodatareplace2)
	ON_BN_CLICKED(IDC_XYZNODATAREPLACE3, OnXyznodatareplace3)
	//}}AFX_MSG_MAP
  ON_BN_CLICKED(IDC_XYZDOUBLEZTYPE, &CXyzPage::OnBnClickedXyzdoubleztype)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CXyzPage message handlers

BOOL CXyzPage::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_XyzSkipDlg = (at3dData->xyzSkipDlgFlag) ? TRUE: FALSE;

  m_XyzType_Group = at3dData->xyzScanFlag;

  m_XyzFileType_Group = at3dData->xyzBinaryFileFlag;

  m_XyzByteOrder_Group = at3dData->xyzMotorolaFlag;

  m_XyzFloatType_Group = at3dData->xyzDoubleFlag;

  m_XyzRows.Format("%d", at3dData->xyzRows);
  m_XyzColumns.Format("%d", at3dData->xyzColumns);

  m_XyzStoredBy_Group = at3dData->xyzByColumnFlag;

  m_XyzReadClip = (at3dData->xyzClipFlag) ? TRUE: FALSE;

  m_XyzFromRow.Format("%d", at3dData->xyzFromRow);
  m_XyzToRow.Format("%d", at3dData->xyzToRow);

  m_XyzFromColumn.Format("%d", at3dData->xyzFromColumn);
  m_XyzToColumn.Format("%d", at3dData->xyzToColumn);

  m_XyzAxis_Group = at3dData->xyzAxisFlag;

  m_XyzScaleZ    = (at3dData->xyzScaleZFlag) ? TRUE: FALSE;
  m_XyzScaleFactorZ.Format("%.4f", at3dData->xyzScaleFactorZ);

  m_XyzHasID = (at3dData->xyzHasIdFlag) ? TRUE: FALSE;
  m_XyzUseID = (at3dData->xyzUseIdFlag) ? TRUE: FALSE;

  m_XyzSaveAsDXF = (at3dData->xyzSaveDxfFlag) ? TRUE: FALSE;

  m_XyzUseNoData = (at3dData->xyzNoDataFlag) ? TRUE: FALSE;
  m_XyzNoDataValue.Format("%.4f", at3dData->xyzNoDataValue);

  m_XyzNoDataReplace_Group = at3dData->xyzNoDataReplaceFlag;

  m_XyzNoDataReplaceValue.Format("%.4f", at3dData->xyzNoDataReplaceValue);

	UpdateData(FALSE);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CXyzPage::OnXyzskipdlg() 
{
	UpdateData(TRUE);
	at3dData->xyzSkipDlgFlag = (m_XyzSkipDlg) ? 1 : 0;
}

void CXyzPage::OnXyzmeshtype() 
{
	at3dData->xyzScanFlag = 0;
}

void CXyzPage::OnXyzscantype() 
{
	at3dData->xyzScanFlag = 1;
}

void CXyzPage::OnXyzasciitype() 
{
	at3dData->xyzBinaryFileFlag = 0;
}

void CXyzPage::OnXyzbinarytype() 
{
	at3dData->xyzBinaryFileFlag = 1;
}

void CXyzPage::OnXyzintel() 
{
	at3dData->xyzMotorolaFlag = 0;
}

void CXyzPage::OnXyzmotorola() 
{
	at3dData->xyzMotorolaFlag = 1;
}

void CXyzPage::OnXyzfloattype() 
{
	at3dData->xyzDoubleFlag = 0;
}

void CXyzPage::OnXyzdoubletype() 
{
	at3dData->xyzDoubleFlag = 1;
}

void CXyzPage::OnXyzbyrow() 
{
	at3dData->xyzByColumnFlag = 0;
}

void CXyzPage::OnXyzbycolumn() 
{
	at3dData->xyzByColumnFlag = 1;
}

void CXyzPage::OnXyzreadclip() 
{
	UpdateData(TRUE);
	at3dData->xyzClipFlag = (m_XyzReadClip) ? 1 : 0;
}

void CXyzPage::OnXyzaxis1() 
{
	at3dData->xyzAxisFlag = 0;
}

void CXyzPage::OnXyzaxis2() 
{
	at3dData->xyzAxisFlag = 1;
}

void CXyzPage::OnXyzaxis3() 
{
	at3dData->xyzAxisFlag = 2;
}

void CXyzPage::OnXyzscalez() 
{
	UpdateData(TRUE);
	at3dData->xyzScaleZFlag = (m_XyzScaleZ) ? 1 : 0;
}

void CXyzPage::OnXyzhasid() 
{
	UpdateData(TRUE);
	at3dData->xyzHasIdFlag = (m_XyzHasID) ? 1 : 0;
}

void CXyzPage::OnXyzuseid() 
{
	UpdateData(TRUE);
	at3dData->xyzUseIdFlag = (m_XyzUseID) ? 1 : 0;
}

void CXyzPage::OnXyzsaveasdxf() 
{
	UpdateData(TRUE);
	at3dData->xyzSaveDxfFlag = (m_XyzSaveAsDXF) ? 1 : 0;
}

void CXyzPage::OnXyzusenodata() 
{
	UpdateData(TRUE);
	at3dData->xyzNoDataFlag = (m_XyzUseNoData) ? 1 : 0;
}

void CXyzPage::OnXyznodatareplace1() 
{
	at3dData->xyzNoDataReplaceFlag = 0;
}

void CXyzPage::OnXyznodatareplace2() 
{
	at3dData->xyzNoDataReplaceFlag = 1;
}

void CXyzPage::OnXyznodatareplace3() 
{
	at3dData->xyzNoDataReplaceFlag = 2;
}

void CXyzPage::Get_XYZ_Data()
{
	UpdateData(TRUE);
	at3dData->xyzRows = atoi(m_XyzRows);
  
  at3dData->xyzColumns = atoi(m_XyzColumns);
  
  at3dData->xyzFromRow = atoi(m_XyzFromRow);
  
  at3dData->xyzToRow = atoi(m_XyzToRow);
  
  at3dData->xyzFromColumn = atoi(m_XyzFromColumn);
  
  at3dData->xyzToColumn = atoi(m_XyzToColumn);
  
  at3dData->xyzScaleFactorZ = atof(m_XyzScaleFactorZ);
  
  at3dData->xyzNoDataValue = atof(m_XyzNoDataValue);
  
  at3dData->xyzNoDataReplaceValue = atof(m_XyzNoDataReplaceValue);  
}

BOOL CXyzPage::OnKillActive() 
{
	// TODO: Add your specialized code here and/or call the base class
	Get_XYZ_Data();

	return CPropertyPage::OnKillActive();
}

void CXyzPage::OnBnClickedXyzdoubleztype()
{
  at3dData->xyzScanFlag = 2;
}
