?? uniquefilldlg.cpp
字號:
// UniqueFillDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SimpleMap.h"
#include "UniqueFillDlg.h"
#include "MainFrm.h"
#include "SimpleMapDoc.h"
#include "SimpleMapView.h"
#include "MapRender.h"
#include "MapFields.h"
#include "MapRender.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CUniqueFillDlg dialog
UINT MapRand(UINT nMax)
{
int nRand = rand();
float fMap = (float)(nMax)/RAND_MAX;
float fRetVal = (float)nRand*fMap + 0.5F;
return (UINT)fRetVal;
};
CUniqueFillDlg::CUniqueFillDlg(CWnd* pParent /*=NULL*/)
: CDialog(CUniqueFillDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CUniqueFillDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_csLayerName = _T("");
m_pLayer = NULL;
m_pRender = NULL;
m_iCurlSel = -1;
}
void CUniqueFillDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CUniqueFillDlg)
DDX_Control(pDX, IDC_SET, m_BtnSet);
DDX_Control(pDX, IDC_LISTLEGEND, m_ListLegend);
DDX_Control(pDX, IDC_CMBFIELD, m_cmbField);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CUniqueFillDlg, CDialog)
//{{AFX_MSG_MAP(CUniqueFillDlg)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_SET, OnSet)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CUniqueFillDlg message handlers
BOOL CUniqueFillDlg::OnInitDialog()
{
CDialog::OnInitDialog();
int i ;
LV_COLUMN lvc;
CString csFieldName;
CMapLayer *pLayer;
CMainFrame *pFrame = (CMainFrame *)::AfxGetMainWnd();
ASSERT(pFrame != NULL );
CSimpleMapView *pView = (CSimpleMapView*)pFrame->GetActiveView();
ASSERT(pView != NULL );
CSimpleMapDoc* pDoc = pView->GetDocument();
ASSERT_VALID(pDoc);
for ( i = 0 ; i < pDoc->m_MapLayers.GetCount() ; i++ )
{
pLayer = (CMapLayer *)pDoc->m_MapLayers.GetAt(i);
if ( pLayer->GetLayerName() == m_csLayerName )
break;
}
if ( i >= pDoc->m_MapLayers.GetCount() )
{
pLayer = NULL;
m_BtnSet.EnableWindow(FALSE);
m_cmbField.EnableWindow(FALSE);
m_ListLegend.EnableWindow(FALSE);
return TRUE;
}
m_pLayer = pLayer;
CMapTableDesc *pTableDsc = (pLayer->GetRecordSet())->GetTableDesc( );
ASSERT(pTableDsc != NULL );
for ( i = 0 ; i < pTableDsc->GetFieldCount() ; i++ )
{
csFieldName = pTableDsc->GetFieldName(i);
m_cmbField.AddString((LPCTSTR)csFieldName);
}
ListView_SetExtendedListViewStyle(m_ListLegend.GetSafeHwnd(),0);
i = 0;
lvc.mask= LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH;
lvc.fmt = LVCFMT_CENTER;
lvc.pszText = L"Classify Value";
lvc.iSubItem = i;
lvc.cx =60;
m_ListLegend.InsertColumn(i,&lvc);
i = 1;
lvc.mask= LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH;
lvc.fmt = LVCFMT_CENTER;
lvc.pszText = L"RGB Value";
lvc.iSubItem = i;
lvc.cx =130;
//m_ListLegend.InsertColumn(i,&lvc);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CUniqueFillDlg::OnDestroy()
{
CDialog::OnDestroy();
if ( m_pRender != NULL )
delete m_pRender;
}
void CUniqueFillDlg::OnSet()
{
int i,iCurSel,iIndex;
int iMItem;
//LV_ITEM lvItem;
CString csText;
CString csFieldName,csValue;
CMapFields *pFields;
CMapField *pField;
RENDERINFO render;
RENDERINFO *pRender;
iCurSel = m_cmbField.GetCurSel();
if ( iCurSel < 0 )
{
::MessageBox(NULL,L"Please select filed",L"Tips",MB_OK);
}
if ( iCurSel == m_iCurlSel )
return;
m_iCurlSel = iCurSel;
m_cmbField.GetLBText(iCurSel,csFieldName);
iIndex = -1;
(m_pLayer->GetRecordSet())->MoveFirst();
pFields = (m_pLayer->GetRecordSet())->GetFields(0);
for ( i = 0 ; i < pFields->GetCout() ; i++ )
{
pField = pFields->GetField(i);
if ( csFieldName == pField->GetName() )
{
iIndex = i;
break;
}
}
if ( m_pRender != NULL )
delete m_pRender;
m_pRender = new CMapRender;
m_pRender->SetFieldIndex(iIndex );
m_ListLegend.DeleteAllItems();
ASSERT( m_pRender != NULL );
iMItem = 0;
while ( !(m_pLayer->GetRecordSet())->GetEOF() && iIndex != -1 )
{
pFields = (m_pLayer->GetRecordSet())->GetFields(0);
pField = pFields->GetField(iIndex);
csValue = pField->GetValueAsString();
if ( m_pRender->GetCount() >= 1000 )
{
::MessageBox(NULL,L"Number of Classify does over 1000!",L"Tips",MB_OK);
m_pRender->Clear();
m_ListLegend.DeleteAllItems();
break;
}
render.csValue = csValue;
render.clr = RGB(MapRand(255),MapRand(255),MapRand(255));
m_pRender->Add(render);
(m_pLayer->GetRecordSet())->MoveNext();
}
for ( i = 0 ; i < m_pRender->GetCount() ; i++ )
{
pRender = m_pRender->GetByIndex(i);
csValue = pRender->csValue;
/*
lvItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
lvItem.state = 0;
lvItem.stateMask = 0;
lvItem.iItem = iMItem++; //項目索引
lvItem.iSubItem =0;
lvItem.pszText = csValue.GetBuffer(0);
lvItem.cchTextMax =255;
*/
m_ListLegend.InsertItem(i,csValue);
}
m_pRender->SetRenderType(UNIQUE_RENDER);
}
void CUniqueFillDlg::OnOK()
{
CMapRender* pRender;
CRect rc;
if ( m_pRender != NULL )
{
pRender = new CMapRender;
ASSERT(pRender != NULL );
m_pRender->Clone(pRender);
m_pLayer->SetRender(pRender);
}
CDialog::OnOK();
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -