Project

General

Profile

Feature #406 » AtsObj.cpp

yufeng wu, 01/04/2020 10:48 AM

 
1
#include "stdafx.h"
2
#include "graph\eg_powerobjects.h"
3
#include "graph\eg_util.h"
4
#include "graph\eg_global.h"
5
#include <math.h>
6
#include "resource.h"
7
#ifndef WIN32
8
#include <sys/time.h>
9
#else 
10
#include <sys/timeb.h>
11
#endif
12

    
13
#define TRAIN_WIDTH		250
14
#define TRAIN_HEGIHT	150
15
STRUCT_GRPCOLINFO AtsColInfo[]=
16
{
17
	{"???????ɫ", objsizeof(STRUCT_ATSINFO, TrainRun8), /*WYF 20200103*/
18
			offsetof(STRUCT_ATSINFO, TrainRun8), sizeof(COLORREF)},
19
	{"???ѡ??ɫ", objsizeof(STRUCT_ATSINFO, TrainRun9), /*WYF 20200103*/
20
			offsetof(STRUCT_ATSINFO, TrainRun9), sizeof(COLORREF)},
21
	{"?????ɫ", objsizeof(STRUCT_ATSINFO, TrainRun6), /*WYF 20200103*/
22
			offsetof(STRUCT_ATSINFO, TrainRun6), sizeof(COLORREF)},
23
	{"?Ǽƻ?????ɫ", objsizeof(STRUCT_ATSINFO, TrainRun7), /*WYF 20200103*/
24
			offsetof(STRUCT_ATSINFO, TrainRun7), sizeof(COLORREF)},
25
	{"??????ɫ", objsizeof(STRUCT_ATSINFO, TrainRun0), 
26
			offsetof(STRUCT_ATSINFO, TrainRun0), sizeof(COLORREF)},
27
	{"?۳???ɫ", objsizeof(STRUCT_ATSINFO, TrainRun1), 
28
			offsetof(STRUCT_ATSINFO, TrainRun1), sizeof(COLORREF)},
29
	{"??????ɫ", objsizeof(STRUCT_ATSINFO, TrainRun2), 
30
			offsetof(STRUCT_ATSINFO, TrainRun2), sizeof(COLORREF)},
31
	{"??????ɫ", objsizeof(STRUCT_ATSINFO, TrainRun3), 
32
			offsetof(STRUCT_ATSINFO, TrainRun3), sizeof(COLORREF)},
33
	{"??վ??ɫ", objsizeof(STRUCT_ATSINFO, TrainRun4), 
34
			offsetof(STRUCT_ATSINFO, TrainRun4), sizeof(COLORREF)},
35
	{"?ı???ɫ", objsizeof(STRUCT_ATSINFO, TrainRun5), 
36
			offsetof(STRUCT_ATSINFO, TrainRun5), sizeof(COLORREF)},
37
	{"?г??߶?", objsizeof(STRUCT_ATSINFO, Height), 
38
			offsetof(STRUCT_ATSINFO, Height), sizeof(BYTE)},
39
	{"?г?????", objsizeof(STRUCT_ATSINFO, Width), 
40
			offsetof(STRUCT_ATSINFO, Width), sizeof(BYTE)},
41
	{"ͷ??", objsizeof(STRUCT_ATSINFO, HeadCode), 
42
			offsetof(STRUCT_ATSINFO, HeadCode), sizeof(char)}			
43
};
44

    
45
const int AtsColNum=sizeof(AtsColInfo)/sizeof(STRUCT_GRPCOLINFO);
46

    
47
STRUCT_FILECOLINFO *CAtsObj::m_FileColInfo=NULL;
48
STRUCT_FILECOLBASEINFO CAtsObj::m_FileColBaseInfo={0,0};
49

    
50
int RoundValue(double dData)
51
{
52
	int nAbsValue = (int)fabs(dData);
53
	double dDelta = fabs(dData) - (double)nAbsValue;
54
	if (dDelta >= 0.5)
55
	{
56
		nAbsValue ++;
57
	}
58
	
59
	if (dData < 0)
60
	{
61
		return -nAbsValue;
62
	}
63
	else 
64
	{
65
		return nAbsValue;
66
	}
67
} // round
68

    
69
int UTL_GetTimeOfDay(timeval  *pTimeVal)  /*to store the result*/
70
{
71

    
72
#ifdef WIN32
73
	struct _timeb timebuf;
74

    
75
	_ftime(&timebuf);
76

    
77
	pTimeVal->tv_sec = timebuf.time;
78
	pTimeVal->tv_usec = timebuf.millitm * 1000;
79
	return  1;
80

    
81
#else  /*end of NT version*/
82

    
83
	int sts;
84

    
85
	int ret_val;
86
	struct timezone tz;
87

    
88
	ret_val = gettimeofday((struct timeval*)pTimeVal, &tz);
89
	if (ret_val == 0)
90
		sts = 1;
91
	else if (ret_val == -1)
92
		sts = 0;
93

    
94
	return(sts);
95

    
96
#endif /*end of Unix portion*/
97
}
98

    
99

    
100
int  UTL_Time_tToTm(
101
	time_t     *pTime,  /*time_t value in seconds*/
102
	struct tm   *pTm)   /*result tm value*/
103
{
104
	int sts;
105
	struct tm *ret_buf;
106

    
107
	if ((pTime == NULL) || (pTm == NULL))
108
	{
109
		sts = 0;
110
		return(sts);
111
	}
112

    
113
	ret_buf = localtime(pTime);
114

    
115
	if (ret_buf == NULL)
116
	{
117
		sts = 0;
118
		return(sts);
119
	}
120

    
121
	ret_buf->tm_year += 1900;
122
	ret_buf->tm_mon += 1;
123

    
124
	memcpy(pTm, ret_buf, sizeof(struct tm));
125

    
126
	return 1;
127
}
128

    
129

    
130
double RadiansToDegrees(double a)
131
{
132
	return ((a) / PI) * 180.0;
133
}
134

    
135
double DegreesToRadians(double x)
136
{
137
  return (((x) / 360.0) * (2.0 * PI)); 
138
}
139

    
140
void DrawRotatedText(CDC* pDC, const CString strText, CRect rect, 
141
                     double dbAngle, UINT nOptions = 0)
