Ejemplo n.º 1
0
        public PreviewForm(IPluginInterface pluginInterface)
        {
            Eto.Serialization.Xaml.XamlReader.Load(this);

            this.pluginInterface              = pluginInterface;
            pluginInterface.FileStateChanged += PluginInterface_FileStateChanged;
            pluginInterface.FileOpened       += PluginInterfaceOnFileOpened;

            var mainForm = (FForm)pluginInterface.RootForm;

            if (Screen != null && mainForm.Bounds.TopRight.X + 500 < Screen.Bounds.Width)
            {
                Location = mainForm.Bounds.TopRight + new Point(10, 0);
            }

            this.SizeChanged += (s, e) => panel.Invalidate();

            routesDropDown.SelectedRouteChanged += (s, e) => ResetRenderer();
            dtc.SelectedDaysChanged             += (s, e) =>
            {
                var attrs = new TimetableStyle(pluginInterface.Timetable);
                attrs.RenderDays = dtc.SelectedDays;
                ResetRenderer();
            };

            splitCheckBox.Checked         = pluginInterface.Settings.Get <bool>("bifpl.lock-stations");
            splitCheckBox.CheckedChanged += (s, e) =>
            {
                ResetRenderer();
                pluginInterface.Settings.Set("bifpl.lock-stations", splitCheckBox.Checked.Value);
            };

            adbg = new AsyncDoubleBufferedGraph(panel, pluginInterface)
            {
                RenderingFinished = () =>
                {
                    if (scrollPosition.HasValue)
                    {
                        scrollable.ScrollPosition = scrollPosition.Value;
                    }
                    scrollPosition = null;
                }
            };

            // Initialisierung der Daten
            dtc.SelectedDays = new TimetableStyle(pluginInterface.Timetable).RenderDays;
            routesDropDown.Initialize(pluginInterface);
            routesDropDown.EnableVirtualRoutes = true;
            virtualRoutesButton.Visible        = pluginInterface.Timetable is { Type : TimetableType.Network };
        }
Ejemplo n.º 2
0
        public PreviewForm(IInfo info)
        {
            Eto.Serialization.Xaml.XamlReader.Load(this);

            this.info              = info;
            info.FileStateChanged += Info_FileStateChanged;

            Resizable = Platform.IsWpf;

            var mainForm = (FForm)info.RootForm;

            if (Screen != null && mainForm.Bounds.TopRight.X + 500 < Screen.Bounds.Width)
            {
                Location = mainForm.Bounds.TopRight + new Point(10, 0);
            }

            routesDropDown.SelectedRouteChanged += (s, e) => ResetRenderer();
            dtc.ValueChanged += (s, e) => ResetRenderer();

            splitCheckBox.Checked         = info.Settings.Get <bool>("bifpl.lock-stations");
            splitCheckBox.CheckedChanged += (s, e) =>
            {
                ResetRenderer();
                info.Settings.Set("bifpl.lock-stations", splitCheckBox.Checked.Value);
            };

            adbg = new AsyncDoubleBufferedGraph(panel)
            {
                RenderingFinished = () =>
                {
                    if (scrollPosition.HasValue)
                    {
                        scrollable.ScrollPosition = scrollPosition.Value;
                    }
                    scrollPosition = null;
                }
            };

            // Initialisierung der Daten
            dtc.Initialize(info);
            routesDropDown.Initialize(info);
        }
