📄 viewlegend.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 "nrdb.h"
#include "nrdbpro.h"
#include "ViewLegend.h"
#include "viewmap.h"
#include "projctns.h"
#include "sheetmapprop.h"
#include "comboboxpattern.h"
#include "comboboxsymbol.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
#define RANGESIZE 5
#define COLUMNS 3
#define RANGECOLOR 10
#define SCROLLRANGE 1000
/////////////////////////////////////////////////////////////////////////////
// CViewLegend
IMPLEMENT_DYNCREATE(CViewLegend, CBDView)
CViewLegend::CViewLegend()
{
m_nDragLayer = null;
m_hCursorKey = LoadCursor(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDC_DRAGLAYER));
m_pDoc = NULL;
m_nBottomY = 1;
}
CViewLegend::~CViewLegend()
{
if (m_hCursorKey != NULL) DestroyCursor(m_hCursorKey);
}
BEGIN_MESSAGE_MAP(CViewLegend, CBDView)
//{{AFX_MSG_MAP(CViewLegend)
ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
ON_WM_SIZE()
ON_WM_SETFOCUS()
ON_WM_KILLFOCUS()
ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview)
ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
ON_COMMAND(ID_VIEW_ZOOMIN, OnViewZoomin)
ON_COMMAND(ID_VIEW_ZOOMNORMAL, OnViewZoomnormal)
ON_COMMAND(ID_VIEW_ZOOMOUT, OnViewZoomout)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONDBLCLK()
ON_WM_RBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_MAP_PAN, OnMapPan)
ON_WM_VSCROLL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CViewLegend diagnostics
#ifdef _DEBUG
void CViewLegend::AssertValid() const
{
CBDView::AssertValid();
}
void CViewLegend::Dump(CDumpContext& dc) const
{
CBDView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CViewLegend message handlers
void CViewLegend::OnInitialUpdate()
{
CBDView::OnInitialUpdate();
m_pDoc = (CDocMap*)GetDocument();
// Allow scrolling
ShowScrollBar(SB_VERT);
SetScrollRange(SB_VERT,0,SCROLLRANGE);
}
/////////////////////////////////////////////////////////////////////////////
// CViewLegend drawing
void CViewLegend::OnDraw(CDC* pDC)
{
CFont *pFontOld;
int cyold = 0;
m_bCancel = FALSE;
if (m_pDoc == NULL) return;
m_nColumn = 1;
m_nCols = 1;
m_anLayerPos.RemoveAll();
// Determine properties
LOGFONT lf = m_pDoc->GetLayers()->GetFontL();
ScaleFont(pDC, &lf);
CFont font;
font.CreateFontIndirect(&lf);
pFontOld = pDC->SelectObject(&font);
CSize sz = pDC->GetTextExtent("W");
pDC->SelectObject(pFontOld);
m_nBorder = sz.cy;
m_nTextPos = (m_nBorder*3);
// If editing mode then display instructions
if (GetDoc()->GetViewMap()->m_pMapLinesEdit != NULL ||
GetDoc()->GetViewMap()->m_pMapCoordEdit != NULL ||
GetDoc()->GetViewMap()->m_bDragMode )
{
CFont font;
LOGFONT lf = m_pDoc->GetLayers()->GetFontL();
font.CreateFontIndirect(&lf);
pFontOld = pDC->SelectObject(&font);
int nString = IDS_EDITMAPINST;
if (GetDoc()->GetViewMap()->m_bDragMode) nString = IDS_POINTSEDITINST;
if (GetDoc()->GetViewMap()->m_pMapCoordEdit != NULL) nString = IDS_ADDPOINTINST;
pDC->DrawText(BDString(nString), m_rect, DT_LEFT|DT_WORDBREAK|DT_TOP|DT_NOPREFIX);
pDC->SelectObject(pFontOld);
return;
}
// Set text mode to transparent
pDC->SetBkMode(TRANSPARENT);
if (pDC->IsPrinting())
{
if (BDGetApp()->GetLayout().IsAuto())
{
if (GetDoc()->GetViewMap()->m_nWidth < GetDoc()->GetViewMap()->m_nHeight)
{
m_rect = GetDoc()->GetViewMap()->GetRectPrint();
m_rect.left += m_nBorder;
m_rect.right = m_rect.left + m_rect.Width() - m_nBorder/2;
m_rect.top = GetDoc()->GetViewMap()->GetRect().bottom + sz.cy*4;
} else
{
m_rect = GetDoc()->GetViewMap()->GetRectPrint();
m_rect.left = GetDoc()->GetViewMap()->GetRect().right;
m_rect.right -= m_nBorder;
m_rect.top = GetDoc()->GetViewMap()->GetRect().top;
};
// Make room for the grid labels
if (m_pDoc->GetLayers()->GetMapGrid().m_nType != CMapGrid::none)
{
m_rect.left += m_nBorder * 2;
};
} else
{
// Determine the position for the legend from the layout
CMapLayoutObj layoutobj = GetDoc()->GetLayers()->GetMapLayout().GetLayoutObj(CMapLayout::legend);
CRect rectLegend = layoutobj.m_rect;
if (pDC->IsPrinting() && rectLegend.Width() != 0)
{
m_rect = CMapLayout::RectFromPercent(GetDoc()->GetViewMap()->GetRectPrint(), rectLegend);
//cy = m_rect.top;
}
}
} else
{
GetClientRect(m_rect);
}
// Set top allow for scrolling
int nPos = GetScrollPos(SB_VERT);
int nViewY = (m_nBottomY * nPos)/SCROLLRANGE;
int cy = m_rect.top + m_nBorder - nViewY;
// Draw title
if (m_pDoc->GetLayers()->GetSize() > 0)
{
// Not portrait
if (!pDC->IsPrinting() || GetDoc()->GetViewMap()->m_nWidth > GetDoc()->GetViewMap()->m_nHeight)
{
cy -= m_nBorder;
}
CRect rect;
// Default title position
if (BDGetApp()->GetLayout().IsAuto() || !pDC->IsPrinting())
{
rect.left = m_rect.left + m_nBorder;
rect.right = m_rect.right - m_nBorder;
rect.top = cy;
rect.bottom = rect.top + sz.cy*8;
}
// Custom title position
else
{
CMapLayoutObj layoutobj = GetDoc()->GetLayers()->GetMapLayout().GetLayoutObj(CMapLayout::title);
CRect rectT = layoutobj.m_rect;
if (rectT.Width() > 0 && pDC->IsPrinting())
{
rect = CMapLayout::RectFromPercent(GetDoc()->GetViewMap()->GetRectPrint(), rectT);
}
};
int ny = cy;
ny += GetDoc()->GetViewMap()->DrawTitle(pDC, &rect);
ny += m_nBorder;
if (!pDC->IsPrinting() || BDGetApp()->GetLayout().IsAuto()) cy = ny;
};
// Store layer positions
m_anLayerPos.Add(cy + nViewY);
// Determine the number of columns
if (pDC->IsPrinting())
{
CFont font;
LOGFONT lf = m_pDoc->GetLayers()->GetFontL();
ScaleFont(pDC, &lf);
font.CreateFontIndirect(&lf);
pFontOld = pDC->SelectObject(&font);
CSize sz = pDC->GetTextExtent("abc");
pDC->SelectObject(pFontOld);
m_nCols = max(1,m_rect.Width() / ((sz.cx * 30) / 3));
m_rect.right = m_rect.left + m_rect.Width() / m_nCols;
}
// For each layer, draw its key
for (int i = 0; i < m_pDoc->GetLayers()->GetSize() && !m_bCancel; i++)
{
CMapLayer* pMapLayer = m_pDoc->GetLayers()->GetAt(i);
CMapStyle mapstyle;
CViewMap::GetStyle(pMapLayer, NULL, 0, mapstyle);
if (pMapLayer->IsVisible())
{
cyold = cy;
// Create font
CFont font;
LOGFONT lf = pMapLayer->GetFont();
if (m_pDoc->GetLayers()->GetLegend1Font())
{
lf = m_pDoc->GetLayers()->GetFontL();
}
ScaleFont(pDC, &lf);
font.CreateFontIndirect(&lf);
pFontOld = pDC->SelectObject(&font);
// Determine height of text
CSize sz;
sz = pDC->GetTextExtent(pMapLayer->GetName());
m_nHeight = sz.cy;
// Display objects within the layer
BOOL bCoord = FALSE;
BOOL bMapLines = FALSE;
BOOL bImage = FALSE;
// Determine type of objects selected
for (int j = 0; j < pMapLayer->GetSize(); j++)
{
CMapLayerObj* pMapLayerObj = pMapLayer->GetAt(j);
if (pMapLayerObj->GetDataType() == BDMAPLINES) {bMapLines = TRUE; break;}
else if (pMapLayerObj->GetDataType() == BDCOORD) {bCoord = TRUE; break;}
else if (pMapLayerObj->GetDataType() == BDIMAGE) {bImage = TRUE; break;}
};
// Draw the legend even if this is overidden
if ((pMapLayer->GetSepColour() || pMapLayer->GetRangeColour() ||
pMapLayer->GetAutoColour() || pMapLayer->GetAutoSize()) &&
pMapLayer->IsShowLayerName())
{
DrawText(pDC, m_rect.left + m_nBorder, cy, pMapLayer->GetName());
}
// Draw appropriate legend
if (pMapLayer->GetSepColour())
{
if (!m_pDoc->GetLayers()->GetLegend1Font())
{
pDC->SetTextColor(pMapLayer->GetTextColour());
};
for (int k = 0; k < pMapLayer->GetMapProp().m_aColourFeature.GetSize(); k++)
{
CColourFeature &rColourFeature = pMapLayer->GetMapProp().m_aColourFeature.GetAt(k);
CMapStyle mapstyle = rColourFeature;
CString s = rColourFeature.m_sFeature;
CString s1 = rColourFeature.m_sAttr;
s.TrimRight();
if (pMapLayer->GetSepColour() == CMapLayer::LegendValues)
{
DrawLegendValues(pDC, pMapLayer, cy, s + "\n" + s1, mapstyle);
} else
{
if (s == "") s = " "; // Ensure space
if (bMapLines)
{
if (!DrawMapLineLegend(pDC, pMapLayer, cy, s, mapstyle)) break;
}
if (bCoord)
{
if (!DrawCoordLegend(pDC, pMapLayer, cy, s, mapstyle)) break;
}
};
}
}
// Range color
else if (pMapLayer->GetRangeColour())
{
// Draw title
if (!m_pDoc->GetLayers()->GetLegend1Font())
{
pDC->SetTextColor(pMapLayer->GetTextColour());
};
CRangeColourArray& aRangeColour = pMapLayer->GetMapProp().m_aRangeColour;
for (int k = 0; k < aRangeColour.GetSize(); k++)
{
CString s = aRangeColour.GetDesc(k);
CMapStyle mapstyle = aRangeColour[k];
if (bMapLines) DrawMapLineLegend(pDC, pMapLayer, cy, s, mapstyle);
if (bCoord) DrawCoordLegend(pDC, pMapLayer, cy, s, mapstyle);
}
}
// Draw auto color
else if (pMapLayer->GetAutoColour() || pMapLayer->GetAutoSize())
{
if (pMapLayer->GetAutoSize())
{
DrawAutoSize(pDC, pMapLayer, cy);
} else
{
DrawAutoColour(pDC, pMapLayer, cy, mapstyle);
}
DrawAutoScale(pDC, pMapLayer, cy);
}
else if (pMapLayer->IsShowLayerName())
{
// If no style then just draw layer name and line or symbol
if (bMapLines) DrawMapLineLegend(pDC, pMapLayer, cy, NULL, mapstyle);
if (bCoord) DrawCoordLegend(pDC, pMapLayer, cy, NULL, mapstyle);
};
// If no lines then display a symbol
if (pMapLayer->GetSize() == 0 || bImage)
{
DrawCoordLegend(pDC, pMapLayer, cy, NULL, mapstyle);
}
// Draw border around active layer
if (!pDC->IsPrinting() && !m_bCopy &&
i == m_pDoc->GetLayers()->GetDefault())
{
CRect rect = m_rect;
rect.top = cyold;
rect.bottom = cy;
DrawBorder(pDC, rect);
}
pDC->SelectObject(pFontOld);
};
// Store layer positions (include invisible layers)
m_anLayerPos.Add(cy + nViewY);
}
// Draw the projection (unless already off edge of screen in automatic layout)
if (m_pDoc->GetLayers()->GetSize() > 0 && (!m_bCancel || (!BDGetApp()->GetLayout().IsAuto() && pDC->IsPrinting())))
{
DrawProjection(pDC, cy);
// Scale e.g. 1:50,000
DrawScale(pDC, cy);
// Scale bar
DrawScaleBar(pDC, cy);
DrawComments(pDC, cy);
};
// Draw the north arrow
if (m_pDoc->GetLayers()->GetSize() > 0)
{
DrawNorthArrow(pDC, cy);
};
// If portrait, draw a box around the legend
if (pDC->IsPrinting())
{
CMapLayoutObj layoutobj = GetDoc()->GetLayers()->GetMapLayout().GetLayoutObj(CMapLayout::legend);
CRect rectLegend = layoutobj.m_rect;
if (rectLegend.Width() == 0)
{
if (GetDoc()->GetViewMap()->m_nWidth < GetDoc()->GetViewMap()->m_nHeight)
{
CRect rect;
rect.left = GetDoc()->GetViewMap()->GetRectPrint().left + m_nBorder;
rect.right = GetDoc()->GetViewMap()->GetRectPrint().right - m_nBorder;
rect.top = m_rect.top;
rect.bottom = m_rect.bottom - m_nBorder;
DrawBorder(pDC, rect, PS_SOLID, 1, RGB(0,0,0));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -