Exemple #1
0
        private void DrawLine(Graphics g, LayoutPolyLine line, Pen pen)
        {
            var linePoints = line.GetLinePoints()
                             .Select(x => PointToDisplay(x)).ToArray();

            g.DrawCurve(pen, linePoints, 0.5f);
        }
Exemple #2
0
        private LwPolyline AddDxfPolyLine(string layerName, LayoutPolyLine line, LineExportConfig lineConfig)
        {
            var splinePoints = new List <Vector2>();

            foreach (var pt in line.Points)
            {
                splinePoints.Add(PointToVector(pt));
            }

            var polyLine = new LwPolyline(splinePoints)
            {
                Layer = GetLayer(layerName),
                Color = GetColor(lineConfig.Color),
            };

            //foreach (var vec in splinePoints)
            //    polyLine.Vertexes.Add(new LwPolylineVertex(vec));

            if (lineConfig.IsDashed)
            {
                polyLine.Linetype = Linetype.Dashed;
            }

            Document.AddEntity(polyLine);
            return(polyLine);
        }
Exemple #3
0
        private SvgPath CreateSvgSpline(SvgElement owner, LayoutPolyLine line, LineExportConfig lineConfig)
        {
            var path = new SvgPath()
            {
                StrokeWidth = GetLineThickness(lineConfig),
                Stroke = new SvgColourServer(lineConfig.Color),
                Fill = SvgPaintServer.None
            };

            if (lineConfig.IsDashed)
                path.StrokeDashArray = LineDashPattern;

            path.PathData.Add(new SvgMoveToSegment(GetRelativePosition(line.Spline.Curves[0].StartPoint)));

            for (int i = 0; i < line.Spline.Curves.Length; i++)
            {
                var curve = line.Spline.Curves[i];
                path.PathData.Add(new SvgCubicCurveSegment(
                    GetRelativePosition(curve.StartPoint),
                    GetRelativePosition(curve.ControlPoints[0]),
                    GetRelativePosition(curve.ControlPoints[1]),
                    GetRelativePosition(curve.EndPoint)
                    )
                );
            }

            if (owner != null)
                owner.Children.Add(path);

            return path;
        }
Exemple #4
0
        private SvgPath CreateSvgPolyLine(SvgElement owner, LayoutPolyLine line, LineExportConfig lineConfig)
        {
            var path = new SvgPath() { 
                StrokeWidth = GetLineThickness(lineConfig), 
                Stroke = new SvgColourServer(lineConfig.Color), 
                Fill = SvgPaintServer.None 
            };

            if (lineConfig.IsDashed)
                path.StrokeDashArray = LineDashPattern;

            path.PathData.Add(new SvgMoveToSegment(GetRelativePosition(line.Points[0])));

            for (int i = 0; i < line.Points.Count - 1; i++)
            {
                path.PathData.Add(new SvgLineSegment(
                    GetRelativePosition(line.Points[i]),
                    GetRelativePosition(line.Points[i + 1])
                    )
                );
            }
            if (owner != null)
                owner.Children.Add(path);
            return path;
        }
Exemple #5
0
        protected override void AddLayoutSpline(LayoutPolyLine line, VisualElementType elementType, LineExportConfig lineConfig)
        {
            switch (elementType)
            {
                case VisualElementType.Fret:
                    {
                        var svgSpline = CreateSvgSpline(GetLayer("Frets"), line, lineConfig);

                        FretLine fretLine = (line as FretLine) ?? (line.Tag as FretLine);
                        if (fretLine != null)
                        {
                            if (fretLine.IsNut)
                                svgSpline.CustomAttributes.Add("Fret", "Nut");
                            else
                                svgSpline.CustomAttributes.Add("Fret", fretLine.FretIndex.ToString());
                        }
                        break;
                    }
                case VisualElementType.FingerboardEdge:
                case VisualElementType.FingerboardMargin:
                case VisualElementType.FingerboardContinuation:
                    CreateSvgSpline(GetLayer("Fingerboard"), line, lineConfig);
                    break;

                //case VisualElementType.GuideLine:
                default:
                    CreateSvgSpline(GetLayer("Layout"), line, lineConfig);
                    break;
            }
        }
Exemple #6
0
        protected override void AddLayoutSpline(LayoutPolyLine line, VisualElementType elementType, LineExportConfig lineConfig)
        {
            switch (elementType)
            {
            case VisualElementType.Fret:
                AddDxfSpline("Frets", line, lineConfig);
                break;

            case VisualElementType.FingerboardEdge:
            case VisualElementType.FingerboardMargin:
            case VisualElementType.FingerboardContinuation:
                AddDxfSpline("Fingerboard", line, lineConfig);
                break;

            //case VisualElementType.GuideLine:
            default:
                AddDxfSpline("Layout", line, lineConfig);
                break;
            }
        }
Exemple #7
0
        private Spline AddDxfSpline(string layerName, LayoutPolyLine line, LineExportConfig lineConfig)
        {
            var splinePoints = new List <Vector2>();

            foreach (var pt in line.Points)
            {
                splinePoints.Add(PointToVector(pt));
            }

            var splineLine = new Spline(splinePoints.Select(x => new SplineVertex(x)).ToList())
            {
                Layer = GetLayer(layerName),
                Color = GetColor(lineConfig.Color)
            };

            if (lineConfig.IsDashed)
            {
                splineLine.Linetype = Linetype.Dashed;
            }

            Document.AddEntity(splineLine);
            return(splineLine);
        }
Exemple #8
0
 protected virtual void AddLayoutSpline(LayoutPolyLine line, VisualElementType elementType, LineExportConfig lineConfig)
 {
 }
Exemple #9
0
        private void FinishFingerboardShape()
        {
            var trebleSideEdge = VisualElements.OfType <FingerboardSideEdge>().First(e => e.Side == FingerboardSide.Treble);
            var bassSideEdge   = VisualElements.OfType <FingerboardSideEdge>().First(e => e.Side == FingerboardSide.Bass);
            var trebleNutFret  = VisualElements.OfType <FretLine>().First(f => f.IsNut && f.Strings.Contains(FirstString));
            var bassNutFret    = VisualElements.OfType <FretLine>().First(f => f.IsNut && f.Strings.Contains(LastString));

            //create inward fingerboard edges from nut
            if (!Strings.AllEqual(s => s.StartingFret))
            {
                foreach (var str in Strings)
                {
                    if (str.Next != null && str.StartingFret != str.Next.StartingFret)
                    {
                        var nut1 = VisualElements.OfType <FretLine>().First(f => f.IsNut && f.Strings.Contains(str));
                        var nut2 = VisualElements.OfType <FretLine>().First(f => f.IsNut && f.Strings.Contains(str.Next));
                        AddVisualElement(new FingerboardEdge(nut1.Points.First(), nut2.Points.Last())
                        {
                            IsSideEdge = true
                        });

                        //var center = GetStringBoundaryLine(str, FingerboardSide.Bass) as StringCenter;
                        //var p1 = center.GetRelativePoint(str.LayoutLine, str.LayoutLine.P1);
                        //var p2 = center.GetRelativePoint(str.Next.LayoutLine, str.Next.LayoutLine.P1);
                        //AddVisualElement(new FingerboardEdge(p1, p2) { IsSideEdge = true });
                    }
                }
            }

            var trebSideNutInter = PointM.Empty;

            if (trebleNutFret.Intersects(trebleSideEdge, out trebSideNutInter))
            {
                trebleSideEdge.P1 = trebSideNutInter;
            }

            var bassSideNutInter = PointM.Empty;

            if (bassNutFret.Intersects(bassSideEdge, out bassSideNutInter))
            {
                bassSideEdge.P1 = bassSideNutInter;
            }

            trebleSideEdge.RealEnd = trebleSideEdge.P2;
            bassSideEdge.RealEnd   = bassSideEdge.P2;

            var trebleLastFret = VisualElements.OfType <FretLine>().First(f => f.FretIndex == FirstString.NumberOfFrets && f.Strings.Contains(FirstString));
            var bassLastFret   = VisualElements.OfType <FretLine>().First(f => f.FretIndex == LastString.NumberOfFrets && f.Strings.Contains(LastString));

            PointM trebleEndPoint = trebleLastFret.Points.Last();
            PointM bassEndPoint   = bassLastFret.Points.First();

            if (!Margins.LastFret.IsEmpty)
            {
                trebleEndPoint += trebleSideEdge.Direction * Margins.LastFret;
                bassEndPoint   += bassSideEdge.Direction * Margins.LastFret;
            }

            //split physical from virtual fingerboard
            var virtualTrebleEdge = AddVisualElement(new LayoutLine(trebleEndPoint, trebleSideEdge.P2, VisualElementType.FingerboardContinuation));
            var virtualBassEdge   = AddVisualElement(new LayoutLine(bassEndPoint, bassSideEdge.P2, VisualElementType.FingerboardContinuation));

            trebleSideEdge.P2 = virtualTrebleEdge.P1;
            bassSideEdge.P2   = virtualBassEdge.P1;

            if (NumberOfStrings > 1)
            {
                var bridgeLine = new LayoutPolyLine(Strings.Select(s => s.LayoutLine.P2), VisualElementType.BridgeLine);
                VisualElements.Add(bridgeLine);

                var bridgeTrebleInter = PointM.Empty;
                if (bridgeLine.Intersects(virtualTrebleEdge, out bridgeTrebleInter))
                {
                    virtualTrebleEdge.P2 = bridgeTrebleInter;
                }

                var bridgeBassInter = PointM.Empty;
                if (bridgeLine.Intersects(virtualBassEdge, out bridgeBassInter))
                {
                    virtualBassEdge.P2 = bridgeBassInter;
                }
            }

            if (trebleLastFret.Strings.Count() == NumberOfStrings && trebleLastFret.IsStraight && trebleLastFret.FretIndex == MaximumFret)
            {
                AddVisualElement(new FingerboardEdge(bassSideEdge.P2, trebleSideEdge.P2));
            }
            else if (!Margins.LastFret.IsEmpty)
            {
                var fretLines  = VisualElements.OfType <FretLine>();
                var edgePoints = new List <PointM>();

                for (int i = NumberOfStrings - 1; i >= 0; i--)
                {
                    var strLastFret = fretLines.First(fl => fl.FretIndex == Strings[i].NumberOfFrets && fl.Strings.Contains(Strings[i]));
                    var trebleSide  = GetStringBoundaryLine(Strings[i], FingerboardSide.Treble);
                    var bassSide    = GetStringBoundaryLine(Strings[i], FingerboardSide.Bass);
                    var pt1         = PointM.Empty;
                    var pt2         = PointM.Empty;

                    if (!strLastFret.Intersects(bassSide, out pt1))
                    {
                        pt1 = strLastFret.Points.First();
                    }

                    if (!strLastFret.Intersects(trebleSide, out pt2))
                    {
                        pt2 = strLastFret.Points.Last();
                    }

                    pt1 += bassSide.Direction * Margins.LastFret;
                    pt2 += trebleSide.Direction * Margins.LastFret;

                    edgePoints.Add(pt1);
                    edgePoints.Add(pt2);
                }

                //edgePoints.RemoveAll(p => p.IsEmpty);
                edgePoints = edgePoints.Distinct().ToList();
                var fretboardEdge = AddVisualElement(new FingerboardEdge(edgePoints));
                //fretboardEdge.InterpolateSpline();
            }

            var fingerboardEnds = VisualElements.OfType <FingerboardEdge>();

            var trebleLine = FirstString.LayoutLine;

            foreach (var end in fingerboardEnds)
            {
                if (end.Intersects(trebleLine, out PointM inter, false))
                {
                    AddVisualElement(new LayoutLine(trebleLine.P1, inter, VisualElementType.FingerboardMargin));
                    break;
                }
            }

            if (LastString != FirstString)
            {
                var bassLine = LastString.LayoutLine;

                foreach (var end in fingerboardEnds)
                {
                    if (end.Intersects(bassLine, out PointM inter, false))
                    {
                        AddVisualElement(new LayoutLine(bassLine.P1, inter, VisualElementType.FingerboardMargin));
                        break;
                    }
                }
            }
        }