40楼#
发布于:2004-01-09 15:01
void CEditDrawObject::ClearSelectObject()
{ m_selLine = NULL ; m_selPolygon = NULL ; } void CEditDrawObject::AddVertex(CMoPoint pt) { if( !m_selLineRecSet && !m_selPolygon ) { return ; } double tol = m_pMap->ToMapDistance( 7 ); double dist ; if( m_selLineRecSet.GetCount() >= 0 ) { CMoFields stateFields ; CMoField stateShapeField ; CMoTrackingLayer tLayer(m_pMap->GetTrackingLayer()); CMoRectangle r ; VARIANT va1 , va2 ; m_selLineRecSet.MoveFirst(); while (!m_selLineRecSet.GetEof()) { stateFields = m_selLineRecSet.GetFields() ; stateShapeField = stateFields.Item(COleVariant(TEXT("Shape"))); CMoLine* pLine = new CMoLine(); pLine->AttachDispatch(stateShapeField.GetValue().pdispVal); /*r = pLine->GetExtent(); VariantInit(&va); va.vt = VT_DISPATCH; va.pdispVal = r.m_lpDispatch; m_pMap->RefreshRect( r );*/ VariantInit(&va1); va1.vt = VT_DISPATCH; VariantInit(&va2); va2.vt = VT_DISPATCH; CMoParts parts = pLine->GetParts();//È¡µÃÏߵIJ¿·Ö CMoPoints pts; CMoPoint point1 , point2 ; m_selLineRecSet.Edit(); for (int i = 0 ; i < parts.GetCount() ; i++ ) { pts = parts.Item( COleVariant(short( i )) );//È¡µÃ¸Ã²¿·ÖµÄµã¼¯ºÏ for (int j = 0 ; j < pts.GetCount() - 1 ; j++ ) { point1 = pts.Item( COleVariant(short( j ))); point2 = pts.Item( COleVariant(short( j + 1 ))); dist = pt.DistanceToSegment( point1, point2 ) ; if( dist <= tol ) { pts.Insert( j + 1 , pt ); m_selVertex = j ; break ; } } } r = pLine->GetExtent(); VariantInit(&va1); va1.vt = VT_DISPATCH; va1.pdispVal = r.m_lpDispatch; m_pMap->RefreshRect( r ); VariantInit(&va1); va1.vt = VT_DISPATCH; va1.pdispVal = pLine->m_lpDispatch; stateShapeField.Set_Value( va1 ); m_selLineRecSet.Update(); m_selLineRecSet.StopEditing(); delete pLine ; m_selLineRecSet.MoveNext(); SelectObject( pt , true ); } } if( m_selPolygonRecSet.GetCount() >= 0 ) { CMoFields stateFields ; CMoField stateShapeField ; CMoTrackingLayer tLayer(m_pMap->GetTrackingLayer()); CMoRectangle r ; VARIANT va1 , va2 ; m_selPolygonRecSet.MoveFirst(); while (!m_selPolygonRecSet.GetEof()) { stateFields = m_selPolygonRecSet.GetFields() ; stateShapeField = stateFields.Item(COleVariant(TEXT("Shape"))); CMoPolygon* pPolygon = new CMoPolygon(); pPolygon->AttachDispatch(stateShapeField.GetValue().pdispVal); /*r = pLine->GetExtent(); VariantInit(&va); va.vt = VT_DISPATCH; va.pdispVal = r.m_lpDispatch; m_pMap->RefreshRect( r );*/ VariantInit(&va1); va1.vt = VT_DISPATCH; VariantInit(&va2); va2.vt = VT_DISPATCH; CMoParts parts = pPolygon->GetParts();//È¡µÃÏߵIJ¿·Ö CMoPoints pts; CMoPoint point1 , point2 ; m_selPolygonRecSet.Edit(); for (int i = 0 ; i < parts.GetCount() ; i++ ) { pts = parts.Item( COleVariant(short( i )) );//È¡µÃ¸Ã²¿·ÖµÄµã¼¯ºÏ for (int j = 0 ; j < pts.GetCount() - 1 ; j++ ) { point1 = pts.Item( COleVariant(short( j ))); point2 = pts.Item( COleVariant(short( j + 1 ))); dist = pt.DistanceToSegment( point1, point2 ) ; if( dist <= tol ) { pts.Insert( j + 1 , pt ); m_selVertex = j ; break ; } } //ÔÚÒ»¸öµãºÍ×îºóÒ»µãÖ®¼äµÄ¶Îʱ point1 = pts.Item( COleVariant(short( pts.GetCount() - 1 ))); point2 = pts.Item( COleVariant(short( 0 ))); dist = pt.DistanceToSegment( point1, point2 ) ; if( dist <= tol ) { pts.Insert( 0 , pt ); m_selVertex = 0 ; } } r = pPolygon->GetExtent(); VariantInit(&va1); va1.vt = VT_DISPATCH; va1.pdispVal = r.m_lpDispatch; m_pMap->RefreshRect( r ); VariantInit(&va1); va1.vt = VT_DISPATCH; va1.pdispVal = pPolygon->m_lpDispatch; stateShapeField.Set_Value( va1 ); m_selPolygonRecSet.Update(); m_selPolygonRecSet.StopEditing(); delete pPolygon ; m_selPolygonRecSet.MoveNext(); SelectObject( pt , true ); } } } void CEditDrawObject::DeleteVertex() { if( !m_selLineRecSet && !m_selPolygon ) { return ; } if( m_selLineRecSet.GetCount() >= 0 ) { CMoFields stateFields ; CMoField stateShapeField ; CMoPoint ptAgainSelect ; CMoTrackingLayer tLayer(m_pMap->GetTrackingLayer()); CMoRectangle r ; VARIANT va; m_selLineRecSet.MoveFirst(); while (!m_selLineRecSet.GetEof()) { stateFields = m_selLineRecSet.GetFields() ; stateShapeField = stateFields.Item(COleVariant(TEXT("Shape"))); CMoLine* pLine = new CMoLine(); pLine->AttachDispatch(stateShapeField.GetValue().pdispVal); r = pLine->GetExtent(); VariantInit(&va); va.vt = VT_DISPATCH; va.pdispVal = r.m_lpDispatch; m_pMap->RefreshRect( r ); CMoParts parts = pLine->GetParts();//È¡µÃÏߵIJ¿·Ö CMoPoints pts; //CMoPoints points; m_selLineRecSet.Edit(); if( m_selVertex >= 0 ) { for (int i = 0 ; i < parts.GetCount() ; i++ ) { pts = parts.Item( COleVariant(short( i )) );//È¡µÃ¸Ã²¿·ÖµÄµã¼¯ºÏ if( pts.GetCount() == 2 ) continue ; for (int j = 0 ; j < pts.GetCount() ; j++ ) { if( m_partNO == i && m_selVertex == j ) { pts.Remove( j ); m_selVertex = j - 1; ptAgainSelect = pts.Item( COleVariant(short( j - 1 ) )); //m_curOperator = DelVertex ; //m_partNO = -1 ; //m_selVertex = -1 ; break; } } } } r = pLine->GetExtent(); VariantInit(&va); va.vt = VT_DISPATCH; va.pdispVal = r.m_lpDispatch; m_pMap->RefreshRect( r ); VariantInit(&va); va.vt = VT_DISPATCH; va.pdispVal = pLine->m_lpDispatch; stateShapeField.Set_Value( va ); m_selLineRecSet.Update(); m_selLineRecSet.StopEditing(); delete pLine ; m_selLineRecSet.MoveNext(); SelectObject( ptAgainSelect , true ); } } if( m_selPolygonRecSet.GetCount() >= 0 ) { CMoFields stateFields ; CMoField stateShapeField ; CMoPoint ptAgainSelect ; CMoTrackingLayer tLayer(m_pMap->GetTrackingLayer()); CMoRectangle r ; VARIANT va; m_selPolygonRecSet.MoveFirst(); while (!m_selPolygonRecSet.GetEof()) { stateFields = m_selPolygonRecSet.GetFields() ; stateShapeField = stateFields.Item(COleVariant(TEXT("Shape"))); CMoPolygon* pPolygon = new CMoPolygon(); pPolygon->AttachDispatch(stateShapeField.GetValue().pdispVal); r = pPolygon->GetExtent(); VariantInit(&va); va.vt = VT_DISPATCH; va.pdispVal = r.m_lpDispatch; m_pMap->RefreshRect( r ); CMoParts parts = pPolygon->GetParts();//È¡µÃÏߵIJ¿·Ö CMoPoints pts; //CMoPoints points; m_selPolygonRecSet.Edit(); if( m_selVertex >= 0 ) { for (int i = 0 ; i < parts.GetCount() ; i++ ) { pts = parts.Item( COleVariant(short( i )) );//È¡µÃ¸Ã²¿·ÖµÄµã¼¯ºÏ if( pts.GetCount() == 3 ) continue ; for (int j = 0 ; j < pts.GetCount() ; j++ ) { if( m_partNO == i && m_selVertex == j ) { pts.Remove( j ); m_selVertex = j - 1; ptAgainSelect = pts.Item( COleVariant(short( j - 1 ) )); //m_curOperator = DelVertex ; //m_partNO = -1 ; //m_selVertex = -1 ; break; } } } } r = pPolygon->GetExtent(); VariantInit(&va); va.vt = VT_DISPATCH; va.pdispVal = r.m_lpDispatch; m_pMap->RefreshRect( r ); VariantInit(&va); va.vt = VT_DISPATCH; va.pdispVal = pPolygon->m_lpDispatch; stateShapeField.Set_Value( va ); m_selPolygonRecSet.Update(); m_selPolygonRecSet.StopEditing(); delete pPolygon ; m_selPolygonRecSet.MoveNext(); SelectObject( ptAgainSelect , true ); } } } |
|
41楼#
发布于:2004-01-09 15:01
void CEditDrawObject::MoveVertex(CMoPoint pt)
{ if( !m_selLineRecSet && !m_selPolygon ) { return ; } if( m_selLineRecSet.GetCount() >= 0 ) { CMoFields stateFields ; CMoField stateShapeField ; CMoTrackingLayer tLayer(m_pMap->GetTrackingLayer()); CMoRectangle r ; VARIANT va; m_selLineRecSet.MoveFirst(); while (!m_selLineRecSet.GetEof()) { stateFields = m_selLineRecSet.GetFields() ; stateShapeField = stateFields.Item(COleVariant(TEXT("Shape"))); CMoLine* pLine = new CMoLine(); pLine->AttachDispatch(stateShapeField.GetValue().pdispVal); r = pLine->GetExtent(); VariantInit(&va); va.vt = VT_DISPATCH; va.pdispVal = r.m_lpDispatch; m_pMap->RefreshRect( r ); CMoParts parts = pLine->GetParts();//È¡µÃÏߵIJ¿·Ö CMoPoints pts; CMoPoint point; m_selLineRecSet.Edit(); for (int i = 0 ; i < parts.GetCount() ; i++ ) { pts = parts.Item( COleVariant(short( i )) );//È¡µÃ¸Ã²¿·ÖµÄµã¼¯ºÏ for (int j = 0 ; j < pts.GetCount() ; j++ ) { if( j == m_selVertex ) { pts.Set( j , pt ); } } } r = pLine->GetExtent(); VariantInit(&va); va.vt = VT_DISPATCH; va.pdispVal = r.m_lpDispatch; m_pMap->RefreshRect( r ); VariantInit(&va); va.vt = VT_DISPATCH; va.pdispVal = pLine->m_lpDispatch; stateShapeField.Set_Value( va ); m_selLineRecSet.Update(); m_selLineRecSet.StopEditing(); delete pLine ; m_selLineRecSet.MoveNext(); } } if( m_selPolygonRecSet.GetCount() >= 0 ) { CMoFields stateFields ; CMoField stateShapeField ; CMoTrackingLayer tLayer(m_pMap->GetTrackingLayer()); CMoRectangle r ; VARIANT va; m_selPolygonRecSet.MoveFirst(); while (!m_selPolygonRecSet.GetEof()) { stateFields = m_selPolygonRecSet.GetFields() ; stateShapeField = stateFields.Item(COleVariant(TEXT("Shape"))); CMoPolygon* pPolygon = new CMoPolygon(); pPolygon->AttachDispatch(stateShapeField.GetValue().pdispVal); r = pPolygon->GetExtent(); VariantInit(&va); va.vt = VT_DISPATCH; va.pdispVal = r.m_lpDispatch; m_pMap->RefreshRect( r ); CMoParts parts = pPolygon->GetParts();//È¡µÃÏߵIJ¿·Ö CMoPoints pts; CMoPoint point; m_selPolygonRecSet.Edit(); for (int i = 0 ; i < parts.GetCount() ; i++ ) { pts = parts.Item( COleVariant(short( i )) );//È¡µÃ¸Ã²¿·ÖµÄµã¼¯ºÏ for (int j = 0 ; j < pts.GetCount() ; j++ ) { if( j == m_selVertex ) { pts.Set( j , pt ); } } } r = pPolygon->GetExtent(); VariantInit(&va); va.vt = VT_DISPATCH; va.pdispVal = r.m_lpDispatch; m_pMap->RefreshRect( r ); VariantInit(&va); va.vt = VT_DISPATCH; va.pdispVal = pPolygon->m_lpDispatch; stateShapeField.Set_Value( va ); m_selPolygonRecSet.Update(); m_selPolygonRecSet.StopEditing(); delete pPolygon ; m_selPolygonRecSet.MoveNext(); } } SelectObject( pt , true ); } void CEditDrawObject::DragVirtualRect(CMoPoint pt) { if( !m_selLine && !m_selPolygon ) { return ; } if( m_selVertex == -1 ) return ; float x1 , y1; m_pMap->FromMapPoint( pt , &x1 , &y1 ); /////»­Ð§¹ûÏß(¾ØÐÎ)¿ªÊ¼////////////// CDC *pDC ; CPen pen, *pOldPen; pDC = m_pMap->GetDC(); pen.CreatePen(1, 1, (COLORREF)pDC->GetBkColor()); pOldPen = pDC->SelectObject(&pen); pDC->SelectStockObject( HOLLOW_BRUSH ); pDC->SetROP2 (R2_NOT); int xx1 ,yy1 ,xx2 ,yy2 ; xx1 = (int)m_oldX - 3 ; yy1 = (int)m_oldY + 3 ; xx2 = (int)m_oldX + 3 ; yy2 = (int)m_oldY - 3 ; pDC->MoveTo( xx1 , yy1 ); pDC->LineTo( xx2 , yy1 ); pDC->MoveTo( xx1 , yy1 ); pDC->LineTo( xx1 , yy2 ); pDC->MoveTo( xx2 , yy1 ); pDC->LineTo( xx2 , yy2 ); pDC->MoveTo( xx1 , yy2 ); pDC->LineTo( xx2 , yy2 ); xx1 = (int)x1 - 3 ; yy1 = (int)y1 + 3 ; xx2 = (int)x1 + 3 ; yy2 = (int)y1 - 3 ; pDC->MoveTo( xx1 , yy1 ); pDC->LineTo( xx2 , yy1 ); pDC->MoveTo( xx1 , yy1 ); pDC->LineTo( xx1 , yy2 ); pDC->MoveTo( xx2 , yy1 ); pDC->LineTo( xx2 , yy2 ); pDC->MoveTo( xx1 , yy2 ); pDC->LineTo( xx2 , yy2 ); //m_pMap->ReleaseDC( pDC ); /////»­Ð§¹ûÏß(¾ØÐÎ)½áÊø////////////// /////»­Ð§¹ûÏß(ÏðƤÏß)¿ªÊ¼////////////// //Ñ¡ÔñµÄÊǵÚÒ»¸ö¶Ëµã if( m_selVertex == 0) { if( m_selLine || m_selPolygon ) { CMoParts parts ; if( m_selLine ) { parts = m_selLine.GetParts();//È¡µÃÏߵIJ¿·Ö } else if( m_selPolygon ) { parts = m_selPolygon.GetParts();//È¡µÃÃæµÄ²¿·Ö } CMoPoints pts; CMoPoint ptNO2; pts = parts.Item( COleVariant(short( m_partNO )) );//È¡µÃ¸Ã²¿·ÖµÄµã¼¯ºÏ ptNO2 = pts.Item( COleVariant(short( 1 )));//È¡µÃ¸Ã¼¯ºÏµÄµã float No2X , No2Y ; m_pMap->FromMapPoint( ptNO2 , &No2X , &No2Y ); pDC->MoveTo( (int)No2X , (int)No2Y); pDC->LineTo( (int)m_oldX , (int)m_oldY ); pDC->MoveTo( (int)No2X , (int)No2Y ); pDC->LineTo( (int)x1 , (int)y1 ); //ÃæÊÇÊ×βÏàÁ¬µÄ£¬ÒªÁ¬×îºóÒ»µã if( m_selPolygon ) { CMoPoint ptLast; ptLast = pts.Item( COleVariant(short( m_vertexCount - 1 )));//È¡µÃ¸Ã¼¯ºÏµÄµã m_pMap->FromMapPoint( ptLast , &No2X , &No2Y ); pDC->MoveTo( (int)No2X , (int)No2Y); pDC->LineTo( (int)m_oldX , (int)m_oldY ); pDC->MoveTo( (int)No2X , (int)No2Y ); pDC->LineTo( (int)x1 , (int)y1 ); } } } //Ñ¡ÔñµÄÊÇ×îºó¶Ëµã else if( m_selVertex == m_vertexCount - 1 ) { if( m_selLine || m_selPolygon ) { CMoParts parts ; if( m_selLine ) { parts = m_selLine.GetParts();//È¡µÃÏߵIJ¿·Ö } else if( m_selPolygon ) { parts = m_selPolygon.GetParts();//È¡µÃÃæµÄ²¿·Ö } CMoPoints pts; CMoPoint ptLast; pts = parts.Item( COleVariant(short( m_partNO )) );//È¡µÃ¸Ã²¿·ÖµÄµã¼¯ºÏ ptLast = pts.Item( COleVariant(short( m_vertexCount - 2 )));//È¡µÃ¸Ã¼¯ºÏµÄµã float LastX , LastY ; m_pMap->FromMapPoint( ptLast , &LastX , &LastY ); pDC->MoveTo( (int)LastX , (int)LastY); pDC->LineTo( (int)m_oldX , (int)m_oldY ); pDC->MoveTo( (int)LastX , (int)LastY ); pDC->LineTo( (int)x1 , (int)y1 ); //ÃæÊÇÊ×βÏàÁ¬µÄ£¬ÒªÁ¬¿ªÊ¼Ò»µã if( m_selPolygon ) { CMoPoint ptFirst ; ptFirst = pts.Item( COleVariant(short( 0 )));//È¡µÃ¸Ã¼¯ºÏµÄµãm_vertexCount - 1 m_pMap->FromMapPoint( ptFirst , &LastX , &LastY ); pDC->MoveTo( (int)LastX , (int)LastY); pDC->LineTo( (int)m_oldX , (int)m_oldY ); pDC->MoveTo( (int)LastX , (int)LastY ); pDC->LineTo( (int)x1 , (int)y1 ); } } } //Ñ¡ÔñµÄÊÇÖмä¶Ëµã else { if( m_selLine || m_selPolygon ) { CMoParts parts ; if( m_selLine ) { parts = m_selLine.GetParts();//È¡µÃÏߵIJ¿·Ö } else if( m_selPolygon ) { parts = m_selPolygon.GetParts();//È¡µÃÃæµÄ²¿·Ö } CMoPoints pts; CMoPoint ptFront , ptBack ; pts = parts.Item( COleVariant(short( m_partNO )) );//È¡µÃ¸Ã²¿·ÖµÄµã¼¯ºÏ ptFront = pts.Item( COleVariant(short( m_selVertex - 1 )));//È¡µÃ¸Ã¼¯ºÏµÄµã ptBack = pts.Item( COleVariant(short( m_selVertex + 1 )));//È¡µÃ¸Ã¼¯ºÏµÄµã float tempX , tempY ; //ǰÏðƤÏß m_pMap->FromMapPoint( ptFront , &tempX , &tempY ); pDC->MoveTo( (int)tempX , (int)tempY); pDC->LineTo( (int)m_oldX , (int)m_oldY ); pDC->MoveTo( (int)tempX , (int)tempY ); pDC->LineTo( (int)x1 , (int)y1 ); //ºóÏðƤÏß m_pMap->FromMapPoint( ptBack , &tempX , &tempY ); pDC->MoveTo( (int)tempX , (int)tempY); pDC->LineTo( (int)m_oldX , (int)m_oldY ); pDC->MoveTo( (int)tempX , (int)tempY ); pDC->LineTo( (int)x1 , (int)y1 ); } } m_pMap->ReleaseDC( pDC ); m_oldX = x1 ; m_oldY = y1 ; /////»­Ð§¹ûÏß(ÏðƤÏß)½áÊø////////////// } |
|
42楼#
发布于:2004-01-09 15:00
// EditDrawObject.cpp : implementation file
// #include "stdafx.h" #include "MapObjectTest.h" #include "EditDrawObject.h" /*#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif*/ ///////////////////////////////////////////////////////////////////////////// // CEditDrawObject CEditDrawObject::CEditDrawObject() { } CEditDrawObject::~CEditDrawObject() { } ///////////////////////////////////////////////////////////////////////////// // CEditDrawObject message handlers void CEditDrawObject::DrawEffect() { CMoSymbol sym; if (!sym.CreateDispatch("MapObjects2.Symbol")) return; // // draw the selected object all Vertexs ; // if( m_selLine || m_selPolygon ) { CMoParts parts ; if( m_selLine ) { parts = m_selLine.GetParts();//È¡µÃÏߵIJ¿·Ö } else if( m_selPolygon ) { parts = m_selPolygon.GetParts();//È¡µÃÃæµÄ²¿·Ö } sym.SetColor(moCyan); sym.SetStyle(moGrayFill); sym.SetSize( 60 ); CMoPoints pts; CMoPoint pt; for (int j , i = 0 ; i < parts.GetCount() ; i++ ) { pts = parts.Item( COleVariant(short( i )) );//È¡µÃ¸Ã²¿·ÖµÄµã¼¯ºÏ m_vertexCount = pts.GetCount() ; for ( j = 0 ; j < m_vertexCount ; j++ ) { pt = pts.Item( COleVariant(short( j )));//È¡µÃ¸Ã¼¯ºÏµÄµã m_pMap->DrawShape( pt, sym); //ÌØ±ðÏÔʾͼÐεı»Ñ¡ÔñµÄ½Úµã if( m_selVertex == j ) { //if( m_curOperator == DelVertex ) { } //else if( m_curOperator == SelVertex ) { m_partNO = i ; sym.SetColor( moYellow ) ; m_pMap->DrawShape( pt , sym ); sym.SetColor( moCyan ); } } } } } } void CEditDrawObject::InitialMap(CMap1 *pMap) { m_pMap = pMap ; m_selLine = NULL ; m_selPolygon = NULL ; m_selVertex = -1 ; } void CEditDrawObject::SelectObject(CMoPoint pt , bool again ) { Refresh() ; m_oldX = m_oldY = 0; m_curOperator = SelVertex ; if( ( m_selLine || m_selPolygon ) && !again ) { SelectVertex( pt ); return ; } CMoLayers layers(m_pMap->GetLayers()); // Set the variant to select the states layer (1) (integer value) // Variant used by a number of different calls VARIANT va; VariantInit(&va); va.vt = VT_I4; va.lVal = 1 ; CMoMapLayer layer ; if (!layer.CreateDispatch(TEXT("MapObjects2.MapLayer"))) { AfxMessageBox("ͼ²ãûÓд´½¨³É¹¦£¡£¡£¡"); return; } int layerCount = layers.GetCount() ; long layerShapeType ; for( int i = 0 ; i < layerCount ; i ++ ) { va.lVal = i ; layer = layers.Item( va ) ; if( layer.GetVisible() == FALSE ) continue ; layerShapeType = layer.GetShapeType(); switch( layerShapeType ) { case moShapeTypePolygon: { m_selPolygonRecSet = layer.SearchShape( pt , moPointInPolygon ,"" );//moLineCross moPointInPolygon m_selPolygonRecSet.MoveFirst(); while (!m_selPolygonRecSet.GetEof()) { CMoFields Fields(m_selPolygonRecSet.GetFields()); CMoField ShapeField(Fields.Item(COleVariant(TEXT("Shape")))); m_selPolygon.AttachDispatch(ShapeField.GetValue().pdispVal); //m_pMap->FlashShape(m_selPolygon, 1); m_selPolygonRecSet.MoveNext(); SelectVertex( pt ); return ; } m_selLine = NULL ; break; } case moShapeTypeLine: { const double tolerance = m_pMap->ToMapDistance((float)2); m_selLineRecSet = layer.SearchByDistance(pt, tolerance, TEXT("")); m_selLineRecSet.MoveFirst(); while (!m_selLineRecSet.GetEof()) { //MessageBox("Ñ¡Ôñµ½ÏßÁË!!!"); CMoFields Fields(m_selLineRecSet.GetFields()); CMoField ShapeField(Fields.Item(COleVariant(TEXT("Shape")))); m_selLine.AttachDispatch(ShapeField.GetValue().pdispVal); //m_pMap->FlashShape(m_selLine, 1); m_selLineRecSet.MoveNext(); SelectVertex( pt ); return ; } m_selPolygon = NULL ; break; } } } } void CEditDrawObject::Refresh() { //ÏÔʾѡÔñͼÐεÄËùÓнڵã if( m_selLine || m_selPolygon) { CMoRectangle rect ; if (!rect.CreateDispatch(TEXT("MapObjects2.Rectangle"))) { AfxMessageBox("¾ØÐÎûÓд´½¨³É¹¦(CEditDrawObject::Refresh())!!!"); return; } if( m_selLine ) { rect = m_selLine.GetExtent() ; } else { rect = m_selPolygon.GetExtent() ; } CMoPoint ptLeftTop; CMoPoint ptRightBottom ; if (!ptLeftTop.CreateDispatch(TEXT("MapObjects2.Point"))) { AfxMessageBox("ͼ²ãûÓд´½¨³É¹¦£¡£¡£¡"); return; } if (!ptRightBottom.CreateDispatch(TEXT("MapObjects2.Point"))) { AfxMessageBox("ͼ²ãûÓд´½¨³É¹¦£¡£¡£¡"); return; } ptLeftTop.SetX( rect.GetLeft() - 5 ); ptLeftTop.SetY( rect.GetTop() + 5 ); ptRightBottom.SetX( rect.GetRight() + 5 ); ptRightBottom.SetY( rect.GetBottom() - 5 ); float x1 , y1 , x2 ,y2 ; m_pMap->FromMapPoint( ptLeftTop , &x1 , &y1 ); m_pMap->FromMapPoint( ptRightBottom , &x2 , &y2 ); CRect r((int)x1 , (int)y1 , (int)x2 ,(int)y2 ); m_pMap->InvalidateRect( r ); } } void CEditDrawObject::SelectVertex(CMoPoint pt) { if( m_selLine || m_selPolygon) { double tol = m_pMap->ToMapDistance( 7 ); double dist ; CMoParts parts ; CMoPoints pts ; CMoPoint point ; if( m_selLine ) { parts = m_selLine.GetParts(); } else if( m_selPolygon ) { parts = m_selPolygon.GetParts(); } for (int j , i = 0 ; i < parts.GetCount() ; i++ ) { pts = parts.Item( COleVariant(short( i )) );//È¡µÃ¸Ã²¿·ÖµÄµã¼¯ºÏ for ( j = 0 ; j < pts.GetCount() ; j++ ) { point = pts.Item( COleVariant(short( j )));//È¡µÃ¸Ã¼¯ºÏµÄµã dist = point.DistanceTo( pt ) ; if( dist < tol ) { m_pMap->FromMapPoint( point , &m_oldX , &m_oldY ); m_selVertex = j ; return ; } } } m_selVertex = -1 ; } } |
|
上一页
下一页