コード例 #1
0
        PDFPage CreateNewPage(PDFFont font, string serialNumber)
        {
            var headerPen       = new PDFPen(Color.DarkSlateBlue, 120);
            var serialfont      = new PDFFont(FontType.Helvetica, 16, PDF.Drawing.FontStyle.Regular);
            var companyNameFont = new PDFFont(FontType.Helvetica, 30, PDF.Drawing.FontStyle.Bold);

            pageNumber++;

            PDFPage page = pdfDocument.AddPage();

            page.Height = 1000;
            page.Width  = 700;

            page.DrawLine(headerPen, 0, 0, 700, 0);
            page.DrawString(LabelConstant.Title, serialfont, Color.White, 10, 50);
            page.DrawString(LabelConstant.SerialNumber + serialNumber, serialfont, Color.White, 550, 50);
            page.DrawString(LabelConstant.CompanyName, companyNameFont, Color.White, 230, 40);
            page.DrawString(LabelConstant.TradeMark, font, Color.White, 450, 20);
            page.DrawString(LabelConstant.Page + pageNumber, font, Color.Black, 600, 980);
            page.DrawString(LabelConstant.Website, font, Color.Black, PDFcoordinates.siteX, PDFcoordinates.siteY);
            page.DrawString(DateTime.UtcNow.ToString("dd/MM/yyy HH:mm:sss UTC"), font, Color.White, PDFcoordinates.dateX, PDFcoordinates.dateY);
            page.DrawString("0.1.9.1", font, Color.Black, PDFcoordinates.versionX, PDFcoordinates.versionY);

            return(page);
        }
コード例 #2
0
        void DrawGraph(HexFileDecoder decoder, LoggerVariables pdfVariables, PDFPage pdfPage, PDFPen pen, PDFFont font)
        {
            var withinlimitsPen = new PDFPen(Color.LightGray, 0.5, PenStyle.ShortDash);
            var abovelimitPen   = new PDFPen(Color.LightSalmon, 1, PenStyle.ShortDash);
            var belowlimitPen   = new PDFPen(Color.CornflowerBlue, 1, PenStyle.ShortDash);

            var presetUpperLimit  = new double[8];
            var presetLowerLimit  = new double[8];
            var presetUpperLimitY = new double[8];
            var presetLowerLimitY = new double[8];

            var maxRecorded  = new double[8];
            var minRecorded  = new double[8];
            var maxRecordedY = new double[8];
            var minRecordedY = new double[8];

            float dateX       = 0;
            float maximumX    = 55;
            float graphScaleX = 0;
            float graphScaleY = 0;
            float y0          = 0;
            float y1          = 0;

            int numberofDates = pdfVariables.RecordedSamples / 5;
            int dateGap;

            if (numberofDates == 0)
            {
                dateGap = 1;
            }
            else
            {
                dateGap = numberofDates;
            }

            //Assign statistics of the first channel
            presetUpperLimit[0] = pdfVariables.ChannelOne.PresetUpperLimit;
            presetLowerLimit[0] = pdfVariables.ChannelOne.PresetLowerLimit;
            maxRecorded[0]      = pdfVariables.ChannelOne.Max;
            minRecorded[0]      = pdfVariables.ChannelOne.Min;

            var yHighest = pdfVariables.ChannelOne.Max;
            var yLowest  = pdfVariables.ChannelOne.Min;

            //Assign statistics of the second channel
            if (pdfVariables.IsChannelTwoEnabled)
            {
                presetUpperLimit[1] = pdfVariables.ChannelTwo.PresetUpperLimit;
                presetLowerLimit[1] = pdfVariables.ChannelTwo.PresetLowerLimit;
                maxRecorded[1]      = pdfVariables.ChannelTwo.Max;
                minRecorded[1]      = pdfVariables.ChannelTwo.Min;

                if (pdfVariables.ChannelTwo.Max > yHighest)
                {
                    yHighest = pdfVariables.ChannelTwo.Max;
                }
                if (pdfVariables.ChannelTwo.Min < yLowest)
                {
                    yLowest = pdfVariables.ChannelTwo.Min;
                }
            }

            //draw graph
            pdfPage.DrawLine(pen, PDFcoordinates.Xstart, PDFcoordinates.Ystart, PDFcoordinates.Xstart, PDFcoordinates.Yfinish);
            pdfPage.DrawLine(pen, PDFcoordinates.Xstart, PDFcoordinates.Yfinish, PDFcoordinates.Xfinish, PDFcoordinates.Yfinish);
            graphScaleY = (float)((PDFcoordinates.graphHeight - 20) / (yHighest - yLowest));
            graphScaleX = (float)PDFcoordinates.graphWidth / pdfVariables.RecordedSamples;

            //graph dates
            while (numberofDates < pdfVariables.RecordedSamples)
            {
                dateX = (graphScaleX * numberofDates) + maximumX;
                pdfPage.DrawString(decoder.UNIXtoUTCDate(Convert.ToInt32(pdfVariables.Time[numberofDates])), font, Color.Black, dateX - 40, PDFcoordinates.Yfinish + 15);
                pdfPage.DrawString(decoder.UNIXtoUTCTime(Convert.ToInt32(pdfVariables.Time[numberofDates])), font, Color.Black, dateX - 45, PDFcoordinates.Yfinish + 28);
                numberofDates += dateGap;
            }

            //Y axis
            var range      = yHighest - yLowest;
            var yIncrement = 0;

            if (range > 100)
            {
                yIncrement = 10;
            }
            else if (range > 50)
            {
                yIncrement = 5;
            }
            else if (range > 20)
            {
                yIncrement = 2;
            }
            else
            {
                yIncrement = 1;
            }

            int currentYLabel = (int)yLowest + yIncrement;

            while (currentYLabel < yHighest)
            {
                var graphCurrentValue = (float)(PDFcoordinates.graphHeight - ((currentYLabel - yLowest) * graphScaleY)) + PDFcoordinates.Ymax;
                pdfPage.DrawLine(withinlimitsPen, PDFcoordinates.Xstart, graphCurrentValue, PDFcoordinates.Xfinish, graphCurrentValue);
                pdfPage.DrawString(currentYLabel.ToString("N2"), font, Color.Black, PDFcoordinates.firstColumn, graphCurrentValue);
                currentYLabel = currentYLabel + yIncrement;
            }

            //If there is more than one channel available, current function is not optimal as if we were to have more than 2 channels we would be loooping to check .isChannelThreeEnabled? and so on
            if (pdfVariables.IsChannelTwoEnabled && pdfVariables.RecordedSamples > 0)
            {
                y1 = (float)(PDFcoordinates.graphHeight - (pdfVariables.ChannelTwo.Data[0] - yLowest) * graphScaleY) + PDFcoordinates.Ymax;
                presetUpperLimitY[1] = (float)(PDFcoordinates.graphHeight - ((presetUpperLimit[1] - yLowest) * graphScaleY)) + PDFcoordinates.Ymax;
                presetLowerLimitY[1] = (float)(PDFcoordinates.graphHeight - ((presetLowerLimit[1] - yLowest) * graphScaleY)) + PDFcoordinates.Ymax;
                maxRecordedY[1]      = (float)(PDFcoordinates.graphHeight - ((pdfVariables.ChannelTwo.Max - yLowest) * graphScaleY)) + PDFcoordinates.Ymax;
                minRecordedY[1]      = (float)(PDFcoordinates.graphHeight - ((pdfVariables.ChannelTwo.Min - yLowest) * graphScaleY)) + PDFcoordinates.Ymax;

                /*pdfPage.DrawLine(withinlimitsPen, PDFcoordinates.Xstart, maxRecordedY[1], PDFcoordinates.Xfinish, maxRecordedY[1]);
                 * pdfPage.DrawLine(withinlimitsPen, PDFcoordinates.Xstart, minRecordedY[1], PDFcoordinates.Xfinish, minRecordedY[1]);
                 * pdfPage.DrawString(minRecorded[1].ToString("N2"), font, Color.Black, PDFcoordinates.firstColumn, minRecordedY[1]);
                 * pdfPage.DrawString(maxRecorded[1].ToString("N2"), font, Color.Black, PDFcoordinates.firstColumn, maxRecordedY[1]);*/

                if ((presetUpperLimit[1] < maxRecorded[1]) && (presetUpperLimit[1] > minRecorded[1]))
                {
                    pdfPage.DrawString(pdfVariables.ChannelTwo.Unit + LabelConstant.UpperLimit, font, Color.LightCoral, PDFcoordinates.thirdColumn, presetUpperLimitY[1] - 5);
                    pdfPage.DrawString(presetUpperLimit[1].ToString("N2"), font, Color.Black, PDFcoordinates.firstColumn, presetUpperLimitY[1]);
                    pdfPage.DrawLine(abovelimitPen, PDFcoordinates.Xstart, presetUpperLimitY[1], PDFcoordinates.Xfinish, presetUpperLimitY[1]);
                }

                if ((presetLowerLimit[1] > minRecorded[1]) && (presetLowerLimit[1] < maxRecorded[1]))
                {
                    pdfPage.DrawString(pdfVariables.ChannelTwo.Unit + LabelConstant.LowerLimit, font, Color.CornflowerBlue, PDFcoordinates.thirdColumn, presetLowerLimitY[1] + 10);
                    pdfPage.DrawString(presetLowerLimit[1].ToString("N2"), font, Color.Black, PDFcoordinates.firstColumn, presetLowerLimitY[1]);
                    pdfPage.DrawLine(belowlimitPen, PDFcoordinates.Xstart, presetLowerLimitY[1], PDFcoordinates.Xfinish, presetLowerLimitY[1]);
                }
            }

            //Retrieve data from channel one
            if (pdfVariables.ChannelOne.Data != null)
            {
                y0 = (float)(PDFcoordinates.graphHeight - (pdfVariables.ChannelOne.Data[0] - yLowest) * graphScaleY) + PDFcoordinates.Ymax;
                presetUpperLimitY[0] = (float)(PDFcoordinates.graphHeight - ((presetUpperLimit[0] - yLowest) * graphScaleY)) + PDFcoordinates.Ymax;
                presetLowerLimitY[0] = (float)(PDFcoordinates.graphHeight - ((presetLowerLimit[0] - yLowest) * graphScaleY)) + PDFcoordinates.Ymax;
                maxRecordedY[0]      = (float)(PDFcoordinates.graphHeight - ((pdfVariables.ChannelOne.Max - yLowest) * graphScaleY)) + PDFcoordinates.Ymax;
                minRecordedY[0]      = (float)(PDFcoordinates.graphHeight - ((pdfVariables.ChannelOne.Min - yLowest) * graphScaleY)) + PDFcoordinates.Ymax;

                /*pdfPage.DrawLine(withinlimitsPen, PDFcoordinates.Xstart, maxRecordedY[0], PDFcoordinates.Xfinish, maxRecordedY[0]);
                 * pdfPage.DrawLine(withinlimitsPen, PDFcoordinates.Xstart, minRecordedY[0], PDFcoordinates.Xfinish, minRecordedY[0]);
                 * pdfPage.DrawString(minRecorded[0].ToString("N2"), font, Color.Black, PDFcoordinates.firstColumn, minRecordedY[0]);
                 * pdfPage.DrawString(maxRecorded[0].ToString("N2"), font, Color.Black, PDFcoordinates.firstColumn, maxRecordedY[0]);*/

                if ((presetUpperLimit[0] < maxRecorded[0]) && (presetUpperLimit[0] > minRecorded[0]))
                {
                    pdfPage.DrawString(pdfVariables.ChannelOne.Unit + LabelConstant.UpperLimit, font, Color.Coral, PDFcoordinates.thirdColumn, presetUpperLimitY[0] - 5);
                    pdfPage.DrawString(presetUpperLimit[0].ToString("N2"), font, Color.Black, PDFcoordinates.firstColumn, presetUpperLimitY[0]);
                    pdfPage.DrawLine(abovelimitPen, PDFcoordinates.Xstart, presetUpperLimitY[0], PDFcoordinates.Xfinish, presetUpperLimitY[0]);
                }

                if ((presetLowerLimit[0] > minRecorded[0]) && (presetLowerLimit[0] < maxRecorded[0]))
                {
                    pdfPage.DrawString(pdfVariables.ChannelOne.Unit + LabelConstant.LowerLimit, font, Color.CornflowerBlue, PDFcoordinates.thirdColumn, presetLowerLimitY[0] + 10);
                    pdfPage.DrawString(presetLowerLimit[0].ToString("N2"), font, Color.Black, PDFcoordinates.firstColumn, presetLowerLimitY[0]);
                    pdfPage.DrawLine(belowlimitPen, PDFcoordinates.Xstart, presetLowerLimitY[0], PDFcoordinates.Xfinish, presetLowerLimitY[0]);
                }
            }

            int i                 = 0;
            int tagCount          = 0;
            var ch0Pen            = new PDFPen(Color.DarkGreen, 1);
            var ch1Pen            = new PDFPen(Color.MediumPurple, 1);
            var abovelimitDataPen = new PDFPen(Color.LightSalmon, 1);
            var belowlimitDataPen = new PDFPen(Color.CornflowerBlue, 1);

            while (i < pdfVariables.RecordedSamples)
            {
                if (tagCount < pdfVariables.Tag.Count && pdfVariables.Tag[tagCount] == i)
                {
                    var tagPen = new PDFPen(Color.ForestGreen, 1);
                    pdfPage.DrawLine(tagPen, maximumX - 2, y0 - 2, maximumX + 2, y0 + 2);
                    pdfPage.DrawLine(tagPen, maximumX - 2, y0 + 2, maximumX + 2, y0 - 2);

                    tagCount++;
                }

                if (pdfVariables.ChannelOne.Data != null)
                {
                    if (pdfVariables.ChannelOne.Data[i] > pdfVariables.ChannelOne.PresetUpperLimit)
                    {
                        pdfPage.DrawLine(abovelimitDataPen, maximumX, y0, maximumX + graphScaleX, (float)(PDFcoordinates.graphHeight - ((pdfVariables.ChannelOne.Data[i] - (yLowest)) * graphScaleY)) + PDFcoordinates.Ymax);
                    }
                    else if (pdfVariables.ChannelOne.Data[i] < pdfVariables.ChannelOne.PresetLowerLimit)
                    {
                        pdfPage.DrawLine(belowlimitDataPen, maximumX, y0, maximumX + graphScaleX, (float)(PDFcoordinates.graphHeight - ((pdfVariables.ChannelOne.Data[i] - (yLowest)) * graphScaleY)) + PDFcoordinates.Ymax);
                    }
                    else
                    {
                        pdfPage.DrawLine(ch0Pen, maximumX, y0, maximumX + graphScaleX, (float)(PDFcoordinates.graphHeight - ((pdfVariables.ChannelOne.Data[i] - (yLowest)) * graphScaleY)) + PDFcoordinates.Ymax);
                    }

                    y0 = (float)(PDFcoordinates.graphHeight - ((pdfVariables.ChannelOne.Data[i] - (yLowest)) * graphScaleY)) + PDFcoordinates.Ymax;
                }

                if (pdfVariables.IsChannelTwoEnabled)
                {
                    if (pdfVariables.ChannelTwo.Data[i] > pdfVariables.ChannelTwo.PresetUpperLimit)
                    {
                        pdfPage.DrawLine(abovelimitDataPen, maximumX, y1, maximumX + graphScaleX, (float)(PDFcoordinates.graphHeight - ((pdfVariables.ChannelTwo.Data[i] - (yLowest)) * graphScaleY)) + PDFcoordinates.Ymax);
                    }
                    else if (pdfVariables.ChannelTwo.Data[i] < pdfVariables.ChannelTwo.PresetLowerLimit)
                    {
                        pdfPage.DrawLine(belowlimitDataPen, maximumX, y1, maximumX + graphScaleX, (float)(PDFcoordinates.graphHeight - ((pdfVariables.ChannelTwo.Data[i] - (yLowest)) * graphScaleY)) + PDFcoordinates.Ymax);
                    }
                    else
                    {
                        pdfPage.DrawLine(ch1Pen, maximumX, y1, maximumX + graphScaleX, (float)(PDFcoordinates.graphHeight - ((pdfVariables.ChannelTwo.Data[i] - (yLowest)) * graphScaleY)) + PDFcoordinates.Ymax);
                    }

                    y1 = (float)(PDFcoordinates.graphHeight - ((pdfVariables.ChannelTwo.Data[i] - (yLowest)) * graphScaleY)) + PDFcoordinates.Ymax;
                }

                maximumX += graphScaleX;
                i++;
            }
        }