Ejemplo n.º 3
0
        public void Initialize(IInfo info)
        {
            this.info = info;
            routesDropDown.Initialize(info);
            info.FileStateChanged += (s, e) =>
            {
                ReloadTimetable();
                newButton.Enabled      = routesDropDown.Enabled = newLineButton.Enabled = e.FileState.Opened;
                routesDropDown.Visible = info.FileState.Opened;

                newLineButton.Visible = joinLineButton.Visible = divider1.Visible = routesDropDown.Visible = info.FileState.Opened && info.Timetable.Type == TimetableType.Network;
                newLineButton.Enabled = joinLineButton.Enabled = info.FileState.Opened && info.Timetable.Type == TimetableType.Network && info.Timetable.GetRoutes().Any();

                foreach (Control c in toolbar.Controls)
                {
                    if (c.Tag is IRouteAction act)
                    {
                        c.Enabled = act.IsEnabled(info);
                    }
                }
            };
            info.ExtensionsLoaded += (s, e) =>
            {
                var actions = info.GetRegistered <IRouteAction>();
                if (actions.Length > 0)
                {
                    toolbar.Items.Add(new Divider());
                }

                foreach (var action in actions)
                {
                    var btn = new Button()
                    {
                        Text = action.DisplayName,
                        Tag  = action,
                    };
                    btn.Enabled = action.IsEnabled(info);
                    btn.Click  += (se, ev) => action.Show(info, info.Timetable?.GetRoute(routesDropDown.SelectedRoute));
                    toolbar.Items.Add(btn);
                }
            };

            routesDropDown.SelectedRouteChanged += (s, e) =>
            {
                lineRenderer.SelectedRoute   = routesDropDown.SelectedRoute;
                info.FileState.SelectedRoute = routesDropDown.SelectedRoute;
            };

            lineRenderer.StationDoubleClicked += (s, e) =>
            {
                info.StageUndoStep();
                var sta = (Station)s;
                var r   = routesDropDown.SelectedRoute;
                if (sta.Routes.Length == 1)
                {
                    r = sta.Routes[0];
                }
                if (!sta.Routes.Contains(r))
                {
                    MessageBox.Show("Die Station liegt auf mehreren Strecken. Bitte zuerst die Strecke auswählen, für die die Station bearbeitet werden soll!",
                                    "FPLedit", MessageBoxButtons.OK, MessageBoxType.Warning);
                    return;
                }
                var nsf = new EditStationForm(sta, r);
                if (nsf.ShowModal(this) == DialogResult.Ok)
                {
                    ReloadTimetable();
                    info.SetUnsaved();
                }
            };
            lineRenderer.StationRightClicked += (s, e) =>
            {
                var menu = new ContextMenu();
                var itm  = menu.CreateItem("Löschen");
                itm.Click += (se, ar) =>
                {
                    info.StageUndoStep();
                    info.Timetable.RemoveStation((Station)s);
                    ReloadTimetable();
                    info.SetUnsaved();
                };
                menu.Show(this);
            };
            lineRenderer.NewRouteAdded += (s, args) =>
            {
                (info.FileState as FileState).Saved = false;
                routesDropDown.SelectedRoute        = args.Value;
            };
            lineRenderer.StationMoveEnd += (s, args) => (info.FileState as FileState).Saved = false;
            newButton.Click             += (s, e) =>
            {
                info.StageUndoStep();
                var nsf = new EditStationForm(info.Timetable, routesDropDown.SelectedRoute);
                if (nsf.ShowModal(this) == DialogResult.Ok)
                {
                    Station sta = nsf.Station;
                    if (info.Timetable.Type == TimetableType.Network)
                    {
                        var handler = new StaPosHandler();
                        handler.SetMiddlePos(routesDropDown.SelectedRoute, sta, info.Timetable);
                        var r = sta.Routes.ToList();
                        r.Add(lineRenderer.SelectedRoute);
                        sta.Routes = r.ToArray();
                    }
                    info.Timetable.AddStation(sta, routesDropDown.SelectedRoute);
                    info.SetUnsaved();
                    ReloadTimetable();
                }
            };
            newLineButton.Click += (s, e) =>
            {
                info.StageUndoStep();
                var nlf = new EditStationForm(info.Timetable);
                if (nlf.ShowModal(this) == DialogResult.Ok)
                {
                    lineRenderer.StartAddStation(nlf.Station, nlf.Position);
                    info.SetUnsaved();
                }
            };
            joinLineButton.Click += (s, e) =>
            {
                info.StageUndoStep();
                var epf = new EditPositionForm();
                if (epf.ShowModal(this) == DialogResult.Ok)
                {
                    lineRenderer.StartJoinLines(epf.Position);
                    ReloadTimetable();
                    info.SetUnsaved();
                }
            };

            KeyDown += (s, e) => DispatchKeystroke(e);
        }
Ejemplo n.º 4
0
        public void InitPrint()
        {
            var form           = new FDialog <bool>();
            var routesDropDown = new RoutesDropDown();
            var routeStack     = new StackLayout(routesDropDown)
            {
                Orientation = Orientation.Horizontal, Padding = new Eto.Drawing.Padding(10), Spacing = 5
            };
            var routeGroup = new GroupBox {
                Content = routeStack, Text = T._("Strecke auswählen")
            };

            var widthLabel = new Label {
                Text = T._("Breite des Bildes (px)")
            };
            var widthTextBox = new TextBox {
                Text = "1000"
            };
            var exportButton = new Button {
                Text = T._("Exportieren")
            };
            var printerStack = new StackLayout(widthLabel, widthTextBox, exportButton)
            {
                Orientation = Orientation.Horizontal, Padding = new Eto.Drawing.Padding(10), Spacing = 5
            };
            var printerGroup = new GroupBox {
                Content = printerStack, Text = T._("Exporteinstellungen")
            };

            var stack = new StackLayout(routeGroup, printerGroup)
            {
                Orientation = Orientation.Vertical, Padding = new Eto.Drawing.Padding(10), Spacing = 5
            };

            routesDropDown.Initialize(pluginInterface);
            routesDropDown.EnableVirtualRoutes = true;

            form.Content       = stack;
            form.DefaultButton = exportButton;
            form.Title         = T._("Bildfahrplan drucken");

            exportButton.Click += (s, e) =>
            {
                form.Result = true;
                form.Close();
            };

            if (form.ShowModal())
            {
                var width = 0;
                int.TryParse(widthTextBox.Text, out width);
                if (width == 0)
                {
                    pluginInterface.Logger.Error("Ungültige Breite angegeben!");
                    return;
                }

                var exportFileDialog = new SaveFileDialog {
                    Title = T._("Bildfahrplan exportieren")
                };
                exportFileDialog.Filters.Add(new FileFilter("PNG-Datei", ".png"));
                if (exportFileDialog.ShowDialog(pluginInterface.RootForm) == DialogResult.Ok)
                {
                    var filename = exportFileDialog.FileName;
                    var export   = new BitmapExport(routesDropDown.SelectedRoute, width, ImageFormat.Png);

                    pluginInterface.Logger.Info(T._("Exportiere Bildfahrplan in Datei {0}", filename));
                    var tsk = export.GetAsyncSafeExport(tt.Clone(), filename, pluginInterface);
                    tsk.ContinueWith((t, o) =>
                    {
                        if (t.Result == false)
                        {
                            pluginInterface.Logger.Error(T._("Exportieren des Bildfahrplans fehlgeschlagen!"));
                        }
                        else
                        {
                            pluginInterface.Logger.Info(T._("Exportieren des Bildfahrplans erfolgreich abgeschlossen!"));
                        }
                    }, null, TaskScheduler.Default);
                    tsk.Start(); // Non-blocking operation.
                }
            }
        }
