// ******************************************************************************** 
// ** RaaToCsvDlg
// **
// ** Copyright (C) 2012-2017 3D at Depth Inc. All Rights Reserved
// ** www.3DatDepth.com  This software can not be copied and/or distributed without 
// ** the express permission of 3D at Depth Inc.
// ******************************************************************************** 

#pragma once


#include "SysThread.h"
#include "WSPacket.h"
#include "afxwin.h"


// CRaaToCsvDlg dialog
class CRaaToCsvDlg : public CDialogEx
{
// Construction
public:
	CRaaToCsvDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_RAATOCSV_DIALOG };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
   afx_msg void OnTimer(UINT_PTR nIDEvent);

private:
   bool        VerifyFolderExists(CString strFolder, bool bCreateNonExistentFolder = false);
   UINT64      FileSize(CString strFile);
	static void ConversionThreadEntry( void *pThreadObj );
	void			ConversionThread();
   void        ReadHeaderData();
   bool        ReadLaserData();

// Implementation
protected:
	HICON m_hIcon;

   CProgressCtrl  m_ctlConvertProgress;
   size_t         m_nBytesRead;
   UINT64         m_nMslFileSize;
   SysThread      m_thdConvert;
   bool           m_bConvertFile;
   char           m_pch[500];
   FILE*          m_pfileMSL;
   FILE*          m_pfileCSV;
   CString        m_strMslFileName;
   CString        m_strCsvFileName;
   bool           m_bInitialized;
   UINT32               m_nPointsPerLos;
   UINT32               m_nLosPerScanLine;
   WSScanLineDataPacket m_pktScanLine;
   UINT16               m_nId;
   UINT16               m_nMagicNumber;
   UINT16               m_nVersion;
   UINT16               m_nSubVersion;
   float                m_fAzStart;
   float                m_fAzEnd;                                      
   UINT16               m_nPulsesPerCrossTrack;                                          
   UINT8                m_nPulsesPerLOS;                                                 
   UINT16               m_nScanLineCount1;
   UINT16               m_nScanLineCount2;                      
   UINT16               m_nRecordID;
   StructTimeStamp      m_sTimeStamp;
   float                m_fAz;
   float                m_fTimeOffset;
   float                m_pfRange[MAX_POINTS_PER_LOS];
   UINT16               m_pnIntensity[MAX_POINTS_PER_LOS];
   UINT32               m_nPulseCountThisScanLine;
   float                m_fCrossTrackAz;
   float                m_fForwardTrackEl;
   float                m_fCrossTrackAzOffset;
   float                m_fForwardTrackElOffset;

   CEdit                m_ctlAzRotationA;
   CEdit                m_ctlElRotationA;
   CEdit                m_ctlAzRotationB;
   CEdit                m_ctlElRotationB;
   float                m_fAzRotation;
   float                m_fElRotation;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
public:
   afx_msg void OnBnClickedSelectFile();
   afx_msg void OnBnClickedStop();
};
