private KmlMultipleFileExporterProperties GetPropertiesFromControls()
        {
            var p = new KmlMultipleFileExporterProperties();

              // include routes
              p.IncludeRoutes = includeRoutes.Checked;

              // include replay
              p.IncludeReplay = includeReplay.Checked;

              // mass start
              p.MassStart = massStart.Checked;

              // tails
              var tails = new List<KmlReplayTail>();
              if (replayTailsVisible.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;
            }
            tails.Add(tail);
              }
              p.ReplayTails = tails;

              // replay time interval
              double timeInterval;
              if (double.TryParse(replayTimeInterval.Text, out timeInterval))
              {
            timeInterval = Math.Max(0.1, Math.Min(3600, timeInterval));
            p.ReplayTimeInterval = new TimeSpan((long)(timeInterval * TimeSpan.TicksPerSecond));
              }
              else
              {
            p.ReplayTimeInterval = originalMultipleFileProperties.ReplayTimeInterval;
              }

              // restart after each lap
              p.ReplayRestartAfterEachLap = replayRestartAfterEachLap.Checked;

              // opacity
              var opacity = (originalMultipleFileProperties.Colors.Count > 0 ? (double)originalMultipleFileProperties.Colors[0].A / 255 : 1.0);
              for (var i = 0; i < originalMultipleFileProperties.Colors.Count; i++)
              {
            p.Colors[i] = Color.FromArgb((int)(255 * opacity), p.Colors[i]);
              }

              // route line width
              p.RouteLineWidth = originalMultipleFileProperties.RouteLineWidth;

              return p;
        }
 public OpenMultipleFilesInGoogleEarthDialog(IEnumerable<string> initialFileNames, KmlMultipleFileExporterProperties multipleFileProperties)
     : this()
 {
     updatingUINow = true;
       fileSelector.FileDialogTitle = Strings.AddFiles;
       fileSelector.FileDialogFilter = Strings.FileFilter_AllQuickRouteFiles + "|" + Strings.FileFilter_QuickRouteFiles + "|" + Strings.FileFilter_QuickRoute10Files + "|" + Strings.FileFilter_JpegFilesExportedFromQuickRoute;
       fileSelector.FileDialogFilterIndex = 1;
       fileSelector.AddFiles(initialFileNames);
       originalMultipleFileProperties = (KmlMultipleFileExporterProperties)multipleFileProperties.Clone();
       SetPropertiesToControls(originalMultipleFileProperties);
       updatingUINow = false;
       UpdateUI();
 }
        public object Clone()
        {
            var clone = new KmlMultipleFileExporterProperties
            {
                IncludeRoutes        = IncludeRoutes,
                IncludeReplay        = IncludeReplay,
                MassStart            = MassStart,
                CompactRouteSegments = CompactRouteSegments,
                Colors                    = new List <Color>(Colors),
                ReplayTimeInterval        = ReplayTimeInterval,
                RouteLineWidth            = RouteLineWidth,
                ReplayTails               = new List <KmlReplayTail>(),
                ReplayRestartAfterEachLap = ReplayRestartAfterEachLap
            };

            foreach (var tail in ReplayTails)
            {
                clone.ReplayTails.Add(tail.Clone() as KmlReplayTail);
            }
            return(clone);
        }
 private void SetPropertiesToControls(KmlMultipleFileExporterProperties p)
 {
     updatingUINow = true;
       includeRoutes.Checked = p.IncludeRoutes;
       includeReplay.Checked = p.IncludeReplay;
       massStart.Checked = p.MassStart;
       replayTailsVisible.Checked = p.HasReplayTails;
       if (p.HasReplayTails)
       {
     replayTailDuration.Text = (p.ReplayTails[0].EndVisible.HasValue
                                 ? p.ReplayTails[0].EndVisible.Value.TotalSeconds.ToString()
                                 : Strings.Infinite);
       }
       replayTimeInterval.Text = p.ReplayTimeInterval.TotalSeconds.ToString();
       replayRestartAfterEachLap.Checked = p.ReplayRestartAfterEachLap;
       updatingUINow = false;
 }
        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;
                        }
                    }
                }
            }
        }
        public object Clone()
        {
            var clone = new KmlMultipleFileExporterProperties
                    {
                      IncludeRoutes = IncludeRoutes,
                      IncludeReplay = IncludeReplay,
                      MassStart = MassStart,
                      CompactRouteSegments = CompactRouteSegments,
                      Colors = new List<Color>(Colors),
                      ReplayTimeInterval = ReplayTimeInterval,
                      RouteLineWidth = RouteLineWidth,
                      ReplayTails = new List<KmlReplayTail>(),
                      ReplayRestartAfterEachLap = ReplayRestartAfterEachLap
                    };

              foreach (var tail in ReplayTails)
              {
            clone.ReplayTails.Add(tail.Clone() as KmlReplayTail);
              }
              return clone;
        }
        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;
            }
              }
            }
              }
        }