Example #1
0
        private static bool drawPicture(FrequencyRange range, double maxShowFreq,
            List<ChannelSetting> channels, bool displayChannel,
            List<WatsEmiSample> samples, int minRssi, int maxRssi, 
            string picturePath, string title)
        {
            try
            {
                double span = range.EndFreq - range.FromFreq;
                double minX = range.FromFreq;

                Bitmap bmp = new Bitmap(418, 180);
                Graphics gs = Graphics.FromImage(bmp);
                /*
                Rectangle rect = new Rectangle(0, 0, 418, 180);
                Metafile mf = new Metafile(channelPictureFile, gs.GetHdc(), rect, MetafileFrameUnit.Pixel);
                */
                Metafile mf = new Metafile(picturePath, gs.GetHdc());

                Graphics g = Graphics.FromImage(mf);
                //Graphics g = Graphics.FromImage(bmp);

                using (Brush bgBrush = new SolidBrush(Color.FromArgb(255, 255, 128)))
                    g.FillRectangle(bgBrush, 0, 0, 418, 180);

                using (Pen outerRectPen = new Pen(Color.Black, 1.0f))
                    g.DrawRectangle(outerRectPen, 52, 15, 350, 130);

                using (Pen gridPen = new Pen(Color.Gray, 0.5f))
                {
                    gridPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                    for (int j = 0; j < 9; j++)
                        g.DrawLine(gridPen, 52, 15 + (j + 1) * 13, 402, 15 + (j + 1) * 13);

                    for (int j = 0; j < 9; j++)
                        g.DrawLine(gridPen, 52 + (j + 1) * 35, 15, 52 + (j + 1) * 35, 145);
                }

                string text;
                using (Font font = new Font("Times New Roman", 8.0f))
                {
                    text = "Power (dBm)";
                    StringFormat sf = new StringFormat(StringFormatFlags.DirectionVertical);
                    SizeF sizef = g.MeasureString(text, font, Int32.MaxValue, sf);

                    RectangleF rf = new RectangleF(15, 75 - sizef.Height / 2, sizef.Width, sizef.Height);

                    g.TranslateTransform((rf.Left + rf.Right) / 2, (rf.Top + rf.Bottom) / 2);
                    g.RotateTransform(180);

                    RectangleF newRf = new RectangleF(-sizef.Width / 2, -sizef.Height / 2, sizef.Width, sizef.Height);
                    g.DrawString(text, font, Brushes.Black, newRf, sf);
                    g.ResetTransform();
                }

                using (Font font = new Font("Times New Roman", 8.0f))
                {
                    text = "Frequency (MHz)";
                    SizeF sizef = g.MeasureString(text, font, Int32.MaxValue);
                    RectangleF rf = new RectangleF(227 - sizef.Width / 2, 160, sizef.Width, sizef.Height);

                    //g.DrawRectangle(Pens.Black, newRf.Left, newRf.Top, newRf.Width, newRf.Height);
                    g.DrawString(text, font, Brushes.Black, rf);
                }

                using (Font font = new Font("Times New Roman", 5.0f))
                {
                    List<string> xTexts = new List<string>();
                    int j = 0;
                    for (j = 0; j < 10; j++)
                        xTexts.Add(Utility.ConvertDoubleString(minX + span * j / 10));
                    xTexts.Add(Utility.ConvertDoubleString(minX + span));

                    j = 0;
                    SizeF sizef;
                    RectangleF rf;
                    foreach (string xText in xTexts)
                    {
                        sizef = g.MeasureString(xText, font, Int32.MaxValue);
                        rf = new RectangleF(52 + j * 35 - sizef.Width / 2, 147,
                            sizef.Width, sizef.Height);
                        g.DrawString(xText, font, Brushes.Black, rf);
                        j++;
                    }
                }

                using (Font font = new Font("Times New Roman", 5.0f))
                {
                    List<string> yTexts = new List<string>();
                    int j;
                    for (j = 0; j < 11; j++)
                        yTexts.Add("-" + (minRssi + (maxRssi - minRssi) / 10 * j).ToString());

                    SizeF sizef;
                    RectangleF rf;
                    j = 0;
                    foreach (string yText in yTexts)
                    {
                        sizef = g.MeasureString(yText, font, Int32.MaxValue);
                        rf = new RectangleF(50 - sizef.Width, 15 + j * 13 - sizef.Height / 2,
                            sizef.Width, sizef.Height);
                        g.DrawString(yText, font, Brushes.Black, rf);
                        j++;
                    }
                }

                if (displayChannel)
                {
                    float x1, x2;
                    float lastDrawX = (float)minX;
                    foreach (ChannelSetting channelSetting in channels)
                    {
                        if ((double)channelSetting.EndFreq < minX)
                            continue;

                        else if ((double)channelSetting.StartFreq < minX
                            && (double)channelSetting.EndFreq > minX)
                        {
                            using (Pen channelPen = new Pen(Color.Red, 1.0f))
                            {
                                x1 = 52;
                                x2 = (float)(((double)channelSetting.EndFreq - minX) * 350 / span + 52);
                                if (x2 <= 402)
                                {
                                    g.DrawLine(channelPen, x2, 15, x2, 145);
                                    lastDrawX = x2;
                                }
                            }

                            using (Font font = new Font("Times New Roman", 6.0f))
                            {
                                SizeF sizef;
                                RectangleF rf;
                                sizef = g.MeasureString(channelSetting.ChannelName, font, Int32.MaxValue);
                                rf = new RectangleF((x1 + x2 - sizef.Width) / 2, 10 - sizef.Height / 2,
                                    sizef.Width, sizef.Height);
                                g.DrawString(channelSetting.ChannelName, font, Brushes.Red, rf);
                            }
                        }
                        else if ((double)channelSetting.StartFreq >= minX && (double)channelSetting.EndFreq <= minX + span)
                        {
                            using (Pen channelPen = new Pen(Color.Red, 1.0f))
                            {
                                x1 = (float)(((double)channelSetting.StartFreq - minX) * 350 / span + 52);
                                if (!Utility.FloatEquals(x1, lastDrawX))
                                {
                                    g.DrawLine(channelPen, x1, 15, x1, 145);
                                    lastDrawX = x1;
                                }

                                x2 = (float)(((double)channelSetting.EndFreq - minX) * 350 / span + 52);
                                if (x2 <= 402)
                                {
                                    if (!Utility.FloatEquals(x2, lastDrawX))
                                    {
                                        g.DrawLine(channelPen, x2, 15, x2, 145);
                                        lastDrawX = x2;
                                    }
                                }
                            }

                            using (Font font = new Font("Times New Roman", 6.0f))
                            {
                                SizeF sizef;
                                RectangleF rf;
                                sizef = g.MeasureString(channelSetting.ChannelName, font, Int32.MaxValue);
                                rf = new RectangleF((x1 + x2 - sizef.Width) / 2, 10 - sizef.Height / 2,
                                    sizef.Width, sizef.Height);
                                g.DrawString(channelSetting.ChannelName, font, Brushes.Red, rf);
                            }
                        }
                        else if ((double)channelSetting.StartFreq <= minX + span
                            && (double)channelSetting.EndFreq > minX + span)
                        {
                            using (Pen channelPen = new Pen(Color.Red, 1.0f))
                            {
                                x1 = (float)(((double)channelSetting.StartFreq - minX) * 350 / span + 52);
                                if (!Utility.FloatEquals(x1, lastDrawX))
                                {
                                    g.DrawLine(channelPen, x1, 15, x1, 145);
                                    lastDrawX = x1;
                                }

                                x2 = 402;
                            }

                            using (Font font = new Font("Times New Roman", 6.0f))
                            {
                                SizeF sizef;
                                RectangleF rf;
                                sizef = g.MeasureString(channelSetting.ChannelName, font, Int32.MaxValue);
                                rf = new RectangleF((x1 + x2 - sizef.Width) / 2, 10 - sizef.Height / 2,
                                    sizef.Width, sizef.Height);
                                g.DrawString(channelSetting.ChannelName, font, Brushes.Red, rf);
                            }
                        }
                    }

                    foreach (ChannelSetting channelSetting in channels)
                    {
                        if ((double)channelSetting.Pair.EndFreq < minX)
                            continue;
                        else if ((double)channelSetting.Pair.StartFreq < minX
                            && (double)channelSetting.Pair.EndFreq > minX)
                        {
                            using (Pen channelPen = new Pen(Color.Purple, 1.0f))
                            {
                                x1 = 52;
                                x2 = (float)(((double)channelSetting.Pair.EndFreq - minX) * 350 / span + 52);
                                if (x2 <= 402)
                                {
                                    g.DrawLine(channelPen, x2, 15, x2, 145);
                                    lastDrawX = x2;
                                }
                            }

                            using (Font font = new Font("Times New Roman", 6.0f))
                            {
                                SizeF sizef;
                                RectangleF rf;
                                sizef = g.MeasureString(channelSetting.Pair.ChannelName, font, Int32.MaxValue);
                                rf = new RectangleF((x1 + x2 - sizef.Width) / 2, 10 - sizef.Height / 2,
                                    sizef.Width, sizef.Height);
                                g.DrawString(channelSetting.Pair.ChannelName, font, Brushes.Purple, rf);
                            }
                        }
                        else if ((double)channelSetting.Pair.StartFreq >= minX && (double)channelSetting.Pair.EndFreq <= minX + span)
                        {
                            using (Pen channelPen = new Pen(Color.Purple, 1.0f))
                            {
                                x1 = (float)(((double)channelSetting.Pair.StartFreq - minX) * 350 / span + 52);
                                if (!Utility.FloatEquals(x1, lastDrawX))
                                {
                                    g.DrawLine(channelPen, x1, 15, x1, 145);
                                    lastDrawX = x1;
                                }

                                x2 = (float)(((double)channelSetting.Pair.EndFreq - minX) * 350 / span + 52);
                                if (x2 <= 402)
                                {
                                    if (!Utility.FloatEquals(x2, lastDrawX))
                                    {
                                        g.DrawLine(channelPen, x2, 15, x2, 145);
                                        lastDrawX = x2;
                                    }
                                }
                            }

                            using (Font font = new Font("Times New Roman", 6.0f))
                            {
                                SizeF sizef;
                                RectangleF rf;
                                sizef = g.MeasureString(channelSetting.Pair.ChannelName, font, Int32.MaxValue);
                                rf = new RectangleF((x1 + x2 - sizef.Width) / 2, 10 - sizef.Height / 2,
                                    sizef.Width, sizef.Height);
                                g.DrawString(channelSetting.Pair.ChannelName, font, Brushes.Purple, rf);
                            }
                        }
                        else if ((double)channelSetting.Pair.StartFreq <= minX + span && (double)channelSetting.Pair.EndFreq > minX + span)
                        {
                            using (Pen channelPen = new Pen(Color.Purple, 1.0f))
                            {
                                x1 = (float)(((double)channelSetting.Pair.StartFreq - minX) * 350 / span + 52);
                                if (!Utility.FloatEquals(x1, lastDrawX))
                                {
                                    g.DrawLine(channelPen, x1, 15, x1, 145);
                                    lastDrawX = x1;
                                }

                                x2 = 402;
                            }

                            using (Font font = new Font("Times New Roman", 6.0f))
                            {
                                SizeF sizef;
                                RectangleF rf;
                                sizef = g.MeasureString(channelSetting.Pair.ChannelName, font, Int32.MaxValue);
                                rf = new RectangleF((x1 + x2 - sizef.Width) / 2, 10 - sizef.Height / 2,
                                    sizef.Width, sizef.Height);
                                g.DrawString(channelSetting.Pair.ChannelName, font, Brushes.Purple, rf);
                            }
                        }
                    }
                }

                using (Pen dataPen = new Pen(Color.Blue, 1.0f))
                {
                    float x1, x2, y1, y2;
                    for (int j = 0; j < samples.Count - 1; j++)
                    {
                        if (samples[j].mFreq > maxShowFreq)
                            break;

                        x1 = (float)((samples[j].mFreq - minX) * 350 / span + 52);
                        y1 = (float)((Math.Abs(samples[j].mRssi) - minRssi) * 130 / (maxRssi - minRssi) + 15);

                        x2 = (float)((samples[j + 1].mFreq - minX) * 350 / span + 52);
                        y2 = (float)((Math.Abs(samples[j + 1].mRssi) - minRssi) * 130 / (maxRssi - minRssi) + 15);

                        g.DrawLine(dataPen, x1, y1, x2, y2);
                    }
                }

                //bmp.Save(channelPictureFile, ImageFormat.Png);
                g.Save();
                g.Dispose();
                //mf.Dispose();
            }
            catch (System.Exception e)
            {
                File.Delete("c:\\watsLog.txt");
                FileStream fs = new FileStream("c:\\watsLog.txt", FileMode.CreateNew);
                StreamWriter sw = new StreamWriter(fs);
                sw.WriteLine(e.Message);
                sw.WriteLine(e.StackTrace);
                sw.Flush();
                sw.Close();
                fs.Close();

                return false;
            }

            return true;
        }
