BOOL COXScreenGrabber::GrabTracker(CWnd* pWndFromStartPoint, CPoint StartPoint, CWnd* pWndForRect)
{
	// some simple validations
	if (pWndFromStartPoint == NULL)
		pWndFromStartPoint = CWnd::GetDesktopWindow();

	if (pWndForRect == NULL)
		return FALSE;

	// the startpoint is defined in the client coordinate system of pWndFromStartPoint
	// but the tracking rect will be defined within pWndForRect, so convert
	pWndFromStartPoint->MapWindowPoints(pWndForRect, &StartPoint, 1);

	CRectTracker tracker;

	// do the tracking
	if (tracker.TrackRubberBand(pWndForRect, StartPoint, TRUE))
	{
		CRect rect = tracker.m_rect;

		// because we allowed inversion in the tracking, normalize the rect
		rect.NormalizeRect();

		// the screengrabber needs screen coordinates
		pWndForRect->ClientToScreen(&rect);

		return GrabRectangle(rect);
	}
	else
		return FALSE;
}
Example #2
0
void CCamShiftDemoView::OnLButtonDown(UINT nFlags, CPoint point) 
{
    int w = 320;
    int h = 240;
    
    CMainFrame*  frame = (CMainFrame*)AfxGetMainWnd();
    CRect  rect = CRect( 0, 0, 0, 0 );
    CRectTracker  tracker;

    CRect srcRect = frame->StartTrackerInit();
    w = srcRect.Width();
    h = srcRect.Height();

    /* recalc rect position according to "bottom-origin" and scale it */ 
    if( tracker.TrackRubberBand( this, point ))
    {
        CRect all;
        int sx, sy;

        frame->GetScaleFactor( sx, sy );
        GetClientRect( &all );
        tracker.GetTrueRect( &rect );
        
        rect.SetRect( rect.left*w*100/(sx*all.Width()), 
                      (all.bottom - rect.bottom*100/sy)*h/all.Height(),
                      rect.right*w*100/(sx*all.Width()),
                      (all.bottom - rect.top*100/sy)*h/all.Height());
    }
    frame->EndTrackerInit( rect );
}
Example #3
0
void Cv11View::OnLButtonDown(UINT nFlags, CPoint point)
{
	CRectTracker rect;
	if (rect.TrackRubberBand(this, point, 1)) {
		rc = rect.m_rect;
		Invalidate();
	}
}
void CIMDisplayView::OnLButtonDown(UINT nFlags, CPoint point) 
{
    CIMDisplayDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);

    CRect rectSave;
    m_tracker.GetTrueRect(rectSave);
    if (m_tracker.HitTest(point) < 0)
    {
		// just to demonstrate CRectTracker::TrackRubberBand
		CRectTracker tracker;
		if (tracker.TrackRubberBand(this, point, true))
		{
			// MessageBeep(0); // beep indicates TRUE

			// see if rubber band intersects with the doc's tracker
			CRect rectT;
			tracker.m_rect.NormalizeRect(); // so intersect rect works
			if (rectT.IntersectRect(tracker.m_rect, m_tracker.m_rect))
			{
				/*
				// dotted line for outline
				m_tracker.m_nStyle &= CRectTracker::dottedLine;

				// if so, put resize handles on it (ie. select it)
				if (m_tracker.m_nStyle & CRectTracker::resizeInside)
				{
					// swap from resize inside to resize outside for effect
					m_tracker.m_nStyle &= ~CRectTracker::resizeInside;
					m_tracker.m_nStyle |= CRectTracker::resizeOutside;
				}
				else
				{
					// just use inside resize handles on first time
					m_tracker.m_nStyle &= ~CRectTracker::resizeOutside;
					m_tracker.m_nStyle |= CRectTracker::resizeInside;
				}
				*/

				UpdateTheView( false );
			}

			m_tracker.m_rect = tracker.m_rect;
		} else {	// clear the selection!
			m_tracker.m_rect.left	= m_tracker.m_rect.right = 0;
			m_tracker.m_rect.top	= m_tracker.m_rect.bottom = 0;
		}

		UpdateTheView( false );
    }
    else if (m_tracker.Track(this, point, true))
    {
		UpdateTheView( false );
    }

    CScrollView::OnLButtonDown(nFlags, point);
}
Example #5
0
void Cv11View::OnLButtonDown(UINT nFlags, CPoint point)
{
	CRectTracker tracker;
	if (tracker.TrackRubberBand(this, point)) {
		rc = tracker.m_rect;
		Invalidate();
	}
	
	// TODO: Add your message handler code here and/or call default
}
Example #6
0
void CImageSelect::OnLButtonDown(UINT nFlags, CPoint point)
{
    // TODO: Add your message handler code here and/or call default
    CDC *pdc=GetDC();
    if (m_tracker.HitTest(point) < 0)
    {
        CRectTracker track;
        CRect rImage((500-(int)(image.GetWidth()*ZoomFactor))/2,(300-(int)(image.GetHeight()*ZoomFactor))/2,
                     (500-(int)(image.GetWidth()*ZoomFactor))/2+(int)(image.GetWidth()*ZoomFactor),
                     (300-(int)(image.GetHeight()*ZoomFactor))/2+(int)(image.GetHeight()*ZoomFactor));
        if (track.TrackRubberBand(this, point, true))
        {
            track.m_rect.NormalizeRect();
            m_tracker.m_rect = track.m_rect;
            //确保发送图片为正方形
            int nlength = max(track.m_rect.Height(),track.m_rect.Width());
            m_tracker.m_rect.bottom = m_tracker.m_rect.top + nlength;
            m_tracker.m_rect.right = m_tracker.m_rect.left + nlength;
            //确保选取框在图片上
            if (m_tracker.m_rect.left<rImage.left)
            {
                m_tracker.m_rect.right += rImage.left-m_tracker.m_rect.left;
                m_tracker.m_rect.left = rImage.left;
            }
            if (m_tracker.m_rect.top<rImage.top)
            {
                m_tracker.m_rect.bottom += rImage.top-m_tracker.m_rect.top;
                m_tracker.m_rect.top = rImage.top;
            }
            if (m_tracker.m_rect.right>rImage.right)
            {
                m_tracker.m_rect.right = rImage.right;
            }
            if (m_tracker.m_rect.bottom>rImage.bottom)
            {
                m_tracker.m_rect.bottom = rImage.bottom;
            }
            nlength = min(m_tracker.m_rect.Height(),m_tracker.m_rect.Width());
            m_tracker.m_rect.bottom = m_tracker.m_rect.top + nlength;
            m_tracker.m_rect.right = m_tracker.m_rect.left + nlength;
            SetImageRectSelection(&(m_tracker.m_rect));
            m_CheckOk.EnableWindow(TRUE);
        }
        else
        {
            m_tracker.m_rect = CRect(0,0,0,0);
        }
    }
    CRect rect;
    GetClientRect(&rect);
    InvalidateRect(&rect,TRUE);
    showed = false;
    CDialog::OnLButtonDown(nFlags, point);
}
Example #7
0
void CTrackerView::OnLButtonDown(UINT nFlags, CPoint point)
{
	CTrackerDoc* pDoc = GetDocument();
	CRect rectSave;
	pDoc->m_tracker.GetTrueRect(rectSave);
	if (pDoc->m_tracker.HitTest(point) < 0)
	{
		// just to demonstrate CRectTracker::TrackRubberBand
		CRectTracker tracker;
		if (tracker.TrackRubberBand(this, point, pDoc->m_bAllowInvert))
		{
			MessageBeep(0); // beep indicates TRUE

			// see if rubber band intersects with the doc's tracker
			CRect rectT;
			tracker.m_rect.NormalizeRect(); // so intersect rect works
			if (rectT.IntersectRect(tracker.m_rect, pDoc->m_tracker.m_rect))
			{
				// if so, put resize handles on it (ie. select it)
				if (pDoc->m_tracker.m_nStyle & CRectTracker::resizeInside)
				{
					// swap from resize inside to resize outside for effect
					pDoc->m_tracker.m_nStyle &= ~CRectTracker::resizeInside;
					pDoc->m_tracker.m_nStyle |= CRectTracker::resizeOutside;
				}
				else
				{
					// just use inside resize handles on first time
					pDoc->m_tracker.m_nStyle &= ~CRectTracker::resizeOutside;
					pDoc->m_tracker.m_nStyle |= CRectTracker::resizeInside;
				}
				pDoc->SetModifiedFlag();
				pDoc->UpdateAllViews(NULL, (LPARAM)(LPCRECT)rectSave);
				pDoc->UpdateAllViews(NULL);
			}
		}
	}
	else if (pDoc->m_tracker.Track(this, point, pDoc->m_bAllowInvert))
	{
		// normal tracking action, when tracker is "hit"
		pDoc->SetModifiedFlag();
		pDoc->UpdateAllViews(NULL, (LPARAM)(LPCRECT)rectSave);
		pDoc->UpdateAllViews(NULL);
	}
	CView::OnLButtonDown(nFlags, point);
}
Example #8
0
void CToolMapZoomin::LButtonDownEvent (UINT nFlags, CPoint point)
{
	//获取活动地图控件
	if(!m_pMapCtrl)
		return;

	//获取活动地区
	Carto::CMapPtr pMap = m_pMapCtrl->GetMap();
	if(!pMap)
		return;

	if(m_pMapCtrl->IsActiveX())
	{
		double geoCenterX, geoCenterY;
		pMap->GetDisplay()->GetDisplayTransformation().ConvertDisplayToGeo(point.x,point.y,geoCenterX, geoCenterY);
		pMap->GetDisplay()->GetDisplayTransformation().SetGeoCenterX(geoCenterX);
		pMap->GetDisplay()->GetDisplayTransformation().SetGeoCenterY(geoCenterY);
		pMap->GetDisplay()->GetDisplayTransformation().ZoomViewPosScale(0.667);
	}
	else
	{
		CRectTracker selectBox = CRectTracker(CRect(0,0,0,0),
			CRectTracker::solidLine +
			CRectTracker::resizeOutside );

		selectBox.m_sizeMin = 0;

		bool selected = selectBox.TrackRubberBand(dynamic_cast<CWnd*>(m_pMapCtrl), point, FALSE );

		CRect rect = selectBox.m_rect;
		rect.NormalizeRect();

		if( ( rect.BottomRight().x - rect.TopLeft().x ) < 10 &&
			( rect.BottomRight().y - rect.TopLeft().y ) < 10 )
			selected = false;


		if( selected == true )
		{
			GEOMETRY::geom::Envelope envelop;
			DIS_RECT disrect;
			disrect.left = rect.left;
			disrect.right = rect.right;
			disrect.top = rect.top;
			disrect.bottom = rect.bottom;

			pMap->GetDisplay()->GetDisplayTransformation().TransformToGeo(disrect,&envelop);
			pMap->GetDisplay()->GetDisplayTransformation().FitViewBound(envelop,true);

		}
		else
		{
			double geoCenterX, geoCenterY;
			pMap->GetDisplay()->GetDisplayTransformation().ConvertDisplayToGeo(point.x,point.y,geoCenterX, geoCenterY);
			pMap->GetDisplay()->GetDisplayTransformation().SetGeoCenterX(geoCenterX);
			pMap->GetDisplay()->GetDisplayTransformation().SetGeoCenterY(geoCenterY);
			pMap->GetDisplay()->GetDisplayTransformation().ZoomViewPosScale(0.667);
		}
		
	}
	
     m_pMapCtrl->UpdateControl(drawAll);
	//记录范围
    GEOMETRY::geom::Envelope curExtent;
    pMap->GetDisplay()->GetDisplayTransformation().GetGeoBound(curExtent);
    pMap->GetDisplay()->GetDisplayTransformation().RecordCurExtent(curExtent);

}
Example #9
0
	void CLayoutMapZoomout::LButtonDownEvent (UINT nFlags, CPoint point)
	{
		//获取活动地图控件
		Framework::IMapCtrl *pMapCtrl = Framework::IMapCtrl::GetActiveMapCtrl();
		if(!pMapCtrl)
			return;

		Carto::CMapPtr pMap = pMapCtrl->GetMap();
		if(!pMap)
			return;

		Framework::ILayoutCtrl *pLayoutCtrl = Framework::ILayoutCtrl::GetActiveLayoutCtrl();
		if(!pLayoutCtrl)
			return;

		Carto::CPageLayoutPtr pPageLayout = pLayoutCtrl->GetPageLayout();
		if(!pPageLayout)
			return;

		Element::CMapFrame* pMapFrame = NULL;
		Element::IElementPtr pElement = pPageLayout->GetGraphicLayer()->Reset();
		while(pElement)
		{
			if(pElement->GetType() != Element::ET_MAP_FRAME_ELEMENT)
			{
				pElement = pPageLayout->GetGraphicLayer()->Next();
				continue;
			}

			Element::CMapFrame* pTmpMapFrm = dynamic_cast<Element::CMapFrame*>(pElement.get());
			if(pTmpMapFrm->GetMap() != pMap)
			{
				pElement = pPageLayout->GetGraphicLayer()->Next();
				continue;
			}

			pMapFrame = pTmpMapFrm;
			break;
		}

		if(!pMapFrame)
			return;

		DIS_RECT* mapFrameBound = NULL;
		CreateDisplayRect(mapFrameBound);
		mapFrameBound = pPageLayout->GetDisplay()->GetDisplayTransformation().TransformToDisplay(pMapFrame->GetGeometry()->getEnvelopeInternal());

		//Selection Box
		CRectTracker selectBox = CRectTracker(CRect(0,0,0,0),
			CRectTracker::solidLine +
			CRectTracker::resizeOutside );

		selectBox.m_sizeMin = 0;
		bool selected = selectBox.TrackRubberBand(dynamic_cast<CWnd*>(pLayoutCtrl), point, FALSE );

		CRect rect = selectBox.m_rect;
		rect.NormalizeRect();
		if( ( rect.BottomRight().x - rect.TopLeft().x ) < 10 &&
			( rect.BottomRight().y - rect.TopLeft().y ) < 10 )
			selected = false;


		if( selected == true )
		{
			GEOMETRY::geom::Envelope envelop;

			pMap->GetDisplay()->GetDisplayTransformation().GetGeoBound(envelop);

			long lWidth = rect.Width();
			long lHeight = rect.Height();

			double rx = envelop.getWidth()/ lWidth;
			double ry = envelop.getHeight()/ lHeight;

			double dbScale = (rx > ry) ? rx : ry;

			pMap->GetDisplay()->GetDisplayTransformation().ZoomToFixScale(dbScale);

			CRect viewRect =pMap->GetDisplay()->GetDisplayTransformation().GetViewBound().GetRect();

			double dx=(rect.CenterPoint().x - mapFrameBound->left - viewRect.CenterPoint().x)*dbScale;
			double dy=(viewRect.CenterPoint().y - (rect.CenterPoint().y - mapFrameBound->top))*dbScale;

			pMap->GetDisplay()->GetDisplayTransformation().MoveViewBound(dx,dy);

		}
		else
		{
			double geoCenterX, geoCenterY;
			long x,y;
			x = point.x - mapFrameBound->left;
			y = point.y - mapFrameBound->top;
			pMap->GetDisplay()->GetDisplayTransformation().ConvertDisplayToGeo(x,y,geoCenterX, geoCenterY);
			pMap->GetDisplay()->GetDisplayTransformation().SetGeoCenterX(geoCenterX);
			pMap->GetDisplay()->GetDisplayTransformation().SetGeoCenterY(geoCenterY);
			pMap->GetDisplay()->GetDisplayTransformation().ZoomViewPosScale(1.5);	
		}

		GEOMETRY::geom::Envelope viewGeo;
		pMap->GetDisplay()->GetDisplayTransformation().GetGeoBound(viewGeo);
		pMap->SetViewEnvelope(viewGeo);


		FreeDisplayObj(mapFrameBound);
		pLayoutCtrl->UpdateControl();	
	}
