Ejemplo n.º 1
0
 private void TrainColorItem_Click(object sender, EventArgs e)
 {
     info.StageUndoStep();
     using (var tcf = new TrainColorForm(info))
         if (tcf.ShowModal(info.RootForm) == DialogResult.Ok)
         {
             info.SetUnsaved();
         }
 }
Ejemplo n.º 2
0
 private void ShowForm(Dialog <DialogResult> form)
 {
     info.StageUndoStep();
     if (form.ShowModal(Program.App.MainForm) == DialogResult.Ok)
     {
         info.SetUnsaved();
     }
 }
Ejemplo n.º 3
0
 private void PreferencesButton_Click(object sender, EventArgs e)
 {
     info.StageUndoStep();
     using (var cnf = new ConfigForm(info.Timetable, info.Settings))
         cnf.ShowModal(this);
     ResetRenderer();
     info.SetUnsaved();
 }
Ejemplo n.º 4
0
 public void Show(IInfo info, Route route)
 {
     info.StageUndoStep();
     using (var svf = new VelocityForm(info, route))
         if (svf.ShowModal() == DialogResult.Ok)
         {
             info.SetUnsaved();
         }
 }
Ejemplo n.º 5
0
 public void Show(IInfo info, Route route)
 {
     info.StageUndoStep();
     using (var lef = new LineEditForm(info, route.Index))
         if (lef.ShowModal(info.RootForm) == DialogResult.Ok)
         {
             info.SetUnsaved();
         }
 }
Ejemplo n.º 6
0
        private void StartNetwork(int route)
        {
            var backupHandle = info.BackupTimetable();

            try
            {
                bool showMessage = info.Settings.Get("jTGStarter.show-message", true);

                if (showMessage)
                {
                    DialogResult res = MessageBox.Show("Dies speichert die aktuell ausgewählte Route in eine temporäre Datei und öffnet dann jTrainGraph (>= 2.02). Nachdem Sie die Arbeit in jTrainGraph beendet haben, speichern Sie damit die Datei und schließen das jTrainGraph-Hauptfenster, damit werden alle Änderungen an den Bildfahrplaneinstellungen übernommen."
                                                       + Environment.NewLine + "ACHTUNG: Es werden nur Änderungen an der Bildfahrplandarstellung übernommen, alle anderen Änderungen (z.B. Bahnhöfe oder Züge einfügen) werden verworfen! Aktion fortsetzen?"
                                                       + Environment.NewLine + Environment.NewLine + "Diese Meldung kann unter jTrainGraph > Einstellungen deaktiviert werden.",
                                                       "jTrainGraph starten (aktuelle Route)", MessageBoxButtons.YesNo, MessageBoxType.Warning);

                    if (res != DialogResult.Yes)
                    {
                        return;
                    }
                }

                var targetVersion = info.Settings.GetEnum("jTGStarter.target-version", JTGShared.DEFAULT_TT_VERSION);

                var exporter = new Shared.Filetypes.XMLExport();
                var importer = new Shared.Filetypes.XMLImport();
                var sync     = new TimetableRouteSync(info.Timetable, route);
                var rtt      = sync.GetRouteTimetable(targetVersion);
                var fn       = info.GetTemp(Guid.NewGuid().ToString() + "-route-" + route + ".fpl");
                exporter.Export(rtt, fn, info);

                StartJtg(fn, () =>
                {
                    info.StageUndoStep();
                    var crtt = importer.Import(fn, info, new SilentLogger(info.Logger));
                    sync.SyncBack(crtt);
                    info.SetUnsaved();
                });
                info.ClearBackup(backupHandle);
            }
            catch (Exception e)
            {
                info.Logger.Error("Beim Verwenden von jTrainGraph ist ein unerwarteter Fehler aufgetreten! " + e);
                info.Logger.LogException(e);
                info.RestoreTimetable(backupHandle);
            }
        }
Ejemplo n.º 7
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);
        }