Example #2
0
        private void GenerateGraphs()
        {
            int minAbsRssi = Int32.MaxValue, maxAbsRssi = Int32.MinValue;
            Dictionary<int, List<WatsEmiSample>> samples;
            foreach (KeyValuePair<double, Dictionary<int, List<WatsEmiSample>>> pair in mDataManagerA.AllSamples)
            {
                samples = pair.Value;
                foreach (WatsEmiSample sample in samples[0])
                {
                    if (Math.Abs(sample.mRssi) < minAbsRssi)
                        minAbsRssi = (int)Math.Abs(sample.mRssi);
                    if (Math.Abs(sample.mRssi) > maxAbsRssi)
                        maxAbsRssi = (int)Math.Abs(sample.mRssi);
                }

                foreach (WatsEmiSample sample in samples[1])
                {
                    if (Math.Abs(sample.mRssi) < minAbsRssi)
                        minAbsRssi = (int)Math.Abs(sample.mRssi);
                    if (Math.Abs(sample.mRssi) > maxAbsRssi)
                        maxAbsRssi = (int)Math.Abs(sample.mRssi);
                }
            }

            foreach (KeyValuePair<double, Dictionary<int, List<WatsEmiSample>>> pair in mDataManagerB.AllSamples)
            {
                samples = pair.Value;
                foreach (WatsEmiSample sample in samples[0])
                {
                    if (Math.Abs(sample.mRssi) < minAbsRssi)
                        minAbsRssi = (int)Math.Abs(sample.mRssi);
                    if (Math.Abs(sample.mRssi) > maxAbsRssi)
                        maxAbsRssi = (int)Math.Abs(sample.mRssi);
                }

                foreach (WatsEmiSample sample in samples[1])
                {
                    if (Math.Abs(sample.mRssi) < minAbsRssi)
                        minAbsRssi = (int)Math.Abs(sample.mRssi);
                    if (Math.Abs(sample.mRssi) > maxAbsRssi)
                        maxAbsRssi = (int)Math.Abs(sample.mRssi);
                }
            }

            minAbsRssi -= 10;
            minAbsRssi = minAbsRssi - minAbsRssi % 10;
            maxAbsRssi += 10;
            maxAbsRssi = maxAbsRssi - maxAbsRssi % 10;

            double span = double.Parse(GraphSpanEditor.Text.Trim());
            //Dictionary<ChannelSetting, WatsEmiData> channelDatasA = mDataManagerA.AllChannelSamples[mAzimuthA];
            //Dictionary<ChannelSetting, WatsEmiData> channelDatasB = mDataManagerB.AllChannelSamples[mAzimuthB];

            double channelStartFreq = mChannelSettings[0].StartFreq;
            double channelEndFreq = mChannelSettings[mChannelSettings.Count - 1].EndFreq;
            if (span > channelEndFreq - channelStartFreq)
                span = channelEndFreq - channelStartFreq;
            List<FrequencyRange> ranges = new List<FrequencyRange>();
            FrequencyRange range;
            double startFreq = channelStartFreq;
            do
            {
                range = new FrequencyRange();
                range.FromFreq = startFreq;
                range.EndFreq = startFreq + span;
            //                 if (range.EndFreq >= channelEndFreq)
            //                     range.EndFreq = channelEndFreq;

                ranges.Add(range);
                if (range.EndFreq >= channelEndFreq)
                    break;
                startFreq = startFreq + span;

            } while (true);

            mBmpInfosA = ReportPictureCreator.create(mAzimuthA, mDataManagerA.AllSamples[mAzimuthA],
                mChannelSettings, false, minAbsRssi, maxAbsRssi, ranges, channelEndFreq);
            mBmpInfosB = ReportPictureCreator.create(mAzimuthB, mDataManagerB.AllSamples[mAzimuthB],
                mChannelSettings, false, minAbsRssi, maxAbsRssi, ranges, channelEndFreq);

            FrequencyBandComboxA.Items.Clear();
            FrequencyBandComboxB.Items.Clear();
            foreach (BitMapInfo bitMapInfo in mBmpInfosA)
                FrequencyBandComboxA.Items.Add(bitMapInfo.Band);
            foreach (BitMapInfo bitMapInfo in mBmpInfosB)
                FrequencyBandComboxB.Items.Add(bitMapInfo.Band);
            if (FrequencyBandComboxA.Items.Count > 0)
                FrequencyBandComboxA.SelectedIndex = 0;
            if (FrequencyBandComboxB.Items.Count > 0)
                FrequencyBandComboxB.SelectedIndex = 0;
        }
Example #3
0
        private void GenerateGraphs()
        {
            int minAbsRssi = Int32.MaxValue, maxAbsRssi = Int32.MinValue;
            Dictionary<int, List<WatsEmiSample>> samples;
            foreach (KeyValuePair<double, Dictionary<int, List<WatsEmiSample>>> pair in mDataManager.AllSamples)
            {
                samples = pair.Value;
                foreach (WatsEmiSample sample in samples[0])
                {
                    if (Math.Abs(sample.mRssi) < minAbsRssi)
                        minAbsRssi = (int)Math.Abs(sample.mRssi);
                    if (Math.Abs(sample.mRssi) > maxAbsRssi)
                        maxAbsRssi = (int)Math.Abs(sample.mRssi);
                }

                foreach (WatsEmiSample sample in samples[1])
                {
                    if (Math.Abs(sample.mRssi) < minAbsRssi)
                        minAbsRssi = (int)Math.Abs(sample.mRssi);
                    if (Math.Abs(sample.mRssi) > maxAbsRssi)
                        maxAbsRssi = (int)Math.Abs(sample.mRssi);
                }
            }
            minAbsRssi -= 10;
            minAbsRssi = minAbsRssi - minAbsRssi % 10;
            maxAbsRssi += 10;
            maxAbsRssi = maxAbsRssi - maxAbsRssi % 10;

            double span = double.Parse(SpanEditor.Text.Trim());
            List<BitMapInfo> bmpInfos;
            double angle;
            List<WatsEmiReportTool.FrequencyRange> ranges;
            WatsEmiReportTool.FrequencyRange range;
            if (ChannelPreferredRadioButton.Checked)
            {
                mBitmaps.Clear();
                foreach (KeyValuePair<double, Dictionary<ChannelSetting, WatsEmiData>> pair in mDataManager.AllChannelSamples)
                {
                    angle = pair.Key;
                    double channelStartFreq = pair.Value.Keys.First<ChannelSetting>().StartFreq;
                    double channelEndFreq = pair.Value.Keys.Last<ChannelSetting>().Pair.EndFreq;
                    if (span > channelEndFreq - channelStartFreq)
                        span = channelEndFreq - channelStartFreq;

                    ranges = new List<WatsEmiReportTool.FrequencyRange>();
                    double startFreq = channelStartFreq;
                    do
                    {
                        range = new WatsEmiReportTool.FrequencyRange();
                        range.FromFreq = startFreq;
                        range.EndFreq = startFreq + span;

                        //if (range.EndFreq >= channelEndFreq)
                        //  range.EndFreq = channelEndFreq;

                        ranges.Add(range);

                        if (range.EndFreq >= channelEndFreq)
                            break;
                        startFreq = startFreq + span;
                    } while (true);

                    bmpInfos = WatsEmiReportTool.ReportPictureCreator.create(angle, mDataManager.AllSamples[angle],
                        mChannelSettings, true, minAbsRssi, maxAbsRssi, ranges, channelEndFreq);
                    mBitmaps[angle] = bmpInfos;
                }
            }
            else
            {
                mBitmaps.Clear();
                double startFreq = double.Parse(StartFreqEditor.Text.Trim());
                double endFreq = double.Parse(EndFreqEditor.Text.Trim());
                if (span > endFreq - startFreq)
                    span = endFreq - startFreq;
                bool displayChannel = DisplayChannelCheckBox.Checked;

                foreach (KeyValuePair<double, Dictionary<int, List<WatsEmiSample>>> pair in mDataManager.AllSamples)
                {
                    angle = pair.Key;
                    ranges = new List<FrequencyRange>();
                    do
                    {
                        range = new FrequencyRange();
                        range.FromFreq = startFreq;
                        range.EndFreq = startFreq + span;
                        //                         if (range.EndFreq >= endFreq)
                        //                             range.EndFreq = endFreq;

                        ranges.Add(range);

                        if (range.EndFreq >= endFreq)
                            break;
                        startFreq = startFreq + span;
                    } while (true);

                    bmpInfos = ReportPictureCreator.create(angle, mDataManager.AllSamples[angle],
                            mChannelSettings, displayChannel, minAbsRssi, maxAbsRssi, ranges, endFreq);
                    mBitmaps[angle] = bmpInfos;
                }
            }

            AngleCombox.Items.Clear();
            BandList.Items.Clear();
            foreach (KeyValuePair<double, List<BitMapInfo>> pair in mBitmaps)
            {
                AngleCombox.Items.Add(pair.Key.ToString());
                foreach (BitMapInfo info in pair.Value)
                {
                    BandList.Items.Add(info.Band);
                }
            }

            if (AngleCombox.Items.Count > 0)
                AngleCombox.SelectedIndex = 0;

            if (BandList.Items.Count > 0)
                BandList.SelectedIndex = 0;
        }
