Example #1
0
        public void ProcessSweepModeDisplayAcquisition(NWTDevice.RunSweepModeParam AcquisitionParams)
        {
            CGraph Graph       = SpectrumPictureBox.GetGraphConfig();
            CCurve CurveConfig = (CCurve)CurveConfigPropertyGrid.SelectedObject;

            SpectrumPictureBox.SetActiveCurve(CurveConfig);

            CurveConfig.nSpectrumLowFrequency  = AcquisitionParams.nBaseFrequency;
            CurveConfig.nSpectrumHighFrequency = AcquisitionParams.nBaseFrequency + AcquisitionParams.nFrequencyStep * AcquisitionParams.nCount;
            CurveConfig.nFrequencyStep         = AcquisitionParams.nFrequencyStep;

            if (AcquisitionParams.ResultDatas != null)
            {
                Utility.FilterArray(AcquisitionParams.ResultDatas, (int)((FilterMode)FilterComboBox.SelectedItem));
                CurveConfig.SpectrumValues = AcquisitionParams.ResultDatas;
                CurveConfig.DetermineMinMaxLevels();
                CurveConfig.ComputeCaracteristicsParams();
                if (bLoop == false)
                {
                    LOGDraw(""); // new line
                    LOGDraw("*** ----- RESULTS----- ***");
                    LOGDraw(CurveConfig.GetCurveDescription());
                }
            }

            Graph.nLastDrawingLowFrequency  = nFrequencyDetectionStart;
            Graph.nLastDrawingHighFrequency = nFrequencyDetectionEnd;
            SpectrumPictureBox.DrawCurveCollection(SweepModeCurvesList, bLoop);
        }
Example #2
0
        void DrawAdditionnalsInfos(Graphics g, CGraph Graph)
        {
            System.Drawing.Font SampleFont = new Font("Verdana", 8.0f);

            //foreach  (CurveBPMarker Marker in MarkerArray)
            for (int nIndex = 0; nIndex < UserMarkerArray.Length; nIndex++)
            {
                CurveBPMarker Marker = UserMarkerArray[nIndex];
                float         fdB    = 0.0f;
                if (Marker != CurveBPMarker.OFF)
                {
                    switch (Marker)
                    {
                    case CurveBPMarker.MAX_LEVEL:
                        fdB = 0.0f;
                        break;

                    case CurveBPMarker.MIN_LEVEL:
                        fdB = fMinLeveldB - fMaxLeveldB;
                        break;

                    case CurveBPMarker.BP_3dB_TO_MIN:
                        fdB = fMinLeveldB - fMaxLeveldB + 3.0f;
                        break;

                    case CurveBPMarker.BP_6dB_TO_MIN:
                        fdB = fMinLeveldB - fMaxLeveldB + 6.0f;
                        break;

                    default:
                        fdB = -((int)Marker);
                        break;
                    }
                    DrawLevel(fdB, UserMarkerArrayValues[nIndex], g, Graph);
                }
            }

//            DrawLevel(-3.0f, n3dBBandpassLowFrequency, n3dBBandpassHighFrequency, g, Graph);
//            DrawLevel(-6.0f, n6dBBandpassLowFrequency, n6dBBandpassHighFrequency, g, Graph);
//            DrawLevel(-60.0f, n60dBBandpassLowFrequency, n60dBBandpassHighFrequency, g, Graph);
        }
Example #3
0
        public void Draw(CGraph Graph, bool IsActive)
        {
            if (Graph.BitmapWhereDraw.Size.Width == 0 || Graph.BitmapWhereDraw.Size.Height == 0 || Visible == CCurve.YesNo.No)
            {
                return;
            }

            int nWidth  = Graph.BitmapWhereDraw.Size.Width - Graph.LeftBorder - Graph.RightBorder;
            int nHeight = Graph.BitmapWhereDraw.Size.Height - Graph.UpBorder - Graph.LowBorder;

            Graphics g = Graphics.FromImage(Graph.BitmapWhereDraw);

            if (Graph.AntiAlias)
            {
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            }
            else
            {
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
            }


            if (SpectrumValues != null &&
                nSpectrumLowFrequency < Graph.nLastDrawingHighFrequency &&
                nSpectrumHighFrequency > Graph.nLastDrawingLowFrequency &&
                Graph.nLastDrawingHighFrequency > Graph.nLastDrawingLowFrequency)    // check if curve is visible
            {
                float fVerticalRangedB = Graph.fLastDrawingLevelHigh - Graph.fLastDrawingLevelLow;
                float fVerticalScale   = nHeight / fVerticalRangedB;


                Pen mypen = new Pen(Color_, LineWidth);


                int    nFirstSpectrumIndex;
                double fXStartOffset = 0;
                double fXEndOffset   = 0;

                double fSpectrumHRes = (double)(Graph.nLastDrawingHighFrequency - Graph.nLastDrawingLowFrequency) / nWidth;
                Int64  nCurveBW      = nSpectrumHighFrequency - nSpectrumLowFrequency;

                if (nSpectrumLowFrequency < Graph.nLastDrawingLowFrequency)
                {
                    nFirstSpectrumIndex = (Int32)(((double)(Graph.nLastDrawingLowFrequency - nSpectrumLowFrequency) * SpectrumValues.Length) / nCurveBW);
                }
                else
                {
                    nFirstSpectrumIndex = 0;
                    fXStartOffset       = (nSpectrumLowFrequency - Graph.nLastDrawingLowFrequency) / fSpectrumHRes;
                }

                int nLastSpectrumIndex;

                if (nSpectrumHighFrequency > Graph.nLastDrawingHighFrequency)
                {
                    nLastSpectrumIndex = (Int32)(((double)(Graph.nLastDrawingHighFrequency - nSpectrumLowFrequency) * SpectrumValues.Length) / nCurveBW);
                }
                else
                {
                    nLastSpectrumIndex = SpectrumValues.Length - 1;
                    fXEndOffset        = (Graph.nLastDrawingHighFrequency - nSpectrumHighFrequency) / fSpectrumHRes;
                }

                int nSpectrumCount = nLastSpectrumIndex - nFirstSpectrumIndex;

                int nPixelToDisplay = nWidth - (int)(fXEndOffset + fXStartOffset);

                PointF[] Mesures = new PointF[nSpectrumCount];

                for (int i = 0; i < nSpectrumCount; i++)
                {
                    float fMesure = 0.0f;
                    if (Graph.outputMode == OutputMode.dB)
                    {
                        fMesure = SpectrumValues[i + nFirstSpectrumIndex];
                    }
                    else
                    {
                        float fdBValue = SpectrumValues[i + nFirstSpectrumIndex];
                        if (fdBValue > 0.0f)
                        {
                            fdBValue = 0.0f;
                        }

                        double fReflective = Math.Pow(10, fdBValue / 20.0f);
                        double WSR         = (1.0 + fReflective) / (1.0 - fReflective);
                        fMesure = (float)Math.Max(Math.Min(WSR, Graph.fLastDrawingLevelHigh), 1.0);
                    }

                    Mesures[i].Y = ((Graph.fLastDrawingLevelHigh - fMesure) * fVerticalScale) + Graph.UpBorder;
                    Mesures[i].X = (float)(((double)i * nPixelToDisplay) / nSpectrumCount + Graph.LeftBorder + fXStartOffset);
                }

                if (Mesures.Length > 1)
                {
                    g.DrawLines(mypen, Mesures);
                }

                if (IsActive)
                {
                    System.Drawing.Font SampleFont = new Font("Verdana", 8.0f);

                    float fPixelPerSample = (float)Math.Round((float)nWidth / nSpectrumCount, 1);
                    float fSamplePerPixel = (float)Math.Round((float)nSpectrumCount / nWidth, 1);


                    if (nSpectrumCount > nWidth)
                    {
                        g.DrawString("Samples: " + nSpectrumCount.ToString() + " (" + fSamplePerPixel.ToString() + " Samples per pixel)", SampleFont, Brushes.Black, new Point(nWidth - 180, 10));
                    }
                    else
                    {
                        g.DrawString("Samples: " + nSpectrumCount.ToString() + " (" + fPixelPerSample.ToString() + " Pixel per sample)", SampleFont, Brushes.Red, new Point(nWidth - 180, 10));
                    }
                }

                if (Graph.outputMode == OutputMode.dB)
                {
                    DrawAdditionnalsInfos(g, Graph);
                }
            }

            g.Dispose();
        }
Example #4
0
        void DrawLevel(float dB, MarkersValues Marker, Graphics g, CGraph Graph)
        {
            Pen mypenArrow = new Pen(Color.Black, 1.0f);
            Pen mypenHline = new Pen(Color.Black, 1.0f);

            mypenHline.DashStyle = DashStyle.Dash;

            Pen mypenVline = new Pen(Color.Black, LineWidth);

            mypenVline.DashStyle = DashStyle.DashDot;

            System.Drawing.StringFormat VerticalTextDrawFormat = new System.Drawing.StringFormat();
            VerticalTextDrawFormat.FormatFlags = StringFormatFlags.DirectionVertical;


            System.Drawing.Font SampleFont = new Font("Verdana", Graph.BitmapWhereDraw.Width / 120.0f);

            String ndB = ((int)dB).ToString() + "dB";

            bool bCliped = false;


            // bandpass
            if (Marker.HighFreq > 0 && Marker.LowFreq > 0)
            {
                // bandpass
                PointF HCoords1 = Graph.GetCoords(Marker.LowFreq, fMaxLeveldB + dB, ref bCliped);
                if (!bCliped)
                {
                    mypenHline.CustomStartCap = new AdjustableArrowCap(5.0f, 5.0f);
                }
                if (!bCliped)
                {
                    PointF VCoords1 = new PointF(HCoords1.X, Graph.UpBorder);
                    PointF VCoords2 = new PointF(HCoords1.X, Graph.BitmapWhereDraw.Height - Graph.LowBorder);
                    g.DrawLine(mypenVline, VCoords1, VCoords2);

                    PointF CoordVCenter = new PointF(VCoords1.X, 0.5f * (VCoords1.Y + VCoords2.Y));
                    g.DrawString(Utility.GetFrequencyStringAtBest(Marker.LowFreq), SampleFont, Brushes.Black, CoordVCenter, VerticalTextDrawFormat);
                }

                PointF HCoords2 = Graph.GetCoords(Marker.HighFreq, fMaxLeveldB + dB, ref bCliped);
                if (!bCliped)
                {
                    mypenHline.CustomEndCap = new AdjustableArrowCap(5.0f, 5.0f);
                }
                if (!bCliped)
                {
                    PointF VCoords1 = new PointF(HCoords2.X, Graph.UpBorder);
                    PointF VCoords2 = new PointF(HCoords2.X, Graph.BitmapWhereDraw.Height - Graph.LowBorder);
                    g.DrawLine(mypenVline, VCoords1, VCoords2);

                    PointF CoordVCenter = new PointF(VCoords1.X, 0.5f * (VCoords1.Y + VCoords2.Y));
                    g.DrawString(Utility.GetFrequencyStringAtBest(Marker.HighFreq), SampleFont, Brushes.Black, CoordVCenter, VerticalTextDrawFormat);
                }

                g.DrawLine(mypenHline, HCoords1, HCoords2);

                PointF CoordCenter = new PointF(0.5f * (HCoords1.X + HCoords2.X), HCoords1.Y);
                g.DrawString(" " + ndB + " (" + Utility.GetFrequencyStringAtBest(Marker.BandPass) + ")", SampleFont, Brushes.Black, CoordCenter);
            }
            else
            {
                if (Marker.BandPass == 0)
                {
                    // Hline ( min or max)
                    PointF Coords0 = Graph.GetCoords(this.nSpectrumLowFrequency, fMaxLeveldB + dB, ref bCliped);
                    PointF Coords1 = Graph.GetCoords(this.nSpectrumHighFrequency, fMaxLeveldB + dB, ref bCliped);
                    g.DrawLine(mypenHline, Coords0, Coords1);
                }
                else
                {
                    if (Marker.HighFreq > 0)
                    {
                        // low pass
                        PointF Coords0 = Graph.GetCoords(this.nSpectrumLowFrequency, fMaxLeveldB + dB, ref bCliped);
                        PointF Coords1 = Graph.GetCoords(Marker.HighFreq, fMaxLeveldB + dB, ref bCliped);
                        PointF Coords2 = new PointF(Coords1.X, Graph.BitmapWhereDraw.Height - Graph.LowBorder);

                        g.DrawLine(mypenHline, Coords0, Coords1);
                        g.DrawLine(mypenVline, Coords1, Coords2);


                        PointF CoordHCenter = new PointF(0.5f * (Coords0.X + Coords1.X), Coords0.Y);
                        PointF CoordVCenter = new PointF(Coords1.X, 0.5f * (Coords1.Y + Coords2.Y));

                        g.DrawString(Utility.GetFrequencyStringAtBest(Marker.HighFreq), SampleFont, Brushes.Black, CoordVCenter, VerticalTextDrawFormat);
                        g.DrawString(ndB, SampleFont, Brushes.Black, CoordHCenter);
                    }

                    if (Marker.LowFreq > 0)
                    {
                        PointF Coords0 = Graph.GetCoords(this.nSpectrumHighFrequency, fMaxLeveldB + dB, ref bCliped);
                        PointF Coords1 = Graph.GetCoords(Marker.LowFreq, fMaxLeveldB + dB, ref bCliped);
                        PointF Coords2 = new PointF(Coords1.X, Graph.BitmapWhereDraw.Height - Graph.LowBorder);

                        g.DrawLine(mypenHline, Coords0, Coords1);
                        g.DrawLine(mypenVline, Coords1, Coords2);

                        PointF CoordCenter  = new PointF(0.5f * (Coords0.X + Coords1.X), Coords0.Y);
                        PointF CoordVCenter = new PointF(Coords1.X, 0.5f * (Coords1.Y + Coords2.Y));

                        g.DrawString(Utility.GetFrequencyStringAtBest(Marker.LowFreq), SampleFont, Brushes.Black, CoordVCenter, VerticalTextDrawFormat);

                        g.DrawString(ndB, SampleFont, Brushes.Black, CoordCenter);
                    }
                }
            }
        }
Example #5
0
        void SetAnalyzer(int Index, bool TakeAcountOfSave = false)
        {
            if (DeviceArray.Count > 0)
            {
                NWTCompatibleDeviceDef DeviceDef = (NWTCompatibleDeviceDef)DeviceArray[Index];
                CurrentDeviceDef = DeviceDef;
                DeviceInterface.SetDevice(DeviceDef);
                LoadCalibrationFile();

                Int64 LowRange;
                Int64 HighRange;

                if (TakeAcountOfSave == true)
                {
                    if (Program.Save.LowFrequency >= DeviceInterface.MinFrequency &&
                        Program.Save.LowFrequency <= DeviceInterface.MaxFrequency)
                    {
                        LowRange = Program.Save.LowFrequency;
                    }
                    else
                    {
                        LowRange = DeviceInterface.MinFrequency;
                    }

                    if (Program.Save.HighFrequency <= DeviceInterface.MaxFrequency &&
                        Program.Save.HighFrequency >= DeviceInterface.MinFrequency)
                    {
                        HighRange = Program.Save.HighFrequency;
                    }
                    else
                    {
                        HighRange = DeviceInterface.MaxFrequency;
                    }
                }
                else
                {
                    LowRange  = DeviceInterface.MinFrequency;
                    HighRange = DeviceInterface.MaxFrequency;
                }

                SetSweepFrequencies(LowRange, HighRange);
                SetSweepFrequencies(LowRange, HighRange);


                CGraph Graph = SpectrumPictureBox.GetGraphConfig();

                Graph.fLastDrawingLevelLow      = -90;
                Graph.fLastDrawingLevelHigh     = 10;
                Graph.nLastDrawingLowFrequency  = LowRange;
                Graph.nLastDrawingHighFrequency = HighRange;
                SpectrumPictureBox.GetGraphConfig().DrawBackGround();

                if (!DeviceDef.Attenuator)
                {
                    AttLevelcomboBox.SelectedIndex = 0;
                    AttLevelcomboBox.Enabled       = false;
                }
                else
                {
                    AttLevelcomboBox.Enabled = true;
                    if (Program.Save.LastUsedAttLevel != null)
                    {
                        AttLevel Level;
                        try
                        {
                            Level = (AttLevel)System.Enum.Parse(typeof(AttLevel), Program.Save.LastUsedAttLevel);
                        }
                        catch (Exception)
                        {
                            Level = AttLevel._0dB;
                        }
                        AttLevelcomboBox.SelectedIndex = (int)Level;
                    }
                    else
                    {
                        AttLevelcomboBox.SelectedIndex = 0;
                    }
                }

                if (!DeviceDef.HaveLinDetector)
                {
                    DetectorCombobox.SelectedIndex = 0;
                    DetectorCombobox.Enabled       = false;
                }
                else
                {
                    DetectorCombobox.Enabled = true;
                }

                AttCalCheckBox.Enabled = DeviceDef.Attenuator;
            }

            if (SerialPortComboBox.SelectedItem != null)
            {
                SerialPortInitialize((String)SerialPortComboBox.SelectedItem);
            }
        }