Exemple #1
0
        /// <summary>
        /// 转换为扩展中频测量结果
        /// </summary>
        /// <param name="pDataFrame"></param>
        /// <param name="pParameter"></param>
        protected override void InternalConverter(RmtpDataFrame pDataFrame, object pParameter)
        {
            int index           = 0;
            var pDescribeHeader = pParameter as IffqexDescribeHeader;

            IfqexCount = BitConverter.ToInt16(pDataFrame.Data, index);
            频谱曲线点数     = BitConverter.ToInt32(pDataFrame.Data, index += 2);
            中心频率       = BitConverter.ToInt64(pDataFrame.Data, index += 4);
            中心点数据值     = BitConverter.ToInt16(pDataFrame.Data, index += 8);
            频谱数据类型     = BitConverter.ToInt16(pDataFrame.Data, index += 2);
            index     += 2;
            for (Int32 i = 0; i < 频谱曲线点数; i++)
            {
                if (index >= pDataFrame.Data.Length)
                {
                    System.Diagnostics.Debug.WriteLine("数据帧大小有问题");
                    return;
                }
                数据值[i] = (Int16)(BitConverter.ToInt16(pDataFrame.Data, index) / 100);  //因senser端做了乘100操作,这里做除100
                index += 2;
            }
            if (pDescribeHeader != null && pDescribeHeader.DataTypeList.Count == IfqexCount)
            {
                for (Int16 i = 0; i < IfqexCount; i++)
                {
                    pDescribeHeader.DataTypeList[i].Value = (float)Utile.MathNoRound(BitConverter.ToSingle(pDataFrame.Data, index), 3);
                    index += 4;
                }
            }
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            object v = value;
            string t = parameter as string;

            if (t != null)
            {
                _converterUnit = t;
            }
            if (!string.IsNullOrWhiteSpace(_converterUnit))
            {
                switch (_converterUnit.ToUpper())
                {
                case "GHZ":
                    v = WMonitorUtile.ConvertFreqValue("hz", "ghz", System.Convert.ToDouble(value));
                    break;

                case "MHZ":
                    v = WMonitorUtile.ConvertFreqValue("hz", "mhz", System.Convert.ToDouble(value));
                    break;

                case "KHZ":
                    v = WMonitorUtile.ConvertFreqValue("hz", "khz", System.Convert.ToDouble(value));
                    break;

                case "HZ":
                    v = Utile.MathNoRound(System.Convert.ToDouble(value), 0);
                    break;
                }
            }
            return(v);
        }
        public void Update()
        {
            if (!BeginValue.Equals(EndValue))
            {
                double vunit      = GetUnitValue();
                uint   defaultDec = DefaultDecLength;

                var valStrs = new List <string>();

start:
                valStrs.Clear();

                for (int i = 0; i < _scaleTextBlocks.Count; i++)
                {
                    double dv = Utile.MathNoRound(BeginValue + i * vunit, defaultDec);
                    if (double.IsNaN(dv))
                    {
                        return;
                    }

                    string v;
                    if (string.IsNullOrWhiteSpace(ValueFormat))
                    {
                        v = string.Format("{0:N" + defaultDec + "}", dv);
                        if (ScaleConvertValue != null)
                        {
                            var args = new ScaleValueConverterArgs(i, defaultDec, v);
                            ScaleConvertValue(args);
                            v = args.NewValue != null?args.NewValue.ToString() : string.Empty;
                        }
                    }
                    else
                    {
                        v = string.Format(ValueFormat, dv);
                    }

                    if (AutoExtendDec && defaultDec < MaxExtendDec)
                    {
                        foreach (var obj in valStrs)
                        {
                            if (obj.StartsWith(v))
                            {
                                defaultDec += 1;
                                goto start;
                            }
                        }
                    }

                    valStrs.Add(_scaleTextBlocks[i].Text);
                    _scaleTextBlocks[i].Text = v;
                }
            }

            for (int i = 0; i < _scaleTextBlocks.Count; i++)
            {
                switch (Direction)
                {
                case ScaleLabelDirection.Left:
                case ScaleLabelDirection.Right:

                    double h = _scaleTextBlocks[i].ActualHeight / 2;
                    if (i == 0)
                    {
                        _scaleTextBlocks[i].Margin = new Thickness(0, -h, 0, 0);
                    }
                    else if (i == ScaleLabelCount - 1)
                    {
                        _scaleTextBlocks[i].Margin = new Thickness(0, 0, 0, -h);
                    }

                    break;

                case ScaleLabelDirection.Bottom:
                case ScaleLabelDirection.Top:
                    double w = _scaleTextBlocks[i].ActualWidth / 2;
                    if (i == 0)
                    {
                        _scaleTextBlocks[i].Margin = new Thickness(-w, 0, 0, 0);
                    }
                    else if (i == ScaleLabelCount - 1)
                    {
                        _scaleTextBlocks[i].Margin = new Thickness(0, 0, -w, 0);
                    }

                    break;
                }
            }
        }
        /// <summary>
        /// 刻度更新
        /// </summary>
        private void UpdateScales()
        {
            if (_rangePanel == null)
            {
                return;
            }
            uint   defaultDec = DefaultDecLength;
            double vunit      = GetUnitValue();
            double unit       = GetUnitSize();
            var    valStrs    = new List <string>();

            if (BeginValue.Equals(EndValue))
            {
                for (int i = 0; i < ScaleLabelCount; i++)
                {
                    valStrs.Add("--:--:--");
                }
                UpdateScales2(Direction, valStrs, unit);
                return;
            }
            if (vunit.Equals(0) || unit.Equals(0))
            {
                return;
            }
start:
            valStrs.Clear();

            for (int i = 0; i < ScaleLabelCount; i++)
            {
                double dv = Utile.MathNoRound(BeginValue + i * vunit, defaultDec);
                if (double.IsNaN(dv))
                {
                    return;
                }
                string v;
                if (string.IsNullOrWhiteSpace(ValueFormat))
                {
                    v = string.Format("{0:N" + defaultDec + "}", dv);
                    if (ScaleConvertValue != null)
                    {
                        var args = new ScaleValueConverterArgs(i, defaultDec, v);
                        ScaleConvertValue(args);
                        v = args.NewValue != null?args.NewValue.ToString() : string.Empty;
                    }
                }
                else
                {
                    v = string.Format(ValueFormat, dv);
                }

                if (AutoExtendDec && defaultDec < MaxExtendDec)
                {
                    foreach (var obj in valStrs)
                    {
                        if (obj.StartsWith(v))
                        {
                            defaultDec += 1;
                            goto start;
                        }
                    }
                }
                valStrs.Add(v);
            }

            UpdateScales2(Direction, valStrs, unit);
        }