diff --git a/Reader.cs b/Reader.cs new file mode 100644 index 0000000..d555ecb --- /dev/null +++ b/Reader.cs @@ -0,0 +1,8 @@ +using System; + +public class Class1 +{ + public Class1() + { + } +} diff --git a/Test_Merge.sln b/Test_Merge.sln index 5137e80..baf1e74 100644 --- a/Test_Merge.sln +++ b/Test_Merge.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.2.32526.322 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_Merge", "Test_Merge\Test_Merge.csproj", "{F6694884-3B45-4017-9C9A-A0AFFC508245}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{BAFC8496-36AE-4539-94DE-0E505E7A8F93}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/Test_Merge/ConfigurationTool.cs b/Test_Merge/ConfigurationTool.cs index 433cee8..6eeeeeb 100644 --- a/Test_Merge/ConfigurationTool.cs +++ b/Test_Merge/ConfigurationTool.cs @@ -18,7 +18,7 @@ namespace Test_Merge public ConfigurationTool(Bitmap fullImage, Rectangle mainZoneDimensions) { - MainZone = new Zone(fullImage, mainZoneDimensions); + MainZone = new Zone(fullImage, mainZoneDimensions,"Main"); AutoCalibrate(); } public void ResetMainZone() @@ -29,7 +29,7 @@ namespace Test_Merge { MainZone.ResetWindows(); } - public void SaveToJson(List drivers,string configName) + public void SaveToJson(List drivers, string configName) { string JSON = ""; @@ -37,7 +37,7 @@ namespace Test_Merge JSON += MainZone.ToJSON() + "," + Environment.NewLine; JSON += "\"Drivers\":[" + Environment.NewLine; - for (int i = 0; i < drivers.Count;i++) + for (int i = 0; i < drivers.Count; i++) { JSON += "\"" + drivers[i] + "\""; if (i < drivers.Count - 1) @@ -49,16 +49,16 @@ namespace Test_Merge JSON += "}"; - if(!Directory.Exists(CONFIGS_FOLDER_NAME)) + if (!Directory.Exists(CONFIGS_FOLDER_NAME)) Directory.CreateDirectory(CONFIGS_FOLDER_NAME); string path = CONFIGS_FOLDER_NAME + configName; - if(File.Exists(path + ".json")) + if (File.Exists(path + ".json")) { //We need to create a new name int count = 2; - while(File.Exists(path + "_" + count + ".json")) + while (File.Exists(path + "_" + count + ".json")) { count++; } @@ -69,7 +69,7 @@ namespace Test_Merge path += ".json"; } - File.WriteAllText(path,JSON); + File.WriteAllText(path, JSON); } public void AddWindows(List rectangles) { @@ -107,15 +107,15 @@ namespace Test_Merge break; case 7: //First zone should be the driver's First Sector - driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i - 1], false)); + driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i - 1], 1, false)); break; case 8: //First zone should be the driver's Second Sector - driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i - 1], false)); + driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i - 1], 2, false)); break; case 9: //First zone should be the driver's Position Sector - driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i - 1], false)); + driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i - 1], 3, false)); break; } } @@ -167,6 +167,8 @@ namespace Test_Merge } } while (iter.Next(PageIteratorLevel.Word)); } + //DEBUG + int i = 1; foreach (Rectangle Rectangle in detectedText) { Rectangle windowRectangle; @@ -174,7 +176,11 @@ namespace Test_Merge Point windowLocation = new Point(0, (Rectangle.Y + Rectangle.Height / 2) - windowSize.Height / 2); windowRectangle = new Rectangle(windowLocation, windowSize); //We add the driver zones - MainZone.AddZone(new Zone(MainZone.ZoneImage, windowRectangle)); + Zone driverZone = new Zone(MainZone.ZoneImage, windowRectangle, "DriverZone"); + MainZone.AddZone(driverZone); + + driverZone.ZoneImage.Save("Driver" + i+".png"); + i++; } } } diff --git a/Test_Merge/DriverData.cs b/Test_Merge/DriverData.cs index f007466..22056f9 100644 --- a/Test_Merge/DriverData.cs +++ b/Test_Merge/DriverData.cs @@ -53,21 +53,21 @@ namespace Test_Merge //Position result += "Position : " + Position + Environment.NewLine; //Gap - result += "Gap to leader : " + OCRDecoder.ConvertMsToTime(GapToLeader) + Environment.NewLine; + result += "GapToLeader : " + Reader.ConvertMsToTime(GapToLeader) + Environment.NewLine; //LapTime - result += "Lap time : " + OCRDecoder.ConvertMsToTime(LapTime) + Environment.NewLine; + result += "LapTime : " + Reader.ConvertMsToTime(LapTime) + Environment.NewLine; //DRS result += "DRS : " + DRS + Environment.NewLine; //Tyres result += "Uses " + CurrentTyre.Coumpound + " tyre " + CurrentTyre.NumberOfLaps + " laps old" + Environment.NewLine; //Name - result += "Driver name : " + Name + Environment.NewLine; + result += "DriverName : " + Name + Environment.NewLine; //Sector 1 - result += "Sector 1 : " + OCRDecoder.ConvertMsToTime(Sector1) + Environment.NewLine; + result += "Sector1 : " + Reader.ConvertMsToTime(Sector1) + Environment.NewLine; //Sector 1 - result += "Sector 2 : " + OCRDecoder.ConvertMsToTime(Sector2) + Environment.NewLine; + result += "Sector2 : " + Reader.ConvertMsToTime(Sector2) + Environment.NewLine; //Sector 1 - result += "Sector 3 : " + OCRDecoder.ConvertMsToTime(Sector3) + Environment.NewLine; + result += "Sector3 : " + Reader.ConvertMsToTime(Sector3) + Environment.NewLine; return result; } diff --git a/Test_Merge/DriverGapToLeaderWindow.cs b/Test_Merge/DriverGapToLeaderWindow.cs index 9c7c756..6f96060 100644 --- a/Test_Merge/DriverGapToLeaderWindow.cs +++ b/Test_Merge/DriverGapToLeaderWindow.cs @@ -11,7 +11,7 @@ namespace Test_Merge { public DriverGapToLeaderWindow(Bitmap image, Rectangle bounds, bool generateEngine = true) : base(image, bounds,generateEngine) { - Name = "Gap to leader"; + Name = "GapToLeader"; } /// /// Decodes the gap to leader using Tesseract OCR diff --git a/Test_Merge/DriverLapTimeWindow.cs b/Test_Merge/DriverLapTimeWindow.cs index b0b3f36..7f5a0ef 100644 --- a/Test_Merge/DriverLapTimeWindow.cs +++ b/Test_Merge/DriverLapTimeWindow.cs @@ -11,7 +11,7 @@ namespace Test_Merge { public DriverLapTimeWindow(Bitmap image, Rectangle bounds, bool generateEngine = true) : base(image, bounds,generateEngine) { - Name = "Lap time"; + Name = "LapTime"; } /// /// Decodes the lap time contained in the image using OCR Tesseract diff --git a/Test_Merge/DriverSectorWindow.cs b/Test_Merge/DriverSectorWindow.cs index 653d66e..bcfd878 100644 --- a/Test_Merge/DriverSectorWindow.cs +++ b/Test_Merge/DriverSectorWindow.cs @@ -9,9 +9,9 @@ namespace Test_Merge { internal class DriverSectorWindow:Window { - public DriverSectorWindow(Bitmap image, Rectangle bounds, bool generateEngine = true) : base(image, bounds,generateEngine) + public DriverSectorWindow(Bitmap image, Rectangle bounds, int sectorId, bool generateEngine = true) : base(image, bounds,generateEngine) { - Name = "Sector 1"; + Name = "Sector"+sectorId; } /// /// Decodes the sector diff --git a/Test_Merge/OCRDecoder.cs b/Test_Merge/Reader.cs similarity index 70% rename from Test_Merge/OCRDecoder.cs rename to Test_Merge/Reader.cs index 4247056..879a3c4 100644 --- a/Test_Merge/OCRDecoder.cs +++ b/Test_Merge/Reader.cs @@ -1,76 +1,56 @@ using System; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Threading.Tasks; using System.Drawing; +using System.Windows.Forms; using System.IO; using System.Text.Json; -using System.Windows.Forms; namespace Test_Merge { - internal class OCRDecoder + public class Reader { - private string _configFile; - private string _imagesFolder; - private List _drivers; - private List _mainZones; - private Bitmap FullImage; - public string ConfigFile { get => _configFile; private set => _configFile = value; } - public string ImagesFolder { get => _imagesFolder; private set => _imagesFolder = value; } - public List Drivers { get => _drivers; private set => _drivers = value; } - public List MainZones { get => _mainZones; set => _mainZones = value; } - - //All the image infos will be deleted in not too much time when the merge with the program that recovers the images - const string DEFAULT_IMAGE_NAME = "screen_"; - // You will defenitely have to change this if you want to be able to see debug images - public const string DEBUG_DUMP_FOLDER = @"C:\Users\Moi\Desktop\imgDump\Decode\"; const int NUMBER_OF_DRIVERS = 20; + public List Drivers; + public List MainZones; - public OCRDecoder(string configFile, string imageFolder) + public Reader(string configFile, Bitmap image,bool loadOCR = true) { - ConfigFile = configFile; - ImagesFolder = imageFolder; - Load(82); + MainZones = Load(image,configFile,ref Drivers,loadOCR); } /// /// Method that reads the JSON config file and create all the Zones and Windows /// /// The image #id on wich you want to create the zones on - private void Load(int imageNumber) + public static List Load(Bitmap image,string configFilePath,ref List driverListToFill,bool LoadOCR) { - MainZones = new List(); - try - { - FullImage = (Bitmap)Image.FromFile(ImagesFolder + DEFAULT_IMAGE_NAME + imageNumber + ".png"); - } - catch - { - MessageBox.Show("Trouble reaching the image"); - //Maybe a bit to harsh, Ill see what I can do to soft this a bit - Application.Exit(); - } + List mainZones = new List(); + Bitmap fullImage = image; + List drivers; + Zone mainZone; - Zone MainZone; try { - using (var streamReader = new StreamReader(ConfigFile)) + using (var streamReader = new StreamReader(configFilePath)) { var jsonText = streamReader.ReadToEnd(); var jsonDocument = JsonDocument.Parse(jsonText); var driversNames = jsonDocument.RootElement.GetProperty("Drivers"); - Drivers = new List(); + driverListToFill = new List(); foreach (var nameElement in driversNames.EnumerateArray()) { - Drivers.Add(nameElement.GetString()); + driverListToFill.Add(nameElement.GetString()); } var mainProperty = jsonDocument.RootElement.GetProperty("Main"); Point MainPosition = new Point(mainProperty.GetProperty("x").GetInt32(), mainProperty.GetProperty("y").GetInt32()); Size MainSize = new Size(mainProperty.GetProperty("width").GetInt32(), mainProperty.GetProperty("height").GetInt32()); Rectangle MainRectangle = new Rectangle(MainPosition, MainSize); - MainZone = new Zone(FullImage, MainRectangle); + mainZone = new Zone(image, MainRectangle,"Main"); var zones = mainProperty.GetProperty("Zones"); var driverZone = zones[0].GetProperty("DriverZone"); @@ -80,7 +60,6 @@ namespace Test_Merge var windows = driverZone.GetProperty("Windows"); - //var driverPosition = windows.GetProperty("Position"); var driverPosition = windows[0].GetProperty("Position"); Size driverPositionArea = new Size(driverPosition.GetProperty("width").GetInt32(), FirstZoneSize.Height); Point driverPositionPosition = new Point(driverPosition.GetProperty("x").GetInt32(), driverPosition.GetProperty("y").GetInt32()); @@ -94,7 +73,7 @@ namespace Test_Merge Point driverLapTimePosition = new Point(driverLapTime.GetProperty("x").GetInt32(), driverLapTime.GetProperty("y").GetInt32()); - var driverDrs = windows[0].GetProperty("Drs"); + var driverDrs = windows[0].GetProperty("DRS"); Size driverDrsArea = new Size(driverDrs.GetProperty("width").GetInt32(), FirstZoneSize.Height); Point driverDrsPosition = new Point(driverDrs.GetProperty("x").GetInt32(), driverDrs.GetProperty("y").GetInt32()); @@ -118,17 +97,19 @@ namespace Test_Merge Size driverSector3Area = new Size(driverSector3.GetProperty("width").GetInt32(), FirstZoneSize.Height); Point driverSector3Position = new Point(driverSector3.GetProperty("x").GetInt32(), driverSector3.GetProperty("y").GetInt32()); - float offset = (((float)MainZone.ZoneImage.Height - (float)(Drivers.Count * FirstZoneSize.Height)) / (float)Drivers.Count); - Bitmap MainZoneImage = MainZone.ZoneImage; + float offset = (((float)mainZone.ZoneImage.Height - (float)(driverListToFill.Count * FirstZoneSize.Height)) / (float)driverListToFill.Count); + Bitmap MainZoneImage = mainZone.ZoneImage; List zonesToAdd = new List(); List zonesImages = new List(); for (int i = 0; i < NUMBER_OF_DRIVERS; i++) { Point tmpPos = new Point(0, FirstZonePosition.Y + i * FirstZoneSize.Height - Convert.ToInt32(i * offset)); - Zone newDriverZone = new Zone(MainZoneImage, new Rectangle(tmpPos, FirstZoneSize)); + Zone newDriverZone = new Zone(MainZoneImage, new Rectangle(tmpPos, FirstZoneSize), "DriverZone"); zonesToAdd.Add(newDriverZone); zonesImages.Add(newDriverZone.ZoneImage); + + newDriverZone.ZoneImage.Save("Driver"+i+".png"); } //Parallel.For(0, NUMBER_OF_DRIVERS, i => @@ -137,20 +118,20 @@ namespace Test_Merge Zone newDriverZone = zonesToAdd[(int)i]; Bitmap zoneImg = zonesImages[(int)i]; - newDriverZone.AddWindow(new DriverPositionWindow(zoneImg, new Rectangle(driverPositionPosition, driverPositionArea))); - newDriverZone.AddWindow(new DriverGapToLeaderWindow(zoneImg, new Rectangle(driverGapToLeaderPosition, driverGapToLeaderArea))); - newDriverZone.AddWindow(new DriverLapTimeWindow(zoneImg, new Rectangle(driverLapTimePosition, driverLapTimeArea))); - newDriverZone.AddWindow(new DriverDrsWindow(zoneImg, new Rectangle(driverDrsPosition, driverDrsArea))); - newDriverZone.AddWindow(new DriverTyresWindow(zoneImg, new Rectangle(driverTyresPosition, driverTyresArea))); - newDriverZone.AddWindow(new DriverNameWindow(zoneImg, new Rectangle(driverNamePosition, driverNameArea))); - newDriverZone.AddWindow(new DriverSectorWindow(zoneImg, new Rectangle(driverSector1Position, driverSector1Area))); - newDriverZone.AddWindow(new DriverSectorWindow(zoneImg, new Rectangle(driverSector2Position, driverSector2Area))); - newDriverZone.AddWindow(new DriverSectorWindow(zoneImg, new Rectangle(driverSector3Position, driverSector3Area))); + newDriverZone.AddWindow(new DriverPositionWindow(zoneImg, new Rectangle(driverPositionPosition, driverPositionArea),LoadOCR)); + newDriverZone.AddWindow(new DriverGapToLeaderWindow(zoneImg, new Rectangle(driverGapToLeaderPosition, driverGapToLeaderArea), LoadOCR)); + newDriverZone.AddWindow(new DriverLapTimeWindow(zoneImg, new Rectangle(driverLapTimePosition, driverLapTimeArea), LoadOCR)); + newDriverZone.AddWindow(new DriverDrsWindow(zoneImg, new Rectangle(driverDrsPosition, driverDrsArea), LoadOCR)); + newDriverZone.AddWindow(new DriverTyresWindow(zoneImg, new Rectangle(driverTyresPosition, driverTyresArea), LoadOCR)); + newDriverZone.AddWindow(new DriverNameWindow(zoneImg, new Rectangle(driverNamePosition, driverNameArea), LoadOCR)); + newDriverZone.AddWindow(new DriverSectorWindow(zoneImg, new Rectangle(driverSector1Position, driverSector1Area),1, LoadOCR)); + newDriverZone.AddWindow(new DriverSectorWindow(zoneImg, new Rectangle(driverSector2Position, driverSector2Area),2, LoadOCR)); + newDriverZone.AddWindow(new DriverSectorWindow(zoneImg, new Rectangle(driverSector3Position, driverSector3Area),3, LoadOCR)); - MainZone.AddZone(newDriverZone); + mainZone.AddZone(newDriverZone); }//); //MessageBox.Show("We have a main zone with " + MainZone.Zones.Count() + " Driver zones with " + MainZone.Zones[4].Windows.Count() + " windows each and we have " + Drivers.Count + " drivers"); - MainZones.Add(MainZone); + mainZones.Add(mainZone); } } catch (IOException ex) @@ -161,51 +142,26 @@ namespace Test_Merge { MessageBox.Show("Invalid JSON format: " + ex.Message); } - } - /// - /// Changes the zones and windows to the new image - /// - /// The #id of the new image on wich to do OCR - public void ChangeImage(int imageNumber) - { - Bitmap img = null; - string imagePath = ImagesFolder + DEFAULT_IMAGE_NAME + imageNumber + ".png"; - try - { - img = (Bitmap)Image.FromFile(imagePath); - } - catch - { - MessageBox.Show("Unable to reach the image at " + imagePath); - } - if (img != null) - { - FullImage = img; - foreach (Zone z in MainZones) - { - z.Image = img; - } - } - } + return mainZones; + } /// /// Method that calls all the zones and windows to get the content they can find on the image to display them /// /// The id of the image we are working with /// a string representation of all the returns - public async Task Decode(int idImage) + public async Task Decode(List mainZones,List drivers) { string result = ""; - ChangeImage(idImage); List mainResults = new List(); //Decode - for (int mainZoneId = 0; mainZoneId < MainZones.Count; mainZoneId++) + for (int mainZoneId = 0; mainZoneId < mainZones.Count; mainZoneId++) { switch (mainZoneId) { case 0: //Main Zone - foreach (Zone z in MainZones[mainZoneId].Zones) + foreach (Zone z in mainZones[mainZoneId].Zones) { mainResults.Add(await z.Decode(Drivers)); } @@ -242,22 +198,12 @@ namespace Test_Merge /// /// the #id of the image we are working with /// the drawed bitmap - public Bitmap Draw(int idImage) + public Bitmap Draw(Bitmap image,List mainZones) { - Bitmap result; - try - { - result = (Bitmap)Image.FromFile(ImagesFolder + DEFAULT_IMAGE_NAME + idImage + ".png"); - } - catch - { - MessageBox.Show("Image could not be found"); - return null; - } - Graphics g = Graphics.FromImage(result); + Graphics g = Graphics.FromImage(image); - foreach (Zone z in MainZones) + foreach (Zone z in mainZones) { int count = 0; foreach (Zone zz in z.Zones) @@ -272,7 +218,7 @@ namespace Test_Merge } } - return result; + return image; } } } diff --git a/Test_Merge/Settings.Designer.cs b/Test_Merge/Settings.Designer.cs index a0a85e6..f0829a1 100644 --- a/Test_Merge/Settings.Designer.cs +++ b/Test_Merge/Settings.Designer.cs @@ -57,6 +57,7 @@ this.btnCreateWindow = new System.Windows.Forms.Button(); this.btnCreatZone = new System.Windows.Forms.Button(); this.btnResetDriver = new System.Windows.Forms.Button(); + this.btnLoadPreset = new System.Windows.Forms.Button(); this.gpbxInfos.SuspendLayout(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); @@ -260,6 +261,7 @@ // // groupBox4 // + this.groupBox4.Controls.Add(this.btnLoadPreset); this.groupBox4.Controls.Add(this.label8); this.groupBox4.Controls.Add(this.lsbPresets); this.groupBox4.Controls.Add(this.tbxPresetName); @@ -280,7 +282,7 @@ // label8 // this.label8.AutoSize = true; - this.label8.Location = new System.Drawing.Point(6, 314); + this.label8.Location = new System.Drawing.Point(6, 337); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(68, 23); this.label8.TabIndex = 9; @@ -290,10 +292,11 @@ // this.lsbPresets.FormattingEnabled = true; this.lsbPresets.ItemHeight = 23; - this.lsbPresets.Location = new System.Drawing.Point(10, 340); + this.lsbPresets.Location = new System.Drawing.Point(10, 363); this.lsbPresets.Name = "lsbPresets"; - this.lsbPresets.Size = new System.Drawing.Size(197, 257); + this.lsbPresets.Size = new System.Drawing.Size(197, 234); this.lsbPresets.TabIndex = 8; + this.lsbPresets.SelectedIndexChanged += new System.EventHandler(this.lsbPresets_SelectedIndexChanged); // // tbxPresetName // @@ -370,6 +373,16 @@ this.btnResetDriver.UseVisualStyleBackColor = true; this.btnResetDriver.Click += new System.EventHandler(this.btnResetDriver_Click); // + // btnLoadPreset + // + this.btnLoadPreset.Location = new System.Drawing.Point(6, 297); + this.btnLoadPreset.Name = "btnLoadPreset"; + this.btnLoadPreset.Size = new System.Drawing.Size(201, 40); + this.btnLoadPreset.TabIndex = 10; + this.btnLoadPreset.Text = "LoadPreset"; + this.btnLoadPreset.UseVisualStyleBackColor = true; + this.btnLoadPreset.Click += new System.EventHandler(this.btnLoadPreset_Click); + // // Settings // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 19F); @@ -433,5 +446,6 @@ private System.Windows.Forms.Label label8; private System.Windows.Forms.Button btnRefresh; private System.Windows.Forms.Button btnResetDriver; + private System.Windows.Forms.Button btnLoadPreset; } } \ No newline at end of file diff --git a/Test_Merge/Settings.cs b/Test_Merge/Settings.cs index 071bb0b..59c5085 100644 --- a/Test_Merge/Settings.cs +++ b/Test_Merge/Settings.cs @@ -47,6 +47,7 @@ namespace Test_Merge } private void RefreshUI() { + lsbDrivers.DataSource = null; lsbDrivers.DataSource = DriverList; @@ -385,5 +386,30 @@ namespace Test_Merge } RefreshUI(); } + + private void lsbPresets_SelectedIndexChanged(object sender, EventArgs e) + { + //Nothing + } + + private void btnLoadPreset_Click(object sender, EventArgs e) + { + if (lsbPresets.SelectedIndex >= 0 && pbxMain.Image != null) + { + try + { + Reader reader = new Reader(lsbPresets.Items[lsbPresets.SelectedIndex].ToString(), (Bitmap)pbxMain.Image,false); + //MainZones #0 is the big main zone containing driver zones + Config = new ConfigurationTool((Bitmap)pbxMain.Image, reader.MainZones[0].Bounds); + Config.MainZone = reader.MainZones[0]; + DriverList = reader.Drivers; + } + catch (Exception ex) + { + MessageBox.Show("Could not load the settings error :" + ex); + } + RefreshUI(); + } + } } } diff --git a/Test_Merge/Test_Merge.csproj b/Test_Merge/Test_Merge.csproj index 02ef32a..8055533 100644 --- a/Test_Merge/Test_Merge.csproj +++ b/Test_Merge/Test_Merge.csproj @@ -102,10 +102,10 @@ Form1.cs - + Form diff --git a/Test_Merge/Zone.cs b/Test_Merge/Zone.cs index 6d6d72f..136018a 100644 --- a/Test_Merge/Zone.cs +++ b/Test_Merge/Zone.cs @@ -13,6 +13,7 @@ namespace Test_Merge private List _zones; private List _windows; private Bitmap _image; + private string _name; public Bitmap ZoneImage { @@ -46,11 +47,13 @@ namespace Test_Merge public Rectangle Bounds { get => _bounds; protected set => _bounds = value; } public List Zones { get => _zones; protected set => _zones = value; } public List Windows { get => _windows; protected set => _windows = value; } + public string Name { get => _name; protected set => _name = value; } - public Zone(Bitmap image, Rectangle bounds) + public Zone(Bitmap image, Rectangle bounds, string name) { Windows = new List(); Zones = new List(); + Name = name; //You cant set the image in the CTOR because the processing is impossible at first initiation _image = image; @@ -97,13 +100,13 @@ namespace Test_Merge if (w is DriverSectorWindow) { sectorCount++; - if (sectorCount == 1) + if (sectorCount == 1) result.Sector1 = (int)await (w as DriverSectorWindow).DecodePng(); if (sectorCount == 2) result.Sector2 = (int)await (w as DriverSectorWindow).DecodePng(); if (sectorCount == 3) result.Sector3 = (int)await (w as DriverSectorWindow).DecodePng(); - } + } if (w is DriverTyresWindow) result.CurrentTyre = (Tyre)await (w as DriverTyresWindow).DecodePng(); }); @@ -122,16 +125,16 @@ namespace Test_Merge { img = ZoneImage; } - + Graphics g = Graphics.FromImage(img); //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(Brushes.Violet, 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); + Rectangle newBounds = new Rectangle(z.Bounds.X, z.Bounds.Y + Bounds.Y, z.Bounds.Width, z.Bounds.Height); g.DrawRectangle(Pens.Red, newBounds); } foreach (Window w in Windows) @@ -155,7 +158,7 @@ namespace Test_Merge public virtual string ToJSON() { string result = ""; - result += "\"" + "Zone" + "\":{" + Environment.NewLine; + 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;