예제 #1
0
        private void SetPropertiesToControls(KmlProperties value)
        {
            includeMap.Checked   = (value.MapType != KmlExportMapType.None);
            includeRoute.Checked = (value.RouteType != KmlExportRouteType.None || value.MapType == KmlExportMapType.MapAndRoute);
            if (value.MapType == KmlExportMapType.MapAndRoute)
            {
                routeLineStyle.SelectedIndex = 0;
            }
            else
            {
                switch (value.RouteType)
                {
                case KmlExportRouteType.Monochrome:
                    routeLineStyle.SelectedIndex = 1;
                    break;

                case KmlExportRouteType.ColorCoded:
                    routeLineStyle.SelectedIndex = 2;
                    break;

                default:
                    routeLineStyle.SelectedIndex = 0;
                    break;
                }
            }
            adaptRouteToMapImage.Checked  = (value.RouteAdaptionStyle != KmlRouteAdaptationStyle.NoAdaption);
            adaptReplayToMapImage.Checked = (value.RouteAdaptionStyle != KmlRouteAdaptationStyle.NoAdaption);

            includeReplay.Checked = (value.ReplayType != KmlExportReplayType.None);
            switch (value.ReplayType)
            {
            case KmlExportReplayType.Monochrome:
                replayMarkerStyle.SelectedIndex = 0;
                break;

            case KmlExportReplayType.ColorCoded:
                replayMarkerStyle.SelectedIndex = 1;
                break;

            default:
                replayMarkerStyle.SelectedIndex = 0;
                break;
            }
            replayTimeInterval.Text   = value.ReplayTimeInterval.TotalSeconds.ToString();
            replayTailVisible.Checked = value.HasReplayTails;
            if (value.HasReplayTails)
            {
                replayTailDuration.Text = (value.ReplayTails[0].EndVisible.HasValue
                                     ? value.ReplayTails[0].EndVisible.Value.TotalSeconds.ToString()
                                     : Strings.Infinite);
            }
            else
            {
                replayTailDuration.Text = "";
            }
        }
예제 #2
0
        public KmlMultipleFilesExporter(IEnumerable <string> fileNames, KmlMultipleFileExporterProperties multipleFileProperties)
        {
            MultipleFileExporterProperties = multipleFileProperties;
            KmlProperties = new KmlProperties()
            {
                MapType            = KmlExportMapType.Map,
                RouteType          = (multipleFileProperties.IncludeRoutes ? KmlExportRouteType.Monochrome : KmlExportRouteType.None),
                ReplayType         = (multipleFileProperties.IncludeReplay ? KmlExportReplayType.Monochrome : KmlExportReplayType.None),
                ReplayTimeInterval = multipleFileProperties.ReplayTimeInterval,
                ReplayTails        = multipleFileProperties.ReplayTails,
                RouteLineStyle     = new KmlLineStyle()
                {
                    Width = multipleFileProperties.RouteLineWidth
                },
                ReplayMarkerStyle = new KmlMarkerStyle()
                {
                    Size = 3 * multipleFileProperties.RouteLineWidth
                }
            };

            var massStartTime          = DateTime.MaxValue;
            var allMapsHaveTheSameSize = true;

            Sessions         = new SessionCollection();
            InvalidFileNames = new List <string>();
            foreach (var fileName in fileNames)
            {
                var d = Document.Open(fileName);
                if (d != null)
                {
                    if (Document == null)
                    {
                        // first file name sets document
                        Document = d;
                    }
                    if (d.Map.Image.Size != Document.Map.Image.Size)
                    {
                        allMapsHaveTheSameSize = false;
                    }
                    var s = d.Sessions[0];
                    if (multipleFileProperties.IncludeReplay && s.Route.FirstWaypoint.Time < massStartTime)
                    {
                        massStartTime = s.Route.FirstWaypoint.Time;
                    }
                    Sessions.Add(s);
                }
                else
                {
                    InvalidFileNames.Add(fileName);
                }
            }
            // if all map images have the same size, then assume that the very same map image is used and adjust the route to the document map
            // otherwise, adjust the route to the individual session map
            // todo: make it possible to choose KmlRouteAdaptationStyle.NoAdjustment in the GUI
            KmlProperties.RouteAdaptionStyle = (allMapsHaveTheSameSize
                                            ? KmlRouteAdaptationStyle.AdaptToDocumentMapImage
                                            : KmlRouteAdaptationStyle.AdaptToSessionMapImage);

            if (multipleFileProperties.IncludeReplay && multipleFileProperties.MassStart)
            {
                // adjust to mass start
                foreach (var s in Sessions)
                {
                    s.AddTimeOffset(massStartTime.Subtract(s.Route.FirstWaypoint.Time));
                }

                // adjust routes to restart after each lap if necessary
                if (multipleFileProperties.ReplayRestartAfterEachLap)
                {
                    var maxTimeDurations = GetMaxLapTimeDurations(Sessions);
                    foreach (var s in Sessions)
                    {
                        Lap previousLap = null;
                        var count       = 0;

                        // 1. Caclulate the durations and place in separate variable (since the session will be altered as time passes by)
                        var durations = new List <TimeSpan>();
                        foreach (var lap in s.Laps)
                        {
                            if (previousLap != null && (lap.LapType == LapType.Lap || lap.LapType == LapType.Stop))
                            {
                                durations.Add(lap.Time - previousLap.Time);
                                count++;
                            }
                            previousLap = lap;
                        }

                        // 2. Add idle time
                        previousLap = null;
                        count       = 0;
                        foreach (var lap in s.Laps)
                        {
                            if (previousLap != null && (lap.LapType == LapType.Lap || lap.LapType == LapType.Stop))
                            {
                                if (durations[count] < maxTimeDurations[count])
                                {
                                    var timeToAdd = maxTimeDurations[count] - durations[count];
                                    s.InsertIdleTime(lap.Time, timeToAdd);
                                }
                                count++;
                            }
                            previousLap = lap;
                        }
                    }
                }
            }
        }
