//
//  wincnc.h - wincnc main header file
//
//  $Id: wincnc.h 52 2014-02-07 19:31:45Z brian $ 
//
//  Copyright (c) 1999-2014 by Precision Micro Control Corp. All rights reserved.
//
#ifndef WINCNC_H
#define WINCNC_H

#include "resource.h"       // main symbols

#define MAKE_VIEW_INVISIBLE		FALSE	// Used for CMultiDocTemplate::OpenDocumentFile() parameter
#define MAKE_VIEW_VISIBLE		TRUE

// Program constants
//
#define MAXUNITS				2				///< Number of unit systems (ie. English & Metric)
#define ENGLISH					0				///< Used for variable array indices
#define METRIC					1
#define ENGLISH_UNITS_TITLE		"ENGLISH"
#define METRIC_UNITS_TITLE		"METRIC"

extern CString UnitsName[2];

#define MCHFILENAMELENGTH		40
#define CFGFILENAMELENGTH		40

#define WORKCOORFILEEXT			".WRK"
#define TOOLDATAFILEEXT			".TOL"

#define PARTMAXLINELENGTH		128
#define SECTIONSTRINGLENGTH		40
#define ENTRYSTRINGLENGTH		40
#define VALUESTRINGLENGTH		80
#define UNITTITLESTRINGLENGTH	40

#define INTSTRINGLENGTH			20				///< Integer string length
#define DOUBLESTRINGLENGTH		30				///< Double string length

#define FIRST_WORKCOOR			1				///< Work coordinates number range
#define LAST_WORKCOOR			6
#define WORKCOOR_SIZE			(LAST_WORKCOOR - FIRST_WORKCOOR + 1)

#define FIRST_TOOL				1				///< Tool number range
#define LAST_TOOL				9
#define TOOL_SIZE				(LAST_TOOL - FIRST_TOOL + 1)

#define FIRST_OFFSET			1				///< Tool number range
#define LAST_OFFSET				32
#define OFFSET_SIZE				(LAST_OFFSET - FIRST_OFFSET + 2)

class CMachine;					// Forward declaration of machine class
class ControlPanel;				// Forward declaration of control panel class

class WinCncApp : public CWinApp
{
public:
	/// <summary>Constructor.</summary>
	WinCncApp();

	/// <summary>Set process output on idle flag.</summary>
	/// <param name="flag">True to allow, false to skip.</param>
	void						OutputOnIdle(bool flag) { m_output_on_idle = flag; }
	/// <summary>Get process output on idle flag.</summary>
	/// <returns>True to allow, false to skip.</returns>
	bool						OutputOnIdle() { return m_output_on_idle; }
	/// <summary>Set the machine object.</summary>
	/// <param name="new_machine">New machine.</param>
	void						SetMachine(CMachine* new_machine) { m_machine = new_machine; }
	/// <summary>Get the machine object.</summary>
	/// <returns>Machine.</returns>
	CMachine*					GetMachine() { return m_machine; }
	/// <summary>Set the control panel object.</summary>
	/// <param name="new_cpanel">New control panel.</param>
	void						SetControlPanel(ControlPanel* new_cpanel) { m_control_panel = new_cpanel; }
	/// <summary>Get the control panel object.</summary>
	/// <returns>Control panel.</returns>
	ControlPanel*				GetControlPanel(void) { return m_control_panel; }
		/// <summary>Get homing display document template.</summary>
	/// <returns>Template.</returns>
	CMultiDocTemplate*			GetHomingDisplayTemplate(void) { return m_homing_display_template; }
	/// <summary>Get MDI panel document template.</summary>
	/// <returns>Template.</returns>
	CMultiDocTemplate*			GetMDIPanelTemplate(void) { return m_mdi_panel_template; }
	/// <summary>Get output display document template.</summary>
	/// <returns>Template.</returns>
	CMultiDocTemplate*			GetOutputDisplayTemplate(void) { return m_output_display_template; }
	/// <summary>Get status display document template.</summary>
	/// <returns>Template.</returns>
	CMultiDocTemplate*			GetStatusDisplayTemplate(void) { return m_status_display_template; }

	/// <summary>Instance initialization handler.</summary>
	virtual BOOL				InitInstance();
	/// <summary>Instance finish handler.</summary>
	virtual	int					ExitInstance();
	/// <summary>Idle handler.</summary>
	virtual BOOL				OnIdle(LONG);

	/// <summary>About handler.</summary>
	afx_msg void				OnAppAbout();
	/// <summary>View current handler.</summary>
	afx_msg void				OnViewCurrent();
	/// <summary>View current UI handler.</summary>
	/// <param name="pCmdUI">UI element.</param>
	afx_msg void				OnUpdateViewCurrent(CCmdUI* pCmdUI);
	/// <summary>View optimal handler.</summary>
	afx_msg void				OnViewOptimal();
	/// <summary>View optimal UI handler.</summary>
	/// <param name="pCmdUI">UI element.</param>
	afx_msg void				OnUpdateViewOptimal(CCmdUI* pCmdUI);
	/// <summary>View status handler.</summary>
	afx_msg void				OnViewStatus();
	/// <summary>View status UI handler.</summary>
	/// <param name="pCmdUI">UI element.</param>
	afx_msg void				OnUpdateViewStatus(CCmdUI* pCmdUI);
	/// <summary>View program handler.</summary>
	afx_msg void				OnViewProgram();
	/// <summary>View program UI handler.</summary>
	/// <param name="pCmdUI">UI element.</param>
	afx_msg void				OnUpdateViewProgram(CCmdUI* pCmdUI);
	/// <summary>View messages handler.</summary>
	afx_msg void				OnViewMessages();
	/// <summary>View messages UI handler.</summary>
	/// <param name="pCmdUI">UI element.</param>
	afx_msg void				OnUpdateViewMessages(CCmdUI* pCmdUI);

