GpsDrawMap.cpp
上传用户:yffx2008
上传日期:2014-10-12
资源大小:12414k
文件大小:97k
- // GpsDrawMap.cpp: implementation of the CGpsDrawMap class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "GpsSC.h"
- #include "GpsDrawMap.h"
- #include "SearchSignDlg.h"
- #include "ShowSignDlg.h"
- #include "InputStringDlg.h"
- #include "ListSimilarStrDlg.h"
- #include "GpsSCDoc.h"
- #include "GpsSCView.h"
- #include "math.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- #define Square(a) ((a) * (a))
- #define Max(a, b) ((a) > (b) ? (a) : (b))
- #define Min(a, b) ((a) > (b) ? (b) : (a))
- #define PI 3.1415927
- #define GPS_INFINITE 0x7fffff
- #define GPS_CAR_WIDTH_HEIGH 40
- #define CompanyIconName "\GpsIcon\GpsSign\Company.bmp"
- #define PlaceNameIconName "\GpsIcon\GpsSign\PlaceName.bmp"
- #define BuildingIconName "\GpsIcon\GpsSign\Building.bmp"
- #define TrafficIconName "\GpsIcon\GpsSign\Traffic.bmp"
- #define OilIconName "\GpsIcon\GpsSign\Oil.bmp"
- #define GovernmentIconName "\GpsIcon\GpsSign\Government.bmp"
- #define EducationIconName "\GpsIcon\GpsSign\edu.bmp"
- #define HotelIconName "\GpsIcon\GpsSign\Hotel.bmp"
- #define ShoppingIconName "\GpsIcon\GpsSign\Shopping.bmp"
- #define AmusementIconName "\GpsIcon\GpsSign\Amusement.bmp"
- #define ProjectIconName "\GpsIcon\GpsSign\finan.bmp"
- #define HospitalIconName "\GpsIcon\GpsSign\Hospital.bmp"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CGpsDrawMap::CGpsDrawMap()
- {
- InitDrawMap();
- }
- CGpsDrawMap::~CGpsDrawMap()
- {
- ClearMemberVar();
- }
- void CGpsDrawMap::ClearMemberVar()
- {
- if(FileContent != NULL) {
- delete [] FileContent;
- }
- m_cFatStruct.Clear();
- m_cCurrMapInfo.Clear();
- ClearLinkList(&mLinkList);
- ClearPointList(&mSaveRecePointList);
- m_cCurrMapInfo.ClearBRoadSaveList(&mSaveBRList);
- ClearPointList(&mSaveTempList1);
- ClearPointList(&mSaveTempList2);
- }
- void CGpsDrawMap::InitDrawMap()
- {
- m_cFatStruct.Clear();
- m_cCurrMapInfo.Clear();
- ClearLinkList(&mLinkList);
- ClearPointList(&mSaveRecePointList);
- long Ret;
- if(Ret = GetGpsFatBuf()) {
- GetGpsFatInfo();
- gCurrMapLevel = 6;
- m_PointWidth = 5;
- m_byZoomCoeffic = 1;
- GetLinkList(&mLinkList,gCurrMapLevel);
- gBRcross.m_bEnable = false;
- gBRcross.m_bHaveSpoint = false;
- gBRcross.m_EndCross.Clear();
- gBRcross.m_StartCross.Clear();
- GetAreaLibList(&m_cCurrMapInfo.lAreaLibList);
- }
- }
- void CGpsDrawMap::ClearStrArr(CString StrArr[],long Count)
- {
- long i;
- for(i = 0; i < Count; i++) {
- StrArr[i].Empty();
- }
- }
- long CGpsDrawMap::GetGpsFatBuf()
- {
- CString sPath;
- char CurrPath[500];
- CFile f;
- long FatLen = 0;
- ClearBYTEArr(CurrPath,500);
- ::GetCurrentDirectory(500,CurrPath);
- sPath = CurrPath;
- sPath += "\Map\fat.fat";
- short Course = 0; //将不同角度的Car保存到数组中
- CString str;
- CString CarPath;
- CarPath = CurrPath;
- CarPath += "\GpsIcon\GpsCar\Car";
- for(BYTE i = 0; i < 24; i++) {
- str.Format("%03d",Course);
- SaveGpsCarPath[i] = CarPath + str + ".bmp";
- Course += 15;
- }
- if(!f.Open(sPath,CFile::modeRead,NULL)) {
- AfxMessageBox("打开地图出错,初始化画图系统失败!");
- FileContent = NULL;
- return FatLen;
- }
- f.SeekToBegin();
- FatLen = f.GetLength();
- FileContent = new BYTE[FatLen];
- f.Read(FileContent,FatLen);
- f.Close();
- return FatLen;
- }
- CString CGpsDrawMap::GetCurrDir()
- {
- CString sPath;
- char CurrPath[500];
- ClearBYTEArr(CurrPath,500);
- ::GetCurrentDirectory(500,CurrPath);
- return sPath = CurrPath;
- }
- bool CGpsDrawMap::ShowSignLib()
- {
- CShowSignDlg dlg;
- if(dlg.DoModal() == IDCANCEL) return false;
- m_ShowSign.bShowBuilding = dlg.m_byBuilding;
- m_ShowSign.bShowHotel = dlg.m_byHotel;
- m_ShowSign.bShowCompany = dlg.m_byCompany;
- m_ShowSign.bShowAmuse = dlg.m_byAmuse;
- m_ShowSign.bShowPlaceName = dlg.m_byPlaceName;
- m_ShowSign.bShowGovern = dlg.m_byGovern;
- m_ShowSign.bShowTraffic = dlg.m_byTraffic;
- m_ShowSign.bShowShopping = dlg.m_byShopping;
- m_ShowSign.bShowEducation = dlg.m_byEducation;
- m_ShowSign.bShowHospital = dlg.m_byHospital;
- m_ShowSign.bShowBureau = dlg.m_byBureau;
- m_ShowSign.bShowOil = dlg.m_byOil;
- return true;
- }
- void CGpsDrawMap::GetGpsFatInfo()
- {
- long BufPos = 0;
- m_cFatStruct.m_lLinkLibTotal = GetFourBNum(FileContent,BufPos); //链接库
- BufPos += LibTotalBytes;
- m_cFatStruct.m_lDataLibTotal = GetFourBNum(FileContent,BufPos); //数据库
- BufPos += LibTotalBytes;
- m_cFatStruct.m_lSignLibTotal = GetFourBNum(FileContent,BufPos); //标志库
- BufPos += LibTotalBytes;
- m_cFatStruct.m_lRegionLibTotal = GetFourBNum(FileContent,BufPos); //地区库
- BufPos += LibTotalBytes;
- m_cFatStruct.m_lRecordLibTotal = GetFourBNum(FileContent,BufPos); //记录库
- BufPos += LibTotalBytes;
- m_cFatStruct.m_lLinkLibAddr = BufPos;
- m_cFatStruct.m_lDataLibAddr = m_cFatStruct.m_lLinkLibAddr +
- m_cFatStruct.m_lLinkLibTotal * LibInfoBytes;
- m_cFatStruct.m_lSignLibAddr = m_cFatStruct.m_lDataLibAddr +
- m_cFatStruct.m_lDataLibTotal * LibInfoBytes;
- m_cFatStruct.m_lRegionLibAddr = m_cFatStruct.m_lSignLibAddr +
- m_cFatStruct.m_lSignLibTotal * LibInfoBytes;
- m_cFatStruct.m_lRecordLibAddr = m_cFatStruct.m_lRegionLibAddr +
- m_cFatStruct.m_lRegionLibTotal * LibInfoBytes;
- }
- /*************Get one NE of Point*************/
- void CGpsDrawMap::GetPointNE(BYTE *BUF,long *BufPos,double *gx,double *gy)
- {
- long tmp1;
- tmp1 = GetFourBNum(BUF,*BufPos);
- *gy = CovertNE(tmp1);
- *BufPos += GpsPointNEBytes;
- tmp1 = GetFourBNum(BUF,*BufPos);
- *gx = CovertNE(tmp1);
- *BufPos += GpsPointNEBytes;
- }
- /*************Get a long number of four bytes*************/
- long CGpsDrawMap::GetFourBNum(BYTE *BUF,long BufPos)
- {
- long RetLong;
- RetLong = BUF[BufPos + 0] + (BUF[BufPos + 1] + BUF[BufPos + 2] * 256 + BUF[BufPos + 3] * 65536) * 256;
- return RetLong;
- }
- short CGpsDrawMap::GetTwoBNum(BYTE *BUF,long BufPos)
- {
- short RetShort;
- RetShort = BUF[BufPos + 0] + BUF[BufPos + 1] * 256;
- return RetShort;
- }
- BYTE CGpsDrawMap::GetOneBNum(BYTE *BUF,long BufPos)
- {
- BYTE RetByte;
- RetByte = BUF[BufPos];
- return RetByte;
- }
- void CGpsDrawMap::GetLenArray(BYTE *pTarget,BYTE Len,BYTE *Buf,long BufPos)
- {
- BYTE i;
- for(i = 0; i < Len; i++) {
- pTarget[i] = Buf[BufPos++];
- }
- }
- void CGpsDrawMap::ClearBYTEArr(char Array[],long ArrLen)
- {
- long i;
- for(i = 0; i < ArrLen; i++) {
- Array[i] = 0;
- }
- }
- void CGpsDrawMap::CopyStr2Arr(CString Str,char *Arr,BYTE ArrLen)
- {
- BYTE i;
- for(i = 0;i < Str.GetLength(); i++) {
- Arr[i] = Str.GetAt(i);
- if(i == ArrLen) break;
- }
- }
- void CGpsDrawMap::CopyEquaLenArr(char *SrcArr,char *DstArr,BYTE CpyLen)
- {
- BYTE i;
- for(i = 0; i < CpyLen; i++) {
- DstArr[i] = SrcArr[i];
- }
- }
- BYTE CGpsDrawMap::CompareTwoArr(char *pArr1,char *pArr2)
- {
- CString Str1(pArr1),Str2(pArr2);
- BYTE Ret = 3;
- Str1.MakeUpper();
- Str2.MakeUpper();
- if((Str1 == Str2) && (!Str1.IsEmpty()) && (!Str2.IsEmpty())) return Ret = 1;
- if(Str1 > Str2) return Ret = 2;
- if(Str1 < Str2) return Ret = 0;
-
- return Ret;
- }
- /*************From XY to NE or From NE to XY*************/
- void CGpsDrawMap::CovertNEXY(CGpsPoint * cmpoint, ChangeNormal change, bool NE2XY)
- {
- #if 0
- if (NE2XY) {
- cmpoint->m_lx = (long)(change.a11 * cmpoint->m_dgx +
- change.a12 * cmpoint->m_dgy + change.dx);
- cmpoint->m_ly = (long)(change.a21 * cmpoint->m_dgx +
- change.a22 * cmpoint->m_dgy + change.dy);
- }
- else {
- cmpoint->m_dgx = change.a11 * cmpoint->m_lx +
- change.a12 * cmpoint->m_ly + change.dx;
- cmpoint->m_dgy = change.a21 * cmpoint->m_lx +
- change.a22 * cmpoint->m_ly + change.dy;
- }
- #else
- long lTemp;
- double x,y,dTemp;
- if (NE2XY) {
- lTemp = (long)cmpoint->m_dgx / 100;
- dTemp = cmpoint->m_dgx - lTemp * 40;
- x = dTemp;
- lTemp = (long)cmpoint->m_dgy / 100;
- dTemp = cmpoint->m_dgy - lTemp * 40;
- y = dTemp;
- cmpoint->m_lx = (long)(change.a11 * x + change.a12 * y + change.dx);
- cmpoint->m_ly = (long)(change.a21 * x + change.a22 * y + change.dy);
- }
- else {
- x = cmpoint->m_lx;
- y = cmpoint->m_ly;
-
- dTemp = change.a11 * x + change.a12 * y + change.dx;
- lTemp = (long)dTemp / 60;
- cmpoint->m_dgx = dTemp + lTemp * 40;
- dTemp = change.a21 * x + change.a22 * y + change.dy;
- lTemp = (long)dTemp / 60;
- cmpoint->m_dgy = dTemp + lTemp * 40;
- }
- #endif
- }
- void CGpsDrawMap::CalculateCoeffNEXY(ChangeTriangle Triangle1,ChangeTriangle Triangle2,ChangeNormal *Change)
- {
- #if 0
- double tmp1,tmp2;
- tmp1 = (Triangle2.x2 - Triangle2.x1) * (Triangle2.y3 - Triangle2.y1) -
- (Triangle2.x3 - Triangle2.x1) * (Triangle2.y2 - Triangle2.y1);
-
- tmp2 = (Triangle1.x2 - Triangle1.x1) * (Triangle2.y3 - Triangle2.y1) -
- (Triangle1.x3 - Triangle1.x1) * (Triangle2.y2 - Triangle2.y1);
- Change->a11 = tmp2 / tmp1;
- tmp2 = (Triangle2.x2 - Triangle2.x1) * (Triangle1.x3 - Triangle1.x1) -
- (Triangle2.x3 - Triangle2.x1) * (Triangle1.x2 - Triangle1.x1);
- Change->a12 = tmp2 / tmp1;
- tmp2 = (Triangle1.y2 - Triangle1.y1) * (Triangle2.y3 - Triangle2.y1) -
- (Triangle1.y3 - Triangle1.y1) * (Triangle2.y2 - Triangle2.y1);
- Change->a21 = tmp2 / tmp1;
- tmp2 = (Triangle2.x2 - Triangle2.x1) * (Triangle1.y3 - Triangle1.y1) -
- (Triangle2.x3 - Triangle2.x1) * (Triangle1.y2 - Triangle1.y1);
- Change->a22 = tmp2 / tmp1;
- Change->dx = Triangle1.x1 - Change->a11 * Triangle2.x1 -
- Change->a12 * Triangle2.y1;
- Change->dy = Triangle1.y1 - Change->a21 * Triangle2.x1 -
- Change->a22 * Triangle2.y1;
- #else
- double tmp1,tmp2;
- tmp1 = (Triangle2.x2 - Triangle2.x1) * (Triangle2.y3 - Triangle2.y1) -
- (Triangle2.x3 - Triangle2.x1) * (Triangle2.y2 - Triangle2.y1);
-
- tmp2 = (Triangle1.x2 - Triangle1.x1) * (Triangle2.y3 - Triangle2.y1) -
- (Triangle1.x3 - Triangle1.x1) * (Triangle2.y2 - Triangle2.y1);
- Change->a11 = tmp2 / tmp1;
- tmp2 = (Triangle2.x2 - Triangle2.x1) * (Triangle1.x3 - Triangle1.x1) -
- (Triangle2.x3 - Triangle2.x1) * (Triangle1.x2 - Triangle1.x1);
- Change->a12 = tmp2 / tmp1;
- tmp2 = (Triangle1.y2 - Triangle1.y1) * (Triangle2.y3 - Triangle2.y1) -
- (Triangle1.y3 - Triangle1.y1) * (Triangle2.y2 - Triangle2.y1);
- Change->a21 = tmp2 / tmp1;
- tmp2 = (Triangle2.x2 - Triangle2.x1) * (Triangle1.y3 - Triangle1.y1) -
- (Triangle2.x3 - Triangle2.x1) * (Triangle1.y2 - Triangle1.y1);
- Change->a22 = tmp2 / tmp1;
- Change->dx = Triangle1.x1 - Change->a11 * Triangle2.x1 -
- Change->a12 * Triangle2.y1;
- Change->dy = Triangle1.y1 - Change->a21 * Triangle2.x1 -
- Change->a22 * Triangle2.y1;
- #endif
- }
- void CGpsDrawMap::RefreshMapWnd()
- {
- ChangeTriangle triangle;
- ChangeNormal TmpTri;
- CRect lpRect;
- ((CGpsSCView*)m_pCurrView)->GetClientRect(lpRect);
- if((m_cCurrMapInfo.m_lWnd_Max_X == 0) || (m_cCurrMapInfo.m_lWnd_Max_Y == 0)) {
- lpRect.right *= m_byZoomCoeffic;
- lpRect.bottom *= m_byZoomCoeffic;
- m_cCurrMapInfo.m_lWnd_Max_X = lpRect.right;
- m_cCurrMapInfo.m_lWnd_Max_Y = lpRect.bottom;
- ((CGpsSCView*)m_pCurrView)->SetScrollSizes(MM_TEXT, CSize(m_cCurrMapInfo.m_lWnd_Max_X, m_cCurrMapInfo.m_lWnd_Max_Y));
- }
- else {
- lpRect.right = m_cCurrMapInfo.m_lWnd_Max_X;
- lpRect.bottom = m_cCurrMapInfo.m_lWnd_Max_Y;
- }
- m_cCurrMapInfo.m_WndTriangle.x1 = lpRect.left;
- m_cCurrMapInfo.m_WndTriangle.y1 = lpRect.top;
- m_cCurrMapInfo.m_WndTriangle.x2 = lpRect.left;
- m_cCurrMapInfo.m_WndTriangle.y2 = lpRect.bottom;
- m_cCurrMapInfo.m_WndTriangle.x3 = lpRect.right;
- m_cCurrMapInfo.m_WndTriangle.y3 = lpRect.bottom;
- #if 1
- triangle = m_cCurrMapInfo.m_MapTriangle;
- long iTemp;
- iTemp = (long)(m_cCurrMapInfo.m_MapTriangle.x1 / 100);
- m_cCurrMapInfo.m_MapTriangle.x1 = m_cCurrMapInfo.m_MapTriangle.x1 - iTemp * 40;
- iTemp = (long)(m_cCurrMapInfo.m_MapTriangle.x2 / 100);
- m_cCurrMapInfo.m_MapTriangle.x2 = m_cCurrMapInfo.m_MapTriangle.x2 - iTemp * 40;
- iTemp = (long)(m_cCurrMapInfo.m_MapTriangle.x3 / 100);
- m_cCurrMapInfo.m_MapTriangle.x3 = m_cCurrMapInfo.m_MapTriangle.x3 - iTemp * 40;
- iTemp = (long)(m_cCurrMapInfo.m_MapTriangle.y1 / 100);
- m_cCurrMapInfo.m_MapTriangle.y1 = m_cCurrMapInfo.m_MapTriangle.y1 - iTemp * 40;
- iTemp = (long)(m_cCurrMapInfo.m_MapTriangle.y2 / 100);
- m_cCurrMapInfo.m_MapTriangle.y2 = m_cCurrMapInfo.m_MapTriangle.y2 - iTemp * 40;
- iTemp = (long)(m_cCurrMapInfo.m_MapTriangle.y3 / 100);
- m_cCurrMapInfo.m_MapTriangle.y3 = m_cCurrMapInfo.m_MapTriangle.y3 - iTemp * 40;
- #endif
- CalculateCoeffNEXY(m_cCurrMapInfo.m_WndTriangle,m_cCurrMapInfo.m_MapTriangle,&TmpTri);
- m_cCurrMapInfo.CoeffNE_XY = TmpTri;
- CalculateCoeffNEXY(m_cCurrMapInfo.m_MapTriangle,m_cCurrMapInfo.m_WndTriangle,&TmpTri);
- m_cCurrMapInfo.CoeffXY_NE = TmpTri;
- m_cCurrMapInfo.m_MapTriangle = triangle;
- }
- void CGpsDrawMap::GetCurrMapInfo(CGpsLinkStruct *pLinkStruct,CCurrMapInfo *MapInfo)
- {
- CopyEquaLenArr(pLinkStruct->m_LinkLibName,MapInfo->m_LinkFileName,pLinkStruct->m_LinkLibName_Bytes);
- CopyEquaLenArr(pLinkStruct->m_RelatedSignLibName,MapInfo->m_SignFileName,pLinkStruct->m_SignLibName_Bytes);
- MapInfo->LinkName2DataLib(MapInfo->m_LinkFileName,MapInfo->m_DataFileName);
- MapInfo->m_MapTriangle = pLinkStruct->m_MapTri;
- }
- long CGpsDrawMap::GetDataLibAddr(char *DataLibName)
- {
- long InfoAddr,DataStartAddr,DataEndAddr,i,RetAddr = -1;
- char DataFileName[GpsLibFileLen + 1];
- InfoAddr = m_cFatStruct.m_lDataLibAddr;
- for(i = 0; i < m_cFatStruct.m_lDataLibTotal; i++) {
- ClearBYTEArr(DataFileName,GpsLibFileLen + 1);
- GetLibInfo(FileContent,InfoAddr,DataFileName,&DataStartAddr,&DataEndAddr);
- InfoAddr += LibInfoBytes; //链接库在FAT表中占用的字节数
- if(CompareTwoArr(DataFileName,DataLibName) == 1) {
- RetAddr = DataStartAddr;
- break;
- }
- }
- return RetAddr;
- }
- bool CGpsDrawMap::GetDataLib(char *DataLibName)
- {
- long DataLibStart;
-
- DataLibStart = GetDataLibAddr(DataLibName);
- if(DataLibStart == -1) return false;
- m_cCurrMapInfo.ClearColorBList();
- DataLibStart = GetColorBList(&m_cCurrMapInfo.lCurrColorBList,DataLibStart);
- m_cCurrMapInfo.ClearRoadList(m_cCurrMapInfo.lCurrRoadList);
- DataLibStart = GetRoadPlainPoint(&m_cCurrMapInfo.lCurrRoadList,DataLibStart);
- m_cCurrMapInfo.ClearCrossList();
- GetRoadCrossPoint(&m_cCurrMapInfo.lCurrCrossList,DataLibStart);
- return true;
- }
- long CGpsDrawMap::GetColorBList(CObList *ColorBList,long StartAddr)
- {
- CGpsColorBlock *pBlock;
- CGpsColorBlock cBlock;
- CGpsPoint *pPoint;
- short i,j;
- StartAddr += ColorBTotalBytes;
- cBlock.m_ColorBlockTotal = GetTwoBNum(FileContent,StartAddr);
- StartAddr += cBlock.m_ColorBlock_Bytes;
- for(i = 0; i < cBlock.m_ColorBlockTotal; i++) {
- pBlock = new CGpsColorBlock;
- ColorBList->AddHead(pBlock);
- pBlock->m_ColorBlockTotal = cBlock.m_ColorBlockTotal;
- pBlock->m_ColorValue = GetTwoBNum(FileContent,StartAddr);
- StartAddr += cBlock.m_ColorValue_Bytes;
- pBlock->m_ColorBlock_PointTotal = GetTwoBNum(FileContent,StartAddr);
- StartAddr += cBlock.m_ColorBlock_PointTotal_Bytes;
- for(j = 0; j < pBlock->m_ColorBlock_PointTotal; j++) {
- pPoint = new CGpsPoint;
- pBlock->ColorBlockPointList.AddHead(pPoint);
- GetPointNE(FileContent,&StartAddr,&pPoint->m_dgx,&pPoint->m_dgy);
- CovertNEXY(pPoint, m_cCurrMapInfo.CoeffNE_XY, true);
- }
- }
- return StartAddr;
- }
- long CGpsDrawMap::GetRoadPlainPoint(CObList *RoadList,long BufPos)
- {
- CSmallRoadStruct *pSmallRoad;
- CGpsRoadStruct *pRoad;
- CRoadPoint *pRoadPoint;
- long RoadTotal,i,j,k;
- BYTE DispLevel;
-
- RoadTotal = GetFourBNum(FileContent,BufPos);
- BufPos += LibTotalBytes;
- for(i = 0; i < RoadTotal; i++) {
- pRoad = new CGpsRoadStruct;
- RoadList->AddHead(pRoad);
- pRoad->BigRoad_Serial = GetOneBNum(FileContent,BufPos);
- BufPos += pRoad->BigRoad_SN_Bytes;
- pRoad->m_BigRoad_Number = GetTwoBNum(FileContent,BufPos);
- BufPos += pRoad->m_byBigRoad_Number_Bytes;
- pRoad->SmallRoadTotal = GetOneBNum(FileContent,BufPos);
- BufPos += pRoad->SmallRoadTotal_Bytes;
- pRoad->m_byIsHelpRoad = GetOneBNum(FileContent,BufPos);
- BufPos += pRoad->m_byHelpRoad_Bytes;
- for(j = 0; j < pRoad->SmallRoadTotal; j++) {
- pSmallRoad = new CSmallRoadStruct;
- pRoad->SmallRoadList.AddHead(pSmallRoad);
- GetLenArray(pSmallRoad->SmallRoad_SerialNumber,pSmallRoad->SmallRoad_SN_Bytes,FileContent,BufPos);
- BufPos += pSmallRoad->SmallRoad_SN_Bytes;
- GetLenArray((BYTE*)pSmallRoad->RoadName,pSmallRoad->RoadName_Bytes,FileContent,BufPos);
- BufPos += pSmallRoad->RoadName_Bytes;
- pSmallRoad->Road_SD = GetOneBNum(FileContent,BufPos);
- BufPos += pSmallRoad->Road_SD_Bytes;
- DispLevel = GetOneBNum(FileContent,BufPos);
- pSmallRoad->RoadorName_DispLevel = GetOneBNum(FileContent,BufPos);
- BufPos += pSmallRoad->DispLevel_Bytes;
- pSmallRoad->SmallRoad_PointTotal = GetTwoBNum(FileContent,BufPos);
- BufPos += pSmallRoad->PointTotal_Bytes;
- for(k = 0; k < pSmallRoad->SmallRoad_PointTotal; k++) {
- pRoadPoint = new CRoadPoint;
- pSmallRoad->RoadPointList.AddHead(pRoadPoint);
- GetLenArray(pRoadPoint->BigRoad_SerialNumber,pRoadPoint->BigRoad_SN_Bytes,FileContent,BufPos);
- BufPos += pRoadPoint->BigRoad_SN_Bytes;
- GetPointNE(FileContent,&BufPos,&pRoadPoint->m_dgx,&pRoadPoint->m_dgy);
- pRoadPoint->OutOfMap = GetOneBNum(FileContent,BufPos);
- BufPos += pRoadPoint->OutOfMap_Bytes;
- BufPos += pRoadPoint->OutOfMap_Bytes;
- CovertNEXY(pRoadPoint, m_cCurrMapInfo.CoeffNE_XY, true);
- }
- }
- }
- return BufPos;
- }
- long CGpsDrawMap::GetRoadCrossPoint(CObList *CrossList,long BufPos)
- {
- CGpsRoadCrossPoint *pCross;
- long CrossTotal,i;
- CrossTotal = GetFourBNum(FileContent,BufPos);
- BufPos += LibTotalBytes;
- for(i = 0; i < CrossTotal; i++) {
- pCross = new CGpsRoadCrossPoint;
- CrossList->AddHead(pCross);
- GetPointNE(FileContent,&BufPos,&pCross->m_dgx,&pCross->m_dgy);
- pCross->m_CrossRoad1_Serial = GetOneBNum(FileContent,BufPos);
- BufPos += pCross->m_CrossRoad1_Serial_Bytes;
- pCross->m_CrossRoad1_Number = GetTwoBNum(FileContent,BufPos);
- BufPos += pCross->m_CrossRoad1_Number_Bytes;
- pCross->m_CrossRoad1_Level = GetOneBNum(FileContent,BufPos);
- BufPos += pCross->m_CrossRoad1_Level_Bytes;
- pCross->m_CrossRoad2_Serial = GetOneBNum(FileContent,BufPos);
- BufPos += pCross->m_CrossRoad2_Serial_Bytes;
- pCross->m_CrossRoad2_Number = GetTwoBNum(FileContent,BufPos);
- BufPos += pCross->m_CrossRoad2_Number_Bytes;
- pCross->m_CrossRoad2_Level = GetOneBNum(FileContent,BufPos);
- BufPos += pCross->m_CrossRoad2_Level_Bytes;
- pCross->m_CrossRoad3_Serial = GetOneBNum(FileContent,BufPos);
- BufPos += pCross->m_CrossRoad3_Serial_Bytes;
- pCross->m_CrossRoad3_Number = GetTwoBNum(FileContent,BufPos);
- BufPos += pCross->m_CrossRoad3_Number_Bytes;
- pCross->m_CrossRoad3_Level = GetOneBNum(FileContent,BufPos);
- BufPos += pCross->m_CrossRoad3_Level_Bytes;
- pCross->m_CrossRoad4_Serial = GetOneBNum(FileContent,BufPos);
- BufPos += pCross->m_CrossRoad4_Serial_Bytes;
- pCross->m_CrossRoad4_Number = GetTwoBNum(FileContent,BufPos);
- BufPos += pCross->m_CrossRoad4_Number_Bytes;
- pCross->m_CrossRoad4_Level = GetOneBNum(FileContent,BufPos);
- BufPos += pCross->m_CrossRoad4_Level_Bytes;
- CovertNEXY(pCross, m_cCurrMapInfo.CoeffNE_XY, true);
- }
- return BufPos;
- }
- //Get Sign Lib...
- long CGpsDrawMap::GetSignLibAddr(char *SignLibName)
- {
- long InfoAddr,SignStartAddr,SignEndAddr,i,RetAddr = -1;
- char SignFileName[GpsLibFileLen + 1];
- InfoAddr = m_cFatStruct.m_lSignLibAddr;
- for(i = 0; i < m_cFatStruct.m_lSignLibTotal; i++) {
- ClearBYTEArr(SignFileName,GpsLibFileLen + 1);
- GetLibInfo(FileContent,InfoAddr,SignFileName,&SignStartAddr,&SignEndAddr);
- InfoAddr += LibInfoBytes; //链接库在FAT表中占用的字节数
- if(CompareTwoArr(SignFileName,SignLibName) == 1) {
- RetAddr = SignStartAddr;
- break;
- }
- }
- return RetAddr;
- }
- bool CGpsDrawMap::GetSignLib(char *SignLibName,CObList *SignList,bool Del)
- {
- long SignLibStart;
-
- SignLibStart = GetSignLibAddr(SignLibName);
- if(SignLibStart == -1) return false;
- if(!GetSignList(SignList,SignLibStart,Del)) return false;
- return true;
- }
- BYTE CGpsDrawMap::GetSignList(CObList *SignList,long StartAddr,bool Del)
- {
- BYTE Ret = 0;
- long Total;
- char CurrPath[500];
- CString Path;
- ClearBYTEArr(CurrPath,500);
- ::GetCurrentDirectory(500,CurrPath);
- Path = CurrPath;
- //Get Building
- if(GetSignObjectList(SignList,StartAddr,SignObjectOfOthers_Bytes,1,false,Del,Path + BuildingIconName)) Ret++;
- //Get Hotel
- if(GetSignObjectList(SignList,StartAddr,SignObjectOfOthers_Bytes,2,false,Del,Path + HotelIconName)) Ret++;
- //Get Company
- if(GetSignObjectList(SignList,StartAddr,SignObjectOfCompany_Bytes,3,true,Del,Path + CompanyIconName)) Ret++;
- //Get Amusement
- if(GetSignObjectList(SignList,StartAddr,SignObjectOfOthers_Bytes,4,false,Del,Path + AmusementIconName)) Ret++;
- //Get PlaceName
- if(GetSignObjectList(SignList,StartAddr,SignObjectOfOthers_Bytes,5,false,Del,Path + PlaceNameIconName)) Ret++;
- //跳过道路名层
- Total = GetFourBNum(FileContent,StartAddr);
- StartAddr += (LibTotalBytes + Total * SignRoadNameObjectBytes);
- //Get Government
- if(GetSignObjectList(SignList,StartAddr,SignObjectOfOthers_Bytes,7,false,Del,Path + GovernmentIconName)) Ret++;
- //Get Traffic
- if(GetSignObjectList(SignList,StartAddr,SignObjectOfOthers_Bytes,8,false,Del,Path + TrafficIconName)) Ret++;
- //Get Shopping
- if(GetSignObjectList(SignList,StartAddr,SignObjectOfOthers_Bytes,9,false,Del,Path + ShoppingIconName)) Ret++;
- //Get Education
- if(GetSignObjectList(SignList,StartAddr,SignObjectOfOthers_Bytes,10,false,Del,Path + EducationIconName)) Ret++;
- //Get AfterService
- if(GetSignObjectList(SignList,StartAddr,SignObjectOfAfterService_Bytes,11,false,Del)) Ret++;
- //Get Hospital
- if(GetSignObjectList(SignList,StartAddr,SignObjectOfOthers_Bytes,12,false,Del,Path + HospitalIconName)) Ret++;
- //Get Project
- if(GetSignObjectList(SignList,StartAddr,SignObjectOfProject_Bytes,13,false,Del,Path + ProjectIconName)) Ret++;
- //Get Oil
- if(GetSignObjectList(SignList,StartAddr,SignObjectOfOil_Bytes,14,false,Del,Path + OilIconName)) Ret++;
- return Ret;
- }
- bool CGpsDrawMap::GetSignObjectList(CObList *SignList,long &StartAddr,BYTE SignObject_Bytes,
- BYTE SignType,bool IsCompany,bool Del,CString IconName)
- {
- CGpsSignObject *pSign;
- long SignTotal,i;
- bool Flag = false;
- SignTotal = GetFourBNum(FileContent,StartAddr);
- StartAddr += LibTotalBytes;
- for(i = 0; i < SignTotal; i++) {
- pSign = new CGpsSignObject(SignObject_Bytes);
- if(SignObject_Bytes > SignObjectOfOil_Bytes) {
- GetLenArray((BYTE*)pSign->m_pSignObjectName,SignObject_Bytes,FileContent,StartAddr);
- StartAddr += SignObject_Bytes;
- GetPointNE(FileContent,&StartAddr,&pSign->m_dgx,&pSign->m_dgy);
- pSign->m_arrSignObject_Serial1 = GetOneBNum(FileContent,StartAddr);
- StartAddr += pSign->m_bySignObject_Serial1_Bytes;
- pSign->m_arrSignObject_Number1 = GetTwoBNum(FileContent,StartAddr);
- StartAddr += pSign->m_bySignObject_Number1_Bytes;
- pSign->m_arrSignObject_Serial2 = GetOneBNum(FileContent,StartAddr);
- StartAddr += pSign->m_bySignObject_Serial2_Bytes;
- pSign->m_arrSignObject_Number2 = GetTwoBNum(FileContent,StartAddr);
- StartAddr += pSign->m_bySignObject_Number2_Bytes;
- GetLenArray((BYTE*)pSign->m_arrSignObjectDispLevel,pSign->m_bySignDispLevel_Bytes,FileContent,StartAddr);
- StartAddr += pSign->m_bySignDispLevel_Bytes;
- if(IsCompany) {
- GetLenArray((BYTE*)pSign->m_arrSignAdvertise,pSign->m_bySignAdvertise_Bytes,FileContent,StartAddr);
- StartAddr += pSign->m_bySignAdvertise_Bytes;
- }
- }
- else {
- pSign->m_dgy = GetFourBNum(FileContent,StartAddr);
- StartAddr += pSign->m_gyBytes;
- pSign->m_dgx = GetFourBNum(FileContent,StartAddr);
- StartAddr += pSign->m_gxBytes;
- pSign->m_arrSignObject_Serial1 = GetOneBNum(FileContent,StartAddr);
- StartAddr += pSign->m_bySignObject_Serial1_Bytes;
- pSign->m_arrSignObject_Number1 = GetTwoBNum(FileContent,StartAddr);
- StartAddr += pSign->m_bySignObject_Number1_Bytes;
- pSign->m_arrSignObject_Serial2 = GetOneBNum(FileContent,StartAddr);
- StartAddr += pSign->m_bySignObject_Serial2_Bytes;
- pSign->m_arrSignObject_Number2 = GetTwoBNum(FileContent,StartAddr);
- StartAddr += pSign->m_bySignObject_Number2_Bytes;
- }
- pSign->m_sIconName = IconName;
- pSign->m_bySignType = SignType;
- CovertNEXY(pSign, m_cCurrMapInfo.CoeffNE_XY, true);
- if(Del) {
- //只显示当前图标志物
- if((pSign->m_lx > m_cCurrMapInfo.m_lWnd_Max_X) || (pSign->m_lx < 0) ||
- (pSign->m_ly > m_cCurrMapInfo.m_lWnd_Max_Y) || (pSign->m_ly < 0)) {
- delete pSign;
- continue;
- }
- }
- SignList->AddHead(pSign);
- }
- if(SignList->GetCount()) Flag = true;
- return Flag;
- }
- bool CGpsDrawMap::CalcNE2XY(double gx,double gy,long &x,long &y)
- {
- if(!IsValidNE(gx,gy)) return false;
- CGpsPoint cPoint;
- cPoint.m_dgx = gx;
- cPoint.m_dgy = gy;
- CovertNEXY(&cPoint, m_cCurrMapInfo.CoeffNE_XY, true);
- x = cPoint.m_lx;
- y = cPoint.m_ly;
- return true;
- }
- /*************Get Library Infomation*************/
- void CGpsDrawMap::GetLibInfo(BYTE *Buf,long InfoAddr,char *FileName,long *StartAddr,long *EndAddr)
- {
- for(long i = 0; i < GpsLibFileLen; i++){
- FileName[i] = Buf[InfoAddr + i];
- }
- InfoAddr += GpsLibFileLen;
- *StartAddr = GetFourBNum(Buf,InfoAddr);
- InfoAddr += LibAddrBytes;
- *EndAddr = GetFourBNum(Buf,InfoAddr);
- }
- /*************Calculate NE*************/
- double CGpsDrawMap::CovertNE(long lTemp)
- {
- double Ret,dTemp;
- dTemp = lTemp % 360000;
- Ret = (lTemp / 360000) * 100 + dTemp / 6000;
- return Ret;
- }
- long CGpsDrawMap::CovertToLongNE(double dTemp)
- {
- long lTmp;
- lTmp = (long)( dTemp / 100);
- lTmp = (long)((lTmp * 3600 + (dTemp - lTmp * 100) * 60) * 100);
- return lTmp;
- }
- void CGpsDrawMap::GetLinkLibThreePoint(BYTE * BUF,long StartAddr,ChangeTriangle * ThreePoint)
- {
- long BufPos;
- long ltmp;
- BufPos = StartAddr;
- ltmp = GetFourBNum(BUF,BufPos);
- ThreePoint->y1 = CovertNE(ltmp);
- BufPos += LibAddrBytes;
- ltmp = GetFourBNum(BUF,BufPos);
- ThreePoint->x1 = CovertNE(ltmp);
- BufPos += LibAddrBytes;
- ltmp = GetFourBNum(BUF,BufPos);
- ThreePoint->y2 = CovertNE(ltmp);
- BufPos += LibAddrBytes;
- ltmp = GetFourBNum(BUF,BufPos);
- ThreePoint->x2 = CovertNE(ltmp);
- BufPos += LibAddrBytes;
- ltmp = GetFourBNum(BUF,BufPos);
- ThreePoint->y3 = CovertNE(ltmp);
- BufPos += LibAddrBytes;
- ltmp = GetFourBNum(BUF,BufPos);
- ThreePoint->x3 = CovertNE(ltmp);
- #if 0
- long iTemp;
- iTemp = (long)(ThreePoint->x1 / 100);
- ThreePoint->x1 = ThreePoint->x1 - iTemp * 40;
- iTemp = (long)(ThreePoint->x2 / 100);
- ThreePoint->x2 = ThreePoint->x2 - iTemp * 40;
- iTemp = (long)(ThreePoint->x3 / 100);
- ThreePoint->x3 = ThreePoint->x3 - iTemp * 40;
- iTemp = (long)(ThreePoint->y1 / 100);
- ThreePoint->y1 = ThreePoint->y1 - iTemp * 40;
- iTemp = (long)(ThreePoint->y2 / 100);
- ThreePoint->y2 = ThreePoint->y2 - iTemp * 40;
- iTemp = (long)(ThreePoint->y3 / 100);
- ThreePoint->y3 = ThreePoint->y3 - iTemp * 40;
- #endif
- }
- long CGpsDrawMap::GetLinkList(CObList *pLinkList,BYTE MapLevel)
- {
- long InfoAddr,LinkStartAddr,LinkEndAddr,i,Count = 0;
- char FirstChar;
- CGpsLinkStruct cGpsLink,*pLink;
- ChangeTriangle TmpTri;
- FirstChar = MapLevel + ('A' - 1);
- InfoAddr = m_cFatStruct.m_lLinkLibAddr;
- for(i = 0; i < m_cFatStruct.m_lLinkLibTotal; i++) {
- ClearBYTEArr(cGpsLink.m_LinkLibName,9);
- GetLibInfo(FileContent,InfoAddr,cGpsLink.m_LinkLibName,&LinkStartAddr,&LinkEndAddr);
- InfoAddr += LibInfoBytes; //链接库在FAT表中占用的字节数
- if(FirstChar != cGpsLink.m_LinkLibName[0]) {
- continue;
- }
- LinkStartAddr += 68; //将链接库指针移动到三个经纬度坐标
- GetLinkLibThreePoint(FileContent,LinkStartAddr,&TmpTri);
- LinkStartAddr += 24;
- ClearBYTEArr(cGpsLink.m_RelatedSignLibName,9);
- GetLenArray((BYTE*)cGpsLink.m_RelatedSignLibName,GpsLibFileLen,FileContent,LinkStartAddr); //获得综合标志库名称
- pLink = new CGpsLinkStruct;
- *pLink = cGpsLink;
- pLink->m_MapTri = TmpTri;
- pLinkList->AddHead(pLink);
- Count++;
- }
- return Count;
- }
- void CGpsDrawMap::GetAreaLibList(CObList *AreaList)
- {
- CGpsAreaLibStruct *pArea = NULL;
- long j,Total,StartAddr,EndAddr;
- char FileName[8],i;
- if(!m_cFatStruct.m_lRegionLibTotal) return ;
- GetLibInfo(FileContent,m_cFatStruct.m_lRegionLibAddr,FileName,&StartAddr,&EndAddr);
- for(i = 1; i <= AreaLibLevelTotal; i++) {
- Total = GetFourBNum(FileContent,StartAddr);
- StartAddr += LibTotalBytes;
- for(j = 0; j < Total; j++) {
- pArea = new CGpsAreaLibStruct;
- AreaList->AddHead(pArea);
- pArea->m_byAreaLevel = i;
- GetLenArray((BYTE*)pArea->m_arrAreaABCD,pArea->m_byAreaABCD_Bytes,FileContent,StartAddr);
- StartAddr += pArea->m_byAreaABCD_Bytes;
- GetLenArray((BYTE*)pArea->m_arrAreaName,pArea->m_byAreaName_Bytes,FileContent,StartAddr);
- StartAddr += pArea->m_byAreaName_Bytes;
- if(i == AreaLibLevelTotal) {
- GetLenArray((BYTE*)pArea->m_arrRelateSignLibName,pArea->m_byRelateSignLibName_Bytes,FileContent,StartAddr);
- StartAddr += pArea->m_byRelateSignLibName_Bytes;
- }
- }
- }
- }
- bool CGpsDrawMap::CompareTri(ChangeTriangle TmpTri1,ChangeTriangle TmpTri2)
- {
- double dx1,dy1,dx2,dy2,Bevel1,Bevel2;
- bool Result = false;
- dx1 = TmpTri1.x3 - TmpTri1.x1; dy1 = TmpTri1.y1 - TmpTri1.y3;
- Bevel1 = sqrt(dx1 * dx1 + dy1 * dy1);
- dx2 = TmpTri2.x3 - TmpTri2.x1; dy2 = TmpTri2.y1 - TmpTri2.y3;
- Bevel2 = sqrt(dx2 * dx2 + dy2 * dy2);
- if((Bevel1 - Bevel2) > 0) {
- Result = true;
- }
- return Result;
- }
- /*************Find CurrPoint in whitch map*************/
- bool CGpsDrawMap::CheckPointInMap(double gx,double gy,ChangeTriangle *TmpTri)
- {
- bool InMap = false;
- if(((gx >= TmpTri->x1) && (gx <= TmpTri->x3)) &&
- ((gy <= TmpTri->y1) && (gy >= TmpTri->y3))) {
- InMap = true;
- }
- return InMap;
- }
- bool CGpsDrawMap::GetCurrLinkLib(CObList *LinkList,CGpsLinkStruct *pLink,double gx,double gy)
- {
- CGpsLinkStruct *pTemp;
- POSITION pos;
- bool Result = false,Flag = false;
- if(LinkList->GetCount() == 0) return false;
- pos = LinkList->GetTailPosition();
- while(pos != NULL) {
- pTemp = (CGpsLinkStruct*)LinkList->GetPrev(pos);
- if(CheckPointInMap(gx,gy,&pTemp->m_MapTri)) {
- if(!Flag) {
- Flag = true;
- Result = true;
- *pLink = *pTemp;
- pLink->m_MapTri = pTemp->m_MapTri;
- }
- else {
- if(CompareTri(pLink->m_MapTri,pTemp->m_MapTri)) {
- *pLink = *pTemp;
- pLink->m_MapTri = pTemp->m_MapTri;
- }
- }
- }
- }
- return Result;
- }
- long CGpsDrawMap::GetLinkLibAddr(char *pLinkName)
- {
- long Result = -1;
- char LinkName[GpsLibFileLen + 1];
- long InfoAddr,LinkStartAddr,LinkEndAddr,i;
- InfoAddr = m_cFatStruct.m_lLinkLibAddr;
- for(i = 0; i < m_cFatStruct.m_lLinkLibTotal; i++) {
- ClearBYTEArr(LinkName,GpsLibFileLen + 1);
- GetLibInfo(FileContent,InfoAddr,LinkName,&LinkStartAddr,&LinkEndAddr);
- InfoAddr += LibInfoBytes; //链接库在FAT表中占用的字节数
- if(CompareTwoArr(pLinkName,LinkName) == 1) {
- Result = InfoAddr;
- break;
- }
- }
- return Result;
- }
- /*************Draw ColorBlock*************/
- void CGpsDrawMap::DrawColorBlock(CObList *ColorBList,CDC * MemDC)
- {
- CGpsColorBlock *pBlock;
- POSITION pos;
- CPen *DrawPen;
- pos = ColorBList->GetTailPosition();
- while(pos != NULL) {
- pBlock = (CGpsColorBlock*)ColorBList->GetPrev(pos);
- pBlock->m_ColorValue == 8 ? DrawPen = m_cColor.MapColor[6]:
- DrawPen = m_cColor.MapColor[pBlock->m_ColorValue - 1];
- DrawOneBlock(&pBlock->ColorBlockPointList,DrawPen,MemDC);
- }
- }
- void CGpsDrawMap::DrawOneBlock(CObList * PointList,CPen * CurrPen,CDC * MemDC)
- {
- long PointXY[3000][2];
- long MapBrim[500][4];
- long minX1 = -3000,minX2,PointCount;
- int i,j;
- BYTE b_draw;
- CGpsPoint *tmpPoint;
- POSITION pos;
- PointCount = PointList->GetCount();
- pos = PointList->GetHeadPosition();
- i = 0;
- while(pos != NULL){
- tmpPoint = (CGpsPoint*)PointList->GetNext(pos);
- PointXY[i][0] = tmpPoint->m_lx;
- PointXY[i][1] = tmpPoint->m_ly;
- i++;
- if(i == 3000) {
- AfxMessageBox("系统内部出错!");
- return;
- }
- }
- minX1 = GetMinX(&PointXY[0][0],PointCount,minX1);
- minX2 = GetMinX(&PointXY[0][0],PointCount,minX1);
- CString str;
- while(true){
- if(minX1 > m_cCurrMapInfo.m_lWnd_Max_X) {
- break;
- }
- minX2 = GetMinX(&PointXY[0][0],PointCount,minX1);
- if(minX2 == 10000){
- break;
- }
- if(minX2 < 0) {
- minX1 = minX2;
- continue;
- }
- b_draw = 0;
- for(i = 0; i < (PointCount - 1);i++){
- if((( PointXY[i][0] <= minX1) &&
- ( PointXY[i + 1][0] >= minX2) &&
- ( PointXY[i][0] < PointXY[i + 1][0])) ||
- ((PointXY[i][0] >= minX2) &&
- ( PointXY[i + 1][0] <= minX1) &&
- ( PointXY[i][0] > PointXY[i + 1][0]))){
- GetDrawPoint(&PointXY[i][0],minX1,minX2,&MapBrim[b_draw][0]);
- b_draw++;
- if(b_draw == 500){
- AfxMessageBox("系统内部出错!");
- return;
- }
- }
- }
- long tmp;
- for(i = 0; i < b_draw; i++){
- for(j = i + 1; j < b_draw; j++){
- if(MapBrim[i][1] > MapBrim[j][1]){
- tmp = MapBrim[i][1];
- MapBrim[i][1] = MapBrim[j][1];
- MapBrim[j][1] = tmp;
- tmp = MapBrim[i][3];
- MapBrim[i][3] = MapBrim[j][3];
- MapBrim[j][3] = tmp;
- }
- }
- }
- b_draw = b_draw / 2;
- for(i = 0; i < b_draw; i++){
- DrawTriangle(&MapBrim[2 * i][0],&MapBrim[2 * i + 1][0],CurrPen,MemDC);
- }
- minX1 = minX2;
- }
- }
- void CGpsDrawMap::DrawTriangle(long *bian1, long *bian2,CPen * CurrPen,CDC * MemDC)
- {
- long y1,y2,tmp;
- if((bian1[3] > bian2[3]) || (bian1[1] > bian2[1])){
- tmp = bian1[3];
- bian1[3] = bian2[3];
- bian2[3] = tmp;
- tmp = bian1[1];
- bian1[1] = bian2[1];
- bian2[1] = tmp;
- }
- for(int i = bian1[0]; i < bian2[2]; i++){
- y1 = bian1[1] + (i - bian1[0]) * (bian1[3] - bian1[1]) / (bian1[2] - bian1[0]);
- if(y1 > m_cCurrMapInfo.m_lWnd_Max_Y) {
- y1 = (long)m_cCurrMapInfo.m_lWnd_Max_Y;
- }
- else if(y1 < 0) {
- y1 = 0;
- }
- y2 = bian2[1] + (i - bian2[0]) * (bian2[3] - bian2[1]) / (bian2[2] - bian2[0]);
- if(y2 > m_cCurrMapInfo.m_lWnd_Max_X) {
- y2 = (long)m_cCurrMapInfo.m_lWnd_Max_X;
- }
- else{
- if(y2 < 0){
- y2 = 0;
- }
- }
- DrawLine(i,y1,i,y2,1,CurrPen,MemDC);
- }
- }
- /*************Draw Line*************/
- void CGpsDrawMap::DrawLine(long SX, long SY, long EX, long EY, int LineCount,CPen * CurrPen,CDC * MemDC)
- {
- CPen * OldPen;
- OldPen = MemDC->SelectObject(CurrPen);
- int bian = 1;
- int LineWide = LineCount;
-
- MemDC->MoveTo(SX,SY);
- MemDC->LineTo(EX,EY);
- while((LineCount--) > 0){
- if(SX == EX){
- bool flag = true;
- BYTE tmp = 1;
- for(int i = 0; i < LineWide; i++){
- if(flag){
- MemDC->MoveTo(SX + tmp,SY);
- MemDC->LineTo(EX + tmp,EY);
- flag = false;
- }
- else{
- MemDC->MoveTo(SX - tmp,SY);
- MemDC->LineTo(EX - tmp,EY);
- flag = true;
- }
- if (flag) tmp++;
- }
- }
- else if( ((EY - SY) / ( EX - SX)) != 0){
- MemDC->MoveTo(SX - bian,SY);
- MemDC->LineTo(EX - bian,EY);
- }
- else{
- MemDC->MoveTo(SX,SY - bian);
- MemDC->LineTo(EX,EY - bian);
- }
- if(bian > 0){
- bian = 0 - bian;
- }
- else{
- bian = 0 - bian;
- bian++;
- }
- }
- MemDC->SelectObject(OldPen);
- }
- long CGpsDrawMap::GetMinX(long *pDataXY,long PointCount,long MinX)
- {
- long ret = 10000;
- bool flag = false;
- for(int i = 0; i < PointCount; i++){
- if(pDataXY[i * 2] > MinX){
- if(pDataXY[i * 2] < ret){
- ret = pDataXY[i * 2];
- flag = true;
- }
- }
- }
- return ret;
- }
- void CGpsDrawMap::GetDrawPoint(long line_p[], int minX1, int minX2, long *Result)
- {
- int x1,y1,x2,y2;
- bool flag = true;
- if(line_p[1] == line_p[3]){
- flag = false;
- }
- if(line_p[0] > line_p[2]){
- x1 = line_p[2];
- y1 = line_p[3];
- x2 = line_p[0];
- y2 = line_p[1];
- }
- else{
- x1 = line_p[0];
- y1 = line_p[1];
- x2 = line_p[2];
- y2 = line_p[3];
- }
- if(minX1 < 0){
- Result[0] = 0;
- }
- else{
- Result[0] = minX1;
- }
- if(minX2 > m_cCurrMapInfo.m_lWnd_Max_X) {
- Result[2] = (long)m_cCurrMapInfo.m_lWnd_Max_X;
- }
- else{
- Result[2] = minX2;
- }
- if(flag){
- Result[1] = y1 + (Result[0] - x1) * (y2 - y1) / (x2 - x1);
- }
- else{
- Result[1] = line_p[1];
- }
- if(flag){
- Result[3] = y1 + (Result[2] - x1) * (y2 - y1) / (x2 - x1);
- }
- else{
- Result[3] = line_p[1];
- }
- }
- /*************Draw Road*************/
- void CGpsDrawMap::DrawRoad(CObList *RoadList,CDC *pDC)
- {
- CGpsRoadStruct *pRoad;
- CSmallRoadStruct *pSmall;
- CRoadPoint *pRoadPoint;
- POSITION pos,pos1,pos2;
- CPoint PrevPoint,CurrPoint;
- CPen *CurrPen;
- BYTE RoadLevel,RoadWidth;
- bool Flag;
- pos = RoadList->GetTailPosition();
- while(pos != NULL) {
- pRoad = (CGpsRoadStruct*)RoadList->GetPrev(pos);
- pos1 = pRoad->SmallRoadList.GetTailPosition();
- Flag = false;
- while(pos1 != NULL) {
- pSmall = (CSmallRoadStruct*)pRoad->SmallRoadList.GetPrev(pos1);
- RoadLevel = pSmall->RoadorName_DispLevel & 0x0f;
- switch (RoadLevel) {
- case 0:
- CurrPen = m_cColor.RoadColor[5];
- RoadWidth = 1;
- break;
- case 1:
- RoadWidth = 3;
- CurrPen = m_cColor.RoadColor[0];
- break;
- case 2:
- RoadWidth = 3;
- CurrPen = m_cColor.RoadColor[1];
- break;
- case 3:
- RoadWidth = 3;
- CurrPen = m_cColor.RoadColor[2];
- break;
- case 4:
- RoadWidth = 2;
- CurrPen = m_cColor.RoadColor[3];
- break;
- case 5:
- RoadWidth = 1;
- CurrPen = m_cColor.RoadColor[4];
- break;
- default:
- RoadWidth = 3;
- CurrPen = m_cColor.RoadColor[2];
- break;
- }
- switch(m_byZoomCoeffic) {
- case 1:
- RoadWidth += 2;
- break;
- case 2:
- RoadWidth += 3;
- break;
- case 4:
- RoadWidth += 4;
- break;
- }
- if(pRoad->m_byIsHelpRoad) {
- RoadWidth = 2;
- }
- pos2 = pSmall->RoadPointList.GetTailPosition();
- while(pos2 != NULL) {
- pRoadPoint = (CRoadPoint*)pSmall->RoadPointList.GetPrev(pos2);
- if(pRoadPoint->BigRoad_SerialNumber[1] == 100) continue;
- CurrPoint.x = pRoadPoint->m_lx; CurrPoint.y = pRoadPoint->m_ly;
- if(!Flag) {
- Flag = true;
- }
- else {
- // DrawLine(PrevPoint.x, PrevPoint.y,
- // CurrPoint.x, CurrPoint.y,
- // RoadWidth,CurrPen,pDC);
- MapDrawRoad(pDC,PrevPoint.x,PrevPoint.y,CurrPoint.x,CurrPoint.y,RoadWidth,CurrPen);
- }
- PrevPoint = CurrPoint;
- }
- }
- }
- }
- void CGpsDrawMap::MapDrawRoad(CDC *pDC, long SX, long SY, long EX, long EY, BYTE RoadWide,CPen *CurrPen)
- {
- CPen BorderPen(PS_SOLID,1,RGB(115,115,115));
- long W;
- MapDrawLineWidth(pDC,SX,SY,EX,EY,RoadWide,CurrPen);
- /*
- ** always draws from small X to large X
- */
- if (SX > EX) {
- W = EX, EX = SX, SX = W;
- W = EY, EY = SY, SY = W;
- }
- if (SX == EX) {
- DrawLine(SX - (RoadWide >> 1), SY, EX - (RoadWide >> 1), EY,0,&BorderPen,pDC);
- DrawLine(SX + (RoadWide >> 1), SY, EX + (RoadWide >> 1), EY,0,&BorderPen,pDC);
- return;
- }
- if (SY == EY) {
- DrawLine(SX, SY - (RoadWide >> 1), EX, EY - (RoadWide >> 1),0,&BorderPen,pDC);
- DrawLine(SX, SY + (RoadWide >> 1), EX, EY + (RoadWide >> 1),0,&BorderPen,pDC);
- return;
- }
- if (SY < EY) {
- DrawLine(SX + (RoadWide >> 1), SY - (RoadWide >> 1), EX + (RoadWide >> 1), EY - (RoadWide >> 1),0,&BorderPen,pDC);
- DrawLine(SX - (RoadWide >> 1), SY + (RoadWide >> 1), EX - (RoadWide >> 1), EY + (RoadWide >> 1),0,&BorderPen,pDC);
- return;
- }
- if (SY > EY) {
- DrawLine(SX - (RoadWide >> 1), SY - (RoadWide >> 1), EX - (RoadWide >> 1), EY - (RoadWide >> 1),0,&BorderPen,pDC);
- DrawLine(SX + (RoadWide >> 1), SY + (RoadWide >> 1), EX + (RoadWide >> 1), EY + (RoadWide >> 1),0,&BorderPen,pDC);
- return;
- }
- }
- void CGpsDrawMap::MapDrawLineWidth(CDC *pDC, long SX, long SY, long EX, long EY, BYTE MapLineWidth,CPen *Pen)
- {
- long W, H, Ha, dY, f;
- BYTE HalfWidth = MapLineWidth / 2;
- CPoint sp,ep;
- CPen *OldPen;
- OldPen = pDC->SelectObject(Pen);
- /*
- for (i = 0; i < MapLineWidth; i++) {
- sp.x = SX - HalfWidth + i;
- sp.y = SX - HalfWidth;
- ep.x = SX - HalfWidth + i;
- ep.y = SX - HalfWidth - MapLineWidth;
- pDC->MoveTo(sp);
- pDC->LineTo(ep);
- sp.x = EX - HalfWidth + i;
- sp.y = EX - HalfWidth;
- ep.x = EX - HalfWidth + i;
- ep.y = EX - HalfWidth - MapLineWidth;
- pDC->MoveTo(sp);
- pDC->LineTo(ep);
- }
- */
- /*
- ** always draws from small X to large X
- */
- if (SX > EX) {
- W = EX, EX = SX, SX = W;
- W = EY, EY = SY, SY = W;
- }
- /*
- ** we might want to clip the line here
- */
- W = (EX - SX);
- H = (EY - SY);
- Ha = (H < 0) ? -H : H;
- dY = (H < 0) ? -1 : 1;
- if (Ha > W) {
- /* Y-majored */
- f = 0;
- while (1) {
- sp.x = SX - HalfWidth;
- sp.y = SY - HalfWidth;
- ep.x = SX - HalfWidth + MapLineWidth;
- ep.y = SY - HalfWidth;
- pDC->MoveTo(sp);
- pDC->LineTo(ep);
- sp.x = SX - HalfWidth;
- sp.y = SY - HalfWidth;
- ep.x = SX - HalfWidth;
- ep.y = SY - HalfWidth + MapLineWidth;
- pDC->MoveTo(sp);
- pDC->LineTo(ep);
- sp.x = SX + HalfWidth;
- sp.y = SY + HalfWidth;
- ep.x = SX + HalfWidth - MapLineWidth;
- ep.y = SY + HalfWidth;
- pDC->MoveTo(sp);
- pDC->LineTo(ep);
- sp.x = SX + HalfWidth;
- sp.y = SY + HalfWidth;
- ep.x = SX + HalfWidth;
- ep.y = SY + HalfWidth - MapLineWidth;
- pDC->MoveTo(sp);
- pDC->LineTo(ep);
- if (SY == EY) break;
- if ((f += W) >= Ha) {
- f -= Ha;
- SX++;
- }
- SY += dY;
- }
- }
- else {
- /* X-majored */
- f = 0;
- while (1) {
- sp.x = SX - HalfWidth;
- sp.y = SY - HalfWidth;
- ep.x = SX - HalfWidth + MapLineWidth;
- ep.y = SY - HalfWidth;
- pDC->MoveTo(sp);
- pDC->LineTo(ep);
- sp.x = SX - HalfWidth;
- sp.y = SY - HalfWidth;
- ep.x = SX - HalfWidth;
- ep.y = SY - HalfWidth + MapLineWidth;
- pDC->MoveTo(sp);
- pDC->LineTo(ep);
- sp.x = SX + HalfWidth;
- sp.y = SY + HalfWidth;
- ep.x = SX + HalfWidth - MapLineWidth;
- ep.y = SY + HalfWidth;
- pDC->MoveTo(sp);
- pDC->LineTo(ep);
- sp.x = SX + HalfWidth;
- sp.y = SY + HalfWidth;
- ep.x = SX + HalfWidth;
- ep.y = SY + HalfWidth - MapLineWidth;
- pDC->MoveTo(sp);
- pDC->LineTo(ep);
- if (SX == EX) break;
- if ((f += Ha) >= W) {
- f -= W;
- SY += dY;
- }
- SX++;
- }
- }
- pDC->SelectObject(OldPen);
- }
- /*************Draw Road Name*************/
- void CGpsDrawMap::DrawRoadName(CObList *RoadList,CDC *pDC)
- {
- CGpsRoadStruct *pRoad;
- CSmallRoadStruct *pSmall;
- POSITION pos,pos1;
- CString RoadName;
- pos = RoadList->GetTailPosition();
- while(pos != NULL) {
- pRoad = (CGpsRoadStruct*)RoadList->GetPrev(pos);
- if(isupper(pRoad->BigRoad_Serial)) continue;
- pos1 = pRoad->SmallRoadList.GetTailPosition();
- while(pos1 != NULL) {
- pSmall = (CSmallRoadStruct*)pRoad->SmallRoadList.GetPrev(pos1);
- RoadName.Empty();
- RoadName = pSmall->RoadName;
- if(RoadName.IsEmpty()) continue;
- if(pSmall->RoadPointList.GetCount() < 2) continue;
- DrawOneRoadName(&pSmall->RoadPointList,RoadName,pDC);
- }
- }
- }
- BYTE CGpsDrawMap::GetChrCount(CString RoadName)
- {
- BYTE chr,pos,Length = 0;
-
- pos = 0;
- while(pos < RoadName.GetLength()) {
- chr = RoadName.GetAt(pos);
- if(chr < 0x80) pos++;
- else pos += 2;
- Length++;
- }
- return Length;
- }
- CPoint CGpsDrawMap::GetRoadMidPoint(CObList *RoadList)
- {
- CGpsPoint *pPoint;
- POSITION pos;
- CPoint point;
- short Mid,Count = 0;
- Mid = RoadList->GetCount() / 2;
- pos = RoadList->GetTailPosition();
- while(pos != NULL) {
- pPoint = (CGpsPoint*)RoadList->GetPrev(pos);
- if(Count == Mid) {
- point.x = pPoint->m_lx;
- point.y = pPoint->m_ly;
- return point;
- }
- Count++;
- }
- return NULL;
- }
- void CGpsDrawMap::DrawStr(CDC *pDC,CPoint point,CString Name)
- {
- CPoint TempPoint,cPoint(6,6),SavePoint;
- CBrush cBrush(RGB(0,255,255));
- CPen CurrPen(PS_SOLID,1,RGB(0,0,255)),*pSavePen = NULL;
- CRect cRect;
- bool Flag1 = false,Flag2 = false;
- pSavePen = pDC->SelectObject(&CurrPen);
- TempPoint.x = (long)(point.x + 30 / sqrt(2));
- TempPoint.y = (long)(point.y - 30 / sqrt(2));
- cRect = CRect(TempPoint.x - 3,TempPoint.y - 2,TempPoint.x + 3 + Name.GetLength() * 8,TempPoint.y + 18);
- if(cRect.top < 0) Flag1 = true;
- if(cRect.right > m_cCurrMapInfo.m_lWnd_Max_X) Flag2 = true;
- if(Flag1) {
- TempPoint.y = (long)(point.y + 30 / sqrt(2));
- }
- if(Flag2) {
- TempPoint.x = (long)(point.x - 30 / sqrt(2));
- }
- pDC->MoveTo(point);
- pDC->LineTo(TempPoint);
- SavePoint = TempPoint;
- if(Flag2) TempPoint.x = TempPoint.x - (3 + Name.GetLength() * 8);
- cRect = CRect(TempPoint.x - 3,TempPoint.y - 2,TempPoint.x + 3 + Name.GetLength() * 8,TempPoint.y + 18);
- pDC->SetBkMode(TRANSPARENT);
- pDC->RoundRect(cRect,cPoint);
- // pDC->FillRect(cRect,&cBrush);
- pDC->TextOut(TempPoint.x,TempPoint.y,Name);
- TempPoint = SavePoint;
- TempPoint.y += 8;
- pDC->MoveTo(point);
- pDC->LineTo(TempPoint);
- pDC->SelectObject(pSavePen);
- }
- long CGpsDrawMap::CalcTwoPointDist(CPoint sp,CPoint ep)
- {
- long dx,dy,Distance;
- dx = abs(sp.x - ep.x);
- dy = abs(sp.y - ep.y);
- Distance = (long)sqrt(Square(dx) + Square(dy));
- return Distance;
- }
- void CGpsDrawMap::SearchSign()
- {
- CSearchSignDlg dlg(&m_cCurrMapInfo.lCurrSignList,&m_cCurrMapInfo.lAreaLibList);
- dlg.GetParent(this);
- dlg.DoModal();
- }
- long CGpsDrawMap::CalcPointsDist(CObList *TempList,bool ByNE)
- {
- CGpsPoint *pPoint;
- POSITION pos = TempList->GetTailPosition();
- CPoint sp,ep;
- long Dist = 0;
- BYTE Flag = 0;
- while(pos != NULL) {
- pPoint = (CGpsPoint*)TempList->GetPrev(pos);
- if(!ByNE) {
- ep.x = pPoint->m_lx;
- ep.y = pPoint->m_ly;
- }
- else {
- ep.x = CovertToLongNE(pPoint->m_dgx);
- ep.y = CovertToLongNE(pPoint->m_dgy);
- }
- if(!Flag) {
- Flag = 1;
- sp = ep;
- continue;
- }
- Dist +=CalcTwoPointDist(sp,ep);
- sp = ep;
- }
- return Dist;
- }
- CPoint CGpsDrawMap::CalcOneLinePoint(CPoint sp,CPoint ep,long WordPos,long Bevel)
- {
- CPoint point;
- long dx,dy;
- dx = ep.x - sp.x; dy = ep.y - sp.y;
- if(dx == 0) {
- point.x = sp.x;
- point.y = sp.y + dy - WordPos;
- }
- else if(dy == 0) {
- point.x = sp.x + dx - WordPos;
- point.y = sp.y;
- }
- else {
- point.x = sp.x + (WordPos * dx) / Bevel;
- point.y = sp.y + (WordPos * dy) / Bevel;
- }
- return point;
- }
- void CGpsDrawMap::DrawOneRoadName(CObList * TempList,CString RoadName,CDC * MemDC)
- {
- CGpsPoint *pPoint = NULL;
- POSITION pos;
- CString Word;
- CPoint point,sp,ep;
- BYTE FirstChr,DrawMode,Flag = 0;
- BYTE NamePos = 1,Len = GetChrCount(RoadName);
- short PointTotal = TempList->GetCount();
- long WordPos,Dist,CurrDist,d = 0,dx,dy;
- FirstChr = RoadName.GetAt(0);
- if(isalpha(FirstChr)) DrawMode = true;
- else if(Len > PointTotal) DrawMode = true;
- else DrawMode = false;
- if(DrawMode) {
- // point = GetRoadMidPoint(TempList);
- // DrawStr(MemDC,point,RoadName);
- return;
- }
- else {
- Dist = CalcPointsDist(TempList);
- WordPos = Dist / (Len + 1) + 1;
- pos = TempList->GetTailPosition();
- while(pos != NULL) {
- pPoint = (CGpsPoint*)TempList->GetPrev(pos);
- ep.x = pPoint->m_lx;
- ep.y = pPoint->m_ly;
- if(!Flag) {
- sp = ep;
- Flag = 1;
- continue;
- }
- CurrDist = CalcTwoPointDist(sp,ep);
- d += CurrDist;
- if(NamePos / 2 >= Len) return;
- dx = abs(sp.x - ep.x); dy = abs(sp.y - ep.y);
- if(d == WordPos) {
- Word.Empty();
- Word += RoadName.GetAt(NamePos - 1);
- Word += RoadName.GetAt(NamePos - 0);
- // AfxMessageBox(Word);
- MemDC->SetBkMode (TRANSPARENT);
- if(dx > dy) {
- MemDC->TextOut(ep.x + 0,ep.y - 15,Word);
- }
- else {
- MemDC->TextOut(ep.x - 15,ep.y + 0,Word);
- }
- d = 0;
- NamePos += 2;
- }
- else if(d > WordPos) {
- point = CalcOneLinePoint(sp,ep,CurrDist - (d - WordPos),CurrDist);
- Word.Empty();
- Word += RoadName.GetAt(NamePos - 1);
- Word += RoadName.GetAt(NamePos - 0);
- // AfxMessageBox(Word);
- MemDC->SetBkMode (TRANSPARENT);
- if(dx > dy) {
- MemDC->TextOut(point.x + 0,point.y - 15,Word);
- }
- else {
- MemDC->TextOut(point.x - 15,point.y + 0,Word);
- }
- d = d - WordPos;
- NamePos += 2;
- }
- sp = ep;
- }
- }
- }
- void CGpsDrawMap::ClearLinkList(CObList *pLinkList)
- {
- CGpsLinkStruct *pLink;
- POSITION pos;
- pos = pLinkList->GetHeadPosition();
- while(pos != NULL) {
- pLink = (CGpsLinkStruct*)pLinkList->GetNext(pos);
- delete pLink;
- }
- pLinkList->RemoveAll();
- }
- void CGpsDrawMap::ClearPointList(CObList *PointList)
- {
- CGpsPoint *pPoint;
- POSITION pos;
- pos = PointList->GetHeadPosition();
- while(pos != NULL) {
- pPoint = (CGpsPoint*)PointList->GetNext(pos);
- delete pPoint;
- }
- PointList->RemoveAll();
- }
- bool CGpsDrawMap::SaveRecePoint(double gx,double gy,CDC *pDC,CString strVehicleNO)
- {
- if(!IsValidNE(gx,gy)) return false;
- CGpsPoint *pPoint,*pTempPoint = NULL;
- POSITION pos;
- bool Flag = false;
- pPoint = new CGpsPoint;
- pPoint->m_dgx = gx; pPoint->m_dgy = gy;
- pPoint->m_sVehicleNO = strVehicleNO;
- CovertNEXY(pPoint, m_cCurrMapInfo.CoeffNE_XY, true);
- pos = mSaveRecePointList.GetTailPosition();
- while(pos != NULL) {
- pTempPoint = (CGpsPoint*)mSaveRecePointList.GetPrev(pos);
- if(pTempPoint->m_sVehicleNO.Compare(strVehicleNO) == 0) {
- // ErasePrevPoint(pDC,pTempPoint->m_lx,pTempPoint->m_ly);
- pTempPoint->m_dgx = pPoint->m_dgx;
- pTempPoint->m_dgy = pPoint->m_dgy;
- pTempPoint->m_lx = pPoint->m_lx;
- pTempPoint->m_ly = pPoint->m_ly;
- delete pPoint;
- Flag = true;
- break;
- }
- }
- if(!Flag) {
- mSaveRecePointList.AddHead(pPoint);
- }
- return true;
- }
- void CGpsDrawMap::ErasePrevPoint(CDC *pDC,long x,long y)
- {
- CRect cRect;
- cRect.left = x - GPS_CAR_WIDTH_HEIGH / 2;
- cRect.right = x + GPS_CAR_WIDTH_HEIGH / 2;
- cRect.top = y - GPS_CAR_WIDTH_HEIGH / 2;
- cRect.bottom = y + GPS_CAR_WIDTH_HEIGH / 2;
- RedrawInvalidRect(cRect,pDC,false);
- }
- void CGpsDrawMap::DrawEllipse(CDC *pDC)
- {
- CGpsPoint *pPoint = NULL;
- CBrush cBrush(RGB(255,8,0));
- CBrush *SaveBrush = pDC->SelectObject(&cBrush);
- CRect cRect;
- BYTE Width = m_PointWidth + 2;
- if(mSaveRecePointList.GetCount() == 0) return;
- #if 1
- pPoint = (CGpsPoint*)mSaveRecePointList.GetHead();
- if(pPoint != NULL) {
- cRect.left = pPoint->m_lx - Width;
- cRect.right = pPoint->m_lx + Width;
- cRect.top = pPoint->m_ly - Width;
- cRect.bottom = pPoint->m_ly + Width;
- pDC->Ellipse(&cRect);
- }
- #else
- pos = mSaveRecePointList.GetTailPosition();
- while(pos != NULL) {
- pPoint = (CGpsPoint*)mSaveRecePointList.GetPrev(pos);
- cRect.left = pPoint->m_lx - Width;
- cRect.right = pPoint->m_lx + Width;
- cRect.top = pPoint->m_ly - Width;
- cRect.bottom = pPoint->m_ly + Width;
- pDC->Ellipse(&cRect);
- }
- #endif
- pDC->SelectObject(SaveBrush);
- SaveBrush->DeleteObject();
- }
- //Get Course of the car ...
- CString CGpsDrawMap::GetCarByDirection(double Course)
- {
- CString ret;
- double TmpCourse = 0;
- ret = SaveGpsCarPath[0];
- for(BYTE i = 0; i < 24; i++) {
- if((Course >= TmpCourse) && (Course < TmpCourse + 15)) {
- ret = SaveGpsCarPath[i];
- }
- TmpCourse += 15;
- }
- return ret;
- }
- //Redraw invalid rectangle...
- void CGpsDrawMap::RedrawInvalidRect(CRect cRect,CDC * pDC,bool Flag)
- {
- int i,j;
- int x,y;
- for(x = 0,i = cRect.left; i < cRect.right; i++,x++) {
- for(y = 0,j = cRect.top; j < cRect.bottom; j++,y++) {
- if((x == 40) || (y == 40)) break;
- if(Flag) {
- SaveInvalidRectColor[x][y]= GetPixel(*pDC,i,j);
- }
- else {
- SetPixel(*pDC,i,j,SaveInvalidRectColor[x][y]);
- }
- }
- }
- }
- //Draw Gps Car ...
- void CGpsDrawMap::DrawGpsCar(CDC *pDC,double Course)
- {
- #if 0
- CString CarName,CarPath;
- CBmpProc CarMap;
- CGpsPoint *pPoint = NULL;
- CRect cRect;
- HWND hWnd = ::GetActiveWindow();
- POSITION pos;
- CarPath += GetCarByDirection(Course);
- CarMap.LoadFromFile(CarPath);
- //refresh Prev Car...
- pos = mSaveRecePointList.GetHeadPosition();
- if(pos != NULL) {
- mSaveRecePointList.GetNext(pos);
- if(pos != NULL) {
- pPoint = (CGpsPoint*)mSaveRecePointList.GetNext(pos);
- if(pPoint != NULL) {
- cRect.left = pPoint->m_lx - CarMap.Width () / 2;
- cRect.right = pPoint->m_lx + CarMap.Width () / 2;
- cRect.top = pPoint->m_ly - CarMap.Height() / 2;
- cRect.bottom = pPoint->m_ly + CarMap.Height() / 2;
- RedrawInvalidRect(cRect,pDC,false);
- }
- }
- }
- //Draw Car...
- pPoint = (CGpsPoint*)mSaveRecePointList.GetHead();
- if(pPoint != NULL) {
- cRect.left = pPoint->m_lx - CarMap.Width () / 2;
- cRect.right = pPoint->m_lx + CarMap.Width () / 2;
- cRect.top = pPoint->m_ly - CarMap.Height() / 2;
- cRect.bottom = pPoint->m_ly + CarMap.Height() / 2;
- RedrawInvalidRect(cRect,pDC,true);
- CarMap.DrawTransparentInRect(*pDC,0,&cRect,NULL,0); //装入汽车位图
- CPoint point;
- point.x = pPoint->m_lx;
- point.y = pPoint->m_ly;
- DrawStr(pDC,point,strVehicleNO);
- }
- CarMap.Clear();
- #else
- CString CarName,CarPath;
- CBmpProc CarMap;
- CGpsPoint *pPoint = NULL;
- CRect cRect;
- POSITION pos;
- CarPath += GetCarByDirection(Course);
- CarMap.LoadFromFile(CarPath);
- //refresh Prev Car...
- /* pos = mSaveRecePointList.GetHeadPosition();
- if(pos != NULL) {
- mSaveRecePointList.GetNext(pos);
- if(pos != NULL) {
- pPoint = (CGpsPoint*)mSaveRecePointList.GetNext(pos);
- if(pPoint != NULL) {
- ErasePrevPoint(pDC,pPoint->m_lx,pPoint->m_ly);
- }
- }
- }
- */
- //Draw Car...
- pos = mSaveRecePointList.GetTailPosition();
- while(pos != NULL) {
- pPoint = (CGpsPoint*)mSaveRecePointList.GetPrev(pos);
- if(pPoint != NULL) {
- cRect.left = pPoint->m_lx - CarMap.Width () / 2;
- cRect.right = pPoint->m_lx + CarMap.Width () / 2;
- cRect.top = pPoint->m_ly - CarMap.Height() / 2;
- cRect.bottom = pPoint->m_ly + CarMap.Height() / 2;
- RedrawInvalidRect(cRect,pDC,true);
- CarMap.DrawTransparentInRect(*pDC,0,&cRect,NULL,0); //装入汽车位图
- CPoint point;
- point.x = pPoint->m_lx;
- point.y = pPoint->m_ly;
- if(!pPoint->m_sVehicleNO.IsEmpty()) {
- DrawStr(pDC,point,pPoint->m_sVehicleNO);
- }
- }
- }
- CarMap.Clear();
- #endif
- }
- void CGpsDrawMap::MoveScrollBar(long x,long y)
- {
- CGpsSCView *pView = ((CGpsSCView*)m_pCurrView);
- CSize scrollsize = pView->GetTotalSize();
- int hscrollpos[5],vscrollpos[4];
- for(int i=0;i<5;i++)
- hscrollpos[i] = scrollsize.cx/5*(i+1);// - scrollsize.cx/15;
- for(i=0;i<4;i++)
- vscrollpos[i]= scrollsize.cy/4*(i+1);// - scrollsize.cy/15 ;
- if(x>=hscrollpos[0]&& x<=hscrollpos[1])
- pView->SetScrollPos(SB_HORZ,hscrollpos[0],TRUE);
- else if(x>hscrollpos[1]&& x<=hscrollpos[2])
- pView->SetScrollPos(SB_HORZ,hscrollpos[1],TRUE);
- else if(x>hscrollpos[2]&& x<=hscrollpos[3])
- pView->SetScrollPos(SB_HORZ,hscrollpos[2],TRUE);
- else if(x>hscrollpos[3]&& x<=hscrollpos[4])
- pView->SetScrollPos(SB_HORZ,hscrollpos[3],TRUE);
- else if(x>hscrollpos[4]&& x<=hscrollpos[5])
- pView->SetScrollPos(SB_HORZ,hscrollpos[4],TRUE);
- else
- pView->SetScrollPos(SB_HORZ,0,TRUE);
- if(y>=vscrollpos[0] && y<=vscrollpos[1])
- pView->SetScrollPos(SB_VERT,vscrollpos[0]);
- else if(y>vscrollpos[1] && y<=vscrollpos[2])
- pView->SetScrollPos(SB_VERT,vscrollpos[1]);
- else if(y>vscrollpos[2] && y<=vscrollpos[3])
- pView->SetScrollPos(SB_VERT,vscrollpos[2]);
- else if(y>vscrollpos[3] && y<=vscrollpos[4])
- pView->SetScrollPos(SB_VERT,vscrollpos[3]);
- else
- pView->SetScrollPos(SB_VERT,0,TRUE);
- }
- /***********Draw icon***********/
- void CGpsDrawMap::DrawIcon(CDC *pDC,CPoint point,CString IconName)
- {
- CRect cRect;
- CString IconPath;
- CBmpProc IconMap;
- IconMap.LoadFromFile(IconName);
- cRect.top = point.y - IconMap.Height() / 2;
- cRect.bottom = point.y + IconMap.Height() / 2;
- cRect.left = point.x - IconMap.Width () / 2;
- cRect.right = point.x + IconMap.Width () / 2;
-
- IconMap.DrawTransparentInRect(*pDC,0,&cRect,NULL,0); //装入标志物图标
- }
- //在NE中国范围内即为有效
- BYTE CGpsDrawMap::IsValidNE(double gx,double gy)
- {
- double MinN,MinE,MaxN,MaxE;
- BYTE Invalid = 0;
- MinN = 7310.0000; MinE = 6060.0080;
- MaxN = 13530.0000; MaxE = 1810.0000;
- if(((gx - MinN >= 0.0) && (gx - MaxN <= 0.0)) &&
- ((gy - MinE <= 0.0) && (gy - MaxE >= 0.0))) {
- Invalid = 1;
- }
- return Invalid;
- }
- void CGpsDrawMap::GetView(CView *pView)
- {
- m_pCurrView = pView;
- }
- void CGpsDrawMap::FreshWnd()
- {
- ((CGpsSCView*)m_pCurrView)->Invalidate();
- }
- BYTE CGpsDrawMap::CheckMapIsChange(double gx,double gy)
- {
- CGpsLinkStruct cLink;
- BYTE IsChange;
- if(!IsValidNE(gx,gy)) return 0;
- if(!GetCurrLinkLib(&mLinkList,&cLink,gx,gy)) return 0;
- if(CompareTwoArr(cLink.m_LinkLibName,m_cCurrMapInfo.m_LinkFileName) != 1) {
- IsChange = 1;
- GetCurrMapInfo(&cLink,&m_cCurrMapInfo);
- ((CGpsSCView*)m_pCurrView)->m_bMapIsDrawed = false;
- ((CGpsSCView*)m_pCurrView)->Invalidate();
- }
- else {
- IsChange = 0;
- ((CGpsSCView*)m_pCurrView)->Invalidate();
- }
- return IsChange;
- }
- void CGpsDrawMap::ClearSaveInvalidRectColor()
- {
- BYTE i,j;
- for(i = 0; i < 40; i++) {
- for(j = 0; j < 40; j++) {
- SaveInvalidRectColor[i][j] = 0;
- }
- }
- }
- void CGpsDrawMap::ReCalcPointXY(CObList *PointList)
- {
- CGpsPoint *pPoint = NULL;
- POSITION pos;
- pos = PointList->GetTailPosition();
- while(pos != NULL) {
- pPoint = (CGpsPoint*)PointList->GetPrev(pos);
- CovertNEXY(pPoint, m_cCurrMapInfo.CoeffNE_XY, true);
- }
- }
- //Draw Fat Map ...
- void CGpsDrawMap::DrawFatMap(CDC *pDC)
- {
- CGpsLinkStruct cLink;
- RefreshMapWnd();
- if(!GetDataLib(m_cCurrMapInfo.m_DataFileName)) return ;
- m_cCurrMapInfo.ClearSignList();
- GetSignLib(m_cCurrMapInfo.m_SignFileName,&m_cCurrMapInfo.lCurrSignList);
- ReDraw(pDC);
- // ClearPointList(&mSaveRecePointList);
- ReCalcPointXY(&mSaveRecePointList);
- ClearSaveInvalidRectColor();
- }
- void CGpsDrawMap::DrawSignLib(CDC *pDC)
- {
- CGpsSignObject *pSign;
- POSITION pos;
- CString SignName;
- CPoint point;
- pos = m_cCurrMapInfo.lCurrSignList.GetTailPosition();
- while(pos != NULL) {
- pSign = (CGpsSignObject*)m_cCurrMapInfo.lCurrSignList.GetPrev(pos);
- if((pSign->m_bySignType == m_ShowSign.bShowBuilding) ||
- (pSign->m_bySignType == m_ShowSign.bShowHotel) ||
- (pSign->m_bySignType == m_ShowSign.bShowCompany) ||
- (pSign->m_bySignType == m_ShowSign.bShowAmuse) ||
- (pSign->m_bySignType == m_ShowSign.bShowPlaceName)||
- (pSign->m_bySignType == m_ShowSign.bShowGovern) ||
- (pSign->m_bySignType == m_ShowSign.bShowTraffic) ||
- (pSign->m_bySignType == m_ShowSign.bShowShopping) ||
- (pSign->m_bySignType == m_ShowSign.bShowEducation)||
- (pSign->m_bySignType == m_ShowSign.bShowHospital) ||
- (pSign->m_bySignType == m_ShowSign.bShowBureau) ||
- (pSign->m_bySignType == m_ShowSign.bShowOil)) {
- // if(!pSign->m_bDraw) continue;
- SignName = pSign->m_pSignObjectName;
- point.x = pSign->m_lx; point.y = pSign->m_ly;
- DrawIcon(pDC,point,pSign->m_sIconName);
- DrawStr(pDC,point,SignName);
- }
- }
- }
- void CGpsDrawMap::DrawOneSignPoint(CDC *pDC)
- {
- // if(pDispOneSign == NULL) return;
- CString SignName;
- CPoint point;
- SignName = pDispOneSign.m_pSignObjectName;
- point.x = pDispOneSign.m_lx; point.y = pDispOneSign.m_ly;
- DrawIcon(pDC,point,pDispOneSign.m_sIconName);
- DrawStr(pDC,point,SignName);
- }
- void CGpsDrawMap::ReDraw(CDC *pDC)
- {
- DrawColorBlock(&m_cCurrMapInfo.lCurrColorBList,pDC);
- DrawRoad(&m_cCurrMapInfo.lCurrRoadList,pDC);
- DrawRoadName(&m_cCurrMapInfo.lCurrRoadList,pDC);
- }
- void CGpsDrawMap::SwapTwoVar(long &a, long &b)
- {
- long SwapVar;
- SwapVar = a;
- a = b;
- b = SwapVar;
- }
- BYTE CGpsDrawMap::PointOnLineNE(long SY, long SX, long EY, long EX, long NY, long NX, long K)
- {
- long W, H;
- long MaxN, MaxE, MinN, MinE;
- W = abs(SX - EX);
- H = abs(SY - EY);
- if (H > W) {
- /* Y-majored */
- MaxN = Max(SY, EY);
- MinN = Min(SY, EY);
- MaxE = Max(SX, EX) + K;
- MinE = Min(SX, EX) - K;
- }
- else {
- /* X-majored */
- MaxN = Max(SY, EY) + K;
- MinN = Min(SY, EY) - K;
- MaxE = Max(SX, EX);
- MinE = Min(SX, EX);
- }
- return (NX > MinE && NX < MaxE && NY > MinN && NY < MaxN);
- }
- long CGpsDrawMap::DistanceToLine(long SY, long SX, long EY, long EX, long NY, long NX)
- {
- long W, H, Ha, dY, f;
- /*
- ** always draws from small X to large X
- */
- if (SX > EX) {
- SwapTwoVar(SX, EX);
- SwapTwoVar(SY, EY);
- }
- /*
- ** we might want to clip the line here
- */
- W = (EX - SX);
- H = (EY - SY);
- Ha = (H < 0) ? -H : H;
- dY = (H < 0) ? -1 : 1;
- if (Ha > W) {
- if (NY > Max(SY, EY) || NY < Min(SY, EY)) return GPS_INFINITE;
- }
- else {
- if (NX > Max(SX, EX) || NX < Min(SX, EX)) return GPS_INFINITE;
- }
- if (Ha > W) {
- /* Y-majored */
- f = 0;
- while (1) {
- if (SY == NY) {
- return ((long)abs(SX - NX));
- }
- if (SY == EY)
- break;
- if ((f += W) >= Ha) {
- f -= Ha;
- SX++;
- }
- SY += dY;
- }
- }
- else {
- /* X-majored */
- f = 0;
- while (1) {
- if (SX == NX) {
- return ((long)abs(SY - NY));
- }
- if (SX == EX)
- break;
- if ((f += Ha) >= W) {
- f -= W;
- SY += dY;
- }
- SX++;
- }
- }
- return GPS_INFINITE;
- }
- long CGpsDrawMap::CalcPointToOneRoadDist(CPoint point,CSmallRoadStruct *pSmall)
- {
- CRoadPoint *pRoadPoint;
- CPoint sp,ep;
- POSITION pos;
- long d,Dist = GPS_INFINITE;
- bool Flag = false;
- pos = pSmall->RoadPointList.GetTailPosition();
- while(pos != NULL) {
- pRoadPoint = (CRoadPoint*)pSmall->RoadPointList.GetPrev(pos);
- ep.x = pRoadPoint->m_lx; ep.y = pRoadPoint->m_ly;
- if(!Flag) {
- Flag = true;
- sp = ep;
- continue;
- }
- if(!PointOnLineNE(sp.y,sp.x,ep.y,ep.x,point.y,point.x,100)) continue;
- d = DistanceToLine(sp.y,sp.x,ep.y,ep.x,point.y,point.x);
- if(d < Dist) {
- Dist = d;
- }
- sp = ep;
- }
- return Dist;
- }
- CString CGpsDrawMap::SearchRoad(const CPoint point,CString &RoadSn)
- {
- CSmallRoadStruct *pSmall;
- CGpsRoadStruct *pRoad;
- POSITION pos,pos1;
- CString RoadName(""),Name;
- long d,Dist = GPS_INFINITE;
- pos = m_cCurrMapInfo.lCurrRoadList.GetTailPosition();
- while(pos != NULL) {
- pRoad = (CGpsRoadStruct*)m_cCurrMapInfo.lCurrRoadList.GetPrev(pos);
- pos1 = pRoad->SmallRoadList.GetTailPosition();
- while(pos1 != NULL) {
- pSmall = (CSmallRoadStruct*)pRoad->SmallRoadList.GetPrev(pos1);
- Name = pSmall->RoadName;
- if(Name.IsEmpty()) continue;
- d = CalcPointToOneRoadDist(point,pSmall);
- if(d < Dist) {
- Dist = d;
- RoadName = Name;
- }
- }
- }
- return RoadName;
- }
- CString CGpsDrawMap::GetMapInfoByNE(double gx,double gy,BYTE SignType,BYTE InfoType)
- {
- CString RelatedInfo("没有找到相关信息!");
- if(InfoType == 2) {
- return RelatedInfo;
- }
- if(!IsValidNE(gx,gy)) return RelatedInfo;
- CGpsSignObject *pSign = NULL,*pMin = NULL;
- POSITION pos;
- CGpsPoint cPoint;
- CPoint p1,p2;
- CString SignName,RoadName,RoadSn;
- long Dist = GPS_INFINITE,d;
- bool Flag;
- cPoint.m_dgx = gx;
- cPoint.m_dgy = gy;
- CovertNEXY(&cPoint, m_cCurrMapInfo.CoeffNE_XY, true);
- p1.x = cPoint.m_lx; p1.y = cPoint.m_ly;
- Flag = false;
- pos = m_cCurrMapInfo.lCurrSignList.GetTailPosition();
- while(pos != NULL) {
- pSign = (CGpsSignObject*)m_cCurrMapInfo.lCurrSignList.GetPrev(pos);
- if((pSign->m_bySignType != SignType) && (SignType != 0)) continue;
- if((abs(pSign->m_lx - cPoint.m_lx) < 100) &&
- (abs(pSign->m_ly - cPoint.m_ly) < 100)) {
- p2.x = pSign->m_lx; p2.y = pSign->m_ly;
- d = CalcTwoPointDist(p1,p2);
- if(d < Dist) {
- Dist = d;
- SignName = pSign->m_pSignObjectName;
- Flag = true;
- pMin = pSign;
- }
- }
- }
- if(Flag) pMin->m_bDraw = true;
- RoadName = SearchRoad(p1,RoadSn);
- if(Flag && (!RoadName.IsEmpty())) {
- RelatedInfo.Format("您现在在%s,%s附近!",RoadName,SignName);
- }
- else if(Flag) {
- RelatedInfo.Format("您现在在%s附近!",SignName);
- }
- else if(!RoadName.IsEmpty()) {
- RelatedInfo.Format("您现在在%s!",RoadName);
- }
- return RelatedInfo;
- }
- #if 0
- //void zoom in
- void CGpsDrawMap::ZoomDown()
- {
- if(m_byZoomCoeffic == 1) return;
- m_cCurrMapInfo.m_lWnd_Max_X = m_cCurrMapInfo.m_lWnd_Max_X / m_byZoomCoeffic;
- m_cCurrMapInfo.m_lWnd_Max_Y = m_cCurrMapInfo.m_lWnd_Max_Y / m_byZoomCoeffic;
- m_byZoomCoeffic = m_byZoomCoeffic / 2;
- if(m_byZoomCoeffic < 1) m_byZoomCoeffic = 1;
- m_cCurrMapInfo.m_lWnd_Max_X = m_cCurrMapInfo.m_lWnd_Max_X * m_byZoomCoeffic;
- m_cCurrMapInfo.m_lWnd_Max_Y = m_cCurrMapInfo.m_lWnd_Max_Y * m_byZoomCoeffic;
- ((CGpsSCView*)m_pCurrView)->SetScrollSizes(MM_TEXT, CSize(m_cCurrMapInfo.m_lWnd_Max_X, m_cCurrMapInfo.m_lWnd_Max_Y));
- RefreshMapWnd();
- CalcAllPointXY();
- ((CGpsSCView*)m_pCurrView)->m_bMapIsDrawed = false;
- ((CGpsSCView*)m_pCurrView)->Invalidate();
- }
- //zoon out
- void CGpsDrawMap::ZoomUp()
- {
- if(m_byZoomCoeffic == 8) return;
- m_cCurrMapInfo.m_lWnd_Max_X = m_cCurrMapInfo.m_lWnd_Max_X / m_byZoomCoeffic;
- m_cCurrMapInfo.m_lWnd_Max_Y = m_cCurrMapInfo.m_lWnd_Max_Y / m_byZoomCoeffic;
- m_byZoomCoeffic *= 2;
- if(m_byZoomCoeffic > 8) m_byZoomCoeffic = 8;
- m_cCurrMapInfo.m_lWnd_Max_X = m_cCurrMapInfo.m_lWnd_Max_X * m_byZoomCoeffic;
- m_cCurrMapInfo.m_lWnd_Max_Y = m_cCurrMapInfo.m_lWnd_Max_Y * m_byZoomCoeffic;
- ((CGpsSCView*)m_pCurrView)->SetScrollSizes(MM_TEXT, CSize(m_cCurrMapInfo.m_lWnd_Max_X, m_cCurrMapInfo.m_lWnd_Max_Y));
- RefreshMapWnd();
- CalcAllPointXY();
- ((CGpsSCView*)m_pCurrView)->m_bMapIsDrawed = false;
- ((CGpsSCView*)m_pCurrView)->Invalidate();
- }
- #else
- void CGpsDrawMap::DispOtherLevelMap()
- {
- if(mSaveRecePointList.GetCount() == 0) return;
- ClearLinkList(&mLinkList);
- GetLinkList(&mLinkList,gCurrMapLevel);
- CGpsPoint *pPoint = NULL;
- pPoint = (CGpsPoint*)mSaveRecePointList.GetHead();
- CheckMapIsChange(pPoint->m_dgx,pPoint->m_dgy);
- CGpsLinkStruct cLink;
- RefreshMapWnd();
- if(!GetDataLib(m_cCurrMapInfo.m_DataFileName)) return ;
- }
- //void zoom in
- void CGpsDrawMap::ZoomDown()
- {
- BYTE SaveCoeff = m_byZoomCoeffic;
- if(m_byZoomCoeffic == 1) {
- if(gCurrMapLevel > 1) {
- gCurrMapLevel--;
- m_byZoomCoeffic = 2;
- DispOtherLevelMap();
- }
- }
- else {
- // m_cCurrMapInfo.m_lWnd_Max_X = m_cCurrMapInfo.m_lWnd_Max_X / m_byZoomCoeffic;
- // m_cCurrMapInfo.m_lWnd_Max_Y = m_cCurrMapInfo.m_lWnd_Max_Y / m_byZoomCoeffic;
- m_byZoomCoeffic = m_byZoomCoeffic / 2;
- if(m_byZoomCoeffic < 1) m_byZoomCoeffic = 1;
- }
- m_cCurrMapInfo.m_lWnd_Max_X = m_cCurrMapInfo.m_lWnd_Max_X / SaveCoeff;
- m_cCurrMapInfo.m_lWnd_Max_Y = m_cCurrMapInfo.m_lWnd_Max_Y / SaveCoeff;
- m_cCurrMapInfo.m_lWnd_Max_X = m_cCurrMapInfo.m_lWnd_Max_X * m_byZoomCoeffic;
- m_cCurrMapInfo.m_lWnd_Max_Y = m_cCurrMapInfo.m_lWnd_Max_Y * m_byZoomCoeffic;
- ((CGpsSCView*)m_pCurrView)->SetScrollSizes(MM_TEXT, CSize(m_cCurrMapInfo.m_lWnd_Max_X, m_cCurrMapInfo.m_lWnd_Max_Y));
- RefreshMapWnd();
- CalcAllPointXY();
- ((CGpsSCView*)m_pCurrView)->m_bMapIsDrawed = false;
- ((CGpsSCView*)m_pCurrView)->Invalidate();
- }
- //zoon out
- void CGpsDrawMap::ZoomUp()
- {
- BYTE SaveCoeff = m_byZoomCoeffic;
- if((m_byZoomCoeffic == 2) && (gCurrMapLevel < 6)) {
- if(gCurrMapLevel < 6) {
- gCurrMapLevel++;
- m_byZoomCoeffic = 1;
- DispOtherLevelMap();
- }
- }
- else {
- // m_cCurrMapInfo.m_lWnd_Max_X = m_cCurrMapInfo.m_lWnd_Max_X / m_byZoomCoeffic;
- // m_cCurrMapInfo.m_lWnd_Max_Y = m_cCurrMapInfo.m_lWnd_Max_Y / m_byZoomCoeffic;
- m_byZoomCoeffic *= 2;
- if(m_byZoomCoeffic > 2) m_byZoomCoeffic = 2;
- }
- m_cCurrMapInfo.m_lWnd_Max_X = m_cCurrMapInfo.m_lWnd_Max_X / SaveCoeff;
- m_cCurrMapInfo.m_lWnd_Max_Y = m_cCurrMapInfo.m_lWnd_Max_Y / SaveCoeff;
- m_cCurrMapInfo.m_lWnd_Max_X = m_cCurrMapInfo.m_lWnd_Max_X * m_byZoomCoeffic;
- m_cCurrMapInfo.m_lWnd_Max_Y = m_cCurrMapInfo.m_lWnd_Max_Y * m_byZoomCoeffic;
- ((CGpsSCView*)m_pCurrView)->SetScrollSizes(MM_TEXT, CSize(m_cCurrMapInfo.m_lWnd_Max_X, m_cCurrMapInfo.m_lWnd_Max_Y));
- RefreshMapWnd();
- CalcAllPointXY();
- ((CGpsSCView*)m_pCurrView)->m_bMapIsDrawed = false;
- ((CGpsSCView*)m_pCurrView)->Invalidate();
- }
- #endif
- void CGpsDrawMap::ReCalcRoadXY(CObList *RoadList)
- {
- CGpsRoadStruct *pRoad;
- CSmallRoadStruct *pSmall;
- POSITION pos,pos1;
- pos = RoadList->GetTailPosition();
- while(pos != NULL) {
- pRoad = (CGpsRoadStruct*)RoadList->GetPrev(pos);
- pos1 = pRoad->SmallRoadList.GetTailPosition();
- while(pos1 != NULL) {
- pSmall = (CSmallRoadStruct*)pRoad->SmallRoadList.GetPrev(pos1);
- ReCalcPointXY(&pSmall->RoadPointList);
- }
- }
- }
- void CGpsDrawMap::ReCalcColorBXY(CObList *ColorBList)
- {
- CGpsColorBlock *pBlock;
- POSITION pos;
- pos = ColorBList->GetTailPosition();
- while(pos != NULL) {
- pBlock = (CGpsColorBlock*)ColorBList->GetPrev(pos);
- ReCalcPointXY(&pBlock->ColorBlockPointList);
- }
- }
- void CGpsDrawMap::CalcAllPointXY()
- {
- ReCalcRoadXY(&m_cCurrMapInfo.lCurrRoadList);
- ReCalcColorBXY(&m_cCurrMapInfo.lCurrColorBList);
- ReCalcPointXY(&m_cCurrMapInfo.lCurrSignList);
- ReCalcPointXY(&m_cCurrMapInfo.lCurrCrossList);
- ReCalcPointXY(&mSaveRecePointList);
- CovertNEXY(&pDispOneSign, m_cCurrMapInfo.CoeffNE_XY, true);
- }
- bool CGpsDrawMap::GetOneRoadPlain(CGpsRoadCrossPoint *pCross1,
- CGpsRoadCrossPoint *pCross2,
- CObList *RoadList,CString RoadSn,CObList *DstList)
- {
- CSmallRoadStruct *pSmall;
- CGpsRoadStruct *pRoad;
- CRoadPoint *pRoadPoint,*pPoint;
- POSITION pos,pos1,pos2;
- CString TempSn;
- char Flag_SD;
- short C1Pos = -1,C2Pos = -1,Pos;
- bool Flag = false;
- // AfxMessageBox(RoadSn);
- pos = RoadList->GetTailPosition();
- while(pos != NULL) {
- pRoad = (CGpsRoadStruct*)RoadList->GetPrev(pos);
- TempSn.Format("%c%d",pRoad->BigRoad_Serial,pRoad->m_BigRoad_Number);
- if(TempSn != RoadSn) continue;
- // AfxMessageBox(RoadSn);
- // if(RoadSn != "S87") continue;
- Flag = true;
- Pos = 1;
- pos1 = pRoad->SmallRoadList.GetTailPosition();
- while(pos1 != NULL) {
- pSmall = (CSmallRoadStruct*)pRoad->SmallRoadList.GetPrev(pos1);
- Flag_SD = (char)pSmall->Road_SD;
- pos2 = pSmall->RoadPointList.GetTailPosition();
- while(pos2 != NULL) {
- pRoadPoint = (CRoadPoint*)pSmall->RoadPointList.GetPrev(pos2);
- CString str;
- str.Format("%d,%d;%d,%d",pRoadPoint->m_lx,pRoadPoint->m_ly,pCross1->m_lx,pCross1->m_ly);
- // AfxMessageBox(str);
- if((pRoadPoint->m_lx == pCross1->m_lx) &&
- (pRoadPoint->m_ly == pCross1->m_ly)) {
- C1Pos = Pos;
- // AfxMessageBox("a");
- }
- if((pRoadPoint->m_lx == pCross2->m_lx) &&
- (pRoadPoint->m_ly == pCross2->m_ly)) {
- C2Pos = Pos;
- // AfxMessageBox("b");
- }
- Pos++;
- }
- }
- if(Flag) break;
- }
- if(!Flag) return false;
- // AfxMessageBox("1");
- if((C1Pos == -1) || (C2Pos == -1)) return false;
- // AfxMessageBox("2");
- bool IsSingle = false;
- if(Flag_SD == 'S') {
- if(C1Pos > C2Pos) return false;
- // if(C1Pos > C2Pos) IsSingle = true;
- }
- // AfxMessageBox("3");
- if(C1Pos > C2Pos) {
- short Temp;
- Temp = C1Pos;
- C1Pos = C2Pos;
- C2Pos = Temp;
- }
- Pos = 1;
- pos1 = pRoad->SmallRoadList.GetTailPosition();
- while(pos1 != NULL) {
- pSmall = (CSmallRoadStruct*)pRoad->SmallRoadList.GetPrev(pos1);
- pos2 = pSmall->RoadPointList.GetTailPosition();
- while(pos2 != NULL) {
- pRoadPoint = (CRoadPoint*)pSmall->RoadPointList.GetPrev(pos2);
- if((Pos >= C1Pos) && (Pos <= C2Pos)) {
- pPoint = new CRoadPoint;
- *pPoint = *pRoadPoint;
- DstList->AddHead(pPoint);
- }
- Pos++;
- }
- }
- CString str;
- str.Format("Count = %d",DstList->GetCount());
- // AfxMessageBox(str);
- return true;
- }
- bool CGpsDrawMap::IsInvalidSn(CString RoadSn)
- {
- if(RoadSn == "x255") return true;
- return false;
- }
- bool CGpsDrawMap::SimilarCross(CGpsRoadCrossPoint *C1,CGpsRoadCrossPoint *C2)
- {
- CString arrRoadSn[4];
- BYTE i;
- if((C1->m_lx != C2->m_lx) || (C1->m_ly != C2->m_ly)) return false;
- arrRoadSn[0].Format("%c%d",C1->m_CrossRoad1_Serial,C1->m_CrossRoad1_Number);
- arrRoadSn[1].Format("%c%d",C1->m_CrossRoad2_Serial,C1->m_CrossRoad2_Number);
- arrRoadSn[2].Format("%c%d",C1->m_CrossRoad3_Serial,C1->m_CrossRoad3_Number);
- arrRoadSn[3].Format("%c%d",C1->m_CrossRoad4_Serial,C1->m_CrossRoad4_Number);
- for(i = 0; i < 4; i++) {
- if(IsInvalidSn(arrRoadSn[i])) continue;
- if(!RoadSnInCross(arrRoadSn[i],C2)) return false;
- }
- arrRoadSn[0].Format("%c%d",C2->m_CrossRoad1_Serial,C2->m_CrossRoad1_Number);
- arrRoadSn[1].Format("%c%d",C2->m_CrossRoad2_Serial,C2->m_CrossRoad2_Number);
- arrRoadSn[2].Format("%c%d",C2->m_CrossRoad3_Serial,C2->m_CrossRoad3_Number);
- arrRoadSn[3].Format("%c%d",C2->m_CrossRoad4_Serial,C2->m_CrossRoad4_Number);
- for(i = 0; i < 4; i++) {
- if(IsInvalidSn(arrRoadSn[i])) continue;
- if(!RoadSnInCross(arrRoadSn[i],C1)) return false;
- }
- return true;
- }
- bool CGpsDrawMap::GetOneRoadPoint(CObList *RoadList,CString RoadSn,CGpsRoadStruct *DstRoad)
- {
- CGpsRoadStruct *pRoad;
- POSITION pos;
- CString TempSn;
- pos = RoadList->GetTailPosition();
- while(pos != NULL) {
- pRoad = (CGpsRoadStruct*)RoadList->GetPrev(pos);
- TempSn.Format("%c%d",pRoad->BigRoad_Serial,pRoad->m_BigRoad_Number);
- if(TempSn != RoadSn) continue;
- *DstRoad = *pRoad;
- return true;
- }
- return false;
- }
- bool CGpsDrawMap::RoadSnInCross(CString RoadSn,CGpsRoadCrossPoint *pCross)
- {
- CString TempSn;
- TempSn.Format("%c%d",pCross->m_CrossRoad1_Serial,pCross->m_CrossRoad1_Number);
- if(TempSn == RoadSn) return true;
- TempSn.Format("%c%d",pCross->m_CrossRoad2_Serial,pCross->m_CrossRoad2_Number);
- if(TempSn == RoadSn) return true;
- TempSn.Format("%c%d",pCross->m_CrossRoad3_Serial,pCross->m_CrossRoad3_Number);
- if(TempSn == RoadSn) return true;
- TempSn.Format("%c%d",pCross->m_CrossRoad4_Serial,pCross->m_CrossRoad4_Number);
- if(TempSn == RoadSn) return true;
- return false;
- }
- bool CGpsDrawMap::GetPointInListEx(CPoint point,CString RoadSn,CObList *CrossList,CGpsRoadCrossPoint *pPoint,BYTE Bound)
- {
- CGpsRoadCrossPoint *pGpsPoint;
- bool ret = false;
- POSITION pos;
- CString TempSn;
-
- pos = CrossList->GetHeadPosition();
-
- while(pos != NULL)
- {
- pGpsPoint = (CGpsRoadCrossPoint*)CrossList->GetNext(pos);
- TempSn.Format("%c%d",pGpsPoint->m_CrossRoad1_Serial,pGpsPoint->m_CrossRoad1_Number);
- if(TempSn != RoadSn) continue;
- if((abs(point.x - pGpsPoint->m_lx) < Bound) &&
- (abs(point.y - pGpsPoint->m_ly) < Bound)) { //捕获范围
- *pPoint = *pGpsPoint;
- ret = true;
- break;
- }
- }
- return ret;
- }
- bool CGpsDrawMap::GetOneBRCrossPoint(CPoint point,CObList *RoadList,CObList *CrossList,
- CString Sn,CBRCrossStruct *pDstCross,CObList *SavePoint)
- {
- CGpsRoadStruct *pRoad;
- CSmallRoadStruct *pSmall;
- CRoadPoint *pRoadPoint;
- CRoadPoint *pTempPoint;
- POSITION pos,pos1,pos2;
- CString RoadSn;
- CPoint Epoint;
- bool Result = false,Flag = false;
- pos = RoadList->GetTailPosition();
- while(pos != NULL) {
- pRoad = (CGpsRoadStruct*)RoadList->GetPrev(pos);
- RoadSn.Format("%c%d",pRoad->BigRoad_Serial,pRoad->m_BigRoad_Number);
- // if(RoadSn != Sn) continue;
- pos1 = pRoad->SmallRoadList.GetTailPosition();
- while(pos1 != NULL) {
- pSmall = (CSmallRoadStruct*)pRoad->SmallRoadList.GetPrev(pos1);
- pos2 = pSmall->RoadPointList.GetTailPosition();
- while(pos2 != NULL) {
- pRoadPoint = (CRoadPoint*)pSmall->RoadPointList.GetPrev(pos2);
- if((abs(pRoadPoint->m_lx - point.x) < m_PointWidth * 10) &&
- (abs(pRoadPoint->m_ly - point.y) < m_PointWidth * 10)) {
- Flag = true;
- }
- if(!Flag) continue;
- pTempPoint = new CRoadPoint;
- pTempPoint->m_lx = pRoadPoint->m_lx;
- pTempPoint->m_ly = pRoadPoint->m_ly;
- SavePoint->AddHead(pTempPoint);
- if((pRoadPoint->OutOfMap == 3) ||
- (pRoadPoint->OutOfMap == 6) ||
- (pRoadPoint->OutOfMap == 8)) {
- Epoint.x = pRoadPoint->m_lx; Epoint.y = pRoadPoint->m_ly;
- Result = GetPointInListEx(Epoint,RoadSn,CrossList,&pDstCross->m_cCross,1);
- if(Result) return true;
- }
- }
- }
- if(Flag) break;
- }
- return Result;
- }
- long CGpsDrawMap::CalcCrossVectorDist(CGpsRoadCrossPoint *StartPoint,CGpsRoadCrossPoint *EndPoint,
- CObList *RoadList)
- {
- CString arrRoadSn[4];
- long Dist;
- BYTE i;
- arrRoadSn[0].Format("%c%d",StartPoint->m_CrossRoad1_Serial,StartPoint->m_CrossRoad1_Number);
- arrRoadSn[1].Format("%c%d",StartPoint->m_CrossRoad2_Serial,StartPoint->m_CrossRoad2_Number);
- arrRoadSn[2].Format("%c%d",StartPoint->m_CrossRoad3_Serial,StartPoint->m_CrossRoad3_Number);
- arrRoadSn[3].Format("%c%d",StartPoint->m_CrossRoad4_Serial,StartPoint->m_CrossRoad4_Number);
- for(i = 0; i < 4; i++) {
- if(IsInvalidSn(arrRoadSn[i])) continue;
- Dist = CalcCrossDistInRoadSn(StartPoint,EndPoint,RoadList,arrRoadSn[i]);
- if(Dist != GPS_INFINITE) return Dist;
- }
- return GPS_INFINITE;
- }
- long CGpsDrawMap::CalcCrossDistInRoadSn(CGpsRoadCrossPoint *StartPoint,CGpsRoadCrossPoint *EndPoint,
- CObList *RoadList,CString RoadSn)
- {
- BYTE RoadDir,i;
- long Dist;
- if(!RoadSnInCross(RoadSn,StartPoint) || !RoadSnInCross(RoadSn,EndPoint)) return GPS_INFINITE;
- if(SimilarCross(StartPoint,EndPoint)) return GPS_INFINITE;
- if((StartPoint->m_lx == EndPoint->m_lx) &&
- (StartPoint->m_ly == EndPoint->m_ly)) {
- return 0;
- }
- CGpsRoadStruct DstRoad;
- CSmallRoadStruct *pSmall;
- CRoadPoint *pRoadPoint,*pPoint;
- CObList TempPointList;
- POSITION pos1,pos2;
- short StartPos = -1,EndPos = -1,Pos = 1;
- if(!GetOneRoadPoint(RoadList,RoadSn,&DstRoad)) return GPS_INFINITE;
- i = 0;
- pos1 = DstRoad.SmallRoadList.GetTailPosition();
- while(pos1 != NULL) {
- pSmall = (CSmallRoadStruct*)DstRoad.SmallRoadList.GetPrev(pos1);
- pos2 = pSmall->RoadPointList.GetTailPosition();
- RoadDir = pSmall->Road_SD;
- while(pos2 != NULL) {
- pRoadPoint = (CRoadPoint*)DstRoad.SmallRoadList.GetPrev(pos2);
- if((pRoadPoint->OutOfMap != 3) &&
- (pRoadPoint->OutOfMap != 6) &&
- (pRoadPoint->OutOfMap != 8)) continue;
- if((pRoadPoint->m_lx == StartPoint->m_lx) && (pRoadPoint->m_ly == StartPoint->m_ly)) {
- if(StartPos == -1) {
- pRoadPoint->m_bIsModify = true;
- StartPos = Pos;
- }
- }
- if((pRoadPoint->m_lx == EndPoint->m_lx) && (pRoadPoint->m_ly == EndPoint->m_ly)) {
- if(EndPos == -1) {
- pRoadPoint->m_bIsModify = true;
- EndPos = Pos;
- }
- }
- Pos++;
- }
- }
- if((StartPos == -1) || (EndPos == -1)) return GPS_INFINITE;
- if(RoadDir == 'S') {
- if(StartPos > EndPos) return GPS_INFINITE;
- }
- i = 0;
- pos1 = DstRoad.SmallRoadList.GetTailPosition();
- while(pos1 != NULL) {
- pSmall = (CSmallRoadStruct*)DstRoad.SmallRoadList.GetPrev(pos1);
- pos2 = pSmall->RoadPointList.GetTailPosition();
- while(pos2 != NULL) {
- pRoadPoint = (CRoadPoint*)DstRoad.SmallRoadList.GetPrev(pos2);
- if(pRoadPoint->m_bIsModify) i++;
- if(i == 1) {
- pPoint = new CRoadPoint;
- *pPoint = *pRoadPoint;
- TempPointList.AddHead(pPoint);
- }
- if(i >= 2) break;
- }
- if(i >= 2) break;
- }
- Dist = CalculateOneRoadVD(&TempPointList);
- m_cCurrMapInfo.ClearPointList(&TempPointList);
- return Dist;
- }
- long CGpsDrawMap::CalculateTwoPointDistance(CPoint PrevP,CPoint CurrP)
- {
- long dx,dy,Distance;
- dx = abs(PrevP.x - CurrP.x);
- dy = abs(PrevP.y - CurrP.y);
- Distance = (long)sqrt(Square(dx) + Square(dy));
- return Distance;
- }
- long CGpsDrawMap::CalculateOneRoadVD(CObList *PlainList)
- {
- CRoadPoint *pRoadPoint;
- POSITION pos;
- CPoint PrevP,CurrP;
- long Distance = 0;
- bool Flag = false;
- pos = PlainList->GetTailPosition();
- while(pos != NULL) {
- pRoadPoint = (CRoadPoint*)PlainList->GetPrev(pos);
- CurrP.x = pRoadPoint->m_lx; CurrP.y = pRoadPoint->m_ly;
- if(Flag) {
- Distance += CalculateTwoPointDistance(PrevP,CurrP);
- // Distance += CalculateDist(PrevP,CurrP);
- }
- else {
- Flag = true;
- }
- PrevP = CurrP;
- }
- if(!Flag) Distance = GPS_INFINITE;
- if(PlainList->GetCount() == 1) Distance = GPS_INFINITE;
- return Distance;
- }
- bool CGpsDrawMap::SaveInitBRCross(CObList *CrossList,CObList *DstList)
- {
- CGpsRoadCrossPoint *pCross;
- CBRCrossStruct *pBRCross,*pSave;
- POSITION pos,pos1;
- bool Flag;
- pos = CrossList->GetTailPosition();
- while(pos != NULL) {
- pCross = (CGpsRoadCrossPoint*)CrossList->GetPrev(pos);
- pos1 = DstList->GetTailPosition();
- if(pos1 == NULL) {
- pSave = new CBRCrossStruct;
- pSave->m_cCross = *pCross;
- // pSave->m_Adjust = 2;
- // pSave->m_Distance = GPS_INFINITE;
- // pSave->m_Double = 0;
- DstList->AddHead(pSave);
- continue;
- }
- Flag = false;
- while(pos1 != NULL) {
- pBRCross = (CBRCrossStruct*)DstList->GetPrev(pos1);
- if(SimilarCross(&pBRCross->m_cCross,pCross)) {
- pBRCross->m_Double = 1;
- break;
- Flag = true;
- }
- }
- if(!Flag) {
- pSave = new CBRCrossStruct;
- pSave->m_cCross = *pCross;
- // pSave->m_Adjust = 2;
- // pSave->m_Distance = GPS_INFINITE;
- // pSave->m_Double = 0;
- DstList->AddHead(pSave);
- }
- }
- if(DstList->GetCount() != 0) return true;
- return false;
- }
- bool CGpsDrawMap::GetMinDistPoint(CObList *CrossList,CBRCrossStruct *MinCross)
- {
- CBRCrossStruct *pBRCross,*pMin;
- POSITION pos;
- long Distance = GPS_INFINITE;
- pos = CrossList->GetTailPosition();
- while(pos != NULL) {
- pBRCross = (CBRCrossStruct*)CrossList->GetPrev(pos);
- if(pBRCross->m_Adjust != 1) continue;
- if(Distance > pBRCross->m_Distance) {
- *MinCross = *pBRCross;
- pMin = pBRCross;
- Distance = pBRCross->m_Distance;
- }
- }
- if(Distance == GPS_INFINITE) return false;
- pMin->m_Adjust = 0;
- return true;
- }
- bool CGpsDrawMap::CheckCrossSame(CGpsRoadCrossPoint *pC1,CGpsRoadCrossPoint *pC2)
- {
- bool Flag = false;
- if( (pC1->m_CrossRoad1_Serial == pC2->m_CrossRoad1_Serial) &&
- (pC1->m_CrossRoad1_Number == pC2->m_CrossRoad1_Number) &&
- // (pC1->CrossRoad1_Level == pC2->CrossRoad2_Level) &&
- (pC1->m_CrossRoad2_Serial == pC2->m_CrossRoad2_Serial) &&
- (pC1->m_CrossRoad2_Number == pC2->m_CrossRoad2_Number) &&
- // (pC1->CrossRoad2_Level == pC2->CrossRoad2_Level) &&
- (pC1->m_CrossRoad3_Serial == pC2->m_CrossRoad3_Serial) &&
- (pC1->m_CrossRoad3_Number == pC2->m_CrossRoad3_Number) &&
- // (pC1->CrossRoad3_Level == pC2->CrossRoad3_Level) &&
- (pC1->m_CrossRoad4_Serial == pC2->m_CrossRoad4_Serial) &&
- (pC1->m_CrossRoad4_Number == pC2->m_CrossRoad4_Number) &&
- // (pC1->CrossRoad4_Level == pC2->CrossRoad4_Level) &&
- (pC1->m_lx == pC2->m_lx) && (pC1->m_ly == pC2->m_ly)) {
- Flag = true;
- }
- return Flag;
- }
- bool CGpsDrawMap::HaveSaveOneRoadSn(CGpsRoadCrossPoint *pCross1,CGpsRoadCrossPoint *pCross2)
- {
- CString arrRoadSn[4];
- BYTE i;
- arrRoadSn[0].Format("%c%d",pCross1->m_CrossRoad1_Serial,pCross1->m_CrossRoad1_Number);
- arrRoadSn[1].Format("%c%d",pCross1->m_CrossRoad2_Serial,pCross1->m_CrossRoad2_Number);
- arrRoadSn[2].Format("%c%d",pCross1->m_CrossRoad3_Serial,pCross1->m_CrossRoad3_Number);
- arrRoadSn[3].Format("%c%d",pCross1->m_CrossRoad4_Serial,pCross1->m_CrossRoad4_Number);
- for(i = 0; i < 4; i++) {
- if(IsInvalidSn(arrRoadSn[i])) continue;
- if(RoadSnInCross(arrRoadSn[i],pCross2)) return true;
- }
- return false;
- }
- bool CGpsDrawMap::BRCrossInList(CBRCrossStruct *pBRCross,CObList *CrossList)
- {
- CBRCrossStruct *pCross;
- POSITION pos;
- pos = CrossList->GetTailPosition();
- while(pos != NULL) {
- pCross = (CBRCrossStruct*)CrossList->GetPrev(pos);
- if(SimilarCross(&pBRCross->m_cCross,&pCross->m_cCross)) {
- return true;
- }
- }
- return false;
- }
- short CGpsDrawMap::BR_SaveOnePath(CGpsRoadCrossPoint *StartPoint,
- CGpsRoadCrossPoint *EndPoint,
- CObList *RoadList,CObList *CrossList,CObList *SavePathList)
- {
- CBRCrossStruct cMinCross,*pBRCross,*pSave,SimilarEnd;
- CBRCrossStruct *pTempCross;
- POSITION pos;
- long Distance,RecordTimes = 0;
- CObList TempCrossList;
- short PathLen = 0;
- bool Flag = false,Flag1 = false;
- if(CheckCrossSame(StartPoint,EndPoint)) return 0;
- if(!SaveInitBRCross(CrossList,&TempCrossList)) return 0;
- pos = TempCrossList.GetTailPosition();
- while(pos != NULL) {
- pBRCross = (CBRCrossStruct*)TempCrossList.GetPrev(pos);
- if(SimilarCross(&pBRCross->m_cCross,StartPoint)) {
- pBRCross->m_Adjust = 1;
- pBRCross->m_Distance = 0;
- Flag = true;
- }
- if(!Flag1) {
- if(SimilarCross(&pBRCross->m_cCross,EndPoint)) {
- SimilarEnd = *pBRCross;
- Flag1 = true;
- }
- }
- if(Flag && Flag1) break;
- }
- if((!Flag) || (!Flag1)) {
- m_cCurrMapInfo.ClearBRoadSaveList(&TempCrossList);
- return 0;
- }
- while(true) {
- cMinCross.Clear();
- if(!GetMinDistPoint(&TempCrossList,&cMinCross)) {
- m_cCurrMapInfo.ClearBRoadSaveList(&TempCrossList);
- return 0;
- }
- if(SimilarCross(&cMinCross.m_cCross,&SimilarEnd.m_cCross)) {
- // if(CheckCrossSame(&cMinCross.m_cCross,&SimilarEnd.m_cCross)) {
- break;
- }
- Distance = GPS_INFINITE;
- pos = TempCrossList.GetTailPosition();
- while(pos != NULL) {
- pBRCross = (CBRCrossStruct*)TempCrossList.GetPrev(pos);
- if(pBRCross->m_Adjust == 0) {
- continue;
- }
- Distance = CalcCrossVectorDist(&cMinCross.m_cCross,
- &pBRCross->m_cCross,RoadList);
- if(Distance == GPS_INFINITE) continue;
- if(cMinCross.m_Distance + Distance < pBRCross->m_Distance) {
- pBRCross->m_Distance = cMinCross.m_Distance + Distance;
- pBRCross->m_Adjust = 1;
- }
- }
- RecordTimes++;
- if(RecordTimes > TempCrossList.GetCount() * 2) {
- break;
- }
- }
-
- PathLen = 0;
- pos = TempCrossList.GetTailPosition();
- while(pos != NULL) {
- pBRCross = (CBRCrossStruct*)TempCrossList.GetPrev(pos);
- // if(CheckCrossSame(&pBRCross->m_cCross,&SimilarEnd.m_cCross) &&
- if(SimilarCross(&pBRCross->m_cCross,&SimilarEnd.m_cCross) &&
- (pBRCross->m_Distance != GPS_INFINITE)) {
- pSave = new CBRCrossStruct;
- *pSave = *pBRCross;
- SavePathList->AddHead(pSave);
- PathLen++;
- break;
- }
- }
- if(PathLen == 0) {
- m_cCurrMapInfo.ClearBRoadSaveList(&TempCrossList);
- return 0;
- }
- Distance = GPS_INFINITE;
- RecordTimes = 0;
- while(true) {
- // Distance = GPS_INFINITE;
- pSave = new CBRCrossStruct;
- pTempCross = (CBRCrossStruct*)SavePathList->GetHead();
- pos = TempCrossList.GetTailPosition();
- while(pos != NULL) {
- pBRCross = (CBRCrossStruct*)TempCrossList.GetPrev(pos);
- // if(BRCrossInList(pBRCross,SavePathList)) continue;
- if(pBRCross->m_Distance == GPS_INFINITE) continue;
- if(pBRCross->m_Adjust != 0) continue;
- if(HaveSaveOneRoadSn(&pBRCross->m_cCross,&pTempCross->m_cCross)) {
- if(pBRCross->m_Distance < Distance) {
- *pSave = *pBRCross;
- Distance = pBRCross->m_Distance;
- }
- }
- }
- if(Distance != GPS_INFINITE) {
- SavePathList->AddHead(pSave);
- PathLen++;
- if((pSave->m_cCross.m_lx == StartPoint->m_lx) &&
- (pSave->m_cCross.m_ly == StartPoint->m_ly)) {
- // if(SimilarCross(&pSave->m_cCross,StartPoint)) {
- break;
- }
- }
- else {
- delete pSave;
- }
- if(RecordTimes > TempCrossList.GetCount()) break;
- RecordTimes++;
- }
- if(RecordTimes > TempCrossList.GetCount()) {
- m_cCurrMapInfo.ClearBRoadSaveList(SavePathList);
- PathLen = 0;
- }
- m_cCurrMapInfo.ClearBRoadSaveList(&TempCrossList);
- return PathLen;
- }
- long CGpsDrawMap::alculateDist(CPoint SP,CPoint EP)
- {
- long dx,dy,min;
- dx = abs(SP.x - EP.x); dy = abs(SP.y - EP.y);
- min = Min(dx,dy);
- return (dx + dy - min / 2 - min / 4 + min / 8);
- }
- void CGpsDrawMap::WritePathToTxt(CObList *PathList)
- {
- CFile f;
- if(!f.Open("Path.txt",CFile::modeCreate | CFile::modeReadWrite,NULL)) return;
- CBRCrossStruct *pCross;
- POSITION pos;
- CString Str;
- short PointTotal;
- PointTotal = PathList->GetCount();
- Str.Format("共经过 %d 个交叉点: %c%c",PointTotal,'r','n');
- f.Write(Str,Str.GetLength());
- pos = PathList->GetHeadPosition();
- while(pos != NULL) {
- pCross = (CBRCrossStruct*)PathList->GetNext(pos);
- Str.Format("(%c%d,%c%d,%c%d,%c%d);(%d,%d);%d;%c%c",
- pCross->m_cCross.m_CrossRoad1_Serial,
- pCross->m_cCross.m_CrossRoad1_Number,
- pCross->m_cCross.m_CrossRoad2_Serial,
- pCross->m_cCross.m_CrossRoad2_Number,
- pCross->m_cCross.m_CrossRoad3_Serial,
- pCross->m_cCross.m_CrossRoad3_Number,
- pCross->m_cCross.m_CrossRoad4_Serial,
- pCross->m_cCross.m_CrossRoad4_Number,
- pCross->m_cCross.m_lx,pCross->m_cCross.m_ly,pCross->m_Distance,
- 'r','n');
- f.Write(Str,Str.GetLength());
- }
- f.Close();
- }
- void CGpsDrawMap::WriteBRcross(CBRCrossStruct *pBRCross,CString FileName)
- {
- CFile f;
- if(!f.Open(FileName,CFile::modeReadWrite,NULL)) {
- if(!f.Open(FileName,CFile::modeCreate | CFile::modeReadWrite,NULL)) {
- return;
- }
- }
- f.SeekToEnd();
- CString str;
- str.Format("(x=%d;y=%d:Dist=%d:Adjust=%d);(%c%d,%c%d,%c%d,%c%d)%c%c",
- pBRCross->m_cCross.m_lx,pBRCross->m_cCross.m_ly,
- pBRCross->m_Distance,pBRCross->m_Adjust,
- pBRCross->m_cCross.m_CrossRoad1_Serial,
- pBRCross->m_cCross.m_CrossRoad1_Number,
- pBRCross->m_cCross.m_CrossRoad2_Serial,
- pBRCross->m_cCross.m_CrossRoad2_Number,
- pBRCross->m_cCross.m_CrossRoad3_Serial,
- pBRCross->m_cCross.m_CrossRoad3_Number,
- pBRCross->m_cCross.m_CrossRoad4_Serial,
- pBRCross->m_cCross.m_CrossRoad4_Number,
- 'r','n');
- // AfxMessageBox(str);
- f.Write(str,str.GetLength());
- f.Close();
- }
- void CGpsDrawMap::WriteCross(CGpsRoadCrossPoint *pCross,CString FileName)
- {
- CFile f;
- if(!f.Open(FileName,CFile::modeReadWrite,NULL)) {
- if(!f.Open(FileName,CFile::modeCreate | CFile::modeReadWrite,NULL)) {
- return;
- }
- }
- f.SeekToEnd();
- CString str;
- str.Format("(x=%d;y=%d);(%c%d,%c%d,%c%d,%c%d)%c%c",
- pCross->m_lx,pCross->m_ly,
- pCross->m_CrossRoad1_Serial,
- pCross->m_CrossRoad1_Number,
- pCross->m_CrossRoad2_Serial,
- pCross->m_CrossRoad2_Number,
- pCross->m_CrossRoad3_Serial,
- pCross->m_CrossRoad3_Number,
- pCross->m_CrossRoad4_Serial,
- pCross->m_CrossRoad4_Number,
- 'r','n');
- // AfxMessageBox(str);
- f.Write(str,str.GetLength());
- f.Close();
- }
- void CGpsDrawMap::DrawBetweenBRCrossLine(CDC *pDC,CObList *SaveBRCrossList)
- {
- CBRCrossStruct *pCross,pPrevCross;
- CObList TempList;
- POSITION pos;
- CString RoadSn("");
- bool Flag = false;
- DrawLineEx(pDC,&mSaveTempList1);
- DrawLineEx(pDC,&mSaveTempList2);
- pos = SaveBRCrossList->GetHeadPosition();
- while(pos != NULL) {
- pCross = (CBRCrossStruct*)SaveBRCrossList->GetNext(pos);
- if(Flag) {
- DrawBetweenCross(&pPrevCross.m_cCross,&pCross->m_cCross,&m_cCurrMapInfo.lCurrRoadList,pDC);
- // if(!DrawBetweenCross(&pPrevCross.m_cCross,&pCross->m_cCross,&DispRoadList,pDC)) {
- // ClearBRoadSaveList(SaveBRCrossList);
- // return;
- // }
- }
- else {
- Flag = true;
- }
- pPrevCross = *pCross;
- }
- }
- bool CGpsDrawMap::DrawBetweenCross(CGpsRoadCrossPoint *pPrevCross,CGpsRoadCrossPoint *pCross,CObList *RoadList,CDC *pDC)
- {
- CObList DstList;
- CString RoadSn;
- RoadSn.Format("%c%d",pPrevCross->m_CrossRoad1_Serial,pPrevCross->m_CrossRoad1_Number);
- if(RoadSnInCross(RoadSn,pCross)) {
- if(GetOneRoadPlain(pPrevCross,pCross,RoadList,RoadSn,&DstList)) {
- DrawLineEx(pDC,&DstList);
- m_cCurrMapInfo.ClearPointList(&DstList);
- return true;
- }
- }
- RoadSn.Format("%c%d",pPrevCross->m_CrossRoad2_Serial,pPrevCross->m_CrossRoad2_Number);
- if(RoadSnInCross(RoadSn,pCross)) {
- if(GetOneRoadPlain(pPrevCross,pCross,RoadList,RoadSn,&DstList)) {
- DrawLineEx(pDC,&DstList);
- m_cCurrMapInfo.ClearPointList(&DstList);
- return true;
- }
- }
- RoadSn.Format("%c%d",pPrevCross->m_CrossRoad3_Serial,pPrevCross->m_CrossRoad3_Number);
- if(RoadSnInCross(RoadSn,pCross)) {
- if(GetOneRoadPlain(pPrevCross,pCross,RoadList,RoadSn,&DstList)) {
- DrawLineEx(pDC,&DstList);
- m_cCurrMapInfo.ClearPointList(&DstList);
- return true;
- }
- }
- RoadSn.Format("%c%d",pPrevCross->m_CrossRoad4_Serial,pPrevCross->m_CrossRoad4_Number);
- if(RoadSnInCross(RoadSn,pCross)) {
- if(GetOneRoadPlain(pPrevCross,pCross,RoadList,RoadSn,&DstList)) {
- DrawLineEx(pDC,&DstList);
- m_cCurrMapInfo.ClearPointList(&DstList);
- return true;
- }
- }
- return false;
- }
- void CGpsDrawMap::DrawLineEx(CDC *pDC,CObList *TempList)
- {
- CRoadPoint *pPoint;
- POSITION pos;
- CPoint point,point1;
- bool Flag = false;
- pos = TempList->GetHeadPosition();
- while(pos != NULL) {
- pPoint = (CRoadPoint*)TempList->GetNext(pos);
- point.x = pPoint->m_lx; point.y = pPoint->m_ly;
- if(Flag) {
- DrawLine(point1.x,point1.y,point.x,point.y,3,m_cColor.RoadColor[6],pDC);
- }
- else {
- Flag = true;
- }
- point1 = point;
- }
- }
- void CGpsDrawMap::CalculateBRroadPath(CPoint point)
- {
- CPoint cPoint;
- CString RoadSn;
- if(!gBRcross.m_bHaveSpoint) {
- if(!SearchSignByPoint(point,cPoint)) return;
- if(SearchRoad(point,RoadSn) == "") return;
- ClearPointList(&mSaveTempList1);
- if(GetOneBRCrossPoint(point,&m_cCurrMapInfo.lCurrRoadList,
- &m_cCurrMapInfo.lCurrCrossList,
- RoadSn,&gBRcross.m_StartCross,&mSaveTempList1)) {
- gBRcross.m_bHaveSpoint = true;
- AfxMessageBox("请选择目标点!");
- }
- }
- else {
- if(!SearchSignByPoint(point,cPoint)) return;
- if(SearchRoad(point,RoadSn) == "") return;
- ClearPointList(&mSaveTempList2);
- if(GetOneBRCrossPoint(point,&m_cCurrMapInfo.lCurrRoadList,
- &m_cCurrMapInfo.lCurrCrossList,
- RoadSn,&gBRcross.m_EndCross,&mSaveTempList2)) {
- m_cCurrMapInfo.ClearBRoadSaveList(&mSaveBRList);
- gBRcross.m_bEnable = true;
- ((CGpsSCView*)m_pCurrView)->StatusPrompt("正在计算路径,请稍等...",0);
- AfxGetApp()->BeginWaitCursor();
- short Len = BR_SaveOnePath(&gBRcross.m_StartCross.m_cCross,
- &gBRcross.m_EndCross.m_cCross,
- &m_cCurrMapInfo.lCurrRoadList,
- &m_cCurrMapInfo.lCurrCrossList,
- &mSaveBRList);
- if(Len <= 1) {
- AfxMessageBox("没有找到路径!");
- }
- else {
- // m_cDrawMap.WritePathToTxt(&mSaveBRList);
- CString Prompt;
- Prompt.Format("查找到路径!",Len);
- AfxMessageBox(Prompt);
- }
- AfxGetApp()->EndWaitCursor();
- ((CGpsSCView*)m_pCurrView)->Invalidate();
- }
- }
- }
- void CGpsDrawMap::DispShootPic(CDC *pDC,CPoint point,CString PicPath)
- {
- /*
- CPicture mPic;
- CRect cRect;
- CSize Size;
- if(mPic.Load(PicPath)) {
- Size = mPic.GetImageSize();
- cRect.top = point.y - Size.cy / 2;
- cRect.bottom = point.y + Size.cy / 2;
- cRect.left = point.x - Size.cx / 2;
- cRect.right = point.x + Size.cx / 2;
- mPic.Render(pDC,cRect);
- }
- */
- }
- bool CGpsDrawMap::SearchSignByPoint(CPoint point,CPoint &Ret)
- {
- CGpsSignObject *pSign = NULL;
- POSITION pos;
- pos = m_cCurrMapInfo.lCurrSignList.GetTailPosition();
- while(pos != NULL) {
- pSign = (CGpsSignObject*)m_cCurrMapInfo.lCurrSignList.GetPrev(pos);
- if((abs(pSign->m_lx - point.x) < m_PointWidth) &&
- (abs(pSign->m_ly - point.y) < m_PointWidth)) {
- Ret.x = pSign->m_lx;
- Ret.y = pSign->m_ly;
- return true;
- }
- }
- return false;
- }
- void CGpsDrawMap::GetCarXY(int &nx,int &ny)
- {
- CGpsPoint *pPoint = NULL;
- POSITION pos;
- pos = mSaveRecePointList.GetTailPosition();
- while(pos != NULL) {
- pPoint = (CGpsPoint*)mSaveRecePointList.GetPrev(pos);
- if(pPoint != NULL) {
- nx = pPoint->m_lx;
- ny = pPoint->m_ly;
- }
- }
- }
- bool CGpsDrawMap::CompanySimilarStr(CString Str1,CString Str2)
- {
- CString Temp;
- BYTE pos = 0;
- while(pos <= Str1.GetLength() - 4) {
- Temp = Str1.Mid(pos,4);
- if(Str2.Find(Temp,0) != -1) return true;
- pos += 2;
- }
- while(pos <= Str2.GetLength() - 4) {
- Temp = Str2.Mid(pos,4);
- if(Str1.Find(Temp,0) != -1) return true;
- pos += 2;
- }
- return false;
- }
- void CGpsDrawMap::SearchSignByInput()
- {
- CInputStringDlg input;
- input.m_sCaption = "请输入标志名称:";
- if(input.DoModal() == IDCANCEL) return;
- if(input.m_sString.IsEmpty()) return;
- CString arrSignName[100];
- int Count = 0;
- CGpsSignObject *pSign = NULL;
- POSITION pos;
- CString Name;
- pos = m_cCurrMapInfo.lCurrSignList.GetTailPosition();
- while(pos != NULL) {
- pSign = (CGpsSignObject*)m_cCurrMapInfo.lCurrSignList.GetPrev(pos);
- Name = pSign->m_pSignObjectName;
- if(CompanySimilarStr(Name, input.m_sString)) {
- arrSignName[Count++] = Name;
- }
- }
- if(Count == 0) return;
- CListSimilarStrDlg dlg(arrSignName,Count);
- dlg.m_sCaption = "相似标志物:";
- dlg.GetParent(this);
- dlg.DoModal();
- }
- void CGpsDrawMap::DrawSignByName(CString SignName)
- {
- CGpsSignObject *pSign = NULL;
- POSITION pos;
- CString Name;
- bool Flag = false;
- pos = m_cCurrMapInfo.lCurrSignList.GetTailPosition();
- while(pos != NULL) {
- pSign = (CGpsSignObject*)m_cCurrMapInfo.lCurrSignList.GetPrev(pos);
- Name = pSign->m_pSignObjectName;
- if(Name == SignName) {
- Flag = true;
- break;
- }
- }
- if(!Flag) return;
- CheckMapIsChange(pSign->m_dgx,pSign->m_dgy);
- RefreshMapWnd();
- CovertNEXY(pSign, m_cCurrMapInfo.CoeffNE_XY, true);
- pDispOneSign.m_lx = pSign->m_lx;
- pDispOneSign.m_ly = pSign->m_ly;
- pDispOneSign.m_dgx = pSign->m_dgx;
- pDispOneSign.m_dgy = pSign->m_dgy;
- pDispOneSign.m_sIconName = pSign->m_sIconName;
- CopyEquaLenArr(pSign->m_pSignObjectName,pDispOneSign.m_pSignObjectName,pSign->m_bySignName_Bytes);
- FreshWnd();
- }