Пример #1
0
        private void SenderStatusUC_MouseMoveInGridEvent(object sender, MouseOperateInGridEventArgs e)
        {
            if (_customToolTip == null)
            {
                _customToolTip                = new CustomToolTip();
                _customToolTip.Owner          = this.ParentForm;
                _customToolTip.TipContentFont = _customToolTipFont;
            }
            if (e.SenderGridInfo == null)
            {
                _customToolTip.SetTipInfo(_senderStatusUC.DrawPanel, null);
                return;
            }
            List <string> noticeStrList = new List <string>();

            noticeStrList.Add(GetLangText("CommPortName", "串口") + ":" + e.SenderGridInfo.CommPort);
            noticeStrList.Add(GetLangText("SenderName", "发送卡") + ":" + (e.SenderGridInfo.SenderIndex + 1).ToString());
            if (e.SenderGridInfo.Status == WorkStatusType.OK)
            {
                noticeStrList.Add(GetLangText("DVISignalOK", "DVI信号:正常"));
                //DVI信号正常时显示发送卡的刷新率
                string refreshReteStr = GetLangText("RefreshRate", "刷新率:");
                if (!e.SenderGridInfo.RefreshRateInfo.IsValid)
                {
                    refreshReteStr += GetLangText("label_Unknown", "未知");
                }
                else
                {
                    refreshReteStr += e.SenderGridInfo.RefreshRateInfo.Value.ToString() + " HZ";
                }
                noticeStrList.Add(refreshReteStr);
            }
            else if (e.SenderGridInfo.Status == WorkStatusType.Error)
            {
                noticeStrList.Add(GetLangText("DVISignalException", "DVI信号:异常"));
            }
            else if (e.SenderGridInfo.Status == WorkStatusType.Unknown)
            {
                noticeStrList.Add(GetLangText("DVISignalUnkonwn", "DVI信号:未知"));
            }
            else if (e.SenderGridInfo.Status == WorkStatusType.SenderCardError)
            {
                noticeStrList.Add(GetLangText("SenderCardUnkonwn", "发送卡:发送卡故障"));
            }
            string msg     = "";
            string portMsg = "";

            if (_tempRedundancyDict != null && _tempRedundancyDict.Count > 0 &&
                _tempRedundancyDict.ContainsKey(e.SenderGridInfo.CommPort))
            {
                if (_tempRedundancyDict[e.SenderGridInfo.CommPort] != null &&
                    _tempRedundancyDict[e.SenderGridInfo.CommPort].Count > 0)
                {
                    foreach (int i in e.SenderGridInfo.RedundantStateTypeList.Keys)
                    {
                        RedundantStateType state = e.SenderGridInfo.RedundantStateTypeList[i];
                        if (state == RedundantStateType.OK)
                        {
                            portMsg = "";
                            msg     = GetLangText("PortNormal", "网口:正常");
                        }
                        else if (state == RedundantStateType.Error)
                        {
                            if (_tempRedundancyDict.ContainsKey(e.SenderGridInfo.CommPort))
                            {
                                for (int j = 0; j < _tempRedundancyDict[e.SenderGridInfo.CommPort].Count; j++)
                                {
                                    SenderRedundancyInfo senderInfo = _tempRedundancyDict[e.SenderGridInfo.CommPort][j];
                                    if (senderInfo.SlaveSenderIndex == e.SenderGridInfo.SenderIndex && senderInfo.SlavePortIndex == i)
                                    {
                                        portMsg = "-" + GetLangText("MasterSenderPort", "主网口:发送卡") + (senderInfo.MasterSenderIndex + 1) + "-" + GetLangText("Port", "网口") + (senderInfo.MasterPortIndex + 1);
                                        msg     = GetLangText("PortRedundant", "网口:冗余");
                                        break;
                                    }
                                    else
                                    {
                                        msg = GetLangText("PortNormal", "网口:正常");
                                    }
                                }
                            }
                        }
                        else if (state == RedundantStateType.Unknown)
                        {
                            portMsg = "";
                            msg     = GetLangText("PortUnknown", "网口:未知");
                        }
                        msg = (i + 1) + msg + portMsg;
                        noticeStrList.Add(msg);
                    }
                }
            }
            _customToolTip.SetTipInfo(_senderStatusUC.DrawPanel, noticeStrList);
            if (!_customToolTip.TopLevel)
            {
                _customToolTip.TopLevel = true;
            }
        }
        /// <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);
        }