	/// <summary>General setup handler.</summary>
	afx_msg void				OnSetupGeneral(void);
	/// <summary>Axis setup handler.</summary>
	afx_msg void				OnSetupAxes(void);
	/// <summary>Cutter setup handler.</summary>
	afx_msg void				OnSetupCutter(void);
	/// <summary>Feed setup handler.</summary>
	afx_msg void				OnSetupFeed(void);
	/// <summary>Homing setup handler.</summary>
	afx_msg void				OnSetupHoming(void);
	/// <summary>Jogging setup handler.</summary>
	afx_msg void				OnSetupJogging(void);
	/// <summary>Limits setup handler.</summary>
	afx_msg void				OnSetupLimits(void);
	/// <summary>Machine coordinates handler.</summary>
	afx_msg void				OnSetupMachineCoordinates(void);
	/// <summary>Rapid rate setup handler.</summary>
	afx_msg void				OnSetupRapid(void);
	/// <summary>Spindle setup handler.</summary>
	afx_msg void				OnSetupSpindle(void);
	/// <summary>Tools setup handler.</summary>
	afx_msg void				OnSetupTools(void);
	/// <summary>Work coordinates handler.</summary>
	afx_msg void				OnSetupWorkCoordinates(void);
	/// <summary>Setup save handler.</summary>
	afx_msg void				OnSetupSave(void);
	/// <summary>Setup save as handler.</summary>
	afx_msg void				OnSetupSaveAs(void);
	/// <summary>Program coordinates setup handler.</summary>
	afx_msg void				OnSetupProgramCoordinates(void);
	/// <summary>External controls setup handler.</summary>
	afx_msg void				OnSetupExternalControls(void);
	/// <summary>Offsets setup handler.</summary>
	afx_msg void				OnSetupOffsets(void);
	/// <summary>Calibrate joystick handler.</summary>
	afx_msg void				OnCalibrateJoystick(void);
	/// <summary>Calibrate joystick UI handler.</summary>
	/// <param name="pCmdUI">UI element.</param>
	afx_msg void				OnUpdateCalibrateJoystick(CCmdUI* pCmdUI);
	/// <summary>Run mode handler.</summary>
	afx_msg void				OnModeRun(void);
	/// <summary>Run mode UI handler.</summary>
	/// <param name="pCmdUI">UI element.</param>
	afx_msg void				OnUpdateModeRun(CCmdUI* pCmdUI);
	/// <summary>MDI mode handler.</summary>
	afx_msg void				OnModeMdi(void);
	/// <summary>MDI mode UI handler.</summary>
	/// <param name="pCmdUI">UI element.</param>
	afx_msg void				OnUpdateModeMdi(CCmdUI* pCmdUI);
	/// <summary>Jog mode handler.</summary>
	afx_msg void				OnModeJog(void);
	/// <summary>Jog mode UI handler.</summary>
	/// <param name="pCmdUI">UI element.</param>
	afx_msg void				OnUpdateModeJog(CCmdUI* pCmdUI);
	/// <summary>Dryrun handler.</summary>
	afx_msg void				OnOptionsDryrun(void);
	/// <summary>Dryrun UI handler.</summary>
	/// <param name="pCmdUI">UI element.</param>
	afx_msg void				OnUpdateOptionsDryrun(CCmdUI* pCmdUI);
	/// <summary>Block skip handler.</summary>
	afx_msg void				OnOptionsBlockskip(void);
	/// <summary>Block skip UI handler.</summary>
	/// <param name="pCmdUI">UI element.</param>
	afx_msg void				OnUpdateOptionsBlockskip(CCmdUI* pCmdUI);
	/// <summary>File restart handler.</summary>
	afx_msg void				OnFileRestart(void);
	/// <summary>Home mode handler.</summary>
	afx_msg void				OnModeHome(void);
	/// <summary>Home mode UI handler.</summary>
	/// <param name="pCmdUI">UI element.</param>
	afx_msg void				OnUpdateModeHome(CCmdUI* pCmdUI);

private:
	ControlPanel*				m_control_panel;				///< The control panel object, one per application
	CMultiDocTemplate*			m_homing_display_template;		///< homing display template
	CMachine*					m_machine;						///< The machine object, one per application
	CMultiDocTemplate*			m_mdi_panel_template;			///< MDI panel template
	CMultiDocTemplate*			m_output_display_template;		///< output display template
	bool						m_output_on_idle;				///< OnIdle() processing flag
	CMultiDocTemplate*			m_status_display_template;		///< status display template

	DECLARE_MESSAGE_MAP()
};

extern WinCncApp theApp;	// Give other objects access to the application

#endif			// WINCNC_H
