Example #1
0
        private void CalculateLapInfo()
        {
            Session s = canvas.CurrentSession;
              if (s == null) return;
              Route r = s.Route;
              ParameterizedLocation previousLapPL = ParameterizedLocation.Start;

              lapInfoList = new List<LapInfo>();
              for (int i = 0; i < s.Laps.Count; i++)
              {
            Lap lap = s.Laps[i];
            ParameterizedLocation lapPL = r.GetParameterizedLocationFromTime(lap.Time, previousLapPL, ParameterizedLocation.Direction.Forward);
            if (lap.LapType != LapType.Start && i > 0)
            {
              var li = new LapInfo { LapType = lap.LapType, Index = i };

              var locations = new RouteLocations(previousLapPL, lapPL);

              foreach (var lpType in ApplicationSettings.LapPropertyTypes)
              {
            if (lpType.Selected)
            {
              RetrieveExternalPropertyDelegate dlg = new ExternalRoutePropertyRetriever(s.Settings).RetrieveExternalProperty;
              var lp = Activator.CreateInstance(lpType.RoutePropertyType, s, locations, dlg) as RouteProperty;
              li.AddProperty(lp);
            }
              }

              if (s.Laps.Count > 2)
              {
            lapInfoList.Add(li);
              }
            }
            previousLapPL = lapPL;
              }

              // total row
              var totalInfo = new LapInfo() { LapType = LapType.Stop, Index = -1 };
              foreach (var lpType in ApplicationSettings.LapPropertyTypes)
              {
            if (lpType.Selected)
            {
              // create route span property object
              var routeSpanProperty =
            Activator.CreateInstance(lpType.RoutePropertyType, s, new RouteLocations(ParameterizedLocation.Start), null) as
            RouteSpanProperty;
              if (routeSpanProperty != null)
              {
            // get the route from start property type for this object
            Type routeFromStartPropertyType = routeSpanProperty.GetRouteFromStartPropertyType();
            // create an instance of that type
            RetrieveExternalPropertyDelegate dlg = new ExternalRoutePropertyRetriever(s.Settings).RetrieveExternalProperty;
            var routeFromStartProperty =
              Activator.CreateInstance(routeFromStartPropertyType, s, new RouteLocations(r.LastPL), dlg) as
              RouteFromStartProperty;
            if (routeFromStartProperty == null)
            {
              // no matching route from start property, add blank column
              totalInfo.AddProperty(new BlankRouteProperty());
            }
            else
            {
              totalInfo.AddProperty(routeFromStartProperty);
            }
              }
              else
              {
            RetrieveExternalPropertyDelegate dlg = new ExternalRoutePropertyRetriever(s.Settings).RetrieveExternalProperty;
            var routeFromStartProperty =
              Activator.CreateInstance(lpType.RoutePropertyType, s, new RouteLocations(r.LastPL), dlg) as
              RouteFromStartProperty;
            if (routeFromStartProperty == null)
            {
              // no matching route from start property, add blank column
              totalInfo.AddProperty(new BlankRouteProperty());
            }
            else
            {
              totalInfo.AddProperty(routeFromStartProperty);
            }
              }
            }
              }
              lapInfoList.Add(totalInfo);

              // set number of rows and columns in grid
              updatingUINowCounter++;
              laps.RowCount = 0;
              laps.ColumnCount = 0;
              laps.RowCount = lapInfoList.Count;
              laps.ColumnCount = (lapInfoList.Count == 0 ? 0 : lapInfoList[0].GetProperties().Count);
              updatingUINowCounter--;
              SetLapGridHeaders();
              SortLapGrid();
              laps.Invalidate();

              updatingUINowCounter -= 100; // ugly!
              laps.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
              updatingUINowCounter += 100; // ugly!

              if (laps.Rows.Count > 0)
              {
            updatingUINowCounter++;
            laps.Rows[laps.Rows.Count - 1].Selected = true;
            updatingUINowCounter--;
              }
              int width = 0;
              foreach (DataGridViewColumn c in laps.Columns)
              {
            width += c.Width;
              }

              updatingUINowCounter++;
              rightPanel.Width = width + laps.Margin.Horizontal;
              updatingUINowCounter--;
        }
