QGISView.cpp
资源名称:QGIS.rar [点击查看]
上传用户:oybseng
上传日期:2015-04-27
资源大小:7831k
文件大小:83k
源码类别:
GDI/图象编程
开发平台:
Visual C++
- // QGISView.cpp : implementation of the CQGISView class
- //
- #include "stdafx.h"
- #include "QGIS.h"
- #include "math.h"
- #include "MainFrm.h"
- #include "QGISDoc.h"
- #include "QGISView.h"
- #include "include/Resource.h"
- #include "QObjects/include/Resource.h"
- #include "QObjects/include/QBaseObj.h"
- #include "QObjects/include/QMapObj.h"
- #include "QObjects/include/QLayerObj.h"
- #include "QObjects/include/QPointObj.h"
- #include "QObjects/include/QLineObj.h"
- #include "QObjects/include/QCoordSys.h"
- #include "QObjects/include/QSelObjManager.h"
- #include "QObjects/include/QLineObj.h"
- #include "QObjects/include/QGISAlgorithmLib.h"
- #include "QObjects/include/QGlobalObj.h"
- #include "QDlg/DlgLayerManager.h"
- #include "QDlg/qdlgptattset.h"
- #include "QDlg/dlgmapattset.h"
- #include "QDlg/DlgLineAttSet.h"
- #include "QDlg/DlgLineBeThin.h"
- #include "QDlg/QDlgTextSet.h"
- #include "QObjects/include/QTextObj.h"
- #include "QReadExcelToMap.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- // extern int g_nPixelsPerInchX;
- // extern int g_nPixelsPerInchY;
- // extern double g_fEffectiveDistance;
- /////////////////////////////////////////////////////////////////////////////
- // CQGISView
- IMPLEMENT_DYNCREATE(CQGISView, CView)
- BEGIN_MESSAGE_MAP(CQGISView, CView)
- //{{AFX_MSG_MAP(CQGISView)
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONUP()
- ON_WM_MOUSEMOVE()
- ON_WM_RBUTTONDOWN()
- ON_WM_CANCELMODE()
- ON_COMMAND(IDM_MENU_ADD_LINE_QGIS, OnMenuAddLineQgis)
- ON_COMMAND(IDM_MENU_ADD_POINT_QGIS, OnMenuAddPointQgis)
- ON_WM_SETCURSOR()
- ON_COMMAND(IDM_MENU_SET_MAP_ATT, OnMenuSetMapAtt)
- ON_WM_SIZE()
- ON_COMMAND(IDM_MENU_PT_SELECT_OBJ_QGIS, OnMenuPtSelectObjQgis)
- ON_WM_TIMER()
- ON_COMMAND(IDM_MENU_USELECT_OBJ_QGIS, OnMenuUselectObjQgis)
- ON_COMMAND(IDM_MENU_LINE_ATT_SET, OnMenuLineAttSet)
- ON_UPDATE_COMMAND_UI(IDM_MENU_LINE_ATT_SET, OnUpdateMenuLineAttSet)
- ON_COMMAND(IDM_MENU_RECT_SELECT_OBJ_QGIS, OnMenuRectSelectObjQgis)
- ON_COMMAND(IDM_MENU_DELETE_OBJ_QGIS, OnMenuDeleteObjQgis)
- ON_COMMAND(IDM_MENU_ADD_POLYLINE, OnMenuAddPolyline)
- ON_COMMAND(ID_EDIT_BUTTON_ARROW, OnEditButtonArrow)
- ON_COMMAND(IDM_MENU_MOVE_OBJ_QGIS, OnMenuMoveObjQgis)
- ON_UPDATE_COMMAND_UI(IDM_MENU_MOVE_OBJ_QGIS, OnUpdateMenuMoveObjQgis)
- ON_COMMAND(IDM_MENU_HIDE_OBJ_QGIS, OnMenuHideObjQgis)
- ON_UPDATE_COMMAND_UI(IDM_MENU_HIDE_OBJ_QGIS, OnUpdateMenuHideObjQgis)
- ON_COMMAND(IDM_MENU_SHOW_OBJ_QGIS, OnMenuShowObjQgis)
- ON_COMMAND(IDM_MENU_ROTATE_OBJ_QGIS, OnMenuRotateObjQgis)
- ON_UPDATE_COMMAND_UI(IDM_MENU_ROTATE_OBJ_QGIS, OnUpdateMenuRotateObjQgis)
- ON_COMMAND(IDM_MENU_CUT_LINE_QGIS, OnMenuCutLineQgis)
- ON_UPDATE_COMMAND_UI(IDM_MENU_CUT_LINE_QGIS, OnUpdateMenuCutLineQgis)
- ON_COMMAND(IDM_MENU_DELETE_LINE_QGIS, OnMenuDeleteLineQgis)
- ON_UPDATE_COMMAND_UI(IDM_MENU_DELETE_LINE_QGIS, OnUpdateMenuDeleteLineQgis)
- ON_COMMAND(IDM_MENU_MOVE_LINE_QGIS, OnMenuMoveLineQgis)
- ON_UPDATE_COMMAND_UI(IDM_MENU_MOVE_LINE_QGIS, OnUpdateMenuMoveLineQgis)
- ON_UPDATE_COMMAND_UI(IDM_MENU_ROTATE_LINE_QGIS, OnUpdateMenuRotateLineQgis)
- ON_COMMAND(IDM_MENU_ROTATE_LINE_QGIS, OnMenuRotateLineQgis)
- ON_COMMAND(IDM_MENU_LINK_LINE_QGIS_, OnMenuLinkLineQgis)
- ON_COMMAND(IDM_MENU_MIRROR_LINE_X_QGIS, OnMenuMirrorLineXQgis)
- ON_COMMAND(IDM_MENU_MIRROR_LINE_Y_QGIS, OnMenuMirrorLineYQgis)
- ON_COMMAND(IDM_MENU_MIRROR_O_QGIS, OnMenuMirrorOQgis)
- ON_COMMAND(IDM_MENU_ADD_RECT_QGIS, OnMenuAddRectQgis)
- ON_COMMAND(IDM_MENU_LAYER_MANAGER_QGIS, OnMenuLayerManagerQgis)
- ON_COMMAND(IDM_MENU_ADD_CIRCLE_QGIS, OnMenuAddCircleQgis)
- ON_COMMAND(IDM_MENU_ADD_ELLIPSE_QGIS, OnMenuAddEllipseQgis)
- ON_UPDATE_COMMAND_UI(IDM_MENU_POINT_ATTSET_QGIS, OnUpdateMenuPointAttsetQgis)
- ON_COMMAND(IDM_MENU_POINT_ATTSET_QGIS, OnMenuPointAttsetQgis)
- ON_COMMAND(IDM_MENU_LINK_POINT_TO_LINE_QGIS, OnMenuLinkPointToLineQgis)
- ON_COMMAND(IDM_MENU_ADD_POLYLINE_STREAM, OnMenuAddPolylineStream)
- ON_COMMAND(IDM_MENU_REFRESH_VIEW, OnMenuRefreshView)
- ON_COMMAND(IDM_MENU_DRAW_ALLOBJ_IN_VIEW, OnMenuDrawAllobjInView)
- ON_COMMAND(ID_MENU_MOVE_MAP, OnMenuMoveMap)
- ON_COMMAND(IDM_MENU_AXIS_QGIS, OnMenuAxisQgis)
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- ON_UPDATE_COMMAND_UI(ID_MENU_INTERPRETATION_CURVE, &CQGISView::OnUpdateMenuInterpretationCurve)
- ON_UPDATE_COMMAND_UI(ID_MENU_TWICE_BCURVE, &CQGISView::OnUpdateMenuTwiceBcurve)
- ON_UPDATE_COMMAND_UI(ID_MENU_THIRD_BCURVE, &CQGISView::OnUpdateMenuThirdBcurve)
- ON_COMMAND(ID_MENU_INTERPRETATION_CURVE, &CQGISView::OnMenuInterpretationCurve)
- ON_COMMAND(ID_MENU_TWICE_BCURVE, &CQGISView::OnMenuTwiceBcurve)
- ON_COMMAND(ID_MENU_THIRD_BCURVE, &CQGISView::OnMenuThirdBcurve)
- ON_COMMAND(IDM_MENU_SELECT_POINT_QGIS, &CQGISView::OnMenuSelectPointQgis)
- ON_COMMAND(IDM_MENU_PT_LINK_TO_LINE_QGIS, &CQGISView::OnMenuPtLinkToLineQgis)
- ON_UPDATE_COMMAND_UI(IDM_MENU_PT_LINK_TO_LINE_QGIS, &CQGISView::OnUpdateMenuPtLinkToLineQgis)
- ON_COMMAND(ID_MENU_ADD_VERVICAL_LINE_QGIS, &CQGISView::OnMenuAddVervicalLineQgis)
- ON_COMMAND(ID_MENU_ADD_HORI_LINE_QGIS, &CQGISView::OnMenuAddHoriLineQgis)
- ON_COMMAND(ID_DGLSPK_LINE_GETPT_QGIS, &CQGISView::OnDglspkLineGetptQgis)
- ON_UPDATE_COMMAND_UI(ID_DGLSPK_LINE_GETPT_QGIS, &CQGISView::OnUpdateDglspkLineGetptQgis)
- ON_COMMAND(ID_MENU_ADD_TEXT_QGIS, &CQGISView::OnMenuAddTextQgis)
- ON_COMMAND(IDM_MENU_TEXT_PARA_SET, &CQGISView::OnMenuTextParaSet)
- ON_COMMAND(ID_MENU_READ_EXCEL_QGIS, &CQGISView::OnMenuReadExcelQgis)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CQGISView construction/destruction
- CQGISView::CQGISView()
- {
- // TODO: add construction code here
- m_nLbtDown = 0;
- m_ptBegin = CQPoint(0,0);
- m_ptOld = CQPoint(0,0);
- m_ptEnd = CQPoint(0,0);
- m_bDrawAxis = FALSE;
- m_nSelectType = QGIS_SELECT_UNKNOWN;
- }
- CQGISView::~CQGISView()
- {
- m_nLbtDown = 0;
- m_bDrawAxis = FALSE;
- m_nSelectType = QGIS_SELECT_UNKNOWN;
- }
- BOOL CQGISView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CQGISView drawing
- void CQGISView::OnDraw(CDC* pDC)
- {
- CQGISDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- CQCoordSys * pSys = pDoc->m_pMap->GetCoordSysPointer();
- ASSERT_VALID(pSys);
- g_QObj.g_nPixelsPerInchX = pDC->GetDeviceCaps(LOGPIXELSX);
- g_QObj.g_nPixelsPerInchY = pDC->GetDeviceCaps(LOGPIXELSY);
- COLORREF cl = RGB(0,0,255);
- CQMapObj * pMap = pDoc->m_pMap;
- pMap->Display(pSys,pDC,R2_COPYPEN,0,&cl);
- long lWndX = 0,lWndY = 0;
- //DrawAxis(m_bDrawAxis,pDC,lWndX,lWndY);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CQGISView printing
- BOOL CQGISView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CQGISView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CQGISView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CQGISView diagnostics
- #ifdef _DEBUG
- void CQGISView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CQGISView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CQGISDoc* CQGISView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CQGISDoc)));
- return (CQGISDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CQGISView message handlers
- void CQGISView::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- ASSERT(pDoc);
- CQMapObj * pMap = pDoc->m_pMap;
- ASSERT(pMap);
- CQCoordSys * pCoordSys = pMap->GetCoordSysPointer();
- ASSERT(pCoordSys);
- CDC * pDC = GetDC();
- CQSelObjManager * pSM = pMap->GetSelObjManager();
- ASSERT(pSM);
- CQPoint ptWorld;
- pCoordSys->LPtoWP(point,&ptWorld);
- static int nDrawEllipseTimes = 0; //绘制椭圆的次数
- //在第一次绘制椭圆的时候会弹出对话框,提示如何绘制
- switch(pDoc->m_MenuItemID)
- {
- case IDM_MENU_ADD_POINT_QGIS: //添加点图元
- {
- CQPointObj * ptObj = new CQPointObj(ptWorld);
- ptObj->SetObjMapID(pMap->GetMapID());
- ptObj->SetObjLayerID(pMap->GetCurLayer()->GetLayerID());
- CBoundaryRect BRect;
- ptObj->GetBoundingRect(&BRect);
- pMap->AddObject(ptObj);
- CRect rect;
- pCoordSys->WPtoLP(BRect,&rect);
- InvalidateRect(rect);
- break;
- }
- case IDM_MENU_ADD_LINE_QGIS: //添加线图元 两点直线 非折线对象 折线对象需要通过右键结束操作
- {
- if(m_nLbtDown == 0) //当鼠标第一次点击
- {
- SetCapture(); //捕捉鼠标指针
- m_ptBegin = ptWorld;
- m_ptOld = ptWorld;
- m_ptEnd = ptWorld;
- m_nLbtDown++;
- }
- else
- {
- m_nLbtDown = 0;
- m_ptEnd = ptWorld;
- CQLineObj * pLine = new CQLineObj;
- pLine->SetObjMapID(pMap->GetMapID());
- pLine->SetObjLayerID(pMap->GetCurLayer()->GetLayerID());
- pLine->m_PtList.AddPoint(&m_ptBegin);
- pLine->m_PtList.AddPoint(&m_ptEnd);
- int n = pLine->m_PtList.GetSize();
- CBoundaryRect BRect;
- CRect rect;
- pLine->CalculateBoundary(&BRect);
- pMap->AddObject(pLine);
- pCoordSys->WPtoLP(BRect,&rect);
- InvalidateRect(rect,TRUE);
- ReleaseCapture();
- }
- break;
- }
- case IDM_MENU_PT_SELECT_OBJ_QGIS: // 鼠标点选对象
- {
- if(m_nLbtDown==0)
- {
- m_ptBegin = ptWorld;
- m_nLbtDown++;
- }
- break;
- }
- case IDM_MENU_RECT_SELECT_OBJ_QGIS: //矩形选择
- {
- if(m_nLbtDown == 0)
- {
- m_ptBegin = ptWorld;
- m_ptOld = ptWorld;
- m_nLbtDown++;
- }
- break;
- }
- case IDM_MENU_ADD_POLYLINE: //添加折线
- {
- if(m_nLbtDown == 0)
- {
- m_ptBegin = ptWorld;
- m_ptOld = ptWorld;
- m_ptEnd = ptWorld;
- m_nLbtDown++;
- m_ptArray.DeleteAll();
- m_ptArray.AddPoint(m_ptBegin.GetX(),m_ptBegin.GetY());
- SetCapture();
- }
- else
- {
- if(m_ptBegin != ptWorld)
- {
- m_ptBegin = ptWorld;
- m_ptOld = ptWorld;
- m_ptEnd = ptWorld;
- m_ptArray.AddPoint(ptWorld.GetX(),ptWorld.GetY());
- m_nLbtDown++;
- }
- }
- break;
- }
- case IDM_MENU_MOVE_LINE_QGIS:
- case IDM_MENU_MOVE_OBJ_QGIS:
- {
- if(pSM->GetSelObjCount()<=0)break;
- if(m_nLbtDown == 0)
- {
- m_ptBegin = ptWorld;
- m_ptOld = ptWorld;
- m_nLbtDown++;
- SetCapture();
- }
- else
- {
- double dx = ptWorld.GetX() - m_ptBegin.GetX();
- double dy = ptWorld.GetY() - m_ptBegin.GetY();
- int nSelObj = pSM->GetSelObjCount();
- POSITION pos = pSM->GetHeadPosition();
- while (pos)
- {
- CQBaseObj * pObj = pSM->GetNext(pos);
- COLORREF cl = pObj->GetObjPenColor();
- if(pObj && !pObj->GetObjDeleted() && !pObj->GetObjHided())
- {
- pObj->Display(pCoordSys,pDC,R2_COPYPEN,0,&cl);
- }
- }
- m_nLbtDown = 0;
- ReleaseCapture();
- InvalidateRect(NULL,TRUE);
- }
- break;
- }
- case IDM_MENU_ROTATE_LINE_QGIS:
- case IDM_MENU_ROTATE_OBJ_QGIS: //图元的旋转
- {
- if(m_nLbtDown == 0) //第一次鼠标电击 记录点位坐标
- {
- m_ptBegin = ptWorld;
- m_ptOld = ptWorld;
- m_ptEnd = ptWorld;
- SetCapture();
- m_nLbtDown++;
- }
- else
- {
- POSITION pos = pSM->GetHeadPosition();
- while (pos)
- {
- CQBaseObj * pObj = pSM->GetNext(pos);
- COLORREF cl = pObj->GetObjPenColor();
- if(pObj && !pObj->GetObjDeleted() && !pObj->GetObjHided())
- {
- pObj->Display(pCoordSys,pDC,R2_COPYPEN,0,&cl);
- }
- }
- m_nLbtDown = 0;
- ReleaseCapture();
- InvalidateRect(NULL,TRUE);
- }
- break;
- }
- case IDM_MENU_CUT_LINE_QGIS: //剪断线
- {
- if(m_nLbtDown == 0)
- {
- m_ptBegin = ptWorld;
- m_nLbtDown++;
- SetCapture();
- }
- break;
- }
- case IDM_MENU_MIRROR_LINE_X_QGIS:
- {
- static BOOL bSelected1 = FALSE;
- if(m_nLbtDown == 0) //假如是第一次点击
- {
- m_ptBegin = ptWorld;
- m_nLbtDown++;
- pSM->RemoveAllSelObj();
- if(pMap->Select(pSM,pCoordSys,m_ptBegin,g_QObj.g_fEffectiveDistance))
- {
- pSM->BeginFlash((CWnd *)this,2,1000);
- pSM->FlashObj(pCoordSys,this->GetSafeHwnd());
- bSelected1 = TRUE;
- }
- else
- {
- bSelected1 = FALSE;
- m_nLbtDown = 0;
- }
- }
- else if(m_nLbtDown == 1 && bSelected1)
- {
- m_ptOld = ptWorld;
- m_nLbtDown = 0;
- CQBaseObj * pObj = (CQBaseObj *)pSM->GetCurSelObj();
- if(pObj->GetObjType() != QGIS_OBJ_LINE) break;
- CQLineObj * pOldLine = NULL;
- pOldLine = (CQLineObj *)pObj;
- if(!pOldLine)break;
- CQLineObj * pNewLine = new CQLineObj;
- pOldLine->Mirror(1,m_ptOld,pNewLine);
- if(pNewLine->m_PtList.GetSize()<=1)
- {
- delete pNewLine;
- break; //镜像操作失败
- }
- else
- {
- CQLayerObj * pMirrorLayer = NULL;
- pMirrorLayer = pMap->FindLayer(pOldLine->GetObjLayerID());
- if(!pMirrorLayer)break;
- pNewLine->CalculateBoundary(NULL);
- pMirrorLayer->AddObject(pNewLine);
- pNewLine->SetObjLayerID(pOldLine->GetObjLayerID());
- pNewLine->SetObjMapID(pOldLine->GetObjMapID());
- pSM->EndFlash((CWnd *)this,2);
- }
- Invalidate();
- }
- break;
- }
- case IDM_MENU_MIRROR_LINE_Y_QGIS:
- {
- static BOOL bSelected1 = FALSE;
- if(m_nLbtDown == 0) //假如是第一次点击
- {
- m_ptBegin = ptWorld;
- m_nLbtDown++;
- pSM->RemoveAllSelObj();
- if(pMap->Select(pSM,pCoordSys,m_ptBegin,g_QObj.g_fEffectiveDistance))
- {
- pSM->BeginFlash((CWnd *)this,2,1000);
- pSM->FlashObj(pCoordSys,this->GetSafeHwnd());
- bSelected1 = TRUE;
- }
- else
- {
- bSelected1 = FALSE;
- m_nLbtDown = 0;
- }
- }
- else if(m_nLbtDown == 1 && bSelected1)
- {
- m_ptOld = ptWorld;
- m_nLbtDown = 0;
- CQBaseObj * pObj = (CQBaseObj *)pSM->GetCurSelObj();
- if(pObj->GetObjType() != QGIS_OBJ_LINE) break;
- CQLineObj * pOldLine = NULL;
- pOldLine = (CQLineObj *)pObj;
- if(!pOldLine)break;
- CQLineObj * pNewLine = new CQLineObj;
- pOldLine->Mirror(0,m_ptOld,pNewLine);
- if(pNewLine->m_PtList.GetSize()<=1)
- {
- delete pNewLine;
- break; //镜像操作失败
- }
- else
- {
- CQLayerObj * pMirrorLayer = NULL;
- pMirrorLayer = pMap->FindLayer(pOldLine->GetObjLayerID());
- if(!pMirrorLayer)break;
- pNewLine->CalculateBoundary(NULL);
- pMirrorLayer->AddObject(pNewLine);
- pNewLine->SetObjLayerID(pOldLine->GetObjLayerID());
- pNewLine->SetObjMapID(pOldLine->GetObjMapID());
- pSM->EndFlash((CWnd *)this,2);
- }
- Invalidate();
- }
- break;
- }
- case IDM_MENU_MIRROR_O_QGIS:
- {
- static BOOL bSelected1 = FALSE;
- if(m_nLbtDown == 0) //假如是第一次点击
- {
- m_ptBegin = ptWorld;
- m_nLbtDown++;
- pSM->RemoveAllSelObj();
- if(pMap->Select(pSM,pCoordSys,m_ptBegin,g_QObj.g_fEffectiveDistance))
- {
- pSM->BeginFlash((CWnd *)this,2,1000);
- pSM->FlashObj(pCoordSys,this->GetSafeHwnd());
- bSelected1 = TRUE;
- }
- else
- {
- bSelected1 = FALSE;
- m_nLbtDown = 0;
- }
- }
- else if(m_nLbtDown == 1 && bSelected1)
- {
- m_ptOld = ptWorld;
- m_nLbtDown = 0;
- CQBaseObj * pObj = (CQBaseObj *)pSM->GetCurSelObj();
- if(pObj->GetObjType() != QGIS_OBJ_LINE) break;
- CQLineObj * pOldLine = NULL;
- pOldLine = (CQLineObj *)pObj;
- if(!pOldLine)break;
- CQLineObj * pNewLine = new CQLineObj;
- pOldLine->Mirror(2,m_ptOld,pNewLine);
- if(pNewLine->m_PtList.GetSize()<=1)
- {
- delete pNewLine;
- break; //镜像操作失败
- }
- else
- {
- CQLayerObj * pMirrorLayer = NULL;
- pMirrorLayer = pMap->FindLayer(pOldLine->GetObjLayerID());
- if(!pMirrorLayer)break;
- pNewLine->CalculateBoundary(NULL);
- pMirrorLayer->AddObject(pNewLine);
- pNewLine->SetObjLayerID(pOldLine->GetObjLayerID());
- pNewLine->SetObjMapID(pOldLine->GetObjMapID());
- pSM->EndFlash((CWnd *)this,2);
- }
- Invalidate();
- }
- break;
- }
- case IDM_MENU_LINK_LINE_QGIS_: //连接线
- {
- static BOOL bSelected1 = FALSE;
- if(m_nLbtDown == 0) //假如是第一次点击
- {
- m_ptBegin = ptWorld;
- m_nLbtDown++;
- pSM->RemoveAllSelObj();
- if(pMap->Select(pSM,pCoordSys,m_ptBegin,g_QObj.g_fEffectiveDistance))
- {
- pSM->BeginFlash((CWnd *)this,2,1000);
- pSM->FlashObj(pCoordSys,this->GetSafeHwnd());
- bSelected1 = TRUE;
- }
- else
- {
- bSelected1 = FALSE;
- m_nLbtDown = 0;
- }
- }
- else if(m_nLbtDown == 1)
- {
- if(bSelected1 == TRUE)
- {
- m_ptOld = ptWorld;
- if(pMap->Select(pSM,pCoordSys,m_ptOld,g_QObj.g_fEffectiveDistance))
- {
- pSM->BeginFlash((CWnd *)this,2,1000);
- pSM->FlashObj(pCoordSys,this->GetSafeHwnd());
- m_nLbtDown = 0;
- int nSelObjCount = pSM->GetSelObjCount();
- if(nSelObjCount != 2)break;
- POSITION pos = pSM->GetHeadPosition();
- CQBaseObj * pObj1 = (CQBaseObj *)pSM->GetNext(pos);
- CQBaseObj * pObj2 = (CQBaseObj *)pSM->GetNext(pos);
- if(pObj1->GetObjType() != QGIS_OBJ_LINE || pObj2->GetObjType() != QGIS_OBJ_LINE)
- {
- break;
- }
- else
- {
- CQLineObj * pLine1 = (CQLineObj *)pObj1;
- CQLineObj * pLine2 = (CQLineObj *)pObj2;
- int nPtNum1 = pLine1->m_PtList.GetSize();
- int nPtNum2 = pLine2->m_PtList.GetSize();
- if(nPtNum1 == 0 || nPtNum2 == 0)break;
- CQPoint * ptEndLine1 = NULL;
- ptEndLine1 = pLine1->m_PtList.GetPoint(nPtNum1-1); // 取得第一条线的终点
- CQPoint * ptBeginLine2 = NULL;
- ptBeginLine2 = pLine2->m_PtList.GetPoint(0);
- CQPoint * ptEndLine2 = NULL;
- ptEndLine2 = pLine2->m_PtList.GetPoint(nPtNum2-1);
- if(!ptEndLine1 || !ptBeginLine2 || !ptEndLine2)break;
- double dDis1 = ptEndLine1->Distance(*ptBeginLine2);
- double dDis2 = ptEndLine1->Distance(*ptEndLine2);
- if(dDis1-dDis2<=1e-5) // 第一条线的终点离第二条线的起点近
- {
- //从第一个点开始装
- int nPtNUm = pLine2->m_PtList.GetSize();
- for(int n=0;n<nPtNUm;n++)
- {
- pLine1->m_PtList.AddPoint(pLine2->m_PtList.GetPoint(n));
- }
- }
- else
- {
- //从最后一个点开始装
- int nptNum = pLine2->m_PtList.GetSize();
- for(int m=nptNum-1;m>=0;m--)
- {
- pLine1->m_PtList.AddPoint(pLine2->m_PtList.GetPoint(m));
- }
- }
- CQLayerObj * pLayer = NULL;
- pLayer = pMap->FindLayer(pLine2->GetObjLayerID());
- if(!pLayer)break;
- pLayer->Deleteobject(pLine2);
- pLine2 = NULL;
- CBoundaryRect Brect;
- pLine1->CalculateBoundary(&Brect);
- CRect rect;
- pCoordSys->WPtoLP(Brect,&rect);
- pSM->EndFlash((CWnd *)this,2);
- InvalidateRect(rect,TRUE);
- }
- }
- }
- }
- break;
- }
- case IDM_MENU_ADD_RECT_QGIS:
- {
- if(m_nLbtDown == 0) //假如是鼠标第一次点击
- {
- m_ptBegin = ptWorld;
- m_ptOld = ptWorld;
- m_ptEnd = ptWorld;
- m_nLbtDown++;
- SetCapture();
- }
- else if(m_nLbtDown == 1)
- {
- m_nLbtDown = 0;
- m_ptEnd = ptWorld;
- if(m_ptEnd != m_ptBegin)
- {
- CQLineObj * pNewLine = new CQLineObj;
- CQPoint pt1,pt2;
- pt1.SetPoint(m_ptBegin.GetX(),m_ptEnd.GetY());
- pt2.SetPoint(m_ptEnd.GetX(),m_ptBegin.GetY());
- pNewLine->m_PtList.AddPoint(&m_ptBegin);
- pNewLine->m_PtList.AddPoint(&pt1);
- pNewLine->m_PtList.AddPoint(&m_ptEnd);
- pNewLine->m_PtList.AddPoint(&pt2);
- pNewLine->m_PtList.AddPoint(&m_ptBegin);
- pNewLine->SetLineClosed(TRUE);
- pNewLine->SetObjMapID(pMap->GetMapID());
- pNewLine->SetObjLayerID(pMap->GetCurLayer()->GetLayerID());
- CBoundaryRect Brect;
- pNewLine->CalculateBoundary(&Brect);
- double dStep = 5.0;
- Brect.Lager(dStep);
- pMap->AddObject(pNewLine);
- CRect rectTemp;
- pCoordSys->WPtoLP(Brect,&rectTemp);
- InvalidateRect(rectTemp,TRUE);
- ReleaseCapture();
- }
- }
- break;
- }
- case IDM_MENU_ADD_CIRCLE_QGIS: //鼠标画圆
- {
- if(m_nLbtDown == 0) //如果是 第一次单击
- {
- m_nLbtDown += 1;
- m_ptBegin = ptWorld;
- m_ptOld = ptWorld;
- m_ptEnd = ptWorld;
- SetCapture(); //捕捉鼠标
- }
- else if(m_nLbtDown == 1 && m_ptBegin != ptWorld)//假如是第二次单击
- {
- m_ptEnd = ptWorld;
- long rCr = (GetEndPos().x - GetBeginPos().x)*(GetEndPos().x - GetBeginPos().x) +
- (GetEndPos().y - GetBeginPos().y)*(GetEndPos().y - GetBeginPos().y);
- rCr = static_cast<long>(sqrt(static_cast<double>(rCr)));
- double fR = pCoordSys->LLtoWL(rCr);
- if(fR>0)
- {
- CQEllipseObj * pCircle = new CQEllipseObj(m_ptBegin.GetX(),m_ptBegin.GetY(),fR,fR,0,2*PI,0);
- pMap->AddObject(pCircle);
- CBoundaryRect bRect;
- pCircle->CalculateBoundary(&bRect);
- bRect.Lager(3);
- CRect rect;
- pCoordSys->WPtoLP(bRect,&rect);
- InvalidateRect(rect,TRUE);
- }
- m_nLbtDown = 0;
- ReleaseCapture();
- break;
- }
- break;
- }
- case IDM_MENU_ADD_ELLIPSE_QGIS:
- {
- if(m_nLbtDown == 0)
- {
- m_nLbtDown++;
- SetCapture();
- m_ptBegin = ptWorld;
- m_ptOld = ptWorld;
- m_ptEnd = ptWorld;
- }
- else if(m_nLbtDown == 1 && m_ptBegin != ptWorld)
- {
- double dx = m_ptBegin.GetX()-ptWorld.GetX();
- double dy = m_ptBegin.GetY()-ptWorld.GetY();
- double fLongAxis = sqrt(dx*dx + dy*dy)/2.0;
- m_Ellipse.SetLongAxis(fLongAxis);
- m_Ellipse.SetShortAxis(fLongAxis); // 在没有调整椭圆形状的时候 先让其形状为圆形
- double dcx = (m_ptBegin.GetX()+ptWorld.GetX())/2.0;
- double dcy = (m_ptBegin.GetY()+ptWorld.GetY())/2.0;
- m_Ellipse.SetCenterPoint(dcx,dcy);
- ptCenter.SetPoint(dcx,dcy);
- m_Ellipse.SetStartAngleRad(0.0f);
- m_Ellipse.SetEndAngleRad(2*PI);
- double fRotateAngle = atan2(dy,dx); //旋转角度
- if(fRotateAngle<0)fRotateAngle+=2*PI;
- else if(fRotateAngle>2*PI) fRotateAngle -= 2*PI;
- m_Ellipse.SetRotateAngleRad(fRotateAngle);
- pDC->SetROP2(R2_NOT);
- m_ptOld.SetPoint(dcx,dcy);
- COLORREF cl = RGB(0,0,0);
- DrawEllipse(m_Ellipse,pDC);
- pDC->MoveTo(GetBeginPos()); //擦除长轴线
- pDC->LineTo(point);
- m_nLbtDown++;
- }
- else if(m_nLbtDown == 2 && ptWorld != ptCenter)
- {
- m_Ellipse.GetCenterPoint(ptCenter);
- double dx = ptCenter.GetX()-ptWorld.GetX();
- double dy = ptCenter.GetY()-ptWorld.GetY(); //确定椭圆短轴
- double fShortAxis = sqrt(dx*dx+dy*dy);
- m_Ellipse.SetShortAxis(fShortAxis);
- double fflag = max(abs(m_ptBegin.GetX()-ptWorld.GetX()),abs(m_ptEnd.GetY()-ptWorld.GetY()));
- if(fflag>0)
- {
- CQEllipseObj * pElipse = NULL;
- pElipse = CreateEllipse(m_Ellipse);
- if(pElipse)
- {
- pMap->AddObject(pElipse);
- CBoundaryRect bRect;
- pElipse->CalculateBoundary(&bRect);
- bRect.Lager(3.0);
- CRect rect;
- pCoordSys->WPtoLP(bRect,&rect);
- InvalidateRect(rect,TRUE);
- m_nLbtDown = 0;
- ReleaseCapture();
- }
- else
- {
- m_nLbtDown = 0;
- ReleaseCapture();
- }
- }
- }
- break;
- }
- case IDM_MENU_ADD_POLYLINE_STREAM: //造流线
- {
- if(m_nLbtDown == 0) //鼠标第一次单击
- {
- m_ptBegin = ptWorld;
- m_ptOld = ptWorld;
- m_ptEnd = ptWorld;
- SetCapture(); //设置鼠标捕捉
- m_ptArray.AddPoint(ptWorld.GetX(),ptWorld.GetY());
- m_nLbtDown++;
- }
- break;
- }
- case ID_MENU_MOVE_MAP:
- {
- if(m_nLbtDown == 0) //假如是第一次单击视图
- {
- ++m_nLbtDown;
- m_ptBegin = ptWorld;
- m_ptOld = ptWorld;
- m_ptEnd = ptWorld;
- m_bDrawAxis = FALSE;
- SetCapture();
- long lOrX,lOrY;
- pCoordSys->GetStartOfWnd(lOrX,lOrY);
- CRect rectAxis = DrawAxis(m_bDrawAxis,pDC,lOrX,lOrY);
- InvalidateRect(rectAxis,TRUE);
- }
- break;
- }
- case IDM_MENU_LINK_POINT_TO_LINE_QGIS: //连点成线
- {
- if(m_nLbtDown == 0) // 第一次点击
- {
- pSM->RemoveAllSelObj(); //清空选择列表
- SetCapture();
- if(pMap->SingleSelect(pSM,pCoordSys,ptWorld,g_QObj.g_fEffectiveDistance,QGIS_OBJ_POINT) == 0)
- {
- m_nLbtDown = 0;
- break;
- }
- else
- {
- m_nLbtDown++;
- CQBaseObj * pObj = pSM->GetCurSelObj();
- if(pObj->GetObjType() == QGIS_OBJ_POINT)
- {
- m_vecObj.push_back(pObj);
- }
- }
- }
- else // 点击一次以上
- {
- if(pMap->SingleSelect(pSM,pCoordSys,ptWorld,g_QObj.g_fEffectiveDistance,QGIS_OBJ_POINT) == 0)
- {
- break;
- }
- else
- {
- m_nLbtDown++;
- CQBaseObj * pObj = pSM->GetCurSelObj();
- if(pObj->GetObjType() == QGIS_OBJ_POINT)
- {
- m_vecObj.push_back(pObj);
- }
- }
- }
- pSM->RemoveAll();
- break;
- }
- case ID_MENU_ADD_HORI_LINE_QGIS: //添加水平线
- //水平线只改变线条的X坐标而Y坐标不变
- {
- if(m_nLbtDown == 0)
- {
- SetCapture();
- m_ptBegin = ptWorld;
- m_ptOld = ptWorld;
- m_ptEnd = ptWorld;
- m_nLbtDown++;
- }
- else
- {
- m_ptEnd = ptWorld;
- CBoundaryRect bRect;
- CRect rect;
- CQLineObj * pHorLine = new CQLineObj;
- pHorLine->m_PtList.AddPoint(m_ptBegin.GetX(),m_ptBegin.GetY());
- pHorLine->m_PtList.AddPoint(m_ptEnd.GetX(),m_ptBegin.GetY());
- pHorLine->CalculateBoundary(&bRect);
- pCoordSys->WPtoLP(bRect,&rect);
- pMap->AddObject(pHorLine);
- InvalidateRect(rect,TRUE);
- m_nLbtDown = 0;
- ReleaseCapture();
- }
- break;
- }
- case ID_MENU_ADD_VERVICAL_LINE_QGIS:
- {
- if(m_nLbtDown == 0)
- {
- SetCapture();
- m_nLbtDown++;
- m_ptBegin = ptWorld;
- m_ptOld = ptWorld;
- m_ptEnd = ptWorld;
- }
- else
- {
- CBoundaryRect bRect;
- CRect rect;
- CQLineObj * pVerLine = new CQLineObj;
- m_ptEnd = ptWorld;
- pVerLine->m_PtList.AddPoint(m_ptBegin.GetX(),m_ptBegin.GetY());
- pVerLine->m_PtList.AddPoint(m_ptBegin.GetX(),m_ptEnd.GetY());
- pVerLine->CalculateBoundary(&bRect);
- pMap->AddObject(pVerLine);
- pCoordSys->WPtoLP(bRect,&rect);
- InvalidateRect(rect,TRUE);
- ReleaseCapture();
- m_nLbtDown = 0;
- }
- break;
- }
- case ID_MENU_ADD_TEXT_QGIS: //添加标住对象
- {
- CQTextObj * pTextObj = new CQTextObj;
- pTextObj->SetPos(ptWorld);
- QDlgTextSet dlg(pTextObj);
- if(dlg.DoModal() == IDOK)
- {
- CBoundaryRect bRect;
- CRect rect;
- pMap->AddObject(pTextObj);
- pTextObj->CalculateBoundary(&bRect);
- pCoordSys->WPtoLP(bRect,&rect);
- InvalidateRect(rect,TRUE);
- }
- else
- {
- delete pTextObj;
- pTextObj = NULL;
- }
- break;
- }
- case ID_MENU_READ_EXCEL_QGIS:
- {
- CQPoint ptExcelStartPt = ptWorld;
- CQReadExcelToView ReadExcelToMap(pMap,pCoordSys,ptExcelStartPt);
- CWaitCursor wait;
- BOOL bSuccess = ReadExcelToMap.ReadExcelFromPC();
- CBoundaryRect brect;
- pMap->CalculateBoundary(&brect);
- CRect rectMap;
- pCoordSys->WPtoLP(brect,&rectMap);
- if(bSuccess)
- {
- AfxMessageBox("Excel文件矢量化完成");
- }
- pDoc->m_MenuItemID = 0;
- break;
- }
- default:
- {
- m_nLbtDown = 0;
- break;
- }
- }
- CView::OnLButtonDown(nFlags, point);
- }
- void CQGISView::OnLButtonUp(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- ASSERT(pDoc);
- CQMapObj * pMap = pDoc->m_pMap;
- ASSERT(pMap);
- CQCoordSys * pCoordSys = pMap->GetCoordSysPointer();
- ASSERT(pCoordSys);
- CQSelObjManager * pSM = pMap->GetSelObjManager();
- ASSERT(pSM);
- CDC * pDC = GetDC();
- CQPoint ptWorld;
- pCoordSys->LPtoWP(point,&ptWorld);
- switch(pDoc->m_MenuItemID)
- {
- case IDM_MENU_PT_SELECT_OBJ_QGIS:
- {
- if(m_nLbtDown != 0)
- {
- pSM->RemoveAllSelObj(); //去除所有选中的图元对象
- if(pMap->Select(pSM,pCoordSys,ptWorld,g_QObj.g_fEffectiveDistance))
- {
- pSM->BeginFlash((CWnd *)this,2,1000);
- pSM->FlashObj(pCoordSys,this->GetSafeHwnd());
- m_nLbtDown = 0;
- }
- }
- break;
- }
- case IDM_MENU_CUT_LINE_QGIS: // 剪断线
- {
- if(m_nLbtDown>0)
- {
- BOOL bInLine = FALSE;
- CQBaseObj * pObj = pSM->GetCurSelObj();
- if(pObj->GetObjType() != QGIS_OBJ_LINE) break;
- CQLineObj * pLine = (CQLineObj *)pObj;
- CQPoint * ptFirst = NULL,* ptSecond = NULL;
- int nPtcount = pLine->m_PtList.GetSize();
- for(int i=0;i<nPtcount-1;i++)
- {
- ptFirst = pLine->m_PtList.GetPoint(i);
- ptSecond = pLine->m_PtList.GetPoint(i+1);
- if(!ptFirst || !ptSecond) return;
- bInLine = m_ptBegin.PtInLine(*ptFirst,*ptSecond);
- if(bInLine == TRUE)break;
- }
- if(bInLine)
- {
- CQLineObj * pCutLine = new CQLineObj;
- CQPointArray ptTmArray;
- int nFirst = -1;
- FindNearestTwoPoints(nFirst,&m_ptBegin,pLine);
- pCutLine->m_PtList.AddPoint(m_ptBegin.GetX(),m_ptBegin.GetY());
- if(nFirst+1 == nPtcount-1)
- {
- pCutLine->m_PtList.AddPoint(pLine->m_PtList.GetPoint(nFirst+1));
- }
- else if(nFirst+1<nPtcount)
- {
- for(int m=nFirst+1;m<nPtcount;m++)
- {
- pCutLine->m_PtList.AddPoint(pLine->m_PtList.GetPoint(m));
- }
- }
- for(int kk=0;kk<=nFirst;kk++)
- {
- ptTmArray.AddPoint(pLine->m_PtList.GetPoint(kk));
- }
- CBoundaryRect bRect1,bRect2;
- pLine->m_PtList.Copy(ptTmArray);
- pLine->m_PtList.AddPoint(m_ptBegin.GetX(),m_ptBegin.GetY());
- pLine->CalculateBoundary(&bRect1);
- pCutLine->CalculateBoundary(&bRect2);
- pLine->SetShowPointFlag(TRUE);
- pCutLine->SetShowPointFlag(TRUE);
- bRect2.Union(&bRect1);
- double fstep = 2.5f;
- bRect2.Lager(fstep);
- pCutLine->SetObjLayerID(pLine->GetObjLayerID());
- pCutLine->SetObjMapID(pLine->GetObjMapID());
- pMap->AddObject(pCutLine);
- CRect rectTm;
- m_nLbtDown = 0;
- ReleaseCapture();
- pCoordSys->WPtoLP(bRect2,&rectTm);
- pSM->EndFlash((CWnd *)this,2);
- InvalidateRect(rectTm,TRUE);
- pDoc->m_MenuItemID = ID_EDIT_BUTTON_ARROW;
- }
- }
- m_nLbtDown = 0;
- ReleaseCapture();
- break;
- }
- case IDM_MENU_ADD_POLYLINE_STREAM: //添加流线
- {
- if(m_nLbtDown>0)
- {
- int nPtSize = m_ptArray.GetSize();
- if(nPtSize < 2) //若点集中点的数量少于2 则退出
- {
- m_ptArray.RemoveAll();
- m_nLbtDown = 0;
- ReleaseCapture();
- }
- else
- {
- CBoundaryRect bRect;
- CRect rectTemp;
- CQLineObj * pStreamLine = new CQLineObj;
- pStreamLine->m_PtList.Copy(m_ptArray);
- pStreamLine->CalculateBoundary(&bRect);
- pMap->AddObject(pStreamLine);
- m_ptArray.DeleteAll(); //删除点阵里所有的点
- ReleaseCapture();
- m_nLbtDown = 0;
- pCoordSys->WPtoLP(bRect,&rectTemp);
- InvalidateRect(rectTemp);
- }
- }
- break;
- }
- case ID_MENU_MOVE_MAP:
- {
- m_nLbtDown = 0;
- ReleaseCapture();
- long lOrX,lOry;
- pCoordSys->GetStartOfWnd(lOrX,lOry);
- DrawAxis(m_bDrawAxis,pDC,lOrX,lOry);
- break;
- }
- case IDM_MENU_RECT_SELECT_OBJ_QGIS:
- {
- if(m_nLbtDown>0)
- {
- pDC->SetROP2(R2_NOT);
- pDC->SelectStockObject(NULL_BRUSH);
- m_nLbtDown = 0;
- m_ptOld = ptWorld;
- double fMinx = min(m_ptBegin.GetX(),ptWorld.GetX());
- double fMinY = min(m_ptBegin.GetY(),ptWorld.GetY());
- double fMaxX = max(m_ptBegin.GetX(),ptWorld.GetX());
- double fMaxY = max(m_ptBegin.GetY(),ptWorld.GetY());
- CBoundaryRect bRect;
- bRect.m_fMinX = fMinx;
- bRect.m_fMinY = fMinY;
- bRect.m_fMaxX = fMaxX;
- bRect.m_fMaxY = fMaxY;
- long lMinx,lMinY,lMaxX,lMaxY;
- pCoordSys->WPtoLP(fMinx,fMinY,&lMinx,&lMinY);
- pCoordSys->WPtoLP(fMaxX,fMaxY,&lMaxX,&lMaxY);
- pDC->Rectangle(lMinx,lMinY,lMaxX,lMaxY);
- pSM->RemoveAllSelObj();
- if(m_nSelectType == QGIS_SELECT_UNKNOWN)
- {
- if(pMap->Select(pSM,pCoordSys,bRect))
- {
- pSM->BeginFlash((CWnd *)this,2,1000);
- pSM->FlashObj(pCoordSys,this->GetSafeHwnd());
- }
- }
- else if(m_nSelectType == QGIS_SELECT_POINT) //假如是选择点
- {
- if(pMap->Select(pSM,pCoordSys,bRect))
- {
- POSITION pos = pSM->GetHeadPosition();
- CQSelObjManager * pTmSel = new CQSelObjManager;
- CQBaseObj * pObj = pSM->GetHead();
- while (pos)
- {
- CQBaseObj * pObj = pSM->GetNext(pos);
- if(pObj && pObj->GetObjDeleted()!=TRUE && pObj->GetObjHided()!=TRUE && pObj->GetObjType()==QGIS_OBJ_POINT)
- {
- pObj->SetObjSelected(FALSE);
- pTmSel->AddSelObj(pObj);
- }
- }
- pSM->RemoveAllSelObj();
- if(pTmSel->GetSelObjCount()>0)
- {
- POSITION pos_2 = pTmSel->GetHeadPosition();
- while (pos_2)
- {
- CQBaseObj * pObj = pTmSel->GetNext(pos_2);
- pObj->SetObjSelected(FALSE);
- pSM->AddSelObj(pObj);
- }
- pTmSel->RemoveAllSelObj();
- }
- pSM->BeginFlash((CWnd *)this,2,1000);
- pSM->FlashObj(pCoordSys,this->GetSafeHwnd());
- delete pTmSel;
- pTmSel = NULL;
- }
- }
- }
- m_nLbtDown = 0;
- ReleaseCapture();
- break;
- }
- default:
- {
- break;
- }
- }
- CView::OnLButtonUp(nFlags, point);
- }
- void CQGISView::OnMouseMove(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- ASSERT(pDoc);
- CQMapObj * pMap = pDoc->m_pMap;
- ASSERT(pMap);
- CQSelObjManager * pSM = pMap->GetSelObjManager();
- ASSERT(pSM);
- CQCoordSys * pCoordSys = pMap->GetCoordSysPointer();
- ASSERT(pCoordSys);
- CDC * pDC = GetDC();
- CPen pen(PS_SOLID,0,RGB(0,0,255));
- CPen * pOldPen = pDC->SelectObject(&pen);
- CQPoint ptWorld;
- pCoordSys->LPtoWP(point,&ptWorld);
- COLORREF cl = RGB(0,0,0);
- ///////////////////////////////////////////////////////////
- CStatusBar * pStatus = NULL;
- CString szMapScale; //定义一个临时变量用于存储鼠标的坐标值
- CString szMousePos;
- //获取状态栏的窗口指针
- pStatus = (CStatusBar *)AfxGetApp()->m_pMainWnd->GetDescendantWindow(AFX_IDW_STATUS_BAR);
- if(pStatus)
- {
- CString szMapUnit = pCoordSys->GetUnitNameCHS();
- const char * pchar = LPCTSTR(szMapUnit);
- szMapScale.Format("当前地图比例尺1:%f",pMap->GetCoordSysPointer()->GetMapScale());
- pStatus->SetPaneText(1,szMapScale);
- szMousePos.Format("X =%10.5f%s,Y =%10.5f%s",ptWorld.GetX(),pchar,ptWorld.GetY(),pchar);
- pStatus->SetPaneText(2,szMousePos);
- }
- ///////////////////////////////////////////////////////////
- switch(pDoc->m_MenuItemID)
- {
- case IDM_MENU_ADD_LINE_QGIS: //当前是画线操作
- {
- if(m_nLbtDown>0) //假如鼠标已经点击了
- {
- pDC->SetROP2(R2_NOT);
- //设置为不填充状态
- if(m_ptEnd != m_ptBegin)
- {
- pDC->MoveTo(GetBeginPos());
- pDC->LineTo(GetEndPos());
- }
- m_ptEnd = ptWorld;
- pDC->MoveTo(GetBeginPos());
- pDC->LineTo(GetEndPos());
- }
- break;
- }
- case IDM_MENU_RECT_SELECT_OBJ_QGIS:
- {
- if(m_nLbtDown >0)
- {
- pDC->SetROP2(R2_NOT);
- pDC->SelectStockObject(NULL_BRUSH);
- CPoint ptBegin,ptOld;
- pCoordSys->WPtoLP(m_ptBegin,&ptBegin);
- if(m_ptOld != m_ptBegin)
- {
- pCoordSys->WPtoLP(m_ptOld,&ptOld);
- long lMinx = min(ptBegin.x,ptOld.x);
- long lMinY = min(ptBegin.y,ptOld.y);
- long lMaxX = max(ptBegin.x,ptOld.x);
- long lMaxY = max(ptBegin.y,ptOld.y);
- pDC->Rectangle(lMinx,lMinY,lMaxX,lMaxY);
- }
- m_ptOld = ptWorld;
- pCoordSys->WPtoLP(m_ptOld,&ptOld);
- long lMinx = min(ptBegin.x,ptOld.x);
- long lMinY = min(ptBegin.y,ptOld.y);
- long lMaxX = max(ptBegin.x,ptOld.x);
- long lMaxY = max(ptBegin.y,ptOld.y);
- pDC->Rectangle(lMinx,lMinY,lMaxX,lMaxY);
- break;
- }
- }
- case IDM_MENU_ADD_POLYLINE:
- {
- if(m_nLbtDown>0)
- {
- if(m_ptOld != m_ptBegin)
- {
- pDC->SetROP2(R2_NOT);
- pCoordSys->WPtoLP(m_ptBegin,&m_ptLBegin);
- pCoordSys->WPtoLP(m_ptOld,&m_ptLOld);
- pDC->MoveTo(m_ptLBegin);
- pDC->LineTo(m_ptLOld);
- }
- pDC->SetROP2(R2_NOT);
- m_ptOld = ptWorld;
- pCoordSys->WPtoLP(m_ptBegin,&m_ptLBegin);
- pCoordSys->WPtoLP(m_ptOld,&m_ptLOld);
- pDC->MoveTo(m_ptLBegin);
- pDC->LineTo(m_ptLOld);
- }
- break;
- }
- case IDM_MENU_MOVE_LINE_QGIS:
- case IDM_MENU_MOVE_OBJ_QGIS:
- {
- if(m_nLbtDown>0)
- {
- CBoundaryRect BRect,bAllRect;
- COLORREF cl = RGB(160,160,160);
- if(m_ptOld != m_ptBegin)
- {
- pCoordSys->WPtoLP(m_ptBegin,&m_ptLBegin);
- pCoordSys->WPtoLP(m_ptOld,&m_ptLOld);
- double dx = ptWorld.GetX() - m_ptOld.GetX();
- double dy = ptWorld.GetY() - m_ptOld.GetY();
- int nSelObj = pSM->GetSelObjCount();
- POSITION pos = pSM->GetHeadPosition();
- while (pos)
- {
- CQBaseObj * pObj = pSM->GetNext(pos);
- if(pObj && !pObj->GetObjDeleted() && !pObj->GetObjHided())
- {
- pObj->Display(pCoordSys,pDC,R2_NOT,2,&cl);
- pObj->Move(dx,dy);
- pObj->Display(pCoordSys,pDC,R2_NOT,2,&cl);
- }
- }
- pDC->SetROP2(R2_NOT);
- pDC->MoveTo(m_ptLBegin);
- pDC->LineTo(m_ptLOld);
- }
- m_ptOld = ptWorld;
- pDC->SetROP2(R2_NOT);
- pCoordSys->WPtoLP(m_ptBegin,&m_ptLBegin);
- pCoordSys->WPtoLP(m_ptOld,&m_ptLOld);
- pDC->MoveTo(m_ptLBegin);
- pDC->LineTo(m_ptLOld);
- }
- break;
- }
- case IDM_MENU_ROTATE_LINE_QGIS:
- case IDM_MENU_ROTATE_OBJ_QGIS:
- {
- if(m_nLbtDown>0)
- {
- if(pSM->GetSelObjCount()<=0)break;
- CObList tmSelObjs;
- POSITION pos = pSM->GetHeadPosition();
- while (pos)
- {
- CQBaseObj * pObj = pSM->GetNext(pos);
- if(!pObj) continue;
- tmSelObjs.AddTail(pObj);
- }
- pSM->EndFlash((CWnd *)this,2);
- COLORREF cl = RGB(0,0,0);
- // m_ptEnd = ptWorld;
- pDC->SetROP2(R2_NOT);
- if(m_ptOld != m_ptBegin)
- {
- pCoordSys->WPtoLP(m_ptBegin,&m_ptLBegin);
- pCoordSys->WPtoLP(m_ptOld,&m_ptLOld);
- double fAngle1 = atan2(ptWorld.GetY()-m_ptBegin.GetY(),ptWorld.GetX()-m_ptBegin.GetX());
- double fAngle2 = atan2(m_ptOld.GetY()-m_ptBegin.GetY(),m_ptOld.GetX()-m_ptBegin.GetX());
- double fAngle = CQGISAlgorithmLib::RadianToDegree(fAngle1-fAngle2);
- pos = tmSelObjs.GetHeadPosition();
- while (pos)
- {
- CQBaseObj * pObj = (CQBaseObj *)tmSelObjs.GetNext(pos);
- pObj->Display(pCoordSys,pDC,R2_NOT,2,&cl);
- pObj->Rotate(m_ptBegin,fAngle);
- pObj->Display(pCoordSys,pDC,R2_NOT,2,&cl);
- }
- pDC->MoveTo(m_ptLBegin);
- pDC->LineTo(m_ptLOld);
- }
- m_ptOld = ptWorld;
- pCoordSys->WPtoLP(m_ptBegin,&m_ptLBegin);
- pCoordSys->WPtoLP(m_ptOld,&m_ptLOld);
- pDC->MoveTo(m_ptLBegin);
- pDC->LineTo(m_ptLOld);
- pos = tmSelObjs.GetHeadPosition();
- while (pos)
- {
- CQBaseObj * pObj = (CQBaseObj *)tmSelObjs.GetNext(pos);
- pSM->AddSelObj(pObj);
- }
- tmSelObjs.RemoveAll();
- }
- break;
- }
- case IDM_MENU_ADD_RECT_QGIS:
- {
- if(m_nLbtDown > 0)
- {
- CPoint pt1,pt2;
- pDC->SetROP2(R2_NOT);
- if(m_ptOld != m_ptBegin)
- {
- pCoordSys->WPtoLP(m_ptBegin,&m_ptLBegin);
- pCoordSys->WPtoLP(m_ptOld,&m_ptLOld);
- pt1.x = m_ptLBegin.x;
- pt1.y = m_ptLOld.y;
- pt2.x = m_ptLOld.x;
- pt2.y = m_ptLBegin.y;
- pDC->MoveTo(m_ptLBegin);
- pDC->LineTo(pt1);
- pDC->LineTo(m_ptLOld);
- pDC->LineTo(pt2);
- pDC->LineTo(m_ptLBegin);
- }
- m_ptOld = ptWorld;
- pCoordSys->WPtoLP(m_ptBegin,&m_ptLBegin);
- pCoordSys->WPtoLP(m_ptOld,&m_ptLOld);
- pt1.x = m_ptLBegin.x;
- pt1.y = m_ptLOld.y;
- pt2.x = m_ptLOld.x;
- pt2.y = m_ptLBegin.y;
- pDC->MoveTo(m_ptLBegin);
- pDC->LineTo(pt1);
- pDC->LineTo(m_ptLOld);
- pDC->LineTo(pt2);
- pDC->LineTo(m_ptLBegin);
- }
- break;
- }
- case IDM_MENU_ADD_CIRCLE_QGIS:
- {
- if(m_nLbtDown == 1)
- {
- long lCr = 0;
- double fR = 0;
- CPen crpen(PS_DASH,0,RGB(0,0,255));
- CPen * pOldPenCr = pDC->SelectObject(&crpen);
- pDC->SelectStockObject(NULL_BRUSH);
- if(m_ptOld != m_ptBegin)
- {
- pDC->SetROP2(R2_NOT);
- lCr = (GetOldPos().x-GetBeginPos().x)*(GetOldPos().x-GetBeginPos().x) +
- (GetOldPos().y-GetBeginPos().y)*(GetOldPos().y-GetBeginPos().y);
- lCr = static_cast<long>(sqrt(static_cast<double>(lCr)));
- CPoint pt = GetBeginPos();
- pDC->Ellipse(pt.x-lCr,pt.y-lCr,pt.x+lCr,pt.y+lCr);
- }
- m_ptOld = ptWorld;
- pDC->SetROP2(R2_NOT);
- lCr = (GetOldPos().x-GetBeginPos().x)*(GetOldPos().x-GetBeginPos().x) +
- (GetOldPos().y-GetBeginPos().y)*(GetOldPos().y-GetBeginPos().y);
- lCr = static_cast<long>(sqrt(static_cast<double>(lCr)));
- CPoint pt = GetBeginPos();
- pDC->Ellipse(pt.x-lCr,pt.y-lCr,pt.x+lCr,pt.y+lCr);
- pDC->SelectObject(pOldPenCr);
- }
- break;
- }
- case IDM_MENU_ADD_ELLIPSE_QGIS:
- {
- m_ptEnd = ptWorld;
- if(m_nLbtDown==1)
- {
- pDC->SetROP2(R2_NOT);
- pDC->MoveTo(GetBeginPos());
- pDC->LineTo(GetOldPos());
- pDC->MoveTo(GetBeginPos());
- pDC->LineTo(GetEndPos());
- }
- else if(m_nLbtDown==2)
- {
- long lx=0,ly=0;
- CQPoint ptCenter;
- pDC->SetROP2(R2_NOT);
- m_Ellipse.GetCenterPoint(ptCenter);
- pCoordSys->WPtoLP(ptCenter.GetX(),ptCenter.GetY(),&lx,&ly);
- pDC->MoveTo(lx,ly);
- pDC->LineTo(GetOldPos());
- pDC->MoveTo(lx,ly);
- pDC->LineTo(GetEndPos());
- //DrawEllipse(m_EllipsePara);
- COLORREF cl = RGB(0,0,0);
- DrawEllipse(m_Ellipse,pDC);
- double dx = ptCenter.GetX() - ptWorld.GetX();
- double dy = ptCenter.GetY() - ptWorld.GetY();
- double fShortAxis = sqrt( dx*dx + dy*dy );//椭圆短轴
- m_Ellipse.SetShortAxis(fShortAxis);
- //DrawEllipse(m_EllipsePara);
- DrawEllipse(m_Ellipse,pDC);
- }
- else
- {
- }
- m_ptOld = ptWorld;
- break;
- }
- case IDM_MENU_ADD_POLYLINE_STREAM: //造流线
- {
- if(m_nLbtDown>0 && MK_LBUTTON && nFlags)
- {
- pDC->SetROP2(R2_NOT);
- pDC->MoveTo(GetBeginPos());
- pDC->LineTo(point);
- m_ptBegin = ptWorld;
- m_ptArray.AddPoint(ptWorld.GetX(),ptWorld.GetY());
- m_nLbtDown++;
- break;
- }
- }
- case ID_MENU_MOVE_MAP:
- {
- if((m_ptOld!=ptWorld) && (nFlags&MK_LBUTTON) && m_nLbtDown==1)
- {
- long dx,dy;
- dx=point.x-GetOldPos().x;
- dy=point.y-GetOldPos().y;
- pCoordSys->Translate(GetOldPos(),point);
- ScrollWindow(dx,dy);
- m_ptOld = ptWorld;
- }
- break;
- }
- case ID_MENU_ADD_HORI_LINE_QGIS: //水平线的操作
- {
- if(m_nLbtDown>0)
- {
- pDC->SetROP2(R2_NOT);
- if(m_ptOld != m_ptBegin)
- {
- pDC->MoveTo(GetBeginPos().x,GetBeginPos().y);
- pDC->LineTo(GetOldPos().x,GetBeginPos().y);
- }
- m_ptOld = ptWorld;
- pDC->MoveTo(GetBeginPos().x,GetBeginPos().y);
- pDC->LineTo(GetOldPos().x,GetBeginPos().y);
- }
- break;
- }
- case ID_MENU_ADD_VERVICAL_LINE_QGIS: // 对垂直线的操作
- {
- if(m_nLbtDown>0)
- {
- pDC->SetROP2(R2_NOT);
- if(m_ptOld != m_ptBegin)
- {
- pDC->MoveTo(GetBeginPos().x,GetBeginPos().y);
- pDC->LineTo(GetBeginPos().x,GetOldPos().y);
- }
- m_ptOld = ptWorld;
- pDC->MoveTo(GetBeginPos().x,GetBeginPos().y);
- pDC->LineTo(GetBeginPos().x,GetOldPos().y);
- }
- break;
- }
- default:
- {
- break;
- }
- }
- pDC->SelectObject(pOldPen);
- CView::OnMouseMove(nFlags, point);
- }
- void CQGISView::OnRButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- ASSERT(pDoc);
- CQMapObj * pMap = pDoc->m_pMap;
- ASSERT(pMap);
- CQCoordSys * pCoordSys = pMap->GetCoordSysPointer();
- ASSERT(pCoordSys);
- CDC * pDC = GetDC();
- CQSelObjManager * pSM = pMap->GetSelObjManager();
- ASSERT(pSM);
- CQPoint ptWorld;
- pCoordSys->LPtoWP(point,&ptWorld);
- switch(pDoc->m_MenuItemID)
- {
- case IDM_MENU_ADD_LINE_QGIS:
- {
- if(m_nLbtDown == 1)
- {
- pDC->SetROP2(R2_NOT);
- pCoordSys->WPtoLP(m_ptBegin,&m_ptLBegin);
- pDC->MoveTo(m_ptLBegin);
- pDC->LineTo(point);
- m_ptArray.DeleteAll();
- m_nLbtDown = 0;
- ReleaseCapture();
- }
- break;
- }
- case IDM_MENU_ADD_POLYLINE:
- {
- if(m_nLbtDown == 1)
- {
- pDC->SetROP2(R2_NOT);
- pCoordSys->WPtoLP(m_ptBegin,&m_ptLBegin);
- pDC->MoveTo(m_ptLBegin);
- pDC->LineTo(point);
- m_ptArray.DeleteAll();
- m_nLbtDown = 0;
- ReleaseCapture();
- }
- else
- {
- CQLineObj * pLine = new CQLineObj;
- pLine->m_PtList.Copy(m_ptArray);
- pLine->SetObjLayerID(pMap->GetCurLayer()->GetLayerID());
- pLine->SetObjMapID(pMap->GetMapID());
- if(pLine && pLine->m_PtList.GetSize()>1)
- {
- CBoundaryRect BRect;
- pLine->CalculateBoundary(&BRect);
- pMap->AddObject(pLine);
- CRect rect;
- pCoordSys->WPtoLP(BRect,&rect);
- rect.left = min(rect.left,point.x);
- rect.top = min(rect.top,point.y);
- rect.right = max(rect.right,point.x);
- rect.bottom = max(rect.bottom,point.y);
- InvalidateRect(rect);
- m_nLbtDown = 0;
- ReleaseCapture();
- }
- }
- m_nLbtDown = 0;
- break;
- }
- case IDM_MENU_MOVE_LINE_QGIS:
- case IDM_MENU_MOVE_OBJ_QGIS: //移动对象在点击右键后结束
- {
- m_nLbtDown = 0;
- if(pSM->GetSelObjCount()>0)
- pSM->EndFlash((CWnd *)this,2);
- pDoc->m_MenuItemID = ID_EDIT_BUTTON_ARROW;
- ReleaseCapture();
- break;
- }
- case IDM_MENU_ROTATE_LINE_QGIS:
- case IDM_MENU_ROTATE_OBJ_QGIS: //移动对象的操作
- {
- m_nLbtDown = 0;
- if(pSM->GetSelObjCount()>0)
- pSM->EndFlash((CWnd *)this,2);
- pDoc->m_MenuItemID = ID_EDIT_BUTTON_ARROW;
- ReleaseCapture();
- break;
- }
- case IDM_MENU_ADD_CIRCLE_QGIS:
- {
- if(m_nLbtDown == 1) //假如单击了一次后不想再 画了
- {
- m_nLbtDown = 0;
- ReleaseCapture();
- pDoc->m_MenuItemID = ID_EDIT_BUTTON_ARROW;
- m_ptOld = ptWorld;
- pDC->SetROP2(R2_NOT);
- pDC->SelectStockObject(NULL_BRUSH);
- long lCr = (GetOldPos().x-GetBeginPos().x)*(GetOldPos().x-GetBeginPos().x) +
- (GetOldPos().y-GetBeginPos().y)*(GetOldPos().y-GetBeginPos().y);
- lCr = static_cast<long>(sqrt(static_cast<double>(lCr)));
- CPoint pt = GetBeginPos();
- pDC->Ellipse(pt.x-lCr,pt.y-lCr,pt.x+lCr,pt.y+lCr);
- }
- break;
- }
- case IDM_MENU_ADD_ELLIPSE_QGIS: //绘制椭圆形时的操作
- {
- if(m_nLbtDown == 1) //假如单击了一次就不想画了
- {
- m_nLbtDown = 0; //结束鼠标输入
- ReleaseCapture(); //释放鼠标捕捉
- pDC->SetROP2(R2_NOT);
- pDC->MoveTo(GetBeginPos());
- pDC->LineTo(point);
- pDoc->m_MenuItemID = ID_EDIT_BUTTON_ARROW;
- }
- else if(m_nLbtDown == 2) // 如果鼠标单击了两次
- {
- //就要绘制一个椭圆
- pDC->SetROP2(R2_NOT);
- CQEllipseObj tmEllipse;
- tmEllipse.Copy(m_Ellipse);// 设置临时椭圆对象的参数
- DrawEllipse(tmEllipse,pDC);
- CPoint ptTemp;
- pCoordSys->WPtoLP(ptCenter,&ptTemp);
- pDC->MoveTo(ptTemp);
- pDC->LineTo(point);
- m_nLbtDown = 0;
- ReleaseCapture();
- pDoc->m_MenuItemID = ID_EDIT_BUTTON_ARROW;
- }
- break;
- }
- case IDM_MENU_LINK_POINT_TO_LINE_QGIS: //连点成线
- {
- if(m_nLbtDown == 0)
- {
- ReleaseCapture();
- pDoc->m_MenuItemID = ID_EDIT_BUTTON_ARROW;
- break;
- }
- else
- {
- int nptSize = m_vecObj.size();
- if(nptSize>=2)
- {
- BOOL bCreated = TRUE;
- CQLineObj * pNewLine = new CQLineObj;
- for(int i=0;i<nptSize;i++)
- {
- CQPointObj * pPt = dynamic_cast<CQPointObj *>(m_vecObj.at(i));
- if(pPt == NULL)
- {
- bCreated = FALSE;
- break;
- }
- else
- {
- double dx=0.0f,dy=0.0f;
- pPt->GetPointPos(dx,dy);
- pNewLine->m_PtList.AddPoint(dx,dy);
- }
- }
- if(bCreated == FALSE)
- {
- delete pNewLine;
- pNewLine = NULL;
- }
- else
- {
- pNewLine->SetObjName(CString("连点成线对象"));
- CBoundaryRect bRect;
- pNewLine->CalculateBoundary(&bRect);
- CRect rectLine;
- pCoordSys->WPtoLP(bRect,&rectLine);
- pMap->AddObject(pNewLine);
- InvalidateRect(rectLine,FALSE);
- }
- }
- m_nLbtDown = 0;
- ReleaseCapture();
- pDoc->m_MenuItemID = ID_EDIT_BUTTON_ARROW;
- m_vecObj.clear();
- break;
- }
- }
- case ID_MENU_ADD_HORI_LINE_QGIS: //水平线
- {
- if(m_nLbtDown == 1)
- {
- //假如在画线的过程想要结束
- ReleaseCapture();
- m_nLbtDown = 0;
- CRect rect;
- rect.left = GetBeginPos().x - 1;
- rect.top = GetBeginPos().y - 1;
- rect.right = point.x + 2;
- rect.bottom = GetBeginPos().y + 1;
- InvalidateRect(rect,TRUE);
- }
- break;
- }
- case ID_MENU_ADD_VERVICAL_LINE_QGIS:
- {
- if(m_nLbtDown == 1)
- {
- ReleaseCapture();
- m_nLbtDown = 0;
- CRect rect;
- rect.left = GetBeginPos().x - 1;
- rect.top = GetBeginPos().y - 1;
- rect.right = GetOldPos().x + 1;
- rect.bottom = GetOldPos().y +1;
- InvalidateRect(rect,TRUE);
- }
- break;
- }
- case ID_MENU_ADD_TEXT_QGIS:
- {
- m_nLbtDown = 0;
- pDoc->m_MenuItemID = 0;
- break;
- }
- }
- CView::OnRButtonDown(nFlags, point);
- }
- void CQGISView::OnCancelMode()
- {
- CView::OnCancelMode();
- // TODO: Add your message handler code here
- }
- void CQGISView::OnMenuAddLineQgis()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = GetDocument(); //获取文档指针
- ASSERT(pDoc);
- pDoc->m_MenuItemID = IDM_MENU_ADD_LINE_QGIS;
- m_nLbtDown = 0;
- }
- void CQGISView::OnMenuAddPointQgis()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- ASSERT(pDoc);
- pDoc->m_MenuItemID = IDM_MENU_ADD_POINT_QGIS;
- m_nLbtDown = 0;
- }
- BOOL CQGISView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
- {
- // TODO: Add your message handler code here and/or call default
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- if(pDoc->m_MenuItemID == IDM_MENU_ADD_POINT_QGIS ||
- pDoc->m_MenuItemID == IDM_MENU_ADD_LINE_QGIS ||
- pDoc->m_MenuItemID == IDM_MENU_PT_SELECT_OBJ_QGIS ||
- pDoc->m_MenuItemID == IDM_MENU_RECT_SELECT_OBJ_QGIS ||
- pDoc->m_MenuItemID == IDM_MENU_ADD_POLYLINE ||
- pDoc->m_MenuItemID == IDM_MENU_CUT_LINE_QGIS ||
- pDoc->m_MenuItemID == IDM_MENU_MIRROR_LINE_X_QGIS ||
- pDoc->m_MenuItemID == IDM_MENU_MIRROR_LINE_Y_QGIS ||
- pDoc->m_MenuItemID == IDM_MENU_MIRROR_O_QGIS ||
- pDoc->m_MenuItemID == ID_MENU_ADD_VERVICAL_LINE_QGIS ||
- pDoc->m_MenuItemID == ID_MENU_ADD_HORI_LINE_QGIS ||
- pDoc->m_MenuItemID == IDM_MENU_ADD_LINE_QGIS ||
- pDoc->m_MenuItemID == ID_MENU_ADD_TEXT_QGIS ||
- pDoc->m_MenuItemID == ID_MENU_READ_EXCEL_QGIS)
- {
- HCURSOR hCursor;
- //测试中发现 替换为LoadCursor就无法显示
- //得出结论 Loadcursor针对自定义的光标资源
- hCursor = AfxGetApp()->LoadStandardCursor(IDC_CROSS);
- SetCursor(hCursor);
- ShowCursor(TRUE);
- return TRUE;
- }
- else if(pDoc->m_MenuItemID == ID_MENU_MOVE_MAP)
- {
- HCURSOR hCursor;
- hCursor = AfxGetApp()->LoadCursor(IDC_CURSOR_MOVE_MAP);
- SetCursor(hCursor);
- ShowCursor(TRUE);
- return TRUE;
- }
- else
- {
- HCURSOR hCursor;
- hCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
- SetCursor(hCursor);
- ShowCursor(TRUE);
- return TRUE;
- }
- return CView::OnSetCursor(pWnd,nHitTest,message);
- }
- void CQGISView::OnMenuSetMapAtt()
- {
- // TODO: Add your command handler code here
- CDlgMapAttSet dlg;
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- CQMapObj * pMap = pDoc->m_pMap;
- if(!pMap)return;
- if(dlg.DoModal() == IDOK)
- {
- CQCoordSys * pSys = pMap->GetCoordSysPointer();
- double fMapScale = dlg.m_lMapScale;
- pSys->SetMapScale(fMapScale);
- pSys->SetUnitType(dlg.m_nUnitType);
- pMap->GetBoundary()->m_fMinX = dlg.m_fLeftX;
- pMap->GetBoundary()->m_fMinY = dlg.m_fLeftY;
- pMap->GetBoundary()->m_fMaxX = dlg.m_fRightX;
- pMap->GetBoundary()->m_fMaxY = dlg.m_fRightY;
- pSys->SetViewportOrg(static_cast<long>(dlg.m_fLeftX),static_cast<long>(dlg.m_fLeftY));
- }
- }
- void CQGISView::OnSize(UINT nType, int cx, int cy)
- {
- CView::OnSize(nType, cx, cy);
- // TODO: Add your message handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- CQMapObj * pMap = pDoc->m_pMap;
- ASSERT(pMap);
- pMap->GetCoordSysPointer()->SetViewport(0,0,cx,cy);
- pMap->GetCoordSysPointer()->SetWndport(0,0,cx,cy);
- pMap->GetCoordSysPointer()->SetStartOfWnd(10,cy-10);
- }
- CPoint CQGISView::GetBeginPos()
- {
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- CQMapObj * pMap = pDoc->m_pMap;
- CQCoordSys * pSys = pMap->GetCoordSysPointer();
- ASSERT(pSys);
- CPoint ptBegin;
- pSys->WPtoLP(m_ptBegin,&ptBegin);
- return ptBegin;
- }
- CPoint CQGISView::GetOldPos()
- {
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- CQMapObj * pMap = pDoc->m_pMap;
- CQCoordSys * pSys = pMap->GetCoordSysPointer();
- ASSERT(pSys);
- CPoint ptOld;
- pSys->WPtoLP(m_ptOld,&ptOld);
- return ptOld;
- }
- CPoint CQGISView::GetEndPos()
- {
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- CQMapObj * pMap = pDoc->m_pMap;
- CQCoordSys * pSys = pMap->GetCoordSysPointer();
- ASSERT(pSys);
- CPoint ptEnd;
- pSys->WPtoLP(m_ptEnd,&ptEnd);
- return ptEnd;
- }
- CQPoint CQGISView::GetwBeginPos()
- {
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- CQMapObj * pMap = pDoc->m_pMap;
- CQCoordSys * pSys = pMap->GetCoordSysPointer();
- ASSERT(pSys);
- CQPoint ptwBegin;
- pSys->LPtoWP(m_ptLBegin,&ptwBegin);
- return ptwBegin;
- }
- CQPoint CQGISView::GetWOldPos()
- {
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- CQMapObj * pMap = pDoc->m_pMap;
- CQCoordSys * pSys = pMap->GetCoordSysPointer();
- ASSERT(pSys);
- CQPoint ptwBegin;
- pSys->LPtoWP(m_ptLBegin,&ptwBegin);
- return ptwBegin;
- }
- CQPoint CQGISView::GetWEndPos()
- {
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- CQMapObj * pMap = pDoc->m_pMap;
- CQCoordSys * pSys = pMap->GetCoordSysPointer();
- ASSERT(pSys);
- CQPoint ptwEnd;
- pSys->LPtoWP(m_ptLBegin,&ptwEnd);
- return ptwEnd;
- }
- void CQGISView::OnMenuPtSelectObjQgis()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- pDoc->m_MenuItemID = IDM_MENU_PT_SELECT_OBJ_QGIS;
- m_nLbtDown = 0;
- pDoc->m_pMap->GetSelObjManager()->BeginFlash((CWnd*)this,2,1000);
- }
- void CQGISView::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- ASSERT(pDoc);
- CQSelObjManager * pSel = pDoc->m_pMap->GetSelObjManager();
- ASSERT(pSel);
- if(pSel->GetSelObjCount()>0)
- {
- pSel->FlashObj(pDoc->m_pMap->GetCoordSysPointer(),this->GetSafeHwnd());
- }
- CView::OnTimer(nIDEvent);
- }
- //放弃选中
- void CQGISView::OnMenuUselectObjQgis()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- ASSERT(pDoc);
- CQMapObj * pMap = pDoc->m_pMap;
- ASSERT(pMap);
- CRect rectTemp;
- pMap->GetSelObjManager()->GetScreenRect(pMap->GetCoordSysPointer(),rectTemp);
- pMap->GetSelObjManager()->RemoveAllSelObj(); //除去所有选中图元
- pMap->GetSelObjManager()->EndFlash(this->GetSafeHwnd(),2);
- InvalidateRect(rectTemp,TRUE);
- m_nSelectType = QGIS_SELECT_UNKNOWN;
- }
- void CQGISView::OnMenuLineAttSet()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- ASSERT(pDoc);
- CQSelObjManager * pSel = pDoc->m_pMap->GetSelObjManager();
- ASSERT(pSel);
- CQCoordSys * pSys = pDoc->m_pMap->GetCoordSysPointer();
- ASSERT(pSys);
- CQLayerObj * pCurLayer = pDoc->m_pMap->GetCurLayer();
- ASSERT(pCurLayer);
- CQBaseObj * pObj = pSel->GetCurSelObj();
- if(pObj->GetObjType() != QGIS_OBJ_LINE)
- return;
- CDlgLineAttSet dlg(pCurLayer,1,(CQLineObj*)pObj);
- if(dlg.DoModal() == IDOK)
- {
- CQLineObj * ppObj = (CQLineObj *)pCurLayer->FindObj(pObj->GetObjID());
- short nObjLineType = dlg.m_nLineStyle;
- ppObj->SetobjLineType(nObjLineType);
- ppObj->SetObjLineWidth(dlg.m_fLineWidth);
- ppObj->SetObjPenColor(dlg.m_crLine);
- ppObj->SetLineClosed(dlg.m_nLineClosed);
- ppObj->SetShowPointFlag(dlg.m_bLineShowPt);
- CBoundaryRect Brect;
- ppObj->CalculateBoundary(&Brect);
- CRect rect;
- pSys->WPtoLP(Brect,&rect);
- InvalidateRect(rect);
- }
- }
- void CQGISView::OnUpdateMenuLineAttSet(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- ASSERT(pDoc);
- CQSelObjManager * pSel = pDoc->m_pMap->GetSelObjManager();
- ASSERT(pSel);
- int nSel = pSel->GetSelObjCount();
- if(nSel == 0)
- {
- pCmdUI->Enable(FALSE);
- return;
- }
- CQBaseObj * pObj = pSel->GetCurSelObj();
- if(pObj->GetObjType() == QGIS_OBJ_LINE && nSel == 1)
- pCmdUI->Enable(TRUE);
- else
- pCmdUI->Enable(FALSE);
- }
- void CQGISView::OnMenuRectSelectObjQgis()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc*)GetDocument();
- pDoc->m_MenuItemID = IDM_MENU_RECT_SELECT_OBJ_QGIS;
- m_nLbtDown = 0;
- pDoc->m_pMap->GetSelObjManager()->BeginFlash((CWnd*)this,2,1000);
- }
- void CQGISView::OnMenuDeleteObjQgis()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- ASSERT(pDoc);
- CQSelObjManager * pSM = pDoc->m_pMap->GetSelObjManager();
- ASSERT(pSM);
- CQMapObj * pMap = pDoc->m_pMap;
- ASSERT(pMap);
- if(pSM->GetSelObjCount()>0)
- {
- // int nLayercount = pDoc->m_pMap->GetLayerCount();
- // for(int i=0;i<nLayercount;i++)
- // {
- // CQLayerObj * pLayer = pMap->GetLayer(i);
- // if(pLayer && pLayer->GetShowFlag() && !pLayer->GetDeleteFlag())
- // {
- // int nObjCount = pLayer->GetObjCount();
- // for(int j=0;j<nObjCount;j++)
- // {
- // CQBaseObj * pObj = pLayer->GetObj(j);
- // if(pObj && !pObj->GetObjDeleted() && !pObj->GetObjHided())
- // {
- // POSITION pos = pSM->GetHeadPosition();
- // while (pos)
- // {
- // CQBaseObj * psmObj = pSM->GetNext(pos);
- // if(psmObj->GetObjID() == pObj->GetObjID())
- // {
- // pObj->SetObjDeleted(TRUE);
- // }
- // }
- // }
- // }
- // }
- // }
- POSITION pos = pSM->GetHeadPosition();
- while(pos)
- {
- CQBaseObj * pObj = pSM->GetNext(pos);
- pObj->SetObjDeleted(TRUE);
- }
- CRect rectTemp;
- pMap->GetSelObjManager()->GetScreenRect(pMap->GetCoordSysPointer(),rectTemp);
- pMap->GetSelObjManager()->RemoveAllSelObj(); //除去所有选中图元
- InvalidateRect(rectTemp);
- pMap->GetSelObjManager()->EndFlash(this->GetSafeHwnd(),2);
- }
- }
- //添加折线对象
- void CQGISView::OnMenuAddPolyline()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- ASSERT(pDoc);
- pDoc->m_MenuItemID = IDM_MENU_ADD_POLYLINE;
- m_nLbtDown=0;
- }
- void CQGISView::OnEditButtonArrow()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc*)GetDocument();
- pDoc->m_MenuItemID = ID_EDIT_BUTTON_ARROW;
- m_nLbtDown = 0;
- }
- void CQGISView::OnMenuMoveObjQgis()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- ASSERT(pDoc);
- pDoc->m_MenuItemID = IDM_MENU_MOVE_OBJ_QGIS;
- m_nLbtDown = 0;
- }
- void CQGISView::OnUpdateMenuMoveObjQgis(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- ASSERT(pDoc);
- CQSelObjManager * pSel = pDoc->m_pMap->GetSelObjManager();
- ASSERT(pSel);
- int nSel = pSel->GetSelObjCount();
- if(nSel == 0)
- {
- pCmdUI->Enable(FALSE);
- return;
- }
- pCmdUI->Enable(TRUE);
- }
- void CQGISView::OnMenuHideObjQgis()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- ASSERT(pDoc);
- CQSelObjManager * pSM = pDoc->m_pMap->GetSelObjManager();
- ASSERT(pSM);
- int nSelCount = pSM->GetCount();
- if(nSelCount == 0)return;
- POSITION pos = pSM->GetHeadPosition();
- while (pos)
- {
- CQBaseObj * pObj = pSM->GetNext(pos);
- if(!pObj || pObj->GetObjDeleted() || pObj->GetObjHided()) continue;
- pObj->SetObjHided(TRUE);
- }
- InvalidateRect(NULL,FALSE);
- pSM->EndFlash((CWnd *)this,2);
- }
- void CQGISView::OnUpdateMenuHideObjQgis(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- ASSERT(pDoc);
- int nSel = pDoc->m_pMap->GetSelObjManager()->GetSelObjCount();
- if(nSel)
- pCmdUI->Enable(TRUE);
- else
- pCmdUI->Enable(FALSE);
- }
- void CQGISView::OnMenuShowObjQgis()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- ASSERT(pDoc);
- CQMapObj * pMap = pDoc->m_pMap;
- ASSERT(pMap);
- int nLayerCount = pMap->GetLayerCount();
- for(int i=0;i<nLayerCount;i++)
- {
- CQLayerObj * pLayer = pMap->GetLayer(i);
- if(!pLayer || pLayer->GetDeleteFlag() || !pLayer->GetShowFlag()) continue;
- int nObjCount = pLayer->GetObjCount();
- for(int j=0;j<nObjCount;j++)
- {
- CQBaseObj * pObj = pLayer->GetObj(j);
- if(!pObj || pObj->GetObjDeleted() || !pObj->GetObjHided()) continue;
- pObj->SetObjHided(FALSE);
- }
- }
- InvalidateRect(NULL,FALSE);
- }
- void CQGISView::OnMenuRotateObjQgis()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- ASSERT(pDoc);
- pDoc->m_MenuItemID = IDM_MENU_ROTATE_OBJ_QGIS;
- m_nLbtDown = 0;
- }
- void CQGISView::OnUpdateMenuRotateObjQgis(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- ASSERT(pDoc);
- int nSel = pDoc->m_pMap->GetSelObjManager()->GetSelObjCount();
- if(nSel)
- pCmdUI->Enable(TRUE);
- else
- pCmdUI->Enable(FALSE);
- }
- void CQGISView::OnMenuCutLineQgis()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- ASSERT(pDoc);
- pDoc->m_MenuItemID = IDM_MENU_CUT_LINE_QGIS; //剪断线
- m_nLbtDown = 0;
- }
- void CQGISView::OnUpdateMenuCutLineQgis(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- ASSERT(pDoc);
- int nSel = pDoc->m_pMap->GetSelObjManager()->GetSelObjCount();
- if(nSel == 1 && pDoc->m_pMap->GetSelObjManager()->GetCurSelObj()->GetObjType() == QGIS_OBJ_LINE)
- pCmdUI->Enable(TRUE);
- else
- pCmdUI->Enable(FALSE);
- }
- void CQGISView::FindNearestTwoPoints(int &nFirst,CQPoint *pPt, CQLineObj *pLine)
- {
- if(!pLine || !pPt)return;
- int nPtCount = pLine->m_PtList.GetSize();
- if(nPtCount <=1 )return;
- else //这里要使用排序算法
- {
- vector<double> dDis;
- CQPoint * ptf = NULL;
- for(int i=0;i<nPtCount;i++)
- {
- ptf = pLine->m_PtList.GetPoint(i);
- double fDis = pPt->Distance(*ptf);
- dDis.push_back(fDis); //将到每个点的距离都保存起来 进行排序
- }
- double fMin = dDis[0];
- nFirst = 0;
- for(int m=0;m<nPtCount;m++)
- {
- double fd = dDis[m];
- if(fd<=fMin)
- {
- fMin = fd;
- nFirst = m;
- }
- }
- }
- }
- void CQGISView::OnMenuDeleteLineQgis()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- ASSERT(pDoc);
- CQSelObjManager * pSM = pDoc->m_pMap->GetSelObjManager();
- ASSERT(pSM);
- int nSelCount = pSM->GetSelObjCount();
- POSITION pos = pSM->GetHeadPosition();
- while (pos)
- {
- CQBaseObj * pObj = pSM->GetNext(pos);
- if(pObj && !pObj->GetObjDeleted() && !pObj->GetObjHided())
- {
- pObj->SetObjDeleted(TRUE);
- }
- }
- pSM->EndFlash((CWnd *)this,2);
- InvalidateRect(NULL,TRUE);
- }
- void CQGISView::OnUpdateMenuDeleteLineQgis(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- CQSelObjManager * pSM = pDoc->m_pMap->GetSelObjManager();
- int nSelObj = pSM->GetSelObjCount();
- BOOL bTrue = TRUE;
- POSITION pos = pSM->GetHeadPosition();
- while (pos)
- {
- CQBaseObj * pObj = (CQBaseObj *)pSM->GetNext(pos);
- if(pObj->GetObjType() == QGIS_OBJ_POINT)
- {
- bTrue = FALSE;
- break;
- }
- }
- pCmdUI->Enable(bTrue);
- }
- void CQGISView::OnMenuMoveLineQgis()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- pDoc->m_MenuItemID = IDM_MENU_MOVE_LINE_QGIS;
- m_nLbtDown = 0;
- }
- void CQGISView::OnUpdateMenuMoveLineQgis(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- CQSelObjManager * pSM = pDoc->m_pMap->GetSelObjManager();
- int nSelObj = pSM->GetSelObjCount();
- BOOL bTrue = TRUE;
- POSITION pos = pSM->GetHeadPosition();
- while (pos)
- {
- CQBaseObj * pObj = (CQBaseObj *)pSM->GetNext(pos);
- if(pObj->GetObjType() == QGIS_OBJ_POINT)
- {
- bTrue = FALSE;
- break;
- }
- }
- pCmdUI->Enable(bTrue);
- }
- void CQGISView::OnUpdateMenuRotateLineQgis(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- CQSelObjManager * pSM = pDoc->m_pMap->GetSelObjManager();
- int nSelObj = pSM->GetSelObjCount();
- BOOL bTrue = TRUE;
- POSITION pos = pSM->GetHeadPosition();
- while (pos)
- {
- CQBaseObj * pObj = (CQBaseObj *)pSM->GetNext(pos);
- if(pObj->GetObjType() == QGIS_OBJ_POINT)
- {
- bTrue = FALSE;
- break;
- }
- }
- pCmdUI->Enable(bTrue);
- }
- void CQGISView::OnMenuRotateLineQgis()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- pDoc->m_MenuItemID = IDM_MENU_ROTATE_LINE_QGIS;
- m_nLbtDown = 0;
- }
- void CQGISView::OnMenuLinkLineQgis()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- pDoc->m_MenuItemID = IDM_MENU_LINK_LINE_QGIS_;
- m_nLbtDown = 0;
- }
- void CQGISView::OnMenuMirrorLineXQgis()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- pDoc->m_MenuItemID = IDM_MENU_MIRROR_LINE_X_QGIS;
- m_nLbtDown = 0;
- }
- void CQGISView::OnMenuMirrorLineYQgis()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- pDoc->m_MenuItemID = IDM_MENU_MIRROR_LINE_Y_QGIS;
- m_nLbtDown = 0;
- }
- void CQGISView::OnMenuMirrorOQgis()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- pDoc->m_MenuItemID = IDM_MENU_MIRROR_O_QGIS;
- m_nLbtDown = 0;
- }
- //添加矩形
- void CQGISView::OnMenuAddRectQgis()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- pDoc->m_MenuItemID = IDM_MENU_ADD_RECT_QGIS;
- m_nLbtDown = 0;
- }
- void CQGISView::OnMenuLayerManagerQgis()
- {
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- ASSERT(pDoc);
- CQCoordSys * pSys = NULL;
- CQMapObj * pMap = pDoc->m_pMap;
- ASSERT(pMap);
- pSys = pMap->GetCoordSysPointer();
- ASSERT(pSys);
- CDlgLayerManager layerdlg(0,pMap);
- if(layerdlg.DoModal() == IDOK)
- {
- CBoundaryRect Brect;
- CRect rectTemp;
- pMap->CalculateBoundary(&Brect);
- pSys->WPtoLP(Brect,&rectTemp);
- InvalidateRect(rectTemp,TRUE);
- }
- }
- void CQGISView::OnMenuAddCircleQgis()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- pDoc->m_MenuItemID = IDM_MENU_ADD_CIRCLE_QGIS;
- m_nLbtDown = 0;
- }
- void CQGISView::OnMenuAddEllipseQgis()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = (CQGISDoc *)GetDocument();
- pDoc->m_MenuItemID = IDM_MENU_ADD_ELLIPSE_QGIS;
- m_nLbtDown = 0;
- CString szHelp = "本系统绘制椭圆,先拖动鼠标左键确定两端点确定椭圆的大小,然后在拉动橡皮线对椭圆的形状进行调整";
- AfxMessageBox(szHelp);
- }
- //创建一个椭圆对象 并且返回其指针
- CQEllipseObj * CQGISView::CreateEllipse(CQEllipseObj & Ellipse)
- {
- CQEllipseObj * pEllipse = new CQEllipseObj;
- CQPoint centerPt;
- Ellipse.GetCenterPoint(centerPt);
- pEllipse->SetEllipseParams(centerPt.GetX(),centerPt.GetY(),Ellipse.GetLongAxis(),Ellipse.GetShortAxis(),
- Ellipse.GetStartAngleRad(),Ellipse.GetEndAngleRad(),Ellipse.GetRotateAngleRad());
- return pEllipse;
- }
- void CQGISView::DrawEllipse(CQEllipseObj & ellipse,CDC * pDC)
- {
- CQCoordSys * pCs = GetDocument()->m_pMap->GetCoordSysPointer();
- if(!pCs)return;
- double x=0,y=0;//世界坐标
- //////////////////////////////////////////////////////////////////////////
- x = ellipse.GetStartAngleRad() - ellipse.GetRotateAngleRad();
- y = ellipse.GetEndAngleRad() - ellipse.GetRotateAngleRad();
- double dStart = min(x,y);
- double dEnd = max(x,y);
- double dStep = fabs(dEnd-dStart) / 100;//100个点绘制椭圆
- if(dStep==0) return;
- long lx=0,ly=0;//逻辑坐标
- double a = ellipse.GetLongAxis();
- double b = ellipse.GetShortAxis();
- double i = dStart;
- double xx=0,yy=0;
- double ro = 0;
- ro = a*b / sqrt( b*b*cos(i)*cos(i) + a*a*sin(i)*sin(i) );
- x = cos(i) * ro;
- y = sin(i) * ro;
- xx = x*cos(ellipse.GetRotateAngleRad()) - y*sin(ellipse.GetRotateAngleRad());
- yy = x*sin(ellipse.GetRotateAngleRad()) + y*cos(ellipse.GetRotateAngleRad());
- CQPoint ptCenter;
- ellipse.GetCenterPoint(ptCenter);
- xx += ptCenter.GetX();
- yy += ptCenter.GetY();
- pCs->WPtoLP(xx,yy, &lx,&ly);
- pDC->MoveTo(lx,ly);
- for(;i<=dEnd;i+=dStep)
- {
- ro = a*b / sqrt( b*b*cos(i)*cos(i) + a*a*sin(i)*sin(i) );
- x = cos(i) * ro;
- y = sin(i) * ro;
- xx = x*cos(ellipse.GetRotateAngleRad()) - y*sin(ellipse.GetRotateAngleRad());
- yy = x*sin(ellipse.GetRotateAngleRad()) + y*cos(ellipse.GetRotateAngleRad());
- xx += ptCenter.GetX();
- yy += ptCenter.GetY();
- pCs->WPtoLP(xx,yy, &lx,&ly);
- pDC->LineTo(lx,ly);
- }
- i = dEnd;
- ro = a*b / sqrt( b*b*cos(i)*cos(i) + a*a*sin(i)*sin(i) );
- x = cos(i) * ro;
- y = sin(i) * ro;
- xx = x*cos(ellipse.GetRotateAngleRad()) - y*sin(ellipse.GetRotateAngleRad());
- yy = x*sin(ellipse.GetRotateAngleRad()) + y*cos(ellipse.GetRotateAngleRad());
- xx += ptCenter.GetX();
- yy += ptCenter.GetY();
- pCs->WPtoLP(xx,yy, &lx,&ly);
- pDC->LineTo(lx,ly);
- }
- //保证点属性菜单 打开后有意义
- void CQGISView::OnUpdateMenuPointAttsetQgis(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- CQGISDoc * pDoc = GetDocument(); //获取文档对象的指针
- ASSERT(pDoc);
- CQSelObjManager * psel = pDoc->m_pMap->GetSelObjManager(); //选择对象管理器
- ASSERT(psel);
- int nSel = psel->GetSelObjCount();
- if(nSel == 0)
- {
- pCmdUI->Enable(FALSE);
- return;
- }
- CQBaseObj * pObj = psel->GetCurSelObj();
- if(pObj->GetObjType() == QGIS_OBJ_POINT && nSel == 1)
- pCmdUI->Enable(TRUE);
- else
- pCmdUI->Enable(FALSE);
- }
- void CQGISView::OnMenuPointAttsetQgis()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- CQMapObj * pMap = pDoc->m_pMap;
- ASSERT(pMap);
- CQSelObjManager * pSel = pDoc->m_pMap->GetSelObjManager();
- ASSERT(pSel); // 获取选择对象管理器
- CQCoordSys * pSys = pMap->GetCoordSysPointer();
- ASSERT(pSys);
- CQPointObj * pPoint = NULL;
- pPoint = static_cast<CQPointObj *>(pSel->GetCurSelObj()); //static_cast在向下转换中是安全的
- if(pPoint != NULL)
- {
- CQDlgPtAttSet ptDlg(pMap,pPoint);
- if(ptDlg.DoModal() == IDOK)
- {
- CBoundaryRect bRect;
- pPoint->CalculateBoundary(&bRect);
- CRect rect;
- pSys->WPtoLP(bRect,&rect);
- pSel->EndFlash((CWnd*)this,2);
- InvalidateRect(rect,TRUE);
- }
- }
- }
- //连点成线功能采取交互形式,每次选中一个点加入到线对象里
- void CQGISView::OnMenuLinkPointToLineQgis()
- {
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- pDoc->m_MenuItemID = IDM_MENU_LINK_POINT_TO_LINE_QGIS;
- m_nLbtDown = 0;
- }
- //添加流线
- void CQGISView::OnMenuAddPolylineStream()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- pDoc->m_MenuItemID = IDM_MENU_ADD_POLYLINE_STREAM;
- m_nLbtDown = 0;
- }
- //刷新视图的代码
- void CQGISView::OnMenuRefreshView()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- CQMapObj * pMap = pDoc->m_pMap;
- ASSERT(pMap);
- CQCoordSys * pCoord = pMap->GetCoordSysPointer();
- ASSERT(pCoord);
- CBoundaryRect bRect;
- CRect rectTemp;
- pMap->CalculateBoundary(&bRect);
- pCoord->WPtoLP(bRect,&rectTemp);
- InvalidateRect(rectTemp);
- }
- //全图显示
- void CQGISView::OnMenuDrawAllobjInView()
- {
- // TODO: Add your command handler code here
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- CQMapObj * pMap = pDoc->m_pMap;
- ASSERT(pMap);
- CQCoordSys * pCoord = pMap->GetCoordSysPointer();
- ASSERT(pCoord);
- pMap->DisplayAllInView(pCoord,this);
- }
- //图幅移动功能
- void CQGISView::OnMenuMoveMap()
- {
- CQGISDoc * pDoc = GetDocument(); //获取文档指针
- ASSERT(pDoc);
- if(pDoc->m_MenuItemID != ID_MENU_MOVE_MAP)
- {
- pDoc->m_MenuItemID = ID_MENU_MOVE_MAP;
- pDoc->m_hCursorCur = ::LoadCursor(AfxGetInstanceHandle(),
- MAKEINTRESOURCE(IDC_CURSOR_MOVE_MAP));
- m_nLbtDown = 0;
- }
- }
- CRect CQGISView::DrawAxis(BOOL bDraw,CDC * pDC,long &lWndX,long &lWndY)
- {
- //绘制坐标系的代码
- if(pDC == NULL)
- return CRect(0,0,0,0);
- if(bDraw != TRUE)
- return CRect(0,0,0,0);
- CRect rectAxis;
- long lOx = lWndX,lOy = lWndY;
- long xArrow = (long)(5*tan(PI/4));
- long Dx = lOx+80;
- CPen pen(PS_SOLID,0,RGB(0,0,0));
- CPen * pOldPen = pDC->SelectObject(&pen);
- CBrush brush(RGB(0,0,0));
- CBrush * pOldBrush = pDC->SelectObject(&brush);
- pDC->MoveTo(lOx,lOy-80);
- pDC->LineTo(lOx,lOy);
- pDC->LineTo(lOx+80,lOy);
- pDC->Ellipse(lOx-2,lOy-2,lOx+2,lOy+2);
- //画向上的箭头的右半部分
- pDC->MoveTo(lOx,lOy-80);
- pDC->LineTo(lOx+xArrow,lOy-70);
- pDC->TextOut(lOx+xArrow+10,lOy-70,"X");
- //画向上的箭头的左半部分
- pDC->MoveTo(lOx,lOy-80);
- pDC->LineTo(lOx-xArrow,lOy-70);
- //画向右的箭头
- pDC->MoveTo(lOx+70,lOy+xArrow);
- pDC->LineTo(lOx+80,lOy);
- pDC->LineTo(lOx+70,lOy-xArrow);
- pDC->TextOut(lOx+60,lOy-xArrow-15,"Y");
- rectAxis.left = lOx-5;
- rectAxis.top = lOy-80;
- rectAxis.bottom = lOy+xArrow;
- rectAxis.right = lOx+90;
- pDC->SelectObject(pOldBrush);
- pDC->SelectObject(pOldPen);
- return rectAxis;
- }
- void CQGISView::OnMenuAxisQgis()
- {
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- CQCoordSys * pSys = pDoc->m_pMap->GetCoordSysPointer();
- ASSERT(pSys);
- static BOOL bShowAxis = FALSE;
- static CRect rectAxis;
- if((bShowAxis = !bShowAxis)!=FALSE)
- {
- CClientDC dc(this);
- long lOrX = 0,lOrY = 0;
- pSys->GetStartOfWnd(lOrX,lOrY);
- m_bDrawAxis = TRUE;
- rectAxis = DrawAxis(m_bDrawAxis,&dc,lOrX,lOrY);
- }
- else
- {
- m_bDrawAxis = FALSE;
- InvalidateRect(rectAxis,TRUE);
- }
- }
- //曲线光滑
- void CQGISView::OnUpdateMenuInterpretationCurve(CCmdUI *pCmdUI)
- {
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- CQSelObjManager * pSel = pDoc->m_pMap->GetSelObjManager();
- ASSERT(pSel);
- if(pSel->GetSelObjCount() == 0)
- {
- pCmdUI->SetCheck(0);
- }
- else
- {
- POSITION pos = pSel->GetHeadPosition();
- WORD nCheck = 0;
- while (pos)
- {
- CQBaseObj * pObj = pSel->GetNext(pos);
- if(pObj->GetObjType() == QGIS_OBJ_LINE)
- {
- nCheck = 1;
- break;
- }
- }
- pCmdUI->SetCheck(nCheck);
- }
- }
- void CQGISView::OnUpdateMenuTwiceBcurve(CCmdUI *pCmdUI)
- {
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- CQSelObjManager * pSel = pDoc->m_pMap->GetSelObjManager();
- ASSERT(pSel);
- if(pSel->GetSelObjCount() == 0)
- {
- pCmdUI->SetCheck(0);
- }
- else
- {
- POSITION pos = pSel->GetHeadPosition();
- WORD nCheck = 0;
- while (pos)
- {
- CQBaseObj * pObj = pSel->GetNext(pos);
- if(pObj->GetObjType() == QGIS_OBJ_LINE)
- {
- nCheck = 1;
- break;
- }
- }
- pCmdUI->SetCheck(nCheck);
- }
- }
- void CQGISView::OnUpdateMenuThirdBcurve(CCmdUI *pCmdUI)
- {
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- CQSelObjManager * pSel = pDoc->m_pMap->GetSelObjManager();
- ASSERT(pSel);
- if(pSel->GetSelObjCount() == 0)
- {
- pCmdUI->SetCheck(0);
- }
- else
- {
- POSITION pos = pSel->GetHeadPosition();
- WORD nCheck = 0;
- while (pos)
- {
- CQBaseObj * pObj = pSel->GetNext(pos);
- if(pObj->GetObjType() == QGIS_OBJ_LINE)
- {
- nCheck = 1;
- break;
- }
- }
- pCmdUI->SetCheck(nCheck);
- }
- }
- void CQGISView::OnMenuInterpretationCurve()
- {
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- CQSelObjManager * pSel = pDoc->m_pMap->GetSelObjManager();
- ASSERT(pSel);
- CQCoordSys * pCoordsys = pDoc->m_pMap->GetCoordSysPointer();
- ASSERT(pCoordsys);
- POSITION pos = pSel->GetHeadPosition();
- CBoundaryRect bRect,bUnionRect;
- while (pos)
- {
- CQBaseObj * pObj = pSel->GetNext(pos);
- if(pObj->GetObjType() == QGIS_OBJ_LINE)
- {
- CQLineObj * pLine = dynamic_cast<CQLineObj *>(pObj);
- if(pLine != NULL)
- {
- pLine->PtListBeThin(0.00001f);
- pLine->SetSplineType(1);
- pLine->CalculateBoundary(&bRect);
- bRect.Lager(1.0f);
- bUnionRect.Union(&bRect);
- }
- }
- }
- if(bRect.IsValid() != FALSE)
- {
- CRect rectTm;
- pCoordsys->WPtoLP(bRect,&rectTm);
- InvalidateRect(rectTm,TRUE);
- }
- pSel->EndFlash(this->GetSafeHwnd(),1);
- }
- //二次样条
- void CQGISView::OnMenuTwiceBcurve()
- {
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- CQSelObjManager * pSel = pDoc->m_pMap->GetSelObjManager();
- ASSERT(pSel);
- CQCoordSys * pCoordsys = pDoc->m_pMap->GetCoordSysPointer();
- ASSERT(pCoordsys);
- POSITION pos = pSel->GetHeadPosition();
- CBoundaryRect bRect,bUnionRect;
- while (pos)
- {
- CQBaseObj * pObj = pSel->GetNext(pos);
- if(pObj->GetObjType() == QGIS_OBJ_LINE)
- {
- CQLineObj * pLine = dynamic_cast<CQLineObj *>(pObj);
- if(pLine != NULL)
- {
- pLine->PtListBeThin(0.00001f);
- pLine->SetSplineType(2);
- pLine->CalculateBoundary(&bRect);
- bUnionRect.Union(&bRect);
- }
- }
- }
- if(bRect.IsValid() != FALSE)
- {
- CRect rectTm;
- pCoordsys->WPtoLP(bRect,&rectTm);
- InvalidateRect(rectTm,TRUE);
- }
- pSel->EndFlash(this->GetSafeHwnd(),1);
- }
- //三次样条
- void CQGISView::OnMenuThirdBcurve()
- {
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- CQSelObjManager * pSel = pDoc->m_pMap->GetSelObjManager();
- ASSERT(pSel);
- CQCoordSys * pCoordsys = pDoc->m_pMap->GetCoordSysPointer();
- ASSERT(pCoordsys);
- POSITION pos = pSel->GetHeadPosition();
- CBoundaryRect bRect,bUnionRect;
- while (pos)
- {
- CQBaseObj * pObj = pSel->GetNext(pos);
- if(pObj->GetObjType() == QGIS_OBJ_LINE)
- {
- CQLineObj * pLine = dynamic_cast<CQLineObj *>(pObj);
- if(pLine != NULL)
- {
- pLine->PtListBeThin(0.00001f);
- pLine->SetSplineType(3);
- pLine->CalculateBoundary(&bRect);
- bUnionRect.Union(&bRect);
- }
- }
- }
- if(bRect.IsValid() != FALSE)
- {
- CRect rectTm;
- pCoordsys->WPtoLP(bRect,&rectTm);
- InvalidateRect(rectTm,TRUE);
- }
- pSel->EndFlash(this->GetSafeHwnd(),1);
- }
- //选择点
- void CQGISView::OnMenuSelectPointQgis()
- {
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- pDoc->m_MenuItemID = IDM_MENU_RECT_SELECT_OBJ_QGIS;
- m_nLbtDown = 0;
- m_nSelectType = QGIS_SELECT_POINT; //选择点
- }
- void CQGISView::OnMenuPtLinkToLineQgis()
- {
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- CQSelObjManager * pSM = pDoc->m_pMap->GetSelObjManager();
- ASSERT(pSM);
- CQCoordSys * pCoordSys = pDoc->m_pMap->GetCoordSysPointer();
- ASSERT(pCoordSys);
- if(pSM->GetSelObjCount()>2)
- return;
- POSITION pos = pSM->GetHeadPosition();
- CQPointObj * pPt = NULL;
- CQLineObj * pLine = NULL;
- CQBaseObj * pObj = NULL;
- while (pos)
- {
- pObj = pSM->GetNext(pos);
- if(pObj->GetObjType() == QGIS_OBJ_POINT)
- {
- pPt = dynamic_cast<CQPointObj *>(pObj);
- }
- else if(pObj->GetObjType() == QGIS_OBJ_LINE)
- {
- pLine = dynamic_cast<CQLineObj *>(pObj);
- }
- }
- if(pPt!=NULL && pLine!=NULL)
- {
- //求出点到直线两端点的距离
- CBoundaryRect bRect;
- int nPtCount = pLine->m_ptListDisplay.GetSize();
- CQPoint ptPt;
- double dx=0.0f,dy=0.0f;
- pPt->GetPointPos(dx,dy);
- ptPt.SetPoint(dx,dy);
- CQPoint * ptOne = pLine->m_PtList.GetPoint(0);
- CQPoint * ptLast = pLine->m_PtList.GetPoint(nPtCount-1);
- double dDisOne=0.0f,dDisTwo=0.0f;
- dDisOne = ptPt.Distance(*ptOne);
- dDisTwo = ptPt.Distance(*ptLast);
- if(dDisOne<=dDisTwo)
- {
- pLine->m_PtList.InsertAt(0,ptPt.GetX(),ptPt.GetY());
- }
- else
- {
- pLine->m_PtList.AddPoint(ptPt.GetX(),ptPt.GetY());
- }
- pLine->CalculateBoundary(&bRect);
- CRect rect;
- pCoordSys->WPtoLP(bRect,&rect);
- InvalidateRect(rect,FALSE);
- }
- pSM->EndFlash(this->GetSafeHwnd(),2);
- }
- void CQGISView::OnUpdateMenuPtLinkToLineQgis(CCmdUI *pCmdUI)
- {
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- CQSelObjManager * pSel = pDoc->m_pMap->GetSelObjManager();
- ASSERT(pSel);
- POSITION pos = pSel->GetHeadPosition();
- int nSelCount = pSel->GetSelObjCount();
- if(nSelCount<=0)
- {
- pCmdUI->Enable(FALSE);
- return;
- }
- int i=0;
- while (pos)
- {
- CQBaseObj * pObj = pSel->GetNext(pos);
- if(pObj->GetObjType() == QGIS_OBJ_POINT || pObj->GetObjType() == QGIS_OBJ_LINE)
- {
- break;
- }
- ++i;
- }
- if(i>nSelCount || nSelCount>2)
- {
- pCmdUI->Enable(FALSE);
- }
- else
- {
- pCmdUI->Enable(TRUE);
- }
- }
- //添加垂直线
- void CQGISView::OnMenuAddVervicalLineQgis()
- {
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- pDoc->m_MenuItemID = ID_MENU_ADD_VERVICAL_LINE_QGIS;
- m_nLbtDown = 0;
- }
- // 添加水平线
- void CQGISView::OnMenuAddHoriLineQgis()
- {
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- pDoc->m_MenuItemID = ID_MENU_ADD_HORI_LINE_QGIS;
- m_nLbtDown = 0;
- }
- void CQGISView::OnDglspkLineGetptQgis()
- {
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- CQSelObjManager * pSel = pDoc->m_pMap->GetSelObjManager();
- ASSERT(pSel);
- CQCoordSys * pCoordObj = pDoc->m_pMap->GetCoordSysPointer();
- ASSERT(pCoordObj);
- if(pSel->GetSelObjCount() == 1)
- {
- CQBaseObj * pBase = pSel->GetCurSelObj();
- if(pBase != NULL && pBase->GetObjType() == QGIS_OBJ_LINE)
- {
- CQLineObj * pLine = dynamic_cast<CQLineObj *>(pBase);
- if(pLine != NULL)
- {
- double fBeThin = 0.0f;
- CDlgLineBeThin dlg;
- if(dlg.DoModal() == IDOK)
- {
- fBeThin = dlg.m_fBeThin;
- CQGISAlgorithmLib::PtListLess(pLine->m_PtList,fBeThin);
- CBoundaryRect bRect;
- pLine->CalculateBoundary(&bRect);
- CRect rect;
- pCoordObj->WPtoLP(bRect,&rect);
- InvalidateRect(rect,TRUE);
- pSel->EndFlash(this->GetSafeHwnd(),2);
- }
- }
- }
- }
- }
- void CQGISView::OnUpdateDglspkLineGetptQgis(CCmdUI *pCmdUI)
- {
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- CQSelObjManager * pSel = pDoc->m_pMap->GetSelObjManager();
- ASSERT(pSel);
- if(pSel->GetSelObjCount() == 0)
- {
- pCmdUI->Enable(FALSE);
- }
- else
- {
- if(pSel->GetSelObjCount() == 1)
- {
- CQBaseObj * pbase = pSel->GetCurSelObj();
- if(pbase->GetObjType() == QGIS_OBJ_LINE)
- {
- pCmdUI->Enable(TRUE);
- return;
- }
- }
- }
- pCmdUI->Enable(FALSE);
- }
- void CQGISView::OnMenuAddTextQgis()
- {
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- pDoc->m_MenuItemID = ID_MENU_ADD_TEXT_QGIS;
- m_nLbtDown = 0;
- }
- void CQGISView::OnMenuTextParaSet()
- {
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- CQSelObjManager * pSel = pDoc->m_pMap->GetSelObjManager();
- ASSERT(pSel);
- CQCoordSys * pSys = pDoc->m_pMap->GetCoordSysPointer();
- ASSERT(pSys);
- POSITION pos = pSel->GetHeadPosition();
- CQTextObj * pTextObj = NULL;
- while (pos)
- {
- CQBaseObj * pObj = pSel->GetNext(pos);
- if(pObj->GetObjType() == QGIS_OBJ_LABEL)
- {
- pTextObj = dynamic_cast<CQTextObj *>(pObj);
- break;
- }
- }
- if(pTextObj != NULL)
- {
- QDlgTextSet dlg(pTextObj);
- if(dlg.DoModal() == IDOK)
- {
- CBoundaryRect bRect;
- CRect rect;
- pTextObj->CalculateBoundary(&bRect);
- pSys->WPtoLP(bRect,&rect);
- pSel->EndFlash(this->GetSafeHwnd(),2);
- InvalidateRect(rect,TRUE);
- }
- }
- }
- //Excel文件矢量化
- void CQGISView::OnMenuReadExcelQgis()
- {
- CQGISDoc * pDoc = GetDocument();
- ASSERT(pDoc);
- pDoc->m_MenuItemID = ID_MENU_READ_EXCEL_QGIS;
- m_nLbtDown = 0;
- }