Example #4
0
        private void GenerateGraphs()
        {
            int minAbsRssi = Int32.MaxValue, maxAbsRssi = Int32.MinValue;
            Dictionary<int, List<WatsEmiSample>> samples;
            foreach (KeyValuePair<double, Dictionary<int, List<WatsEmiSample>>> pair in mEmiDataMgrA.AllSamples)
            {
                samples = pair.Value;
                foreach (WatsEmiSample sample in samples[0])
                {
                    if (Math.Abs(sample.mRssi) < minAbsRssi)
                        minAbsRssi = (int)Math.Abs(sample.mRssi);
                    if (Math.Abs(sample.mRssi) > maxAbsRssi)
                        maxAbsRssi = (int)Math.Abs(sample.mRssi);
                }

                foreach (WatsEmiSample sample in samples[1])
                {
                    if (Math.Abs(sample.mRssi) < minAbsRssi)
                        minAbsRssi = (int)Math.Abs(sample.mRssi);
                    if (Math.Abs(sample.mRssi) > maxAbsRssi)
                        maxAbsRssi = (int)Math.Abs(sample.mRssi);
                }
            }

            foreach (KeyValuePair<double, Dictionary<int, List<WatsEmiSample>>> pair in mEmiDataMgrB.AllSamples)
            {
                samples = pair.Value;
                foreach (WatsEmiSample sample in samples[0])
                {
                    if (Math.Abs(sample.mRssi) < minAbsRssi)
                        minAbsRssi = (int)Math.Abs(sample.mRssi);
                    if (Math.Abs(sample.mRssi) > maxAbsRssi)
                        maxAbsRssi = (int)Math.Abs(sample.mRssi);
                }

                foreach (WatsEmiSample sample in samples[1])
                {
                    if (Math.Abs(sample.mRssi) < minAbsRssi)
                        minAbsRssi = (int)Math.Abs(sample.mRssi);
                    if (Math.Abs(sample.mRssi) > maxAbsRssi)
                        maxAbsRssi = (int)Math.Abs(sample.mRssi);
                }
            }

            minAbsRssi -= 10;
            minAbsRssi = minAbsRssi - minAbsRssi % 10;
            maxAbsRssi += 10;
            maxAbsRssi = maxAbsRssi - maxAbsRssi % 10;

            int graphCount = GraphCountComboBox.SelectedIndex + 1;
            double span = (mChannelSettings[mChannelSettings.Count - 1].Pair.EndFreq - mChannelSettings[0].StartFreq) / graphCount * 1.0f;
            double channelStartFreq = mChannelSettings[0].StartFreq;
            double channelEndFreq = mChannelSettings[mChannelSettings.Count - 1].Pair.EndFreq;
            List<FrequencyRange> ranges = new List<FrequencyRange>();
            FrequencyRange range;
            double startFreq = channelStartFreq;
            do
            {
                range = new FrequencyRange();
                range.FromFreq = startFreq;
                range.EndFreq = startFreq + span;
                if (Math.Ceiling(range.EndFreq) >= channelEndFreq)
                {
                    range.EndFreq = channelEndFreq;
                    ranges.Add(range);
                    break;
                }
                ranges.Add(range);
                startFreq = startFreq + span;

            } while (true);

            mBmpInfosA = VenezuelaReportPictureCreator.create(mEmiA, mAzimuthA,
                mEmiA.Site_ID + " to " + mEmiB.Site_ID + " - " + mAzimuthA + "\x00B0",
                mEmiDataMgrA, mChannelSettings, mLimitSetting, minAbsRssi, maxAbsRssi, span, ranges,
                ref mVerticalCircleTitleA, ref mHorizontalCircleTitleA,
                ref mVerticalCircleBmpFileA, ref mHorizontalCircleBmpFileA);
            mBmpInfosB = VenezuelaReportPictureCreator.create(mEmiB, mAzimuthB,
                mEmiB.Site_ID + " to " + mEmiA.Site_ID + " - " + mAzimuthB + "\x00B0",
                mEmiDataMgrB, mChannelSettings, mLimitSetting, minAbsRssi, maxAbsRssi, span, ranges,
                ref mVerticalCircleTitleB, ref mHorizontalCircleTitleB,
                ref mVerticalCircleBmpFileB, ref mHorizontalCircleBmpFileB);

            FrequencyBandComboxA.Items.Clear();
            FrequencyBandComboxB.Items.Clear();
            foreach (BitMapInfo bitMapInfo in mBmpInfosA)
                FrequencyBandComboxA.Items.Add(bitMapInfo.Band);
            foreach (BitMapInfo bitMapInfo in mBmpInfosB)
                FrequencyBandComboxB.Items.Add(bitMapInfo.Band);
            if (FrequencyBandComboxA.Items.Count > 0)
                FrequencyBandComboxA.SelectedIndex = 0;
            if (FrequencyBandComboxB.Items.Count > 0)
                FrequencyBandComboxB.SelectedIndex = 0;
        }
        private static bool drawPicture(EMIFileData emi, List<WatsEmiSample> samples,
            double span, FrequencyRange range, LimitSetting limitSetting,
            string picturePath, string title, int minAbsRssi, int maxAbsRssi,
            List<Marker> markers, int markerRows)
        {
            try
            {
                int height = 180 + (markerRows + 1) * 15 + 4 * 15;
                Bitmap bmp = new Bitmap(425, height);
                Graphics gs = Graphics.FromImage(bmp);
                Metafile mf = new Metafile(picturePath, gs.GetHdc());
                Graphics g = Graphics.FromImage(mf);

                double minX = range.FromFreq;
                using (Brush bgBrush = new SolidBrush(Color.FromArgb(255, 255, 128)))
                {
                    g.FillRectangle(bgBrush, 0, 0, 425, height);
                }

                using (Pen boldRectPen = new Pen(Color.Black, 2.0f))
                {
                    g.DrawRectangle(boldRectPen, 0, 0, 425, height);
                }

                using (Pen boldRectPen = new Pen(Color.Black, 1.0f))
                {
                    g.DrawRectangle(boldRectPen, 52, 15, 350, 130);
                }

                using (Pen gridPen = new Pen(Color.Gray, 0.5f))
                {
                    gridPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                    for (int j = 0; j < 9; j++)
                        g.DrawLine(gridPen, 52, 15 + (j + 1) * 13, 402, 15 + (j + 1) * 13);

                    for (int j = 0; j < 9; j++)
                        g.DrawLine(gridPen, 52 + (j + 1) * 35, 15, 52 + (j + 1) * 35, 145);
                }

                string text;
                SizeF sizef;
                RectangleF rf;

                //drawing title
                using (Font font = new Font("Times New Roman", 8.0f))
                {
                    text = title;
                    sizef = g.MeasureString(text, font, Int32.MaxValue);
                    rf = new RectangleF(227 - sizef.Width / 2, 10 - sizef.Height / 2, sizef.Width, sizef.Height);

                    g.DrawString(text, font, Brushes.Black, rf);
                }

                //drawing side text
                using (Font font = new Font("Times New Roman", 8.0f))
                {
                    text = "Power (dBm)";
                    StringFormat sf = new StringFormat(StringFormatFlags.DirectionVertical);
                    sizef = g.MeasureString(text, font, Int32.MaxValue, sf);
                    rf = new RectangleF(5, 75 - sizef.Height / 2, sizef.Width, sizef.Height);

                    g.TranslateTransform((rf.Left + rf.Right) / 2, (rf.Top + rf.Bottom) / 2);
                    g.RotateTransform(180);

                    RectangleF newRf = new RectangleF(-sizef.Width / 2, -sizef.Height / 2, sizef.Width, sizef.Height);
                    g.DrawString(text, font, Brushes.Black, newRf, sf);
                    g.ResetTransform();
                }

                //drawing bottom
                using (Font font = new Font("Times New Roman", 8.0f))
                {
                    text = "Frequency (MHz)";
                    sizef = g.MeasureString(text, font, Int32.MaxValue);
                    rf = new RectangleF(227 - sizef.Width / 2, 160, sizef.Width, sizef.Height);

                    g.DrawString(text, font, Brushes.Black, rf);
                }

                //drawing x
                using (Font font = new Font("Times New Roman", 5.0f))
                {
                    List<string> xTexts = new List<string>();
                    int j;
                    for (j = 0; j < 11; j++)
                        xTexts.Add(Utility.ConvertDoubleString(minX + span * j / 10));

                    j = 0;
                    foreach (string xText in xTexts)
                    {
                        sizef = g.MeasureString(xText, font, Int32.MaxValue);
                        rf = new RectangleF(52 + j * 35 - sizef.Width / 2, 147,
                            sizef.Width, sizef.Height);
                        g.DrawString(xText, font, Brushes.Black, rf);
                        j++;
                    }
                }

                //drawing y
                using (Font font = new Font("Times New Roman", 5.0f))
                {
                    List<string> yTexts = new List<string>();
                    int j;
                    for (j = 0; j < 11; j++)
                        yTexts.Add("-" + (minAbsRssi + (maxAbsRssi - minAbsRssi) / 10 * j).ToString());

                    j = 0;
                    foreach (string yText in yTexts)
                    {
                        sizef = g.MeasureString(yText, font, Int32.MaxValue);
                        rf = new RectangleF(50 - sizef.Width, 15 + j * 13 - sizef.Height / 2,
                            sizef.Width, sizef.Height);
                        g.DrawString(yText, font, Brushes.Black, rf);
                        j++;
                    }
                }

                //drawing curve
                using (Pen dataPen = new Pen(Color.Blue, 1.0f))
                {
                    float x1, x2, y1, y2;
                    for (int j = 0; j < samples.Count - 1; j++)
                    {
                        x1 = (float)((samples[j].mFreq - minX) * 350 / span + 52);
                        y1 = (float)((Math.Abs(samples[j].mRssi) - minAbsRssi) * 130 / (maxAbsRssi - minAbsRssi) + 15);

                        x2 = (float)((samples[j + 1].mFreq - minX) * 350 / span + 52);
                        y2 = (float)((Math.Abs(samples[j + 1].mRssi) - minAbsRssi) * 130 / (maxAbsRssi - minAbsRssi) + 15);

                        g.DrawLine(dataPen, x1, y1, x2, y2);
                    }
                }

                //drawing bold separate line
                using (Pen boldSeparateLinePen = new Pen(Color.Black, 2.0f))
                {
                    g.DrawLine(boldSeparateLinePen, 0, 180, 425, 180);
                    g.DrawLine(boldSeparateLinePen, 0, 180 + (markerRows + 1) * 15, 425, 180 + (markerRows + 1) * 15);
                }

                using (Pen thinPen = new Pen(Color.Black, 1.0f))
                {
                    using (Font font = new Font("Times New Roman", 7.0f))
                    {
                        //thin horizontal marking separate line
                        for (int j = 0; j < markerRows; j++)
                            g.DrawLine(thinPen, 0, 180 + (j + 1) * 15, 425, 180 + (j + 1) * 15);

                        //thin vertical marking separate line
                        g.DrawLine(thinPen, 65, 180, 65, 180 + (markerRows + 1) * 15);
                        g.DrawLine(thinPen, 65 + 120, 180, 65 + 120, 180 + (markerRows + 1) * 15);
                        g.DrawLine(thinPen, 65 + 240, 180, 65 + 240, 180 + (markerRows + 1) * 15);

                        //marker titles
                        text = "Marker No.";
                        sizef = g.MeasureString(text, font, Int32.MaxValue);
                        rf = new RectangleF(5, 180 + 3.5f,
                            sizef.Width, sizef.Height);
                        g.DrawString(text, font, Brushes.Black, rf);

                        text = "Frequency (MHz)";
                        sizef = g.MeasureString(text, font, Int32.MaxValue);
                        rf = new RectangleF(65 + 5, 180 + 3.5f,
                            sizef.Width, sizef.Height);
                        g.DrawString(text, font, Brushes.Black, rf);

                        text = "RSSI (dBm)";
                        sizef = g.MeasureString(text, font, Int32.MaxValue);
                        rf = new RectangleF(185 + 5, 180 + 3.5f,
                            sizef.Width, sizef.Height);
                        g.DrawString(text, font, Brushes.Black, rf);

                        text = "Channel";
                        sizef = g.MeasureString(text, font, Int32.MaxValue);
                        rf = new RectangleF(305 + 5, 180 + 3.5f,
                            sizef.Width, sizef.Height);
                        g.DrawString(text, font, Brushes.Black, rf);

                        //marker no.
                        for (int j = 0; j < markers.Count; j++)
                        {
                            text = (j + 1).ToString();
                            sizef = g.MeasureString(text, font, Int32.MaxValue);
                            rf = new RectangleF(5, 180 + (j + 1) * 15 + 3.5f,
                                sizef.Width, sizef.Height);
                            g.DrawString(text, font, Brushes.Black, rf);
                        }

                        //drawing mark
                        int i = 0;
                        foreach (Marker marker in markers)
                        {
                            text = Utility.ConvertDoubleString(marker.frequency);
                            sizef = g.MeasureString(text, font, Int32.MaxValue);
                            rf = new RectangleF(65 + 5, 180 + (i + 1) * 15 + 3.5f,
                                sizef.Width, sizef.Height);
                            g.DrawString(text, font, Brushes.Black, rf);

                            text = Utility.ConvertDoubleString(marker.rssi);
                            sizef = g.MeasureString(text, font, Int32.MaxValue);
                            rf = new RectangleF(185 + 5, 180 + (i + 1) * 15 + 3.5f,
                                sizef.Width, sizef.Height);
                            g.DrawString(text, font, Brushes.Black, rf);

                            text = marker.channelName;
                            sizef = g.MeasureString(text, font, Int32.MaxValue);
                            rf = new RectangleF(305 + 5, 180 + (i + 1) * 15 + 3.5f,
                                sizef.Width, sizef.Height);
                            g.DrawString(text, font, Brushes.Black, rf);

                            drawMarker(g, minX, span, minAbsRssi, maxAbsRssi, marker);

                            i++;
                        }

                        //thin horizontal measurement separate line
                        for (int j = 0; j < 3; j++)
                            g.DrawLine(thinPen, 0, 180 + (markerRows + 1) * 15 + (j + 1) * 15, 425, 180 + (markerRows + 1) * 15 + (j + 1) * 15);

                        //thin vertical measurement separate line
                        g.DrawLine(thinPen, 90, 180 + (markerRows + 1) * 15 + 15,
                            90, 180 + (markerRows + 1) * 15 + 60);
                        g.DrawLine(thinPen, 90 + 112, 180 + (markerRows + 1) * 15 + 15,
                            90 + 112, 180 + (markerRows + 1) * 15 + 60);
                        g.DrawLine(thinPen, 90 + 112 + 90, 180 + (markerRows + 1) * 15 + 15,
                            90 + 112 + 90, 180 + (markerRows + 1) * 15 + 60);

                        //drawing measurement
                        text = "Measurement Parameter";
                        sizef = g.MeasureString(text, font, Int32.MaxValue);
                        rf = new RectangleF(209 - sizef.Width / 2, 180 + (markerRows + 1) * 15.0f + 3.5f,
                            sizef.Width, sizef.Height);
                        g.DrawString(text, font, Brushes.Black, rf);

                        /************************************************************************/
                        /* Reference Level                                                      */
                        /************************************************************************/
                        text = "Reference Level";
                        sizef = g.MeasureString(text, font, Int32.MaxValue);
                        rf = new RectangleF(5, 180 + (markerRows + 1) * 15 + 15 + 3.5f,
                            sizef.Width, sizef.Height);
                        g.DrawString(text, font, Brushes.Black, rf);

                        text = Utility.ConvertDoubleString(emi.SA_REF_LEVEL) + " dBm";
                        sizef = g.MeasureString(text, font, Int32.MaxValue);
                        rf = new RectangleF(90 + 5, 180 + (markerRows + 1) * 15 + 15 + 3.5f,
                            sizef.Width, sizef.Height);
                        g.DrawString(text, font, Brushes.Black, rf);

                        /************************************************************************/
                        /* Attenuation                                                          */
                        /************************************************************************/
                        text = "Attenuation";
                        sizef = g.MeasureString(text, font, Int32.MaxValue);
                        rf = new RectangleF(202 + 5, 180 + (markerRows + 1) * 15 + 15 + 3.5f,
                            sizef.Width, sizef.Height);
                        g.DrawString(text, font, Brushes.Black, rf);

                        text = emi.SA_Attenuation_Value.ToString() + " dB";
                        sizef = g.MeasureString(text, font, Int32.MaxValue);
                        rf = new RectangleF(292 + 5, 180 + (markerRows + 1) * 15 + 15 + 3.5f,
                            sizef.Width, sizef.Height);
                        g.DrawString(text, font, Brushes.Black, rf);

                        /************************************************************************/
                        /* RBW                                                                  */
                        /************************************************************************/
                        text = "RBW";
                        sizef = g.MeasureString(text, font, Int32.MaxValue);
                        rf = new RectangleF(5, 180 + (markerRows + 1) * 15 + 30 + 3.5f,
                            sizef.Width, sizef.Height);
                        g.DrawString(text, font, Brushes.Black, rf);

                        text = Utility.ConvertDoubleString(emi.SA_RBW) + " Hz";
                        sizef = g.MeasureString(text, font, Int32.MaxValue);
                        rf = new RectangleF(90 + 5, 180 + (markerRows + 1) * 15 + 30 + 3.5f,
                            sizef.Width, sizef.Height);
                        g.DrawString(text, font, Brushes.Black, rf);

                        /************************************************************************/
                        /* VBW                                                          */
                        /************************************************************************/
                        text = "VBW";
                        sizef = g.MeasureString(text, font, Int32.MaxValue);
                        rf = new RectangleF(202 + 5, 180 + (markerRows + 1) * 15 + 30 + 3.5f,
                            sizef.Width, sizef.Height);
                        g.DrawString(text, font, Brushes.Black, rf);

                        text = Utility.ConvertDoubleString(emi.SA_VBW) + " Hz";
                        sizef = g.MeasureString(text, font, Int32.MaxValue);
                        rf = new RectangleF(292 + 5, 180 + (markerRows + 1) * 15 + 30 + 3.5f,
                            sizef.Width, sizef.Height);
                        g.DrawString(text, font, Brushes.Black, rf);

                        /************************************************************************/
                        /* Detection                                                            */
                        /************************************************************************/
                        text = "Detection";
                        sizef = g.MeasureString(text, font, Int32.MaxValue);
                        rf = new RectangleF(5, 180 + (markers.Count + 1) * 15 + 43 + 3.5f,
                            sizef.Width, sizef.Height);
                        g.DrawString(text, font, Brushes.Black, rf);

                        text = emi.SA_Detector;
                        sizef = g.MeasureString(text, font, Int32.MaxValue);
                        rf = new RectangleF(90 + 5, 180 + (markers.Count + 1) * 15 + 43 + 3.5f,
                            sizef.Width, sizef.Height);
                        g.DrawString(text, font, Brushes.Black, rf);

                        /************************************************************************/
                        /* Mode                                                                 */
                        /************************************************************************/
                        text = "Mode";
                        sizef = g.MeasureString(text, font, Int32.MaxValue);
                        rf = new RectangleF(202 + 5, 180 + (markers.Count + 1) * 15 + 43 + 3.5f,
                            sizef.Width, sizef.Height);
                        g.DrawString(text, font, Brushes.Black, rf);

                        text = emi.SA_Sweep_Mode;
                        sizef = g.MeasureString(text, font, Int32.MaxValue);
                        rf = new RectangleF(292 + 5, 180 + (markers.Count + 1) * 15 + 43 + 3.5f,
                            sizef.Width, sizef.Height);
                        g.DrawString(text, font, Brushes.Black, rf);
                    }
                }

                g.Save();
                g.Dispose();
            }
            catch (System.Exception e)
            {
                File.Delete("c:\\watsLog.txt");
                FileStream fs = new FileStream("c:\\watsLog.txt", FileMode.CreateNew);
                StreamWriter sw = new StreamWriter(fs);
                sw.WriteLine(e.Message);
                sw.WriteLine(e.StackTrace);
                sw.Flush();
                sw.Close();
                fs.Close();

                return false;
            }

            return true;
        }