Example #2
0
        private void CalculateMomentaneousInfoLabelRectangles()
        {
            momentaneousInfoLabelRectangles = new Dictionary<Type, Rectangle>();
              if (canvas.Document == null) return;

              // calculate size and locations of labels
              Route r = canvas.CurrentSession.Route;
              var noOfRows = 0;
              var xPos = momentaneousInfoPanel.Padding.Left;
              var rowHeight = 0;
              foreach (var selectableRoutePropertyType in ApplicationSettings.MomentaneousInfoPropertyTypes)
              {
            if (selectableRoutePropertyType.Selected)
            {
              RetrieveExternalPropertyDelegate dlg = new ExternalRoutePropertyRetriever(canvas.CurrentSession.Settings).RetrieveExternalProperty;
              var property = Activator.CreateInstance(selectableRoutePropertyType.RoutePropertyType, canvas.CurrentSession, new RouteLocations(r.FirstPL), dlg) as RouteProperty;
              if (property != null && property.ContainsValue)
              {
            var templateString = Strings.ResourceManager.GetString("RoutePropertyNameAndValue_" +
                                                                   property.GetType().Name)
                                 ??
                                 property.GetType().Name + ": {0}";
            var maxWidthString = string.Format(templateString, property.MaxWidthString);
            var label = new Rectangle()
                          {
                            Size = TextRenderer.MeasureText(maxWidthString, momentaneousInfoPanel.Font)
                          };

            if (rowHeight == 0) rowHeight = label.Size.Height + momentaneousInfoLabelPadding.Vertical;
            if (xPos + label.Size.Width + momentaneousInfoLabelPadding.Horizontal + momentaneousInfoPanel.Padding.Right >
                momentaneousInfoPanel.Width)
            {
              // new row needed
              noOfRows++;
              xPos = momentaneousInfoPanel.Padding.Left;
            }
            label.Location = new Point(xPos + momentaneousInfoLabelPadding.Left,
                                       noOfRows * rowHeight + momentaneousInfoLabelPadding.Top +
                                       momentaneousInfoPanel.Padding.Top);
            xPos += label.Size.Width + momentaneousInfoLabelPadding.Horizontal;
            momentaneousInfoLabelRectangles.Add(selectableRoutePropertyType.RoutePropertyType, label);
              }
            }
              }
              momentaneousInfoPanel.Visible = true;
              momentaneousInfoPanel.Height = Math.Max((noOfRows + 1) * (rowHeight == 0 ? 20 : rowHeight) + momentaneousInfoPanel.Padding.Vertical, 1);
              UpdateMomentaneousInfo(null);
        }
Example #3
0
        private void UpdateMomentaneousInfo(ParameterizedLocation pl)
        {
            // TODO: backbuffering?
              // TODO: toolstrip back color? At least some sort of top line that separates it from above

              var g = momentaneousInfoPanelBackBufferGraphics;

              g.Clear(momentaneousInfoPanel.BackColor);
              g.TextRenderingHint = TextRenderingHint.AntiAlias;
              var lightPen = new Pen(SystemColors.ControlLight, 1F);
              var darkPen = new Pen(SystemColors.ControlDark, 1F);

              g.DrawLine(darkPen, 0, 0, momentaneousInfoPanelBackBuffer.Width - 1, 0);

              if (pl != null)
              {
            Route r = canvas.CurrentSession.Route;
            var lapStartPL = r.GetLapStartParameterizedLocation(pl);
            foreach (var selectableRoutePropertyType in ApplicationSettings.MomentaneousInfoPropertyTypes)
            {
              if (selectableRoutePropertyType.Selected)
              {
            RetrieveExternalPropertyDelegate dlg = new ExternalRoutePropertyRetriever(canvas.CurrentSession.Settings).RetrieveExternalProperty;
            var property =
              Activator.CreateInstance(selectableRoutePropertyType.RoutePropertyType, canvas.CurrentSession, new RouteLocations(lapStartPL, pl), dlg) as
              RouteProperty;
            if (property != null )
            {
              var templateString = Strings.ResourceManager.GetString("RoutePropertyNameAndValue_" +
                                                                     property.GetType().Name)
                                   ??
                                   property.GetType().Name + ": {0}";
              var text = property.Value != null
                           ? string.Format(templateString, property)
                           : string.Format(templateString, "-");
              if (momentaneousInfoLabelRectangles.ContainsKey(selectableRoutePropertyType.RoutePropertyType)) // this should not be needed, but people seem to have problem with "The given key was not present in the dictionary. (mscorlib)"
              {
                var rect = momentaneousInfoLabelRectangles[selectableRoutePropertyType.RoutePropertyType];

                g.DrawString(text, momentaneousInfoPanel.Font, Brushes.Black, rect.Location);
                // draw separator
                g.DrawLine(lightPen,
                           rect.Right + momentaneousInfoLabelPadding.Right, rect.Top,
                           rect.Right + momentaneousInfoLabelPadding.Right, rect.Bottom);
                g.DrawLine(darkPen,
                           rect.Right + momentaneousInfoLabelPadding.Right + 1, rect.Top,
                           rect.Right + momentaneousInfoLabelPadding.Right + 1, rect.Bottom);
              }
            }
              }
            }
              }
              lightPen.Dispose();
              darkPen.Dispose();
              CopyMomentaneousInfoBackBufferToScreen();
        }