📄 gpsdrawmap.cpp
字号:
ep.y = SY - HalfWidth;
pDC->MoveTo(sp);
pDC->LineTo(ep);
sp.x = SX - HalfWidth;
sp.y = SY - HalfWidth;
ep.x = SX - HalfWidth;
ep.y = SY - HalfWidth + MapLineWidth;
pDC->MoveTo(sp);
pDC->LineTo(ep);
sp.x = SX + HalfWidth;
sp.y = SY + HalfWidth;
ep.x = SX + HalfWidth - MapLineWidth;
ep.y = SY + HalfWidth;
pDC->MoveTo(sp);
pDC->LineTo(ep);
sp.x = SX + HalfWidth;
sp.y = SY + HalfWidth;
ep.x = SX + HalfWidth;
ep.y = SY + HalfWidth - MapLineWidth;
pDC->MoveTo(sp);
pDC->LineTo(ep);
if (SY == EY) break;
if ((f += W) >= Ha) {
f -= Ha;
SX++;
}
SY += dY;
}
}
else {
/* X-majored */
f = 0;
while (1) {
sp.x = SX - HalfWidth;
sp.y = SY - HalfWidth;
ep.x = SX - HalfWidth + MapLineWidth;
ep.y = SY - HalfWidth;
pDC->MoveTo(sp);
pDC->LineTo(ep);
sp.x = SX - HalfWidth;
sp.y = SY - HalfWidth;
ep.x = SX - HalfWidth;
ep.y = SY - HalfWidth + MapLineWidth;
pDC->MoveTo(sp);
pDC->LineTo(ep);
sp.x = SX + HalfWidth;
sp.y = SY + HalfWidth;
ep.x = SX + HalfWidth - MapLineWidth;
ep.y = SY + HalfWidth;
pDC->MoveTo(sp);
pDC->LineTo(ep);
sp.x = SX + HalfWidth;
sp.y = SY + HalfWidth;
ep.x = SX + HalfWidth;
ep.y = SY + HalfWidth - MapLineWidth;
pDC->MoveTo(sp);
pDC->LineTo(ep);
if (SX == EX) break;
if ((f += Ha) >= W) {
f -= W;
SY += dY;
}
SX++;
}
}
pDC->SelectObject(OldPen);
}
/*************Draw Road Name*************/
void CGpsDrawMap::DrawRoadName(CObList *RoadList,CDC *pDC)
{
CGpsRoadStruct *pRoad;
CSmallRoadStruct *pSmall;
POSITION pos,pos1;
CString RoadName;
pos = RoadList->GetTailPosition();
while(pos != NULL) {
pRoad = (CGpsRoadStruct*)RoadList->GetPrev(pos);
if(isupper(pRoad->BigRoad_Serial)) continue;
pos1 = pRoad->SmallRoadList.GetTailPosition();
while(pos1 != NULL) {
pSmall = (CSmallRoadStruct*)pRoad->SmallRoadList.GetPrev(pos1);
RoadName.Empty();
RoadName = pSmall->RoadName;
if(RoadName.IsEmpty()) continue;
if(pSmall->RoadPointList.GetCount() < 2) continue;
DrawOneRoadName(&pSmall->RoadPointList,RoadName,pDC);
}
}
}
BYTE CGpsDrawMap::GetChrCount(CString RoadName)
{
BYTE chr,pos,Length = 0;
pos = 0;
while(pos < RoadName.GetLength()) {
chr = RoadName.GetAt(pos);
if(chr < 0x80) pos++;
else pos += 2;
Length++;
}
return Length;
}
CPoint CGpsDrawMap::GetRoadMidPoint(CObList *RoadList)
{
CGpsPoint *pPoint;
POSITION pos;
CPoint point;
short Mid,Count = 0;
Mid = RoadList->GetCount() / 2;
pos = RoadList->GetTailPosition();
while(pos != NULL) {
pPoint = (CGpsPoint*)RoadList->GetPrev(pos);
if(Count == Mid) {
point.x = pPoint->m_lx;
point.y = pPoint->m_ly;
return point;
}
Count++;
}
return NULL;
}
void CGpsDrawMap::DrawStr(CDC *pDC,CPoint point,CString Name)
{
CPoint TempPoint,cPoint(6,6),SavePoint;
CBrush cBrush(RGB(0,255,255));
CPen CurrPen(PS_SOLID,1,RGB(0,0,255)),*pSavePen = NULL;
CRect cRect;
bool Flag1 = false,Flag2 = false;
pSavePen = pDC->SelectObject(&CurrPen);
TempPoint.x = (long)(point.x + 30 / sqrt(2));
TempPoint.y = (long)(point.y - 30 / sqrt(2));
cRect = CRect(TempPoint.x - 3,TempPoint.y - 2,TempPoint.x + 3 + Name.GetLength() * 8,TempPoint.y + 18);
if(cRect.top < 0) Flag1 = true;
if(cRect.right > m_cCurrMapInfo.m_lWnd_Max_X) Flag2 = true;
if(Flag1) {
TempPoint.y = (long)(point.y + 30 / sqrt(2));
}
if(Flag2) {
TempPoint.x = (long)(point.x - 30 / sqrt(2));
}
pDC->MoveTo(point);
pDC->LineTo(TempPoint);
SavePoint = TempPoint;
if(Flag2) TempPoint.x = TempPoint.x - (3 + Name.GetLength() * 8);
cRect = CRect(TempPoint.x - 3,TempPoint.y - 2,TempPoint.x + 3 + Name.GetLength() * 8,TempPoint.y + 18);
pDC->SetBkMode(TRANSPARENT);
pDC->RoundRect(cRect,cPoint);
// pDC->FillRect(cRect,&cBrush);
pDC->TextOut(TempPoint.x,TempPoint.y,Name);
TempPoint = SavePoint;
TempPoint.y += 8;
pDC->MoveTo(point);
pDC->LineTo(TempPoint);
pDC->SelectObject(pSavePen);
}
long CGpsDrawMap::CalcTwoPointDist(CPoint sp,CPoint ep)
{
long dx,dy,Distance;
dx = abs(sp.x - ep.x);
dy = abs(sp.y - ep.y);
Distance = (long)sqrt(Square(dx) + Square(dy));
return Distance;
}
void CGpsDrawMap::SearchSign()
{
CSearchSignDlg dlg(&m_cCurrMapInfo.lCurrSignList,&m_cCurrMapInfo.lAreaLibList);
dlg.GetParent(this);
dlg.DoModal();
}
long CGpsDrawMap::CalcPointsDist(CObList *TempList,bool ByNE)
{
CGpsPoint *pPoint;
POSITION pos = TempList->GetTailPosition();
CPoint sp,ep;
long Dist = 0;
BYTE Flag = 0;
while(pos != NULL) {
pPoint = (CGpsPoint*)TempList->GetPrev(pos);
if(!ByNE) {
ep.x = pPoint->m_lx;
ep.y = pPoint->m_ly;
}
else {
ep.x = CovertToLongNE(pPoint->m_dgx);
ep.y = CovertToLongNE(pPoint->m_dgy);
}
if(!Flag) {
Flag = 1;
sp = ep;
continue;
}
Dist +=CalcTwoPointDist(sp,ep);
sp = ep;
}
return Dist;
}
CPoint CGpsDrawMap::CalcOneLinePoint(CPoint sp,CPoint ep,long WordPos,long Bevel)
{
CPoint point;
long dx,dy;
dx = ep.x - sp.x; dy = ep.y - sp.y;
if(dx == 0) {
point.x = sp.x;
point.y = sp.y + dy - WordPos;
}
else if(dy == 0) {
point.x = sp.x + dx - WordPos;
point.y = sp.y;
}
else {
point.x = sp.x + (WordPos * dx) / Bevel;
point.y = sp.y + (WordPos * dy) / Bevel;
}
return point;
}
void CGpsDrawMap::DrawOneRoadName(CObList * TempList,CString RoadName,CDC * MemDC)
{
CGpsPoint *pPoint = NULL;
POSITION pos;
CString Word;
CPoint point,sp,ep;
BYTE FirstChr,DrawMode,Flag = 0;
BYTE NamePos = 1,Len = GetChrCount(RoadName);
short PointTotal = TempList->GetCount();
long WordPos,Dist,CurrDist,d = 0,dx,dy;
FirstChr = RoadName.GetAt(0);
if(isalpha(FirstChr)) DrawMode = true;
else if(Len > PointTotal) DrawMode = true;
else DrawMode = false;
if(DrawMode) {
// point = GetRoadMidPoint(TempList);
// DrawStr(MemDC,point,RoadName);
return;
}
else {
Dist = CalcPointsDist(TempList);
WordPos = Dist / (Len + 1) + 1;
pos = TempList->GetTailPosition();
while(pos != NULL) {
pPoint = (CGpsPoint*)TempList->GetPrev(pos);
ep.x = pPoint->m_lx;
ep.y = pPoint->m_ly;
if(!Flag) {
sp = ep;
Flag = 1;
continue;
}
CurrDist = CalcTwoPointDist(sp,ep);
d += CurrDist;
if(NamePos / 2 >= Len) return;
dx = abs(sp.x - ep.x); dy = abs(sp.y - ep.y);
if(d == WordPos) {
Word.Empty();
Word += RoadName.GetAt(NamePos - 1);
Word += RoadName.GetAt(NamePos - 0);
// AfxMessageBox(Word);
MemDC->SetBkMode (TRANSPARENT);
if(dx > dy) {
MemDC->TextOut(ep.x + 0,ep.y - 15,Word);
}
else {
MemDC->TextOut(ep.x - 15,ep.y + 0,Word);
}
d = 0;
NamePos += 2;
}
else if(d > WordPos) {
point = CalcOneLinePoint(sp,ep,CurrDist - (d - WordPos),CurrDist);
Word.Empty();
Word += RoadName.GetAt(NamePos - 1);
Word += RoadName.GetAt(NamePos - 0);
// AfxMessageBox(Word);
MemDC->SetBkMode (TRANSPARENT);
if(dx > dy) {
MemDC->TextOut(point.x + 0,point.y - 15,Word);
}
else {
MemDC->TextOut(point.x - 15,point.y + 0,Word);
}
d = d - WordPos;
NamePos += 2;
}
sp = ep;
}
}
}
void CGpsDrawMap::ClearLinkList(CObList *pLinkList)
{
CGpsLinkStruct *pLink;
POSITION pos;
pos = pLinkList->GetHeadPosition();
while(pos != NULL) {
pLink = (CGpsLinkStruct*)pLinkList->GetNext(pos);
delete pLink;
}
pLinkList->RemoveAll();
}
void CGpsDrawMap::ClearPointList(CObList *PointList)
{
CGpsPoint *pPoint;
POSITION pos;
pos = PointList->GetHeadPosition();
while(pos != NULL) {
pPoint = (CGpsPoint*)PointList->GetNext(pos);
delete pPoint;
}
PointList->RemoveAll();
}
bool CGpsDrawMap::SaveRecePoint(double gx,double gy,CDC *pDC,CString strVehicleNO)
{
if(!IsValidNE(gx,gy)) return false;
CGpsPoint *pPoint,*pTempPoint = NULL;
POSITION pos;
bool Flag = false;
pPoint = new CGpsPoint;
pPoint->m_dgx = gx; pPoint->m_dgy = gy;
pPoint->m_sVehicleNO = strVehicleNO;
CovertNEXY(pPoint, m_cCurrMapInfo.CoeffNE_XY, true);
pos = mSaveRecePointList.GetTailPosition();
while(pos != NULL) {
pTempPoint = (CGpsPoint*)mSaveRecePointList.GetPrev(pos);
if(pTempPoint->m_sVehicleNO.Compare(strVehicleNO) == 0) {
// ErasePrevPoint(pDC,pTempPoint->m_lx,pTempPoint->m_ly);
pTempPoint->m_dgx = pPoint->m_dgx;
pTempPoint->m_dgy = pPoint->m_dgy;
pTempPoint->m_lx = pPoint->m_lx;
pTempPoint->m_ly = pPoint->m_ly;
delete pPoint;
Flag = true;
break;
}
}
if(!Flag) {
mSaveRecePointList.AddHead(pPoint);
}
return true;
}
void CGpsDrawMap::ErasePrevPoint(CDC *pDC,long x,long y)
{
CRect cRect;
cRect.left = x - GPS_CAR_WIDTH_HEIGH / 2;
cRect.right = x + GPS_CAR_WIDTH_HEIGH / 2;
cRect.top = y - GPS_CAR_WIDTH_HEIGH / 2;
cRect.bottom = y + GPS_CAR_WIDTH_HEIGH / 2;
RedrawInvalidRect(cRect,pDC,false);
}
void CGpsDrawMap::DrawEllipse(CDC *pDC)
{
CGpsPoint *pPoint = NULL;
CBrush cBrush(RGB(255,8,0));
CBrush *SaveBrush = pDC->SelectObject(&cBrush);
CRect cRect;
BYTE Width = m_PointWidth + 2;
if(mSaveRecePointList.GetCount() == 0) return;
#if 1
pPoint = (CGpsPoint*)mSaveRecePointList.GetHead();
if(pPoint != NULL) {
cRect.left = pPoint->m_lx - Width;
cRect.right = pPoint->m_lx + Width;
cRect.top = pPoint->m_ly - Width;
cRect.bottom = pPoint->m_ly + Width;
pDC->Ellipse(&cRect);
}
#else
pos = mSaveRecePointList.GetTailPosition();
while(pos != NULL) {
pPoint = (CGpsPoint*)mSaveRecePointList.GetPrev(pos);
cRect.left = pPoint->m_lx - Width;
cRect.right = pPoint->m_lx + Width;
cRect.top = pPoint->m_ly - Width;
cRect.bottom = pPoint->m_ly + Width;
pDC->Ellipse(&cRect);
}
#endif
pDC->SelectObject(SaveBrush);
SaveBrush->DeleteObject();
}
//Get Course of the car ...
CString CGpsDrawMap::GetCarByDirection(double Course)
{
CString ret;
double TmpCourse = 0;
ret = SaveGpsCarPath[0];
for(BYTE i = 0; i < 24; i++) {
if((Course >= TmpCourse) && (Course < TmpCourse + 15)) {
ret = SaveGpsCarPath[i];
}
TmpCourse += 15;
}
return ret;
}
//Redraw invalid rectangle...
void CGpsDrawMap::RedrawInvalidRect(CRect cRect,CDC * pDC,bool Flag)
{
int i,j;
int x,y;
for(x = 0,i = cRect.left; i < cRect.right; i++,x++) {
for(y = 0,j = cRect.top; j < cRect.bottom; j++,y++) {
if((x == 40) || (y == 40)) break;
if(Flag) {
SaveInvalidRectColor[x][y]= GetPixel(*pDC,i,j);
}
else {
SetPixel(*pDC,i,j,SaveInvalidRectColor[x][y]);
}
}
}
}
//Draw Gps Car ...
void CGpsDrawMap::DrawGpsCar(CDC *pDC,double Course)
{
#if 0
CString CarName,CarPath;
CBmpProc CarMap;
CGpsPoint *pPoint = NULL;
CRect cRect;
HWND hWnd = ::GetActiveWindow();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -