www.pudn.com > Geotest.rar > LayerControl.cpp


// LayerControl.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "geotest.h" 
#include "LayerControl.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CLayerControl dialog 
 
 
CLayerControl::CLayerControl(CWnd* pParent /*=NULL*/) 
	: CDialog(CLayerControl::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CLayerControl) 
	m_strLayerName = _T(""); 
	m_visible = FALSE; 
	m_selectable = FALSE; 
	m_editable = FALSE; 
	m_autoLabels = FALSE; 
	//}}AFX_DATA_INIT 
} 
CLayerControl::CLayerControl(CMapX* pMapX,CWnd* pParent /*=NULL*/) 
	: CDialog(CLayerControl::IDD, pParent) 
{ 
	m_pMapX = pMapX; 
} 
 
 
void CLayerControl::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CLayerControl) 
	DDX_Control(pDX, IDC_BUTTON_REMOVE, m_ctrlRemove); 
	DDX_Control(pDX, IDC_CHECK3, m_ctrlAutoLabels); 
	DDX_Control(pDX, IDC_CHECK4, m_ctrlEditable); 
	DDX_Control(pDX, IDC_CHECK2, m_ctrlSelectable); 
	DDX_Control(pDX, IDC_CHECK1, m_ctrlVisible); 
	DDX_Control(pDX, IDC_BUTTON_DOWN, m_ctrlButtonDown); 
	DDX_Control(pDX, IDC_BUTTON_UP, m_ctrlButtonUp); 
	DDX_Control(pDX, IDC_LIST_LAYER, m_ctrlLayerControl); 
	DDX_LBString(pDX, IDC_LIST_LAYER, m_strLayerName); 
	DDX_Check(pDX, IDC_CHECK1, m_visible); 
	DDX_Check(pDX, IDC_CHECK2, m_selectable); 
	DDX_Check(pDX, IDC_CHECK4, m_editable); 
	DDX_Check(pDX, IDC_CHECK3, m_autoLabels); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CLayerControl, CDialog) 
	//{{AFX_MSG_MAP(CLayerControl) 
	ON_BN_CLICKED(IDC_BUTTON_UP, OnButtonUp) 
	ON_LBN_SELCHANGE(IDC_LIST_LAYER, OnSelchangeListLayer) 
	ON_BN_CLICKED(IDC_CHECK1, OnCheckVisible) 
	ON_BN_CLICKED(IDC_CHECK2, OnCheckSelectable) 
	ON_BN_CLICKED(IDC_CHECK3, OnCheckAutoLabels) 
	ON_BN_CLICKED(IDC_CHECK4, OnCheckEditable) 
	ON_BN_CLICKED(IDC_BUTTON_DOWN, OnButtonDown) 
	ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd) 
	ON_BN_CLICKED(IDC_BUTTON_REMOVE, OnButtonRemove) 
	ON_BN_CLICKED(IDC_BUTTON1, OnButtonDisplay) 
	ON_BN_CLICKED(IDC_BUTTON2, OnButtonLabelStyle) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CLayerControl message handlers 
 
 
