コード例 #1
0
ファイル: FileHandler.cs プロジェクト: fadoe/FPLedit
        internal void Import()
        {
            var importers = info.GetRegistered <IImport>();

            if (importers.Length == 0)
            {
                info.Logger.Error("Keine Importer gefunden, Import nicht möglich!");
                return;
            }

            if (!NotifyIfUnsaved())
            {
                return;
            }
            if (importFileDialog.ShowDialog(parent) == DialogResult.Ok)
            {
                IImport import = importers[importFileDialog.CurrentFilterIndex - 1];
                info.Logger.Info("Öffne Datei " + importFileDialog.FileName);
                Timetable = import.Import(importFileDialog.FileName, info);
                if (Timetable == null)
                {
                    return;
                }
                info.Logger.Info("Datei erfolgeich geöffnet!");
                FileState.Opened   = true;
                FileState.Saved    = true;
                FileState.FileName = importFileDialog.FileName;
                undo.ClearHistory();
            }
        }
コード例 #2
0
        private void Info_ExtensionsLoaded(object sender, EventArgs e)
        {
            var previewables = info.GetRegistered <IPreviewable>();

            if (previewables.Length == 0)
            {
                info.Menu.Items.Remove(previewRoot); // Ausblenden in der harten Art
            }
            foreach (var prev in previewables)
            {
                var itm = previewRoot.CreateItem(prev.DisplayName);
                itm.Enabled = false;
                itm.Click  += (s, ev) => prev.Show(info);
            }

            dialogs = info.GetRegistered <IEditingDialog>();
            if (dialogs.Length > 0)
            {
                editRoot.Items.Add(new SeparatorMenuItem());
            }

            dialogOffset = editRoot.Items.Count;
            foreach (var dialog in dialogs)
            {
                var itm = editRoot.CreateItem(dialog.DisplayName);
                itm.Enabled = dialog.IsEnabled(info);
                itm.Click  += (s, ev) => dialog.Show(info);
            }

            hasFilterables = info.GetRegistered <IFilterableUi>().Length > 0;
            hasDesignables = info.GetRegistered <IDesignableUiProxy>().Length > 0;
        }
コード例 #3
0
        public TimetableCheckRunner(IInfo info)
        {
            var checks = info.GetRegistered <ITimetableCheck>();

            info.FileStateChanged += (s, e) =>
            {
                if (info.Timetable == null)
                {
                    return;
                }

                var list = new List <string>();

                foreach (var check in checks)
                {
                    list.AddRange(check.Check(info.Timetable));
                }

                if (list.Any() && form == null)
                {
                    GetForm().Show();
                }
                if (gridView != null)
                {
                    gridView.DataStore = list;
                }
            };
        }
コード例 #4
0
#pragma warning restore CS0649

        public FilterForm(IInfo info)
        {
            Eto.Serialization.Xaml.XamlReader.Load(this);

            this.info = info;
            var tt = info.Timetable;

            var filterables = info.GetRegistered <IFilterableUi>();

            fcontainers = filterables.Select(f => new FilterableContainer()
            {
                Filterable   = f,
                StationRules = f.LoadStationRules(tt),
                TrainRules   = f.LoadTrainRules(tt),
            }).ToArray();

            typeListBox.Items.AddRange(filterables.Select(f => new ListItem()
            {
                Text = f.DisplayName
            }));
            typeListBox.SelectedIndexChanged += listBox1_SelectedIndexChanged;

            InitView(trainPattListView);
            InitView(stationPattListView);

            if (fcontainers.Length == 0)
            {
                return;
            }
            SwitchType(0);
            typeListBox.SelectedIndex = 0;

            this.AddSizeStateHandler();
        }
コード例 #5
0
ファイル: XMLImport.cs プロジェクト: fadoe/FPLedit
        public Timetable Import(string filename, IInfo info, ILog replaceLog = null)
        {
            try
            {
                XElement el = XElement.Load(filename);

                XMLEntity en = new XMLEntity(el);
                var       tt = new Timetable(en);

                var actions = info.GetRegistered <ITimetableInitAction>();
                foreach (var action in actions)
                {
                    var message = action.Init(tt);
                    if (message != null)
                    {
                        info.Logger.Warning(message);
                    }
                }

                return(tt);
            }
            catch (Exception ex)
            {
                var log = replaceLog ?? info.Logger;
                log.Error("XMLImporter: " + ex.Message);
                return(null);
            }
        }
