Ejemplo n.º 1
0
        /// <summary>
        /// 格子风格的clone
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            SenderInfo newObj = new SenderInfo();

            CopyTo(newObj);
            return(newObj);
        }
 /// <summary>
 /// 获取指定未知所在的格子信息
 /// </summary>
 /// <param name="pixelX"></param>
 /// <param name="pixelY"></param>
 /// <param name="gridInfo"></param>
 private void GetGridInfoByPos(int pixelX, int pixelY, out SenderInfo gridInfo)
 {
     gridInfo = null;
     if (_curAllSenderGridDic == null)
     {
         return;
     }
     foreach (string commPort in _curAllSenderGridDic.Keys)
     {
         if (_curAllSenderGridDic[commPort] == null)
         {
             continue;
         }
         for (int i = 0; i < _curAllSenderGridDic[commPort].Count; i++)
         {
             if (_curAllSenderGridDic[commPort][i] == null)
             {
                 continue;
             }
             if (_curAllSenderGridDic[commPort][i].SenderRect.Contains(new Point(pixelX, pixelY)))
             {
                 gridInfo = (SenderInfo)(_curAllSenderGridDic[commPort][i].Clone());
                 return;
             }
         }
     }
 }
Ejemplo n.º 3
0
 public MouseOperateInGridEventArgs(MouseEventArgs baseArgs, SenderInfo senderGridInfo)
 {
     _baseArgs = baseArgs;
     if (senderGridInfo == null)
     {
         _senderGridInfo = null;
     }
     else
     {
         _senderGridInfo = (SenderInfo)senderGridInfo.Clone();
     }
 }
Ejemplo n.º 4
0
 public MouseOperateInGridEventArgs(MouseEventArgs baseArgs, SenderInfo senderGridInfo)
 {
     _baseArgs = baseArgs;
     if (senderGridInfo == null)
     {
         _senderGridInfo = null;
     }
     else
     {
         _senderGridInfo = (SenderInfo)senderGridInfo.Clone();
     }
 }
 private void doubleBufferPanel_Draw_MouseMove(object sender, MouseEventArgs e)
 {
     try
     {
         if ((this._lastMouseMoveX != e.X) || (this._lastMouseMoveY != e.Y))
         {
             this._lastMouseMoveX = e.X;
             this._lastMouseMoveY = e.Y;
             if (MouseMoveInGridEvent != null)
             {
                 SenderInfo gridInfo = null;
                 GetGridInfoByPos(e.X, e.Y, out gridInfo);
                 MouseMoveInGridEvent(sender, new MouseOperateInGridEventArgs(e, gridInfo));
             }
         }
     }
     catch
     {
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 格子风格拷贝
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool CopyTo(object obj)
        {
            SenderInfo gridInfo = (SenderInfo)obj;

            if (gridInfo == null)
            {
                return(false);
            }
            gridInfo.CommPort    = CommPort;
            gridInfo.SenderIndex = SenderIndex;
            gridInfo.SenderRect  = SenderRect;
            gridInfo.Status      = Status;

            gridInfo.RefreshRateInfo         = new ValueInfo();
            gridInfo.RefreshRateInfo.IsValid = RefreshRateInfo.IsValid;
            gridInfo.RefreshRateInfo.Value   = RefreshRateInfo.Value;
            gridInfo.RedundantStateTypeList  = new Dictionary <int, RedundantStateType>();
            foreach (int index in RedundantStateTypeList.Keys)
            {
                gridInfo.RedundantStateTypeList.Add(index, RedundantStateTypeList[index]);
            }
            return(true);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 格子风格的clone
 /// </summary>
 /// <returns></returns>
 public object Clone()
 {
     SenderInfo newObj = new SenderInfo();
     CopyTo(newObj);
     return newObj;
 }
        /// <summary>
        /// 绘制一个串口的发送卡
        /// </summary>
        /// <param name="drawX">绘制的X</param>
        /// <param name="drawY">绘制的Y</param>
        /// <param name="commPort">串口名称</param>
        /// <param name="drawGraphics">绘制Graphics</param>
        private void DrawOneCommPortSender(int drawX, int drawY, string commPort, Graphics drawGraphics)
        {
            if (_curAllSenderStatusDic == null ||
                !_curAllSenderStatusDic.ContainsKey(commPort) ||
                _curAllSenderStatusDic[commPort] == null ||
                _curAllSenderStatusDic[commPort].Count <= 0)
            {
                return;
            }
            Point lineStart = Point.Empty;
            Point lineEnd   = Point.Empty;

            drawGraphics.DrawImage(Properties.Resources.CommPort, drawX, drawY, OneCommPortInfoImagePixel, OneCommPortInfoImagePixel);

            lineStart.X = drawX + OneCommPortInfoImagePixel;
            lineStart.Y = drawY + OneCommPortInfoImagePixel / 2;
            lineEnd.X   = lineStart.X + CommPortLineLength;
            lineEnd.Y   = lineStart.Y;
            drawGraphics.DrawLine(CommPortLinePen, lineStart, lineEnd);

            SizeF stringSizeF = drawGraphics.MeasureString(commPort, _commPortFont);

            drawGraphics.DrawString(commPort, _commPortFont, CommPortStrBrush, new PointF(lineStart.X, lineStart.Y - stringSizeF.Height));

            Rectangle senderRect = new Rectangle(lineEnd.X, drawY + SenderSizeOffset / 2,
                                                 OneCommPortInfoImagePixel - SenderSizeOffset,
                                                 OneCommPortInfoImagePixel - SenderSizeOffset);

            int               senderCnt = _curAllSenderStatusDic[commPort].Count;
            string            indexStr  = "";
            PointF            strPointF;
            SenderInfo        senderGridInfo     = null;
            List <SenderInfo> senderGridInfoList = new List <SenderInfo>();
            WorkStatusType    status             = WorkStatusType.Unknown;
            ValueInfo         tempRefreshReate;

            for (byte i = 0; i < senderCnt; i++)
            {
                if (i > 0)
                {
                    senderRect.X += SenderConnectLineLength + OneCommPortInfoImagePixel - SenderSizeOffset;
                }
                status = _curAllSenderStatusDic[commPort][i];
                if (status == WorkStatusType.OK)
                {
                    SenderBrush = new SolidBrush(Color.Green);
                }
                else if (status == WorkStatusType.Error)
                {
                    SenderBrush = new SolidBrush(Color.Yellow);
                }
                else if (status == WorkStatusType.SenderCardError)
                {
                    SenderBrush = new SolidBrush(Color.DarkOrange);
                }
                else
                {
                    SenderBrush = new SolidBrush(Color.Gray);
                }
                tempRefreshReate = new ValueInfo();
                if (_curAllSenderRefreshDic == null ||
                    !_curAllSenderRefreshDic.ContainsKey(commPort) ||
                    _curAllSenderRefreshDic[commPort] == null ||
                    i >= _curAllSenderRefreshDic[commPort].Count)
                {
                    tempRefreshReate.IsValid = false;
                }
                else
                {
                    tempRefreshReate.IsValid = _curAllSenderRefreshDic[commPort][i].IsValid;
                    tempRefreshReate.Value   = _curAllSenderRefreshDic[commPort][i].Value;
                }
                drawGraphics.FillRectangle(SenderBrush, senderRect);
                drawGraphics.DrawRectangle(SenderBoarderAndLinePen, senderRect);

                indexStr    = (i + 1).ToString();
                stringSizeF = drawGraphics.MeasureString(indexStr, _senderStrFont);

                strPointF = new PointF(senderRect.X + (senderRect.Width - stringSizeF.Width) / 2,
                                       senderRect.Y + (senderRect.Height - stringSizeF.Height) / 2);
                drawGraphics.DrawString(indexStr, _senderStrFont, SenderIndexBrush, strPointF);
                RedundantStateType rState = RedundantStateType.Unknown;
                float weightCount         = senderRect.Width;
                if (_commPortData.ContainsKey(commPort) && _commPortData[commPort] > 0)
                {
                    weightCount = senderRect.Width / (float)_commPortData[commPort];
                }
                float    heightCount = (float)senderRect.Width / 4 * 3;
                PointF   newPoint    = senderRect.Location;
                PointF   startPoint  = new PointF(0, 0);
                PointF   endPoint    = new PointF(0, 0);
                PointF[] pointList   = new PointF[4];
                int      step        = 0;

                int masterSender = SenderConnectLineLength + OneCommPortInfoImagePixel - SenderSizeOffset;
                if (_tempRedundancyDict != null && _tempRedundancyDict.ContainsKey(commPort) &&
                    _tempRedundancyDict[commPort] != null &&
                    _commPortData.ContainsKey(commPort) && _redundantStateType.ContainsKey(commPort) &&
                    _redundantStateType[commPort] != null && _redundantStateType[commPort].Count > 0)
                {
                    for (int j = 0; j < _commPortData[commPort]; j++)
                    {
                        if (j >= _redundantStateType[commPort][i].RedundantStateTypeList.Count)
                        {
                            rState = RedundantStateType.Unknown;
                        }
                        else
                        {
                            rState = _redundantStateType[commPort][i].RedundantStateTypeList[j];
                        }
                        if (rState == RedundantStateType.OK)
                        {
                            SenderBrush        = new SolidBrush(Color.Green);
                            CommPortLine.Color = Color.Green;
                            step += 4;
                        }
                        else if (rState == RedundantStateType.Error)
                        {
                            CommPortLine.Color = Color.Red;
                            if (_tempRedundancyDict.ContainsKey(commPort))
                            {
                                for (int k = 0; k < _tempRedundancyDict[commPort].Count; k++)
                                {
                                    SenderRedundancyInfo senderInfo = _tempRedundancyDict[commPort][k];
                                    if (senderInfo.SlaveSenderIndex == i && senderInfo.SlavePortIndex == j)
                                    {
                                        SenderBrush = new SolidBrush(Color.Yellow);
                                        break;
                                    }
                                    else
                                    {
                                        SenderBrush = new SolidBrush(Color.Green);
                                    }
                                }
                            }
                            step += 4;
                        }
                        else
                        {
                            CommPortLine.Color = Color.Gray;
                            SenderBrush        = new SolidBrush(Color.Gray);
                            step += 4;
                        }
                        RectangleF portRect = new RectangleF(newPoint.X + weightCount * j, newPoint.Y + heightCount, weightCount, senderRect.Height / 4);

                        drawGraphics.FillRectangle(SenderBrush, portRect);
                        if (_tempRedundancyDict.ContainsKey(commPort))
                        {
                            for (int k = 0; k < _tempRedundancyDict[commPort].Count; k++)
                            {
                                SenderRedundancyInfo senderInfo = _tempRedundancyDict[commPort][k];
                                if (senderInfo.SlaveSenderIndex == i && senderInfo.SlavePortIndex == j)
                                {
                                    pointList[0] = new PointF(newPoint.X + weightCount * j + weightCount / 2, newPoint.Y + senderRect.Height);
                                    pointList[1] = new PointF(newPoint.X + weightCount * j + weightCount / 2, newPoint.Y + senderRect.Height + step);
                                    if (senderInfo.MasterSenderIndex > senderInfo.SlaveSenderIndex)
                                    {
                                        pointList[2] = new PointF(newPoint.X + masterSender + weightCount * senderInfo.MasterPortIndex + weightCount / 2, newPoint.Y + senderRect.Height + step);
                                        pointList[3] = new PointF(newPoint.X + masterSender + weightCount * senderInfo.MasterPortIndex + weightCount / 2, newPoint.Y + senderRect.Height);
                                    }
                                    else if (senderInfo.MasterSenderIndex < senderInfo.SlaveSenderIndex)
                                    {
                                        pointList[2] = new PointF(newPoint.X - masterSender + weightCount * senderInfo.MasterPortIndex + weightCount / 2, newPoint.Y + senderRect.Height + step);
                                        pointList[3] = new PointF(newPoint.X - masterSender + weightCount * senderInfo.MasterPortIndex + weightCount / 2, newPoint.Y + senderRect.Height);
                                    }
                                    else
                                    {
                                        pointList[2] = new PointF(newPoint.X + weightCount * senderInfo.MasterPortIndex + weightCount / 2, newPoint.Y + senderRect.Height + step);
                                        pointList[3] = new PointF(newPoint.X + weightCount * senderInfo.MasterPortIndex + weightCount / 2, newPoint.Y + senderRect.Height);
                                    }
                                    drawGraphics.DrawLines(CommPortLine, pointList);

                                    if (rState == RedundantStateType.Error)
                                    {
                                        PointF centerPoint = new PointF(pointList[2].X + (pointList[1].X - pointList[2].X) / 2, pointList[1].Y);
                                        startPoint = new PointF(centerPoint.X - 4, centerPoint.Y - 4);
                                        endPoint   = new PointF(centerPoint.X + 4, centerPoint.Y + 4);
                                        drawGraphics.DrawLine(CommPortLine, startPoint, endPoint);

                                        startPoint = new PointF(centerPoint.X - 4, centerPoint.Y + 4);
                                        endPoint   = new PointF(centerPoint.X + 4, centerPoint.Y - 4);
                                        drawGraphics.DrawLine(CommPortLine, startPoint, endPoint);
                                    }

                                    break;
                                }
                            }
                        }
                    }
                    CommPortLine.Color = Color.Black;
                    for (int j = 1; j < _commPortData[commPort]; j++)
                    {
                        startPoint = new PointF(newPoint.X + weightCount * j, newPoint.Y + heightCount);
                        endPoint   = new PointF(newPoint.X + weightCount * j, newPoint.Y + senderRect.Height);
                        drawGraphics.DrawLine(CommPortLine, startPoint, endPoint);
                    }

                    startPoint = new PointF(newPoint.X, newPoint.Y + heightCount);
                    endPoint   = new PointF(newPoint.X + senderRect.Width, newPoint.Y + heightCount);
                    drawGraphics.DrawLine(CommPortLine, startPoint, endPoint);
                }
                if (i < senderCnt - 1)
                {
                    lineStart.X = senderRect.Right;
                    lineStart.Y = drawY + OneCommPortInfoImagePixel / 2;

                    lineEnd.X = senderRect.Right + SenderConnectLineLength;
                    lineEnd.Y = lineStart.Y;

                    drawGraphics.DrawLine(SenderBoarderAndLinePen, lineStart, lineEnd);
                }
                senderGridInfo                 = new SenderInfo();
                senderGridInfo.CommPort        = commPort;
                senderGridInfo.SenderIndex     = i;
                senderGridInfo.SenderRect      = senderRect;
                senderGridInfo.Status          = status;
                senderGridInfo.RefreshRateInfo = tempRefreshReate;
                if (_commPortData.ContainsKey(commPort) && _redundantStateType.ContainsKey(commPort) &&
                    i < _redundantStateType[commPort].Count)
                {
                    for (int j = 0; j < _commPortData[commPort]; j++)
                    {
                        if (j < _redundantStateType[commPort][i].RedundantStateTypeList.Count)
                        {
                            senderGridInfo.RedundantStateTypeList.Add(j, _redundantStateType[commPort][i].RedundantStateTypeList[j]);
                        }
                    }
                }
                senderGridInfoList.Add(senderGridInfo);
            }
            _curAllSenderGridDic.Add(commPort, senderGridInfoList);
        }