Ejemplo n.º 5
0
        public void InitPrint()
        {
            var printers = Print.PrinterSettings.InstalledPrinters.Cast <string>().ToArray();

            doc = new Print.PrintDocument();
            var form           = new FDialog <string>();
            var routesDropDown = new RoutesDropDown();
            var routeStack     = new StackLayout(routesDropDown)
            {
                Orientation = Orientation.Horizontal, Padding = new Eto.Drawing.Padding(10), Spacing = 5
            };
            var routeGroup = new GroupBox {
                Content = routeStack, Text = T._("Strecke auswählen")
            };
            var printerDropDown = new DropDown {
                DataStore = printers
            };
            var paperDropDown = new DropDown();
            var landscapeChk  = new CheckBox {
                Text = T._("Querformat")
            };
            var printButton = new Button {
                Text = T._("Drucken")
            };
            var printerStack = new StackLayout(printerDropDown, paperDropDown, landscapeChk, printButton)
            {
                Orientation = Orientation.Horizontal, Padding = new Eto.Drawing.Padding(10), Spacing = 5
            };
            var printerGroup = new GroupBox {
                Content = printerStack, Text = T._("Druckeinstellungen")
            };
            var stack = new StackLayout(routeGroup, printerGroup)
            {
                Orientation = Orientation.Vertical, Padding = new Eto.Drawing.Padding(10), Spacing = 5
            };

            routesDropDown.Initialize(pluginInterface);
            routesDropDown.EnableVirtualRoutes = true;

            form.Content       = stack;
            form.DefaultButton = printButton;
            form.Title         = T._("Bildfahrplan drucken");

            printButton.Click += (s, e) =>
            {
                form.Result = (string)printerDropDown.SelectedValue;
                form.Close();
            };

            printerDropDown.SelectedIndexChanged += (s, e) =>
            {
                doc.PrinterSettings.PrinterName = (string)printerDropDown.SelectedValue;
                var paper   = doc.PrinterSettings.PaperSizes.Cast <Print.PaperSize>().Select(p => p.PaperName).ToArray();
                var a4Index = Array.IndexOf(paper, "A4");
                paperDropDown.DataStore     = paper;
                paperDropDown.SelectedIndex = (a4Index != -1) ? a4Index : 0;
            };

            printerDropDown.SelectedIndex = 0;

            if (form.ShowModal() != null)
            {
                if (routesDropDown.SelectedRoute > Timetable.UNASSIGNED_ROUTE_ID)
                {
                    pd = Renderer.DefaultPathData(routesDropDown.SelectedRoute, pluginInterface.Timetable);
                }
                else
                {
                    var virt = VirtualRoute.GetVRoute(pluginInterface.Timetable, routesDropDown.SelectedRoute);
                    pd = virt !.GetPathData;
                }

                doc.PrintPage   += Doc_PrintPage;
                doc.DocumentName = T._("Bildfahrplan generiert mit FPLedit");

                doc.PrinterSettings.PrinterName = form.Result;

                doc.DefaultPageSettings.Margins = new Print.Margins(50, 50, 50, 50); // not working (turning page????)

                if (Eto.Platform.Instance.IsGtk)
                {
                    var paperSize = doc.PrinterSettings.PaperSizes[paperDropDown.SelectedIndex];
                    //HACK: Do not use doc.DefaultPageSettings.Landscape on Linux, as it will lead to awkwardly turned rendering areas, ???)
                    if (landscapeChk.Checked !.Value)
                    {
                        doc.DefaultPageSettings.PaperSize = new Print.PaperSize(paperSize.PaperName, paperSize.Height, paperSize.Width);
                    }
                    else
                    {
                        doc.DefaultPageSettings.PaperSize = paperSize;
                    }
                }
                else
                {
                    doc.DefaultPageSettings.Landscape = landscapeChk.Checked !.Value;
                }

                if (!doc.PrinterSettings.IsValid)
                {
                    MessageBox.Show(T._("Ungültige Druckereinstellungen!"), "FPLedit", MessageBoxType.Error);
                }
                else
                {
                    try
                    {
                        doc.Print();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(T._("Fehler beim Drucken! {0}", ex.Message), "FPLedit", MessageBoxType.Error);
                    }
                }
            }