⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 themedlg.cpp

📁 GIS地理信息系统开发。大名鼎鼎的MAPX+C++软件开发
💻 CPP
字号:
// ThemeDlg.cpp : implementation file
//
/*
 * This sample application and corresponding sample code is provided for 
 * example purposes only.  It has not undergone rigorous testing and as 
 * such should not be shipped as part of a final application without 
 * extensive testing on the part of the organization releasing the 
 * end-user product. 
 */

#include "stdafx.h"
#include "MapTest.h"
#include "ThemeDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CThemeDlg dialog


CThemeDlg::CThemeDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CThemeDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CThemeDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_bMultiVar=FALSE; //Initializes the variables of the ThemeDialog 
	m_pMapX = NULL;
	m_nThemeType = 0;
}


void CThemeDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CThemeDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
	DDX_Control(pDX, IDC_FIELDS, m_ckListBox);
}


BEGIN_MESSAGE_MAP(CThemeDlg, CDialog)
	//{{AFX_MSG_MAP(CThemeDlg)
	ON_CBN_SELCHANGE(IDC_DATASETS, OnSelchangeDatasets)
	ON_CBN_SELCHANGE(IDC_THEMETYPES, OnSelchangeThemetypes)
	//}}AFX_MSG_MAP
	ON_CLBN_CHKCHANGE(IDC_FIELDS, OnCheckChange)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CThemeDlg message handlers



BOOL CThemeDlg::OnInitDialog()//Used for setting up the dialog 
{
	
	CDialog::OnInitDialog();
	ASSERT(m_pMapX);
	
	// add datasets to combo
	// combo is not sorted, so combo index = dataset index
	CComboBox *pDatasetCombo = (CComboBox *)GetDlgItem(IDC_DATASETS);
	ASSERT(pDatasetCombo);
	pDatasetCombo->AddString("<None>");
	try {
		CMapXDatasets dss = m_pMapX->GetDatasets();
		long nCount = dss.GetCount();
								//This section adds the datasets of the map pointed
								//to by m_pMapX, to the combo box holding the datasets
								//on the Theme dialog box.
		for (long i=1; i<=nCount; i++) {
			CMapXDataset ds = dss[i];

			pDatasetCombo->AddString(ds.GetName());//Add the dataset to the combo box
		}
		if (nCount > 0) {
			pDatasetCombo->SetCurSel(1);
		}
	}
	catch (COleDispatchException *e) {
		e->ReportError();
		e->Delete();
	}
	catch (COleException *e) {
		e->ReportError();
		e->Delete();
	}

	CComboBox *pThemeCombo = (CComboBox *)GetDlgItem(IDC_THEMETYPES);
	ASSERT(pThemeCombo);

	pThemeCombo->AddString("Ranged");
	pThemeCombo->AddString("Bar Chart");
	pThemeCombo->AddString("Pie Chart");
	pThemeCombo->AddString("Graduated Symbol");
	pThemeCombo->AddString("Dot Density");
	pThemeCombo->AddString("Individual Value");
	pThemeCombo->AddString("Auto");
	
	pThemeCombo->SetCurSel(6); // auto
	m_nThemeType = 6;
	
	// add dataset fields to listbox
	InitListBox();
	

	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}



void CThemeDlg::OnCheckChange()
{
	int n = m_ckListBox.GetCurSel();//Get the index of the currently selected item
	int num=m_ckListBox.GetCount();//Get the count of the number of items in the list box
	int i;

	if (n == -1)
		return;

	BOOL b = m_ckListBox.GetCheck(n); //Checks to see if item n is checked or not, if it
									  //is then b = 1, else b = 0.
	if (!m_bMultiVar) {
		for (i=0;i<num;i++) { //Set the check box to unchecked for all those not
							  // selected.  This only allows for one field to be checked.
			if(i!=n)
				m_ckListBox.SetCheck(i, 0);
		}
	}
}


void CThemeDlg::OnSelchangeDatasets() 
{
	InitListBox();
}