コード例 #6
0
        public DesignableForm(IInfo info) : this()
        {
            this.info = info;

            var designables = info.GetRegistered <IDesignableUiProxy>();

            tabControl.SuspendLayout();
            tabControl.Pages.Clear();

            foreach (var d in designables)
            {
                var c  = d.GetControl(info);
                var tp = new TabPage(c)
                {
                    Text = d.DisplayName
                };
                c.BackgroundColor = tp.BackgroundColor;
                tabControl.Pages.Add(tp);

                if (c is ISaveHandler sh)
                {
                    saveHandlers.Add(sh);
                }
                if (c is IExpertHandler eh)
                {
                    expertHandlers.Add(eh);
                }
            }

            tabControl.ResumeLayout();

            expertCheckBox.Checked         = info.Settings.Get <bool>("std.expert");
            expertCheckBox.CheckedChanged += ExpertCheckBox_CheckedChanged;
            ExpertCheckBox_CheckedChanged(this, null);
        }
コード例 #7
0
ファイル: NetworkExport.cs プロジェクト: fadoe/FPLedit
        public bool Export(Timetable tt, string filename, IInfo info)
        {
            if (tt.Type == TimetableType.Network)
            {
                throw new Exception("Der Fahrplan ist bereits ein Netzwerk-Fahrplan");
            }

            var clone = tt.Clone();

            var trainPaths = new Dictionary <Train, TrainPathData>();

            foreach (var orig in clone.Trains)
            {
                trainPaths[orig] = new TrainPathData(clone, orig);
            }

            var rt = Timetable.LINEAR_ROUTE_ID.ToString();
            var id = 0;
            var y  = 0;

            foreach (var sta in clone.Stations)
            {
                ConvertStationLinToNet(sta);

                sta.SetAttribute("fpl-rt", rt);
                sta.SetAttribute("fpl-pos", (y += 40).ToString() + ";0");
                sta.SetAttribute("fpl-id", id++.ToString());
            }

            var actions = info.GetRegistered <ITimetableTypeChangeAction>();

            foreach (var action in actions)
            {
                action.ToNetwork(clone);
            }

            clone.SetAttribute("version", TimetableVersion.Extended_FPL.ToNumberString());

            foreach (var train in clone.Trains)
            {
                var data = trainPaths[train];

                train.Children.Clear();
                train.AddAllArrDeps(data.GetRawPath());
                train.XMLEntity.XName = "tr";

                foreach (var sta in data.PathEntries)
                {
                    if (sta.ArrDep != null)
                    {
                        train.GetArrDep(sta.Station).ApplyCopy(sta.ArrDep);
                    }
                }
            }

            ColorTimetableConverter.ConvertAll(clone);

            return(new XMLExport().Export(clone, filename, info));
        }
コード例 #8
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);
        }
コード例 #9
0
        public bool Export(Timetable tt, string filename, IInfo info)
        {
            if (tt.Type == TimetableType.Linear)
            {
                throw new Exception("Der Fahrplan ist bereits ein Linear-Fahrplan");
            }
            if (tt.GetRoutes().Count() != 1)
            {
                throw new Exception("Der Fahrplan hat mehr als eine oder keine Strecke");
            }

            var clone = tt.Clone();

            var trainPaths = new Dictionary <Train, TrainPathData>();

            foreach (var orig in clone.Trains)
            {
                trainPaths[orig] = new TrainPathData(clone, orig);
            }

            var route = clone.GetRoutes().FirstOrDefault().Index;

            foreach (var sta in clone.Stations)
            {
                ConvertStationNetToLin(sta, route, Timetable.DefaultLinearVersion);

                sta.RemoveAttribute("fpl-rt");
                sta.RemoveAttribute("fpl-pos");
                sta.RemoveAttribute("fpl-id");
            }

            var actions = info.GetRegistered <ITimetableTypeChangeAction>();

            foreach (var action in actions)
            {
                action.ToLinear(clone);
            }

            clone.SetAttribute("version", Timetable.DefaultLinearVersion.ToNumberString());

            var sortedStations = clone.GetRoutes()[Timetable.LINEAR_ROUTE_ID].GetOrderedStations();

            foreach (var t in clone.Trains)
            {
                var data = trainPaths[t];

                var sta1 = data.PathEntries.FirstOrDefault()?.Station;
                var sta2 = data.PathEntries.LastOrDefault()?.Station;

                var dir = TrainDirection.ti;
                if (sta1 != sta2)
                {
                    if (sortedStations.IndexOf(sta1) > sortedStations.IndexOf(sta2))
                    {
                        dir = TrainDirection.ta;
                    }
                }
                else if (sortedStations.IndexOf(sta1) == sortedStations.Count - 1)
                {
                    dir = TrainDirection.ta;
                }

                t.XMLEntity.XName = dir.ToString();

                t.Children.Clear();
                t.AddLinearArrDeps();

                foreach (var sta in data.PathEntries)
                {
                    if (sta.ArrDep != null)
                    {
                        t.GetArrDep(sta.Station).ApplyCopy(sta.ArrDep);
                    }
                }
            }

            ColorTimetableConverter.ConvertAll(clone);

            return(new XMLExport().Export(clone, filename, info));
        }