예제 #3
0
 public KmlPropertySelectorDialog(KmlProperties properties)
 {
     InitializeComponent();
     Properties = properties;
 }
예제 #4
0
        private KmlProperties GetPropertiesFromControls()
        {
            var controlProperties = new KmlProperties
            {
                MapType = (includeMap.Checked ? KmlExportMapType.Map : KmlExportMapType.None)
            };

            if (includeRoute.Checked && routeLineStyle.SelectedIndex == 0)
            {
                controlProperties.MapType = KmlExportMapType.MapAndRoute;
            }

            if (!includeRoute.Checked)
            {
                controlProperties.RouteType = KmlExportRouteType.None;
            }
            else
            {
                switch (routeLineStyle.SelectedIndex)
                {
                case 1:
                    controlProperties.RouteType = KmlExportRouteType.Monochrome;
                    break;

                case 2:
                    controlProperties.RouteType = KmlExportRouteType.ColorCoded;
                    break;

                default:
                    controlProperties.RouteType = KmlExportRouteType.None;
                    break;
                }
            }
            controlProperties.RouteAdaptionStyle = includeMap.Checked && adaptRouteToMapImage.Checked
                                               ? KmlRouteAdaptationStyle.AdaptToSessionMapImage
                                               : KmlRouteAdaptationStyle.NoAdaption;

            if (!includeReplay.Checked)
            {
                controlProperties.ReplayType = KmlExportReplayType.None;
            }
            else
            {
                switch (replayMarkerStyle.SelectedIndex)
                {
                case 0:
                    controlProperties.ReplayType = KmlExportReplayType.Monochrome;
                    break;

                case 1:
                    controlProperties.ReplayType = KmlExportReplayType.ColorCoded;
                    break;

                default:
                    controlProperties.ReplayType = KmlExportReplayType.None;
                    break;
                }
                double timeInterval = 1;
                double.TryParse(replayTimeInterval.Text, out timeInterval);
                timeInterval = Math.Max(0.1, Math.Min(3600, timeInterval));
                controlProperties.ReplayTimeInterval = new TimeSpan((long)(timeInterval * TimeSpan.TicksPerSecond));

                var tails = new List <KmlReplayTail>();
                if (replayTailVisible.Checked)
                {
                    var tail = new KmlReplayTail()
                    {
                        StartVisible = new TimeSpan(0)
                    };
                    double tailDurationSeconds = 0;
                    if (double.TryParse(replayTailDuration.Text, out tailDurationSeconds))
                    {
                        tailDurationSeconds = Math.Max(0.1, Math.Min(3600, tailDurationSeconds));
                        tail.EndVisible     = new TimeSpan((long)(tailDurationSeconds * TimeSpan.TicksPerSecond));
                    }
                    else
                    {
                        tail.EndVisible = null; // infinite
                    }
                    tails.Add(tail);
                }
                controlProperties.ReplayTails = tails;
            }

            return(controlProperties);
        }