Ejemplo n.º 1
0
        private TableHeader GetTableHeaderLine(TextDocument document, int offset, CurveInfo curveInfo)
        {
            var line = document.GetLineByOffset(offset)?.NextLine;

            while (line != null)
            {
                string tableHeader = document.GetText(line).Trim();
                if (IsEmptyOrCommentLine(tableHeader))
                {
                    line = line.NextLine;
                }
                else
                {
                    var tableRow     = ToRow(tableHeader);
                    int xColumnIndex = tableRow.IndexOf(curveInfo.XColumn);
                    int yColumnIndex = tableRow.IndexOf(curveInfo.YColumn);

                    if ((xColumnIndex >= 0) && (yColumnIndex >= 0))
                    {
                        return(new TableHeader
                        {
                            HeaderLine = line,
                            XColumn = xColumnIndex,
                            YColumn = yColumnIndex
                        });
                    }
                    return(null);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        private CurveViewItem LoadCurveViewItem(TextDocument document, int offset, CurveInfo curveInfo)
        {
            var tableHeader = GetTableHeaderLine(document, offset, curveInfo);

            if (tableHeader == null)
            {
                return(null);
            }

            double        duration;
            List <GPoint> points = ExtractPoints(document, tableHeader, curveInfo.IsGeoCoordinate, out duration);

            if (points.Count < 3)
            {
                return(null);
            }

            string        key           = CurvePlotModel.MakeKey(document.FileName, points, curveInfo);
            CurveViewItem curveViewItem = m_CurveViewItems.FirstOrDefault(x => x.Key == key);

            if (curveViewItem == null)
            {
                var curveModel = new CurvePlotModel(document.FileName, points, ShowPlotMarker, curveInfo, m_CurveManeuverParameter, duration);
                curveViewItem = new CurveViewItem(curveModel);
                m_CurveViewItems.Insert(0, curveViewItem);
            }

            Util.Util.RemoveLastItems(m_CurveViewItems, max_num: CacheSize);

            return(curveViewItem);
        }
Ejemplo n.º 3
0
        public static string MakeKey(string featureFileName, List <GPoint> points, CurveInfo curveInfo)
        {
            double xValue = 0;
            double yValue = 0;

            for (int i = 0; i < points.Count; i++)
            {
                xValue += points[i].X * (i + 1);
                yValue += points[i].Y * (i + 1);
            }

            StringBuilder sb = new StringBuilder();

            sb.Append(featureFileName)
            .Append(curveInfo.IsGeoCoordinate.ToString())
            .Append(curveInfo.Option)
            .Append("_")
            .Append(curveInfo.Description)
            .Append("_")
            .Append(curveInfo.XColumn)
            .Append(curveInfo.YColumn)
            .Append(xValue)
            .Append(yValue);

            return(sb.ToString());
        }
Ejemplo n.º 4
0
        InlineObjectElement CreateUIElement(int length, int offset, CurveInfo curveInfo)
        {
            if (base.IsPrinting)
            {
                BitmapImage bitmap = CurveViewCache.Instance.LoadImage(Document, offset, curveInfo);
                if (bitmap != null)
                {
                    var image = new System.Windows.Controls.Image();
                    image.Source = bitmap;

                    image.Width  = bitmap.PixelWidth;
                    image.Height = bitmap.PixelHeight;
                    image.Cursor = Cursors.Arrow;
                    // Pass the length of the match to the 'documentLength' parameter
                    // of InlineObjectElement.
                    return(new InlineObjectElement(length, image));
                }
            }
            else
            {
                OxyPlot.Wpf.PlotView view = CurveViewCache.Instance.LoadPlotView(Document, offset, curveInfo);
                if (view != null)
                {
                    return(new InlineObjectElement(length, view));
                }
            }

            return(null);
        }
Ejemplo n.º 5
0
        private List <GPoint> ConvertCurvatureUnit(List <GPoint> points, CurveInfo curveInfo)
        {
            if (curveInfo.Option != "simplify_cm")
            {
                return(points);
            }

            List <GPoint> newPoints = new List <GPoint>(points.Count);

            points.ForEach(x => newPoints.Add(new GPoint(x.X, x.Y * 100.0)));
            return(newPoints);
        }
Ejemplo n.º 6
0
        protected override InlineObjectElement ConstructMainElement(int offset)
        {
            Match m = FindMatch(offset);

            // check whether there's a match exactly at offset
            if (m.Success && m.Index == 0)
            {
                CurveInfo curveInfo = new CurveInfo();
                curveInfo.IsGeoCoordinate = m.Groups[1].Value.Length > 0;
                curveInfo.Option          = m.Groups[2].Value;
                curveInfo.Description     = m.Groups[3].Value.Trim();
                curveInfo.XColumn         = m.Groups[4].Value.Trim();
                curveInfo.YColumn         = m.Groups[5].Value.Trim();

                return(CreateUIElement(m.Length, offset, curveInfo));
            }
            return(null);
        }
Ejemplo n.º 7
0
        public BitmapImage LoadImage(TextDocument document, int offset, CurveInfo curveInfo)
        {
            CurveViewItem curveViewItem = LoadCurveViewItem(document, offset, curveInfo);

            return(curveViewItem?.BitmapImage);
        }
Ejemplo n.º 8
0
        public OxyPlot.Wpf.PlotView LoadPlotView(TextDocument document, int offset, CurveInfo curveInfo)
        {
            CurveViewItem curveViewItem = LoadCurveViewItem(document, offset, curveInfo);

            return(curveViewItem?.PlotView);
        }
Ejemplo n.º 9
0
        public CurvePlotModel(string featureFileName,
                              List <GPoint> points,
                              bool showMarker,
                              CurveInfo curveInfo,
                              CurveManeuverParameter curveManeuverParameter,
                              double pointExtractionDuration)
        {
            this.ShowMarker                    = showMarker;
            this.CurveInfo                     = curveInfo;
            this.CurveManeuverParameter        = curveManeuverParameter;
            this.PointExtractionDurationTimeMS = pointExtractionDuration;

            Key = MakeKey(featureFileName, points, curveInfo);

            double curveLength = BezierCurveLength.LengthByQuadratic(points);

            base.PlotMargins = new OxyPlot.OxyThickness(60, 0, 0, 40);
            base.Title       = curveInfo.Title;

            List <GPoint> newPoint;

            switch (curveInfo.Option)
            {
            case "simplify":
                PlotOriginalCurve(points);
                PlotSimplifyCurvature(points);
                break;

            case "simplify_cm":
                newPoint = ConvertCurvatureUnit(points, curveInfo);
                PlotOriginalCurve(newPoint);
                PlotSimplifyCurvature(newPoint);
                break;

            case "bezier":
                PlotOriginalCurve(points);
                AddBezierByNURBS(points);
                PlotCurveManeuver(points, curveLength, points.Count - 1);
                break;

            case "bspline":
                PlotOriginalCurve(points);
                AddBSplineByNURBS(points, curveLength);
                PlotCurveManeuver(points, curveLength, SplineDegree(points));
                break;

            case "brcurvature":     // Raw curvature
                PlotBSplineRawCurvatureByNURBS(points, curveLength);
                break;

            case "bcurvature":      // Bezier curvature
            case "curvature":
                PlotBezierCurvatureByNURBS(points, curveLength);
                break;

            case "tangent":       // Tangent
                PlotTangent(points);
                break;

            case "degtangent":       // Tangent by degree of Bezier curve
                PlotBezierTangentByDegree(points);
                break;

            case "linreg":       // linear regression
                PlotOriginalCurve(points, useLinearSeries: false);
                PlotLinearRegression(points);
                break;

            default:
                PlotOriginalCurve(points);
                break;
            }
        }