/// <summary> 初始化类变量 /// </summary> private void InitializeComponent() { _pro = new ElePath(); _pro.Style.Color = Color.FromArgb(0, 255, 0); _pro.Style.LineHeight = 2; _con = new ElePath(); _con.Style.Color = Color.FromArgb(255, 255, 0); _con.Style.LineHeight = 2; }
/// <summary> 重新设置元素绘制属性 /// </summary> /// <returns>Boolean.</returns> public Boolean ResetElementAll() { _isredraw = true; List <Elements> removeelement = new List <Elements>(); foreach (Elements item in Config.AllElements) { if (item.IsMove(new Rectangle(0, 0, Width, Height))) { switch (item.GetType().BaseType.Name) { default: { break; } case "DrawElements": { switch (item.GetType().Name) { default: { break; } case "ElePath": { ElePath tmp = item as ElePath; tmp.Style.LineHeight = Config.LineWidth; tmp.StartPoint = CorrectPoint(tmp.StartPoint); tmp.EndPoint = CorrectPoint(tmp.EndPoint); break; } case "EleFork": { EleFork tmp = item as EleFork; tmp.ProStyle.LineHeight = Config.LineWidth; tmp.ConStyle.LineHeight = Config.LineWidth; tmp.Root = CorrectPoint(tmp.Root); tmp.Fork1 = CorrectPoint(tmp.Fork1); tmp.Fork2 = CorrectPoint(tmp.Fork2); break; } } break; } case "SignalElements": { SignalElements tmp = item as SignalElements; tmp.LightDiameter = Config.LightDiameter; tmp.DrawPoint = CorrectPoint(tmp.DrawPoint); break; } } } else { removeelement.Add(item); } } foreach (Elements item in removeelement) { Config.AllElements.Remove(item); } return(true); }
/// <summary> 向工作区域绘制元素 /// </summary> /// <param name="gp">绘图对象实例</param> /// <param name="muslocation">鼠标位置坐标</param> /// <param name="eletype">图形种类</param> /// <param name="argv">参数数组<para /> /// argv[0]:绘制类型为路段,muslocation表示StartPoint坐标,argv[0]表示EndPoint坐标;<para /> /// 绘制类型为道岔,muslocation表示Root坐标,argv[0]表示Fork2坐标; /// </param> /// <returns>绘图成功返true,否则返回false</returns> public Boolean DrawElement(Graphics gp, Point muslocation, ElementType eletype, params Object[] argv) { try { switch (eletype) { default: { //判断是否需要重新绘制 if (_isredraw) { Bitmap ways = new Bitmap(_viewsize.Width, _viewsize.Height); Bitmap signals = new Bitmap(_viewsize.Width, _viewsize.Height); Bitmap nodes = new Bitmap(_viewsize.Width, _viewsize.Height); Graphics ways_gp = Graphics.FromImage(ways); Graphics signals_gp = Graphics.FromImage(signals); Graphics nodes_gp = Graphics.FromImage(nodes); gp.Clear(Color.Transparent); foreach (Elements show in _showelements) { if (!show.Selected) { switch (show.GetType().Name) { default: { break; } case "ElePath": case "EleFork": { show.Draw(ways_gp, _viewsize.Location); break; } case "INode": case "ONode": { show.Draw(nodes_gp, _viewsize.Location); break; } case "DSignal": case "DHSignal": case "SSignal": case "SHSignal": { show.Draw(signals_gp, _viewsize.Location); break; } } } else { show.Selected = true; } } gp.DrawImage(ways, 0, 0); gp.DrawImage(nodes, 0, 0); gp.DrawImage(signals, 0, 0); ((IDisposable)ways).Dispose(); ((IDisposable)signals).Dispose(); ((IDisposable)nodes).Dispose(); ((IDisposable)ways_gp).Dispose(); ((IDisposable)signals_gp).Dispose(); ((IDisposable)nodes_gp).Dispose(); } _isredraw = false; break; } case ElementType.Path: { ElePath ele = new ElePath(); ele.StartPoint = CorrectPoint(muslocation); ele.EndPoint = CorrectPoint((Point)argv[0]); ele.Style.LineHeight = Config.LineWidth; ele.Draw(gp, _viewsize.Location); Config.AllElements.Add(ele); _showelements.Add(ele); break; } case ElementType.Fork: { EleFork ele = new EleFork(); ele.Root = CorrectPoint(muslocation); ele.Fork2 = CorrectPoint((Point)argv[0]); ele.Fork1 = new Point(ele.Fork2.X, ele.Root.Y); ele.ProStyle.LineHeight = Config.LineWidth; ele.ConStyle.LineHeight = Config.LineWidth; ele.Draw(gp, _viewsize.Location); Config.AllElements.Add(ele); _showelements.Add(ele); break; } case ElementType.DSignal: { DSignal ele = new DSignal(); ele.DrawPoint = CorrectPoint(muslocation); ele.LightDiameter = Config.LightDiameter; CheckImageLocation(ele, muslocation); ele.Draw(gp, _viewsize.Location); Config.AllElements.Add(ele); _showelements.Add(ele); break; } case ElementType.DHSignal: { DHSignal ele = new DHSignal(); ele.DrawPoint = CorrectPoint(muslocation); ele.LightDiameter = Config.LightDiameter; CheckImageLocation(ele, muslocation); ele.Draw(gp, _viewsize.Location); Config.AllElements.Add(ele); _showelements.Add(ele); break; } case ElementType.SSignal: { SSignal ele = new SSignal(); ele.DrawPoint = CorrectPoint(muslocation); ele.LightDiameter = Config.LightDiameter; CheckImageLocation(ele, muslocation); ele.Draw(gp, _viewsize.Location); Config.AllElements.Add(ele); _showelements.Add(ele); break; } case ElementType.SHSignal: { SHSignal ele = new SHSignal(); ele.DrawPoint = CorrectPoint(muslocation); ele.LightDiameter = Config.LightDiameter; CheckImageLocation(ele, muslocation); ele.Draw(gp, _viewsize.Location); Config.AllElements.Add(ele); _showelements.Add(ele); break; } case ElementType.INode: { INode ele = new INode(); ele.DrawPoint = CorrectPoint(muslocation); CheckImageLocation(ele, muslocation); ele.Draw(gp, _viewsize.Location); Config.AllElements.Add(ele); _showelements.Add(ele); break; } case ElementType.ONode: { ONode ele = new ONode(); ele.DrawPoint = CorrectPoint(muslocation); CheckImageLocation(ele, muslocation); ele.Draw(gp, _viewsize.Location); Config.AllElements.Add(ele); _showelements.Add(ele); break; } } return(true); } catch (Exception) { return(false); } }