📄 pagemaplayerprop.cpp
字号:
//////////////////////////////////////////////////////
//
// NRDB Pro - Spatial database and mapping application
//
// Copyright (c) 1989-2004 Richard D. Alexander
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// NRDB Pro is part of the Natural Resources Database Project
//
// Homepage: http://www.nrdb.co.uk/
// Users' Forum: http://nrdb.mypalawan.info/
//
#include "stdafx.h"
#include <strstrea.h>
#include <io.h>
#include "nrdb.h"
#include "PageMapLayerProp.h"
#include "viewmap.h"
#include "docmap.h"
#include "definitions.h"
#include "sheetmapprop.h"
#include "dlgsavescheme.h"
#include "xmlfile.h"
#include "dlgcolourrange.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
#define SCHEMEFILE "schemes.xml"
/////////////////////////////////////////////////////////////////////////////
inline void swap(double& d1, double& d2)
{
double dTemp = d1;
d1 = d2;
d2 = dTemp;
}
#define HLSMAX 240 /* H,L, and S vary over 0-HLSMAX */
#define RGBMAX 255 /* R,G, and B vary over 0-RGBMAX */
/* HLSMAX BEST IF DIVISIBLE BY 6 */
/* RGBMAX, HLSMAX must each fit in a byte. */
#define UNDEFINED (HLSMAX*2/3)
DWORD HLStoRGB(WORD hue, WORD lum, WORD sat);
/////////////////////////////////////////////////////////////////////////////
// CPageMapLayerProp property page
IMPLEMENT_DYNCREATE(CPageMapLayerProp, CPropertyPage)
CPageMapLayerProp::CPageMapLayerProp()
{
}
CPageMapLayerProp::CPageMapLayerProp(CMapLayer* pMapLayer, CMapProperties* pMapProperty) :
CPropertyPage(CPageMapLayerProp::IDD)
{
m_pMapLayer = pMapLayer;
m_pMapProperty = pMapProperty;
m_bCoord = FALSE;
m_bMapLines = FALSE;
//{{AFX_DATA_INIT(CPageMapLayerProp)
//}}AFX_DATA_INIT
}
CPageMapLayerProp::~CPageMapLayerProp()
{
}
void CPageMapLayerProp::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPageMapLayerProp)
DDX_Control(pDX, IDC_SCHEMEMENU, m_pbSchemeMenu);
DDX_Control(pDX, IDC_COLOURSCHEME, m_cbColourScheme);
DDX_Control(pDX, IDC_AUTOSTYLE, m_cbAutoStyle);
DDX_Control(pDX, IDC_FEATURENAME, m_eFeatureName);
DDX_Control(pDX, IDC_LAYERS, m_lbLayers);
DDX_Control(pDX, IDC_MIN, m_eMin);
DDX_Control(pDX, IDC_MAX, m_eMax);
//DDX_Control(pDX, IDC_COLOR, m_pbColour);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPageMapLayerProp, CPropertyPage)
//{{AFX_MSG_MAP(CPageMapLayerProp)
ON_LBN_SELCHANGE(IDC_LAYERS, OnSelchangeLayers)
ON_EN_CHANGE(IDC_FEATURENAME, OnChangeFeaturename)
ON_NOTIFY(UDN_DELTAPOS, IDC_UPDOWN, OnDeltaposUpdown)
ON_CBN_SELCHANGE(IDC_AUTOSTYLE, OnSelchangeAutostyle)
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_BN_CLICKED(IDC_DELETE, OnDelete)
ON_CBN_SELCHANGE(IDC_COLOURSCHEME, OnSelchangeColourscheme)
ON_COMMAND(ID_SCHEME_SAVE, OnSchemeSave)
ON_COMMAND(ID_SCHEME_DELETE, OnSchemeDelete)
ON_BN_CLICKED(IDC_SCHEMEMENU, OnSchememenu)
//}}AFX_MSG_MAP
ON_COMMAND(ID_ADVANCED, OnAdvanced)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPageMapLayerProp message handlers
BOOL CPageMapLayerProp::OnInitDialog()
{
CPropertyPage::OnInitDialog();
// Scan the map objects to determine which properties to display
for (int i = 0; i < m_pMapLayer->GetSize(); i++)
{
CMapLayerObj* pMapLayerObj = (CMapLayerObj*)m_pMapLayer->GetAt(i);
if (pMapLayerObj->GetDataType() == BDCOORD) m_bCoord = TRUE;
if (pMapLayerObj->GetDataType() == BDMAPLINES) m_bMapLines = TRUE;
}
// Fill list of available styles
int index = m_cbAutoStyle.AddString(BDString(IDS_NONE));
m_cbAutoStyle.SetItemData(index,0);
m_cbAutoStyle.SetCurSel(index);
if (m_bCoord)
{
index = m_cbAutoStyle.AddString(BDString(IDS_AUTOSIZE));
m_cbAutoStyle.SetItemData(index,autosize);
};
index = m_cbAutoStyle.AddString(BDString(IDS_AUTOCOLOR) + " (" + BDString(IDS_LIGHTTODARK) +")");
m_cbAutoStyle.SetItemData(index,autocolor);
index = m_cbAutoStyle.AddString(BDString(IDS_SEPARATECOLOR));
m_cbAutoStyle.SetItemData(index,sepcolor);
index = m_cbAutoStyle.AddString(BDString(IDS_COLORRANGE));
m_cbAutoStyle.SetItemData(index,rangecolor);
index = m_cbAutoStyle.AddString(BDString(IDS_LEGENDVALUES));
m_cbAutoStyle.SetItemData(index,legendvalues);
// Initialise controls
//m_pbColour.SetColour(m_pMapLayer->GetColour());
// Set combo box for style
for (i = 0; i < m_cbAutoStyle.GetCount(); i++)
{
if ((m_cbAutoStyle.GetItemData(i) == autocolor && m_pMapLayer->GetAutoColour() ||
m_cbAutoStyle.GetItemData(i) == autosize && m_pMapLayer->GetAutoSize()) &&
m_pMapLayer->GetAutoMin() < m_pMapLayer->GetAutoMax())
{
m_cbAutoStyle.SetCurSel(i);
}
if (m_cbAutoStyle.GetItemData(i) == sepcolor && (m_pMapLayer->GetSepColour() == CMapLayer::SepColourAttr ||
m_pMapLayer->GetSepColour() == CMapLayer::SepColourFeature))
{
m_cbAutoStyle.SetCurSel(i);
}
if (m_cbAutoStyle.GetItemData(i) == legendvalues && m_pMapLayer->GetSepColour() == CMapLayer::LegendValues)
{
m_cbAutoStyle.SetCurSel(i);
}
if (m_cbAutoStyle.GetItemData(i) == rangecolor && m_pMapLayer->GetRangeColour())
{
m_cbAutoStyle.SetCurSel(i);
}
}
// Initialise auto color / separate color
OnAutocolor();
double dMin = m_pMapLayer->GetAutoMin();
double dMax = m_pMapLayer->GetAutoMax();
if (dMin > dMax) swap(dMin, dMax);
m_eMin.SetValue(dMin);
m_eMax.SetValue(dMax);
m_nSepColour = m_pMapLayer->GetSepColour();
SepColour(TRUE);
RangeColour(TRUE);
// Indicate whether the separate layers list displays symbols or map lines
m_lbLayers.SetMode(m_bCoord ? CViewMap::points : (m_pMapProperty->m_bPolygon ? CViewMap::polygon : CViewMap::polyline));
// Disable for legends
if (!m_bCoord && !m_bMapLines)
{
m_cbAutoStyle.EnableWindow(FALSE);
}
// Initialise colour schemes
InitSchemes();
// Initialise bitmap for scheme load/save
m_bitmapPopup.LoadBitmap(IDB_POPUPMENU);
m_pbSchemeMenu.SetBitmap(m_bitmapPopup);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
/////////////////////////////////////////////////////////////////////////////
void CPageMapLayerProp::OnSelchangeAutostyle()
{
int index = m_cbAutoStyle.GetCurSel();
if (index != CB_ERR)
{
OnAutocolor();
SepColour();
RangeColour();
}
}
/////////////////////////////////////////////////////////////////////////////
void CPageMapLayerProp::OnAutocolor()
{
int index = m_cbAutoStyle.GetCurSel();
ASSERT(index != CB_ERR);
DWORD dw = m_cbAutoStyle.GetItemData(index);
BOOL bAutoColour = dw == autocolor || dw == autosize || dw == ranking;
InitControls();
// Determine default values for maximum and minimum
if (m_pMapLayer->GetSize() > 0)
{
double dMin, dMax;
if (GetMinMax(m_pMapLayer, dMin, dMax))
{
m_eMin.SetValue(dMin);
m_eMax.SetValue(dMax);
};
}
};
/////////////////////////////////////////////////////////////////////////////
BOOL CPageMapLayerProp::GetMinMax(CMapLayer* pMapLayer, double& dMin, double& dMax)
{
dMin = DBL_MAX;
dMax = -DBL_MAX;
for (int j = 0; j < pMapLayer->GetSize(); j++)
{
CMapLayerObj* pMapLayerObj = pMapLayer->GetAt(j);
if (pMapLayerObj->GetValue() != NULL_READING &&
pMapLayerObj->GetValue() != NULL_READING_OLD)
{
dMin = min(dMin, pMapLayerObj->GetValue());
dMax = max(dMax, pMapLayerObj->GetValue());
};
}
if (dMin == DBL_MAX || dMax == AFX_RFX_DOUBLE_PSEUDO_NULL) return FALSE;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
//
// Each feature, within a map layer is to have a separate color
void CPageMapLayerProp::SepColour(BOOL bInit)
{
// Enable the corresponding list box
// Prevent auto color and auto size
int index = m_cbAutoStyle.GetCurSel();
ASSERT(index != CB_ERR);
DWORD dw = m_cbAutoStyle.GetItemData(index);
BOOL bCheck = dw == sepcolor || dw == legendvalues;
InitControls();
// Determine unique colours
if (bCheck)
{
// If list is empty then restore
CColourFeatureArray& aColourFeature = m_pMapProperty->m_aColourFeature;
// Set the default colour scheme
if (m_cbColourScheme.GetCurSel() == CB_ERR) m_cbColourScheme.SetCurSel(0);
if (!bInit)
{
BeginWaitCursor();
aColourFeature.RemoveAll();
// If legend values then just retrieve values
if (dw == legendvalues)
{
m_nSepColour = CMapLayer::LegendValues;
for (int i = 0; i < m_pMapLayer->GetSize(); i++)
{
CMapLayerObj* pMapObj = m_pMapLayer->GetAt(i);
CColourFeature feature;
feature.m_lFeatureId = pMapObj->GetFeature();
if (pMapObj->GetValue() != AFX_RFX_DOUBLE_PSEUDO_NULL)
{
strstream ss;
ss.precision(10);
ss << pMapObj->GetValue() << ends;
feature.m_sAttr = ss.str();
ss.rdbuf()->freeze(0);
};
aColourFeature.Add(feature);
};
}
// Determine the number of unique features, if equal to the
// number of items then sort by attribute
else
{
m_nSepColour = CMapLayer::SepColourFeature;
for (int i = 0; i < m_pMapLayer->GetSize(); i++)
{
CMapLayerObj* pMapObj = m_pMapLayer->GetAt(i);
if (pMapObj->GetValue() != AFX_RFX_DOUBLE_PSEUDO_NULL &&
pMapObj->GetFeature() != 0)
{
break;
}
else if (CString(pMapObj->GetText()) != "")
{
m_nSepColour = CMapLayer::SepColourAttr;
break;
}
}
// Search for unique features / attribute
for (i = 0; i < m_pMapLayer->GetSize(); i++)
{
CMapLayerObj* pMapObj = m_pMapLayer->GetAt(i);
// Search for existing
for (int j = 0; j < aColourFeature.GetSize(); j++)
{
if (m_nSepColour == CMapLayer::SepColourFeature &&
aColourFeature[j].m_lFeatureId == pMapObj->GetFeature() &&
pMapObj->GetFeature() != 0)
{
break;
}
else if (m_nSepColour != CMapLayer::SepColourFeature &&
aColourFeature[j].m_sAttr == pMapObj->GetText())
{
break;
}
}
// Not found then add
if (j == aColourFeature.GetSize())
{
CColourFeature feature;
if (m_nSepColour == CMapLayer::SepColourFeature)
{
feature.m_lFeatureId = pMapObj->GetFeature();
}
else
{
feature.m_sAttr = pMapObj->GetText();
feature.m_sFeature = pMapObj->GetText();
};
aColourFeature.Add(feature);
}
}
};
// Now determine the names of features
if (m_nSepColour == CMapLayer::SepColourFeature ||
m_nSepColour == CMapLayer::LegendValues)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -