コード例 #1
0
        private Margins CalcMargins(Graphics g, Margins orig, IEnumerable <Station> stations, TimeEntry startTime, TimeEntry endTime, bool drawHeader)
        {
            const int additionalMargin = 5;
            var       result           = new Margins(orig.Left + additionalMargin, orig.Top + additionalMargin, orig.Right + additionalMargin, orig.Bottom + additionalMargin);

            var path = getPathData();

            // MarginTop berechnen
            var hr = new HeaderRenderer(attrs, path);

            result.Top = drawHeader ? (
                attrs.DrawHeader ?
                hr.GetMarginTop(g) + result.Top
                    : result.Top)
                : 5;

            // MarginLeft berechnen
            var tr = new TimeRenderer(attrs);

            result.Left += tr.GetMarginLeftOffset(g, startTime, endTime);

            return(result);
        }
コード例 #2
0
ファイル: HeaderRenderer.cs プロジェクト: fadoe/FPLedit
        public Dictionary <Station, StationX> Render(Graphics g, Margins margin, float width, float height, bool drawHeader)
        {
            var stationFont    = (Font)attrs.StationFont; // Reminder: Do not dispose, will be disposed with MFont instance!
            var firstStation   = stations.First();
            var lastStation    = stations.Last();
            var stationOffsets = new Dictionary <Station, StationX>();

            var allTrackCount  = stations.Select(s => s.Tracks.Count).Sum();
            var stasWithTracks = stations.Count(s => s.Tracks.Any());
            var allTrackWidth  = (stasWithTracks + allTrackCount) * StationX.IndividualTrackOffset;

            var emSize = g.MeasureString(stationFont, "M").Width;

            StationX lastPos = null;

            foreach (var sta in stations)
            {
                var style = new StationStyle(sta, attrs);

                var kil    = sta.Positions.GetPosition(route) - firstStation.Positions.GetPosition(route);
                var length = lastStation.Positions.GetPosition(route) - firstStation.Positions.GetPosition(route);

                if (!kil.HasValue || !length.HasValue)
                {
                    throw new Exception("Unerwarteter Fehler beim Rendern der Route!");
                }

                StationX posX;
                if (!attrs.MultiTrack)
                {
                    posX = new StationX(sta, kil.Value, ((kil / length) * (width - margin.Right - margin.Left)).Value);
                }
                else
                {
                    var availWidth = width - margin.Right - margin.Left - allTrackWidth;
                    var lastKil    = lastPos?.CurKilometer ?? 0f;
                    var lastRight  = lastPos?.Right ?? 0f;
                    var leftOffset = (((kil / length) - (lastKil / length)) * availWidth).Value;
                    posX = new StationX(sta, kil.Value, lastRight + leftOffset, true);
                }
                lastPos = posX;
                stationOffsets.Add(sta, posX);

                if (!style.CalcedShow)
                {
                    continue;
                }

                using (var pen = new Pen((Color)style.CalcedColor, style.CalcedWidth)
                {
                    DashStyle = ds.ParseDashstyle(style.CalcedLineStyle)
                })
                    using (var brush = new SolidBrush((Color)style.CalcedColor))
                    {
                        if (!attrs.MultiTrack)
                        {
                            // Linie (Single-Track-Mode)
                            g.DrawLine(pen, margin.Left + posX.Center, margin.Top - 5, margin.Left + posX.Center, height - margin.Bottom);
                        }
                        else
                        {
                            // Linie (Multi-Track-Mode)
                            g.DrawLine(pen, margin.Left + posX.Left, margin.Top - 5, margin.Left + posX.Left, height - margin.Bottom);
                            foreach (var trackX in posX.TrackOffsets)
                            {
                                g.DrawLine(pen, margin.Left + trackX.Value, margin.Top - 5, margin.Left + trackX.Value, height - margin.Bottom);
                            }
                            g.DrawLine(pen, margin.Left + posX.Right, margin.Top - 5, margin.Left + posX.Right, height - margin.Bottom);
                        }

                        if (!drawHeader)
                        {
                            continue;
                        }

                        // Stationsnamen
                        if (attrs.DrawHeader)
                        {
                            var display = sta.ToString(attrs.DisplayKilometre, route);
                            var size    = g.MeasureString(stationFont, display);

                            var addOffset = attrs.MultiTrack ? emSize + 3 : 0;

                            if (attrs.StationVertical)
                            {
                                g.SaveTransform();
                                g.TranslateTransform(margin.Left + posX.Center + (size.Height / 2), margin.Top - 8 - addOffset - size.Width);
                                g.RotateTransform(90);
                                g.DrawText(stationFont, brush, 0, 0, display);
                                g.RestoreTransform();
                            }
                            else
                            {
                                g.DrawText(stationFont, brush, margin.Left + posX.Center - (size.Width / 2), margin.Top - size.Height - addOffset - 5, display);
                            }

                            if (attrs.MultiTrack)
                            {
                                foreach (var track in posX.TrackOffsets)
                                {
                                    var trackSize = g.MeasureString(stationFont, track.Key);
                                    g.DrawText(stationFont, brush, margin.Left + track.Value - (trackSize.Width / 2), margin.Top - trackSize.Height - 5, track.Key);
                                }
                            }
                        }
                    }// Disposing Pens and Brushes
            }
            return(stationOffsets);
        }
コード例 #3
0
 public void SetMargins(Margins margins)
 {
     defaultMargin = margins;
 }
コード例 #4
0
        public Dictionary <Station, StationRenderProps> Render(Graphics g, Margins margin, float width, float height, bool drawHeader, bool exportColor)
        {
            var stationFont    = (Font)attrs.StationFont; // Reminder: Do not dispose, will be disposed with MFont instance!
            var stationOffsets = new Dictionary <Station, StationRenderProps>();

            var raw                 = path.GetRawPath().ToList();
            var allTrackCount       = raw.Select(s => s.Tracks.Count).Sum();
            var stasWithTracks      = raw.Count(s => s.Tracks.Any());
            var allTrackWidth       = (stasWithTracks + allTrackCount) * StationRenderProps.IndividualTrackOffset;
            var verticalTrackOffset = GetTrackOffset(g, stationFont) + TOP_GAP;

            float length = 0f;

            PathEntry lastpe = null;

            foreach (var sta in path.PathEntries)
            {
                var er = path.GetEntryRoute(sta.Station);
                if (er != Timetable.UNASSIGNED_ROUTE_ID)
                {
                    length += (sta !.Station.Positions.GetPosition(er) - lastpe !.Station.Positions.GetPosition(er)) !.Value;
                }
                lastpe = sta;
            }

            StationRenderProps lastPos = null;

            lastpe = null;
            float kil = 0f;

            foreach (var sta in path.PathEntries)
            {
                var style = new StationStyle(sta.Station, attrs);

                var er = path.GetEntryRoute(sta.Station);
                if (er != Timetable.UNASSIGNED_ROUTE_ID)
                {
                    kil += (sta !.Station.Positions.GetPosition(er) - lastpe !.Station.Positions.GetPosition(er)) !.Value;
                }
                lastpe = sta;

                StationRenderProps posX;
                if (!attrs.MultiTrack)
                {
                    posX = new StationRenderProps(sta.Station, kil, ((kil / length) * (width - margin.Right - margin.Left)));
                }
                else
                {
                    var availWidth = width - margin.Right - margin.Left - allTrackWidth;
                    var lastKil    = lastPos?.CurKilometer ?? 0f;
                    var lastRight  = lastPos?.Right ?? 0f;
                    var leftOffset = (((kil / length) - (lastKil / length)) * availWidth);
                    posX = new StationRenderProps(sta.Station, kil, lastRight + leftOffset, true);
                }
                lastPos = posX;
                stationOffsets.Add(sta.Station, posX);

                if (!style.CalcedShow)
                {
                    continue;
                }

                using var pen = new Pen(style.CalcedColor.ToSD(exportColor), style.CalcedWidth)
                      {
                          DashPattern = ds.ParseDashstyle(style.CalcedLineStyle)
                      };
                using var brush = new SolidBrush(style.CalcedColor.ToSD(exportColor));

                if (!attrs.MultiTrack)
                {
                    // Linie (Single-Track-Mode)
                    g.DrawLine(pen, margin.Left + posX.Center, margin.Top - TOP_GAP, margin.Left + posX.Center, height - margin.Bottom);
                }
                else
                {
                    // Linie (Multi-Track-Mode)
                    g.DrawLine(pen, margin.Left + posX.Left, margin.Top - TOP_GAP, margin.Left + posX.Left, height - margin.Bottom);
                    foreach (var trackX in posX.TrackOffsets)
                    {
                        g.DrawLine(pen, margin.Left + trackX.Value, margin.Top - TOP_GAP, margin.Left + trackX.Value, height - margin.Bottom);
                    }
                    g.DrawLine(pen, margin.Left + posX.Right, margin.Top - TOP_GAP, margin.Left + posX.Right, height - margin.Bottom);
                }

                if (!drawHeader)
                {
                    continue;
                }

                // Stationsnamen
                if (attrs.DrawHeader)
                {
                    var display = StationDisplay(sta);
                    var size    = g.MeasureString(stationFont, display);

                    if (attrs.StationVertical)
                    {
                        var matrix = g.Transform.Clone();

                        g.TranslateTransform(margin.Left + posX.Center + (size.Height / 2), margin.Top - 8 - verticalTrackOffset - size.Width);
                        g.RotateTransform(90);
                        g.DrawText(stationFont, brush, 0, 0, display);

                        g.Transform = matrix;
                    }
                    else
                    {
                        g.DrawText(stationFont, brush, margin.Left + posX.Center - (size.Width / 2), margin.Top - size.Height - verticalTrackOffset - TOP_GAP, display);
                    }

                    if (attrs.MultiTrack)
                    {
                        foreach (var track in posX.TrackOffsets)
                        {
                            var trackSize = g.MeasureString(stationFont, track.Key);
                            if (attrs.StationVertical)
                            {
                                var matrix = g.Transform.Clone();

                                g.TranslateTransform(margin.Left + track.Value + (trackSize.Height / 2), margin.Top - 8 - trackSize.Width);
                                g.RotateTransform(90);
                                g.DrawText(stationFont, brush, 0, 0, track.Key);

                                g.Transform = matrix;
                            }
                            else
                            {
                                g.DrawText(stationFont, brush, margin.Left + track.Value - (trackSize.Width / 2), margin.Top - trackSize.Height - TOP_GAP, track.Key);
                            }
                        }
                    }
                }
            }
            return(stationOffsets);
        }