142
{
143
   // get the center of a not-rotated text
144
   CSize TextSize = pDC->GetTextExtent(strText);
145
   CPoint center;
146
   center.x = TextSize.cx / 2;
147
   center.y = TextSize.cy / 2;
148
 
149
   // now calculate the center of the rotated text
150
   CPoint rcenter;
151
   //rcenter.x = long(cos(dbAngle) * center.x);
152
   //rcenter.y = long(sin(dbAngle) * center.x);
153
   rcenter.x = long(cos(dbAngle) * center.x - sin(dbAngle) * center.y);
154
   rcenter.y = long(sin(dbAngle) * center.x + cos(dbAngle) * center.y);
155
 
156
   // finally draw the text and move it to the center of the rectangle
157
   /*pDC->SetTextAlign(TA_BASELINE);
158
   pDC->SetBkMode(TRANSPARENT);
159
   CPoint pt = rect.CenterPoint();
160
   pDC->TextOut(pt.x + rcenter.x, pt.y + rcenter.y, str);*/
161

    
162
   	int nOldmode = pDC->SetBkMode(TRANSPARENT);
163
	COLORREF oldcolor = pDC->SetTextColor(RGB(255, 0, 0));
164
	pDC->DrawText(strText, strlen(strText), &rect, DT_WORDBREAK | DT_CENTER);
165
	pDC->ExtTextOut(rect.left + rect.Width() / 2 - rcenter.x, 
166
                   rect.top + rect.Height() / 2 + rcenter.y,
167
                   nOptions, rect, strText, NULL);
168
	/*pDC->ExtTextOut(rect.left + rcenter.x, 
169
                   rect.top + rect.Height() / 2 + rcenter.y,
170
                   nOptions, rect, strText, NULL);*/
171
	pDC->SetTextColor(oldcolor);
172
	pDC->SetBkMode(nOldmode);
173
}
174

    
175

    
176
double ComputeLineAngle(const CFPoint &ptStart, const CFPoint &ptEnd)
177
{
178
	double dbRadian = atan2((double)(ptEnd.y - ptStart.y), 
179
		(double)(ptEnd.x - ptStart.x));
180
	double dbAngle = RadiansToDegrees(dbRadian);
181
	return dbAngle;
182
}
183

    
184
int ComputeLineLength(const CFPoint &ptStart, const CFPoint &ptEnd)
185
{
186
	int	nDistance = (int)sqrt((ptStart.x - ptEnd.x) * (ptStart.x - ptEnd.x)
187
						+ (ptStart.y - ptEnd.y) * (ptStart.y - ptEnd.y));
188
	return nDistance;
189
}
190

    
191
BOOL CAtsObj::RWPicFile(FILE *fp,unsigned char writeflag)
192
{
193
	CBaseObj::RWPicFile(fp,writeflag);
194
	STRUCT_FILECOLBASEINFO nowbaseinfo;
195
	nowbaseinfo.colnum=AtsColNum;
196
	nowbaseinfo.rcdlen=sizeof(m_AtsInfo);
197
	if(writeflag==0)
198
         InitAtsInfo();
199

    
200
	//Read/Write property first
201
	if(!Base_RWPicFile(fp,writeflag,nowbaseinfo,AtsColInfo,
202
		m_FileColBaseInfo,m_FileColInfo,&m_AtsInfo))
203
		return FALSE;
204
	AddRef();
205
	return TRUE;
206
}
207
BOOL CAtsObj::RWPicColInfo(FILE *fp,unsigned char writeflag)
208
{
209
	STRUCT_FILECOLBASEINFO baseinfo;
210
	baseinfo.colnum=AtsColNum;
211
	baseinfo.rcdlen=sizeof(STRUCT_ATSINFO);
212
	return RWGrpClassColInfo(fp,writeflag,baseinfo,AtsColInfo,m_FileColBaseInfo,&m_FileColInfo);
213
}
214
BOOL CAtsObj::FreeColInfo()
215
{
216
	m_FileColBaseInfo.colnum=0;
217
	m_FileColBaseInfo.rcdlen=0;
218
	if(m_FileColInfo)
219
		free(m_FileColInfo);
220
	m_FileColInfo=NULL;
221
	return TRUE;
222
}
223

    
224
CAtsObj::CAtsObj()
225
	: CRectObj()
226
{
227
	m_bAttach = FALSE;
228
	m_shape = OS_ATS;
229
    m_nDrawType =1;
230
	m_Uint =0.0;
231
	InitAtsInfo();	
232
}
233

    
234
CAtsObj::CAtsObj(const CFRect& rcpos)
235
	: CRectObj(rcpos)
236
{
237
	m_bAttach = FALSE;
238
	m_shape = OS_ATS;
239
    m_nDrawType =1;
240
	m_Uint =0.0;
241
	InitAtsInfo();
242
}
243

    
244
CAtsObj::~CAtsObj()
245
{
246
	m_bAttach = FALSE;
247
	m_bmBitmap.DeleteObject();	
248
	m_lstParentEdges.DelAll();
249
	Release();
250
}
251

    
252
void CAtsObj::Draw(CDC* pdc, CTransDriver *trans)
253
{
254
	if (!CanDrawNow())
255
		return;
256
	m_BaseObjInfo.rectpos.right = m_BaseObjInfo.rectpos.left + 32;
257
	m_BaseObjInfo.rectpos.bottom = m_BaseObjInfo.rectpos.top + 32;
258
	CFRect objrect=m_BaseObjInfo.rectpos;
259
	trans->MapToClient(&objrect, &m_drawrect);
260
	
261
	if (CGlobal::m_IsPaintFlag != 0)
262
	{
263
		DrawImage(pdc, m_drawrect);
264
	}
265
	DrawHandle(pdc, trans);
266
}
267

    
268
void CAtsObj::InitAtsInfo()
269
{
270
	m_AtsInfo.TrainRun0 =RGB(0,255,0); //????????
271
	m_AtsInfo.TrainRun1 =RGB(0,200,0); //?۳?
272
	m_AtsInfo.TrainRun2 =RGB(0,155,0); //????
273
	m_AtsInfo.TrainRun3 =RGB(0,100,0); //????
274
	m_AtsInfo.TrainRun4 =RGB(0,55,0);  //??վ
275
	m_AtsInfo.TrainRun5 =RGB(255,0,0);  //??վ
276
	m_AtsInfo.TrainRun6 =RGB(255,255,255);  //???//WYF 20200103
277
	m_AtsInfo.TrainRun7 =RGB(127,127,127);  //?Ǽƻ???
278
	m_AtsInfo.TrainRun8 =RGB(0,0,0);	//???????ɫ//WYF 20200103
279
	m_AtsInfo.TrainRun9 =RGB(0,0,255);	//???ѡ??ɫ
280
	m_AtsInfo.Height = TRAIN_HEGIHT;
281
	m_AtsInfo.Width = TRAIN_WIDTH;
282
	if (!m_bAttach)
283
	{
284
	   m_bAttach = m_bmBitmap.LoadBitmap(IDB_ATS);			 
285
	}
286
	m_lstParentEdges.DelAll();
287
	memset(&m_AtsInfo, 0, sizeof(STRUCT_ATSINFO));
288
}
289

    
290
// pDispDC ??ʾDC?? pSrcDC ת??͸??λͼ??DC??x??y ??pDispDC?е?????
291
// nWidth ??nHeightλͼ?Ŀ??ȡ??߶ȣ?crColor ???Σ?mask??????ɫ
292
void DrawTransparent(CDC* pDispDC, CDC *pSrcDC, int x, int y, 
293
					 int nWidth, int nHeight, COLORREF crColor, CBitmap &bitmapTrans)