Example #10
0
void CDemoView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	CDemoDoc* pDoc = GetDocument();
	if (pDoc) {
		switch(pDoc->m_tool){
		case 0: // select
		case 1:
			{
#ifdef VATI_EXTENSIONS
				if ( nFlags & MK_SHIFT )
					pDoc->m_isRectSel = 1;
				else
					pDoc->m_isRectSel = 0;
#endif
				CxImage* ima = pDoc->GetImage();
				if (ima) {
					m_RefScroll = GetScrollPosition();
					m_RefPoint.x = point.x;
					m_RefPoint.y = point.y;
				}
			}
			break;
		case 2: // zoom
			if (!pDoc->GetWaitingClick()) PostMessage(WM_COMMAND,ID_VIEW_ZOOMIN);
			break;
		case 4: // tracker
			{
				if (m_tracker.HitTest(point) < 0)
				{
					CRectTracker track;
					if (track.TrackRubberBand(this, point, true)) {
						track.m_rect.NormalizeRect();
						m_tracker.m_rect = track.m_rect;
						SetImageRectSelection(pDoc,&(m_tracker.m_rect));
					} else {
						m_tracker.m_rect = CRect(0,0,0,0);
					}
				} else {
					if (m_tracker.Track(this, point, true)){
						m_tracker.m_rect.NormalizeRect();
						SetImageRectSelection(pDoc,&(m_tracker.m_rect));
					} else {
						m_tracker.m_rect = CRect(0,0,0,0);
					}
				}
				OnUpdate(0,0,0);
			}
			break;
		case 3: //text
			{
				//pDoc->m_tool=-1;
				CxImage* ima = pDoc->GetImage();
				if (ima){
					pDoc->SubmitUndo();
					long x = point.x;
					long y = point.y;
					GetImageXY(pDoc, ima, &x,&y);
#ifndef VATI_EXTENSIONS
					RGBQUAD c = ima->RGBtoRGBQUAD(pDoc->m_color);
					c.rgbReserved=255;
					ima->DrawString(0,x,y,pDoc->m_text,c,
								pDoc->m_font.lfFaceName,
								pDoc->m_font.lfHeight,
								pDoc->m_font.lfWeight,
								pDoc->m_font.lfItalic,
								pDoc->m_font.lfUnderline,
								true);
#else
					ima->DrawStringEx(0,x,y,&theApp.m_text );
#endif
				}
				Invalidate(0);
			}
			break;
		case 5: //flood fill
			{
				CxImage* ima = pDoc->GetImage();
				if (ima){
					DlgFloodFill* pDlg = ((CMainFrame *)(AfxGetApp()->m_pMainWnd))->m_pDlgFlood;
					if (pDlg){
						pDlg->UpdateData(1);
						theApp.m_FloodColor = ima->RGBtoRGBQUAD(pDlg->m_color);
						theApp.m_FloodTolerance = pDlg->m_tol;
						theApp.m_FloodOpacity = pDlg->m_opacity;
						theApp.m_FloodSelect = pDlg->m_select;
					}
					pDoc->SubmitUndo();
					long x = point.x;
					long y = point.y;
					GetImageXY(pDoc, ima, &x,&y);
					long yflip = ima->GetHeight() - y - 1;
					ima->FloodFill(x,yflip,theApp.m_FloodColor,theApp.m_FloodTolerance,theApp.m_FloodOpacity,theApp.m_FloodSelect!=0);
					Invalidate(0);
				}
			}
			break;
		}

		if (pDoc->GetWaitingClick()){
			pDoc->SetWaitingClick(0);
			CxImage* ima = pDoc->GetImage();
			if (ima) {
				long x = point.x;
				long y = point.y;
				GetImageXY(pDoc, ima, &x,&y);
				if (ima->IsInside(x,y))	{
					pDoc->SubmitUndo();
					long yflip = ima->GetHeight() - y - 1;
					ima->SetTransIndex(ima->GetPixelIndex(x,yflip));
					// <DP> RGB transparency
					ima->SetTransColor(ima->GetPixelColor(x,yflip));
					pDoc->UpdateAllViews(NULL);
				}
			}
		}
#if CXIMAGE_DEMO_SELECT
		 else {
			KillTimer(1);
			pDoc->m_NumSel=0;
			m_SelShift=0;
		}
#endif
	}
	CScrollView::OnLButtonDown(nFlags, point);
}
Example #11
0
void CLayoutZoomoutTool::LButtonDownEvent (UINT nFlags, CPoint point)
{
	if(!m_pLayoutCtrl)
		return;


	if(!m_pLayoutCtrl->GetPageLayout())
		return;


	//Selection Box
	CRectTracker selectBox = CRectTracker(CRect(0,0,0,0),
		CRectTracker::solidLine +
		CRectTracker::resizeOutside );

	selectBox.m_sizeMin = 0;

	bool selected = selectBox.TrackRubberBand(dynamic_cast<CWnd*>(m_pLayoutCtrl), point, FALSE );

	CRect rect = selectBox.m_rect;
	rect.NormalizeRect();

	if( ( rect.BottomRight().x - rect.TopLeft().x ) < 10 &&
		( rect.BottomRight().y - rect.TopLeft().y ) < 10 )
		selected = false;

	
	if( selected == true )
	{
		GEOMETRY::geom::Envelope envelop;
		m_pLayoutCtrl->GetPageLayout()->GetDisplay()->GetDisplayTransformation().GetGeoBound(envelop);

		long lWidth = rect.Width();
		long lHeight = rect.Height();

		double rx = envelop.getWidth()/ lWidth;
		double ry = envelop.getHeight()/ lHeight;

		double dbScale = (rx > ry) ? rx : ry;

		m_pLayoutCtrl->GetPageLayout()->GetDisplay()->GetDisplayTransformation().ZoomToFixScale(dbScale);

		CRect viewRect =m_pLayoutCtrl->GetPageLayout()->GetDisplay()->GetDisplayTransformation().GetViewBound().GetRect();

		double dx=(rect.CenterPoint().x-viewRect.CenterPoint().x)*dbScale;
		double dy=(viewRect.CenterPoint().y-rect.CenterPoint().y)*dbScale;

		m_pLayoutCtrl->GetPageLayout()->GetDisplay()->GetDisplayTransformation().MoveViewBound(dx,dy);

	}
	else
	{
		double geoCenterX, geoCenterY;
		m_pLayoutCtrl->GetPageLayout()->GetDisplay()->GetDisplayTransformation().ConvertDisplayToGeo(point.x,point.y,geoCenterX, geoCenterY);
		m_pLayoutCtrl->GetPageLayout()->GetDisplay()->GetDisplayTransformation().SetGeoCenterX(geoCenterX);
		m_pLayoutCtrl->GetPageLayout()->GetDisplay()->GetDisplayTransformation().SetGeoCenterY(geoCenterY);
		m_pLayoutCtrl->GetPageLayout()->GetDisplay()->GetDisplayTransformation().ZoomViewPosScale(1.5);
	}
	m_pLayoutCtrl->UpdateControl(drawAll);

	
}
Example #12
0
void CActionSelByRect::LButtonDownEvent(UINT nFlags, CPoint point)
{
	

	//Selection Box
	CRectTracker selectBox = CRectTracker(CRect(0,0,0,0),
		CRectTracker::solidLine +
		CRectTracker::resizeOutside );

	selectBox.m_sizeMin = 0;

	bool selected = selectBox.TrackRubberBand(dynamic_cast<CWnd*>(m_pMapCtrl), point, FALSE );

	CRect rect = selectBox.m_rect;
	rect.NormalizeRect();

	if( ( rect.BottomRight().x - rect.TopLeft().x ) < 10 &&
		( rect.BottomRight().y - rect.TopLeft().y ) < 10 )
		selected = false;

	if(!selected)
	{
		return;
	}

	GEOMETRY::geom::Envelope envelop;
	DIS_RECT disrect;
	disrect.left = rect.left;
	disrect.right = rect.right;
	disrect.top = rect.top;
	disrect.bottom = rect.bottom;
	m_pMap->GetDisplay()->GetDisplayTransformation().TransformToGeo(disrect,&envelop);

	//构造一个用于查询的多边形

	Geodatabase::CSpatialQuery queryfilter;

	//Coordinate coord;
	//LinearRing *pring = GeometryFactory::getDefaultInstance()->createLinearRing();

	/*coord.x =envelop.getMinX();
	coord.y =envelop.getMinY();
	pring->AddPoint(coord);

	coord.x =cExtent.xmax;
	coord.y =cExtent.ymin;
	pring->AddPoint(coord);

	coord.x =cExtent.xmax;
	coord.y =cExtent.ymax;
	pring->AddPoint(coord);

	coord.x =cExtent.xmin;
	coord.y =cExtent.ymax;
	pring->AddPoint(coord);

	coord.x =cExtent.xmin;
	coord.y =cExtent.ymin;
	pring->AddPoint(coord);*/



	//构造一个空间查询条件
	GEOMETRY::geom::Geometry *pGeometry =GEOMETRY::geom::GeometryFactory::getDefaultInstance()->toGeometry(&envelop);
	queryfilter.SetGeometry(pGeometry);
	queryfilter.SetSpatialRel(Geodatabase::SpatialRelIntersects);

	ISelectFeatureTool::Select(&queryfilter);

	GEOMETRY::geom::GeometryFactory::getDefaultInstance()->destroyGeometry(pGeometry);


}
Example #13
0
void CSelectbyPointTool::LButtonDownEvent (UINT nFlags, CPoint point)
{
    //获取活动地图控件
    Framework::IMapCtrl *pMapCtrl = Framework::IMapCtrl::GetActiveMapCtrl();
    if(!pMapCtrl)
        return;
    m_pMapCtrl = pMapCtrl;
    //获取活动地区
    Carto::CMapPtr pMap = pMapCtrl->GetMap();
    if(!pMap)
        return;


    CRectTracker selectBox = CRectTracker(CRect(0,0,0,0),
                                          CRectTracker::solidLine +
                                          CRectTracker::resizeOutside );

    selectBox.m_sizeMin = 0;

    bool selected = selectBox.TrackRubberBand(dynamic_cast<CWnd*>(m_pMapCtrl), point, TRUE );

    CRect rect = selectBox.m_rect;
    rect.NormalizeRect();

    if( ( rect.BottomRight().x - rect.TopLeft().x ) < 10 &&
            ( rect.BottomRight().y - rect.TopLeft().y ) < 10 )
        selected = false;


    //矩形选择
    if( selected == true )
    {
        GEOMETRY::geom::Envelope envelop;
        DIS_RECT disrect;
        disrect.left = rect.left;
        disrect.right = rect.right;
        disrect.top = rect.top;
        disrect.bottom = rect.bottom;
        pMap->GetDisplay()->GetDisplayTransformation().TransformToGeo(disrect,&envelop);

        //构造一个用于查询的多边形

        Geodatabase::CSpatialQuery queryfilter;




        //构造一个空间查询条件
        GEOMETRY::geom::Geometry *pGeometry =GeometryFactory::getDefaultInstance()->toGeometry(&envelop);
        queryfilter.SetGeometry(pGeometry);
        queryfilter.SetSpatialRel(Geodatabase::SpatialRelIntersects);

        ISelectFeatureTool::Select(&queryfilter);

    }
    else
    {
        //点选
        GEOMETRY::geom::Envelope envelop;
        DIS_RECT rect;
        rect.left =point.x -m_SnapTol;
        rect.right =point.x+m_SnapTol;
        rect.top =point.y -m_SnapTol;
        rect.bottom =point.y+m_SnapTol;

        pMap->GetDisplay()->GetDisplayTransformation().TransformToGeo(rect,&envelop);
        //构造一个用于查询的多边形

        Geodatabase::CSpatialQuery queryfilter;


        //构造一个空间查询条件
        GEOMETRY::geom::Geometry *pGeometry =GeometryFactory::getDefaultInstance()->toGeometry(&envelop);
        queryfilter.SetGeometry(pGeometry);
        queryfilter.SetSpatialRel(Geodatabase::SpatialRelIntersects);

        ISelectFeatureTool::Select(&queryfilter);
    }

}