//! 显示数据集。 BOOL CDrawing::DrawVector(CDC* pDC, OgdcDatasetVector* pDatasetV) { OGDCASSERT(!OGDCIS0(m_dCoordRatio) && !m_rcClient.IsRectEmpty()); OgdcQueryDef queryDef; queryDef.m_nType = OgdcQueryDef::Bounds; queryDef.m_nOptions = OgdcQueryDef::Geometry; queryDef.m_nCursorType = OgdcQueryDef::OpenStatic; queryDef.m_nCursorLocation = OgdcQueryDef::UseClient; queryDef.m_rc2Bounds = m_rcViewBounds; OgdcRect2D rcDtBounds = pDatasetV->GetBounds(); double dSearchArea = m_rcViewBounds.Width() * m_rcViewBounds.Height(); double dDatasetArea = rcDtBounds.Width() * rcDtBounds.Height(); if(dSearchArea >= dDatasetArea*0.6) { queryDef.m_rc2Bounds = rcDtBounds; } OgdcRecordset* pRecordset = pDatasetV->Query(queryDef); if(pRecordset != NULL) { OgdcElement* pElement = NULL; pRecordset->Move(OgdcRecordset::Begin, 0); while(!pRecordset->IsEOF()) { if(pRecordset->GetElement(pElement) && pElement != NULL) { DrawElement(pDC, pElement); } else//断网情况下避免长时间等待 http://192.168.115.2:8090/browse/UGC-4322 { break; } pRecordset->Move(); if(pElement != NULL) { delete pElement; pElement = NULL; } } pDatasetV->ReleaseRecordset(pRecordset); pRecordset = NULL; } return TRUE; }
LONG CViewerWnd::HitTest(const OgdcPoint2D& pntHitTest, OgdcDatasetVector* pDatasetV) { if(!pDatasetV->IsOpen()) { pDatasetV->Open(); } double dTolerance = 3.0*m_drawing.m_dCoordRatio; OgdcQueryDef queryDef; queryDef.m_nType = OgdcQueryDef::Bounds; queryDef.m_nOptions = OgdcQueryDef::Geometry; queryDef.m_nCursorType = OgdcQueryDef::OpenStatic; queryDef.m_nCursorLocation = OgdcQueryDef::UseClient; queryDef.m_rc2Bounds = OgdcRect2D(pntHitTest.x-dTolerance, pntHitTest.y+dTolerance, pntHitTest.x+dTolerance, pntHitTest.y-dTolerance); LONG nSelectID = -1; OgdcRecordset* pRecordset = pDatasetV->Query(queryDef); if(pRecordset != NULL) { pRecordset->Move(OgdcRecordset::End, 0); if (pDatasetV->GetType() == OgdcDataset::PointEPS || pDatasetV->GetType() == OgdcDataset::LineEPS || pDatasetV->GetType() == OgdcDataset::RegionEPS || pDatasetV->GetType() == OgdcDataset::TextEPS) { UGC::UGGeometry* pGeometry = NULL; while(!pRecordset->IsBOF()) { if(pRecordset->GetElement(pGeometry) && pGeometry != NULL) { if (pGeometry->HitTest(pntHitTest, dTolerance)) { nSelectID = pGeometry->GetID(); } if(nSelectID >= 0) { delete pGeometry; pGeometry = NULL; break; } } pRecordset->Move(OgdcRecordset::Current, -1); if(pGeometry != NULL) { delete pGeometry; pGeometry = NULL; } } } else { OgdcElement* pElement = NULL; while(!pRecordset->IsBOF()) { if(pRecordset->GetElement(pElement) && pElement != NULL) { if(pElement->GetType() == OgdcElement::ElemLine) { if(HitTest(pntHitTest, (OgdcElemLine*)pElement, dTolerance)) { nSelectID = pElement->m_nID; } } else if(pElement->GetType() == OgdcElement::ElemRegion) { if(HitTest(pntHitTest, (OgdcElemRegion*)pElement, dTolerance)) { nSelectID = pElement->m_nID; } } else if (pElement->GetType() == OgdcElement::ElemLine3D) { if(HitTest(pntHitTest, (OgdcElemLine3D*)pElement, dTolerance)) { nSelectID = pElement->m_nID; } } else if (pElement->GetType() == OgdcElement::ElemRegion3D) { if(HitTest(pntHitTest, (OgdcElemRegion3D*)pElement, dTolerance)) { nSelectID = pElement->m_nID; } } else { nSelectID = pElement->m_nID; } if(nSelectID >= 0) { delete pElement; pElement = NULL; break; } } pRecordset->Move(OgdcRecordset::Current, -1); if(pElement != NULL) { delete pElement; pElement = NULL; } } } pDatasetV->ReleaseRecordset(pRecordset); pRecordset = NULL; } return nSelectID; }
//! 显示数据 void CViewerWnd::OnDraw(CDC* pDC, const CRect& rcClient) { if((rcClient.Width()<1) || (rcClient.Height()<1)) { return; } if(OGDCIS0(m_drawing.m_dCoordRatio)) { return; } if(m_drawing.m_rcClient != rcClient) { m_drawing.ChangeClient(rcClient); m_bRefresh = TRUE; } OgdcRect2D rcBounds = ComputeBounds(); if(m_drawing.m_rcBounds != rcBounds) { m_drawing.m_rcBounds = rcBounds; m_bRefresh = TRUE; } BOOL bDeviceChange = FALSE; LONG ncxFullScreen = GetSystemMetrics( SM_CXFULLSCREEN ); LONG ncyFullScreen = GetSystemMetrics( SM_CYFULLSCREEN ); if(m_bitmap.m_hObject != NULL) { BITMAP BM; m_bitmap.GetBitmap(&BM); if(BM.bmWidth != ncxFullScreen || BM.bmHeight != ncyFullScreen || pDC->GetDeviceCaps(BITSPIXEL) != BM.bmBitsPixel) { bDeviceChange = TRUE; m_bRefresh = TRUE; } } if(pDC->IsPrinting() || m_bRefresh) { if(!pDC->IsPrinting() && bDeviceChange && m_pOldBitmap != NULL) { m_memDC.SelectObject(m_pOldBitmap); m_pOldBitmap = NULL; m_bitmap.DeleteObject(); m_memDC.DeleteDC(); } if(!pDC->IsPrinting() && m_bitmap.m_hObject == NULL) { m_memDC.CreateCompatibleDC(pDC); if(!m_bitmap.CreateCompatibleBitmap(pDC, ncxFullScreen, ncyFullScreen)) { m_bRefresh = FALSE; return; } m_pOldBitmap = m_memDC.SelectObject(&m_bitmap); } CDC* pDeviceDC = pDC; if(!pDC->IsPrinting()) { pDeviceDC = &m_memDC; } //! 画背景矩形 CBrush brush(RGB(255,255,255)); pDeviceDC->FillRect(rcClient, &brush); //! 画数据 for(int i=0;i<m_datasets.GetSize();i++) { OgdcStyle style = m_styles[i]; OgdcDataset* pDT = m_datasets.GetAt(i); CPen pen(PS_SOLID, style.m_nLineWidth, style.m_clrLine); CPen* pOldPen = pDeviceDC->SelectObject(&pen); CBrush brush(style.m_clrFillFore); CBrush* pOldBrush = NULL; if(style.m_nFillStyle == 1) { pOldBrush = (CBrush*)pDeviceDC->SelectStockObject(NULL_BRUSH); } else { pOldBrush = pDeviceDC->SelectObject(&brush); } m_drawing.m_curStyle = style; m_drawing.DrawDataset(pDeviceDC, m_datasets[i]); pDeviceDC->SelectObject(pOldPen); pDeviceDC->SelectObject(pOldBrush); } m_bRefresh = FALSE; } if(!pDC->IsPrinting() && m_bitmap.m_hObject != NULL) { pDC->BitBlt(rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(), &m_memDC, rcClient.left, rcClient.top, SRCCOPY ); } //! 画选择 if(m_nSelectID >= 0 && m_pSelectDataset != NULL && !pDC->IsPrinting()) { OgdcDatasetVector* pDatasetV = m_pSelectDataset; OgdcQueryDef queryDef; queryDef.m_nType = OgdcQueryDef::IDs; queryDef.m_nOptions = OgdcQueryDef::Geometry; queryDef.m_nCursorType = OgdcQueryDef::OpenStatic; queryDef.m_nCursorLocation = OgdcQueryDef::UseClient; queryDef.m_IDs.Add(m_nSelectID); OgdcRecordset* pRecordset = pDatasetV->Query(queryDef); if(pRecordset != NULL) { pRecordset->Move(OgdcRecordset::End, 0); if (pDatasetV->GetType() == OgdcDataset::PointEPS || pDatasetV->GetType() == OgdcDataset::LineEPS || pDatasetV->GetType() == OgdcDataset::RegionEPS || pDatasetV->GetType() == OgdcDataset::TextEPS) { UGC::UGGeometry* pGeometry = NULL; while(!pRecordset->IsBOF()) { if(pRecordset->GetElement(pGeometry) && pGeometry != NULL) { CPen pen(PS_SOLID, 2, RGB(0,0,255)); CPen* pOldPen = pDC->SelectObject(&pen); CBrush brush(RGB(255,255,115)); CBrush *pOldBrush = pDC->SelectObject(&brush); m_drawing.DrawElement(pDC, pGeometry, true); pDC->SelectObject(pOldPen); pDC->SelectObject(pOldBrush); delete pGeometry; pGeometry = NULL; break; } pRecordset->Move(OgdcRecordset::Current, -1); if(pGeometry != NULL) { delete pGeometry; pGeometry = NULL; } } } else { OgdcElement* pElement = NULL; while(!pRecordset->IsBOF()) { if(pRecordset->GetElement(pElement) && pElement != NULL) { CPen pen(PS_SOLID, 2, RGB(0,0,255)); CPen* pOldPen = pDC->SelectObject(&pen); CBrush brush(RGB(255,255,115)); CBrush *pOldBrush = pDC->SelectObject(&brush); m_drawing.DrawElement(pDC, pElement, true); pDC->SelectObject(pOldPen); pDC->SelectObject(pOldBrush); delete pElement; pElement = NULL; break; } pRecordset->Move(OgdcRecordset::Current, -1); if(pElement != NULL) { delete pElement; pElement = NULL; } } } pDatasetV->ReleaseRecordset(pRecordset); pRecordset = NULL; } } }