void CThemeDlg::OnSelchangeThemetypes() 
{
	int n;
	CComboBox *pCombo = (CComboBox *)GetDlgItem(IDC_THEMETYPES);
	n = pCombo->GetCurSel();
	if (n != -1) {
		m_nThemeType = n;
		m_bMultiVar = (m_nThemeType == miThemeBarChart || m_nThemeType == miThemePieChart);
		if (m_bMultiVar){
			AfxMessageBox("For Customer Layer you can only create single variable themes!!");
			pCombo->SetCurSel(6);  //Reset the combo to "auto"
			m_nThemeType = 6;  //Reset the theme type to number 6 "auto
			return;
		}
		if (m_nThemeType == miThemeDotDensity){
			AfxMessageBox("Dot Density doen't work well unless you're working with a Region!!");
			pCombo->SetCurSel(6);	//Reset the combo to "auto"
			m_nThemeType = 6;	//Reset the theme type to number 6 "auto
			return;
		}

		// single var theme
		// make sure only 1 checked
		int num = m_ckListBox.GetCount();
		int i;
		BOOL bFirst=TRUE;
		for (i=0;i<num;i++) {
			if (m_ckListBox.GetCheck(i)) {
				m_ckListBox.SetCheck(i, bFirst);
				bFirst=FALSE;
			}
		}
	}
	
}

void CThemeDlg::InitListBox()
{
	int nDataset = ((CComboBox *)GetDlgItem(IDC_DATASETS))->GetCurSel();
			//Grabs the pointer to the IDC_DATASETS combo box and the currently
			//selected dataset from the list.

	m_ckListBox.ResetContent();		//Remove all the items from the list box

	// no dataset selected		//If there isn't a dataset selected then Return.
	if (nDataset <= 0) {
		return;
	}
	try {
		CMapXDataset ds = m_pMapX->GetDatasets().Item(nDataset);
					//Try to set ds equal to the dataset selected for the map
					// pointed to by m_pMapX.

		CMapXFields flds = ds.GetFields(); //Set flds equal to the fields in ds
		long nFieldCount = flds.GetCount();	//Set nFieldCount equal to the number of
											//fields in fields.

		for (long i=1; i<=nFieldCount; i++) {	//This section places the fields (flds)
			CMapXField fld = flds[i];			//of the dataset into the fields list
												//box.
			int n=m_ckListBox.AddString(fld.GetName());//Add the field to the list box.
			m_ckListBox.SetItemData(n, (DWORD)i);
		}
	}
	catch (COleDispatchException *e) {
		e->ReportError();
		e->Delete();
	}
	catch (COleException *e) {
		e->ReportError();
		e->Delete();
	}
}

void CThemeDlg::OnOK() //In response to the user pushing the "Add" button on the Theme 
						//dialog.
{
	// TODO: Add extra validation here
	
	try {
		COptionalVariant Name;//Declarations of the types needed to create the dataset
		VARIANT Field;
		CMapXFields flds;

		int nDataset = ((CComboBox *)GetDlgItem(IDC_DATASETS))->GetCurSel();
						//nDataset will hold the index of the currently selected dataset

		
		CMapXDataset ds = m_pMapX->GetDatasets().Item(nDataset);
		//Set ds equal to the dataset selected above,  NOTE: all work is done thru the
		//pointer to the original map m_ctrlMapX.

		CMapXFields dsflds = ds.GetFields();//Get the fields from ds.

		// set theme type
		COleVariant Type((long)m_nThemeType);
		
		// create a fields collection of 1 or more fields
		// to create theme on
		int num=m_ckListBox.GetCount();
		long i;

		flds.CreateDispatch(flds.GetClsid());
		for (i=0;i<num;i++) {
			if (m_ckListBox.GetCheck(i)) {
				CMapXField fld = dsflds[i+1L];
				flds.Add(fld.GetName(), fld.GetName());
			}
		}
		if (flds.GetCount() <= 0) {
			// assume we are letting mapx pick field
			if (m_bMultiVar) {
				AfxMessageBox("For Bar and Pie themes, you must choose at least 1 field");
				return;
			}
			Field.vt = VT_ERROR;
			Field.scode = DISP_E_PARAMNOTFOUND;
		}
		else {
			Field.vt = VT_DISPATCH;
			Field.pdispVal = flds.m_lpDispatch;
			Field.pdispVal->AddRef();
		}

		// get themes collection
		CMapXThemes objThemes = ds.GetThemes();

		// add theme - will be visible by default
		CMapXTheme thm = objThemes.Add(Type, Field, Name);

		CMapXThemeProperties thmProps = thm.GetThemeProperties();
					// thmProps holds the Theme Properties for the map pointed to by m_pMapX. (Here it is
					// pointing at m_ctrlMapX.

		if (m_nThemeType == 0)			//If the theme type is 0 or miThemeRanged then
			thmProps.SetNumRanges(2);	//reduce the number of ranges to 2 for visibility
										 	
		
	}
	catch (COleDispatchException *e) {
		e->ReportError();
		e->Delete();
	}
	catch (COleException *e) {
		e->ReportError();
		e->Delete();
	}

	CDialog::OnOK();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -