From 16be9bf7ef4228ed33a5877407eef8c5446a029d Mon Sep 17 00:00:00 2001 From: maxluli Date: Fri, 5 May 2023 15:00:39 +0200 Subject: [PATCH] Fixed the calibration and added the JSON serialising --- Test_Merge/ConfigurationTool.cs | 90 +++++++++++++++++++++------ Test_Merge/DriverDrsWindow.cs | 2 +- Test_Merge/DriverGapToLeaderWindow.cs | 2 +- Test_Merge/DriverLapTimeWindow.cs | 2 +- Test_Merge/DriverNameWindow.cs | 2 +- Test_Merge/DriverPositionWindow.cs | 2 +- Test_Merge/DriverSectorWindow.cs | 2 +- Test_Merge/DriverTyresWindow.cs | 2 +- Test_Merge/F1TVEmulator.cs | 6 ++ Test_Merge/Settings.Designer.cs | 52 ++++++++++------ Test_Merge/Settings.cs | 74 +++++++++++++++------- Test_Merge/Window.cs | 9 ++- Test_Merge/Zone.cs | 32 +++++++++- 13 files changed, 205 insertions(+), 72 deletions(-) diff --git a/Test_Merge/ConfigurationTool.cs b/Test_Merge/ConfigurationTool.cs index a0d3934..433cee8 100644 --- a/Test_Merge/ConfigurationTool.cs +++ b/Test_Merge/ConfigurationTool.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tesseract; +using System.IO; namespace Test_Merge { @@ -13,12 +14,63 @@ namespace Test_Merge public Zone MainZone; public const int NUMBER_OF_DRIVERS = 20; public const int NUMBER_OF_ZONES = 9; + public const string CONFIGS_FOLDER_NAME = "./Presets/"; - public ConfigurationTool(Bitmap fullImage,Rectangle mainZoneDimensions) + public ConfigurationTool(Bitmap fullImage, Rectangle mainZoneDimensions) { - MainZone = new Zone(fullImage,mainZoneDimensions); + MainZone = new Zone(fullImage, mainZoneDimensions); AutoCalibrate(); } + public void ResetMainZone() + { + MainZone.ResetZones(); + } + public void ResetWindows() + { + MainZone.ResetWindows(); + } + public void SaveToJson(List drivers,string configName) + { + string JSON = ""; + + JSON += "{" + Environment.NewLine; + JSON += MainZone.ToJSON() + "," + Environment.NewLine; + JSON += "\"Drivers\":[" + Environment.NewLine; + + for (int i = 0; i < drivers.Count;i++) + { + JSON += "\"" + drivers[i] + "\""; + if (i < drivers.Count - 1) + JSON += ","; + JSON += Environment.NewLine; + } + + JSON += "]" + Environment.NewLine; + + JSON += "}"; + + if(!Directory.Exists(CONFIGS_FOLDER_NAME)) + Directory.CreateDirectory(CONFIGS_FOLDER_NAME); + + string path = CONFIGS_FOLDER_NAME + configName; + + if(File.Exists(path + ".json")) + { + //We need to create a new name + int count = 2; + while(File.Exists(path + "_" + count + ".json")) + { + count++; + } + path += "_" + count + ".json"; + } + else + { + path += ".json"; + } + + File.WriteAllText(path,JSON); + } public void AddWindows(List rectangles) { foreach (Zone driverZone in MainZone.Zones) @@ -31,39 +83,39 @@ namespace Test_Merge { case 1: //First zone should be the driver's Position - driverZone.AddWindow(new DriverPositionWindow(driverZone.ZoneImage, rectangles[i])); + driverZone.AddWindow(new DriverPositionWindow(driverZone.ZoneImage, rectangles[i - 1], false)); break; case 2: - //First zone should be the driver's Position - driverZone.AddWindow(new DriverGapToLeaderWindow(driverZone.ZoneImage, rectangles[i])); + //First zone should be the Gap to leader + driverZone.AddWindow(new DriverGapToLeaderWindow(driverZone.ZoneImage, rectangles[i - 1], false)); break; case 3: - //First zone should be the driver's Position - driverZone.AddWindow(new DriverLapTimeWindow(driverZone.ZoneImage, rectangles[i])); + //First zone should be the driver's Lap Time + driverZone.AddWindow(new DriverLapTimeWindow(driverZone.ZoneImage, rectangles[i - 1], false)); break; case 4: - //First zone should be the driver's Position - driverZone.AddWindow(new DriverDrsWindow(driverZone.ZoneImage, rectangles[i])); + //First zone should be the driver's DRS status + driverZone.AddWindow(new DriverDrsWindow(driverZone.ZoneImage, rectangles[i - 1], false)); break; case 5: - //First zone should be the driver's Position - driverZone.AddWindow(new DriverTyresWindow(driverZone.ZoneImage, rectangles[i])); + //First zone should be the driver's Tyre's informations + driverZone.AddWindow(new DriverTyresWindow(driverZone.ZoneImage, rectangles[i - 1], false)); break; case 6: - //First zone should be the driver's Position - driverZone.AddWindow(new DriverNameWindow(driverZone.ZoneImage, rectangles[i])); + //First zone should be the driver's Name + driverZone.AddWindow(new DriverNameWindow(driverZone.ZoneImage, rectangles[i - 1], false)); break; case 7: - //First zone should be the driver's Position - driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i])); + //First zone should be the driver's First Sector + driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i - 1], false)); break; case 8: - //First zone should be the driver's Position - driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i])); + //First zone should be the driver's Second Sector + driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i - 1], false)); break; case 9: - //First zone should be the driver's Position - driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i])); + //First zone should be the driver's Position Sector + driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i - 1], false)); break; } } diff --git a/Test_Merge/DriverDrsWindow.cs b/Test_Merge/DriverDrsWindow.cs index 4a5bafc..92ed5c9 100644 --- a/Test_Merge/DriverDrsWindow.cs +++ b/Test_Merge/DriverDrsWindow.cs @@ -13,7 +13,7 @@ namespace Test_Merge { private static int EmptyDrsGreenValue = -1; private static Random rnd = new Random(); - public DriverDrsWindow(Bitmap image, Rectangle bounds) : base(image, bounds) + public DriverDrsWindow(Bitmap image, Rectangle bounds,bool generateEngine = true) : base(image, bounds,generateEngine) { Name = "DRS"; } diff --git a/Test_Merge/DriverGapToLeaderWindow.cs b/Test_Merge/DriverGapToLeaderWindow.cs index bbd79db..9c7c756 100644 --- a/Test_Merge/DriverGapToLeaderWindow.cs +++ b/Test_Merge/DriverGapToLeaderWindow.cs @@ -9,7 +9,7 @@ namespace Test_Merge { internal class DriverGapToLeaderWindow:Window { - public DriverGapToLeaderWindow(Bitmap image, Rectangle bounds) : base(image, bounds) + public DriverGapToLeaderWindow(Bitmap image, Rectangle bounds, bool generateEngine = true) : base(image, bounds,generateEngine) { Name = "Gap to leader"; } diff --git a/Test_Merge/DriverLapTimeWindow.cs b/Test_Merge/DriverLapTimeWindow.cs index 4bc5d7a..b0b3f36 100644 --- a/Test_Merge/DriverLapTimeWindow.cs +++ b/Test_Merge/DriverLapTimeWindow.cs @@ -9,7 +9,7 @@ namespace Test_Merge { internal class DriverLapTimeWindow:Window { - public DriverLapTimeWindow(Bitmap image, Rectangle bounds) : base(image, bounds) + public DriverLapTimeWindow(Bitmap image, Rectangle bounds, bool generateEngine = true) : base(image, bounds,generateEngine) { Name = "Lap time"; } diff --git a/Test_Merge/DriverNameWindow.cs b/Test_Merge/DriverNameWindow.cs index ca08a2a..abc6e20 100644 --- a/Test_Merge/DriverNameWindow.cs +++ b/Test_Merge/DriverNameWindow.cs @@ -10,7 +10,7 @@ namespace Test_Merge public class DriverNameWindow : Window { public static Random rnd = new Random(); - public DriverNameWindow(Bitmap image, Rectangle bounds) : base(image, bounds) + public DriverNameWindow(Bitmap image, Rectangle bounds, bool generateEngine = true) : base(image, bounds,generateEngine) { Name = "Name"; } diff --git a/Test_Merge/DriverPositionWindow.cs b/Test_Merge/DriverPositionWindow.cs index 6fe3f6d..4202a8a 100644 --- a/Test_Merge/DriverPositionWindow.cs +++ b/Test_Merge/DriverPositionWindow.cs @@ -9,7 +9,7 @@ namespace Test_Merge { public class DriverPositionWindow:Window { - public DriverPositionWindow(Bitmap image, Rectangle bounds) : base(image, bounds) + public DriverPositionWindow(Bitmap image, Rectangle bounds, bool generateEngine = true) : base(image, bounds,generateEngine) { Name = "Position"; } diff --git a/Test_Merge/DriverSectorWindow.cs b/Test_Merge/DriverSectorWindow.cs index c08d845..653d66e 100644 --- a/Test_Merge/DriverSectorWindow.cs +++ b/Test_Merge/DriverSectorWindow.cs @@ -9,7 +9,7 @@ namespace Test_Merge { internal class DriverSectorWindow:Window { - public DriverSectorWindow(Bitmap image, Rectangle bounds) : base(image, bounds) + public DriverSectorWindow(Bitmap image, Rectangle bounds, bool generateEngine = true) : base(image, bounds,generateEngine) { Name = "Sector 1"; } diff --git a/Test_Merge/DriverTyresWindow.cs b/Test_Merge/DriverTyresWindow.cs index 213459c..849f185 100644 --- a/Test_Merge/DriverTyresWindow.cs +++ b/Test_Merge/DriverTyresWindow.cs @@ -20,7 +20,7 @@ namespace Test_Merge public static Color WET_TYRE_COLOR = Color.FromArgb(0x27, 0x60, 0xa6); public static Color EMPTY_COLOR = Color.FromArgb(0x20, 0x20, 0x20); - public DriverTyresWindow(Bitmap image, Rectangle bounds) : base(image, bounds) + public DriverTyresWindow(Bitmap image, Rectangle bounds, bool generateEngine = true) : base(image, bounds,generateEngine) { Name = "Tyres"; } diff --git a/Test_Merge/F1TVEmulator.cs b/Test_Merge/F1TVEmulator.cs index 6946ce9..feb63c2 100644 --- a/Test_Merge/F1TVEmulator.cs +++ b/Test_Merge/F1TVEmulator.cs @@ -272,5 +272,11 @@ namespace Test_Merge Ready = false; Driver.Dispose(); } + public void ResetDriver() + { + Ready = false; + Driver.Dispose(); + Driver = null; + } } } diff --git a/Test_Merge/Settings.Designer.cs b/Test_Merge/Settings.Designer.cs index 19af6b4..a0a85e6 100644 --- a/Test_Merge/Settings.Designer.cs +++ b/Test_Merge/Settings.Designer.cs @@ -49,13 +49,14 @@ this.groupBox4 = new System.Windows.Forms.GroupBox(); this.label8 = new System.Windows.Forms.Label(); this.lsbPresets = new System.Windows.Forms.ListBox(); - this.textBox5 = new System.Windows.Forms.TextBox(); + this.tbxPresetName = new System.Windows.Forms.TextBox(); this.btnSavePreset = new System.Windows.Forms.Button(); this.lblWindowsRemaining = new System.Windows.Forms.Label(); this.lblZonePointsRemaning = new System.Windows.Forms.Label(); this.lblWindowPointsRemaining = new System.Windows.Forms.Label(); this.btnCreateWindow = new System.Windows.Forms.Button(); this.btnCreatZone = new System.Windows.Forms.Button(); + this.btnResetDriver = new System.Windows.Forms.Button(); this.gpbxInfos.SuspendLayout(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); @@ -203,12 +204,13 @@ // // groupBox2 // + this.groupBox2.Controls.Add(this.btnResetDriver); this.groupBox2.Controls.Add(this.btnRefresh); this.groupBox2.Controls.Add(this.pbxMain); this.groupBox2.Font = new System.Drawing.Font("Microsoft YaHei UI", 10F); this.groupBox2.Location = new System.Drawing.Point(283, 55); this.groupBox2.Name = "groupBox2"; - this.groupBox2.Size = new System.Drawing.Size(906, 608); + this.groupBox2.Size = new System.Drawing.Size(968, 608); this.groupBox2.TabIndex = 4; this.groupBox2.TabStop = false; this.groupBox2.Text = "Preview"; @@ -225,13 +227,14 @@ // // pbxMain // - this.pbxMain.Location = new System.Drawing.Point(6, 23); + this.pbxMain.Location = new System.Drawing.Point(6, 62); this.pbxMain.Name = "pbxMain"; - this.pbxMain.Size = new System.Drawing.Size(900, 579); - this.pbxMain.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pbxMain.Size = new System.Drawing.Size(950, 535); + this.pbxMain.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pbxMain.TabIndex = 0; this.pbxMain.TabStop = false; this.pbxMain.Click += new System.EventHandler(this.pbxMain_Click); + this.pbxMain.MouseClick += new System.Windows.Forms.MouseEventHandler(this.pbxMain_MouseClick); // // groupBox3 // @@ -239,7 +242,7 @@ this.groupBox3.Font = new System.Drawing.Font("Microsoft YaHei UI", 10F); this.groupBox3.Location = new System.Drawing.Point(18, 669); this.groupBox3.Name = "groupBox3"; - this.groupBox3.Size = new System.Drawing.Size(1390, 83); + this.groupBox3.Size = new System.Drawing.Size(1452, 83); this.groupBox3.TabIndex = 5; this.groupBox3.TabStop = false; this.groupBox3.Text = "DriverZonePreview"; @@ -248,17 +251,18 @@ // this.pbxDriverZone.Location = new System.Drawing.Point(10, 27); this.pbxDriverZone.Name = "pbxDriverZone"; - this.pbxDriverZone.Size = new System.Drawing.Size(1374, 50); - this.pbxDriverZone.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pbxDriverZone.Size = new System.Drawing.Size(1436, 50); + this.pbxDriverZone.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pbxDriverZone.TabIndex = 0; this.pbxDriverZone.TabStop = false; this.pbxDriverZone.Click += new System.EventHandler(this.pbxDriverZone_Click); + this.pbxDriverZone.MouseClick += new System.Windows.Forms.MouseEventHandler(this.pbxDriverZone_MouseClick); // // groupBox4 // this.groupBox4.Controls.Add(this.label8); this.groupBox4.Controls.Add(this.lsbPresets); - this.groupBox4.Controls.Add(this.textBox5); + this.groupBox4.Controls.Add(this.tbxPresetName); this.groupBox4.Controls.Add(this.btnSavePreset); this.groupBox4.Controls.Add(this.lblWindowsRemaining); this.groupBox4.Controls.Add(this.lblZonePointsRemaning); @@ -266,7 +270,7 @@ this.groupBox4.Controls.Add(this.btnCreateWindow); this.groupBox4.Controls.Add(this.btnCreatZone); this.groupBox4.Font = new System.Drawing.Font("Microsoft YaHei UI", 10F); - this.groupBox4.Location = new System.Drawing.Point(1195, 55); + this.groupBox4.Location = new System.Drawing.Point(1257, 55); this.groupBox4.Name = "groupBox4"; this.groupBox4.Size = new System.Drawing.Size(213, 608); this.groupBox4.TabIndex = 6; @@ -291,13 +295,13 @@ this.lsbPresets.Size = new System.Drawing.Size(197, 257); this.lsbPresets.TabIndex = 8; // - // textBox5 + // tbxPresetName // - this.textBox5.Font = new System.Drawing.Font("Microsoft YaHei UI", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.textBox5.Location = new System.Drawing.Point(10, 216); - this.textBox5.Name = "textBox5"; - this.textBox5.Size = new System.Drawing.Size(197, 29); - this.textBox5.TabIndex = 7; + this.tbxPresetName.Font = new System.Drawing.Font("Microsoft YaHei UI", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.tbxPresetName.Location = new System.Drawing.Point(10, 216); + this.tbxPresetName.Name = "tbxPresetName"; + this.tbxPresetName.Size = new System.Drawing.Size(197, 29); + this.tbxPresetName.TabIndex = 7; // // btnSavePreset // @@ -307,6 +311,7 @@ this.btnSavePreset.TabIndex = 7; this.btnSavePreset.Text = "Save as new preset"; this.btnSavePreset.UseVisualStyleBackColor = true; + this.btnSavePreset.Click += new System.EventHandler(this.btnSavePreset_Click); // // lblWindowsRemaining // @@ -355,11 +360,21 @@ this.btnCreatZone.UseVisualStyleBackColor = true; this.btnCreatZone.Click += new System.EventHandler(this.btnCreatZone_Click); // + // btnResetDriver + // + this.btnResetDriver.Location = new System.Drawing.Point(113, 22); + this.btnResetDriver.Name = "btnResetDriver"; + this.btnResetDriver.Size = new System.Drawing.Size(101, 33); + this.btnResetDriver.TabIndex = 2; + this.btnResetDriver.Text = "Reset"; + this.btnResetDriver.UseVisualStyleBackColor = true; + this.btnResetDriver.Click += new System.EventHandler(this.btnResetDriver_Click); + // // Settings // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 19F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1420, 760); + this.ClientSize = new System.Drawing.Size(1478, 760); this.Controls.Add(this.groupBox4); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox2); @@ -410,12 +425,13 @@ private System.Windows.Forms.Button btnCreateWindow; private System.Windows.Forms.Button btnCreatZone; private System.Windows.Forms.ListBox lsbPresets; - private System.Windows.Forms.TextBox textBox5; + private System.Windows.Forms.TextBox tbxPresetName; private System.Windows.Forms.Button btnSavePreset; private System.Windows.Forms.Label lblWindowsRemaining; private System.Windows.Forms.Label lblZonePointsRemaning; private System.Windows.Forms.Label lblWindowPointsRemaining; private System.Windows.Forms.Label label8; private System.Windows.Forms.Button btnRefresh; + private System.Windows.Forms.Button btnResetDriver; } } \ No newline at end of file diff --git a/Test_Merge/Settings.cs b/Test_Merge/Settings.cs index cfb2ba0..071bb0b 100644 --- a/Test_Merge/Settings.cs +++ b/Test_Merge/Settings.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using System.IO; namespace Test_Merge { @@ -49,6 +50,11 @@ namespace Test_Merge lsbDrivers.DataSource = null; lsbDrivers.DataSource = DriverList; + if (Directory.Exists(ConfigurationTool.CONFIGS_FOLDER_NAME)) + { + lsbPresets.DataSource = null; + lsbPresets.DataSource = Directory.GetFiles(ConfigurationTool.CONFIGS_FOLDER_NAME); + } if (CreatingZone) { if (ZoneP1 == new Point(-1, -1)) @@ -85,7 +91,8 @@ namespace Test_Merge if (Config != null) { pbxMain.Image = Config.MainZone.Draw(); - pbxDriverZone.Image = Config.MainZone.Zones[0].ZoneImage; + if(Config.MainZone.Zones.Count > 0) + pbxDriverZone.Image = Config.MainZone.Zones[0].Draw(); } } private void CreateNewZone(Point p1, Point p2) @@ -129,6 +136,7 @@ namespace Test_Merge { string newDriver = tbxDriverName.Text; DriverList.Add(newDriver); + tbxDriverName.Text = ""; RefreshUI(); } @@ -150,6 +158,10 @@ namespace Test_Merge else { CreatingZone = true; + + if (Config != null) + Config.ResetMainZone(); + if (CreatingWindow) SwitchWindowCreation(); @@ -176,6 +188,9 @@ namespace Test_Merge { CreatingWindow = true; + if (Config != null) + Config.ResetWindows(); + if (CreatingZone) SwitchZoneCreation(); @@ -194,19 +209,17 @@ namespace Test_Merge { SwitchWindowCreation(); } - private void pbxMain_Click(object sender, EventArgs e) + private void pbxMain_MouseClick(object sender, MouseEventArgs e) { if (CreatingZone && pbxMain.Image != null) { - Point coordinates = pbxMain.PointToClient(new Point(MousePosition.X, MousePosition.Y)); + //Point coordinates = pbxMain.PointToClient(new Point(MousePosition.X, MousePosition.Y)); + Point coordinates = e.Location; float xOffset = (float)pbxMain.Image.Width / (float)pbxMain.Width; float yOffset = (float)pbxMain.Image.Height / (float)pbxMain.Height; Point newPoint = new Point(Convert.ToInt32((float)coordinates.X * xOffset), Convert.ToInt32((float)coordinates.Y * yOffset)); - //Point newPoint = new Point(coordinates.X - pbxMain.Left, coordinates.Y - pbxMain.Top); - //newPoint = new Point(Convert.ToInt32((float)newPoint.X * xOffset),Convert.ToInt32((float)newPoint.Y * yOffset)); - - MessageBox.Show("Coordinates" + Environment.NewLine + "Old : " + coordinates.ToString() + Environment.NewLine + "New : " + newPoint.ToString()); + //MessageBox.Show("Coordinates" + Environment.NewLine + "Old : " + coordinates.ToString() + Environment.NewLine + "New : " + newPoint.ToString()); if (ZoneP1 == new Point(-1, -1)) { @@ -215,31 +228,21 @@ namespace Test_Merge else { ZoneP2 = newPoint; - - /* - //Correction - if(ZoneP1.Y > ZoneP2.Y) - { - ZoneP1 = new Point(ZoneP1.X,ZoneP1.Y + pbxMain.Top); - } - else - { - ZoneP2 = new Point(ZoneP2.X, ZoneP2.Y - pbxMain.Top); - } - */ - CreateNewZone(ZoneP1, ZoneP2); SwitchZoneCreation(); } RefreshUI(); } } - - private void pbxDriverZone_Click(object sender, EventArgs e) + private void pbxMain_Click(object sender, EventArgs e) + { + //Not the right one to use visibly + } + private void pbxDriverZone_MouseClick(object sender, MouseEventArgs e) { if (CreatingWindow && pbxDriverZone.Image != null) { - Point coordinates = pbxDriverZone.PointToClient(new Point(MousePosition.X, MousePosition.Y)); + Point coordinates = e.Location; float xOffset = (float)pbxDriverZone.Image.Width / (float)pbxDriverZone.Width; float yOffset = (float)pbxDriverZone.Image.Height / (float)pbxDriverZone.Height; @@ -262,12 +265,19 @@ namespace Test_Merge } else { + WindowP1 = new Point(WindowP1.X, 0); + WindowP2 = new Point(WindowP2.X, pbxDriverZone.Image.Height); CreateWindows(WindowsToAdd); + SwitchWindowCreation(); } } RefreshUI(); } } + private void pbxDriverZone_Click(object sender, EventArgs e) + { + //Not the right one to use visibly + } private Rectangle CreateAbsoluteRectangle(Point p1, Point p2) { Point newP1 = new Point(); @@ -357,5 +367,23 @@ namespace Test_Merge Emulator.Stop(); } } + + private void btnResetDriver_Click(object sender, EventArgs e) + { + if (Emulator != null) + { + Emulator.ResetDriver(); + } + } + + private void btnSavePreset_Click(object sender, EventArgs e) + { + string presetName = tbxPresetName.Text; + if (Config != null) + { + Config.SaveToJson(DriverList,presetName); + } + RefreshUI(); + } } } diff --git a/Test_Merge/Window.cs b/Test_Merge/Window.cs index 945c4ca..3d40c6d 100644 --- a/Test_Merge/Window.cs +++ b/Test_Merge/Window.cs @@ -35,12 +35,15 @@ namespace Test_Merge return sample; } } - public Window(Bitmap image, Rectangle bounds) + public Window(Bitmap image, Rectangle bounds, bool generateEngine = true) { Image = image; Bounds = bounds; - Engine = new TesseractEngine(TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default); - Engine.DefaultPageSegMode = PageSegMode.SingleLine; + if (generateEngine) + { + Engine = new TesseractEngine(TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default); + Engine.DefaultPageSegMode = PageSegMode.SingleLine; + } } /// /// Method that will have to be used by the childrens to let the model make them decode the images they have diff --git a/Test_Merge/Zone.cs b/Test_Merge/Zone.cs index a21a751..6d6d72f 100644 --- a/Test_Merge/Zone.cs +++ b/Test_Merge/Zone.cs @@ -111,8 +111,24 @@ namespace Test_Merge } public virtual Bitmap Draw() { - Image img = Image; + Bitmap img; + + //If its the main zone we want to see everything + if (Zones.Count > 0) + { + img = Image; + } + else + { + 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); + foreach (Zone z in Zones) { Rectangle newBounds = new Rectangle(z.Bounds.X,z.Bounds.Y + Bounds.Y,z.Bounds.Width,z.Bounds.Height); @@ -122,7 +138,19 @@ namespace Test_Merge { g.DrawRectangle(Pens.Blue, w.Bounds); } - return (Bitmap)img; + return img; + } + public void ResetZones() + { + Zones.Clear(); + } + public void ResetWindows() + { + foreach (Zone z in Zones) + { + z.ResetWindows(); + } + Windows.Clear(); } public virtual string ToJSON() {