diff --git a/BTD-PDF.sln b/BTD-PDF.sln new file mode 100644 index 0000000..18bca8b --- /dev/null +++ b/BTD-PDF.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32505.173 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BTD-PDF", "BTD-PDF\BTD-PDF.csproj", "{6FEF3E67-A180-415D-8CD5-9742FADDDC79}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6FEF3E67-A180-415D-8CD5-9742FADDDC79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6FEF3E67-A180-415D-8CD5-9742FADDDC79}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6FEF3E67-A180-415D-8CD5-9742FADDDC79}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6FEF3E67-A180-415D-8CD5-9742FADDDC79}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3DFE2C56-46DA-41CF-B117-63126E933493} + EndGlobalSection +EndGlobal diff --git a/BTD-PDF/BTD-PDF.csproj b/BTD-PDF/BTD-PDF.csproj new file mode 100644 index 0000000..482f010 --- /dev/null +++ b/BTD-PDF/BTD-PDF.csproj @@ -0,0 +1,16 @@ + + + + WinExe + net6.0-windows + BTD_PDF + enable + true + enable + + + + + + + \ No newline at end of file diff --git a/BTD-PDF/ConfigToPDF.Designer.cs b/BTD-PDF/ConfigToPDF.Designer.cs new file mode 100644 index 0000000..7354e61 --- /dev/null +++ b/BTD-PDF/ConfigToPDF.Designer.cs @@ -0,0 +1,121 @@ +namespace BTD_PDF { + partial class ConfigToPDF { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) { + if (disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() { + this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); + this.btnFile = new System.Windows.Forms.Button(); + this.lblFilename = new System.Windows.Forms.Label(); + this.btnParse = new System.Windows.Forms.Button(); + this.comboParser = new System.Windows.Forms.ComboBox(); + this.lblContents = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // openFileDialog1 + // + this.openFileDialog1.FileName = "openFileDialog1"; + this.openFileDialog1.FileOk += new System.ComponentModel.CancelEventHandler(this.openFileDialog1_FileOk); + // + // btnFile + // + this.btnFile.AllowDrop = true; + this.btnFile.Location = new System.Drawing.Point(12, 12); + this.btnFile.Name = "btnFile"; + this.btnFile.Size = new System.Drawing.Size(122, 36); + this.btnFile.TabIndex = 0; + this.btnFile.Text = "Open File"; + this.btnFile.UseVisualStyleBackColor = true; + // + // lblFilename + // + this.lblFilename.AutoSize = true; + this.lblFilename.Location = new System.Drawing.Point(140, 23); + this.lblFilename.Name = "lblFilename"; + this.lblFilename.Size = new System.Drawing.Size(16, 15); + this.lblFilename.TabIndex = 1; + this.lblFilename.Text = "..."; + // + // btnParse + // + this.btnParse.Enabled = false; + this.btnParse.Location = new System.Drawing.Point(12, 92); + this.btnParse.Name = "btnParse"; + this.btnParse.Size = new System.Drawing.Size(122, 36); + this.btnParse.TabIndex = 2; + this.btnParse.Text = "Parse"; + this.btnParse.UseVisualStyleBackColor = true; + this.btnParse.Click += new System.EventHandler(this.btnParse_Click); + // + // comboParser + // + this.comboParser.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboParser.FormattingEnabled = true; + this.comboParser.Items.AddRange(new object[] { + "Program Config", + "Hardware Calibration Report", + "Transducer Verify"}); + this.comboParser.Location = new System.Drawing.Point(12, 54); + this.comboParser.Name = "comboParser"; + this.comboParser.Size = new System.Drawing.Size(176, 23); + this.comboParser.TabIndex = 3; + this.comboParser.SelectedIndexChanged += new System.EventHandler(this.comboParser_SelectedIndexChanged); + // + // lblContents + // + this.lblContents.AutoSize = true; + this.lblContents.Location = new System.Drawing.Point(12, 144); + this.lblContents.Name = "lblContents"; + this.lblContents.Size = new System.Drawing.Size(16, 15); + this.lblContents.TabIndex = 4; + this.lblContents.Text = "..."; + // + // ConfigToPDF + // + this.AllowDrop = true; + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.lblContents); + this.Controls.Add(this.comboParser); + this.Controls.Add(this.btnParse); + this.Controls.Add(this.lblFilename); + this.Controls.Add(this.btnFile); + this.Name = "ConfigToPDF"; + this.Text = "ConfigToPDF"; + this.DragDrop += new System.Windows.Forms.DragEventHandler(this.ConfigToPDF_DragDrop); + this.DragEnter += new System.Windows.Forms.DragEventHandler(this.ConfigToPDF_DragEnter); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private OpenFileDialog openFileDialog1; + private Button btnFile; + private Label lblFilename; + private Button btnParse; + private ComboBox comboParser; + private Label lblContents; + } +} \ No newline at end of file diff --git a/BTD-PDF/ConfigToPDF.cs b/BTD-PDF/ConfigToPDF.cs new file mode 100644 index 0000000..5f5ecd4 --- /dev/null +++ b/BTD-PDF/ConfigToPDF.cs @@ -0,0 +1,108 @@ +using BenchtopParser; + +namespace BTD_PDF { + enum Parser { + ProgramConfig, + TransducerVerify, + HardwareCalibrationReport + } + + public partial class ConfigToPDF : Form { + string? fileName = null; + Parser? parser = null; + + private void setParseEnabled() { + if (fileName != null && fileName.Length > 0) { + if (parser != null) { + btnParse.Enabled = true; + } + } + } + + void ConfigToPDF_DragEnter(object sender, DragEventArgs e) { + if (!e.Data.GetDataPresent(DataFormats.FileDrop)) { + return; + } + + e.Effect = DragDropEffects.Copy; + } + + void ConfigToPDF_DragDrop(object sender, DragEventArgs e) { + IDataObject? data = e.Data; + string[] files = (string[])data.GetData(DataFormats.FileDrop); + fileName = files[0]; + if (fileName != null) { + lblFilename.Text = fileName; + parser = null; + comboParser.SelectedItem = null; + } + } + + public ConfigToPDF() { + InitializeComponent(); + this.AllowDrop = true; + this.DragEnter += new DragEventHandler(ConfigToPDF_DragEnter); + this.DragDrop += new DragEventHandler(ConfigToPDF_DragDrop); + } + + private void openFileDialog1_FileOk(object sender, System.ComponentModel.CancelEventArgs e) { + + } + + private void btnParse_Click(object sender, EventArgs e) { + if (fileName == null) { + return; + } + + var contents = File.ReadAllText(Path.Combine(fileName)); + switch (parser) { + case Parser.ProgramConfig: + parseProgramConfig(contents); + break; + case Parser.HardwareCalibrationReport: + parseHardwareCalibrationReport(contents); + break; + case Parser.TransducerVerify: + parseTransducerVerify(contents); + break; + } + } + + private void parseProgramConfig(string contents) { + ProgramConfig pc = new ProgramConfig(contents); + Console.WriteLine("Parsed PC"); + lblContents.Text = pc.Programs["P1"].ProgramNumber; + } + private void parseHardwareCalibrationReport(string contents) { + HardwareCalibrationReport hr = new HardwareCalibrationReport(contents); + Console.WriteLine("Parsed HR"); + lblContents.Text = hr.Instrument.Name; + + } + private void parseTransducerVerify(string contents) { + TransducerVerify tv = new TransducerVerify(contents); + Console.WriteLine("Parsed TV"); + lblContents.Text = tv.Transducers[1].Name; + } + + + private void comboParser_SelectedIndexChanged(object sender, EventArgs e) { + string value = comboParser.Text; + switch (value) { + case "Program Config": + parser = Parser.ProgramConfig; + break; + case "Hardware Calibration Report": + parser = Parser.HardwareCalibrationReport; + break; + case "Transducer Verify": + parser = Parser.TransducerVerify; + break; + } + setParseEnabled(); + } + + + + } +} \ No newline at end of file diff --git a/BTD-PDF/ConfigToPDF.resx b/BTD-PDF/ConfigToPDF.resx new file mode 100644 index 0000000..4a03187 --- /dev/null +++ b/BTD-PDF/ConfigToPDF.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/BTD-PDF/Program.cs b/BTD-PDF/Program.cs new file mode 100644 index 0000000..d767588 --- /dev/null +++ b/BTD-PDF/Program.cs @@ -0,0 +1,14 @@ +namespace BTD_PDF { + internal static class Program { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new ConfigToPDF()); + } + } +} \ No newline at end of file