📄 viewmap.cpp
字号:
/////////////////////////////////////////////////////////////////////////////
void CViewMap::SetCopyRect(CDC* pDC)
{
CSize sz = pDC->GetTextExtent("ABC");
m_rect.top = sz.cy*2;
m_rect.bottom = min((m_rect.bottom * 9) / 10, m_rect.bottom - sz.cy *3);
DetermineAspect(pDC);
};
/////////////////////////////////////////////////////////////////////////////
// CViewMap printing
BOOL CViewMap::OnPreparePrinting(CPrintInfo* pInfo)
{
pInfo->SetMaxPage(1);
// default preparation
return DoPreparePrinting(pInfo);
}
void CViewMap::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* pInfo)
{
pInfo->m_nNumPreviewPages = 1;
}
void CViewMap::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
m_nCurPage = 0;
GetClientRect(&m_rect);
DetermineAspect();
}
/////////////////////////////////////////////////////////////////////////////
void CViewMap::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
m_rectP = pInfo->m_rectDraw;
InitPrint(pDC);
m_nCurPage = pInfo->m_nCurPage;
CBDView::OnPrint(pDC, pInfo);
}
/////////////////////////////////////////////////////////////////////////////
void CViewMap::InitPrint(CDC* pDC)
{
LOGFONT lf;
CFont font, fontT;
// Retrieve the default layout
m_pDoc->GetLayers()->SetMapLayout(BDGetApp()->GetLayout().GetDefault());
// Determine the offset so that the left and right hand margins are the
// same size
m_nWidth = pDC->GetDeviceCaps(PHYSICALWIDTH);
m_nHeight = pDC->GetDeviceCaps(PHYSICALHEIGHT);
// Layout mode
if (m_nWidth == 0 && m_nHeight == 0)
{
m_nWidth = m_rectP.Width();
m_nHeight = m_rectP.Height();
}
// Determine font height. This is performed after the width and
// height are calculated as these parameters are used for layout
// and saving the image
memset(&lf,0,sizeof(LOGFONT));
lf.lfHeight = -8;
lf.lfPitchAndFamily = 12;
lf.lfCharSet = NRDB_CHARSET;
strcpy(lf.lfFaceName, BDString(IDS_DEFAULTFONT));
ScaleFont(pDC, &lf);
font.CreateFontIndirect(&lf);
CFont* pFontOld = pDC->SelectObject(&font);
CSize sz = pDC->GetTextExtent("ABC");
pDC->SelectObject(pFontOld);
int nOffSetXL = pDC->GetDeviceCaps(PHYSICALOFFSETX);
int nOffSetXR = m_nWidth - m_rectP.Width() - nOffSetXL;
int nOffSetX = max(nOffSetXL, nOffSetXR);
m_rectP.left = m_rectP.left + nOffSetX - nOffSetXL;
// If the layout position is defined then use this
// Determine the rectangle into which to draw the map
if (BDGetApp()->GetLayout().IsAuto())
{
if (m_nHeight > m_nWidth) // Portrait
{
m_rect = m_rectP;
m_rect.left += sz.cy*2;
m_rect.right = m_rect.right - sz.cy*2;
m_rect.top += sz.cy*2;
m_rect.bottom = m_rect.top + (m_rectP.Height()*6)/10;
}
else
{
m_rect = m_rectP;
m_rect.left += sz.cy*2;
m_rect.right = (m_rect.right * 8)/10;
m_rect.top += sz.cy*4;
m_rect.bottom -= sz.cy*5;
};
// Adjust to fit scale on legend
if (m_pDoc->GetLayers()->GetMapGrid().m_nType != CMapGrid::none &&
m_pDoc->GetLayers()->GetMapGrid().m_nType != CMapGrid::defaultgrid)
{
m_rect.left += sz.cx;
m_rect.right -= sz.cx;
}
}
else
{
// Determine map position from active layout
CMapLayoutObj layoutobj = m_pDoc->GetLayers()->GetMapLayout().GetLayoutObj(CMapLayout::map);
CRect rectMap = layoutobj.m_rect;
if (rectMap.Width() > 0)
{
m_rect = CMapLayout::RectFromPercent(m_rectP, rectMap);
}
};
// Adjust the aspect ratio
DetermineAspect(pDC);
}
/////////////////////////////////////////////////////////////////////////////
// CViewMap diagnostics
#ifdef _DEBUG
void CViewMap::AssertValid() const
{
CBDView::AssertValid();
}
void CViewMap::Dump(CDumpContext& dc) const
{
CBDView::Dump(dc);
}
CDocMap* CViewMap::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDocMap)));
return (CDocMap*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CViewMap message handlers
void CViewMap::DrawLogo(CDC* pDC)
{
CRect rect;
CDocMap* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// Retrieve logo info
if (m_sLogoText == "")
{
CBDMain main;
BDMain(BDHandle(), &main, BDGETINIT);
BDEnd(BDHandle());
m_sLogoText = main.m_Organization;
m_sLogoFile = main.m_Logo;
if (m_sLogoFile.Find('\\') == -1) m_sLogoFile = BDGetAppPath() + m_sLogoFile;
m_imagefile.Close();
};
// Load the logo file file
if (!m_imagefile.IsOpen() && m_sLogoFile != "")
{
m_imagefile.m_nWaterColor = 4;
if (!m_imagefile.Open(m_sLogoFile, 0))
{
m_sLogoFile = "";
}
};
// Display logo
if (m_sLogoFile != "")
{
m_imagefile.OnDraw(pDC, m_rect);
}
// If no logo then display default
else
{
CBitmap bitmap, *pBitMapOld;
bitmap.LoadBitmap(IDB_LOGO2);
CDC dc;
dc.CreateCompatibleDC(pDC);
pBitMapOld = dc.SelectObject(&bitmap);
CRect rectS(0,0,299,284);
CRect rectC;
rectC = m_rect;
int nWidth = rectC.Width();
int nHeight = rectC.Height();
// Adjust aspect ratio
if (rectC.bottom == 0 || rectC.right == 0) return;
if ((double)rectS.bottom / nHeight > (double)rectS.right / nWidth)
{
nWidth = (nHeight * rectS.bottom) / rectS.right;
} else
{
nHeight = (nHeight * rectS.right) / rectS.bottom;
}
// Centre to page
rectC.left = m_rect.left + (m_rect.Width() - nWidth) / 2;
rectC.right = rectC.left + nWidth;
rectC.top = m_rect.top + (m_rect.Height() - nHeight) /2;
rectC.bottom = rectC.top + nHeight;
// Copy, nb stretchblt handles changes of palette
pDC->StretchBlt(rectC.left,rectC.top, rectC.Width(), rectC.Height(), &dc, 0,0, rectS.Width(),
rectS.Height(), SRCCOPY);
dc.SelectObject(pBitMapOld);
};
// Create Font
LOGFONT lf;
memset(&lf,0,sizeof(lf));
// Adjust size of font to window area
lf.lfHeight = max(min(40, 40 * m_rect.Height() * m_rect.Width() / 75000), 6);
lf.lfPitchAndFamily = 18;
lf.lfCharSet = NRDB_CHARSET;
strcpy(lf.lfFaceName, BDString(IDS_DEFAULTFONT));
CFont font;
font.CreateFontIndirect(&lf);
// Draw Text
rect = m_rect;
CFont* pFontOld = pDC->SelectObject(&font);
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(192,192,192));
pDC->DrawText(m_sLogoText, &rect, DT_RIGHT|DT_WORDBREAK);
rect.left-=1;
rect.right-=1;
pDC->SetTextColor(RGB(0,0,192));
pDC->DrawText(m_sLogoText, &rect, DT_RIGHT|DT_WORDBREAK);
pDC->SelectObject(pFontOld);
}
/////////////////////////////////////////////////////////////////////////////
void CViewMap::DrawLayers(CDC* pDC)
{
CFont *pFontOld = NULL;
// Select clip region, allowing for different device context in
// print preview mode
CRect rectC = GetScreenRect(pDC);
CRgn rgn;
rgn.CreateRectRgn(rectC.left, rectC.top, rectC.right, rectC.bottom);
pDC->SelectClipRgn(&rgn);
// Draw each layer
for (int i = m_pDoc->GetLayers()->GetSize()-1; i >= 0; i--)
{
CMapLayer* pMapLayer = m_pDoc->GetLayers()->GetAt(i);
if (pMapLayer->IsVisible())
{
// Display objects within the layer
for (int j = 0; j < pMapLayer->GetSize(); j++)
{
CMapLayerObj* pMapLayerObj = pMapLayer->GetAt(j);
ASSERT(pMapLayerObj->GetMapObject() != NULL);
if (m_bAutoUpdate || pDC->IsPrinting() || m_bCopy)
{
// If default layer then check for search match
if (pMapLayerObj != m_pEditMapObj) // Don't draw obj being edited
{
if (pMapLayerObj->GetDataType() == BDMAPLINES)
{
DrawMapLines(pDC, pMapLayerObj, pMapLayer);
}
else if (pMapLayerObj->GetDataType() == BDCOORD)
{
DrawCoords(pDC, pMapLayerObj, pMapLayer);
}
else if (pMapLayerObj->GetDataType() == BDIMAGE)
{
DrawImage(pDC, pMapLayerObj, pMapLayer);
}
};
}
// If autodraw if off then draw extent
else
{
DrawWireFrame(pDC, pMapLayer, pMapLayerObj);
}
};
};
}
m_aRectSym.RemoveAll();
// Draw the text in the reverse order so that the last layers have
// precedence
for (i = 0; i < m_pDoc->GetLayers()->GetSize(); i++)
{
CMapLayer* pMapLayer = m_pDoc->GetLayers()->GetAt(i);
if (pMapLayer->IsVisible())
{
// Create font
CFont font;
LOGFONT lf = pMapLayer->GetFont();
ScaleFont(pDC, &lf);
if (pMapLayer->GetScaleFont())
{
lf.lfHeight = (int)(lf.lfHeight * m_dZoom);
lf.lfWidth = (int)(lf.lfWidth * m_dZoom);
}
font.CreateFontIndirect(&lf);
pFontOld = pDC->SelectObject(&font);
// Draw the text associated with map layers
DrawLineText(pDC, pMapLayer);
// Tidy up
pDC->SelectObject(pFontOld);
};
}
m_aRectText.RemoveAll();
// Clear clip region
pDC->SelectClipRgn(NULL);
// Draw bounding coordinates
DrawCoords(pDC);
// Draw bounding rectangle on print
if (m_pDoc->GetLayers()->GetMapGrid().m_nType != CMapGrid::none)
{
CRect rect = m_rect;
rect.right--;
rect.bottom--;
CMapLayoutObj layoutobj = m_pDoc->GetLayers()->GetMapLayout().GetLayoutObj(CMapLayout::map);
DrawRect(pDC, &rect, layoutobj.m_style.m_crLine, layoutobj.m_style.m_nLineStyle, layoutobj.m_style.m_nLineWidth);
};
// Draw user defined borders
if (pDC->IsPrinting())
{
DrawLayoutBorders(pDC);
DrawLayoutImages(pDC);
DrawLayoutText(pDC);
};
// Draw print specific outputs
if (pDC->IsPrinting())
{
// Draw bounding rectangle
if (BDGetApp()->GetLayout().IsAuto())
{
CRect rect = m_rectP;
rect.right--;
rect.bottom--;
DrawRect(pDC, &rect, RGB(0,0,64), PS_SOLID, 1);
};
// Draw key
// Set extent for calculating font size for images
m_pDoc->GetViewLegend()->SetExtent(m_nWidth, m_nHeight);
m_pDoc->GetViewLegend()->DrawLegend(pDC);
};
// Draw the scale bar on copy
if (m_bCopy)
{
GetClientRect(&m_rectP);
DrawCoords(pDC);
}
}
/////////////////////////////////////////////////////////////////////////////
void CViewMap::DrawMapLines(CDC* pDC, CMapLayerObj* pMapLayerObj, CMapLayer* pMapLayer, BOOL bSearch)
{
CArray <POINT,POINT> aPoints;
CArray <POINT,POINT> aPolyPoints;
CArray <INT,INT> aPolyCounts;
POINT point;
BOOL bNewLine = FALSE;
BOOL bOut;
int nClipped = 0;
CMapStyle mapstyle;
GetStyle(pMapLayer, pMapLayerObj, 0, mapstyle);
// Determine the extent
GetExtent(pMapLayer, pMapLayerObj);
// Optimization: If the extent is outside the current view then no need to draw
if (!IsVisible(pDC, pMapLayerObj)) return;
// Create the pen
if (bSearch)
{
mapstyle.m_crFill = RGB(255,255,255);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -