GpsDrawMap.cpp
上传用户:yffx2008
上传日期:2014-10-12
资源大小:12414k
文件大小:97k
源码类别:

交通/航空行业

开发平台:

Visual C++

  1. // GpsDrawMap.cpp: implementation of the CGpsDrawMap class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "GpsSC.h"
  6. #include "GpsDrawMap.h"
  7. #include "SearchSignDlg.h"
  8. #include "ShowSignDlg.h"
  9. #include "InputStringDlg.h"
  10. #include "ListSimilarStrDlg.h"
  11. #include "GpsSCDoc.h"
  12. #include "GpsSCView.h"
  13. #include "math.h"
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char THIS_FILE[]=__FILE__;
  17. #define new DEBUG_NEW
  18. #endif
  19. #define Square(a) ((a) * (a))
  20. #define Max(a, b) ((a) > (b) ? (a) : (b))
  21. #define Min(a, b) ((a) > (b) ? (b) : (a))
  22. #define PI 3.1415927
  23. #define GPS_INFINITE 0x7fffff
  24. #define GPS_CAR_WIDTH_HEIGH 40
  25. #define CompanyIconName "\GpsIcon\GpsSign\Company.bmp"
  26. #define PlaceNameIconName "\GpsIcon\GpsSign\PlaceName.bmp"
  27. #define BuildingIconName "\GpsIcon\GpsSign\Building.bmp"
  28. #define TrafficIconName "\GpsIcon\GpsSign\Traffic.bmp"
  29. #define OilIconName "\GpsIcon\GpsSign\Oil.bmp"
  30. #define GovernmentIconName "\GpsIcon\GpsSign\Government.bmp"
  31. #define EducationIconName "\GpsIcon\GpsSign\edu.bmp"
  32. #define HotelIconName "\GpsIcon\GpsSign\Hotel.bmp"
  33. #define ShoppingIconName "\GpsIcon\GpsSign\Shopping.bmp"
  34. #define AmusementIconName "\GpsIcon\GpsSign\Amusement.bmp"
  35. #define ProjectIconName "\GpsIcon\GpsSign\finan.bmp"
  36. #define HospitalIconName "\GpsIcon\GpsSign\Hospital.bmp"
  37. //////////////////////////////////////////////////////////////////////
  38. // Construction/Destruction
  39. //////////////////////////////////////////////////////////////////////
  40. CGpsDrawMap::CGpsDrawMap()
  41. {
  42. InitDrawMap();
  43. }
  44. CGpsDrawMap::~CGpsDrawMap()
  45. {
  46. ClearMemberVar();
  47. }
  48. void CGpsDrawMap::ClearMemberVar()
  49. {
  50. if(FileContent != NULL) {
  51. delete [] FileContent;
  52. }
  53. m_cFatStruct.Clear();
  54. m_cCurrMapInfo.Clear();
  55. ClearLinkList(&mLinkList);
  56. ClearPointList(&mSaveRecePointList);
  57. m_cCurrMapInfo.ClearBRoadSaveList(&mSaveBRList);
  58. ClearPointList(&mSaveTempList1);
  59. ClearPointList(&mSaveTempList2);
  60. }
  61. void CGpsDrawMap::InitDrawMap()
  62. {
  63. m_cFatStruct.Clear();
  64. m_cCurrMapInfo.Clear();
  65. ClearLinkList(&mLinkList);
  66. ClearPointList(&mSaveRecePointList);
  67. long Ret;
  68. if(Ret = GetGpsFatBuf()) {
  69. GetGpsFatInfo();
  70. gCurrMapLevel = 6;
  71. m_PointWidth = 5;
  72. m_byZoomCoeffic = 1;
  73. GetLinkList(&mLinkList,gCurrMapLevel);
  74. gBRcross.m_bEnable = false;
  75. gBRcross.m_bHaveSpoint = false;
  76. gBRcross.m_EndCross.Clear();
  77. gBRcross.m_StartCross.Clear();
  78. GetAreaLibList(&m_cCurrMapInfo.lAreaLibList);
  79. }
  80. }
  81. void CGpsDrawMap::ClearStrArr(CString StrArr[],long Count)
  82. {
  83. long i;
  84. for(i = 0; i < Count; i++) {
  85. StrArr[i].Empty();
  86. }
  87. }
  88. long CGpsDrawMap::GetGpsFatBuf()
  89. {
  90. CString sPath;
  91. char CurrPath[500];
  92. CFile f;
  93. long FatLen = 0;
  94. ClearBYTEArr(CurrPath,500);
  95. ::GetCurrentDirectory(500,CurrPath);
  96. sPath = CurrPath;
  97. sPath  += "\Map\fat.fat";
  98. short Course = 0; //将不同角度的Car保存到数组中
  99. CString str;
  100. CString CarPath;
  101. CarPath  = CurrPath;
  102. CarPath += "\GpsIcon\GpsCar\Car";
  103. for(BYTE i = 0; i < 24; i++) {
  104. str.Format("%03d",Course);
  105. SaveGpsCarPath[i] = CarPath + str + ".bmp";
  106. Course    += 15;
  107. }
  108. if(!f.Open(sPath,CFile::modeRead,NULL)) {
  109. AfxMessageBox("打开地图出错,初始化画图系统失败!");
  110. FileContent = NULL;
  111. return FatLen;
  112. }
  113. f.SeekToBegin();
  114. FatLen = f.GetLength();
  115. FileContent = new BYTE[FatLen];
  116. f.Read(FileContent,FatLen);
  117. f.Close();
  118. return FatLen;
  119. }
  120. CString CGpsDrawMap::GetCurrDir()
  121. {
  122. CString sPath;
  123. char CurrPath[500];
  124. ClearBYTEArr(CurrPath,500);
  125. ::GetCurrentDirectory(500,CurrPath);
  126. return sPath = CurrPath;
  127. }
  128. bool CGpsDrawMap::ShowSignLib()
  129. {
  130. CShowSignDlg dlg;
  131. if(dlg.DoModal() == IDCANCEL) return false;
  132. m_ShowSign.bShowBuilding = dlg.m_byBuilding;
  133. m_ShowSign.bShowHotel = dlg.m_byHotel;
  134. m_ShowSign.bShowCompany = dlg.m_byCompany;
  135. m_ShowSign.bShowAmuse = dlg.m_byAmuse;
  136. m_ShowSign.bShowPlaceName = dlg.m_byPlaceName;
  137. m_ShowSign.bShowGovern = dlg.m_byGovern;
  138. m_ShowSign.bShowTraffic = dlg.m_byTraffic;
  139. m_ShowSign.bShowShopping = dlg.m_byShopping;
  140. m_ShowSign.bShowEducation = dlg.m_byEducation;
  141. m_ShowSign.bShowHospital = dlg.m_byHospital;
  142. m_ShowSign.bShowBureau = dlg.m_byBureau;
  143. m_ShowSign.bShowOil = dlg.m_byOil;
  144. return true;
  145. }
  146. void CGpsDrawMap::GetGpsFatInfo()
  147. {
  148. long BufPos = 0;
  149. m_cFatStruct.m_lLinkLibTotal = GetFourBNum(FileContent,BufPos); //链接库
  150. BufPos += LibTotalBytes;
  151. m_cFatStruct.m_lDataLibTotal = GetFourBNum(FileContent,BufPos); //数据库
  152. BufPos += LibTotalBytes;
  153. m_cFatStruct.m_lSignLibTotal = GetFourBNum(FileContent,BufPos); //标志库
  154. BufPos += LibTotalBytes;
  155. m_cFatStruct.m_lRegionLibTotal = GetFourBNum(FileContent,BufPos); //地区库
  156. BufPos += LibTotalBytes;
  157. m_cFatStruct.m_lRecordLibTotal = GetFourBNum(FileContent,BufPos); //记录库
  158. BufPos += LibTotalBytes;
  159. m_cFatStruct.m_lLinkLibAddr = BufPos;
  160. m_cFatStruct.m_lDataLibAddr = m_cFatStruct.m_lLinkLibAddr  + 
  161.   m_cFatStruct.m_lLinkLibTotal  * LibInfoBytes;
  162. m_cFatStruct.m_lSignLibAddr = m_cFatStruct.m_lDataLibAddr  + 
  163.   m_cFatStruct.m_lDataLibTotal  * LibInfoBytes;
  164. m_cFatStruct.m_lRegionLibAddr = m_cFatStruct.m_lSignLibAddr  + 
  165.   m_cFatStruct.m_lSignLibTotal  * LibInfoBytes;
  166. m_cFatStruct.m_lRecordLibAddr = m_cFatStruct.m_lRegionLibAddr  +
  167.   m_cFatStruct.m_lRegionLibTotal * LibInfoBytes;
  168. }
  169. /*************Get one NE of Point*************/
  170. void CGpsDrawMap::GetPointNE(BYTE *BUF,long *BufPos,double *gx,double *gy)
  171. {
  172. long tmp1;
  173. tmp1 = GetFourBNum(BUF,*BufPos);
  174. *gy = CovertNE(tmp1);
  175. *BufPos += GpsPointNEBytes;
  176. tmp1 = GetFourBNum(BUF,*BufPos);
  177. *gx = CovertNE(tmp1);
  178. *BufPos += GpsPointNEBytes;
  179. }
  180. /*************Get a long number of four bytes*************/
  181. long CGpsDrawMap::GetFourBNum(BYTE *BUF,long BufPos)
  182. {
  183. long RetLong;
  184. RetLong = BUF[BufPos + 0]  + (BUF[BufPos + 1]  + BUF[BufPos + 2]  * 256 + BUF[BufPos + 3]  * 65536) * 256;
  185. return RetLong;
  186. }
  187. short CGpsDrawMap::GetTwoBNum(BYTE *BUF,long BufPos)
  188. {
  189. short RetShort;
  190. RetShort = BUF[BufPos + 0]  + BUF[BufPos + 1] * 256;
  191. return RetShort;
  192. }
  193. BYTE CGpsDrawMap::GetOneBNum(BYTE *BUF,long BufPos)
  194. {
  195. BYTE RetByte;
  196. RetByte = BUF[BufPos];
  197. return RetByte;
  198. }
  199. void CGpsDrawMap::GetLenArray(BYTE *pTarget,BYTE Len,BYTE *Buf,long BufPos)
  200. {
  201. BYTE i;
  202. for(i = 0; i < Len; i++) {
  203. pTarget[i] = Buf[BufPos++];
  204. }
  205. }
  206. void CGpsDrawMap::ClearBYTEArr(char Array[],long ArrLen)
  207. {
  208. long i;
  209. for(i = 0; i < ArrLen; i++) {
  210. Array[i] = 0;
  211. }
  212. }
  213. void CGpsDrawMap::CopyStr2Arr(CString Str,char *Arr,BYTE ArrLen)
  214. {
  215. BYTE i;
  216. for(i = 0;i < Str.GetLength(); i++) {
  217. Arr[i] = Str.GetAt(i);
  218. if(i == ArrLen) break;
  219. }
  220. }
  221. void CGpsDrawMap::CopyEquaLenArr(char *SrcArr,char *DstArr,BYTE CpyLen)
  222. {
  223. BYTE i;
  224. for(i = 0; i < CpyLen; i++) {
  225. DstArr[i] = SrcArr[i];
  226. }
  227. }
  228. BYTE CGpsDrawMap::CompareTwoArr(char *pArr1,char *pArr2)
  229. {
  230. CString Str1(pArr1),Str2(pArr2);
  231. BYTE Ret = 3;
  232. Str1.MakeUpper();
  233. Str2.MakeUpper();
  234. if((Str1 == Str2) && (!Str1.IsEmpty()) && (!Str2.IsEmpty())) return Ret = 1;
  235. if(Str1  > Str2) return Ret = 2;
  236. if(Str1  < Str2) return Ret = 0;
  237. return Ret;
  238. }
  239. /*************From XY to NE or From NE to XY*************/
  240. void CGpsDrawMap::CovertNEXY(CGpsPoint * cmpoint, ChangeNormal change, bool NE2XY)
  241. {
  242. #if 0
  243. if (NE2XY) {
  244. cmpoint->m_lx = (long)(change.a11 * cmpoint->m_dgx +
  245.  change.a12 * cmpoint->m_dgy + change.dx);
  246. cmpoint->m_ly = (long)(change.a21 * cmpoint->m_dgx +
  247.  change.a22 * cmpoint->m_dgy + change.dy);
  248.     }
  249.     else {
  250. cmpoint->m_dgx = change.a11 * cmpoint->m_lx +
  251.   change.a12 * cmpoint->m_ly + change.dx;
  252. cmpoint->m_dgy = change.a21 * cmpoint->m_lx +
  253.   change.a22 * cmpoint->m_ly + change.dy;
  254.     }
  255. #else
  256. long lTemp;
  257. double x,y,dTemp;
  258.     if (NE2XY) {
  259. lTemp = (long)cmpoint->m_dgx   / 100;
  260. dTemp = cmpoint->m_dgx - lTemp * 40;
  261. x = dTemp;
  262. lTemp = (long)cmpoint->m_dgy   / 100;
  263. dTemp = cmpoint->m_dgy - lTemp * 40;
  264. y = dTemp;
  265. cmpoint->m_lx = (long)(change.a11 * x + change.a12 * y + change.dx);
  266. cmpoint->m_ly = (long)(change.a21 * x + change.a22 * y + change.dy);
  267.     }
  268.     else {
  269. x = cmpoint->m_lx;
  270. y = cmpoint->m_ly;
  271. dTemp = change.a11 * x + change.a12 * y + change.dx;
  272. lTemp = (long)dTemp   / 60;
  273. cmpoint->m_dgx = dTemp + lTemp * 40;
  274. dTemp = change.a21 * x + change.a22 * y + change.dy;
  275. lTemp = (long)dTemp   / 60;
  276. cmpoint->m_dgy = dTemp + lTemp * 40;
  277.     }
  278. #endif
  279. }
  280. void CGpsDrawMap::CalculateCoeffNEXY(ChangeTriangle Triangle1,ChangeTriangle Triangle2,ChangeNormal *Change)
  281. {
  282. #if 0
  283. double tmp1,tmp2;
  284. tmp1 = (Triangle2.x2 - Triangle2.x1) * (Triangle2.y3 - Triangle2.y1) - 
  285.    (Triangle2.x3 - Triangle2.x1) * (Triangle2.y2 - Triangle2.y1);
  286.      
  287. tmp2 = (Triangle1.x2 - Triangle1.x1) * (Triangle2.y3 - Triangle2.y1) - 
  288.    (Triangle1.x3 - Triangle1.x1) * (Triangle2.y2 - Triangle2.y1);
  289. Change->a11 = tmp2 / tmp1;
  290. tmp2 = (Triangle2.x2 - Triangle2.x1) * (Triangle1.x3 - Triangle1.x1) - 
  291.    (Triangle2.x3 - Triangle2.x1) * (Triangle1.x2 - Triangle1.x1);
  292. Change->a12 = tmp2 / tmp1;
  293. tmp2 = (Triangle1.y2 - Triangle1.y1) * (Triangle2.y3 - Triangle2.y1) - 
  294.    (Triangle1.y3 - Triangle1.y1) * (Triangle2.y2 - Triangle2.y1);
  295. Change->a21 = tmp2 / tmp1;
  296. tmp2 = (Triangle2.x2 - Triangle2.x1) * (Triangle1.y3 - Triangle1.y1) - 
  297.    (Triangle2.x3 - Triangle2.x1) * (Triangle1.y2 - Triangle1.y1);
  298. Change->a22 = tmp2 / tmp1;
  299. Change->dx = Triangle1.x1 - Change->a11 * Triangle2.x1 - 
  300. Change->a12 * Triangle2.y1;
  301. Change->dy = Triangle1.y1 - Change->a21 * Triangle2.x1 - 
  302. Change->a22 * Triangle2.y1;
  303. #else
  304. double tmp1,tmp2;
  305. tmp1 = (Triangle2.x2 - Triangle2.x1) * (Triangle2.y3 - Triangle2.y1) - 
  306.    (Triangle2.x3 - Triangle2.x1) * (Triangle2.y2 - Triangle2.y1);
  307.      
  308. tmp2 = (Triangle1.x2 - Triangle1.x1) * (Triangle2.y3 - Triangle2.y1) - 
  309.    (Triangle1.x3 - Triangle1.x1) * (Triangle2.y2 - Triangle2.y1);
  310. Change->a11 = tmp2 / tmp1;
  311. tmp2 = (Triangle2.x2 - Triangle2.x1) * (Triangle1.x3 - Triangle1.x1) - 
  312.    (Triangle2.x3 - Triangle2.x1) * (Triangle1.x2 - Triangle1.x1);
  313. Change->a12 = tmp2 / tmp1;
  314. tmp2 = (Triangle1.y2 - Triangle1.y1) * (Triangle2.y3 - Triangle2.y1) - 
  315.    (Triangle1.y3 - Triangle1.y1) * (Triangle2.y2 - Triangle2.y1);
  316. Change->a21 = tmp2 / tmp1;
  317. tmp2 = (Triangle2.x2 - Triangle2.x1) * (Triangle1.y3 - Triangle1.y1) - 
  318.    (Triangle2.x3 - Triangle2.x1) * (Triangle1.y2 - Triangle1.y1);
  319. Change->a22 = tmp2 / tmp1;
  320. Change->dx = Triangle1.x1 - Change->a11 * Triangle2.x1 - 
  321. Change->a12 * Triangle2.y1;
  322. Change->dy = Triangle1.y1 - Change->a21 * Triangle2.x1 - 
  323. Change->a22 * Triangle2.y1;
  324. #endif
  325. }
  326. void CGpsDrawMap::RefreshMapWnd()
  327. {
  328. ChangeTriangle triangle;
  329. ChangeNormal TmpTri;
  330. CRect lpRect;
  331. ((CGpsSCView*)m_pCurrView)->GetClientRect(lpRect);
  332. if((m_cCurrMapInfo.m_lWnd_Max_X == 0) || (m_cCurrMapInfo.m_lWnd_Max_Y == 0)) {
  333. lpRect.right *= m_byZoomCoeffic;
  334. lpRect.bottom *= m_byZoomCoeffic;
  335. m_cCurrMapInfo.m_lWnd_Max_X = lpRect.right;
  336. m_cCurrMapInfo.m_lWnd_Max_Y = lpRect.bottom;
  337. ((CGpsSCView*)m_pCurrView)->SetScrollSizes(MM_TEXT, CSize(m_cCurrMapInfo.m_lWnd_Max_X, m_cCurrMapInfo.m_lWnd_Max_Y));
  338. }
  339. else {
  340. lpRect.right = m_cCurrMapInfo.m_lWnd_Max_X;
  341. lpRect.bottom = m_cCurrMapInfo.m_lWnd_Max_Y;
  342. }
  343. m_cCurrMapInfo.m_WndTriangle.x1 = lpRect.left;
  344. m_cCurrMapInfo.m_WndTriangle.y1 = lpRect.top;
  345. m_cCurrMapInfo.m_WndTriangle.x2 = lpRect.left;
  346. m_cCurrMapInfo.m_WndTriangle.y2 = lpRect.bottom;
  347. m_cCurrMapInfo.m_WndTriangle.x3 = lpRect.right;
  348. m_cCurrMapInfo.m_WndTriangle.y3 = lpRect.bottom;
  349. #if 1
  350. triangle =  m_cCurrMapInfo.m_MapTriangle;
  351. long iTemp;
  352. iTemp = (long)(m_cCurrMapInfo.m_MapTriangle.x1 / 100);
  353. m_cCurrMapInfo.m_MapTriangle.x1 = m_cCurrMapInfo.m_MapTriangle.x1 - iTemp * 40;
  354. iTemp = (long)(m_cCurrMapInfo.m_MapTriangle.x2 / 100);
  355. m_cCurrMapInfo.m_MapTriangle.x2 = m_cCurrMapInfo.m_MapTriangle.x2 - iTemp * 40;
  356. iTemp = (long)(m_cCurrMapInfo.m_MapTriangle.x3 / 100);
  357. m_cCurrMapInfo.m_MapTriangle.x3 = m_cCurrMapInfo.m_MapTriangle.x3 - iTemp * 40;
  358. iTemp = (long)(m_cCurrMapInfo.m_MapTriangle.y1 / 100);
  359. m_cCurrMapInfo.m_MapTriangle.y1 = m_cCurrMapInfo.m_MapTriangle.y1 - iTemp * 40;
  360. iTemp = (long)(m_cCurrMapInfo.m_MapTriangle.y2 / 100);
  361. m_cCurrMapInfo.m_MapTriangle.y2 = m_cCurrMapInfo.m_MapTriangle.y2 - iTemp * 40;
  362. iTemp = (long)(m_cCurrMapInfo.m_MapTriangle.y3 / 100);
  363. m_cCurrMapInfo.m_MapTriangle.y3 = m_cCurrMapInfo.m_MapTriangle.y3 - iTemp * 40;
  364. #endif
  365. CalculateCoeffNEXY(m_cCurrMapInfo.m_WndTriangle,m_cCurrMapInfo.m_MapTriangle,&TmpTri);
  366. m_cCurrMapInfo.CoeffNE_XY = TmpTri;
  367. CalculateCoeffNEXY(m_cCurrMapInfo.m_MapTriangle,m_cCurrMapInfo.m_WndTriangle,&TmpTri);
  368. m_cCurrMapInfo.CoeffXY_NE = TmpTri;
  369. m_cCurrMapInfo.m_MapTriangle = triangle;
  370. }
  371. void CGpsDrawMap::GetCurrMapInfo(CGpsLinkStruct *pLinkStruct,CCurrMapInfo *MapInfo)
  372. {
  373. CopyEquaLenArr(pLinkStruct->m_LinkLibName,MapInfo->m_LinkFileName,pLinkStruct->m_LinkLibName_Bytes);
  374. CopyEquaLenArr(pLinkStruct->m_RelatedSignLibName,MapInfo->m_SignFileName,pLinkStruct->m_SignLibName_Bytes);
  375. MapInfo->LinkName2DataLib(MapInfo->m_LinkFileName,MapInfo->m_DataFileName);
  376. MapInfo->m_MapTriangle = pLinkStruct->m_MapTri;
  377. }
  378. long CGpsDrawMap::GetDataLibAddr(char *DataLibName)
  379. {
  380. long InfoAddr,DataStartAddr,DataEndAddr,i,RetAddr = -1;
  381. char DataFileName[GpsLibFileLen + 1];
  382. InfoAddr = m_cFatStruct.m_lDataLibAddr;
  383. for(i = 0; i < m_cFatStruct.m_lDataLibTotal; i++) {
  384. ClearBYTEArr(DataFileName,GpsLibFileLen + 1);
  385. GetLibInfo(FileContent,InfoAddr,DataFileName,&DataStartAddr,&DataEndAddr);
  386. InfoAddr += LibInfoBytes; //链接库在FAT表中占用的字节数
  387. if(CompareTwoArr(DataFileName,DataLibName) == 1) {
  388. RetAddr = DataStartAddr;
  389. break;
  390. }
  391. }
  392. return RetAddr;
  393. }
  394. bool CGpsDrawMap::GetDataLib(char *DataLibName)
  395. {
  396. long DataLibStart;
  397. DataLibStart = GetDataLibAddr(DataLibName);
  398. if(DataLibStart == -1) return false;
  399. m_cCurrMapInfo.ClearColorBList();
  400. DataLibStart = GetColorBList(&m_cCurrMapInfo.lCurrColorBList,DataLibStart);
  401. m_cCurrMapInfo.ClearRoadList(m_cCurrMapInfo.lCurrRoadList);
  402. DataLibStart = GetRoadPlainPoint(&m_cCurrMapInfo.lCurrRoadList,DataLibStart);
  403. m_cCurrMapInfo.ClearCrossList();
  404. GetRoadCrossPoint(&m_cCurrMapInfo.lCurrCrossList,DataLibStart);
  405. return true;
  406. }
  407. long CGpsDrawMap::GetColorBList(CObList *ColorBList,long StartAddr)
  408. {
  409. CGpsColorBlock *pBlock;
  410. CGpsColorBlock cBlock;
  411. CGpsPoint *pPoint;
  412. short i,j;
  413. StartAddr += ColorBTotalBytes;
  414. cBlock.m_ColorBlockTotal = GetTwoBNum(FileContent,StartAddr);
  415. StartAddr += cBlock.m_ColorBlock_Bytes;
  416. for(i = 0; i < cBlock.m_ColorBlockTotal; i++) {
  417. pBlock = new CGpsColorBlock;
  418. ColorBList->AddHead(pBlock);
  419. pBlock->m_ColorBlockTotal = cBlock.m_ColorBlockTotal;
  420. pBlock->m_ColorValue = GetTwoBNum(FileContent,StartAddr);
  421. StartAddr += cBlock.m_ColorValue_Bytes;
  422. pBlock->m_ColorBlock_PointTotal = GetTwoBNum(FileContent,StartAddr);
  423. StartAddr += cBlock.m_ColorBlock_PointTotal_Bytes;
  424. for(j = 0; j < pBlock->m_ColorBlock_PointTotal; j++) {
  425. pPoint = new CGpsPoint;
  426. pBlock->ColorBlockPointList.AddHead(pPoint);
  427. GetPointNE(FileContent,&StartAddr,&pPoint->m_dgx,&pPoint->m_dgy);
  428. CovertNEXY(pPoint, m_cCurrMapInfo.CoeffNE_XY, true);
  429. }
  430. }
  431. return StartAddr;
  432. }
  433. long CGpsDrawMap::GetRoadPlainPoint(CObList *RoadList,long BufPos)
  434. {
  435. CSmallRoadStruct *pSmallRoad;
  436. CGpsRoadStruct *pRoad;
  437. CRoadPoint *pRoadPoint;
  438. long RoadTotal,i,j,k;
  439. BYTE DispLevel;
  440. RoadTotal = GetFourBNum(FileContent,BufPos);
  441. BufPos += LibTotalBytes;
  442. for(i = 0; i < RoadTotal; i++) {
  443. pRoad = new CGpsRoadStruct;
  444. RoadList->AddHead(pRoad);
  445. pRoad->BigRoad_Serial = GetOneBNum(FileContent,BufPos);
  446. BufPos += pRoad->BigRoad_SN_Bytes;
  447. pRoad->m_BigRoad_Number = GetTwoBNum(FileContent,BufPos);
  448. BufPos += pRoad->m_byBigRoad_Number_Bytes;
  449. pRoad->SmallRoadTotal = GetOneBNum(FileContent,BufPos);
  450. BufPos += pRoad->SmallRoadTotal_Bytes;
  451. pRoad->m_byIsHelpRoad = GetOneBNum(FileContent,BufPos);
  452. BufPos += pRoad->m_byHelpRoad_Bytes;
  453. for(j = 0; j < pRoad->SmallRoadTotal; j++) {
  454. pSmallRoad = new CSmallRoadStruct;
  455. pRoad->SmallRoadList.AddHead(pSmallRoad);
  456. GetLenArray(pSmallRoad->SmallRoad_SerialNumber,pSmallRoad->SmallRoad_SN_Bytes,FileContent,BufPos);
  457. BufPos += pSmallRoad->SmallRoad_SN_Bytes;
  458. GetLenArray((BYTE*)pSmallRoad->RoadName,pSmallRoad->RoadName_Bytes,FileContent,BufPos);
  459. BufPos += pSmallRoad->RoadName_Bytes;
  460. pSmallRoad->Road_SD = GetOneBNum(FileContent,BufPos);
  461. BufPos += pSmallRoad->Road_SD_Bytes;
  462. DispLevel = GetOneBNum(FileContent,BufPos);
  463. pSmallRoad->RoadorName_DispLevel = GetOneBNum(FileContent,BufPos);
  464. BufPos += pSmallRoad->DispLevel_Bytes;
  465. pSmallRoad->SmallRoad_PointTotal = GetTwoBNum(FileContent,BufPos);
  466. BufPos += pSmallRoad->PointTotal_Bytes;
  467. for(k = 0; k < pSmallRoad->SmallRoad_PointTotal; k++) {
  468. pRoadPoint = new CRoadPoint;
  469. pSmallRoad->RoadPointList.AddHead(pRoadPoint);
  470. GetLenArray(pRoadPoint->BigRoad_SerialNumber,pRoadPoint->BigRoad_SN_Bytes,FileContent,BufPos);
  471. BufPos += pRoadPoint->BigRoad_SN_Bytes;
  472. GetPointNE(FileContent,&BufPos,&pRoadPoint->m_dgx,&pRoadPoint->m_dgy);
  473. pRoadPoint->OutOfMap = GetOneBNum(FileContent,BufPos);
  474. BufPos += pRoadPoint->OutOfMap_Bytes;
  475. BufPos += pRoadPoint->OutOfMap_Bytes;
  476. CovertNEXY(pRoadPoint, m_cCurrMapInfo.CoeffNE_XY, true);
  477. }
  478. }
  479. }
  480. return BufPos;
  481. }
  482. long CGpsDrawMap::GetRoadCrossPoint(CObList *CrossList,long BufPos)
  483. {
  484. CGpsRoadCrossPoint *pCross;
  485. long CrossTotal,i;
  486. CrossTotal = GetFourBNum(FileContent,BufPos);
  487. BufPos += LibTotalBytes;
  488. for(i = 0; i < CrossTotal; i++) {
  489. pCross = new CGpsRoadCrossPoint;
  490. CrossList->AddHead(pCross);
  491. GetPointNE(FileContent,&BufPos,&pCross->m_dgx,&pCross->m_dgy);
  492. pCross->m_CrossRoad1_Serial = GetOneBNum(FileContent,BufPos);
  493. BufPos += pCross->m_CrossRoad1_Serial_Bytes;
  494. pCross->m_CrossRoad1_Number = GetTwoBNum(FileContent,BufPos);
  495. BufPos += pCross->m_CrossRoad1_Number_Bytes;
  496. pCross->m_CrossRoad1_Level  = GetOneBNum(FileContent,BufPos);
  497. BufPos += pCross->m_CrossRoad1_Level_Bytes;
  498. pCross->m_CrossRoad2_Serial = GetOneBNum(FileContent,BufPos);
  499. BufPos += pCross->m_CrossRoad2_Serial_Bytes;
  500. pCross->m_CrossRoad2_Number = GetTwoBNum(FileContent,BufPos);
  501. BufPos += pCross->m_CrossRoad2_Number_Bytes;
  502. pCross->m_CrossRoad2_Level  = GetOneBNum(FileContent,BufPos);
  503. BufPos += pCross->m_CrossRoad2_Level_Bytes;
  504. pCross->m_CrossRoad3_Serial = GetOneBNum(FileContent,BufPos);
  505. BufPos += pCross->m_CrossRoad3_Serial_Bytes;
  506. pCross->m_CrossRoad3_Number = GetTwoBNum(FileContent,BufPos);
  507. BufPos += pCross->m_CrossRoad3_Number_Bytes;
  508. pCross->m_CrossRoad3_Level  = GetOneBNum(FileContent,BufPos);
  509. BufPos += pCross->m_CrossRoad3_Level_Bytes;
  510. pCross->m_CrossRoad4_Serial = GetOneBNum(FileContent,BufPos);
  511. BufPos += pCross->m_CrossRoad4_Serial_Bytes;
  512. pCross->m_CrossRoad4_Number = GetTwoBNum(FileContent,BufPos);
  513. BufPos += pCross->m_CrossRoad4_Number_Bytes;
  514. pCross->m_CrossRoad4_Level  = GetOneBNum(FileContent,BufPos);
  515. BufPos += pCross->m_CrossRoad4_Level_Bytes;
  516. CovertNEXY(pCross, m_cCurrMapInfo.CoeffNE_XY, true);
  517. }
  518. return BufPos;
  519. }
  520. //Get Sign Lib...
  521. long CGpsDrawMap::GetSignLibAddr(char *SignLibName)
  522. {
  523. long InfoAddr,SignStartAddr,SignEndAddr,i,RetAddr = -1;
  524. char SignFileName[GpsLibFileLen + 1];
  525. InfoAddr = m_cFatStruct.m_lSignLibAddr;
  526. for(i = 0; i < m_cFatStruct.m_lSignLibTotal; i++) {
  527. ClearBYTEArr(SignFileName,GpsLibFileLen + 1);
  528. GetLibInfo(FileContent,InfoAddr,SignFileName,&SignStartAddr,&SignEndAddr);
  529. InfoAddr += LibInfoBytes; //链接库在FAT表中占用的字节数
  530. if(CompareTwoArr(SignFileName,SignLibName) == 1) {
  531. RetAddr = SignStartAddr;
  532. break;
  533. }
  534. }
  535. return RetAddr;
  536. }
  537. bool CGpsDrawMap::GetSignLib(char *SignLibName,CObList *SignList,bool Del)
  538. {
  539. long SignLibStart;
  540. SignLibStart = GetSignLibAddr(SignLibName);
  541. if(SignLibStart == -1) return false;
  542. if(!GetSignList(SignList,SignLibStart,Del)) return false;
  543. return true;
  544. }
  545. BYTE CGpsDrawMap::GetSignList(CObList *SignList,long StartAddr,bool Del)
  546. {
  547. BYTE Ret = 0;
  548. long Total;
  549. char CurrPath[500];
  550. CString Path;
  551. ClearBYTEArr(CurrPath,500);
  552. ::GetCurrentDirectory(500,CurrPath);
  553. Path = CurrPath;
  554. //Get Building
  555. if(GetSignObjectList(SignList,StartAddr,SignObjectOfOthers_Bytes,1,false,Del,Path + BuildingIconName)) Ret++;
  556. //Get Hotel
  557. if(GetSignObjectList(SignList,StartAddr,SignObjectOfOthers_Bytes,2,false,Del,Path + HotelIconName)) Ret++;
  558. //Get Company
  559. if(GetSignObjectList(SignList,StartAddr,SignObjectOfCompany_Bytes,3,true,Del,Path + CompanyIconName)) Ret++;
  560. //Get Amusement
  561. if(GetSignObjectList(SignList,StartAddr,SignObjectOfOthers_Bytes,4,false,Del,Path + AmusementIconName)) Ret++;
  562. //Get PlaceName
  563. if(GetSignObjectList(SignList,StartAddr,SignObjectOfOthers_Bytes,5,false,Del,Path + PlaceNameIconName)) Ret++;
  564. //跳过道路名层
  565. Total = GetFourBNum(FileContent,StartAddr);
  566. StartAddr += (LibTotalBytes + Total * SignRoadNameObjectBytes);
  567. //Get Government
  568. if(GetSignObjectList(SignList,StartAddr,SignObjectOfOthers_Bytes,7,false,Del,Path + GovernmentIconName)) Ret++;
  569. //Get Traffic
  570. if(GetSignObjectList(SignList,StartAddr,SignObjectOfOthers_Bytes,8,false,Del,Path + TrafficIconName)) Ret++;
  571. //Get Shopping
  572. if(GetSignObjectList(SignList,StartAddr,SignObjectOfOthers_Bytes,9,false,Del,Path + ShoppingIconName)) Ret++;
  573. //Get Education
  574. if(GetSignObjectList(SignList,StartAddr,SignObjectOfOthers_Bytes,10,false,Del,Path + EducationIconName)) Ret++;
  575. //Get AfterService
  576. if(GetSignObjectList(SignList,StartAddr,SignObjectOfAfterService_Bytes,11,false,Del)) Ret++;
  577. //Get Hospital
  578. if(GetSignObjectList(SignList,StartAddr,SignObjectOfOthers_Bytes,12,false,Del,Path + HospitalIconName)) Ret++;
  579. //Get Project
  580. if(GetSignObjectList(SignList,StartAddr,SignObjectOfProject_Bytes,13,false,Del,Path + ProjectIconName)) Ret++;
  581. //Get Oil
  582. if(GetSignObjectList(SignList,StartAddr,SignObjectOfOil_Bytes,14,false,Del,Path + OilIconName)) Ret++;
  583. return Ret;
  584. }
  585. bool CGpsDrawMap::GetSignObjectList(CObList *SignList,long &StartAddr,BYTE SignObject_Bytes,
  586. BYTE SignType,bool IsCompany,bool Del,CString IconName)
  587. {
  588. CGpsSignObject *pSign;
  589. long SignTotal,i;
  590. bool Flag = false;
  591. SignTotal = GetFourBNum(FileContent,StartAddr);
  592. StartAddr += LibTotalBytes;
  593. for(i = 0; i < SignTotal; i++) {
  594. pSign = new CGpsSignObject(SignObject_Bytes);
  595. if(SignObject_Bytes > SignObjectOfOil_Bytes) {
  596. GetLenArray((BYTE*)pSign->m_pSignObjectName,SignObject_Bytes,FileContent,StartAddr);
  597. StartAddr += SignObject_Bytes;
  598. GetPointNE(FileContent,&StartAddr,&pSign->m_dgx,&pSign->m_dgy);
  599. pSign->m_arrSignObject_Serial1 = GetOneBNum(FileContent,StartAddr);
  600. StartAddr += pSign->m_bySignObject_Serial1_Bytes;
  601. pSign->m_arrSignObject_Number1 = GetTwoBNum(FileContent,StartAddr);
  602. StartAddr += pSign->m_bySignObject_Number1_Bytes;
  603. pSign->m_arrSignObject_Serial2 = GetOneBNum(FileContent,StartAddr);
  604. StartAddr += pSign->m_bySignObject_Serial2_Bytes;
  605. pSign->m_arrSignObject_Number2 = GetTwoBNum(FileContent,StartAddr);
  606. StartAddr += pSign->m_bySignObject_Number2_Bytes;
  607. GetLenArray((BYTE*)pSign->m_arrSignObjectDispLevel,pSign->m_bySignDispLevel_Bytes,FileContent,StartAddr);
  608. StartAddr += pSign->m_bySignDispLevel_Bytes;
  609. if(IsCompany) {
  610. GetLenArray((BYTE*)pSign->m_arrSignAdvertise,pSign->m_bySignAdvertise_Bytes,FileContent,StartAddr);
  611. StartAddr += pSign->m_bySignAdvertise_Bytes;
  612. }
  613. }
  614. else {
  615. pSign->m_dgy = GetFourBNum(FileContent,StartAddr);
  616. StartAddr += pSign->m_gyBytes;
  617. pSign->m_dgx = GetFourBNum(FileContent,StartAddr);
  618. StartAddr += pSign->m_gxBytes;
  619. pSign->m_arrSignObject_Serial1 = GetOneBNum(FileContent,StartAddr);
  620. StartAddr += pSign->m_bySignObject_Serial1_Bytes;
  621. pSign->m_arrSignObject_Number1 = GetTwoBNum(FileContent,StartAddr);
  622. StartAddr += pSign->m_bySignObject_Number1_Bytes;
  623. pSign->m_arrSignObject_Serial2 = GetOneBNum(FileContent,StartAddr);
  624. StartAddr += pSign->m_bySignObject_Serial2_Bytes;
  625. pSign->m_arrSignObject_Number2 = GetTwoBNum(FileContent,StartAddr);
  626. StartAddr += pSign->m_bySignObject_Number2_Bytes;
  627. }
  628. pSign->m_sIconName = IconName;
  629. pSign->m_bySignType = SignType;
  630. CovertNEXY(pSign, m_cCurrMapInfo.CoeffNE_XY, true);
  631. if(Del) {
  632. //只显示当前图标志物
  633. if((pSign->m_lx > m_cCurrMapInfo.m_lWnd_Max_X) || (pSign->m_lx < 0) ||
  634.    (pSign->m_ly > m_cCurrMapInfo.m_lWnd_Max_Y) || (pSign->m_ly < 0)) {
  635. delete pSign;
  636. continue;
  637. }
  638. }
  639. SignList->AddHead(pSign);
  640. }
  641. if(SignList->GetCount()) Flag = true;
  642. return Flag;
  643. }
  644. bool CGpsDrawMap::CalcNE2XY(double gx,double gy,long &x,long &y)
  645. {
  646. if(!IsValidNE(gx,gy)) return false;
  647. CGpsPoint cPoint;
  648. cPoint.m_dgx = gx;
  649. cPoint.m_dgy = gy;
  650. CovertNEXY(&cPoint, m_cCurrMapInfo.CoeffNE_XY, true);
  651. x = cPoint.m_lx;
  652. y = cPoint.m_ly;
  653. return true;
  654. }
  655. /*************Get Library Infomation*************/
  656. void CGpsDrawMap::GetLibInfo(BYTE *Buf,long InfoAddr,char *FileName,long *StartAddr,long *EndAddr)
  657. {
  658. for(long i = 0; i < GpsLibFileLen; i++){
  659. FileName[i] = Buf[InfoAddr + i];
  660. }
  661. InfoAddr  += GpsLibFileLen;
  662. *StartAddr = GetFourBNum(Buf,InfoAddr);
  663. InfoAddr  += LibAddrBytes;
  664. *EndAddr   = GetFourBNum(Buf,InfoAddr);
  665. }
  666. /*************Calculate NE*************/
  667. double CGpsDrawMap::CovertNE(long lTemp)
  668. {
  669. double Ret,dTemp;
  670. dTemp = lTemp % 360000;
  671. Ret  = (lTemp / 360000) * 100 + dTemp / 6000;
  672. return Ret;
  673. }
  674. long CGpsDrawMap::CovertToLongNE(double dTemp)
  675. {
  676. long lTmp;
  677. lTmp = (long)( dTemp / 100);
  678. lTmp = (long)((lTmp  * 3600 + (dTemp - lTmp * 100) * 60) * 100);
  679. return lTmp;
  680. }
  681. void CGpsDrawMap::GetLinkLibThreePoint(BYTE * BUF,long StartAddr,ChangeTriangle * ThreePoint)
  682. {
  683. long BufPos;
  684. long ltmp;
  685. BufPos = StartAddr;
  686. ltmp = GetFourBNum(BUF,BufPos);
  687. ThreePoint->y1 = CovertNE(ltmp);
  688. BufPos += LibAddrBytes;
  689. ltmp = GetFourBNum(BUF,BufPos);
  690. ThreePoint->x1 = CovertNE(ltmp);
  691. BufPos += LibAddrBytes;
  692. ltmp = GetFourBNum(BUF,BufPos);
  693. ThreePoint->y2 = CovertNE(ltmp);
  694. BufPos += LibAddrBytes;
  695. ltmp = GetFourBNum(BUF,BufPos);
  696. ThreePoint->x2 = CovertNE(ltmp);
  697. BufPos += LibAddrBytes;
  698. ltmp = GetFourBNum(BUF,BufPos);
  699. ThreePoint->y3 = CovertNE(ltmp);
  700. BufPos += LibAddrBytes;
  701. ltmp = GetFourBNum(BUF,BufPos);
  702. ThreePoint->x3 = CovertNE(ltmp);
  703. #if 0
  704. long iTemp;
  705. iTemp = (long)(ThreePoint->x1 / 100);
  706. ThreePoint->x1 = ThreePoint->x1 - iTemp * 40;
  707. iTemp = (long)(ThreePoint->x2 / 100);
  708. ThreePoint->x2 = ThreePoint->x2 - iTemp * 40;
  709. iTemp = (long)(ThreePoint->x3 / 100);
  710. ThreePoint->x3 = ThreePoint->x3 - iTemp * 40;
  711. iTemp = (long)(ThreePoint->y1 / 100);
  712. ThreePoint->y1 = ThreePoint->y1 - iTemp * 40;
  713. iTemp = (long)(ThreePoint->y2 / 100);
  714. ThreePoint->y2 = ThreePoint->y2 - iTemp * 40;
  715. iTemp = (long)(ThreePoint->y3 / 100);
  716. ThreePoint->y3 = ThreePoint->y3 - iTemp * 40;
  717. #endif
  718. }
  719. long CGpsDrawMap::GetLinkList(CObList *pLinkList,BYTE MapLevel)
  720. {
  721. long InfoAddr,LinkStartAddr,LinkEndAddr,i,Count = 0;
  722. char FirstChar;
  723. CGpsLinkStruct cGpsLink,*pLink;
  724. ChangeTriangle TmpTri;
  725. FirstChar = MapLevel + ('A' - 1);
  726. InfoAddr = m_cFatStruct.m_lLinkLibAddr;
  727. for(i = 0; i < m_cFatStruct.m_lLinkLibTotal; i++) {
  728. ClearBYTEArr(cGpsLink.m_LinkLibName,9);
  729. GetLibInfo(FileContent,InfoAddr,cGpsLink.m_LinkLibName,&LinkStartAddr,&LinkEndAddr);
  730. InfoAddr += LibInfoBytes; //链接库在FAT表中占用的字节数
  731. if(FirstChar != cGpsLink.m_LinkLibName[0]) {
  732. continue;
  733. }
  734. LinkStartAddr += 68; //将链接库指针移动到三个经纬度坐标
  735. GetLinkLibThreePoint(FileContent,LinkStartAddr,&TmpTri);
  736. LinkStartAddr += 24;
  737. ClearBYTEArr(cGpsLink.m_RelatedSignLibName,9);
  738. GetLenArray((BYTE*)cGpsLink.m_RelatedSignLibName,GpsLibFileLen,FileContent,LinkStartAddr); //获得综合标志库名称
  739. pLink  = new CGpsLinkStruct;
  740. *pLink = cGpsLink;
  741. pLink->m_MapTri = TmpTri;
  742. pLinkList->AddHead(pLink);
  743. Count++;
  744. }
  745. return Count;
  746. }
  747. void CGpsDrawMap::GetAreaLibList(CObList *AreaList)
  748. {
  749. CGpsAreaLibStruct *pArea = NULL;
  750. long j,Total,StartAddr,EndAddr;
  751. char FileName[8],i;
  752. if(!m_cFatStruct.m_lRegionLibTotal) return ;
  753. GetLibInfo(FileContent,m_cFatStruct.m_lRegionLibAddr,FileName,&StartAddr,&EndAddr);
  754. for(i = 1; i <= AreaLibLevelTotal; i++) {
  755. Total = GetFourBNum(FileContent,StartAddr);
  756. StartAddr += LibTotalBytes;
  757. for(j = 0; j < Total; j++) {
  758. pArea = new CGpsAreaLibStruct;
  759. AreaList->AddHead(pArea);
  760. pArea->m_byAreaLevel = i;
  761. GetLenArray((BYTE*)pArea->m_arrAreaABCD,pArea->m_byAreaABCD_Bytes,FileContent,StartAddr);
  762. StartAddr += pArea->m_byAreaABCD_Bytes;
  763. GetLenArray((BYTE*)pArea->m_arrAreaName,pArea->m_byAreaName_Bytes,FileContent,StartAddr);
  764. StartAddr += pArea->m_byAreaName_Bytes;
  765. if(i == AreaLibLevelTotal) {
  766. GetLenArray((BYTE*)pArea->m_arrRelateSignLibName,pArea->m_byRelateSignLibName_Bytes,FileContent,StartAddr);
  767. StartAddr += pArea->m_byRelateSignLibName_Bytes;
  768. }
  769. }
  770. }
  771. }
  772. bool CGpsDrawMap::CompareTri(ChangeTriangle TmpTri1,ChangeTriangle TmpTri2)
  773. {
  774. double dx1,dy1,dx2,dy2,Bevel1,Bevel2;
  775. bool Result = false;
  776. dx1 = TmpTri1.x3 - TmpTri1.x1; dy1 = TmpTri1.y1 - TmpTri1.y3;
  777. Bevel1 = sqrt(dx1 * dx1 + dy1 * dy1);
  778. dx2 = TmpTri2.x3 - TmpTri2.x1; dy2 = TmpTri2.y1 - TmpTri2.y3;
  779. Bevel2 = sqrt(dx2 * dx2 + dy2 * dy2);
  780. if((Bevel1 - Bevel2) > 0) {
  781. Result = true;
  782. }
  783. return Result;
  784. }
  785. /*************Find CurrPoint in whitch map*************/
  786. bool CGpsDrawMap::CheckPointInMap(double gx,double gy,ChangeTriangle *TmpTri)
  787. {
  788. bool InMap = false;
  789. if(((gx >= TmpTri->x1) && (gx <= TmpTri->x3)) &&
  790.    ((gy <= TmpTri->y1) && (gy >= TmpTri->y3))) {
  791. InMap = true;
  792. }
  793. return InMap;
  794. }
  795. bool CGpsDrawMap::GetCurrLinkLib(CObList *LinkList,CGpsLinkStruct *pLink,double gx,double gy)
  796. {
  797. CGpsLinkStruct *pTemp;
  798. POSITION pos;
  799. bool Result = false,Flag = false;
  800. if(LinkList->GetCount() == 0) return false;
  801. pos = LinkList->GetTailPosition();
  802. while(pos != NULL) {
  803. pTemp  = (CGpsLinkStruct*)LinkList->GetPrev(pos);
  804. if(CheckPointInMap(gx,gy,&pTemp->m_MapTri)) {
  805. if(!Flag) {
  806. Flag = true;
  807. Result = true;
  808. *pLink = *pTemp;
  809. pLink->m_MapTri = pTemp->m_MapTri;
  810. }
  811. else {
  812. if(CompareTri(pLink->m_MapTri,pTemp->m_MapTri)) {
  813. *pLink = *pTemp;
  814. pLink->m_MapTri = pTemp->m_MapTri;
  815. }
  816. }
  817. }
  818. }
  819. return Result;
  820. }
  821. long CGpsDrawMap::GetLinkLibAddr(char *pLinkName)
  822. {
  823. long Result = -1;
  824. char LinkName[GpsLibFileLen + 1];
  825. long InfoAddr,LinkStartAddr,LinkEndAddr,i;
  826. InfoAddr = m_cFatStruct.m_lLinkLibAddr;
  827. for(i  = 0; i < m_cFatStruct.m_lLinkLibTotal; i++) {
  828. ClearBYTEArr(LinkName,GpsLibFileLen + 1);
  829. GetLibInfo(FileContent,InfoAddr,LinkName,&LinkStartAddr,&LinkEndAddr);
  830. InfoAddr += LibInfoBytes; //链接库在FAT表中占用的字节数
  831. if(CompareTwoArr(pLinkName,LinkName) == 1) {
  832. Result = InfoAddr;
  833. break;
  834. }
  835. }
  836. return Result;
  837. }
  838. /*************Draw ColorBlock*************/
  839. void CGpsDrawMap::DrawColorBlock(CObList *ColorBList,CDC * MemDC)
  840. {
  841. CGpsColorBlock *pBlock;
  842. POSITION pos;
  843. CPen *DrawPen;
  844. pos = ColorBList->GetTailPosition();
  845. while(pos != NULL) {
  846. pBlock = (CGpsColorBlock*)ColorBList->GetPrev(pos);
  847. pBlock->m_ColorValue == 8 ? DrawPen = m_cColor.MapColor[6]:
  848. DrawPen = m_cColor.MapColor[pBlock->m_ColorValue - 1];
  849. DrawOneBlock(&pBlock->ColorBlockPointList,DrawPen,MemDC);
  850. }
  851. }
  852. void CGpsDrawMap::DrawOneBlock(CObList * PointList,CPen * CurrPen,CDC * MemDC)
  853. {
  854. long PointXY[3000][2];
  855. long MapBrim[500][4];
  856. long minX1 = -3000,minX2,PointCount;
  857. int i,j;
  858. BYTE b_draw;
  859. CGpsPoint *tmpPoint;
  860. POSITION pos;
  861. PointCount = PointList->GetCount();
  862. pos = PointList->GetHeadPosition();
  863. i = 0;
  864. while(pos != NULL){
  865. tmpPoint = (CGpsPoint*)PointList->GetNext(pos);
  866. PointXY[i][0] = tmpPoint->m_lx;
  867. PointXY[i][1] = tmpPoint->m_ly;
  868. i++;
  869. if(i == 3000) {
  870. AfxMessageBox("系统内部出错!");
  871. return;
  872. }
  873. }
  874. minX1 = GetMinX(&PointXY[0][0],PointCount,minX1);
  875. minX2 = GetMinX(&PointXY[0][0],PointCount,minX1);
  876. CString str;
  877. while(true){
  878. if(minX1 > m_cCurrMapInfo.m_lWnd_Max_X) {
  879.         break;
  880. }
  881.     minX2 = GetMinX(&PointXY[0][0],PointCount,minX1);
  882. if(minX2 == 10000){
  883.         break;
  884. }
  885.     if(minX2 < 0) {
  886.         minX1 = minX2;
  887. continue;
  888. }
  889.     b_draw = 0;
  890.     for(i = 0; i < (PointCount - 1);i++){
  891.         if((( PointXY[i][0] <= minX1) &&
  892. ( PointXY[i + 1][0] >= minX2) &&
  893. ( PointXY[i][0] <  PointXY[i + 1][0])) ||
  894. ((PointXY[i][0] >= minX2) &&
  895. ( PointXY[i + 1][0] <= minX1) &&
  896. ( PointXY[i][0] >  PointXY[i + 1][0]))){
  897.         GetDrawPoint(&PointXY[i][0],minX1,minX2,&MapBrim[b_draw][0]);
  898. b_draw++;
  899. if(b_draw == 500){
  900. AfxMessageBox("系统内部出错!");
  901. return;
  902. }
  903. }
  904.     }
  905. long tmp;
  906. for(i = 0; i < b_draw; i++){
  907. for(j = i + 1; j < b_draw; j++){
  908. if(MapBrim[i][1] > MapBrim[j][1]){
  909. tmp = MapBrim[i][1];
  910. MapBrim[i][1] = MapBrim[j][1]; 
  911. MapBrim[j][1] = tmp;
  912. tmp = MapBrim[i][3];
  913. MapBrim[i][3] = MapBrim[j][3]; 
  914. MapBrim[j][3] = tmp;
  915. }
  916. }
  917. }
  918. b_draw = b_draw / 2;
  919. for(i = 0; i < b_draw; i++){
  920. DrawTriangle(&MapBrim[2 * i][0],&MapBrim[2 * i + 1][0],CurrPen,MemDC);
  921.     }
  922.     minX1 = minX2;
  923. }
  924. }
  925. void CGpsDrawMap::DrawTriangle(long *bian1, long *bian2,CPen * CurrPen,CDC * MemDC)
  926. {
  927. long y1,y2,tmp;
  928.     if((bian1[3] > bian2[3]) || (bian1[1] > bian2[1])){
  929. tmp = bian1[3];
  930. bian1[3] = bian2[3];
  931. bian2[3] = tmp;
  932. tmp = bian1[1];
  933. bian1[1] = bian2[1];
  934. bian2[1] = tmp;
  935.     }
  936.     for(int i = bian1[0]; i < bian2[2]; i++){
  937.         y1 = bian1[1] + (i - bian1[0]) * (bian1[3] - bian1[1]) / (bian1[2] - bian1[0]);
  938. if(y1 > m_cCurrMapInfo.m_lWnd_Max_Y) {
  939. y1 = (long)m_cCurrMapInfo.m_lWnd_Max_Y;
  940. }
  941. else if(y1 < 0) {
  942.         y1 = 0;
  943. }
  944.         y2 = bian2[1] + (i - bian2[0]) * (bian2[3] - bian2[1]) / (bian2[2] - bian2[0]);
  945. if(y2 > m_cCurrMapInfo.m_lWnd_Max_X) {
  946.     y2 = (long)m_cCurrMapInfo.m_lWnd_Max_X;
  947. }
  948. else{
  949. if(y2 < 0){
  950. y2 = 0;
  951. }
  952. }
  953. DrawLine(i,y1,i,y2,1,CurrPen,MemDC);
  954.     }
  955. }
  956. /*************Draw Line*************/
  957. void CGpsDrawMap::DrawLine(long SX, long SY, long EX, long EY, int LineCount,CPen * CurrPen,CDC * MemDC)
  958. {
  959. CPen * OldPen;
  960. OldPen = MemDC->SelectObject(CurrPen);
  961. int bian  = 1;
  962. int LineWide = LineCount;
  963. MemDC->MoveTo(SX,SY);
  964. MemDC->LineTo(EX,EY);
  965.     while((LineCount--) > 0){
  966. if(SX == EX){
  967. bool flag = true;
  968. BYTE tmp  = 1;
  969. for(int i = 0; i < LineWide; i++){
  970. if(flag){
  971. MemDC->MoveTo(SX + tmp,SY);
  972. MemDC->LineTo(EX + tmp,EY);
  973. flag = false;
  974. }
  975. else{
  976. MemDC->MoveTo(SX - tmp,SY);
  977. MemDC->LineTo(EX - tmp,EY);
  978. flag = true;
  979. }
  980. if (flag) tmp++;
  981. }
  982. }
  983. else if( ((EY - SY) / ( EX - SX)) != 0){
  984. MemDC->MoveTo(SX - bian,SY);
  985. MemDC->LineTo(EX - bian,EY);
  986. }
  987. else{
  988. MemDC->MoveTo(SX,SY - bian);
  989. MemDC->LineTo(EX,EY - bian);
  990. }
  991. if(bian > 0){
  992. bian = 0 - bian;
  993. }
  994. else{
  995. bian = 0 - bian;
  996. bian++;
  997. }
  998. }
  999. MemDC->SelectObject(OldPen);
  1000. }
  1001. long CGpsDrawMap::GetMinX(long *pDataXY,long PointCount,long MinX)
  1002. {
  1003.     long ret = 10000;
  1004.     bool flag = false;
  1005.     for(int i = 0; i < PointCount; i++){
  1006.         if(pDataXY[i * 2] > MinX){
  1007.     if(pDataXY[i * 2] < ret){
  1008.         ret = pDataXY[i * 2];
  1009. flag = true;
  1010.     }
  1011. }
  1012. }
  1013. return ret;
  1014. }
  1015. void CGpsDrawMap::GetDrawPoint(long line_p[], int minX1, int minX2, long *Result)
  1016. {
  1017.     int x1,y1,x2,y2;
  1018. bool flag = true;
  1019.     if(line_p[1] == line_p[3]){
  1020.         flag = false;
  1021. }
  1022.     if(line_p[0] > line_p[2]){
  1023.         x1 = line_p[2];
  1024.         y1 = line_p[3];
  1025.         x2 = line_p[0];
  1026.         y2 = line_p[1];
  1027.     }
  1028.     else{
  1029.         x1 = line_p[0];
  1030.         y1 = line_p[1];
  1031.         x2 = line_p[2];
  1032.         y2 = line_p[3];
  1033.     }
  1034.     if(minX1 < 0){
  1035.         Result[0] = 0;
  1036.     }
  1037.     else{
  1038.         Result[0] = minX1;
  1039.     }
  1040.     if(minX2 > m_cCurrMapInfo.m_lWnd_Max_X) {
  1041.         Result[2] = (long)m_cCurrMapInfo.m_lWnd_Max_X;
  1042.     }
  1043.     else{
  1044.         Result[2] = minX2;
  1045.     }
  1046.     if(flag){
  1047. Result[1] = y1 + (Result[0] - x1) * (y2 - y1) / (x2 - x1);
  1048. }
  1049.     else{
  1050. Result[1] = line_p[1];
  1051. }
  1052.     if(flag){
  1053.         Result[3] = y1 + (Result[2] - x1) * (y2 - y1) / (x2 - x1);
  1054. }
  1055.     else{
  1056.         Result[3] = line_p[1];
  1057. }
  1058. }
  1059. /*************Draw Road*************/
  1060. void CGpsDrawMap::DrawRoad(CObList *RoadList,CDC *pDC)
  1061. {
  1062. CGpsRoadStruct *pRoad;
  1063. CSmallRoadStruct *pSmall;
  1064. CRoadPoint *pRoadPoint;
  1065. POSITION pos,pos1,pos2;
  1066. CPoint PrevPoint,CurrPoint;
  1067. CPen *CurrPen;
  1068. BYTE RoadLevel,RoadWidth;
  1069. bool Flag;
  1070. pos = RoadList->GetTailPosition();
  1071. while(pos != NULL) {
  1072. pRoad  = (CGpsRoadStruct*)RoadList->GetPrev(pos);
  1073. pos1   = pRoad->SmallRoadList.GetTailPosition();
  1074. Flag   = false;
  1075. while(pos1 != NULL) {
  1076. pSmall  = (CSmallRoadStruct*)pRoad->SmallRoadList.GetPrev(pos1);
  1077. RoadLevel = pSmall->RoadorName_DispLevel & 0x0f;
  1078. switch (RoadLevel) {
  1079. case 0:
  1080. CurrPen   = m_cColor.RoadColor[5];
  1081. RoadWidth = 1;
  1082. break;
  1083. case 1:
  1084. RoadWidth = 3;
  1085. CurrPen   = m_cColor.RoadColor[0];
  1086. break;
  1087. case 2:
  1088. RoadWidth = 3;
  1089. CurrPen   = m_cColor.RoadColor[1];
  1090. break;
  1091. case 3:
  1092. RoadWidth = 3;
  1093. CurrPen   = m_cColor.RoadColor[2];
  1094. break;
  1095. case 4:
  1096. RoadWidth = 2;
  1097. CurrPen   = m_cColor.RoadColor[3];
  1098. break;
  1099. case 5:
  1100. RoadWidth = 1;
  1101. CurrPen   = m_cColor.RoadColor[4];
  1102. break;
  1103. default:
  1104. RoadWidth = 3;
  1105. CurrPen   = m_cColor.RoadColor[2];
  1106. break;
  1107. }
  1108. switch(m_byZoomCoeffic) {
  1109. case 1:
  1110. RoadWidth += 2;
  1111. break;
  1112. case 2:
  1113. RoadWidth += 3;
  1114. break;
  1115. case 4:
  1116. RoadWidth += 4;
  1117. break;
  1118. }
  1119. if(pRoad->m_byIsHelpRoad) {
  1120. RoadWidth = 2;
  1121. }
  1122. pos2 = pSmall->RoadPointList.GetTailPosition();
  1123. while(pos2 != NULL) {
  1124. pRoadPoint = (CRoadPoint*)pSmall->RoadPointList.GetPrev(pos2);
  1125. if(pRoadPoint->BigRoad_SerialNumber[1] == 100) continue;
  1126. CurrPoint.x = pRoadPoint->m_lx; CurrPoint.y = pRoadPoint->m_ly;
  1127. if(!Flag) {
  1128. Flag = true;
  1129. }
  1130. else {
  1131. // DrawLine(PrevPoint.x, PrevPoint.y, 
  1132. //  CurrPoint.x, CurrPoint.y, 
  1133. //  RoadWidth,CurrPen,pDC);
  1134. MapDrawRoad(pDC,PrevPoint.x,PrevPoint.y,CurrPoint.x,CurrPoint.y,RoadWidth,CurrPen);
  1135. }
  1136. PrevPoint = CurrPoint;
  1137. }
  1138. }
  1139. }
  1140. }
  1141. void CGpsDrawMap::MapDrawRoad(CDC *pDC, long SX, long SY, long EX, long EY, BYTE RoadWide,CPen *CurrPen)
  1142. {
  1143. CPen BorderPen(PS_SOLID,1,RGB(115,115,115));
  1144. long W;
  1145. MapDrawLineWidth(pDC,SX,SY,EX,EY,RoadWide,CurrPen);
  1146. /*
  1147.  ** always draws from small X to large X
  1148. */
  1149. if (SX > EX) {
  1150. W = EX, EX = SX, SX = W;
  1151. W = EY, EY = SY, SY = W;
  1152. }
  1153. if (SX == EX) {
  1154. DrawLine(SX - (RoadWide >> 1), SY, EX - (RoadWide >> 1), EY,0,&BorderPen,pDC);
  1155. DrawLine(SX + (RoadWide >> 1), SY, EX + (RoadWide >> 1), EY,0,&BorderPen,pDC);
  1156. return;
  1157. }
  1158. if (SY == EY) {
  1159. DrawLine(SX, SY - (RoadWide >> 1), EX, EY - (RoadWide >> 1),0,&BorderPen,pDC);
  1160. DrawLine(SX, SY + (RoadWide >> 1), EX, EY + (RoadWide >> 1),0,&BorderPen,pDC);
  1161. return;
  1162. }
  1163. if (SY < EY) {
  1164. DrawLine(SX + (RoadWide >> 1), SY - (RoadWide >> 1), EX + (RoadWide >> 1), EY - (RoadWide >> 1),0,&BorderPen,pDC);
  1165. DrawLine(SX - (RoadWide >> 1), SY + (RoadWide >> 1), EX - (RoadWide >> 1), EY + (RoadWide >> 1),0,&BorderPen,pDC);
  1166. return;
  1167. }
  1168. if (SY > EY) {
  1169. DrawLine(SX - (RoadWide >> 1), SY - (RoadWide >> 1), EX - (RoadWide >> 1), EY - (RoadWide >> 1),0,&BorderPen,pDC);
  1170. DrawLine(SX + (RoadWide >> 1), SY + (RoadWide >> 1), EX + (RoadWide >> 1), EY + (RoadWide >> 1),0,&BorderPen,pDC);
  1171. return;
  1172. }
  1173. }
  1174. void CGpsDrawMap::MapDrawLineWidth(CDC *pDC, long SX, long SY, long EX, long EY, BYTE MapLineWidth,CPen *Pen)
  1175. {
  1176. long W, H, Ha, dY, f;
  1177. BYTE HalfWidth = MapLineWidth / 2;
  1178. CPoint sp,ep;
  1179. CPen *OldPen;
  1180. OldPen = pDC->SelectObject(Pen);
  1181. /*
  1182. for (i = 0; i < MapLineWidth; i++) {
  1183. sp.x = SX - HalfWidth + i;
  1184. sp.y = SX - HalfWidth;
  1185. ep.x = SX - HalfWidth + i;
  1186. ep.y = SX - HalfWidth - MapLineWidth;
  1187. pDC->MoveTo(sp);
  1188. pDC->LineTo(ep);
  1189. sp.x = EX - HalfWidth + i;
  1190. sp.y = EX - HalfWidth;
  1191. ep.x = EX - HalfWidth + i;
  1192. ep.y = EX - HalfWidth - MapLineWidth;
  1193. pDC->MoveTo(sp);
  1194. pDC->LineTo(ep);
  1195. }
  1196. */
  1197. /*
  1198.  ** always draws from small X to large X
  1199.  */
  1200. if (SX > EX) {
  1201. W = EX, EX = SX, SX = W;
  1202. W = EY, EY = SY, SY = W;
  1203. }
  1204. /*
  1205.  ** we might want to clip the line here
  1206.  */
  1207. W = (EX - SX);
  1208. H = (EY - SY);
  1209. Ha = (H < 0) ? -H : H;
  1210. dY = (H < 0) ? -1 : 1;
  1211. if (Ha > W) {
  1212. /* Y-majored */
  1213. f = 0;
  1214. while (1) {
  1215. sp.x = SX - HalfWidth;
  1216. sp.y = SY - HalfWidth;
  1217. ep.x = SX - HalfWidth + MapLineWidth;
  1218. ep.y = SY - HalfWidth;
  1219. pDC->MoveTo(sp);
  1220. pDC->LineTo(ep);
  1221. sp.x = SX - HalfWidth;
  1222. sp.y = SY - HalfWidth;
  1223. ep.x = SX - HalfWidth;
  1224. ep.y = SY - HalfWidth + MapLineWidth;
  1225. pDC->MoveTo(sp);
  1226. pDC->LineTo(ep);
  1227. sp.x = SX + HalfWidth;
  1228. sp.y = SY + HalfWidth;
  1229. ep.x = SX + HalfWidth - MapLineWidth;
  1230. ep.y = SY + HalfWidth;
  1231. pDC->MoveTo(sp);
  1232. pDC->LineTo(ep);
  1233. sp.x = SX + HalfWidth;
  1234. sp.y = SY + HalfWidth;
  1235. ep.x = SX + HalfWidth;
  1236. ep.y = SY + HalfWidth - MapLineWidth;
  1237. pDC->MoveTo(sp);
  1238. pDC->LineTo(ep);
  1239. if (SY == EY) break;
  1240. if ((f += W) >= Ha) {
  1241. f -= Ha;
  1242. SX++;
  1243. }
  1244. SY += dY;
  1245. }
  1246. }
  1247. else {
  1248. /* X-majored */
  1249. f = 0;
  1250. while (1) {
  1251. sp.x = SX - HalfWidth;
  1252. sp.y = SY - HalfWidth;
  1253. ep.x = SX - HalfWidth + MapLineWidth;
  1254. ep.y = SY - HalfWidth;
  1255. pDC->MoveTo(sp);
  1256. pDC->LineTo(ep);
  1257. sp.x = SX - HalfWidth;
  1258. sp.y = SY - HalfWidth;
  1259. ep.x = SX - HalfWidth;
  1260. ep.y = SY - HalfWidth + MapLineWidth;
  1261. pDC->MoveTo(sp);
  1262. pDC->LineTo(ep);
  1263. sp.x = SX + HalfWidth;
  1264. sp.y = SY + HalfWidth;
  1265. ep.x = SX + HalfWidth - MapLineWidth;
  1266. ep.y = SY + HalfWidth;
  1267. pDC->MoveTo(sp);
  1268. pDC->LineTo(ep);
  1269. sp.x = SX + HalfWidth;
  1270. sp.y = SY + HalfWidth;
  1271. ep.x = SX + HalfWidth;
  1272. ep.y = SY + HalfWidth - MapLineWidth;
  1273. pDC->MoveTo(sp);
  1274. pDC->LineTo(ep);
  1275. if (SX == EX) break;
  1276. if ((f += Ha) >= W) {
  1277. f -= W;
  1278. SY += dY;
  1279. }
  1280. SX++;
  1281. }
  1282. }
  1283. pDC->SelectObject(OldPen);
  1284. }
  1285. /*************Draw Road Name*************/
  1286. void CGpsDrawMap::DrawRoadName(CObList *RoadList,CDC *pDC)
  1287. {
  1288. CGpsRoadStruct *pRoad;
  1289. CSmallRoadStruct *pSmall;
  1290. POSITION pos,pos1;
  1291. CString RoadName;
  1292. pos = RoadList->GetTailPosition();
  1293. while(pos != NULL) {
  1294. pRoad  = (CGpsRoadStruct*)RoadList->GetPrev(pos);
  1295. if(isupper(pRoad->BigRoad_Serial)) continue;
  1296. pos1   = pRoad->SmallRoadList.GetTailPosition();
  1297. while(pos1  != NULL) {
  1298. pSmall   = (CSmallRoadStruct*)pRoad->SmallRoadList.GetPrev(pos1);
  1299. RoadName.Empty();
  1300. RoadName = pSmall->RoadName;
  1301. if(RoadName.IsEmpty()) continue;
  1302. if(pSmall->RoadPointList.GetCount() < 2) continue;
  1303. DrawOneRoadName(&pSmall->RoadPointList,RoadName,pDC);
  1304. }
  1305. }
  1306. }
  1307. BYTE CGpsDrawMap::GetChrCount(CString RoadName)
  1308. {
  1309. BYTE chr,pos,Length = 0;
  1310. pos = 0;
  1311. while(pos < RoadName.GetLength()) {
  1312. chr = RoadName.GetAt(pos);
  1313. if(chr < 0x80) pos++;
  1314. else pos += 2;
  1315. Length++;
  1316. }
  1317. return Length;
  1318. }
  1319. CPoint CGpsDrawMap::GetRoadMidPoint(CObList *RoadList)
  1320. {
  1321. CGpsPoint *pPoint;
  1322. POSITION pos;
  1323. CPoint point;
  1324. short Mid,Count = 0;
  1325. Mid = RoadList->GetCount() / 2;
  1326. pos = RoadList->GetTailPosition();
  1327. while(pos != NULL) {
  1328. pPoint = (CGpsPoint*)RoadList->GetPrev(pos);
  1329. if(Count == Mid) {
  1330. point.x = pPoint->m_lx;
  1331. point.y = pPoint->m_ly;
  1332. return point;
  1333. }
  1334. Count++;
  1335. }
  1336. return NULL;
  1337. }
  1338. void CGpsDrawMap::DrawStr(CDC *pDC,CPoint point,CString Name)
  1339. {
  1340. CPoint TempPoint,cPoint(6,6),SavePoint;
  1341. CBrush cBrush(RGB(0,255,255));
  1342. CPen CurrPen(PS_SOLID,1,RGB(0,0,255)),*pSavePen = NULL;
  1343. CRect cRect;
  1344. bool Flag1 = false,Flag2 = false;
  1345. pSavePen = pDC->SelectObject(&CurrPen);
  1346. TempPoint.x = (long)(point.x + 30 / sqrt(2));
  1347. TempPoint.y = (long)(point.y - 30 / sqrt(2));
  1348. cRect = CRect(TempPoint.x - 3,TempPoint.y - 2,TempPoint.x + 3 + Name.GetLength() * 8,TempPoint.y + 18);
  1349. if(cRect.top < 0) Flag1 = true;
  1350. if(cRect.right > m_cCurrMapInfo.m_lWnd_Max_X) Flag2 = true;
  1351. if(Flag1) {
  1352. TempPoint.y = (long)(point.y + 30 / sqrt(2));
  1353. }
  1354. if(Flag2) {
  1355. TempPoint.x = (long)(point.x - 30 / sqrt(2));
  1356. }
  1357. pDC->MoveTo(point);
  1358. pDC->LineTo(TempPoint);
  1359. SavePoint = TempPoint;
  1360. if(Flag2) TempPoint.x = TempPoint.x - (3 + Name.GetLength() * 8);
  1361. cRect = CRect(TempPoint.x - 3,TempPoint.y - 2,TempPoint.x + 3 + Name.GetLength() * 8,TempPoint.y + 18);
  1362. pDC->SetBkMode(TRANSPARENT);
  1363. pDC->RoundRect(cRect,cPoint);
  1364. // pDC->FillRect(cRect,&cBrush);
  1365. pDC->TextOut(TempPoint.x,TempPoint.y,Name);
  1366. TempPoint = SavePoint;
  1367. TempPoint.y += 8;
  1368. pDC->MoveTo(point);
  1369. pDC->LineTo(TempPoint);
  1370. pDC->SelectObject(pSavePen);
  1371. }
  1372. long CGpsDrawMap::CalcTwoPointDist(CPoint sp,CPoint ep)
  1373. {
  1374. long dx,dy,Distance;
  1375. dx = abs(sp.x - ep.x);
  1376. dy = abs(sp.y - ep.y);
  1377. Distance = (long)sqrt(Square(dx) + Square(dy));
  1378. return Distance;
  1379. }
  1380. void CGpsDrawMap::SearchSign()
  1381. {
  1382. CSearchSignDlg dlg(&m_cCurrMapInfo.lCurrSignList,&m_cCurrMapInfo.lAreaLibList);
  1383. dlg.GetParent(this);
  1384. dlg.DoModal();
  1385. }
  1386. long CGpsDrawMap::CalcPointsDist(CObList *TempList,bool ByNE)
  1387. {
  1388. CGpsPoint *pPoint;
  1389. POSITION pos = TempList->GetTailPosition();
  1390. CPoint sp,ep;
  1391. long Dist = 0;
  1392. BYTE Flag = 0;
  1393. while(pos != NULL) {
  1394. pPoint = (CGpsPoint*)TempList->GetPrev(pos);
  1395. if(!ByNE) {
  1396. ep.x = pPoint->m_lx;
  1397. ep.y = pPoint->m_ly;
  1398. }
  1399. else {
  1400. ep.x = CovertToLongNE(pPoint->m_dgx);
  1401. ep.y = CovertToLongNE(pPoint->m_dgy);
  1402. }
  1403. if(!Flag) {
  1404. Flag = 1;
  1405. sp = ep;
  1406. continue;
  1407. }
  1408. Dist +=CalcTwoPointDist(sp,ep);
  1409. sp = ep;
  1410. }
  1411. return Dist;
  1412. }
  1413. CPoint CGpsDrawMap::CalcOneLinePoint(CPoint sp,CPoint ep,long WordPos,long Bevel)
  1414. {
  1415. CPoint point;
  1416. long dx,dy;
  1417. dx = ep.x - sp.x; dy = ep.y - sp.y;
  1418. if(dx == 0) {
  1419. point.x = sp.x;
  1420. point.y = sp.y + dy - WordPos;
  1421. }
  1422. else if(dy == 0) {
  1423. point.x = sp.x + dx - WordPos;
  1424. point.y = sp.y;
  1425. }
  1426. else {
  1427. point.x = sp.x + (WordPos * dx) / Bevel;
  1428. point.y = sp.y + (WordPos * dy) / Bevel;
  1429. }
  1430. return point;
  1431. }
  1432. void CGpsDrawMap::DrawOneRoadName(CObList * TempList,CString RoadName,CDC * MemDC)
  1433. {
  1434. CGpsPoint *pPoint = NULL;
  1435. POSITION pos;
  1436. CString Word;
  1437. CPoint point,sp,ep;
  1438. BYTE FirstChr,DrawMode,Flag = 0;
  1439. BYTE NamePos = 1,Len = GetChrCount(RoadName);
  1440. short PointTotal = TempList->GetCount();
  1441. long WordPos,Dist,CurrDist,d = 0,dx,dy;
  1442. FirstChr = RoadName.GetAt(0);
  1443. if(isalpha(FirstChr)) DrawMode = true;
  1444. else if(Len > PointTotal) DrawMode = true;
  1445. else DrawMode = false;
  1446. if(DrawMode) {
  1447. // point = GetRoadMidPoint(TempList);
  1448. // DrawStr(MemDC,point,RoadName);
  1449. return;
  1450. }
  1451. else {
  1452. Dist = CalcPointsDist(TempList);
  1453. WordPos = Dist / (Len + 1) + 1;
  1454. pos = TempList->GetTailPosition();
  1455. while(pos  != NULL) {
  1456. pPoint  = (CGpsPoint*)TempList->GetPrev(pos);
  1457. ep.x = pPoint->m_lx;
  1458. ep.y = pPoint->m_ly;
  1459. if(!Flag) {
  1460. sp = ep;
  1461. Flag = 1;
  1462. continue;
  1463. }
  1464. CurrDist = CalcTwoPointDist(sp,ep);
  1465. d  += CurrDist;
  1466. if(NamePos / 2 >= Len) return;
  1467. dx = abs(sp.x - ep.x); dy = abs(sp.y - ep.y);
  1468. if(d == WordPos) {
  1469. Word.Empty();
  1470. Word += RoadName.GetAt(NamePos - 1);
  1471. Word += RoadName.GetAt(NamePos - 0);
  1472. // AfxMessageBox(Word);
  1473. MemDC->SetBkMode (TRANSPARENT);
  1474. if(dx > dy) {
  1475. MemDC->TextOut(ep.x +  0,ep.y - 15,Word);
  1476. }
  1477. else {
  1478. MemDC->TextOut(ep.x - 15,ep.y +  0,Word);
  1479. }
  1480. d = 0;
  1481. NamePos += 2;
  1482. }
  1483. else if(d > WordPos) {
  1484. point = CalcOneLinePoint(sp,ep,CurrDist - (d - WordPos),CurrDist);
  1485. Word.Empty();
  1486. Word += RoadName.GetAt(NamePos - 1);
  1487. Word += RoadName.GetAt(NamePos - 0);
  1488. // AfxMessageBox(Word);
  1489. MemDC->SetBkMode (TRANSPARENT);
  1490. if(dx > dy) {
  1491. MemDC->TextOut(point.x +  0,point.y - 15,Word);
  1492. }
  1493. else {
  1494. MemDC->TextOut(point.x - 15,point.y +  0,Word);
  1495. }
  1496. d = d - WordPos;
  1497. NamePos += 2;
  1498. }
  1499. sp = ep;
  1500. }
  1501. }
  1502. }
  1503. void CGpsDrawMap::ClearLinkList(CObList *pLinkList)
  1504. {
  1505. CGpsLinkStruct *pLink;
  1506. POSITION pos;
  1507. pos = pLinkList->GetHeadPosition();
  1508. while(pos != NULL) {
  1509. pLink  = (CGpsLinkStruct*)pLinkList->GetNext(pos);
  1510. delete pLink;
  1511. }
  1512. pLinkList->RemoveAll();
  1513. }
  1514. void CGpsDrawMap::ClearPointList(CObList *PointList)
  1515. {
  1516. CGpsPoint *pPoint;
  1517. POSITION pos;
  1518. pos = PointList->GetHeadPosition();
  1519. while(pos != NULL) {
  1520. pPoint = (CGpsPoint*)PointList->GetNext(pos);
  1521. delete pPoint;
  1522. }
  1523. PointList->RemoveAll();
  1524. }
  1525. bool CGpsDrawMap::SaveRecePoint(double gx,double gy,CDC *pDC,CString strVehicleNO)
  1526. {
  1527. if(!IsValidNE(gx,gy)) return false;
  1528. CGpsPoint *pPoint,*pTempPoint = NULL;
  1529. POSITION pos;
  1530. bool Flag = false;
  1531. pPoint = new CGpsPoint;
  1532. pPoint->m_dgx = gx; pPoint->m_dgy = gy;
  1533. pPoint->m_sVehicleNO = strVehicleNO;
  1534. CovertNEXY(pPoint, m_cCurrMapInfo.CoeffNE_XY, true);
  1535. pos = mSaveRecePointList.GetTailPosition();
  1536. while(pos != NULL) {
  1537. pTempPoint = (CGpsPoint*)mSaveRecePointList.GetPrev(pos);
  1538. if(pTempPoint->m_sVehicleNO.Compare(strVehicleNO) == 0) {
  1539. // ErasePrevPoint(pDC,pTempPoint->m_lx,pTempPoint->m_ly);
  1540. pTempPoint->m_dgx = pPoint->m_dgx;
  1541. pTempPoint->m_dgy = pPoint->m_dgy;
  1542. pTempPoint->m_lx = pPoint->m_lx;
  1543. pTempPoint->m_ly = pPoint->m_ly;
  1544. delete pPoint;
  1545. Flag = true;
  1546. break;
  1547. }
  1548. }
  1549. if(!Flag) {
  1550. mSaveRecePointList.AddHead(pPoint);
  1551. }
  1552. return true;
  1553. }
  1554. void CGpsDrawMap::ErasePrevPoint(CDC *pDC,long x,long y)
  1555. {
  1556. CRect cRect;
  1557. cRect.left  = x - GPS_CAR_WIDTH_HEIGH / 2;
  1558. cRect.right  = x + GPS_CAR_WIDTH_HEIGH / 2;
  1559. cRect.top  = y - GPS_CAR_WIDTH_HEIGH / 2;
  1560. cRect.bottom = y + GPS_CAR_WIDTH_HEIGH / 2;
  1561. RedrawInvalidRect(cRect,pDC,false);
  1562. }
  1563. void CGpsDrawMap::DrawEllipse(CDC *pDC)
  1564. {
  1565. CGpsPoint *pPoint = NULL;
  1566. CBrush cBrush(RGB(255,8,0));
  1567. CBrush *SaveBrush = pDC->SelectObject(&cBrush);
  1568. CRect cRect;
  1569. BYTE Width = m_PointWidth + 2;
  1570. if(mSaveRecePointList.GetCount() == 0) return;
  1571. #if 1
  1572. pPoint = (CGpsPoint*)mSaveRecePointList.GetHead();
  1573. if(pPoint != NULL) {
  1574. cRect.left  = pPoint->m_lx - Width;
  1575. cRect.right  = pPoint->m_lx + Width;
  1576. cRect.top  = pPoint->m_ly - Width;
  1577. cRect.bottom = pPoint->m_ly + Width;
  1578. pDC->Ellipse(&cRect);
  1579. }
  1580. #else
  1581. pos = mSaveRecePointList.GetTailPosition();
  1582. while(pos != NULL) {
  1583. pPoint = (CGpsPoint*)mSaveRecePointList.GetPrev(pos);
  1584. cRect.left  = pPoint->m_lx - Width;
  1585. cRect.right  = pPoint->m_lx + Width;
  1586. cRect.top  = pPoint->m_ly - Width;
  1587. cRect.bottom = pPoint->m_ly  + Width;
  1588. pDC->Ellipse(&cRect);
  1589. }
  1590. #endif
  1591. pDC->SelectObject(SaveBrush);
  1592. SaveBrush->DeleteObject();
  1593. }
  1594. //Get Course of the car ...
  1595. CString CGpsDrawMap::GetCarByDirection(double Course)
  1596. {
  1597. CString ret;
  1598. double TmpCourse = 0;
  1599. ret = SaveGpsCarPath[0];
  1600. for(BYTE i = 0; i < 24; i++) {
  1601. if((Course >= TmpCourse) && (Course < TmpCourse + 15)) {
  1602. ret = SaveGpsCarPath[i];
  1603. }
  1604. TmpCourse += 15;
  1605. }
  1606. return ret;
  1607. }
  1608. //Redraw invalid rectangle...
  1609. void CGpsDrawMap::RedrawInvalidRect(CRect cRect,CDC * pDC,bool Flag)
  1610. {
  1611. int i,j;
  1612. int x,y;
  1613. for(x = 0,i = cRect.left; i < cRect.right; i++,x++) {
  1614. for(y = 0,j = cRect.top; j < cRect.bottom; j++,y++) {
  1615. if((x == 40) || (y == 40)) break;
  1616. if(Flag) {
  1617. SaveInvalidRectColor[x][y]= GetPixel(*pDC,i,j);
  1618. }
  1619. else {
  1620. SetPixel(*pDC,i,j,SaveInvalidRectColor[x][y]);
  1621. }
  1622. }
  1623. }
  1624. }
  1625. //Draw Gps Car ...
  1626. void CGpsDrawMap::DrawGpsCar(CDC *pDC,double Course)
  1627. {
  1628. #if 0
  1629. CString CarName,CarPath;
  1630. CBmpProc CarMap;
  1631. CGpsPoint *pPoint = NULL;
  1632. CRect cRect;
  1633. HWND hWnd = ::GetActiveWindow();
  1634. POSITION pos;
  1635. CarPath += GetCarByDirection(Course);
  1636. CarMap.LoadFromFile(CarPath);
  1637. //refresh Prev Car...
  1638. pos = mSaveRecePointList.GetHeadPosition();
  1639. if(pos != NULL) {
  1640. mSaveRecePointList.GetNext(pos);
  1641. if(pos != NULL) {
  1642. pPoint = (CGpsPoint*)mSaveRecePointList.GetNext(pos);
  1643. if(pPoint != NULL) {
  1644. cRect.left  = pPoint->m_lx - CarMap.Width () / 2;
  1645. cRect.right  = pPoint->m_lx + CarMap.Width () / 2;
  1646. cRect.top  = pPoint->m_ly - CarMap.Height() / 2;
  1647. cRect.bottom = pPoint->m_ly + CarMap.Height() / 2;
  1648. RedrawInvalidRect(cRect,pDC,false);
  1649. }
  1650. }
  1651. }
  1652. //Draw Car...
  1653. pPoint = (CGpsPoint*)mSaveRecePointList.GetHead();
  1654. if(pPoint != NULL) {
  1655. cRect.left  = pPoint->m_lx - CarMap.Width () / 2;
  1656. cRect.right  = pPoint->m_lx + CarMap.Width () / 2;
  1657. cRect.top  = pPoint->m_ly - CarMap.Height() / 2;
  1658. cRect.bottom = pPoint->m_ly + CarMap.Height() / 2;
  1659. RedrawInvalidRect(cRect,pDC,true);
  1660. CarMap.DrawTransparentInRect(*pDC,0,&cRect,NULL,0); //装入汽车位图
  1661. CPoint point;
  1662. point.x = pPoint->m_lx;
  1663. point.y = pPoint->m_ly;
  1664. DrawStr(pDC,point,strVehicleNO);
  1665. }
  1666. CarMap.Clear();
  1667. #else
  1668. CString CarName,CarPath;
  1669. CBmpProc CarMap;
  1670. CGpsPoint *pPoint = NULL;
  1671. CRect cRect;
  1672. POSITION pos;
  1673. CarPath += GetCarByDirection(Course);
  1674. CarMap.LoadFromFile(CarPath);
  1675. //refresh Prev Car...
  1676. /* pos = mSaveRecePointList.GetHeadPosition();
  1677. if(pos != NULL) {
  1678. mSaveRecePointList.GetNext(pos);
  1679. if(pos != NULL) {
  1680. pPoint = (CGpsPoint*)mSaveRecePointList.GetNext(pos);
  1681. if(pPoint != NULL) {
  1682. ErasePrevPoint(pDC,pPoint->m_lx,pPoint->m_ly);
  1683. }
  1684. }
  1685. }
  1686. */
  1687. //Draw Car...
  1688. pos  = mSaveRecePointList.GetTailPosition();
  1689. while(pos != NULL) {
  1690. pPoint = (CGpsPoint*)mSaveRecePointList.GetPrev(pos);
  1691. if(pPoint != NULL) {
  1692. cRect.left  = pPoint->m_lx - CarMap.Width () / 2;
  1693. cRect.right  = pPoint->m_lx + CarMap.Width () / 2;
  1694. cRect.top  = pPoint->m_ly - CarMap.Height() / 2;
  1695. cRect.bottom = pPoint->m_ly + CarMap.Height() / 2;
  1696. RedrawInvalidRect(cRect,pDC,true);
  1697. CarMap.DrawTransparentInRect(*pDC,0,&cRect,NULL,0); //装入汽车位图
  1698. CPoint point;
  1699. point.x = pPoint->m_lx;
  1700. point.y = pPoint->m_ly;
  1701. if(!pPoint->m_sVehicleNO.IsEmpty()) {
  1702. DrawStr(pDC,point,pPoint->m_sVehicleNO);
  1703. }
  1704. }
  1705. }
  1706. CarMap.Clear();
  1707. #endif
  1708. }
  1709. void CGpsDrawMap::MoveScrollBar(long x,long y)
  1710. {
  1711. CGpsSCView *pView = ((CGpsSCView*)m_pCurrView);
  1712. CSize scrollsize = pView->GetTotalSize();
  1713. int hscrollpos[5],vscrollpos[4];
  1714. for(int i=0;i<5;i++)
  1715. hscrollpos[i] = scrollsize.cx/5*(i+1);// - scrollsize.cx/15;
  1716. for(i=0;i<4;i++)
  1717. vscrollpos[i]= scrollsize.cy/4*(i+1);// - scrollsize.cy/15 ;
  1718. if(x>=hscrollpos[0]&& x<=hscrollpos[1])
  1719. pView->SetScrollPos(SB_HORZ,hscrollpos[0],TRUE);
  1720. else if(x>hscrollpos[1]&& x<=hscrollpos[2])
  1721. pView->SetScrollPos(SB_HORZ,hscrollpos[1],TRUE);
  1722. else if(x>hscrollpos[2]&& x<=hscrollpos[3])
  1723. pView->SetScrollPos(SB_HORZ,hscrollpos[2],TRUE);
  1724. else if(x>hscrollpos[3]&& x<=hscrollpos[4])
  1725. pView->SetScrollPos(SB_HORZ,hscrollpos[3],TRUE);
  1726. else if(x>hscrollpos[4]&& x<=hscrollpos[5])
  1727. pView->SetScrollPos(SB_HORZ,hscrollpos[4],TRUE);
  1728. else
  1729. pView->SetScrollPos(SB_HORZ,0,TRUE);
  1730. if(y>=vscrollpos[0] && y<=vscrollpos[1])
  1731. pView->SetScrollPos(SB_VERT,vscrollpos[0]);
  1732. else if(y>vscrollpos[1] && y<=vscrollpos[2])
  1733. pView->SetScrollPos(SB_VERT,vscrollpos[1]);
  1734. else if(y>vscrollpos[2] && y<=vscrollpos[3])
  1735. pView->SetScrollPos(SB_VERT,vscrollpos[2]);
  1736. else if(y>vscrollpos[3] && y<=vscrollpos[4])
  1737. pView->SetScrollPos(SB_VERT,vscrollpos[3]);
  1738. else
  1739. pView->SetScrollPos(SB_VERT,0,TRUE);
  1740. }
  1741. /***********Draw icon***********/
  1742. void CGpsDrawMap::DrawIcon(CDC *pDC,CPoint point,CString IconName)
  1743. {
  1744. CRect cRect;
  1745. CString IconPath;
  1746. CBmpProc IconMap;
  1747. IconMap.LoadFromFile(IconName);
  1748. cRect.top  = point.y - IconMap.Height() / 2;
  1749. cRect.bottom = point.y + IconMap.Height() / 2;
  1750. cRect.left  = point.x - IconMap.Width () / 2;
  1751. cRect.right  = point.x + IconMap.Width () / 2;
  1752. IconMap.DrawTransparentInRect(*pDC,0,&cRect,NULL,0); //装入标志物图标
  1753. }
  1754. //在NE中国范围内即为有效
  1755. BYTE CGpsDrawMap::IsValidNE(double gx,double gy)
  1756. {
  1757. double MinN,MinE,MaxN,MaxE;
  1758. BYTE Invalid = 0;
  1759. MinN = 7310.0000; MinE = 6060.0080;
  1760. MaxN = 13530.0000; MaxE = 1810.0000;
  1761. if(((gx - MinN >= 0.0) && (gx - MaxN <= 0.0)) &&
  1762.    ((gy - MinE <= 0.0) && (gy - MaxE >= 0.0))) {
  1763. Invalid = 1;
  1764. }
  1765. return Invalid;
  1766. }
  1767. void CGpsDrawMap::GetView(CView *pView)
  1768. {
  1769. m_pCurrView = pView;
  1770. }
  1771. void CGpsDrawMap::FreshWnd()
  1772. {
  1773. ((CGpsSCView*)m_pCurrView)->Invalidate();
  1774. }
  1775. BYTE CGpsDrawMap::CheckMapIsChange(double gx,double gy)
  1776. {
  1777. CGpsLinkStruct cLink;
  1778. BYTE IsChange;
  1779. if(!IsValidNE(gx,gy)) return 0;
  1780. if(!GetCurrLinkLib(&mLinkList,&cLink,gx,gy)) return 0;
  1781. if(CompareTwoArr(cLink.m_LinkLibName,m_cCurrMapInfo.m_LinkFileName) != 1) {
  1782. IsChange = 1;
  1783. GetCurrMapInfo(&cLink,&m_cCurrMapInfo);
  1784. ((CGpsSCView*)m_pCurrView)->m_bMapIsDrawed = false;
  1785. ((CGpsSCView*)m_pCurrView)->Invalidate();
  1786. }
  1787. else {
  1788. IsChange = 0;
  1789. ((CGpsSCView*)m_pCurrView)->Invalidate();
  1790. }
  1791. return IsChange;
  1792. }
  1793. void CGpsDrawMap::ClearSaveInvalidRectColor()
  1794. {
  1795. BYTE i,j;
  1796. for(i = 0; i < 40; i++) {
  1797. for(j = 0; j < 40; j++) {
  1798. SaveInvalidRectColor[i][j] = 0;
  1799. }
  1800. }
  1801. }
  1802. void CGpsDrawMap::ReCalcPointXY(CObList *PointList)
  1803. {
  1804. CGpsPoint *pPoint = NULL;
  1805. POSITION pos;
  1806. pos = PointList->GetTailPosition();
  1807. while(pos != NULL) {
  1808. pPoint = (CGpsPoint*)PointList->GetPrev(pos);
  1809. CovertNEXY(pPoint, m_cCurrMapInfo.CoeffNE_XY, true);
  1810. }
  1811. }
  1812. //Draw Fat Map ...
  1813. void CGpsDrawMap::DrawFatMap(CDC *pDC)
  1814. {
  1815. CGpsLinkStruct cLink;
  1816. RefreshMapWnd();
  1817. if(!GetDataLib(m_cCurrMapInfo.m_DataFileName)) return ;
  1818. m_cCurrMapInfo.ClearSignList();
  1819. GetSignLib(m_cCurrMapInfo.m_SignFileName,&m_cCurrMapInfo.lCurrSignList);
  1820. ReDraw(pDC);
  1821. // ClearPointList(&mSaveRecePointList);
  1822. ReCalcPointXY(&mSaveRecePointList);
  1823. ClearSaveInvalidRectColor();
  1824. }
  1825. void CGpsDrawMap::DrawSignLib(CDC *pDC)
  1826. {
  1827. CGpsSignObject *pSign;
  1828. POSITION pos;
  1829. CString SignName;
  1830. CPoint point;
  1831. pos  = m_cCurrMapInfo.lCurrSignList.GetTailPosition();
  1832. while(pos != NULL) {
  1833. pSign  = (CGpsSignObject*)m_cCurrMapInfo.lCurrSignList.GetPrev(pos);
  1834. if((pSign->m_bySignType == m_ShowSign.bShowBuilding) ||
  1835.    (pSign->m_bySignType == m_ShowSign.bShowHotel)    ||
  1836.        (pSign->m_bySignType == m_ShowSign.bShowCompany)  ||
  1837.    (pSign->m_bySignType == m_ShowSign.bShowAmuse)    ||
  1838.    (pSign->m_bySignType == m_ShowSign.bShowPlaceName)||
  1839.    (pSign->m_bySignType == m_ShowSign.bShowGovern)   ||
  1840.    (pSign->m_bySignType == m_ShowSign.bShowTraffic)  ||
  1841.    (pSign->m_bySignType == m_ShowSign.bShowShopping) ||
  1842.    (pSign->m_bySignType == m_ShowSign.bShowEducation)||
  1843.    (pSign->m_bySignType == m_ShowSign.bShowHospital) ||
  1844.    (pSign->m_bySignType == m_ShowSign.bShowBureau)   ||
  1845.    (pSign->m_bySignType == m_ShowSign.bShowOil)) {
  1846. // if(!pSign->m_bDraw) continue;
  1847. SignName = pSign->m_pSignObjectName;
  1848. point.x = pSign->m_lx; point.y = pSign->m_ly;
  1849. DrawIcon(pDC,point,pSign->m_sIconName);
  1850. DrawStr(pDC,point,SignName);
  1851. }
  1852. }
  1853. }
  1854. void CGpsDrawMap::DrawOneSignPoint(CDC *pDC)
  1855. {
  1856. // if(pDispOneSign == NULL) return;
  1857. CString SignName;
  1858. CPoint point;
  1859. SignName = pDispOneSign.m_pSignObjectName;
  1860. point.x = pDispOneSign.m_lx; point.y = pDispOneSign.m_ly;
  1861. DrawIcon(pDC,point,pDispOneSign.m_sIconName);
  1862. DrawStr(pDC,point,SignName);
  1863. }
  1864. void CGpsDrawMap::ReDraw(CDC *pDC)
  1865. {
  1866. DrawColorBlock(&m_cCurrMapInfo.lCurrColorBList,pDC);
  1867. DrawRoad(&m_cCurrMapInfo.lCurrRoadList,pDC);
  1868. DrawRoadName(&m_cCurrMapInfo.lCurrRoadList,pDC);
  1869. }
  1870. void CGpsDrawMap::SwapTwoVar(long &a, long &b)
  1871. {
  1872. long SwapVar;
  1873. SwapVar = a;
  1874. a = b;
  1875. b = SwapVar;
  1876. }
  1877. BYTE CGpsDrawMap::PointOnLineNE(long SY, long SX, long EY, long EX, long NY, long NX, long K)
  1878. {
  1879.     long W, H;
  1880.     long MaxN, MaxE, MinN, MinE;
  1881.     W = abs(SX - EX);
  1882.     H = abs(SY - EY);
  1883.     if (H > W) {
  1884. /* Y-majored */
  1885. MaxN = Max(SY, EY);
  1886. MinN = Min(SY, EY);
  1887. MaxE = Max(SX, EX) + K;
  1888. MinE = Min(SX, EX) - K;
  1889.     }
  1890.     else {
  1891. /* X-majored */
  1892. MaxN = Max(SY, EY) + K;
  1893. MinN = Min(SY, EY) - K;
  1894. MaxE = Max(SX, EX);
  1895. MinE = Min(SX, EX);
  1896.     }
  1897.     return (NX > MinE && NX < MaxE && NY > MinN && NY < MaxN);
  1898. }
  1899. long CGpsDrawMap::DistanceToLine(long SY, long SX, long EY, long EX, long NY, long NX)
  1900. {
  1901.     long W, H, Ha, dY, f;
  1902.     /*
  1903.      ** always draws from small X to large X
  1904.      */
  1905.     if (SX > EX) {
  1906. SwapTwoVar(SX, EX);
  1907. SwapTwoVar(SY, EY);
  1908.     }
  1909.     /*
  1910.      ** we might want to clip the line here
  1911.      */
  1912.     W = (EX - SX);
  1913.     H = (EY - SY);
  1914.     Ha = (H < 0) ? -H : H;
  1915.     dY = (H < 0) ? -1 : 1;
  1916.     if (Ha > W) {
  1917. if (NY > Max(SY, EY) || NY < Min(SY, EY)) return GPS_INFINITE;
  1918.     }
  1919.     else {
  1920. if (NX > Max(SX, EX) || NX < Min(SX, EX)) return GPS_INFINITE;
  1921.     }
  1922.     if (Ha > W) {
  1923. /* Y-majored */
  1924. f = 0;
  1925. while (1) {
  1926. if (SY == NY) {
  1927. return ((long)abs(SX - NX));
  1928. }
  1929. if (SY == EY)
  1930. break;
  1931. if ((f += W) >= Ha) {
  1932. f -= Ha;
  1933. SX++;
  1934. }
  1935. SY += dY;
  1936. }
  1937.     }
  1938. else {
  1939. /* X-majored */
  1940. f = 0;
  1941. while (1) {
  1942. if (SX == NX) {
  1943. return ((long)abs(SY - NY));
  1944. }
  1945. if (SX == EX)
  1946. break;
  1947. if ((f += Ha) >= W) {
  1948. f -= W;
  1949. SY += dY;
  1950. }
  1951. SX++;
  1952. }
  1953.     }
  1954.     return GPS_INFINITE;
  1955. }
  1956. long CGpsDrawMap::CalcPointToOneRoadDist(CPoint point,CSmallRoadStruct *pSmall)
  1957. {
  1958. CRoadPoint *pRoadPoint;
  1959. CPoint sp,ep;
  1960. POSITION pos;
  1961. long d,Dist = GPS_INFINITE;
  1962. bool Flag = false;
  1963. pos = pSmall->RoadPointList.GetTailPosition();
  1964. while(pos != NULL) {
  1965. pRoadPoint = (CRoadPoint*)pSmall->RoadPointList.GetPrev(pos);
  1966. ep.x = pRoadPoint->m_lx; ep.y = pRoadPoint->m_ly;
  1967. if(!Flag) {
  1968. Flag = true;
  1969. sp = ep;
  1970. continue;
  1971. }
  1972. if(!PointOnLineNE(sp.y,sp.x,ep.y,ep.x,point.y,point.x,100)) continue;
  1973. d = DistanceToLine(sp.y,sp.x,ep.y,ep.x,point.y,point.x);
  1974. if(d < Dist) {
  1975. Dist = d;
  1976. }
  1977. sp = ep;
  1978. }
  1979. return Dist;
  1980. }
  1981. CString CGpsDrawMap::SearchRoad(const CPoint point,CString &RoadSn)
  1982. {
  1983. CSmallRoadStruct *pSmall;
  1984. CGpsRoadStruct *pRoad;
  1985. POSITION pos,pos1;
  1986. CString RoadName(""),Name;
  1987. long d,Dist = GPS_INFINITE;
  1988. pos = m_cCurrMapInfo.lCurrRoadList.GetTailPosition();
  1989. while(pos != NULL) {
  1990. pRoad  = (CGpsRoadStruct*)m_cCurrMapInfo.lCurrRoadList.GetPrev(pos);
  1991. pos1   = pRoad->SmallRoadList.GetTailPosition();
  1992. while(pos1 != NULL) {
  1993. pSmall = (CSmallRoadStruct*)pRoad->SmallRoadList.GetPrev(pos1);
  1994. Name = pSmall->RoadName;
  1995. if(Name.IsEmpty()) continue;
  1996. d = CalcPointToOneRoadDist(point,pSmall);
  1997. if(d < Dist) {
  1998. Dist = d;
  1999. RoadName = Name;
  2000. }
  2001. }
  2002. }
  2003. return RoadName;
  2004. }
  2005. CString CGpsDrawMap::GetMapInfoByNE(double gx,double gy,BYTE SignType,BYTE InfoType)
  2006. {
  2007. CString RelatedInfo("没有找到相关信息!");
  2008. if(InfoType == 2) {
  2009. return RelatedInfo;
  2010. }
  2011. if(!IsValidNE(gx,gy)) return RelatedInfo;
  2012. CGpsSignObject *pSign = NULL,*pMin = NULL;
  2013. POSITION pos;
  2014. CGpsPoint cPoint;
  2015. CPoint p1,p2;
  2016. CString SignName,RoadName,RoadSn;
  2017. long Dist = GPS_INFINITE,d;
  2018. bool Flag;
  2019. cPoint.m_dgx = gx;
  2020. cPoint.m_dgy = gy;
  2021. CovertNEXY(&cPoint, m_cCurrMapInfo.CoeffNE_XY, true);
  2022. p1.x = cPoint.m_lx; p1.y = cPoint.m_ly;
  2023. Flag = false;
  2024. pos  = m_cCurrMapInfo.lCurrSignList.GetTailPosition();
  2025. while(pos != NULL) {
  2026. pSign  = (CGpsSignObject*)m_cCurrMapInfo.lCurrSignList.GetPrev(pos);
  2027. if((pSign->m_bySignType != SignType) && (SignType != 0)) continue;
  2028. if((abs(pSign->m_lx - cPoint.m_lx) < 100) && 
  2029.    (abs(pSign->m_ly - cPoint.m_ly) < 100)) {
  2030. p2.x = pSign->m_lx; p2.y = pSign->m_ly;
  2031. d = CalcTwoPointDist(p1,p2);
  2032. if(d < Dist) {
  2033. Dist = d;
  2034. SignName = pSign->m_pSignObjectName;
  2035. Flag = true;
  2036. pMin = pSign;
  2037. }
  2038. }
  2039. }
  2040. if(Flag) pMin->m_bDraw = true;
  2041. RoadName = SearchRoad(p1,RoadSn);
  2042. if(Flag && (!RoadName.IsEmpty())) {
  2043. RelatedInfo.Format("您现在在%s,%s附近!",RoadName,SignName);
  2044. }
  2045. else if(Flag) {
  2046. RelatedInfo.Format("您现在在%s附近!",SignName);
  2047. }
  2048. else if(!RoadName.IsEmpty()) {
  2049. RelatedInfo.Format("您现在在%s!",RoadName);
  2050. }
  2051. return RelatedInfo;
  2052. }
  2053. #if 0
  2054. //void zoom in
  2055. void CGpsDrawMap::ZoomDown()
  2056. {
  2057. if(m_byZoomCoeffic == 1) return;
  2058. m_cCurrMapInfo.m_lWnd_Max_X = m_cCurrMapInfo.m_lWnd_Max_X / m_byZoomCoeffic;
  2059. m_cCurrMapInfo.m_lWnd_Max_Y = m_cCurrMapInfo.m_lWnd_Max_Y / m_byZoomCoeffic;
  2060. m_byZoomCoeffic = m_byZoomCoeffic / 2;
  2061. if(m_byZoomCoeffic < 1) m_byZoomCoeffic = 1;
  2062. m_cCurrMapInfo.m_lWnd_Max_X = m_cCurrMapInfo.m_lWnd_Max_X * m_byZoomCoeffic;
  2063. m_cCurrMapInfo.m_lWnd_Max_Y = m_cCurrMapInfo.m_lWnd_Max_Y * m_byZoomCoeffic;
  2064. ((CGpsSCView*)m_pCurrView)->SetScrollSizes(MM_TEXT, CSize(m_cCurrMapInfo.m_lWnd_Max_X, m_cCurrMapInfo.m_lWnd_Max_Y));
  2065. RefreshMapWnd();
  2066. CalcAllPointXY();
  2067. ((CGpsSCView*)m_pCurrView)->m_bMapIsDrawed = false;
  2068. ((CGpsSCView*)m_pCurrView)->Invalidate();
  2069. }
  2070. //zoon out
  2071. void CGpsDrawMap::ZoomUp()
  2072. {
  2073. if(m_byZoomCoeffic == 8) return;
  2074. m_cCurrMapInfo.m_lWnd_Max_X = m_cCurrMapInfo.m_lWnd_Max_X / m_byZoomCoeffic;
  2075. m_cCurrMapInfo.m_lWnd_Max_Y = m_cCurrMapInfo.m_lWnd_Max_Y / m_byZoomCoeffic;
  2076. m_byZoomCoeffic *= 2;
  2077. if(m_byZoomCoeffic > 8) m_byZoomCoeffic = 8;
  2078. m_cCurrMapInfo.m_lWnd_Max_X = m_cCurrMapInfo.m_lWnd_Max_X * m_byZoomCoeffic;
  2079. m_cCurrMapInfo.m_lWnd_Max_Y = m_cCurrMapInfo.m_lWnd_Max_Y * m_byZoomCoeffic;
  2080. ((CGpsSCView*)m_pCurrView)->SetScrollSizes(MM_TEXT, CSize(m_cCurrMapInfo.m_lWnd_Max_X, m_cCurrMapInfo.m_lWnd_Max_Y));
  2081. RefreshMapWnd();
  2082. CalcAllPointXY();
  2083. ((CGpsSCView*)m_pCurrView)->m_bMapIsDrawed = false;
  2084. ((CGpsSCView*)m_pCurrView)->Invalidate();
  2085. }
  2086. #else
  2087. void CGpsDrawMap::DispOtherLevelMap()
  2088. {
  2089. if(mSaveRecePointList.GetCount() == 0) return;
  2090. ClearLinkList(&mLinkList);
  2091. GetLinkList(&mLinkList,gCurrMapLevel);
  2092. CGpsPoint *pPoint = NULL;
  2093. pPoint = (CGpsPoint*)mSaveRecePointList.GetHead();
  2094. CheckMapIsChange(pPoint->m_dgx,pPoint->m_dgy);
  2095. CGpsLinkStruct cLink;
  2096. RefreshMapWnd();
  2097. if(!GetDataLib(m_cCurrMapInfo.m_DataFileName)) return ;
  2098. }
  2099. //void zoom in
  2100. void CGpsDrawMap::ZoomDown()
  2101. {
  2102. BYTE SaveCoeff = m_byZoomCoeffic;
  2103. if(m_byZoomCoeffic == 1) {
  2104. if(gCurrMapLevel > 1) {
  2105. gCurrMapLevel--;
  2106. m_byZoomCoeffic = 2;
  2107. DispOtherLevelMap();
  2108. }
  2109. }
  2110. else {
  2111. // m_cCurrMapInfo.m_lWnd_Max_X = m_cCurrMapInfo.m_lWnd_Max_X / m_byZoomCoeffic;
  2112. // m_cCurrMapInfo.m_lWnd_Max_Y = m_cCurrMapInfo.m_lWnd_Max_Y / m_byZoomCoeffic;
  2113. m_byZoomCoeffic = m_byZoomCoeffic / 2;
  2114. if(m_byZoomCoeffic < 1) m_byZoomCoeffic = 1;
  2115. }
  2116. m_cCurrMapInfo.m_lWnd_Max_X = m_cCurrMapInfo.m_lWnd_Max_X / SaveCoeff;
  2117. m_cCurrMapInfo.m_lWnd_Max_Y = m_cCurrMapInfo.m_lWnd_Max_Y / SaveCoeff;
  2118. m_cCurrMapInfo.m_lWnd_Max_X = m_cCurrMapInfo.m_lWnd_Max_X * m_byZoomCoeffic;
  2119. m_cCurrMapInfo.m_lWnd_Max_Y = m_cCurrMapInfo.m_lWnd_Max_Y * m_byZoomCoeffic;
  2120. ((CGpsSCView*)m_pCurrView)->SetScrollSizes(MM_TEXT, CSize(m_cCurrMapInfo.m_lWnd_Max_X, m_cCurrMapInfo.m_lWnd_Max_Y));
  2121. RefreshMapWnd();
  2122. CalcAllPointXY();
  2123. ((CGpsSCView*)m_pCurrView)->m_bMapIsDrawed = false;
  2124. ((CGpsSCView*)m_pCurrView)->Invalidate();
  2125. }
  2126. //zoon out
  2127. void CGpsDrawMap::ZoomUp()
  2128. {
  2129. BYTE SaveCoeff = m_byZoomCoeffic;
  2130. if((m_byZoomCoeffic == 2) && (gCurrMapLevel < 6)) {
  2131. if(gCurrMapLevel < 6) {
  2132. gCurrMapLevel++;
  2133. m_byZoomCoeffic = 1;
  2134. DispOtherLevelMap();
  2135. }
  2136. }
  2137. else {
  2138. // m_cCurrMapInfo.m_lWnd_Max_X = m_cCurrMapInfo.m_lWnd_Max_X / m_byZoomCoeffic;
  2139. // m_cCurrMapInfo.m_lWnd_Max_Y = m_cCurrMapInfo.m_lWnd_Max_Y / m_byZoomCoeffic;
  2140. m_byZoomCoeffic *= 2;
  2141. if(m_byZoomCoeffic > 2) m_byZoomCoeffic = 2;
  2142. }
  2143. m_cCurrMapInfo.m_lWnd_Max_X = m_cCurrMapInfo.m_lWnd_Max_X / SaveCoeff;
  2144. m_cCurrMapInfo.m_lWnd_Max_Y = m_cCurrMapInfo.m_lWnd_Max_Y / SaveCoeff;
  2145. m_cCurrMapInfo.m_lWnd_Max_X = m_cCurrMapInfo.m_lWnd_Max_X * m_byZoomCoeffic;
  2146. m_cCurrMapInfo.m_lWnd_Max_Y = m_cCurrMapInfo.m_lWnd_Max_Y * m_byZoomCoeffic;
  2147. ((CGpsSCView*)m_pCurrView)->SetScrollSizes(MM_TEXT, CSize(m_cCurrMapInfo.m_lWnd_Max_X, m_cCurrMapInfo.m_lWnd_Max_Y));
  2148. RefreshMapWnd();
  2149. CalcAllPointXY();
  2150. ((CGpsSCView*)m_pCurrView)->m_bMapIsDrawed = false;
  2151. ((CGpsSCView*)m_pCurrView)->Invalidate();
  2152. }
  2153. #endif
  2154. void CGpsDrawMap::ReCalcRoadXY(CObList *RoadList)
  2155. {
  2156. CGpsRoadStruct *pRoad;
  2157. CSmallRoadStruct *pSmall;
  2158. POSITION pos,pos1;
  2159. pos = RoadList->GetTailPosition();
  2160. while(pos != NULL) {
  2161. pRoad = (CGpsRoadStruct*)RoadList->GetPrev(pos);
  2162. pos1 = pRoad->SmallRoadList.GetTailPosition();
  2163. while(pos1 != NULL) {
  2164. pSmall = (CSmallRoadStruct*)pRoad->SmallRoadList.GetPrev(pos1);
  2165. ReCalcPointXY(&pSmall->RoadPointList);
  2166. }
  2167. }
  2168. }
  2169. void CGpsDrawMap::ReCalcColorBXY(CObList *ColorBList)
  2170. {
  2171. CGpsColorBlock *pBlock;
  2172. POSITION pos;
  2173. pos = ColorBList->GetTailPosition();
  2174. while(pos != NULL) {
  2175. pBlock = (CGpsColorBlock*)ColorBList->GetPrev(pos);
  2176. ReCalcPointXY(&pBlock->ColorBlockPointList);
  2177. }
  2178. }
  2179. void CGpsDrawMap::CalcAllPointXY()
  2180. {
  2181. ReCalcRoadXY(&m_cCurrMapInfo.lCurrRoadList);
  2182. ReCalcColorBXY(&m_cCurrMapInfo.lCurrColorBList);
  2183. ReCalcPointXY(&m_cCurrMapInfo.lCurrSignList);
  2184. ReCalcPointXY(&m_cCurrMapInfo.lCurrCrossList);
  2185. ReCalcPointXY(&mSaveRecePointList);
  2186. CovertNEXY(&pDispOneSign, m_cCurrMapInfo.CoeffNE_XY, true);
  2187. }
  2188. bool CGpsDrawMap::GetOneRoadPlain(CGpsRoadCrossPoint *pCross1,
  2189.  CGpsRoadCrossPoint *pCross2,
  2190.  CObList *RoadList,CString RoadSn,CObList *DstList)
  2191. {
  2192. CSmallRoadStruct *pSmall;
  2193. CGpsRoadStruct *pRoad;
  2194. CRoadPoint *pRoadPoint,*pPoint;
  2195. POSITION pos,pos1,pos2;
  2196. CString TempSn;
  2197. char Flag_SD;
  2198. short C1Pos = -1,C2Pos = -1,Pos;
  2199. bool Flag = false;
  2200. // AfxMessageBox(RoadSn);
  2201. pos = RoadList->GetTailPosition();
  2202. while(pos != NULL) {
  2203. pRoad  = (CGpsRoadStruct*)RoadList->GetPrev(pos);
  2204. TempSn.Format("%c%d",pRoad->BigRoad_Serial,pRoad->m_BigRoad_Number);
  2205. if(TempSn != RoadSn) continue;
  2206. // AfxMessageBox(RoadSn);
  2207. // if(RoadSn != "S87") continue;
  2208. Flag = true;
  2209. Pos  = 1;
  2210. pos1 = pRoad->SmallRoadList.GetTailPosition();
  2211. while(pos1 != NULL) {
  2212. pSmall  = (CSmallRoadStruct*)pRoad->SmallRoadList.GetPrev(pos1);
  2213. Flag_SD = (char)pSmall->Road_SD;
  2214. pos2 = pSmall->RoadPointList.GetTailPosition();
  2215. while(pos2 != NULL) {
  2216. pRoadPoint = (CRoadPoint*)pSmall->RoadPointList.GetPrev(pos2);
  2217. CString str;
  2218. str.Format("%d,%d;%d,%d",pRoadPoint->m_lx,pRoadPoint->m_ly,pCross1->m_lx,pCross1->m_ly);
  2219. // AfxMessageBox(str);
  2220. if((pRoadPoint->m_lx == pCross1->m_lx) && 
  2221.    (pRoadPoint->m_ly == pCross1->m_ly)) {
  2222. C1Pos = Pos;
  2223. // AfxMessageBox("a");
  2224. }
  2225. if((pRoadPoint->m_lx == pCross2->m_lx) &&
  2226.    (pRoadPoint->m_ly == pCross2->m_ly)) {
  2227. C2Pos = Pos;
  2228. // AfxMessageBox("b");
  2229. }
  2230. Pos++;
  2231. }
  2232. }
  2233. if(Flag) break;
  2234. }
  2235. if(!Flag) return false;
  2236. // AfxMessageBox("1");
  2237. if((C1Pos == -1) || (C2Pos == -1)) return false;
  2238. // AfxMessageBox("2");
  2239. bool IsSingle = false;
  2240. if(Flag_SD == 'S') {
  2241. if(C1Pos > C2Pos) return false;
  2242. // if(C1Pos > C2Pos) IsSingle = true;
  2243. }
  2244. // AfxMessageBox("3");
  2245. if(C1Pos > C2Pos) {
  2246. short Temp;
  2247. Temp  = C1Pos;
  2248. C1Pos = C2Pos;
  2249. C2Pos = Temp;
  2250. }
  2251. Pos  = 1;
  2252. pos1 = pRoad->SmallRoadList.GetTailPosition();
  2253. while(pos1 != NULL) {
  2254. pSmall  = (CSmallRoadStruct*)pRoad->SmallRoadList.GetPrev(pos1);
  2255. pos2 = pSmall->RoadPointList.GetTailPosition();
  2256. while(pos2 != NULL) {
  2257. pRoadPoint = (CRoadPoint*)pSmall->RoadPointList.GetPrev(pos2);
  2258. if((Pos >= C1Pos) && (Pos <= C2Pos)) {
  2259. pPoint  = new CRoadPoint;
  2260. *pPoint = *pRoadPoint;
  2261. DstList->AddHead(pPoint);
  2262. }
  2263. Pos++;
  2264. }
  2265. }
  2266. CString str;
  2267. str.Format("Count = %d",DstList->GetCount());
  2268. // AfxMessageBox(str);
  2269. return true;
  2270. }
  2271. bool CGpsDrawMap::IsInvalidSn(CString RoadSn)
  2272. {
  2273. if(RoadSn == "x255") return true;
  2274. return false;
  2275. }
  2276. bool CGpsDrawMap::SimilarCross(CGpsRoadCrossPoint *C1,CGpsRoadCrossPoint *C2)
  2277. {
  2278. CString arrRoadSn[4];
  2279. BYTE i;
  2280. if((C1->m_lx != C2->m_lx) || (C1->m_ly != C2->m_ly)) return false;
  2281. arrRoadSn[0].Format("%c%d",C1->m_CrossRoad1_Serial,C1->m_CrossRoad1_Number);
  2282. arrRoadSn[1].Format("%c%d",C1->m_CrossRoad2_Serial,C1->m_CrossRoad2_Number);
  2283. arrRoadSn[2].Format("%c%d",C1->m_CrossRoad3_Serial,C1->m_CrossRoad3_Number);
  2284. arrRoadSn[3].Format("%c%d",C1->m_CrossRoad4_Serial,C1->m_CrossRoad4_Number);
  2285. for(i = 0; i < 4; i++) {
  2286. if(IsInvalidSn(arrRoadSn[i])) continue;
  2287. if(!RoadSnInCross(arrRoadSn[i],C2)) return false;
  2288. }
  2289. arrRoadSn[0].Format("%c%d",C2->m_CrossRoad1_Serial,C2->m_CrossRoad1_Number);
  2290. arrRoadSn[1].Format("%c%d",C2->m_CrossRoad2_Serial,C2->m_CrossRoad2_Number);
  2291. arrRoadSn[2].Format("%c%d",C2->m_CrossRoad3_Serial,C2->m_CrossRoad3_Number);
  2292. arrRoadSn[3].Format("%c%d",C2->m_CrossRoad4_Serial,C2->m_CrossRoad4_Number);
  2293. for(i = 0; i < 4; i++) {
  2294. if(IsInvalidSn(arrRoadSn[i])) continue;
  2295. if(!RoadSnInCross(arrRoadSn[i],C1)) return false;
  2296. }
  2297. return true;
  2298. }
  2299. bool CGpsDrawMap::GetOneRoadPoint(CObList *RoadList,CString RoadSn,CGpsRoadStruct *DstRoad)
  2300. {
  2301. CGpsRoadStruct *pRoad;
  2302. POSITION pos;
  2303. CString TempSn;
  2304. pos = RoadList->GetTailPosition();
  2305. while(pos != NULL) {
  2306. pRoad  = (CGpsRoadStruct*)RoadList->GetPrev(pos);
  2307. TempSn.Format("%c%d",pRoad->BigRoad_Serial,pRoad->m_BigRoad_Number);
  2308. if(TempSn != RoadSn) continue;
  2309. *DstRoad   = *pRoad;
  2310. return true;
  2311. }
  2312. return false;
  2313. }
  2314. bool CGpsDrawMap::RoadSnInCross(CString RoadSn,CGpsRoadCrossPoint *pCross)
  2315. {
  2316. CString TempSn;
  2317. TempSn.Format("%c%d",pCross->m_CrossRoad1_Serial,pCross->m_CrossRoad1_Number);
  2318. if(TempSn == RoadSn) return true;
  2319. TempSn.Format("%c%d",pCross->m_CrossRoad2_Serial,pCross->m_CrossRoad2_Number);
  2320. if(TempSn == RoadSn) return true;
  2321. TempSn.Format("%c%d",pCross->m_CrossRoad3_Serial,pCross->m_CrossRoad3_Number);
  2322. if(TempSn == RoadSn) return true;
  2323. TempSn.Format("%c%d",pCross->m_CrossRoad4_Serial,pCross->m_CrossRoad4_Number);
  2324. if(TempSn == RoadSn) return true;
  2325. return false;
  2326. }
  2327. bool CGpsDrawMap::GetPointInListEx(CPoint point,CString RoadSn,CObList *CrossList,CGpsRoadCrossPoint *pPoint,BYTE Bound)
  2328. {
  2329. CGpsRoadCrossPoint *pGpsPoint;
  2330. bool ret = false;
  2331. POSITION pos;
  2332. CString TempSn;
  2333. pos = CrossList->GetHeadPosition();
  2334. while(pos != NULL)
  2335. {
  2336. pGpsPoint = (CGpsRoadCrossPoint*)CrossList->GetNext(pos);
  2337. TempSn.Format("%c%d",pGpsPoint->m_CrossRoad1_Serial,pGpsPoint->m_CrossRoad1_Number);
  2338. if(TempSn != RoadSn) continue;
  2339. if((abs(point.x - pGpsPoint->m_lx) < Bound) && 
  2340.    (abs(point.y - pGpsPoint->m_ly) < Bound)) { //捕获范围
  2341. *pPoint = *pGpsPoint; 
  2342. ret = true;
  2343. break;
  2344. }
  2345. }
  2346. return ret;
  2347. }
  2348. bool CGpsDrawMap::GetOneBRCrossPoint(CPoint point,CObList *RoadList,CObList *CrossList,
  2349.  CString Sn,CBRCrossStruct *pDstCross,CObList *SavePoint)
  2350. {
  2351. CGpsRoadStruct *pRoad;
  2352. CSmallRoadStruct *pSmall;
  2353. CRoadPoint *pRoadPoint;
  2354. CRoadPoint *pTempPoint;
  2355. POSITION pos,pos1,pos2;
  2356. CString RoadSn;
  2357. CPoint Epoint;
  2358. bool Result = false,Flag = false;
  2359. pos = RoadList->GetTailPosition();
  2360. while(pos != NULL) {
  2361. pRoad  = (CGpsRoadStruct*)RoadList->GetPrev(pos);
  2362. RoadSn.Format("%c%d",pRoad->BigRoad_Serial,pRoad->m_BigRoad_Number);
  2363. // if(RoadSn != Sn) continue;
  2364. pos1   = pRoad->SmallRoadList.GetTailPosition();
  2365. while(pos1 != NULL) {
  2366. pSmall = (CSmallRoadStruct*)pRoad->SmallRoadList.GetPrev(pos1);
  2367. pos2 = pSmall->RoadPointList.GetTailPosition();
  2368. while(pos2 != NULL) {
  2369. pRoadPoint = (CRoadPoint*)pSmall->RoadPointList.GetPrev(pos2);
  2370. if((abs(pRoadPoint->m_lx - point.x) < m_PointWidth * 10) && 
  2371.    (abs(pRoadPoint->m_ly - point.y) < m_PointWidth * 10)) {
  2372. Flag = true;
  2373. }
  2374. if(!Flag) continue;
  2375. pTempPoint = new CRoadPoint;
  2376. pTempPoint->m_lx = pRoadPoint->m_lx;
  2377. pTempPoint->m_ly = pRoadPoint->m_ly;
  2378. SavePoint->AddHead(pTempPoint);
  2379. if((pRoadPoint->OutOfMap == 3) || 
  2380.    (pRoadPoint->OutOfMap == 6) ||
  2381.    (pRoadPoint->OutOfMap == 8)) {
  2382. Epoint.x = pRoadPoint->m_lx; Epoint.y = pRoadPoint->m_ly;
  2383. Result = GetPointInListEx(Epoint,RoadSn,CrossList,&pDstCross->m_cCross,1);
  2384. if(Result) return true;
  2385. }
  2386. }
  2387. }
  2388. if(Flag) break;
  2389. }
  2390. return Result;
  2391. }
  2392. long CGpsDrawMap::CalcCrossVectorDist(CGpsRoadCrossPoint *StartPoint,CGpsRoadCrossPoint *EndPoint,
  2393.  CObList *RoadList)
  2394. {
  2395. CString arrRoadSn[4];
  2396. long Dist;
  2397. BYTE i;
  2398. arrRoadSn[0].Format("%c%d",StartPoint->m_CrossRoad1_Serial,StartPoint->m_CrossRoad1_Number);
  2399. arrRoadSn[1].Format("%c%d",StartPoint->m_CrossRoad2_Serial,StartPoint->m_CrossRoad2_Number);
  2400. arrRoadSn[2].Format("%c%d",StartPoint->m_CrossRoad3_Serial,StartPoint->m_CrossRoad3_Number);
  2401. arrRoadSn[3].Format("%c%d",StartPoint->m_CrossRoad4_Serial,StartPoint->m_CrossRoad4_Number);
  2402. for(i = 0; i < 4; i++) {
  2403. if(IsInvalidSn(arrRoadSn[i])) continue;
  2404. Dist = CalcCrossDistInRoadSn(StartPoint,EndPoint,RoadList,arrRoadSn[i]);
  2405. if(Dist != GPS_INFINITE) return Dist;
  2406. }
  2407. return GPS_INFINITE;
  2408. }
  2409. long CGpsDrawMap::CalcCrossDistInRoadSn(CGpsRoadCrossPoint *StartPoint,CGpsRoadCrossPoint *EndPoint,
  2410.    CObList *RoadList,CString RoadSn)
  2411. {
  2412. BYTE RoadDir,i;
  2413. long Dist;
  2414. if(!RoadSnInCross(RoadSn,StartPoint) || !RoadSnInCross(RoadSn,EndPoint)) return GPS_INFINITE;
  2415. if(SimilarCross(StartPoint,EndPoint)) return GPS_INFINITE;
  2416. if((StartPoint->m_lx == EndPoint->m_lx) && 
  2417.    (StartPoint->m_ly == EndPoint->m_ly)) {
  2418. return 0;
  2419. }
  2420. CGpsRoadStruct DstRoad;
  2421. CSmallRoadStruct *pSmall;
  2422. CRoadPoint *pRoadPoint,*pPoint;
  2423. CObList TempPointList;
  2424. POSITION pos1,pos2;
  2425. short StartPos = -1,EndPos = -1,Pos = 1;
  2426. if(!GetOneRoadPoint(RoadList,RoadSn,&DstRoad)) return GPS_INFINITE;
  2427. i  = 0;
  2428. pos1 = DstRoad.SmallRoadList.GetTailPosition();
  2429. while(pos1 != NULL) {
  2430. pSmall  = (CSmallRoadStruct*)DstRoad.SmallRoadList.GetPrev(pos1);
  2431. pos2 = pSmall->RoadPointList.GetTailPosition();
  2432. RoadDir = pSmall->Road_SD;
  2433. while(pos2 != NULL) {
  2434. pRoadPoint = (CRoadPoint*)DstRoad.SmallRoadList.GetPrev(pos2);
  2435. if((pRoadPoint->OutOfMap != 3) && 
  2436.    (pRoadPoint->OutOfMap != 6) &&
  2437.    (pRoadPoint->OutOfMap != 8)) continue;
  2438. if((pRoadPoint->m_lx == StartPoint->m_lx) && (pRoadPoint->m_ly == StartPoint->m_ly)) {
  2439. if(StartPos == -1) {
  2440. pRoadPoint->m_bIsModify = true;
  2441. StartPos = Pos;
  2442. }
  2443. }
  2444. if((pRoadPoint->m_lx == EndPoint->m_lx) && (pRoadPoint->m_ly == EndPoint->m_ly)) {
  2445. if(EndPos == -1) {
  2446. pRoadPoint->m_bIsModify = true;
  2447. EndPos = Pos;
  2448. }
  2449. }
  2450. Pos++;
  2451. }
  2452. }
  2453. if((StartPos == -1) || (EndPos == -1)) return GPS_INFINITE;
  2454. if(RoadDir == 'S') {
  2455. if(StartPos > EndPos) return GPS_INFINITE;
  2456. }
  2457. i  = 0;
  2458. pos1 = DstRoad.SmallRoadList.GetTailPosition();
  2459. while(pos1 != NULL) {
  2460. pSmall  = (CSmallRoadStruct*)DstRoad.SmallRoadList.GetPrev(pos1);
  2461. pos2 = pSmall->RoadPointList.GetTailPosition();
  2462. while(pos2 != NULL) {
  2463. pRoadPoint = (CRoadPoint*)DstRoad.SmallRoadList.GetPrev(pos2);
  2464. if(pRoadPoint->m_bIsModify) i++;
  2465. if(i == 1) {
  2466. pPoint  = new CRoadPoint;
  2467. *pPoint = *pRoadPoint;
  2468. TempPointList.AddHead(pPoint);
  2469. }
  2470. if(i >= 2) break;
  2471. }
  2472. if(i >= 2) break;
  2473. }
  2474. Dist = CalculateOneRoadVD(&TempPointList);
  2475. m_cCurrMapInfo.ClearPointList(&TempPointList);
  2476. return Dist;
  2477. }
  2478. long CGpsDrawMap::CalculateTwoPointDistance(CPoint PrevP,CPoint CurrP)
  2479. {
  2480. long dx,dy,Distance;
  2481. dx = abs(PrevP.x - CurrP.x);
  2482. dy = abs(PrevP.y - CurrP.y);
  2483. Distance = (long)sqrt(Square(dx) + Square(dy));
  2484. return Distance;
  2485. }
  2486. long CGpsDrawMap::CalculateOneRoadVD(CObList *PlainList)
  2487. {
  2488. CRoadPoint *pRoadPoint;
  2489. POSITION pos;
  2490. CPoint PrevP,CurrP;
  2491. long Distance = 0;
  2492. bool Flag = false;
  2493. pos = PlainList->GetTailPosition();
  2494. while(pos != NULL) {
  2495. pRoadPoint = (CRoadPoint*)PlainList->GetPrev(pos);
  2496. CurrP.x = pRoadPoint->m_lx; CurrP.y = pRoadPoint->m_ly;
  2497. if(Flag) {
  2498. Distance += CalculateTwoPointDistance(PrevP,CurrP);
  2499. // Distance += CalculateDist(PrevP,CurrP);
  2500. }
  2501. else {
  2502. Flag = true;
  2503. }
  2504. PrevP = CurrP;
  2505. }
  2506. if(!Flag) Distance = GPS_INFINITE;
  2507. if(PlainList->GetCount() == 1) Distance = GPS_INFINITE;
  2508. return Distance;
  2509. }
  2510. bool CGpsDrawMap::SaveInitBRCross(CObList *CrossList,CObList *DstList)
  2511. {
  2512. CGpsRoadCrossPoint *pCross;
  2513. CBRCrossStruct *pBRCross,*pSave;
  2514. POSITION pos,pos1;
  2515. bool Flag;
  2516. pos = CrossList->GetTailPosition();
  2517. while(pos != NULL) {
  2518. pCross = (CGpsRoadCrossPoint*)CrossList->GetPrev(pos);
  2519. pos1   = DstList->GetTailPosition();
  2520. if(pos1  == NULL) {
  2521. pSave = new CBRCrossStruct;
  2522. pSave->m_cCross = *pCross;
  2523. // pSave->m_Adjust = 2;
  2524. // pSave->m_Distance = GPS_INFINITE;
  2525. // pSave->m_Double = 0;
  2526. DstList->AddHead(pSave);
  2527. continue;
  2528. }
  2529. Flag = false;
  2530. while(pos1  != NULL) {
  2531. pBRCross = (CBRCrossStruct*)DstList->GetPrev(pos1);
  2532. if(SimilarCross(&pBRCross->m_cCross,pCross)) {
  2533. pBRCross->m_Double = 1;
  2534. break;
  2535. Flag = true;
  2536. }
  2537. }
  2538. if(!Flag) {
  2539. pSave = new CBRCrossStruct;
  2540. pSave->m_cCross = *pCross;
  2541. // pSave->m_Adjust = 2;
  2542. // pSave->m_Distance = GPS_INFINITE;
  2543. // pSave->m_Double = 0;
  2544. DstList->AddHead(pSave);
  2545. }
  2546. }
  2547. if(DstList->GetCount() != 0) return true;
  2548. return false;
  2549. }
  2550. bool CGpsDrawMap::GetMinDistPoint(CObList *CrossList,CBRCrossStruct *MinCross)
  2551. {
  2552. CBRCrossStruct *pBRCross,*pMin;
  2553. POSITION pos;
  2554. long Distance = GPS_INFINITE;
  2555. pos = CrossList->GetTailPosition();
  2556. while(pos != NULL) {
  2557. pBRCross = (CBRCrossStruct*)CrossList->GetPrev(pos);
  2558. if(pBRCross->m_Adjust != 1) continue;
  2559. if(Distance > pBRCross->m_Distance) {
  2560. *MinCross = *pBRCross;
  2561. pMin = pBRCross;
  2562. Distance = pBRCross->m_Distance;
  2563. }
  2564. }
  2565. if(Distance == GPS_INFINITE) return false;
  2566. pMin->m_Adjust = 0;
  2567. return true;
  2568. }
  2569. bool CGpsDrawMap::CheckCrossSame(CGpsRoadCrossPoint *pC1,CGpsRoadCrossPoint *pC2)
  2570. {
  2571. bool Flag = false;
  2572. if( (pC1->m_CrossRoad1_Serial == pC2->m_CrossRoad1_Serial) &&
  2573. (pC1->m_CrossRoad1_Number == pC2->m_CrossRoad1_Number) &&
  2574. // (pC1->CrossRoad1_Level  == pC2->CrossRoad2_Level)  &&
  2575. (pC1->m_CrossRoad2_Serial == pC2->m_CrossRoad2_Serial) &&
  2576. (pC1->m_CrossRoad2_Number == pC2->m_CrossRoad2_Number) &&
  2577. // (pC1->CrossRoad2_Level  == pC2->CrossRoad2_Level)  &&
  2578. (pC1->m_CrossRoad3_Serial == pC2->m_CrossRoad3_Serial) &&
  2579. (pC1->m_CrossRoad3_Number == pC2->m_CrossRoad3_Number) &&
  2580. // (pC1->CrossRoad3_Level  == pC2->CrossRoad3_Level)  &&
  2581. (pC1->m_CrossRoad4_Serial == pC2->m_CrossRoad4_Serial) &&
  2582. (pC1->m_CrossRoad4_Number == pC2->m_CrossRoad4_Number) &&
  2583. // (pC1->CrossRoad4_Level  == pC2->CrossRoad4_Level)  &&
  2584. (pC1->m_lx == pC2->m_lx) && (pC1->m_ly == pC2->m_ly)) {
  2585. Flag = true;
  2586. }
  2587. return Flag;
  2588. }
  2589. bool CGpsDrawMap::HaveSaveOneRoadSn(CGpsRoadCrossPoint *pCross1,CGpsRoadCrossPoint *pCross2)
  2590. {
  2591. CString arrRoadSn[4];
  2592. BYTE i;
  2593. arrRoadSn[0].Format("%c%d",pCross1->m_CrossRoad1_Serial,pCross1->m_CrossRoad1_Number);
  2594. arrRoadSn[1].Format("%c%d",pCross1->m_CrossRoad2_Serial,pCross1->m_CrossRoad2_Number);
  2595. arrRoadSn[2].Format("%c%d",pCross1->m_CrossRoad3_Serial,pCross1->m_CrossRoad3_Number);
  2596. arrRoadSn[3].Format("%c%d",pCross1->m_CrossRoad4_Serial,pCross1->m_CrossRoad4_Number);
  2597. for(i = 0; i < 4; i++) {
  2598. if(IsInvalidSn(arrRoadSn[i])) continue;
  2599. if(RoadSnInCross(arrRoadSn[i],pCross2)) return true;
  2600. }
  2601. return false;
  2602. }
  2603. bool CGpsDrawMap::BRCrossInList(CBRCrossStruct *pBRCross,CObList *CrossList)
  2604. {
  2605. CBRCrossStruct *pCross;
  2606. POSITION pos;
  2607. pos = CrossList->GetTailPosition();
  2608. while(pos != NULL) {
  2609. pCross = (CBRCrossStruct*)CrossList->GetPrev(pos);
  2610. if(SimilarCross(&pBRCross->m_cCross,&pCross->m_cCross)) {
  2611. return true;
  2612. }
  2613. }
  2614. return false;
  2615. }
  2616. short CGpsDrawMap::BR_SaveOnePath(CGpsRoadCrossPoint *StartPoint,
  2617.  CGpsRoadCrossPoint *EndPoint,
  2618.  CObList *RoadList,CObList *CrossList,CObList *SavePathList)
  2619. {
  2620. CBRCrossStruct cMinCross,*pBRCross,*pSave,SimilarEnd;
  2621. CBRCrossStruct *pTempCross;
  2622. POSITION pos;
  2623. long Distance,RecordTimes = 0;
  2624. CObList TempCrossList;
  2625. short PathLen = 0;
  2626. bool Flag = false,Flag1 = false;
  2627. if(CheckCrossSame(StartPoint,EndPoint)) return 0;
  2628. if(!SaveInitBRCross(CrossList,&TempCrossList)) return 0;
  2629. pos = TempCrossList.GetTailPosition();
  2630. while(pos != NULL) {
  2631. pBRCross = (CBRCrossStruct*)TempCrossList.GetPrev(pos);
  2632. if(SimilarCross(&pBRCross->m_cCross,StartPoint)) {
  2633. pBRCross->m_Adjust = 1;
  2634. pBRCross->m_Distance = 0;
  2635. Flag = true;
  2636. }
  2637. if(!Flag1) {
  2638. if(SimilarCross(&pBRCross->m_cCross,EndPoint)) {
  2639. SimilarEnd = *pBRCross;
  2640. Flag1 = true;
  2641. }
  2642. }
  2643. if(Flag && Flag1) break;
  2644. }
  2645. if((!Flag) || (!Flag1)) {
  2646. m_cCurrMapInfo.ClearBRoadSaveList(&TempCrossList);
  2647. return 0;
  2648. }
  2649. while(true) {
  2650. cMinCross.Clear();
  2651. if(!GetMinDistPoint(&TempCrossList,&cMinCross)) {
  2652. m_cCurrMapInfo.ClearBRoadSaveList(&TempCrossList);
  2653. return 0;
  2654. }
  2655. if(SimilarCross(&cMinCross.m_cCross,&SimilarEnd.m_cCross)) {
  2656. // if(CheckCrossSame(&cMinCross.m_cCross,&SimilarEnd.m_cCross)) {
  2657. break;
  2658. }
  2659. Distance = GPS_INFINITE;
  2660. pos = TempCrossList.GetTailPosition();
  2661. while(pos != NULL) {
  2662. pBRCross = (CBRCrossStruct*)TempCrossList.GetPrev(pos);
  2663. if(pBRCross->m_Adjust == 0) {
  2664. continue;
  2665. }
  2666. Distance = CalcCrossVectorDist(&cMinCross.m_cCross,
  2667.    &pBRCross->m_cCross,RoadList);
  2668. if(Distance == GPS_INFINITE) continue;
  2669. if(cMinCross.m_Distance  + Distance < pBRCross->m_Distance) {
  2670. pBRCross->m_Distance = cMinCross.m_Distance + Distance;
  2671. pBRCross->m_Adjust  = 1;
  2672. }
  2673. }
  2674. RecordTimes++;
  2675. if(RecordTimes > TempCrossList.GetCount() * 2) {
  2676. break;
  2677. }
  2678. }
  2679. PathLen = 0;
  2680. pos = TempCrossList.GetTailPosition();
  2681. while(pos != NULL) {
  2682. pBRCross = (CBRCrossStruct*)TempCrossList.GetPrev(pos);
  2683. // if(CheckCrossSame(&pBRCross->m_cCross,&SimilarEnd.m_cCross) && 
  2684. if(SimilarCross(&pBRCross->m_cCross,&SimilarEnd.m_cCross) && 
  2685.   (pBRCross->m_Distance != GPS_INFINITE)) {
  2686. pSave  = new CBRCrossStruct;
  2687. *pSave = *pBRCross;
  2688. SavePathList->AddHead(pSave);
  2689. PathLen++;
  2690. break;
  2691. }
  2692. }
  2693. if(PathLen == 0) {
  2694. m_cCurrMapInfo.ClearBRoadSaveList(&TempCrossList);
  2695. return 0;
  2696. }
  2697. Distance = GPS_INFINITE;
  2698. RecordTimes = 0;
  2699. while(true) {
  2700. // Distance = GPS_INFINITE;
  2701. pSave  = new CBRCrossStruct;
  2702. pTempCross  = (CBRCrossStruct*)SavePathList->GetHead();
  2703. pos = TempCrossList.GetTailPosition();
  2704. while(pos != NULL) {
  2705. pBRCross = (CBRCrossStruct*)TempCrossList.GetPrev(pos);
  2706. // if(BRCrossInList(pBRCross,SavePathList)) continue;
  2707. if(pBRCross->m_Distance == GPS_INFINITE) continue;
  2708. if(pBRCross->m_Adjust != 0) continue;
  2709. if(HaveSaveOneRoadSn(&pBRCross->m_cCross,&pTempCross->m_cCross)) {
  2710. if(pBRCross->m_Distance < Distance) {
  2711. *pSave = *pBRCross;
  2712. Distance = pBRCross->m_Distance;
  2713. }
  2714. }
  2715. }
  2716. if(Distance != GPS_INFINITE) {
  2717. SavePathList->AddHead(pSave);
  2718. PathLen++;
  2719. if((pSave->m_cCross.m_lx == StartPoint->m_lx) &&
  2720.    (pSave->m_cCross.m_ly == StartPoint->m_ly)) {
  2721. // if(SimilarCross(&pSave->m_cCross,StartPoint)) {
  2722. break;
  2723. }
  2724. }
  2725. else {
  2726. delete pSave;
  2727. }
  2728. if(RecordTimes > TempCrossList.GetCount()) break;
  2729. RecordTimes++;
  2730. }
  2731. if(RecordTimes > TempCrossList.GetCount()) {
  2732. m_cCurrMapInfo.ClearBRoadSaveList(SavePathList);
  2733. PathLen = 0;
  2734. }
  2735. m_cCurrMapInfo.ClearBRoadSaveList(&TempCrossList);
  2736. return PathLen;
  2737. }
  2738. long CGpsDrawMap::alculateDist(CPoint SP,CPoint EP)
  2739. {
  2740. long dx,dy,min;
  2741. dx = abs(SP.x - EP.x); dy = abs(SP.y - EP.y);
  2742. min = Min(dx,dy);
  2743. return (dx + dy - min / 2 - min / 4 + min / 8);
  2744. }
  2745. void CGpsDrawMap::WritePathToTxt(CObList *PathList)
  2746. {
  2747. CFile f;
  2748. if(!f.Open("Path.txt",CFile::modeCreate | CFile::modeReadWrite,NULL)) return;
  2749. CBRCrossStruct *pCross;
  2750. POSITION pos;
  2751. CString Str;
  2752. short PointTotal;
  2753. PointTotal = PathList->GetCount();
  2754. Str.Format("共经过 %d 个交叉点: %c%c",PointTotal,'r','n');
  2755. f.Write(Str,Str.GetLength());
  2756. pos = PathList->GetHeadPosition();
  2757. while(pos != NULL) {
  2758. pCross = (CBRCrossStruct*)PathList->GetNext(pos);
  2759. Str.Format("(%c%d,%c%d,%c%d,%c%d);(%d,%d);%d;%c%c",
  2760. pCross->m_cCross.m_CrossRoad1_Serial,
  2761. pCross->m_cCross.m_CrossRoad1_Number,
  2762. pCross->m_cCross.m_CrossRoad2_Serial,
  2763. pCross->m_cCross.m_CrossRoad2_Number,
  2764. pCross->m_cCross.m_CrossRoad3_Serial,
  2765. pCross->m_cCross.m_CrossRoad3_Number,
  2766. pCross->m_cCross.m_CrossRoad4_Serial,
  2767. pCross->m_cCross.m_CrossRoad4_Number,
  2768. pCross->m_cCross.m_lx,pCross->m_cCross.m_ly,pCross->m_Distance,
  2769. 'r','n');
  2770. f.Write(Str,Str.GetLength());
  2771. }
  2772. f.Close();
  2773. }
  2774. void CGpsDrawMap::WriteBRcross(CBRCrossStruct *pBRCross,CString FileName)
  2775. {
  2776. CFile f;
  2777. if(!f.Open(FileName,CFile::modeReadWrite,NULL)) {
  2778. if(!f.Open(FileName,CFile::modeCreate | CFile::modeReadWrite,NULL)) {
  2779. return;
  2780. }
  2781. }
  2782. f.SeekToEnd();
  2783. CString str;
  2784. str.Format("(x=%d;y=%d:Dist=%d:Adjust=%d);(%c%d,%c%d,%c%d,%c%d)%c%c",
  2785. pBRCross->m_cCross.m_lx,pBRCross->m_cCross.m_ly,
  2786. pBRCross->m_Distance,pBRCross->m_Adjust,
  2787. pBRCross->m_cCross.m_CrossRoad1_Serial,
  2788. pBRCross->m_cCross.m_CrossRoad1_Number,
  2789. pBRCross->m_cCross.m_CrossRoad2_Serial,
  2790. pBRCross->m_cCross.m_CrossRoad2_Number,
  2791. pBRCross->m_cCross.m_CrossRoad3_Serial,
  2792. pBRCross->m_cCross.m_CrossRoad3_Number,
  2793. pBRCross->m_cCross.m_CrossRoad4_Serial,
  2794. pBRCross->m_cCross.m_CrossRoad4_Number,
  2795. 'r','n');
  2796. // AfxMessageBox(str);
  2797. f.Write(str,str.GetLength());
  2798. f.Close();
  2799. }
  2800. void CGpsDrawMap::WriteCross(CGpsRoadCrossPoint *pCross,CString FileName)
  2801. {
  2802. CFile f;
  2803. if(!f.Open(FileName,CFile::modeReadWrite,NULL)) {
  2804. if(!f.Open(FileName,CFile::modeCreate | CFile::modeReadWrite,NULL)) {
  2805. return;
  2806. }
  2807. }
  2808. f.SeekToEnd();
  2809. CString str;
  2810. str.Format("(x=%d;y=%d);(%c%d,%c%d,%c%d,%c%d)%c%c",
  2811. pCross->m_lx,pCross->m_ly,
  2812. pCross->m_CrossRoad1_Serial,
  2813. pCross->m_CrossRoad1_Number,
  2814. pCross->m_CrossRoad2_Serial,
  2815. pCross->m_CrossRoad2_Number,
  2816. pCross->m_CrossRoad3_Serial,
  2817. pCross->m_CrossRoad3_Number,
  2818. pCross->m_CrossRoad4_Serial,
  2819. pCross->m_CrossRoad4_Number,
  2820. 'r','n');
  2821. // AfxMessageBox(str);
  2822. f.Write(str,str.GetLength());
  2823. f.Close();
  2824. }
  2825. void CGpsDrawMap::DrawBetweenBRCrossLine(CDC *pDC,CObList *SaveBRCrossList)
  2826. {
  2827. CBRCrossStruct *pCross,pPrevCross;
  2828. CObList TempList;
  2829. POSITION pos;
  2830. CString RoadSn("");
  2831. bool Flag = false;
  2832. DrawLineEx(pDC,&mSaveTempList1);
  2833. DrawLineEx(pDC,&mSaveTempList2);
  2834. pos = SaveBRCrossList->GetHeadPosition();
  2835. while(pos != NULL) {
  2836. pCross = (CBRCrossStruct*)SaveBRCrossList->GetNext(pos);
  2837. if(Flag) {
  2838. DrawBetweenCross(&pPrevCross.m_cCross,&pCross->m_cCross,&m_cCurrMapInfo.lCurrRoadList,pDC);
  2839. // if(!DrawBetweenCross(&pPrevCross.m_cCross,&pCross->m_cCross,&DispRoadList,pDC)) {
  2840. // ClearBRoadSaveList(SaveBRCrossList);
  2841. // return;
  2842. // }
  2843. }
  2844. else {
  2845. Flag = true;
  2846. }
  2847. pPrevCross = *pCross;
  2848. }
  2849. }
  2850. bool CGpsDrawMap::DrawBetweenCross(CGpsRoadCrossPoint *pPrevCross,CGpsRoadCrossPoint *pCross,CObList *RoadList,CDC *pDC)
  2851. {
  2852. CObList DstList;
  2853. CString RoadSn;
  2854. RoadSn.Format("%c%d",pPrevCross->m_CrossRoad1_Serial,pPrevCross->m_CrossRoad1_Number);
  2855. if(RoadSnInCross(RoadSn,pCross)) {
  2856. if(GetOneRoadPlain(pPrevCross,pCross,RoadList,RoadSn,&DstList)) {
  2857. DrawLineEx(pDC,&DstList);
  2858. m_cCurrMapInfo.ClearPointList(&DstList);
  2859. return true;
  2860. }
  2861. }
  2862. RoadSn.Format("%c%d",pPrevCross->m_CrossRoad2_Serial,pPrevCross->m_CrossRoad2_Number);
  2863. if(RoadSnInCross(RoadSn,pCross)) {
  2864. if(GetOneRoadPlain(pPrevCross,pCross,RoadList,RoadSn,&DstList)) {
  2865. DrawLineEx(pDC,&DstList);
  2866. m_cCurrMapInfo.ClearPointList(&DstList);
  2867. return true;
  2868. }
  2869. }
  2870. RoadSn.Format("%c%d",pPrevCross->m_CrossRoad3_Serial,pPrevCross->m_CrossRoad3_Number);
  2871. if(RoadSnInCross(RoadSn,pCross)) {
  2872. if(GetOneRoadPlain(pPrevCross,pCross,RoadList,RoadSn,&DstList)) {
  2873. DrawLineEx(pDC,&DstList);
  2874. m_cCurrMapInfo.ClearPointList(&DstList);
  2875. return true;
  2876. }
  2877. }
  2878. RoadSn.Format("%c%d",pPrevCross->m_CrossRoad4_Serial,pPrevCross->m_CrossRoad4_Number);
  2879. if(RoadSnInCross(RoadSn,pCross)) {
  2880. if(GetOneRoadPlain(pPrevCross,pCross,RoadList,RoadSn,&DstList)) {
  2881. DrawLineEx(pDC,&DstList);
  2882. m_cCurrMapInfo.ClearPointList(&DstList);
  2883. return true;
  2884. }
  2885. }
  2886. return false;
  2887. }
  2888. void CGpsDrawMap::DrawLineEx(CDC *pDC,CObList *TempList)
  2889. {
  2890. CRoadPoint *pPoint;
  2891. POSITION pos;
  2892. CPoint point,point1;
  2893. bool Flag = false;
  2894. pos = TempList->GetHeadPosition();
  2895. while(pos  != NULL) {
  2896. pPoint  = (CRoadPoint*)TempList->GetNext(pos);
  2897. point.x = pPoint->m_lx; point.y = pPoint->m_ly;
  2898. if(Flag) {
  2899. DrawLine(point1.x,point1.y,point.x,point.y,3,m_cColor.RoadColor[6],pDC);
  2900. }
  2901. else {
  2902. Flag = true;
  2903. }
  2904. point1 = point;
  2905. }
  2906. }
  2907. void CGpsDrawMap::CalculateBRroadPath(CPoint point)
  2908. {
  2909. CPoint cPoint;
  2910. CString RoadSn;
  2911. if(!gBRcross.m_bHaveSpoint) {
  2912. if(!SearchSignByPoint(point,cPoint)) return;
  2913. if(SearchRoad(point,RoadSn) == "") return;
  2914. ClearPointList(&mSaveTempList1);
  2915. if(GetOneBRCrossPoint(point,&m_cCurrMapInfo.lCurrRoadList,
  2916. &m_cCurrMapInfo.lCurrCrossList,
  2917. RoadSn,&gBRcross.m_StartCross,&mSaveTempList1)) {
  2918. gBRcross.m_bHaveSpoint = true;
  2919. AfxMessageBox("请选择目标点!");
  2920. }
  2921. }
  2922. else {
  2923. if(!SearchSignByPoint(point,cPoint)) return;
  2924. if(SearchRoad(point,RoadSn) == "") return;
  2925. ClearPointList(&mSaveTempList2);
  2926. if(GetOneBRCrossPoint(point,&m_cCurrMapInfo.lCurrRoadList,
  2927. &m_cCurrMapInfo.lCurrCrossList,
  2928. RoadSn,&gBRcross.m_EndCross,&mSaveTempList2)) {
  2929. m_cCurrMapInfo.ClearBRoadSaveList(&mSaveBRList);
  2930. gBRcross.m_bEnable = true;
  2931. ((CGpsSCView*)m_pCurrView)->StatusPrompt("正在计算路径,请稍等...",0);
  2932. AfxGetApp()->BeginWaitCursor();
  2933. short Len = BR_SaveOnePath(&gBRcross.m_StartCross.m_cCross,
  2934.    &gBRcross.m_EndCross.m_cCross,
  2935.    &m_cCurrMapInfo.lCurrRoadList,
  2936.    &m_cCurrMapInfo.lCurrCrossList,
  2937.    &mSaveBRList);
  2938. if(Len <= 1) {
  2939. AfxMessageBox("没有找到路径!");
  2940. }
  2941. else {
  2942. // m_cDrawMap.WritePathToTxt(&mSaveBRList);
  2943. CString Prompt;
  2944. Prompt.Format("查找到路径!",Len);
  2945. AfxMessageBox(Prompt);
  2946. }
  2947. AfxGetApp()->EndWaitCursor();
  2948. ((CGpsSCView*)m_pCurrView)->Invalidate();
  2949. }
  2950. }
  2951. }
  2952. void CGpsDrawMap::DispShootPic(CDC *pDC,CPoint point,CString PicPath)
  2953. {
  2954. /*
  2955. CPicture mPic;
  2956. CRect cRect;
  2957. CSize Size;
  2958. if(mPic.Load(PicPath)) {
  2959. Size  = mPic.GetImageSize();
  2960. cRect.top  = point.y - Size.cy / 2;
  2961. cRect.bottom = point.y + Size.cy / 2;
  2962. cRect.left  = point.x - Size.cx / 2;
  2963. cRect.right  = point.x + Size.cx / 2;
  2964. mPic.Render(pDC,cRect);
  2965. }
  2966. */
  2967. }
  2968. bool CGpsDrawMap::SearchSignByPoint(CPoint point,CPoint &Ret)
  2969. {
  2970. CGpsSignObject *pSign = NULL;
  2971. POSITION pos;
  2972. pos = m_cCurrMapInfo.lCurrSignList.GetTailPosition();
  2973. while(pos != NULL) {
  2974. pSign  = (CGpsSignObject*)m_cCurrMapInfo.lCurrSignList.GetPrev(pos);
  2975. if((abs(pSign->m_lx - point.x) < m_PointWidth) &&
  2976.    (abs(pSign->m_ly - point.y) < m_PointWidth)) {
  2977. Ret.x = pSign->m_lx;
  2978. Ret.y = pSign->m_ly;
  2979. return true;
  2980. }
  2981. }
  2982. return false;
  2983. }
  2984. void CGpsDrawMap::GetCarXY(int &nx,int &ny)
  2985. {
  2986. CGpsPoint *pPoint = NULL;
  2987. POSITION pos;
  2988. pos  = mSaveRecePointList.GetTailPosition();
  2989. while(pos != NULL) {
  2990. pPoint = (CGpsPoint*)mSaveRecePointList.GetPrev(pos);
  2991. if(pPoint != NULL) {
  2992. nx = pPoint->m_lx;
  2993. ny = pPoint->m_ly;
  2994. }
  2995. }
  2996. }
  2997. bool CGpsDrawMap::CompanySimilarStr(CString Str1,CString Str2)
  2998. {
  2999. CString Temp;
  3000. BYTE pos = 0;
  3001. while(pos <= Str1.GetLength() - 4) {
  3002. Temp = Str1.Mid(pos,4);
  3003. if(Str2.Find(Temp,0) != -1) return true;
  3004. pos += 2;
  3005. }
  3006. while(pos <= Str2.GetLength() - 4) {
  3007. Temp = Str2.Mid(pos,4);
  3008. if(Str1.Find(Temp,0) != -1) return true;
  3009. pos += 2;
  3010. }
  3011. return false;
  3012. }
  3013. void CGpsDrawMap::SearchSignByInput()
  3014. {
  3015. CInputStringDlg input;
  3016. input.m_sCaption = "请输入标志名称:";
  3017. if(input.DoModal() == IDCANCEL) return;
  3018. if(input.m_sString.IsEmpty()) return;
  3019. CString arrSignName[100];
  3020. int Count = 0;
  3021. CGpsSignObject *pSign = NULL;
  3022. POSITION pos;
  3023. CString Name;
  3024. pos  = m_cCurrMapInfo.lCurrSignList.GetTailPosition();
  3025. while(pos != NULL) {
  3026. pSign = (CGpsSignObject*)m_cCurrMapInfo.lCurrSignList.GetPrev(pos);
  3027. Name = pSign->m_pSignObjectName;
  3028. if(CompanySimilarStr(Name, input.m_sString)) {
  3029. arrSignName[Count++] = Name;
  3030. }
  3031. }
  3032. if(Count == 0) return;
  3033. CListSimilarStrDlg dlg(arrSignName,Count);
  3034. dlg.m_sCaption = "相似标志物:";
  3035. dlg.GetParent(this);
  3036. dlg.DoModal();
  3037. }
  3038. void CGpsDrawMap::DrawSignByName(CString SignName)
  3039. {
  3040. CGpsSignObject *pSign = NULL;
  3041. POSITION pos;
  3042. CString Name;
  3043. bool Flag = false;
  3044. pos  = m_cCurrMapInfo.lCurrSignList.GetTailPosition();
  3045. while(pos != NULL) {
  3046. pSign = (CGpsSignObject*)m_cCurrMapInfo.lCurrSignList.GetPrev(pos);
  3047. Name = pSign->m_pSignObjectName;
  3048. if(Name == SignName) {
  3049. Flag = true;
  3050. break;
  3051. }
  3052. }
  3053. if(!Flag) return;
  3054. CheckMapIsChange(pSign->m_dgx,pSign->m_dgy);
  3055. RefreshMapWnd();
  3056. CovertNEXY(pSign, m_cCurrMapInfo.CoeffNE_XY, true);
  3057. pDispOneSign.m_lx = pSign->m_lx;
  3058. pDispOneSign.m_ly = pSign->m_ly;
  3059. pDispOneSign.m_dgx = pSign->m_dgx;
  3060. pDispOneSign.m_dgy = pSign->m_dgy;
  3061. pDispOneSign.m_sIconName = pSign->m_sIconName;
  3062. CopyEquaLenArr(pSign->m_pSignObjectName,pDispOneSign.m_pSignObjectName,pSign->m_bySignName_Bytes);
  3063. FreshWnd();
  3064. }