BOOL CLayerControl::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	//设置列表项 
	if(m_pMapX==NULL) return FALSE; 
	CMapXLayers Layers = m_pMapX->GetLayers(); 
	for(int i=0;iGetLayers().Item(1);	 
	UpdateData(FALSE); 
	//设置可编辑等初始属性 
	m_ctrlVisible.SetCheck(layer.GetVisible()); 
	m_ctrlSelectable.SetCheck(layer.GetSelectable()); 
	m_ctrlAutoLabels.SetCheck(layer. GetAutoLabel()); 
	m_ctrlEditable.SetCheck(layer.GetEditable()); 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
void CLayerControl::OnSelchangeListLayer()  
{ 
	UpdateData(TRUE); 
	if(m_ctrlLayerControl.GetSel(0)==TRUE) 
		m_ctrlButtonUp.EnableWindow(FALSE); 
	else 
		m_ctrlButtonUp.EnableWindow(TRUE); 
	if(m_ctrlLayerControl.GetSel(m_ctrlLayerControl.GetCount()-1)==TRUE) 
		m_ctrlButtonDown.EnableWindow(FALSE); 
	else 
		m_ctrlButtonDown.EnableWindow(TRUE); 
	//设置可编辑等属性 
	LayerName =m_strLayerName; 
	CMapXLayer layer =m_pMapX->GetLayers().Item(LayerName); 
	m_ctrlVisible.SetCheck(layer.GetVisible()); 
	m_ctrlSelectable.SetCheck(layer.GetSelectable()); 
	m_ctrlAutoLabels.SetCheck(layer.GetAutoLabel()); 
	m_ctrlEditable.SetCheck(layer.GetEditable()); 
} 
//得到选中的图层 
CMapXLayer CLayerControl:: GetTargetLayer() 
{ 
	UpdateData(TRUE); 
	CMapXLayer layer=m_pMapX->GetLayers().Item(m_strLayerName); 
	return layer; 
} 
 
 
void CLayerControl::OnCheckVisible()  
{ 
	CMapXLayer layer=GetTargetLayer(); 
	layer.SetVisible(m_visible); 
	//UpdateWindow(); 
} 
 
void CLayerControl::OnCheckSelectable()  
{ 
	CMapXLayer layer=GetTargetLayer(); 
	layer.SetSelectable(m_selectable); 
} 
 
void CLayerControl::OnCheckAutoLabels()  
{ 
	CMapXLayer layer=GetTargetLayer(); 
	layer.SetAutoLabel(m_autoLabels); 
} 
 
void CLayerControl::OnCheckEditable()  
{ 
	CMapXLayer layer=GetTargetLayer(); 
	layer.SetEditable(m_editable); 
} 
 
void CLayerControl::OnButtonUp()  
{ 
	//修改列表框项 
	CMapXLayer layer=GetTargetLayer(); 
	short Num=m_ctrlLayerControl.GetCurSel(); 
	m_ctrlLayerControl.InsertString(Num-1,layer.GetName()); 
	m_ctrlLayerControl.DeleteString(Num+1); 
	m_ctrlLayerControl.SetCurSel(Num-1); 
	//改变图层顺序 
    for(short i=1;i<=m_pMapX->GetLayers().GetCount();i++) 
		if(m_pMapX->GetLayers().Item(i).GetName()==layer.GetName()) 
		{Num=i;break;} 
	m_pMapX->GetLayers().Move(Num,Num-1); 
	//检查是否最顶或最底层 
	if(m_ctrlLayerControl.GetCurSel()==0) 
		m_ctrlButtonUp.EnableWindow(FALSE); 
	else 
		m_ctrlButtonUp.EnableWindow(TRUE); 
	if(m_ctrlLayerControl.GetSel(m_ctrlLayerControl.GetCount()-1)==TRUE) 
		m_ctrlButtonDown.EnableWindow(FALSE); 
	else 
		m_ctrlButtonDown.EnableWindow(TRUE); 
} 
 
void CLayerControl::OnButtonDown()  
{ 
	//修改列表框项 
	CMapXLayer layer=GetTargetLayer(); 
	short Num=m_ctrlLayerControl.GetCurSel(); 
	m_ctrlLayerControl.InsertString(Num+2,layer.GetName()); 
	m_ctrlLayerControl.DeleteString(Num); 
	m_ctrlLayerControl.SetCurSel(Num+1); 
	//改变图层顺序 
    for(short i=1;i<=m_pMapX->GetLayers().GetCount();i++) 
		if(m_pMapX->GetLayers().Item(i).GetName()==layer.GetName()) 
		{Num=i;break;} 
	m_pMapX->GetLayers().Move(Num,Num+1); 
	//检查是否最顶或最底层 
	if(m_ctrlLayerControl.GetCurSel()==0) 
		m_ctrlButtonUp.EnableWindow(FALSE); 
	else 
		m_ctrlButtonUp.EnableWindow(TRUE); 
	if(m_ctrlLayerControl.GetSel(m_ctrlLayerControl.GetCount()-1)==TRUE) 
		m_ctrlButtonDown.EnableWindow(FALSE); 
	else 
		m_ctrlButtonDown.EnableWindow(TRUE); 
	 
} 
 
void CLayerControl::OnButtonAdd() 
{ 
	static char BASED_CODE szDataFilter[] = "mapinfo table (*.tab)|*.tab|All Files (*.*)|*.*||"; 
	CFileDialog dlgFile(TRUE, "*.tab", NULL, 0, szDataFilter, this); 
	if (dlgFile.DoModal()==IDCANCEL) 
		return; 
	dlgFile.m_ofn.lpstrTitle = "添加Mapinfo表";//对话框名称 
	CString m_dataPath= dlgFile.GetPathName(); 
	m_pMapX->GetLayers().Add(m_dataPath,1); 
	CString str=m_pMapX->GetLayers().Item(1).GetName(); 
	m_ctrlLayerControl.InsertString(0,str); 
	m_ctrlLayerControl.SetCurSel(0); 
	//////////////////// 
	if(m_ctrlLayerControl.GetCount()==0) 
		m_ctrlRemove.EnableWindow(FALSE); 
	else 
		m_ctrlRemove.EnableWindow(TRUE); 
} 
 
void CLayerControl::OnButtonRemove()  
{ 
	UpdateData(TRUE); 
	m_pMapX->GetLayers().Remove(m_strLayerName); 
	//改变列表框选项 
	short Num=m_ctrlLayerControl.GetCurSel(); 
	m_ctrlLayerControl.DeleteString(Num); 
	if(Num==0) 
		m_ctrlLayerControl.SetCurSel(Num+1); 
	else 
		m_ctrlLayerControl.SetCurSel(Num-1); 
	if(m_ctrlLayerControl.GetCount()==0) 
		m_ctrlRemove.EnableWindow(FALSE); 
} 
 
void CLayerControl::OnButtonDisplay()  
{	 
} 
 
void CLayerControl::OnButtonLabelStyle()  
{	 
}