294
{
295
	// ????pDispDC?ı???ɫ??ǰ??ɫ
296
	COLORREF crOldBack = pDispDC->SetBkColor(RGB(255, 255, 255));
297
	COLORREF crOldText = pDispDC->SetTextColor(RGB(0, 0, 0));
298

    
299
	// ????dcTrans,?????л???????λͼ
300
	CDC dcTrans;
301
	dcTrans.CreateCompatibleDC(pDispDC);
302
//	CBitmap bitmapTrans;
303
	//bitmapTrans.CreateBitmap(nWidth, nHeight, 1, 1, NULL);
304
	CBitmap *pOldBitmapTrans = dcTrans.SelectObject(&bitmapTrans);
305
	
306
	COLORREF crOldBackSrc = pSrcDC->SetBkColor(crColor);
307
	dcTrans.BitBlt(0, 0, nWidth, nHeight, pSrcDC, 0, 0, SRCCOPY);
308
	
309
	// ??XOR,AND,XOR?ķ?ʽ????λͼ??ʹ֮͸??
310
	pDispDC->BitBlt(x, y, nWidth, nHeight, pSrcDC, 0, 0, SRCINVERT);
311
	pDispDC->BitBlt(x, y, nWidth, nHeight, &dcTrans, 0, 0, SRCAND);
312
	pDispDC->BitBlt(x, y, nWidth, nHeight, pSrcDC, 0, 0, SRCINVERT);
313

    
314
	
315
	// ?ָ???ǰ??????
316
	dcTrans.SelectObject(&pOldBitmapTrans);
317
	pDispDC->SetBkColor(crOldBack);
318
	pDispDC->SetTextColor(crOldText);
319
	pSrcDC->SetBkColor(crOldBackSrc);
320

    
321
}
322

    
323
void CAtsObj::DrawImage(CDC *pDC, CRect rect)
324
{	
325
	CDC dcMem;
326
	if (m_bAttach)
327
	{
328
		dcMem.CreateCompatibleDC(pDC);
329
		DrawTransparent(pDC, &dcMem, rect.left, rect.top, 
330
			rect.Width(), rect.Height(), RGB(255, 255, 255), m_bmBitmap);
331
	}
332
}
333

    
334
CBaseObj* CAtsObj::Clone()
335
{
336
	CAtsObj* pObj = new CAtsObj(m_BaseObjInfo.rectpos);
337
    if (pObj == NULL)
338
		return NULL;
339

    
340
	RectClone(pObj);
341

    
342
	pObj->m_AtsInfo.TrainRun0 = m_AtsInfo.TrainRun0;
343
	pObj->m_AtsInfo.TrainRun1 = m_AtsInfo.TrainRun1;
344
	pObj->m_AtsInfo.TrainRun2 = m_AtsInfo.TrainRun2;
345
	pObj->m_AtsInfo.TrainRun3 = m_AtsInfo.TrainRun3;
346
	pObj->m_AtsInfo.TrainRun4 = m_AtsInfo.TrainRun4;
347
	pObj->m_AtsInfo.TrainRun5 = m_AtsInfo.TrainRun5;
348
	pObj->m_AtsInfo.TrainRun6 = m_AtsInfo.TrainRun6;//WYF 20200103
349
	pObj->m_AtsInfo.TrainRun7 = m_AtsInfo.TrainRun7;//WYF 20200103
350
	pObj->m_AtsInfo.TrainRun8 = m_AtsInfo.TrainRun8;//WYF 20200103
351
	pObj->m_AtsInfo.TrainRun9 = m_AtsInfo.TrainRun9;//WYF 20200103
352
	sprintf(pObj->m_AtsInfo.HeadCode, "%s", m_AtsInfo.HeadCode);
353
	return pObj;
354
}
355

    
356

    
357
void CAtsObj::SetDrawType(int nType)
358
{
359
	if(nType >=0 &&nType <=2)
360
        m_nDrawType =nType;
361
}
362

    
363
STRUCT_ATSINFO CAtsObj::GetAtsInfo()
364
{
365
    return m_AtsInfo;
366
}
367

    
368
void CAtsObj::SetAtsInfo(STRUCT_ATSINFO *pInfo)
369
{
370
    m_AtsInfo.TrainRun0 =pInfo->TrainRun0;
371
	m_AtsInfo.TrainRun1 =pInfo->TrainRun1;
372
	m_AtsInfo.TrainRun2 =pInfo->TrainRun2;
373
	m_AtsInfo.TrainRun3 =pInfo->TrainRun3;
374
	m_AtsInfo.TrainRun4 =pInfo->TrainRun4;
375
	m_AtsInfo.TrainRun5 =pInfo->TrainRun5;
376
	m_AtsInfo.TrainRun6 =pInfo->TrainRun6;//WYF 20200103
377
	m_AtsInfo.TrainRun7 =pInfo->TrainRun7;//WYF 20200103
378
	m_AtsInfo.TrainRun8 =pInfo->TrainRun8;//WYF 20200103
379
	m_AtsInfo.TrainRun9 =pInfo->TrainRun9;//WYF 20200103
380
	UINT nHeight = pInfo->Height;
381
	UINT nWidth = pInfo->Width;
382
	if (nHeight > TRAIN_HEGIHT || nHeight == 0)
383
	{
384
		nHeight = TRAIN_HEGIHT;
385
	}
386
	if (nWidth > TRAIN_WIDTH || nWidth == 0)
387
	{
388
		nWidth = TRAIN_WIDTH;
389
	}
390
	m_AtsInfo.Height = nHeight;
391
	m_AtsInfo.Width = nWidth;
392
	int nLen = sizeof(m_AtsInfo.HeadCode);
393
	strncpy(m_AtsInfo.HeadCode, pInfo->HeadCode, nLen);
394
	m_AtsInfo.HeadCode[nLen - 1] = '\0';	
395
}
396

    
397
UINT CAtsObj::GetHandleCount()
398
{
399
	return 4;
400
}
401

    
402
int CAtsObj::HitTestHandles(CFPoint point, CTransDriver *trans)
403
{
404
	CFRect frect = GetPosition();
405
	CRect rect;
406
	if (trans)
407
		trans->MapToClient(&frect, &rect);
408
	else
409
	{
410
		rect.left = (int)(frect.left+0.5);
411
		rect.right = (int)(frect.right+0.5);
412
		rect.top = (int)(frect.top+0.5);
413
		rect.bottom = (int)(frect.bottom+0.5);
414
		rect.NormalizeRect();
415
	}
416
	int len = max(rect.Width(), rect.Height());
417
	if (len <= HANDLE_WIDTH) 
418
		return INVALID_OBJHANDLE;
419
	
420
	CRect rc;
421
	CFPoint ptpos;
422
	if (trans)
423
		trans->MapToClient(&point);
424
	for (UINT i=0; i<GetHandleCount(); i++)
425
	{
426
		ptpos = GetHandlePos(i);
427
		if (trans)
428
			trans->MapToClient(&ptpos);
429
		rc = GetPointRect(ptpos);
430
		if (rc.PtInRect(point.PNT()))
431
			return i;
432
	}	
433
	return INVALID_OBJHANDLE;
434
}
435

    
436
BOOL CAtsObj::SetCursor(CFPoint point, CTransDriver *trans)
437
{
438
	if (m_status == ST_NORMAL || !CanDrawNow())
439
		return FALSE;
440

    
441
	if (!PtInPosition(point))
442
		return FALSE;
443

    
444
	int nHandle = HitTestHandles(point, trans);
445
	if (nHandle == INVALID_OBJHANDLE)
446
	{
447
		if (PtInObject(point))
448
		{
449
			::SetCursor(_objCursors[4]);
450
			return TRUE;
451
		}
452
		return FALSE;
453
	}
454

    
455
	switch (nHandle)
456
	{
457
	case 0:		::SetCursor(_objCursors[0]);	break;
458
	case 1:		::SetCursor(_objCursors[1]);	break;
459
	case 2:		::SetCursor(_objCursors[2]);	break;
460
	case 3:		::SetCursor(_objCursors[3]);	break;
461
//	case 4:		::SetCursor(_objCursors[5]);	break;//??ת
462
	default:	::SetCursor(_objCursors[4]);	break;
463
	}
464

    
465
	return TRUE;
466
}
467

    
468
void CAtsObj::WndEdges(CEasyList &lstEdges)
469
{
470
	m_lstParentEdges.DelAll();
471
	int nSize = lstEdges.GetListLen();
472
	for (int i = 0; i < nSize; i++)
473
	{
474
		CAtsEdge *pObj = (CAtsEdge *)lstEdges.GetNth(i);
475
		if (pObj->GetObjectShape() == OS_ATSEDGE)
476
		{
477
			m_lstParentEdges.AddLast(pObj);
478
		}
479
	}
480
}
481

    
482
static int KeySort(const void* pObj1, const void* pObj2)
483
{
484
	STRUCT_ATSEDGEINFO info1 = ((CAtsEdge *)pObj1)->GetObjectInfo();
485
	STRUCT_ATSEDGEINFO info2 = ((CAtsEdge *)pObj2)->GetObjectInfo();
486
	if (info1.Key > info2.Key)
487
	{
488
		return 1;
489
	}
490
	else
491
	{
492
		return -1;
493
	}
494
}
495

    
496
void CAtsObj::GetWndEdges(CEasyList &lstEdge, UINT ParentEdge)
497
{
498
	lstEdge.DelAll();
499
	int nSize = m_lstParentEdges.GetListLen();
500
	for (int i = 0; i < nSize; i++)
501
	{
502
		CAtsEdge *pObj = (CAtsEdge *)m_lstParentEdges.GetNth(i);
503
		STRUCT_ATSEDGEINFO info = pObj->GetObjectInfo();
504
		if ((UINT)info.ID == ParentEdge)
505
		{
506
			lstEdge.AddSorted(pObj, KeySort);
507
		}	
508
	}
509
}
510

    
511
CString CAtsObj::GetItemDesc(UINT nHeadCode)
512
{
513
	CString strTemp = _T("");
514
	UINT nSize;
515
	nSize = m_aryItems.GetListLen();
516
	for (uint i = 0; i < nSize; i++)
517
	{
518
		LPDATAITEM pData = (LPDATAITEM)m_aryItems.GetNth(i);
519
		if (nHeadCode == pData->nValue)
520
		{
521
			strTemp = pData->ItemDesc;
522
			break;
523
		}
524
	}
525
	return strTemp;
526
}
527

    
528
void CAtsObj::AddRef()
529
{
530
	CString strPath, strFile;
531
	strFile = m_AtsInfo.HeadCode;
532
	strPath = getenv("SEROOT");
533
	strPath += _T("\\cfg\\") + strFile;
534
	int nSize = GetPrivateProfileInt(_T("CAtsObj"), _T("COUNT"), 0, strPath);	
535
	int i = 0;
536
	for ( i = 0; i < nSize; i++)
537
	{
538
		char szItem[128];
539
		CString strKeyName;
540
		strKeyName.Format("%d", i);				
541
		int nLen = GetPrivateProfileString(_T("CAtsObj"), strKeyName, "", 
542
			szItem,	128, strPath);
543
		
544
		BYTE size = sizeof(DATAITEM);	
545
		LPDATAITEM pData = (LPDATAITEM)malloc(size);
546
		memset(pData, 0, size);
547
		pData->nValue = i;	
548
		strncpy(pData->ItemDesc, szItem, 128 - 1);
549
		m_aryItems.AddLast(pData);
550
	}
551

    
552
	int r, g, b;
553
	char szColor[64];
554
	GetPrivateProfileString(_T("PlatForm"), _T("ARRIVAL"), _T("255,0,0"), szColor, 64, strPath);
555
	sscanf(szColor, "%d,%d,%d", &r, &g, &b);
556
	m_clrArrival = RGB(r, g, b);
557
	GetPrivateProfileString(_T("PlatForm"), _T("DISARRIVAL"), _T("0,0,255"), szColor, 64, strPath);
558
	sscanf(szColor, "%d,%d,%d", &r, &g, &b);
559
	m_clrDisArrival = RGB(r, g, b);
560

    
561
	nSize = GetPrivateProfileInt(_T("PlatForm"), _T("COUNT"), 0, strPath);	
562
	for (i = 0; i < nSize; i++)
563
	{
564
		uint32 Id;
565
//		char szItem[24];
566
		CString strKeyName;
567
		strKeyName.Format("PlatForm#%d", i);				
568
	
569
		Id = GetPrivateProfileInt(strKeyName, _T("Id"), 0, strPath);
570
		if (Id == 0)
571
		{
572
			continue;
573
		}
574
		BYTE size = sizeof(PLATFORM);	
575
		LPPLATFORM pData = (LPPLATFORM)malloc(size);
576
		memset(pData, 0, size);
577
		pData->Id = Id;
578
		GetPrivateProfileString(strKeyName, _T("Name"), "", pData->Name, 24, strPath);
579
		uint32 Start, End;
580
		pData->Edge = GetPrivateProfileInt(strKeyName, _T("Edge"), 0, strPath);
581
		Start = GetPrivateProfileInt(strKeyName, _T("Start"), 0, strPath);
582
		pData->Start = (float)(Start / 100.0f);
583
		End = GetPrivateProfileInt(strKeyName, _T("End"), 0, strPath);
584
		pData->End = (float)(End / 100.0f);
585
		m_aryPlatForm.AddLast(pData);	
586
	}
587
}
588

    
589
void CAtsObj::Release()
590
{
591
	int i = 0;
592
	for ( i = 0; i < m_aryItems.GetListLen(); i++)
593
	{
594
		LPDATAITEM pData = (LPDATAITEM)m_aryItems.GetNth(i);
595
		if (pData)
596
		{
597
			free(pData);
598
			pData = NULL;
599
		}
600
	}
601
	m_aryItems.DelAll();
602

    
603
	for (i = 0; i < m_aryPlatForm.GetListLen(); i++)
604
	{
605
		LPPLATFORM pData = (LPPLATFORM)m_aryPlatForm.GetNth(i);
606
		if (pData)
607
		{
608
			free(pData);
609
			pData = NULL;
610
		}
611
	}
612
	m_aryPlatForm.DelAll();
613
}
614

    
615
void CAtsObj::WndPlatForms(CEasyList &lstStatics)
616
{
617
	m_lstStatics.DelAll();
618
	int nSize = lstStatics.GetListLen();
619
	for (int i = 0; i < nSize; i++)
620
	{
621
		CBaseObj *pObj = (CBaseObj *)lstStatics.GetNth(i);
622
		for (int j = 0; j < m_aryPlatForm.GetListLen(); j++)
623
		{
624
			LPPLATFORM pData = (LPPLATFORM)m_aryPlatForm.GetNth(j);
625
			if (strcmp(pData->Name, pObj->GetObjectName()) == 0)
626
			{
627
				m_lstStatics.AddLast(pObj);
628
				break;
629
			}
630
		}
631
	}
632
}
633

    
634
CBaseObj *CAtsObj::GetPlatFormObj(int Dir, int ParentEdge, float Offset)
635
{
636
	CBaseObj *pObj = NULL;
637
	for (int i = 0; i < m_aryPlatForm.GetListLen(); i++)
638
	{
639
		LPPLATFORM pData = (LPPLATFORM)m_aryPlatForm.GetNth(i);
640
		if (ParentEdge == 0)
641
		{
642
			break;
643
		}
644
		if (strcmp(pData->Name, "") == 0)
645
		{
646
			continue;
647
		}
648
		if (Dir == TD_UPTRACK)
649
		{
650
			if (pData->Edge == (uint)ParentEdge && (pData->End >= (Offset - 1) &&
651
				pData->End <= (Offset + 1)))
652
			{
653
				pObj = GetPlatForm(pData->Name);
654
				break;
655
			}
656
		}
657
		else if (Dir == TD_DOWNTRACK)
658
		{
659
			if (pData->Edge == (uint)ParentEdge && (pData->Start >= (Offset - 1) &&
660
				pData->Start <= (Offset + 1)))
661
			{
662
				pObj = GetPlatForm(pData->Name);
663
				break;
664
			}
665
		}		
666
	}
667
	return pObj;
668
}
669

    
670
CBaseObj *CAtsObj::GetPlatForm(char *ObjName)
671
{
672
	if (ObjName == NULL || strcmp(ObjName, "") == 0)
673
	{
674
		return NULL;
675
	}
676
	int nSize = m_lstStatics.GetListLen();
677
	for (int i = 0; i < nSize; i++)
678
	{
679
		CBaseObj *pObj = (CBaseObj *)m_lstStatics.GetNth(i);
680
		if (strcmp(pObj->GetObjectName(), ObjName) == 0)
681
		{
682
			return pObj;
683
		}	
684
	}
685
	return NULL;
686
}
687

    
688
COLORREF CAtsObj::GetArrivalColor()
689
{
690
	return m_clrArrival;
691
}
692

    
693
COLORREF CAtsObj::GetDisArrivalColor()
694
{
695
	return m_clrDisArrival;
696
}
697

    
698
//////////////////////////////////////////////////////////////////////
699
// Construction/Destruction
700
//////////////////////////////////////////////////////////////////////
701
CAtsTrain::CAtsTrain(CAtsObj *objParent, STRUCT_ATSDATA atsData)
702
{	
703
	SetParent(objParent);
704
	m_AtsInfo = objParent->GetAtsInfo();
705
	m_AtsData = atsData;
706
	m_fPosX = 0;
707
	m_fPosY = 0;
708
	m_dbScale = 1.0;
709
	m_bShowID = TRUE;
710
	m_shape = OS_ATSTRAIN;
711
	m_strHeadCode = _T("");
712
	CFRect frect(0, 0, TRAIN_WIDTH, TRAIN_HEGIHT);
713
	SetObjectRect(frect);
714
	m_flag=0;//WYF 20200103
715
}
716

    
717
CAtsTrain::~CAtsTrain()
718
{
719

    
720
}
721

    
722
COLORREF CAtsTrain::GetStatusColor(int nStatus)
723
{
724
	COLORREF clrStatus = RGB(0, 0, 0);
725
	switch (nStatus)
726
	{
727
	case TS_RUN:
728
		clrStatus = m_AtsInfo.TrainRun0;
729
		break;
730
	case TS_HOLD:
731
		clrStatus = m_AtsInfo.TrainRun1;
732
		break;
733
	case TS_BLOCK:
734
		clrStatus = m_AtsInfo.TrainRun2;
735
		break;
736
	case TS_SKIP:
737
		clrStatus = m_AtsInfo.TrainRun3;
738
		break;
739
	case TS_ARRIVE:
740
		clrStatus = m_AtsInfo.TrainRun4;
741
		break;	
742
	case TV_TEXT:
743
		clrStatus = m_AtsInfo.TrainRun5;
744
		break;
745
	case TS_EMPTY://WYF 20200103
746
		clrStatus = m_AtsInfo.TrainRun6;
747
		break;
748
	case TS_UNPLANNED://WYF 20200103
749
		clrStatus = m_AtsInfo.TrainRun7;
750
		break;
751
	case TV_NORMAL://WYF 20200103
752
		clrStatus = m_AtsInfo.TrainRun8;
753
		break;
754
	case TV_SELECTED://WYF 20200103
755
		clrStatus = m_AtsInfo.TrainRun9;
756
		break;
757
	}
758
	return clrStatus;
759
}
760

    
761
CAtsEdge *CAtsTrain::InEdge(float fOffset)
762
{
763
	UINT nNodeID1 = 0, nNodeID2 = 0;
764
	float fLocate1 = 0.000f, fLocate2 = 0.000f;
765
	m_fOffset = 0.0f;
766
	CAtsEdge *pObj = NULL;
767
	CEasyList lstEdge;
768
	CAtsObj *pParent = (CAtsObj *)GetParent();
769
	pParent->GetWndEdges(lstEdge, m_AtsData.ParentEdge);
770
	int nSize = lstEdge.GetListLen();
771
	for (int i = 0; i < nSize; i++)
772
	{
773
		CAtsEdge *pObj = (CAtsEdge *)lstEdge.GetNth(i);
774
		STRUCT_ATSEDGEINFO info = pObj->GetObjectInfo();
775
		CEasyList *plstNodes = pObj->GetWndNodes();
776
		int nNodes = plstNodes->GetListLen();
777
		if (nNodes != 2)
778
		{
779
			pObj = NULL;
780
			continue;
781
		}
782
		CFPoint fpt[2];
783
		for (int j = 0; j < nNodes; j++)
784
		{
785
			CAtsNode *pNodeObj = (CAtsNode *)plstNodes->GetNth(j);
786
			STRUCT_ATSNODEINFO info = pNodeObj->GetObjectInfo();
787
			CFRect frect = pNodeObj->GetObjectRect();
788
			if (j == 0)
789
			{
790
				nNodeID1 = info.NodeID;
791
				fLocate1 = info.Chainage;			
792
				fpt[0] = frect.CenterPoint();
793
			}
794
			else if (j == 1)
795
			{
796
				nNodeID2 = info.NodeID;
797
				fLocate2 = info.Chainage;
798
				fpt[1] = frect.CenterPoint();
799
			}			
800
		}
801
	
802
		if (fLocate1 + fOffset <= fLocate2)
803
		{
804
			m_fOffset = fOffset;
805
			m_fpt0 = fpt[0];
806
			m_fpt1 = fpt[1];
807
			return pObj;
808
		}		
809
		else if (fLocate2 + fOffset <= fLocate1)
810
		{
811
			m_fOffset = fOffset;
812
			m_fpt0 = fpt[1];
813
			m_fpt1 = fpt[0];
814
			return pObj;
815
		}		
816
		fOffset -= info.Width;	
817
		pObj = NULL;
818
	}
819
	if (pObj == NULL)
820
	{
821
		EnableObject(FALSE);
822
		
823
		struct tm stmNow;
824
		timeval tNow;
825
		UTL_GetTimeOfDay(&tNow);		
826
		memset(&stmNow, 0, sizeof(tm));
827
		UTL_Time_tToTm(&tNow.tv_sec, &stmNow);	
828
		int nMSecNow = tNow.tv_usec / 1000;
829
		TRACE("%04d??%02d??%02d?? %02d:%02d:%02d:%03d %04d %04d %d %02d %02d %0.3f\n", \
830
				stmNow.tm_year, stmNow.tm_mon, stmNow.tm_mday, stmNow.tm_hour, \
831
				stmNow.tm_min, stmNow.tm_sec, nMSecNow, m_AtsData.TrainID, m_AtsData.TDN, \
832
				m_AtsData.Dir, m_AtsData.HeadCode, m_AtsData.ParentEdge, m_AtsData.Offset);
833
	}
834
	else
835
	{
836
		EnableObject(TRUE);
837
	}
838
	return pObj;
839
}
840

    
841
CBaseObj *CAtsTrain::CheckArrivalPlatForm(COLORREF &clrActive)
842
{
843
	CAtsObj *pAtsObj = (CAtsObj *)GetParent();
844
	CBaseObj *pObj = pAtsObj->GetPlatFormObj(m_AtsData.Dir,
845
		m_AtsData.ParentEdge, m_AtsData.Offset);
846
	
847
	if (pObj)
848
	{
849
		strcpy(m_PlatFormName, pObj->GetObjectName());
850
		clrActive = pAtsObj->GetArrivalColor();
851
	}
852
	else
853
	{
854
		if (strcmp(m_PlatFormName, "") != 0)
855
		{
856
			pObj = pAtsObj->GetPlatForm(m_PlatFormName);
857
			clrActive = pAtsObj->GetDisArrivalColor();
858
			memset(m_PlatFormName, 0, SMALL_BUFFER_SIZE_NUM);
859
		}
860
	}
861
	return pObj;
862
}
863

    
864

    
865
/*
866
// С?????еĹ켣???ɶ????߶????
867
//						     <<--
868
//	       @-------@-------@---??--@------@------@
869
//        /                                     /
870
//       /                                     / 
871
//	 @--@	      						   @--@
872
//	/   								  /
873
// /									 /
874
//@------@------@------@--------@-------@
875
//                   -->>
876
// @		 :?????߶εĶε?
877
// <<--(????) ?? -->>(????):???????з???
878
*/
879
void CAtsTrain::Draw(CDC *pDC, CTransDriver *pTrans)
880
{
881
	CFRect frectNew, frectOld;
882
	CRect rectNew, rectOld;
883
	CAtsEdge *pObj = NULL;
884
	if (m_AtsData.ParentEdge <= 0)
885
	{
886
		return;
887
	}
888
	double curdbScale;
889
	pTrans->GetCurScale(&curdbScale);
890
	m_dbScale = CGlobal::basescale / curdbScale;
891
	// ?жϵ??Ƿ??ڱ??߶???
892
	pObj = InEdge(m_AtsData.Offset);
893
	if (pObj)
894
	{
895
		// ??ͼ????ת??Ϊ?ͻ?(??Ļ)????
896
		pTrans->MapToClient(&m_fpt0);
897
		pTrans->MapToClient(&m_fpt1);	
898
		double dbAngle = ComputeLineAngle(m_fpt0, m_fpt1);
899
		int nLength = ComputeLineLength(m_fpt0, m_fpt1);
900
		STRUCT_ATSEDGEINFO edgeinfo = pObj->GetObjectInfo();
901
		float fZero = 0.0f;
902
		float fWidth= edgeinfo.Width;
903
		if (fWidth != fZero)
904
		{
905
			float fRealPos = (m_fOffset / fWidth) * nLength;
906
			double dbSlop = DegreesToRadians(dbAngle);
907
			short int nAngle = ((int)dbAngle) % 3600;
908
			SetRotateAngle(nAngle);
909
			int ndx = (int)(fRealPos * cos(dbSlop) + 0.5);
910
			int ndy = (int)(fRealPos * sin(dbSlop) + 0.5);
911
	
912
			// ?????????
913
			CFRect frectPrev;
914
			frectPrev = GetObjectRect();
915

    
916
			m_fPosX = (float)m_fpt0.x;
917
			m_fPosY = (float)m_fpt0.y;
918
			m_fPosX += ndx;
919
			m_fPosY += ndy;
920
		
921
			DrawTrain(pDC, pTrans);	
922
		}
923
	}
924
}
925

    
926
void CAtsTrain::DrawTrain(CDC *pDC, CTransDriver *pTrans)
927
{
928
	BOOL bDrawText = TRUE;
929
	HDC hDc = pDC->GetSafeHdc();
930
	CPoint centerPt;
931
	CFRect frect = GetObjectRect();	
932
	CRect rect;
933
	UINT nHeight = m_AtsInfo.Height;
934
	UINT nWidth = m_AtsInfo.Width;
935

    
936
	CPoint ptTrain[5];
937
	CPoint ptIn[5];
938
	CPoint fptOut[5];
939
	CRgn rgn;
940
	// draw a rectangle or ellipse
941
	CBrush brush;   
942
	COLORREF clrBack;
943
	LONG    left = 1920;
944
    LONG    top = 1200;
945
    LONG    right = 0;
946
    LONG    bottom = 0;
947
	int nLeftOffset = 0;
948
	int nRightOffset = 0;
949
	centerPt.x = (int)m_fPosX;
950
	centerPt.y = (int)m_fPosY;
951
	if (m_AtsData.Dir == TD_UPTRACK)
952
	{	
953
		nRightOffset = (int)(nWidth/4 * m_dbScale);//(int)(5 * m_dbScale);//WYF 20200101 
954
		rect.left = (int)(RoundValue(m_fPosX) - nWidth * m_dbScale - nRightOffset);
955
		rect.top = (int)(RoundValue(m_fPosY) - nHeight  * m_dbScale / 2);
956
		rect.right  = (int)(RoundValue(m_fPosX)  - nRightOffset);
957
		rect.bottom = (int)(RoundValue(m_fPosY) + nHeight * m_dbScale / 2);
958
	
959
		ptIn[0].x = rect.left;		
960
		ptIn[0].y = rect.top;
961
		ptIn[1].x = rect.right;		
962
		ptIn[1].y = rect.top;
963
		
964
		ptIn[2].x = (int)m_fPosX;		
965
		ptIn[2].y = (int)m_fPosY;	
966
		ptIn[3].x = rect.right;		
967
		ptIn[3].y = rect.bottom;
968
		ptIn[4].x = rect.left;		
969
		ptIn[4].y = rect.bottom;	
970
		CalcRotatePoints(ptIn, fptOut, 5, centerPt);
971
		
972
		for (int i = 0; i < 5; i++)
973
		{
974
			ptTrain[i].x = (long)(fptOut[i].x);
975
			ptTrain[i].y = (long)(fptOut[i].y);
976
			left = min(ptTrain[i].x, left);
977
			right = max(ptTrain[i].x, right);			
978
			top = min(ptTrain[i].y, top);
979
			bottom = max(ptTrain[i].y, bottom);
980
		}
981
	
982
		clrBack	= GetStatusColor(m_AtsData.Status);	
983
		brush.CreateSolidBrush(clrBack);
984
		
985
		if (rgn.CreatePolygonRgn(ptTrain, 5, WINDING))
986
		{
987
			pDC->FillRgn(&rgn, &brush);
988
			rgn.DeleteObject();
989
			
990
			CPen NewPen(PS_SOLID, 1, m_AtsInfo.TrainRun8);//RGB(255, 0, 0));//WYF 20200103??ɫ
991
			CPen NewPen1(PS_SOLID, 4, m_AtsInfo.TrainRun9);//RGB(255, 0, 0));//WYF 20200103??ɫ
992
			CPen *pOldPen=NULL;
993
			if(m_flag>0)//WYF 20200103 ???λ????ѡ??С??????ɫ
994
				pOldPen = pDC->SelectObject(&NewPen1);
995
			else
996
				pOldPen = pDC->SelectObject(&NewPen);
997
			pDC->MoveTo(ptTrain[0].x, ptTrain[0].y);
998
			for (i = 1; i < 5; i++)
999
			{
1000
				pDC->LineTo(ptTrain[i].x, ptTrain[i].y);
1001
			}
1002
			pDC->LineTo(ptTrain[0].x, ptTrain[0].y);
1003
			pDC->SelectObject(pOldPen);
1004
		}
1005
	}
1006
	else if (m_AtsData.Dir == TD_DOWNTRACK)
1007
	{
1008
		nLeftOffset = (int)(nWidth/4 * m_dbScale);//(int)(5 * m_dbScale);//WYF 20200101
1009
		rect.left = (int)(RoundValue(m_fPosX) + nLeftOffset);
1010
		rect.top = (int)(RoundValue(m_fPosY) - nHeight  * m_dbScale / 2);
1011
		rect.right  = (int)(RoundValue(m_fPosX) + nWidth * m_dbScale + nLeftOffset);
1012
		rect.bottom = (int)(RoundValue(m_fPosY) + nHeight * m_dbScale / 2);
1013
	
1014
		ptIn[0].x = rect.left;		
1015
		ptIn[0].y = rect.top;
1016
		ptIn[1].x = rect.right;		
1017
		ptIn[1].y = rect.top;	
1018
		ptIn[2].x = rect.right;		
1019
		ptIn[2].y = rect.bottom;
1020
		ptIn[3].x = rect.left;		
1021
		ptIn[3].y = rect.bottom;
1022
		
1023
		ptIn[4].x = (int)(m_fPosX);		
1024
		ptIn[4].y = (int)(m_fPosY);	
1025
		CalcRotatePoints(ptIn, fptOut, 5, centerPt);
1026
		
1027
		for (int i = 0; i < 5; i++)
1028
		{
1029
			ptTrain[i].x = (long)(fptOut[i].x);
1030
			ptTrain[i].y = (long)(fptOut[i].y);
1031
			left = min(ptTrain[i].x, left);
1032
			right = max(ptTrain[i].x, right);			
1033
			top = min(ptTrain[i].y, top);
1034
			bottom = max(ptTrain[i].y, bottom);
1035
		}
1036
	
1037
		clrBack	= GetStatusColor(m_AtsData.Status);	
1038
		brush.CreateSolidBrush(clrBack);
1039
		
1040
		if (rgn.CreatePolygonRgn(ptTrain, 5, WINDING))
1041
		{
1042
			pDC->FillRgn(&rgn, &brush);
1043
			rgn.DeleteObject();
1044

    
1045
			CPen NewPen(PS_SOLID, 1, m_AtsInfo.TrainRun8);//RGB(255, 0, 0));//WYF 20200103??ɫ
1046
			CPen NewPen1(PS_SOLID, 4, m_AtsInfo.TrainRun9);//RGB(255, 0, 0));//WYF 20200103??ɫ
1047
			CPen *pOldPen=NULL;
1048
			if(m_flag>0)//WYF 20200103 ???λ????ѡ??С??????ɫ
1049
				pOldPen = pDC->SelectObject(&NewPen1);
1050
			else
1051
				pOldPen = pDC->SelectObject(&NewPen);
1052
			pDC->MoveTo(ptTrain[0].x, ptTrain[0].y);
1053
			for (i = 1; i < 5; i++)
1054
			{
1055
				pDC->LineTo(ptTrain[i].x, ptTrain[i].y);
1056
			}
1057
			pDC->LineTo(ptTrain[0].x, ptTrain[0].y);
1058
			pDC->SelectObject(pOldPen);
1059
		}	
1060
	}
1061
//	else if (m_AtsData.Dir >= TD_UNKNOWM)
1062
	else if (m_AtsData.Dir >= TD_UNKNOWM || 0>=m_AtsData.Dir)//WYF 20190115
1063
	{
1064
		rect.left = (int)(RoundValue(m_fPosX) - nWidth * m_dbScale / 2);
1065
		rect.top = (int)(RoundValue(m_fPosY) - nHeight  * m_dbScale / 2);
1066
		rect.right  = (int)(RoundValue(m_fPosX) + nWidth  * m_dbScale / 2);
1067
		rect.bottom = (int)(RoundValue(m_fPosY) + nHeight * m_dbScale / 2);
1068
	
1069
		ptIn[0].x = rect.left;		
1070
		ptIn[0].y = rect.top;
1071
		ptIn[1].x = rect.right;		
1072
		ptIn[1].y = rect.top;
1073
		ptIn[2].x = rect.right;		
1074
		ptIn[2].y = rect.bottom;
1075
		ptIn[3].x = rect.left;		
1076
		ptIn[3].y = rect.bottom;
1077
		ptIn[4].x = rect.left;		
1078
		ptIn[4].y = rect.bottom;
1079
		CalcRotatePoints(ptIn, fptOut, 4, centerPt);
1080
		
1081
		for (int i = 0; i < 4; i++)
1082
		{
1083
			ptTrain[i].x = (long)(fptOut[i].x);
1084
			ptTrain[i].y = (long)(fptOut[i].y);
1085
			left = min(ptTrain[i].x, left);
1086
			right = max(ptTrain[i].x, right);			
1087
			top = min(ptTrain[i].y, top);
1088
			bottom = max(ptTrain[i].y, bottom);
1089
		}
1090
		clrBack	= GetStatusColor(m_AtsData.Status);	
1091
		brush.CreateSolidBrush(clrBack);
1092
		
1093
		if (rgn.CreatePolygonRgn(ptTrain, 4, WINDING))
1094
		{
1095
			pDC->FillRgn(&rgn, &brush);
1096
			rgn.DeleteObject();
1097
			
1098
			CPen NewPen(PS_SOLID, 1, m_AtsInfo.TrainRun8);//RGB(255, 0, 0));//WYF 20200103??ɫ
1099
			CPen NewPen1(PS_SOLID, 4, m_AtsInfo.TrainRun9);//RGB(255, 0, 0));//WYF 20200103??ɫ
1100
			CPen *pOldPen=NULL;
1101
			if(m_flag>0 & 0x80)//WYF 20200103 ???λ????ѡ??С??????ɫ
1102
				pOldPen = pDC->SelectObject(&NewPen1);
1103
			else
1104
				pOldPen = pDC->SelectObject(&NewPen);
1105
			pDC->MoveTo(ptTrain[0].x, ptTrain[0].y);
1106
			for (i = 1; i < 4; i++)
1107
			{
1108
				pDC->LineTo(ptTrain[i].x, ptTrain[i].y);
1109
			}
1110
			pDC->LineTo(ptTrain[0].x, ptTrain[0].y);
1111
			pDC->SelectObject(pOldPen);
1112
		}	
1113
	}
1114
	int nAngle = GetRotateAngle();
1115
	CFRect frectNext;
1116
	int nOffset = (int)(2 * m_dbScale + 0.5);
1117
	CRect rectNext(left-nOffset, top-nOffset, right+nOffset, bottom+nOffset);
1118
	// ?ͻ?(??Ļ)????ת??Ϊ??ͼ????
1119
	pTrans->ClientToMap(&rectNext, &frectNext);	
1120
	SetRotateAngle(nAngle);
1121
	SetObjectRect(frectNext);
1122

    
1123
	// ?ı?????
1124
	LOGFONT logFont;
1125
	CFont NewFont, *OldFont;
1126
	double dbw, dbh;	
1127
	CString strText;
1128
	CSize size;	
1129
	CFPoint ptOutText;
1130
	CPoint ptTxtIn, ptTxtOut;
1131
	CRect rectTxt;
1132

    
1133
	BOOL bRet = CalcFontSize(rect, dbh, dbw);
1134
	if (dbh < 5.0 || dbw < 2.0 || m_bShowID == FALSE)
1135
	{
1136
		return;
1137
	}	
1138
	
1139
	logFont.lfHeight = int(dbh - 1);
1140
	logFont.lfWidth = int(dbw - 1);
1141
	logFont.lfEscapement = 3600 - nAngle * 10;
1142
	logFont.lfOrientation = 3600 - nAngle * 10;
1143
	logFont.lfWeight = FW_NORMAL;
1144
	logFont.lfCharSet = DEFAULT_CHARSET;
1145
	logFont.lfOutPrecision = OUT_STRING_PRECIS;
1146
	logFont.lfClipPrecision = CLIP_LH_ANGLES | CLIP_STROKE_PRECIS;
1147
	logFont.lfQuality = DRAFT_QUALITY;
1148
	logFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS;
1149
	logFont.lfItalic = 0;
1150
	logFont.lfUnderline = 0;
1151
	logFont.lfStrikeOut = 0;
1152
	strcpy(logFont.lfFaceName, _T("Arial"));
1153
	NewFont.CreateFontIndirect(&logFont);
1154
	OldFont = pDC->SelectObject(&NewFont);
1155
	COLORREF OldClrTxt, NewClrTxt;
1156
	NewClrTxt	= GetStatusColor(TV_TEXT);	
1157

    
1158

    
1159
	strText.Format("%05d", m_AtsData.TDN);//WYF 20200101 04d??05d
1160

    
1161
	GetTextExtentPoint32(pDC->m_hDC, strText, strText.GetLength(), &size);
1162

    
1163

    
1164
	//????ˮƽλ??	
1165
	ptTxtIn.x = (long)(rect.CenterPoint().x - size.cx/2.0 + 0.5 + 1);
1166

    
1167
	//???㴹ֱλ??
1168
	ptTxtIn.y = (long)(rect.CenterPoint().y - size.cy/2.0 + 0.5);
1169

    
1170

    
1171
	CalcRotatePoints(&ptTxtIn, &ptTxtOut, 1, centerPt);
1172
	
1173
	rectTxt.left = int(ptTxtOut.x+0.5) ;
1174
	rectTxt.right= rectTxt.left  + size.cx ;
1175
	rectTxt.top  = int(ptTxtOut.y+0.5) ;
1176
	rectTxt.bottom = rectTxt.top + size.cy;
1177

    
1178
	int nOldMode = pDC->SetBkMode(TRANSPARENT);
1179
	OldClrTxt = pDC->SetTextColor(NewClrTxt);
1180

    
1181
	pDC->TextOut(rectTxt.left, rectTxt.top, strText, strlen(strText));
1182

    
1183
	pDC->SetBkMode(nOldMode);
1184
	pDC->SetTextColor(OldClrTxt);
1185

    
1186
	pDC->SelectObject(OldFont);		
1187
	NewFont.DeleteObject();	
1188
}
1189

    
1190
char *CAtsTrain::GetTrianNo()
1191
{
1192
	return m_AtsData.TrainNo;
1193
}
1194

    
1195
#define ATS_TRAINID		1
1196
#define ATS_DIR			2
1197
#define ATS_PARENTEDGE	3
1198
#define ATS_OFFSET		4
1199
#define ATS_STATE		5
1200
#define ATS_HEADCODE	6
1201
#define ATS_TDN			7
1202
/*
1203
//char szValue[] = 
1204
//			{
1205
//				"TrainID=1317\n"	\
1206
//				"Dir=1\n"			\
1207
//				"ParentEdge=67\n"	\
1208
//				"Offset=0.000\n"	\
1209
//				"State=0\n"			\
1210
//				"HeadCode=33\n"		\
1211
//				"TDN=712\n"
1212
//			};
1213
*/
1214
void EnCodeATS(CString strATS, STRUCT_ATSDATA &Train)
1215
{
1216
	int nCount = 1;
1217
	CString strKey, strValue;
1218
	CString strAdd;
1219
	while (strATS.Find(_T("\n")) != -1)
1220
	{
1221
		int nDelim = strATS.Find(_T("\n"));
1222
		strAdd = strATS.Left(nDelim);
1223
		int nEqual = strAdd.Find(_T("="));
1224
		if (nEqual > 0)
1225
		{					
1226
			strKey = strAdd.Mid(0, nEqual);
1227
			strValue = strAdd.Mid(nEqual + 1);
1228
			switch (nCount)
1229
			{
1230
			case ATS_TRAINID:
1231
				if (strcmp(strKey, _T("TrainID")) == 0)
1232
				{
1233
					Train.TrainID = atoi(strValue);
1234
				}
1235
				break;
1236
			case ATS_DIR:
1237
				if (strcmp(strKey, _T("Dir")) == 0)
1238
				{
1239
					Train.Dir = atoi(strValue);
1240
				}
1241
				break;
1242
			case ATS_PARENTEDGE:
1243
				if (strcmp(strKey, _T("ParentEdge")) == 0)
1244
				{
1245
					Train.ParentEdge = atoi(strValue);
1246
				}
1247
				break;
1248
			case ATS_OFFSET:
1249
				if (strcmp(strKey, _T("Offset")) == 0)
1250
				{
1251
					Train.Offset = (float)atof(strValue);
1252
				}
1253
				break;
1254
			case ATS_STATE:
1255
				if (strcmp(strKey, _T("State")) == 0)
1256
				{
1257
					Train.Status = atoi(strValue);
1258
				}
1259
				break;
1260
			case ATS_HEADCODE:
1261
				if (strcmp(strKey, _T("HeadCode")) == 0)
1262
				{
1263
					Train.HeadCode = atoi(strValue);
1264
				}
1265
				break;
1266
			case ATS_TDN:
1267
				if (strcmp(strKey, _T("TDN")) == 0)
1268
				{
1269
					Train.TDN = atoi(strValue);
1270
				}
1271
				break;
1272
			}
1273
		}
1274
		strATS = strATS.Mid(nDelim + 1);
1275
		nCount++;
1276
	}
1277
}
1278

    
1279
void CAtsTrain::SetValue(TRAIN_VALUE tv, SREALDB_VAR vtValue)
1280
{
1281
	switch (tv)
1282
	{
1283
	case TV_TRIANID:
1284
		m_AtsData.TrainID = vtValue.m_val.uintval;
1285
		break;
1286
	case TV_TDN:
1287
		m_AtsData.TDN = vtValue.m_val.uintval;
1288
		break;
1289
	case TV_DIR:
1290
		m_AtsData.Dir = vtValue.m_val.ucharval;
1291
		break;
1292
	case TV_PARENTEDGE:
1293
		m_AtsData.ParentEdge = vtValue.m_val.uintval;
1294
		break;
1295
	case TV_OFFSET:
1296
		m_AtsData.Offset = vtValue.m_val.floatval;
1297
		break;
1298
	case TV_STATUS:
1299
		m_AtsData.Status = vtValue.m_val.ucharval;
1300
		break;
1301
	case TV_HEADCODE:
1302
		{
1303
			m_AtsData.HeadCode = vtValue.m_val.ucharval;
1304
			CAtsObj *pParent = (CAtsObj *)GetParent();
1305
			m_strHeadCode = pParent->GetItemDesc(m_AtsData.HeadCode);
1306
		}
1307
	case TV_STRUCT:
1308
		{
1309
			char *szValue = (char *)vtValue.m_strval;
1310
			EnCodeATS(szValue, m_AtsData);
1311
			CAtsObj *pParent = (CAtsObj *)GetParent();
1312
			CString strTrainID, strDesc;
1313
			strTrainID.Format("(%d)", m_AtsData.TrainID);
1314
			strDesc = pParent->GetItemDesc(m_AtsData.HeadCode);
1315
			m_strHeadCode = strDesc + strTrainID;			
1316
		}
1317
	default:
1318
		break;
1319
	}
1320
}
1321

    
1322
void CAtsTrain::ShowID(BOOL bShow)
1323
{
1324
	m_bShowID = bShow;
1325
}
1326

    
1327
BOOL CAtsTrain::CalcFontSize(CRect frect, double &dbheight, double &dbwidth)
1328
{
1329
	char szTrainID[20];
1330
	if (VG_TOO_SMALL(frect.Width()) || VG_TOO_SMALL(frect.Height())) 
1331
	{
1332
		return FALSE;
1333
	}
1334
	sprintf(szTrainID, "%05d", m_AtsData.TrainID);//WYF 20200101 04d??05d
1335
	int nCount = strlen(szTrainID);
1336
	if (nCount <= 0) 
1337
	{
1338
		return FALSE;
1339
	}
1340
	dbheight = frect.Height();
1341
	dbwidth = frect.Width() / (nCount+1);//WYF 20200101ǰ????1?ո??ַ?????
1342
	return TRUE;
1343
}
1344

    
1345
BOOL CAtsTrain::CalcRotatePoints(CPoint* ptIn, CPoint* ptOut, int nptNum, CPoint centerPt)
1346
{
1347
	BOOL bRet = FALSE;
1348
	short int nAngle = GetRotateAngle();
1349
	if (nAngle != 0 && ptIn && ptOut)
1350
	{
1351
		double theta = nAngle * (PI / 180);		
1352
		for (int i = 0; i < nptNum; i++)
1353
		{
1354
			ptOut[i].x = (int)((ptIn[i].x - centerPt.x) * cos(theta) \
1355
				- (ptIn[i].y - centerPt.y) * sin(theta) + centerPt.x);
1356
			ptOut[i].y = (int)((ptIn[i].x - centerPt.x) * sin(theta) \
1357
				+ (ptIn[i].y - centerPt.y) * cos(theta) + centerPt.y);
1358
		}
1359
		bRet = TRUE;
1360
	}
1361
	else if (ptIn && ptOut)
1362
	{
1363
		for (int i = 0; i < nptNum; i++)
1364
		{
1365
			ptOut[i].x = (int)ptIn[i].x;
1366
			ptOut[i].y = (int)ptIn[i].y;
1367
		}
1368
	}
1369
	return bRet;
1370
}
1371

    
1372
CString CAtsTrain::GetHeadCode()
1373
{
1374
	return m_strHeadCode;
1375
}
1376

    
1377
int CAtsTrain::SearchByCircle(CFPoint c, double r, int selmodel)
1378
{
1379
	CFPoint ptTemp[4];
1380
	ptTemp[0].x = m_BaseObjInfo.rectpos.left;
1381
	ptTemp[0].y = m_BaseObjInfo.rectpos.top;
1382
	ptTemp[1].x = m_BaseObjInfo.rectpos.right;
1383
	ptTemp[1].y = m_BaseObjInfo.rectpos.top;
1384
	ptTemp[2].x = m_BaseObjInfo.rectpos.right;
1385
	ptTemp[2].y = m_BaseObjInfo.rectpos.bottom;
1386
	ptTemp[3].x = m_BaseObjInfo.rectpos.left;	
1387
	ptTemp[3].y = m_BaseObjInfo.rectpos.bottom;
1388
	CalcRotatePointArray(ptTemp, NULL, 4);//rotate
1389

    
1390
	if ((SEARCH_MODEL)selmodel == SM_FULL_INSIDE)
1391
	{
1392
		for (int i = 0; i < 4; i++)
1393
		{
1394
			if (VG_DISTANCE_2D(ptTemp[i].x, ptTemp[i].y, c.x, c.y) > r)	return FALSE;
1395
//			if (LineIntersectCircle(ptTemp[i], ptTemp[i+1], c, r, FALSE)) return FALSE;
1396
		}
1397
//		if (VG_DISTANCE_2D(ptTemp[3].x, ptTemp[3].y, c.x, c.y) > r)	return FALSE;
1398
//		if (LineIntersectCircle(ptTemp[0], ptTemp[3], c, r, FALSE)) return FALSE;
1399
		return TRUE;
1400
	}
1401
	else
1402
	{
1403
		for (int i = 0; i < 3; i++)
1404
		{
1405
			if (LineIntersectCircle(ptTemp[i], ptTemp[i+1], c, r)) return TRUE;
1406
		}
1407
		if (LineIntersectCircle(ptTemp[0], ptTemp[3], c, r)) return TRUE;
1408
		if (PointInPolygon(c, ptTemp, 4)) 
1409
			return TRUE;
1410
		return FALSE;
1411
	}
1412
}
(7-7/9)