private void HistoryrecordWin_Load(object sender, EventArgs e) { for (int i = 0; i < 24; i++) { shourTB.Items.Add(i); ehourTB.Items.Add(i); } for (int i = 0; i < 60; i++) { sminuteTB.Items.Add(i); eminuteTB.Items.Add(i); } shourTB.SelectedIndex = 0; ehourTB.SelectedIndex = 0; sminuteTB.SelectedIndex = 0; eminuteTB.SelectedIndex = eminuteTB.Items.Count - 1; ehourTB.SelectedIndex = ehourTB.Items.Count - 1; Dxf.scale = 1; pauseBtn.Text = StrPause; TraceCb.SelectedIndex = 0; //DrawPanel.MouseWheel += DrawPanel_MouseWheel; //设置窗体大小,高度和屏幕相同,宽度为屏幕的2/3; SetWinParam(); //加载当前的地图 StrMapPath = Ini.GetValue(Ini.ConfigPath, Ini.MapSeg, Ini.MapKey_Path); Dxf.PanelCenterX = Dxf.CenterX = DrawPanel.Width / 2; Dxf.PanelCenterY = Dxf.CenterY = DrawPanel.Height / 2; CurBitMap = DxfMapParam.GetDxfMap(StrMapPath, 1, Dxf.CenterX, Dxf.CenterY, DrawPanel.Width, DrawPanel.Height); DrawPanel_Paint(null, null); //计算出面板中地图的宽度与高度 if (DrawPanel.Width / Parameter.RealWidth > DrawPanel.Height / Parameter.RealHeight) { mapheight = DrawPanel.Height; mapwid = mapheight * (Parameter.RealWidth / Parameter.RealHeight); } else { mapwid = DrawPanel.Width; mapheight = mapwid * (Parameter.RealHeight / Parameter.RealWidth); } //计算当前图片与面板的比例 mrscale = (double)mapwid / Parameter.RealWidth; //判断当前是否是多区域模式 if (Parameter.isSupportMulArea) {//在多区域模式下,无法查看轨迹, TraceCb.SelectedIndex = 0; TraceCb.Enabled = false; } }
private void StartBtn_Click(object sender, EventArgs e) { string StrText = StartBtn.Text.Trim(); if (StrText.Equals(StrStart)) { SpeedRate = 8; //在调用程序开始时,先将地图上原来的轨迹删除掉 if (!Parameter.isSupportMulArea) { string StrMapPath = Ini.GetValue(Ini.ConfigPath, Ini.MapSeg, Ini.MapKey_Path); CurBitMap = DxfMapParam.GetDxfMap(StrMapPath, 1, DrawPanel.Width / 2, DrawPanel.Height / 2, DrawPanel.Width, DrawPanel.Height); DrawPanel_Paint(null, null); } StartTrace(); } else { StopTrace(); pauseBtn.Text = StrPause; } Thread.Sleep(10); }
private void DrawTagNode(Dictionary <string, CardImg> tpks) { if (!Parameter.isSupportMulArea) {//不是多区域时,只有一张地图 if (null == CurBitMap) { return; } } Graphics g = null; try { if (!Parameter.isSupportMulArea) { g = Graphics.FromImage(CurBitMap); } } catch (System.InvalidOperationException) { return; } float wscale = 0.0f, hscale = 0.0f; if (!Parameter.isSupportMulArea) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; } Brush tagbrush = Brushes.Green; TagPen linetagpen = null; Pen linepen; System.Drawing.PointF[] points = null; double mapx = 0.0d, mapy = 0.0d, panelx = 0.0d, panely = 0.0d; string strtagid = "", strgroupid = ""; foreach (CardImg tpk in tpks.Values) { strtagid = tpk.ID[0].ToString("X2") + tpk.ID[1].ToString("X2"); if (tpk.Name == null || "".Equals(tpk.Name)) { tpk.Name = Ini.GetValue(Ini.CardPath, strtagid, Ini.Name); } if (!"".Equals(StrTagInfor) && !StrTagInfor.Equals(tpk.Name) && !StrTagInfor.Equals(tpk.ID[0].ToString("X2") + tpk.ID[1].ToString("X2"))) { continue; } if (Parameter.isSupportMulArea) {//支持多区域 strgroupid = tpk.GroupID[0].ToString("X2") + tpk.GroupID[1].ToString("X2"); Group group = null; if (!frm.Groups.TryGetValue(strgroupid, out group)) { continue; } DxfMapParam.ClearDxf(); CurBitMap = DxfMapParam.GetDxfMap(group.grouppath, Dxf.scale, DrawPanel.Width / 2, DrawPanel.Height / 2, DrawPanel.Width, DrawPanel.Height); if (null == CurBitMap) { continue; } DrawPanel.CreateGraphics().DrawImageUnscaled(CurBitMap, 0, 0); g = Graphics.FromImage(CurBitMap); wscale = (float)DrawPanel.Width / group.actualwidth; hscale = (float)DrawPanel.Height / group.actualheight; mrscale = wscale > hscale ? hscale : wscale; mapwid = group.actualwidth * mrscale; mapheight = group.actualheight * mrscale; } // 计算Tag在地图上的坐标 mapx = mrscale * tpk.CardPoint.x; mapy = mrscale * tpk.CardPoint.y; // Tag在面板中的坐标 panelx = (DrawPanel.Width - mapwid) / 2 + mapx; panely = (DrawPanel.Height - mapheight) / 2 + mapy; if (tpk.LocaType == TPPID.TagCommonLocal) { tagbrush = Brushes.Green; } if (tpk.isOverNoMove) { tagbrush = Brushes.Black; } if (tpk.isLowBattery) { tagbrush = Brushes.Indigo; } if (tpk.LocaType == TPPID.TagWarmLocal) { tagbrush = Brushes.Red; } if (TraceMode == 0) { if (panelx <= 0 || panely <= 0) { continue; } g.FillEllipse(tagbrush, (float)(panelx - 4), (float)panely - 4, 8, 8); if (null == tpk.Name || "".Equals(tpk.Name)) { g.DrawString(tpk.ID[0].ToString("X2") + tpk.ID[1].ToString("X2"), new Font("宋体", 12), Brushes.Red, (float)(panelx + 4), (float)(panely + 6)); } else { g.DrawString(tpk.Name + "(" + tpk.ID[0].ToString("X2") + tpk.ID[1].ToString("X2") + ")", new Font("宋体", 12), Brushes.Red, (float)(panelx + 4), (float)(panely + 6)); } } else { linetagpen = GetTagPen(strtagid); if (null == linetagpen) { if (AllTagPens.Count >= 6) { continue; } linetagpen = new TagPen(); System.Buffer.BlockCopy(tpk.ID, 0, linetagpen.ID, 0, 2); linepen = Get6Color(); linetagpen.tagpen = linepen; linetagpen.Name = tpk.Name; AllTagPens.Add(linetagpen); if (panelx >= 0 && panely >= 0) { linetagpen.oldx = panelx; linetagpen.oldy = panely; } } else { if (linetagpen.oldx <= 0 || linetagpen.oldy <= 0) { linetagpen.oldx = panelx; linetagpen.oldy = panely; return; } if (panelx > 0 && panely > 0) { if (null == points) { points = new PointF[2]; } points[0] = new System.Drawing.PointF((float)linetagpen.oldx, (float)linetagpen.oldy); points[1] = new System.Drawing.PointF((float)panelx, (float)panely); try { g.DrawCurve(linetagpen.tagpen, points); } catch (System.OutOfMemoryException ex) { FreeMemory(); Console.WriteLine("内存不足!" + ex.ToString()); } } linetagpen.oldx = panelx; linetagpen.oldy = panely; } } if (Parameter.isSupportMulArea) { if (null == CurBitMap) { return; } DrawPanel_Paint(null, null); } } if (!Parameter.isSupportMulArea) { if (null == CurBitMap) { return; } DrawPanel_Paint(null, null); } if (TraceMode == 1) { if (null == AllTagPens) { return; } if (AllTagPens.Count <= 0) { return; } int logox1 = 15, logoy1 = 0, logox2 = 45, logoy2 = 0; for (int i = 0; i < AllTagPens.Count; i++) { if (null == AllTagPens[i]) { continue; } if (AllTagPens[i].isLogo) { continue; } logoy1 = logoy2 = (i + 1) * 25; if (null == AllTagPens[i].tagpen) { continue; } g.DrawLine(AllTagPens[i].tagpen, new System.Drawing.Point(logox1, logoy1), new System.Drawing.Point(logox2, logoy2)); if (null == AllTagPens[i].Name || "".Equals(AllTagPens[i].Name)) { g.DrawString(AllTagPens[i].ID[0].ToString("X2") + AllTagPens[i].ID[1].ToString("X2"), new Font("宋体", 12), AllTagPens[i].tagpen.Brush, logox2 + 5, logoy2 - 8); } else { g.DrawString(AllTagPens[i].Name + "(" + AllTagPens[i].ID[0].ToString("X2") + AllTagPens[i].ID[1].ToString("X2") + ")", new Font("宋体", 12), AllTagPens[i].tagpen.Brush, logox2 + 5, logoy2 - 8); } AllTagPens[i].isLogo = true; } } if (null != g) { g.Dispose(); } }
private void ShowTag() { try { Dictionary <string, CardImg> dictags = new Dictionary <string, CardImg>(); string StrID = ""; int index = 0; //String strgroupid = ""; while (isStop) { if (DateTime.Compare(startdt, enddt) >= 0) {//达到设置的最终时间后,停止显示 isStop = false; this.Invoke(new Action(() => { StopTrace(); })); break; } Thread.Sleep((int)(TabSec * 1000)); this.Invoke(new Action(() => { label8.Text = "The current time is " + startdt.ToString(); })); //Allpack是所有记录讯息 for (int i = index; i < Allpack.Count; i++) { if (DateTime.Compare(startdt, Allpack[i].ReceiTime) < 0) {//此时时间早于数据包上报的时间 index = i; break; } StrID = Allpack[i].ID[0].ToString("X2") + Allpack[i].ID[1]; CardImg tagimg = null; if (dictags.TryGetValue(StrID, out tagimg)) { tagimg.CardPoint = Allpack[i].CardPoint; tagimg.isShowImg = Allpack[i].isShowImg; tagimg.LocaType = Allpack[i].LocaType; tagimg.isOverNoMove = Allpack[i].isOverNoMove; tagimg.isLowBattery = Allpack[i].isLowBattery; System.Buffer.BlockCopy(Allpack[i].GroupID, 0, tagimg.GroupID, 0, 2); } else { dictags.Add(StrID, (CardImg)Form1.CopyObject(Allpack[i])); } } if (!Parameter.isSupportMulArea) { if (TraceMode == 0) {//以坐标进行显示时每次清楚地图 if (!Parameter.isSupportMulArea) { CurBitMap = DxfMapParam.GetDxfMap(StrMapPath, Dxf.scale, DrawPanel.Width / 2, DrawPanel.Height / 2, DrawPanel.Width, DrawPanel.Height); if (null == CurBitMap) { continue; } else { DrawPanel_Paint(null, null); } } } } DrawTagNode(dictags); try { startdt = startdt.AddSeconds(1); } catch (Exception) { } } } catch (System.Threading.ThreadAbortException) { } catch (Exception ex) { MessageBox.Show(ex.ToString()); return; } }