예제 #1
0
 /// <summary> 绘制元素
 /// </summary>
 /// <param name="gp">绘图图面实例</param>
 /// <param name="offsetlocation">绘制偏移坐标</param>
 public override void Draw(Graphics gp, Point offsetlocation)
 {
     if (Selected)
     {
         _pro.Selected = true;
         _con.Selected = true;
     }
     _pro.Draw(gp, offsetlocation);
     _con.Draw(gp, offsetlocation);
 }
예제 #2
0
        /// <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);
            }
        }