Added a lot to the doc and modified the pdf generation

This commit is contained in:
2023-06-02 13:41:12 +02:00
parent bef8b9d635
commit a368e02453
113 changed files with 54217 additions and 17276 deletions
+25 -77
View File
@@ -1,8 +1,8 @@
/// Author : Maxime Rohmer
/// Date : 08/05/2023
/// Date : 30/05/2023
/// File : Zone.cs
/// Brief : Class that contains all the methods and infos for a zone. This is designed to be potentially be inherited.
/// Version : 0.1
/// Version : Alpha 1.0
using System;
using System.Collections.Generic;
@@ -11,7 +11,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test_Merge
namespace TrackTrends
{
public class Zone
{
@@ -38,7 +38,7 @@ namespace Test_Merge
set
{
//It automatically sets the image for the contained windows and zones
_image = Image;
_image = value;
foreach (Window w in Windows)
{
w.Image = ZoneImage;
@@ -49,12 +49,16 @@ namespace Test_Merge
}
}
}
public Rectangle Bounds { get => _bounds; protected set => _bounds = value; }
public List<Zone> Zones { get => _zones; protected set => _zones = value; }
public List<Window> Windows { get => _windows; protected set => _windows = value; }
public string Name { get => _name; protected set => _name = value; }
/// <summary>
/// Creates a new Zone
/// </summary>
/// <param name="image">Image of the parent zone</param>
/// <param name="bounds">The position and size of the zone</param>
/// <param name="name">THe name of the zone (usefull for the JSON formatting)</param>
public Zone(Bitmap image, Rectangle bounds, string name)
{
Windows = new List<Window>();
@@ -86,36 +90,36 @@ namespace Test_Merge
/// </summary>
/// <param name="driverList">A list of all the driver in the race to help with text recognition</param>
/// <returns>A driver data object that contains all the infos about a driver</returns>
public virtual async Task<DriverData> Decode(List<string> driverList)
public virtual DriverData Decode(List<string> driverList)
{
int sectorCount = 0;
DriverData result = new DriverData();
Parallel.ForEach(Windows, async w =>
foreach(Window w in Windows)
{
// A switch would be prettier but I dont think its supported in this C# version
if (w is DriverNameWindow)
result.Name = (string)await (w as DriverNameWindow).DecodePng(driverList);
result.Name = (string)(w as DriverNameWindow).DecodePng(driverList);
if (w is DriverDrsWindow)
result.DRS = (bool)await (w as DriverDrsWindow).DecodePng();
result.DRS = (bool)(w as DriverDrsWindow).DecodePng();
if (w is DriverGapToLeaderWindow)
result.GapToLeader = (int)await (w as DriverGapToLeaderWindow).DecodePng();
result.GapToLeader = (int)(w as DriverGapToLeaderWindow).DecodePng();
if (w is DriverLapTimeWindow)
result.LapTime = (int)await (w as DriverLapTimeWindow).DecodePng();
result.LapTime = (int)(w as DriverLapTimeWindow).DecodePng();
if (w is DriverPositionWindow)
result.Position = (int)await (w as DriverPositionWindow).DecodePng();
result.Position = (int)(w as DriverPositionWindow).DecodePng();
if (w is DriverSectorWindow)
{
sectorCount++;
if (sectorCount == 1)
result.Sector1 = (int)await (w as DriverSectorWindow).DecodePng();
result.Sector1 = (int)(w as DriverSectorWindow).DecodePng();
if (sectorCount == 2)
result.Sector2 = (int)await (w as DriverSectorWindow).DecodePng();
result.Sector2 = (int)(w as DriverSectorWindow).DecodePng();
if (sectorCount == 3)
result.Sector3 = (int)await (w as DriverSectorWindow).DecodePng();
result.Sector3 = (int)(w as DriverSectorWindow).DecodePng();
}
if (w is DriverTyresWindow)
result.CurrentTyre = (Tyre)await (w as DriverTyresWindow).DecodePng();
});
result.CurrentTyre = (Tyre)(w as DriverTyresWindow).DecodePng();
}
return result;
}
public virtual Bitmap Draw()
@@ -136,16 +140,16 @@ namespace Test_Merge
//If its the main zone we need to visualize the Zone bounds displayed
if (Zones.Count > 0)
g.DrawRectangle(new Pen(Brushes.Violet, 5), Bounds);
g.DrawRectangle(new Pen(new SolidBrush(Color.FromArgb(249,194,46)), 5), Bounds);
foreach (Zone z in Zones)
{
Rectangle newBounds = new Rectangle(z.Bounds.X, z.Bounds.Y + Bounds.Y, z.Bounds.Width, z.Bounds.Height);
g.DrawRectangle(Pens.Red, newBounds);
g.DrawRectangle(new Pen(new SolidBrush(Color.FromArgb(249, 194, 46)), 5), newBounds);
}
foreach (Window w in Windows)
{
g.DrawRectangle(Pens.Blue, w.Bounds);
g.DrawRectangle(new Pen(new SolidBrush(Color.FromArgb(252, 252, 252)), 5), w.Bounds);
}
return img;
}
@@ -161,62 +165,6 @@ namespace Test_Merge
}
Windows.Clear();
}
public virtual string ToJSON()
{
string result = "";
result += "\"" + Name + "\":{" + Environment.NewLine;
result += "\t" + "\"x\":" + Bounds.X + "," + Environment.NewLine;
result += "\t" + "\"y\":" + Bounds.Y + "," + Environment.NewLine;
result += "\t" + "\"width\":" + Bounds.Width + "," + Environment.NewLine;
result += "\t" + "\"height\":" + Bounds.Height;
if (Windows.Count != 0)
{
result += "," + Environment.NewLine;
result += "\t" + "\"Windows\":[" + Environment.NewLine;
result += "\t\t{" + Environment.NewLine;
int Wcount = 0;
foreach (Window w in Windows)
{
result += "\t\t" + w.ToJSON();
Wcount++;
if (Wcount != Windows.Count)
result += ",";
}
result += "\t\t}" + Environment.NewLine;
result += "\t" + "]" + Environment.NewLine;
}
else
{
result += Environment.NewLine;
}
if (Zones.Count != 0)
{
result += "," + Environment.NewLine;
result += "\t" + "\"Zones\":[" + Environment.NewLine;
result += "\t\t{" + Environment.NewLine;
int Zcount = 0;
//foreach (Zone z in Zones)
//{
result += "\t\t" + Zones[0].ToJSON();
Zcount++;
if (Zcount != Zones.Count)
//result += ",";
//}
result += "\t\t}" + Environment.NewLine;
result += "\t" + "]" + Environment.NewLine;
}
else
{
result += Environment.NewLine;
}
result += "}";
return result;
}
/// <summary>
/// Checks if the given Rectangle fits in the current zone
/// </summary>