#ifndef Mtx_Map_Edit_INCLUDED
	#define Mtx_Map_Edit_INCLUDED

#include <bncs_script_helper.h>

#ifdef WIN32
	#ifdef DOEXPORT_SCRIPT
		#define EXPORT_SCRIPT __declspec(dllexport) 
	#else
		#define EXPORT_SCRIPT 
	#endif
#else 
	#define EXPORT_SCRIPT
#endif
 
#define NUM_GROUPS		12		// Maximum number of groups to be managed
#define ENTRYS_PER_PAGE	30		// Maximum number of sources or destinations
#define SRC_DB			0
#define	DST_DB			1
#define GRP_SRC_DB		4
#define GRP_DST_DB		5
#define MAP_DB			8
#define MAP_SRC_OFFSET	0
#define MAP_DST_OFFSET	100
#define SRC_GRP_MAP		201
#define DST_GRP_MAP		251
#define MAX_MATRIX_SIZE	260		// A number bigger than the maximum matrix size to map.

class Mtx_Map_Edit : public bncs_script_helper
{
public:
	Mtx_Map_Edit( bncs_client_callback * parent, const char* path );
	virtual ~Mtx_Map_Edit();

	void buttonCallback(buttonNotify *b);
	int revertiveCallback(revertiveNotify *r);
	void databaseCallback(revertiveNotify *r);
	bncs_string parentCallback(parentNotify *p);
	void timerCallback(int);
	
private:
	// Variables
	bncs_string homePanel;		// Holds the name of the home panel for the workstation screen size
	bncs_string xptMapPanel;	// Holds the name of the crosspoint map editing panel
	bncs_string groupMapPanel;	// Holds the name of the group map edit panel
	bncs_string groupNamePanel;	// Holds the name of the group name editing panel

	int matrix_id;				// Holds the BNCS driver id being edited
	int database_id;			// Holds the database number (0 or 1) being edited
	int db_size;				// Holds the number of sources/destinations in current matrix
	int active_panel;			// Holds the ID of the current active panel
	int selected_matrix;		// Used by the HOME panel to note the matrix selection
	int selected_function;		// Used by the HOME panel to note the selected function
	int select_mtx;				// Holds the matrix ID for the user selected number (set using up/down pushes)

	int mtx_map[NUM_GROUPS][ENTRYS_PER_PAGE];	// This 2-D array holds the matrix map of the currently edited matrix.
												// Note that indexing uses C convention (eg 0 - 11), not BNCS (1 - 12)
	int	num_xpts;				// Holds the number of sources/destinations on the selected matrix

	// XPT_EDIT panel
	int grp_sel;				// Holds the selected group id.
	int map_sel;				// Holds the selected map button.
	int xpt_sel;				// Holds the selected xpt id

	// GROUP_MAP enable/disable panel
	int grp_map_id;				// Holds the map id being edited
	int grp_db;					// Holds database id for the source/destination

	// GROUP_NAME edit panel
	int grp_name_db;						// Group name database number being edited
	int editid;								// Number of group being edited
	bncs_string groupNames[NUM_GROUPS];		// List of 12 names.

	bool matrix_selected;					// True when a matrix is selected on the home panel
	bool function_selected;					// True when an edit function is selected on the home panel
	bool edit_enabled;						// True when HOME EDIT button is enabled.
	bool mtx_changed;						// True when Matrix Map has been edited, and Save Network button is enabled.
	bool SetMapBtnState;					// True if the Map Crosspoint button is enabled
	bool page_changed[NUM_GROUPS];			// Keeps a list of flags to show if the page of maps has been updated (value=true) or not (value=false).
	bool xpt_is_mapped[MAX_MATRIX_SIZE];	// Used by the routine that looks for unmapped crosspoints.
	bool grp_enabled[NUM_GROUPS];			// Keeps list of flags to show if associated group button should be enabled.
	bool grp_map_save;						//
	bool grp_name_changed;					// True is a group name has been edited, and the SAVE button is active.
	bool grp_name_grpchanged[NUM_GROUPS];	// Holds the current set of names being edited.

	// Local Methods
	void processHome(buttonNotify *b);		// Process buttons on the Home panel (Select edit function)
	void processXptMap(buttonNotify *b);	// Process button preses on the Crosspoint Map edit panel.
	void processGroupMapEnables(buttonNotify *b);	// Process button presses on the Map Enables panel
	void processGroupNameEdit(buttonNotify *b);	// Process buttons on the group name editor panel.
	void checkEditEnable(void);				//
	void loadGroupNames(void);				// Prepares the group names for editing
	void loadMtxMap(int m_id, int db_id);	//
	void ShowMapGroup(int group_id);		// Show the mapping for the group passed as a parameter
	void updateMappedList(void);			// Updates list of places where crosspoint is mapped.
	void updateSetMapBtn(void);				// Updates the enabled/disabled state of the Set Map button
	void showUnmappedXpt(void);				// Updates the list on panel XPT_MAP showing whihc crosspoints are not mapped to a group/element
	void prepGroupMapPanel(void);			// Prepares the group enable/disable panel for display
	void setMatrix(int step);				// Update the matrix number of the user entered vale.
};


#endif // Mtx_Map_Edit_INCLUDED