Exemplo n.º 1
0
        /// <summary>
        /// Hilfetext für Optionen ausgeben
        /// </summary>
        /// <param name="cmd"></param>
        public void ShowHelp()
        {
            Console.Error.WriteLine("GpxTool[Optionen] gpx - input...");

            List <string> help = cmd.GetHelpText();

            for (int i = 0; i < help.Count; i++)
            {
                Console.Error.WriteLine(help[i]);
            }
            Console.Error.WriteLine();
            Console.Error.WriteLine("Zusatzinfos:");

            Console.Error.WriteLine("Für '--' darf auch '/' stehen und für '=' Leerzeichen oder ':'.");

            // ...

            if (File.Exists("gpxtool.html"))
            {
                CmdlineOptions.ShowHtmlfile("gpxtool.html");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Auswertung der Optionen
        /// </summary>
        /// <param name="args"></param>
        public void Evaluate(string[] args)
        {
            if (args == null)
            {
                return;
            }
            List <string> NewTrackName_Tmp = new List <string>();

            try {
                cmd.Parse(args);

                foreach (MyOptions opt in Enum.GetValues(typeof(MyOptions)))  // jede denkbare Option testen
                {
                    int optcount = cmd.OptionAssignment((int)opt);            // Wie oft wurde diese Option verwendet?
                    if (optcount > 0)
                    {
                        switch (opt)
                        {
                        case MyOptions.ShowInfo:
                            ShowInfo = GetBoolDefTrue(opt);
                            break;

                        case MyOptions.InputWithSubdirs:
                            InputWithSubdirs = GetBoolDefTrue(opt);
                            break;

                        case MyOptions.NewTrackName:
                            for (int i = 0; i < optcount; i++)
                            {
                                NewTrackName_Tmp.Add(cmd.StringValue((int)opt, i));
                            }
                            break;

                        case MyOptions.OutputOverwrite:
                            OutputOverwrite = GetBoolDefTrue(opt);
                            break;

                        case MyOptions.SimplifyGPX:
                            SimplifyGPX = GetBoolDefTrue(opt);
                            break;

                        case MyOptions.FormatedOutput:
                            FormatedOutput = GetBoolDefTrue(opt);
                            break;

                        case MyOptions.Outputfile:
                            Outputfile = cmd.StringValue((int)opt);
                            break;

                        case MyOptions.HeightOutputfile:
                            HeightOutputfile = cmd.StringValue((int)opt);
                            break;

                        case MyOptions.Output4Tracks:
                            Output4Tracks = GetIndexArray(cmd.StringValue((int)opt));
                            break;

                        case MyOptions.Segment2Track:
                            Segment2Track = GetBoolDefTrue(opt);
                            break;

                        case MyOptions.DeleteTimestamp:
                            DeleteTimestamp = GetBoolDefTrue(opt);
                            break;

                        case MyOptions.DeleteHeight:
                            DeleteHeight = GetBoolDefTrue(opt);
                            break;

                        case MyOptions.ConstantHeight:
                            ConstantHeight = cmd.DoubleValue((int)opt);
                            break;

                        case MyOptions.GapFill:
                            GapFill = GetBoolDefTrue(opt);
                            break;

                        case MyOptions.HorizontalSimplification: {
                            string tmp = null;
                            if (cmd.ArgIsUsed((int)opt))
                            {
                                tmp = cmd.StringValue((int)opt).ToUpper();
                            }
                            if (string.IsNullOrEmpty(tmp) ||
                                tmp == "DP" ||
                                tmp == "Douglas-Peucker")
                            {
                                HorizontalSimplification = HSimplification.Douglas_Peucker;
                            }
                            else if (tmp == "RW" ||
                                     tmp == "Reumann-Witkam")
                            {
                                HorizontalSimplification = HSimplification.Reumann_Witkam;
                            }
                            else
                            {
                                throw new Exception("Unbekannter Typ: " + tmp);
                            }
                        }
                        break;

                        case MyOptions.HorizontalWidth:
                            HorizontalWidth = cmd.PositivDoubleValue((int)opt);
                            break;

                        case MyOptions.HorizontalMaxSpeed:
                            HorizontalMaxSpeed = cmd.PositivDoubleValue((int)opt);
                            break;

                        case MyOptions.HorizontalRestArea:
                            HorizontalRestArea = GetParaArray(cmd.StringValue((int)opt));
                            break;

                        case MyOptions.HorizontalRestAreaProt:
                            HorizontalRestAreaProt = cmd.StringValue((int)opt);
                            break;

                        case MyOptions.MinHeight:
                            MinHeight = cmd.DoubleValue((int)opt);
                            break;

                        case MyOptions.MaxHeight:
                            MaxHeight = cmd.DoubleValue((int)opt);
                            break;

                        case MyOptions.VerticalSimplification: {
                            string tmp = null;
                            if (cmd.ArgIsUsed((int)opt))
                            {
                                tmp = cmd.StringValue((int)opt).ToUpper();
                            }
                            if (string.IsNullOrEmpty(tmp) ||
                                tmp == "SI" ||
                                tmp == "SlidingIntegral")
                            {
                                VerticalSimplification = VSimplification.SlidingIntegral;
                            }
                            else if (tmp == "SM" ||
                                     tmp == "SlidingMean")
                            {
                                VerticalSimplification = VSimplification.SlidingMean;
                            }
                            else
                            {
                                throw new Exception("Unbekannter Typ: " + tmp);
                            }
                        }
                        break;

                        case MyOptions.VerticalWidth:
                            VerticalWidth = cmd.PositivDoubleValue((int)opt);
                            break;

                        case MyOptions.VerticalOutlierWidth:
                            VerticalOutlierWidth = cmd.UnsignedDoubleValue((int)opt);
                            break;

                        case MyOptions.MaxAscent:
                            MaxAscent = cmd.PositivDoubleValue((int)opt);
                            break;

                        case MyOptions.Output4Routes:
                            Output4Routes = GetIndexArray(cmd.StringValue((int)opt));
                            break;

                        case MyOptions.Output4Waypoints:
                            Output4Waypoints = GetIndexArray(cmd.StringValue((int)opt));
                            break;

                        case MyOptions.Filename2TrackName:
                            Filename2TrackName = GetBoolDefTrue(opt);
                            break;

                        case MyOptions.OneFilePerTrack:
                            OneFilePerTrack = GetBoolDefTrue(opt);
                            break;

                        case MyOptions.KmlTrackData:
                            KmlTrackdata = ReadKmlTrackDataList(cmd.StringValue((int)opt));
                            break;

                        case MyOptions.Help:
                            ShowHelp();
                            break;
                        }
                    }
                }

                Console.Error.WriteLine(cmd);

                Inputfiles = new List <string>();
                foreach (string item in cmd.Parameters)
                {
                    Inputfiles.AddRange(CmdlineOptions.WildcardExpansion4Files(item));
                }

                Console.Error.WriteLine(Inputfiles.Count);



                //if (cmd.Parameters.Count > 0)
                //   throw new Exception("Es sind keine Argumente sondern nur Optionen erlaubt.");

                NewTrackName = new string[NewTrackName_Tmp.Count];
                NewTrackName_Tmp.CopyTo(NewTrackName);

                if (VerticalSimplification != VSimplification.Nothing)
                {
                    GapFill = true;
                }
                else
                {
                    VerticalOutlierWidth = 0;
                }

                if (GapFill)
                {
                    DeleteHeight    = false;
                    DeleteTimestamp = false;
                }

                if (MinHeight > MaxHeight)
                {
                    MaxHeight = double.MaxValue;
                }

                if (ConstantHeight != double.MinValue)
                {
                    DeleteHeight = false;
                }
            } catch (Exception ex) {
                Console.Error.WriteLine(ex.Message);
                ShowHelp();
                throw new Exception("Fehler beim Ermitteln oder Anwenden der Programmoptionen.");
            }
        }
Exemplo n.º 3
0
        public Options()
        {
            try {
                cmd = new CmdlineOptions();

                // Definition der Optionen
                ShowInfo = true;
                cmd.DefineOption((int)MyOptions.ShowInfo, "info", "i", "Ausgabe von Waypoint-, Routen-, Track- und Segment-Infos auf STDOUT (Name, Länge usw.)" + System.Environment.NewLine +
                                 "(Standard: true)", CmdlineOptions.OptionArgumentType.BooleanOrNothing);
                InputWithSubdirs = false;
                cmd.DefineOption((int)MyOptions.InputWithSubdirs, "withsubdirs", "", "bei Verwendung von * oder ? werden Eingabedateien auch in Unterverzeichnissen gesucht", CmdlineOptions.OptionArgumentType.BooleanOrNothing);

                Outputfile = "";
                cmd.DefineOption((int)MyOptions.Outputfile, "output", "o", "Name der Ausgabedatei für die (ev. veränderten) GPX-Daten", CmdlineOptions.OptionArgumentType.String);
                OutputOverwrite = false;
                cmd.DefineOption((int)MyOptions.OutputOverwrite, "overwrite", "", "eine ev. schon vorhandene GPX-Datei darf überschrieben werden (ohne arg 'true', Standard 'false')", CmdlineOptions.OptionArgumentType.BooleanOrNothing);
                FormatedOutput = true;
                cmd.DefineOption((int)MyOptions.FormatedOutput, "formated", "f", "Ausgabe formatiert oder '1-zeilig' (ohne arg 'true', Standard: 'false')", CmdlineOptions.OptionArgumentType.BooleanOrNothing);
                SimplifyGPX = false;
                cmd.DefineOption((int)MyOptions.SimplifyGPX, "simplifygpx", "", "GPX-Datei vereinfachen (ohne arg 'true', Standard: 'false', bei mehreren Dateien immer true)", CmdlineOptions.OptionArgumentType.BooleanOrNothing);

                NewTrackName = new string[0];
                cmd.DefineOption((int)MyOptions.NewTrackName, "name", "n", "neuer Trackname (mehrfach verwendbar für Track 1 usw.)", CmdlineOptions.OptionArgumentType.String, int.MaxValue);

                HeightOutputfile = "";
                cmd.DefineOption((int)MyOptions.HeightOutputfile, "heightoutput", "O", "Name der Ausgabedatei für die (ev. veränderten) Höhen-Daten in Abhängigkeit" + System.Environment.NewLine +
                                 "der jeweiligen Tracklänge", CmdlineOptions.OptionArgumentType.String);
                Output4Tracks = null;
                cmd.DefineOption((int)MyOptions.Output4Tracks, "tracks", "t", "Liste (mit Komma) der zu verwendenden Tracknummern (1, ...) (Standard: alle)", CmdlineOptions.OptionArgumentType.String);
                Output4Routes = null;
                cmd.DefineOption((int)MyOptions.Output4Routes, "routes", "r", "Liste (mit Komma) der zu verwendenden Routennummern (1, ...) (Standard: alle)", CmdlineOptions.OptionArgumentType.String);
                Output4Waypoints = null;
                cmd.DefineOption((int)MyOptions.Output4Waypoints, "waypoints", "p", "Liste (mit Komma) der zu verwendenden Waypoints (1, ...) (Standard: alle)", CmdlineOptions.OptionArgumentType.String);

                Segment2Track = false;
                cmd.DefineOption((int)MyOptions.Segment2Track, "segment2track", "", "zusätzliche Segmente in eigene Tracks umwandeln (ohne arg 'true', Standard: 'false')", CmdlineOptions.OptionArgumentType.BooleanOrNothing);

                DeleteTimestamp = false;
                cmd.DefineOption((int)MyOptions.DeleteTimestamp, "deletetime", "", "alle Zeitstempel werden aus den Trackpunkten entfernt (ohne arg 'true', Standard: 'false')", CmdlineOptions.OptionArgumentType.BooleanOrNothing);
                DeleteHeight = false;
                cmd.DefineOption((int)MyOptions.DeleteHeight, "deleteheight", "", "alle Höhenangaben werden aus den Trackpunkten entfernt (ohne arg 'true', Standard: 'false')", CmdlineOptions.OptionArgumentType.BooleanOrNothing);
                ConstantHeight = double.MinValue;
                cmd.DefineOption((int)MyOptions.ConstantHeight, "newheigth", "N", "alle Höhen werden in den Trackpunkten auf einen konstanten Wert gesetzt", CmdlineOptions.OptionArgumentType.Double);
                GapFill = false;
                cmd.DefineOption((int)MyOptions.GapFill, "gapfill", "G", "fehlende Höhenwerte und Zeitstempel linear interpolieren  (ohne arg 'true', Standard: 'false')", CmdlineOptions.OptionArgumentType.BooleanOrNothing);

                HorizontalSimplification = HSimplification.Nothing;
                cmd.DefineOption((int)MyOptions.HorizontalSimplification, "simplify", "s", "Vereinfachung der Tracks [mit Algorithmus Reumann-Witkam (RW) oder Douglas-Peucker (DP)]" + System.Environment.NewLine +
                                 "(Standard: keine)", CmdlineOptions.OptionArgumentType.StringOrNothing);
                HorizontalWidth = 0.05;
                cmd.DefineOption((int)MyOptions.HorizontalWidth, "width", "w", "Breite des Toleranzbereiches für die Vereinfachung (Standard 0.05)", CmdlineOptions.OptionArgumentType.PositivDouble);
                HorizontalMaxSpeed = 0;
                cmd.DefineOption((int)MyOptions.HorizontalMaxSpeed, "maxspeed", "m", "Punkte entfernen, die mit einer höheren Geschwindigkeit in km/h erreicht werden" + System.Environment.NewLine +
                                 "(Standard: inaktiv)", CmdlineOptions.OptionArgumentType.PositivDouble);
                HorizontalRestArea = null;
                cmd.DefineOption((int)MyOptions.HorizontalRestArea, "restarea", "a", "Werteliste (mit Komma) für die Pausenplatzeliminierung, z.B. 10,1,20,60,2,25,50" + System.Environment.NewLine +
                                 "(Standard: inaktiv)", CmdlineOptions.OptionArgumentType.String);
                HorizontalRestAreaProt = null;
                cmd.DefineOption((int)MyOptions.HorizontalRestAreaProt, "restareaprot", "", "Name der Protokolldatei für die Pausenplatzeliminierung", CmdlineOptions.OptionArgumentType.String);

                MinHeight = double.MinValue;
                cmd.DefineOption((int)MyOptions.MinHeight, "minheight", "", "Minimalhöhe; alle kleineren Höhen werden damit ersetzt", CmdlineOptions.OptionArgumentType.Double);
                MaxHeight = double.MaxValue;
                cmd.DefineOption((int)MyOptions.MaxHeight, "maxheight", "", "Maximalhöhe; alle größeren Höhen werden damit ersetzt", CmdlineOptions.OptionArgumentType.Double);

                VerticalSimplification = VSimplification.Nothing;
                cmd.DefineOption((int)MyOptions.VerticalSimplification, "heightsimplify", "S", "Höhenprofil vereinfachen [mit Algorithmus SlidingIntegral (SI) oder SlidingMean (SM)]" + System.Environment.NewLine +
                                 "(Standard: keine)", CmdlineOptions.OptionArgumentType.StringOrNothing);
                VerticalWidth = 100;
                cmd.DefineOption((int)MyOptions.VerticalWidth, "heightwidth", "W", "Breite des Höhen-Integrationsbereiches in Metern (Standard 100m)", CmdlineOptions.OptionArgumentType.PositivDouble);
                VerticalOutlierWidth = 50;
                cmd.DefineOption((int)MyOptions.VerticalOutlierWidth, "heightoutlierwidth", "U", "Länge des Bereiches für die 'Ausreißer'-Korrektur von Höhen (Standard 50m)", CmdlineOptions.OptionArgumentType.UnsignedDouble);
                MaxAscent = 25;
                cmd.DefineOption((int)MyOptions.MaxAscent, "maxascent", "A", "max. gültiger An-/Abstieg in Prozent (Standard 25%)", CmdlineOptions.OptionArgumentType.PositivDouble);
                Filename2TrackName = false;
                cmd.DefineOption((int)MyOptions.Filename2TrackName, "filenametotrackname", "", "Tracknamen auf den Dateinamen setzen (Standard: false)", CmdlineOptions.OptionArgumentType.BooleanOrNothing);
                OneFilePerTrack = false;
                cmd.DefineOption((int)MyOptions.OneFilePerTrack, "onefilepertrack", "", "jeden Track in einer eigenen Datei ausgeben (Standard: false)", CmdlineOptions.OptionArgumentType.BooleanOrNothing);

                KmlTrackdata = new List <KmlTrackData>();
                cmd.DefineOption((int)MyOptions.KmlTrackData, "kmltrackdata", "", "Farbe und Linienbreite für jeden Track bei KML-Ausgabe (Liste aus jeweils ARGB/RGB-Farbe und Breite)", CmdlineOptions.OptionArgumentType.String);


                cmd.DefineOption((int)MyOptions.Help, "help", "?", "diese Hilfe", CmdlineOptions.OptionArgumentType.Nothing);
            } catch (Exception ex) {
                Console.Error.WriteLine(ex.Message);
            }
        }