diff --git a/mainProgram/Form1.Designer.cs b/mainProgram/Form1.Designer.cs index a8c8fc7..dc69dcd 100644 --- a/mainProgram/Form1.Designer.cs +++ b/mainProgram/Form1.Designer.cs @@ -34,9 +34,16 @@ this.OpenProjectToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.addToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.SaveProjectToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ExitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.preprocessToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.RadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.sifComputeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.SvdToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.DoasToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.SfmToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.SfmGaussinToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.SfldToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.Fld3ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -59,7 +66,8 @@ this.NewProjectToolStripMenuItem, this.OpenProjectToolStripMenuItem, this.addToolStripMenuItem, - this.SaveProjectToolStripMenuItem}); + this.SaveProjectToolStripMenuItem, + this.ExitToolStripMenuItem}); this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; this.fileToolStripMenuItem.Size = new System.Drawing.Size(39, 21); this.fileToolStripMenuItem.Text = "File"; @@ -90,6 +98,13 @@ this.SaveProjectToolStripMenuItem.Size = new System.Drawing.Size(108, 22); this.SaveProjectToolStripMenuItem.Text = "Save"; // + // ExitToolStripMenuItem + // + this.ExitToolStripMenuItem.Name = "ExitToolStripMenuItem"; + this.ExitToolStripMenuItem.Size = new System.Drawing.Size(108, 22); + this.ExitToolStripMenuItem.Text = "Exit"; + this.ExitToolStripMenuItem.Click += new System.EventHandler(this.ExitToolStripMenuItem_Click); + // // preprocessToolStripMenuItem // this.preprocessToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -107,10 +122,59 @@ // // sifComputeToolStripMenuItem // + this.sifComputeToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.SvdToolStripMenuItem, + this.DoasToolStripMenuItem, + this.SfmToolStripMenuItem, + this.SfmGaussinToolStripMenuItem, + this.SfldToolStripMenuItem, + this.Fld3ToolStripMenuItem}); this.sifComputeToolStripMenuItem.Name = "sifComputeToolStripMenuItem"; this.sifComputeToolStripMenuItem.Size = new System.Drawing.Size(87, 21); this.sifComputeToolStripMenuItem.Text = "SifCompute"; // + // SvdToolStripMenuItem + // + this.SvdToolStripMenuItem.Name = "SvdToolStripMenuItem"; + this.SvdToolStripMenuItem.Size = new System.Drawing.Size(146, 22); + this.SvdToolStripMenuItem.Text = "Svd"; + this.SvdToolStripMenuItem.Click += new System.EventHandler(this.SvdToolStripMenuItem_Click); + // + // DoasToolStripMenuItem + // + this.DoasToolStripMenuItem.Name = "DoasToolStripMenuItem"; + this.DoasToolStripMenuItem.Size = new System.Drawing.Size(146, 22); + this.DoasToolStripMenuItem.Text = "Doas"; + this.DoasToolStripMenuItem.Click += new System.EventHandler(this.DoasToolStripMenuItem_Click); + // + // SfmToolStripMenuItem + // + this.SfmToolStripMenuItem.Name = "SfmToolStripMenuItem"; + this.SfmToolStripMenuItem.Size = new System.Drawing.Size(146, 22); + this.SfmToolStripMenuItem.Text = "Sfm"; + this.SfmToolStripMenuItem.Click += new System.EventHandler(this.SfmToolStripMenuItem_Click); + // + // SfmGaussinToolStripMenuItem + // + this.SfmGaussinToolStripMenuItem.Name = "SfmGaussinToolStripMenuItem"; + this.SfmGaussinToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.SfmGaussinToolStripMenuItem.Text = "Sfm gaussian"; + this.SfmGaussinToolStripMenuItem.Click += new System.EventHandler(this.SfmGaussinToolStripMenuItem_Click); + // + // SfldToolStripMenuItem + // + this.SfldToolStripMenuItem.Name = "SfldToolStripMenuItem"; + this.SfldToolStripMenuItem.Size = new System.Drawing.Size(146, 22); + this.SfldToolStripMenuItem.Text = "Sfld"; + this.SfldToolStripMenuItem.Click += new System.EventHandler(this.SfldToolStripMenuItem_Click); + // + // Fld3ToolStripMenuItem + // + this.Fld3ToolStripMenuItem.Name = "Fld3ToolStripMenuItem"; + this.Fld3ToolStripMenuItem.Size = new System.Drawing.Size(146, 22); + this.Fld3ToolStripMenuItem.Text = "Fld3"; + this.Fld3ToolStripMenuItem.Click += new System.EventHandler(this.Fld3ToolStripMenuItem_Click); + // // statusStrip1 // this.statusStrip1.Location = new System.Drawing.Point(0, 428); @@ -129,6 +193,7 @@ this.MainMenuStrip = this.menuStrip1; this.Name = "main"; this.Text = "easySif"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.main_FormClosing); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); this.ResumeLayout(false); @@ -148,6 +213,13 @@ private System.Windows.Forms.ToolStripMenuItem RadToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem sifComputeToolStripMenuItem; private System.Windows.Forms.StatusStrip statusStrip1; + private System.Windows.Forms.ToolStripMenuItem ExitToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem SvdToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem DoasToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem SfmToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem SfmGaussinToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem SfldToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem Fld3ToolStripMenuItem; } } diff --git a/mainProgram/Form1.cs b/mainProgram/Form1.cs index c4ca342..b1b5c9a 100644 --- a/mainProgram/Form1.cs +++ b/mainProgram/Form1.cs @@ -9,6 +9,8 @@ using System.Threading.Tasks; using System.Windows.Forms; using System.IO; using System.Threading; +using System.Runtime.InteropServices; +using System.Diagnostics; namespace mainProgram { @@ -54,19 +56,128 @@ namespace mainProgram return; } - RadCorrectionWindow w = new RadCorrectionWindow(); + RadCorrectionWindow w = new RadCorrectionWindow(mProjectManager); + //w.TransferEvent += RecieveProjectManager; + + var addr2 = getMemory(mProjectManager); + Console.WriteLine("父窗口变量的地址 = " + addr2); + + //w.Show();//不阻塞 + w.ShowDialog();//阻塞 + } + + public string getMemory(object o) // 获取引用类型的内存地址方法 + { + GCHandle h = GCHandle.Alloc(o, GCHandleType.WeakTrackResurrection); + IntPtr addr = GCHandle.ToIntPtr(h); + return "0x" + addr.ToString("X"); + } + + private void ExitToolStripMenuItem_Click(object sender, EventArgs e) + { + + } + + private void main_FormClosing(object sender, FormClosingEventArgs e) + { + if (MessageBox.Show("确实退出吗", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) + { + e.Cancel = false; + } + else + { + e.Cancel = true; + } + } + + private void SvdToolStripMenuItem_Click(object sender, EventArgs e) + { + if (mProjectManager is null) + { + MessageBox.Show(this, "请先打开工程!", "提示"); + return; + } + + SVDWindows w = new SVDWindows(mProjectManager, "svd"); //w.TransferEvent += RecieveProjectManager; //w.Show();//不阻塞 w.ShowDialog();//阻塞 - - //mProjectManager.Rad(); - - Thread t1 = new Thread(new ThreadStart(mProjectManager.Rad)); - t1.Start(); - - } + private void DoasToolStripMenuItem_Click(object sender, EventArgs e) + { + if (mProjectManager is null) + { + MessageBox.Show(this, "请先打开工程!", "提示"); + return; + } + + SVDWindows w = new SVDWindows(mProjectManager, "doas"); + //w.TransferEvent += RecieveProjectManager; + + //w.Show();//不阻塞 + w.ShowDialog();//阻塞 + } + + private void SfmToolStripMenuItem_Click(object sender, EventArgs e) + { + if (mProjectManager is null) + { + MessageBox.Show(this, "请先打开工程!", "提示"); + return; + } + + SVDWindows w = new SVDWindows(mProjectManager, "sfm"); + //w.TransferEvent += RecieveProjectManager; + + //w.Show();//不阻塞 + w.ShowDialog();//阻塞 + } + + private void SfmGaussinToolStripMenuItem_Click(object sender, EventArgs e) + { + if (mProjectManager is null) + { + MessageBox.Show(this, "请先打开工程!", "提示"); + return; + } + + SVDWindows w = new SVDWindows(mProjectManager, "sfm_gaussian"); + //w.TransferEvent += RecieveProjectManager; + + //w.Show();//不阻塞 + w.ShowDialog();//阻塞 + } + + private void SfldToolStripMenuItem_Click(object sender, EventArgs e) + { + if (mProjectManager is null) + { + MessageBox.Show(this, "请先打开工程!", "提示"); + return; + } + + SVDWindows w = new SVDWindows(mProjectManager, "sfld"); + //w.TransferEvent += RecieveProjectManager; + + //w.Show();//不阻塞 + w.ShowDialog();//阻塞 + } + + private void Fld3ToolStripMenuItem_Click(object sender, EventArgs e) + { + if (mProjectManager is null) + { + MessageBox.Show(this, "请先打开工程!", "提示"); + return; + } + + SVDWindows w = new SVDWindows(mProjectManager, "3fld"); + //w.TransferEvent += RecieveProjectManager; + + //w.Show();//不阻塞 + w.ShowDialog();//阻塞 + } } } diff --git a/mainProgram/NewProjectWindow.Designer.cs b/mainProgram/NewProjectWindow.Designer.cs index 8658506..0c1c147 100644 --- a/mainProgram/NewProjectWindow.Designer.cs +++ b/mainProgram/NewProjectWindow.Designer.cs @@ -36,12 +36,15 @@ this.DataPathTextBox = new System.Windows.Forms.TextBox(); this.SelectDataPathBtn = new System.Windows.Forms.Button(); this.SelectProjectPathBtn = new System.Windows.Forms.Button(); + this.CalFilePathTextBox = new System.Windows.Forms.TextBox(); + this.SelectCalFilePathBtn = new System.Windows.Forms.Button(); + this.label3 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(143, 63); + this.label1.Location = new System.Drawing.Point(36, 41); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(53, 12); this.label1.TabIndex = 0; @@ -49,7 +52,7 @@ // // ProjectPathTextBox // - this.ProjectPathTextBox.Location = new System.Drawing.Point(217, 53); + this.ProjectPathTextBox.Location = new System.Drawing.Point(115, 37); this.ProjectPathTextBox.Name = "ProjectPathTextBox"; this.ProjectPathTextBox.ReadOnly = true; this.ProjectPathTextBox.Size = new System.Drawing.Size(205, 21); @@ -58,7 +61,7 @@ // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(143, 113); + this.label2.Location = new System.Drawing.Point(36, 154); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(53, 12); this.label2.TabIndex = 2; @@ -66,7 +69,7 @@ // // CreateProjectBtn // - this.CreateProjectBtn.Location = new System.Drawing.Point(157, 230); + this.CreateProjectBtn.Location = new System.Drawing.Point(77, 217); this.CreateProjectBtn.Name = "CreateProjectBtn"; this.CreateProjectBtn.Size = new System.Drawing.Size(75, 23); this.CreateProjectBtn.TabIndex = 3; @@ -76,7 +79,7 @@ // // Cancel // - this.Cancel.Location = new System.Drawing.Point(397, 229); + this.Cancel.Location = new System.Drawing.Point(310, 217); this.Cancel.Name = "Cancel"; this.Cancel.Size = new System.Drawing.Size(75, 23); this.Cancel.TabIndex = 4; @@ -86,7 +89,7 @@ // // DataPathTextBox // - this.DataPathTextBox.Location = new System.Drawing.Point(217, 104); + this.DataPathTextBox.Location = new System.Drawing.Point(115, 150); this.DataPathTextBox.Name = "DataPathTextBox"; this.DataPathTextBox.ReadOnly = true; this.DataPathTextBox.Size = new System.Drawing.Size(205, 21); @@ -94,7 +97,7 @@ // // SelectDataPathBtn // - this.SelectDataPathBtn.Location = new System.Drawing.Point(461, 104); + this.SelectDataPathBtn.Location = new System.Drawing.Point(374, 149); this.SelectDataPathBtn.Name = "SelectDataPathBtn"; this.SelectDataPathBtn.Size = new System.Drawing.Size(75, 23); this.SelectDataPathBtn.TabIndex = 4; @@ -104,7 +107,7 @@ // // SelectProjectPathBtn // - this.SelectProjectPathBtn.Location = new System.Drawing.Point(461, 52); + this.SelectProjectPathBtn.Location = new System.Drawing.Point(374, 36); this.SelectProjectPathBtn.Name = "SelectProjectPathBtn"; this.SelectProjectPathBtn.Size = new System.Drawing.Size(75, 23); this.SelectProjectPathBtn.TabIndex = 5; @@ -112,11 +115,41 @@ this.SelectProjectPathBtn.UseVisualStyleBackColor = true; this.SelectProjectPathBtn.Click += new System.EventHandler(this.SelectProjectPathBtn_Click); // + // CalFilePathTextBox + // + this.CalFilePathTextBox.Location = new System.Drawing.Point(115, 91); + this.CalFilePathTextBox.Name = "CalFilePathTextBox"; + this.CalFilePathTextBox.ReadOnly = true; + this.CalFilePathTextBox.Size = new System.Drawing.Size(205, 21); + this.CalFilePathTextBox.TabIndex = 7; + // + // SelectCalFilePathBtn + // + this.SelectCalFilePathBtn.Location = new System.Drawing.Point(374, 90); + this.SelectCalFilePathBtn.Name = "SelectCalFilePathBtn"; + this.SelectCalFilePathBtn.Size = new System.Drawing.Size(75, 23); + this.SelectCalFilePathBtn.TabIndex = 8; + this.SelectCalFilePathBtn.Text = "选择"; + this.SelectCalFilePathBtn.UseVisualStyleBackColor = true; + this.SelectCalFilePathBtn.Click += new System.EventHandler(this.SelectCalFilePathBtn_Click); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(36, 95); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(53, 12); + this.label3.TabIndex = 9; + this.label3.Text = "定标文件"; + // // NewProjectWindow // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); + this.ClientSize = new System.Drawing.Size(494, 292); + this.Controls.Add(this.label3); + this.Controls.Add(this.SelectCalFilePathBtn); + this.Controls.Add(this.CalFilePathTextBox); this.Controls.Add(this.SelectProjectPathBtn); this.Controls.Add(this.SelectDataPathBtn); this.Controls.Add(this.Cancel); @@ -142,5 +175,8 @@ private System.Windows.Forms.TextBox DataPathTextBox; private System.Windows.Forms.Button SelectDataPathBtn; private System.Windows.Forms.Button SelectProjectPathBtn; + private System.Windows.Forms.TextBox CalFilePathTextBox; + private System.Windows.Forms.Button SelectCalFilePathBtn; + private System.Windows.Forms.Label label3; } } \ No newline at end of file diff --git a/mainProgram/NewProjectWindow.cs b/mainProgram/NewProjectWindow.cs index 407c5b8..d888074 100644 --- a/mainProgram/NewProjectWindow.cs +++ b/mainProgram/NewProjectWindow.cs @@ -13,7 +13,7 @@ using System.Threading; namespace mainProgram { //子窗口向父窗口传递参数:https://www.cnblogs.com/xcong/p/3386085.html - public delegate void transferProjectManagerDelegate(ProjectManager value); + public delegate void transferProjectManagerDelegate(ProjectManager value);//申明委托 public partial class NewProjectWindow : Form { @@ -29,9 +29,10 @@ namespace mainProgram private void CreateProjectBtn_Click(object sender, EventArgs e) { //获取数据 - string dataPath = DataPathTextBox.Text; //string currPath = Application.StartupPath; + string dataPath = DataPathTextBox.Text; string projectPath = ProjectPathTextBox.Text; + string calFilePath = CalFilePathTextBox.Text; if (dataPath != null && dataPath.Length == 0) { @@ -43,9 +44,14 @@ namespace mainProgram MessageBox.Show(this, "工程路径不能为空", "提示"); return; } + if (calFilePath != null && calFilePath.Length == 0) + { + MessageBox.Show(this, "定标路径不能为空", "提示"); + return; + } ProjectManager projectManager = new ProjectManager(projectPath); - projectManager.CreateProject(dataPath); + projectManager.CreateProject(calFilePath, dataPath); TransferEvent(projectManager);//触发事件 @@ -92,5 +98,22 @@ namespace mainProgram { Close(); } + + private void SelectCalFilePathBtn_Click(object sender, EventArgs e) + { + FolderBrowserDialog dialog = new FolderBrowserDialog(); + dialog.Description = "请选择定标文件夹"; + if (dialog.ShowDialog() == DialogResult.OK) + { + if (string.IsNullOrEmpty(dialog.SelectedPath)) + { + MessageBox.Show(this, "文件夹路径不能为空", "提示"); + return; + } + string savePath = dialog.SelectedPath; + CalFilePathTextBox.Text = savePath; + + } + } } } diff --git a/mainProgram/OpenProjectWindow.Designer.cs b/mainProgram/OpenProjectWindow.Designer.cs index 24812cf..904d4c6 100644 --- a/mainProgram/OpenProjectWindow.Designer.cs +++ b/mainProgram/OpenProjectWindow.Designer.cs @@ -37,17 +37,17 @@ // // ProjectPathTextBox // - this.ProjectPathTextBox.Location = new System.Drawing.Point(246, 133); + this.ProjectPathTextBox.Location = new System.Drawing.Point(219, 81); this.ProjectPathTextBox.Name = "ProjectPathTextBox"; this.ProjectPathTextBox.ReadOnly = true; - this.ProjectPathTextBox.Size = new System.Drawing.Size(163, 21); + this.ProjectPathTextBox.Size = new System.Drawing.Size(162, 21); this.ProjectPathTextBox.TabIndex = 0; // // OpenProjectPathBtn // - this.OpenProjectPathBtn.Location = new System.Drawing.Point(206, 228); + this.OpenProjectPathBtn.Location = new System.Drawing.Point(133, 196); this.OpenProjectPathBtn.Name = "OpenProjectPathBtn"; - this.OpenProjectPathBtn.Size = new System.Drawing.Size(75, 23); + this.OpenProjectPathBtn.Size = new System.Drawing.Size(135, 23); this.OpenProjectPathBtn.TabIndex = 2; this.OpenProjectPathBtn.Text = "打开工程"; this.OpenProjectPathBtn.UseVisualStyleBackColor = true; @@ -56,7 +56,7 @@ // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(162, 133); + this.label1.Location = new System.Drawing.Point(131, 81); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(53, 12); this.label1.TabIndex = 3; @@ -64,9 +64,9 @@ // // SelectProjectPathBtn // - this.SelectProjectPathBtn.Location = new System.Drawing.Point(432, 130); + this.SelectProjectPathBtn.Location = new System.Drawing.Point(401, 81); this.SelectProjectPathBtn.Name = "SelectProjectPathBtn"; - this.SelectProjectPathBtn.Size = new System.Drawing.Size(75, 23); + this.SelectProjectPathBtn.Size = new System.Drawing.Size(135, 23); this.SelectProjectPathBtn.TabIndex = 4; this.SelectProjectPathBtn.Text = "选择"; this.SelectProjectPathBtn.UseVisualStyleBackColor = true; @@ -74,9 +74,9 @@ // // CancelBtn // - this.CancelBtn.Location = new System.Drawing.Point(444, 227); + this.CancelBtn.Location = new System.Drawing.Point(401, 196); this.CancelBtn.Name = "CancelBtn"; - this.CancelBtn.Size = new System.Drawing.Size(75, 23); + this.CancelBtn.Size = new System.Drawing.Size(135, 23); this.CancelBtn.TabIndex = 5; this.CancelBtn.Text = "取消"; this.CancelBtn.UseVisualStyleBackColor = true; @@ -86,7 +86,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); + this.ClientSize = new System.Drawing.Size(738, 390); this.Controls.Add(this.CancelBtn); this.Controls.Add(this.SelectProjectPathBtn); this.Controls.Add(this.label1); diff --git a/mainProgram/OpenProjectWindow.cs b/mainProgram/OpenProjectWindow.cs index 70abc8e..425276d 100644 --- a/mainProgram/OpenProjectWindow.cs +++ b/mainProgram/OpenProjectWindow.cs @@ -45,7 +45,7 @@ namespace mainProgram } ProjectManager projectManager = new ProjectManager(projectPath); - projectManager.OpenProject(projectPath); + projectManager.OpenProject(); TransferEvent(projectManager);//触发事件 diff --git a/mainProgram/ProjectManager.cs b/mainProgram/ProjectManager.cs index 680a57e..98e7f78 100644 --- a/mainProgram/ProjectManager.cs +++ b/mainProgram/ProjectManager.cs @@ -9,6 +9,164 @@ using System.Windows.Forms; namespace mainProgram { + public delegate void UpdateProgressBarInfoDelegate(int ipos, string vinfo);//申明代理:用于进度条的更新UpdateProgressBarInfoDelegate 1 + + public class DateFolder : IComparable//接口 + { + private int mYear; + private int mMonth; + private int mDay; + + //int hout; + //int minute; + //int second; + + public string mDateFolder; + + public DateFolder(string dateFolder) + { + string[] tmp = dateFolder.Split('_'); + + mYear = int.Parse(tmp[0]); + mMonth = int.Parse(tmp[1]); + mDay = int.Parse(tmp[2]); + + mDateFolder = dateFolder; + } + + public string GetDateFolder() + { + return mDateFolder; + } + + //重载运算符 + public static bool operator >(DateFolder a, DateFolder b) + { + if (a.mYear > b.mYear) + { + return true; + } + else if (a.mYear < b.mYear) + { + return false; + } + else if (a.mYear == b.mYear) + { + if (a.mMonth > b.mMonth) + { + return true; + } + else if (a.mMonth < b.mMonth) + { + return false; + } + else if (a.mMonth == b.mMonth) + { + if (a.mDay > b.mDay) + { + return true; + } + else if (a.mDay < b.mDay) + { + return false; + } + else if (a.mDay == b.mDay) + { + + } + } + } + + return false; + } + public static bool operator <(DateFolder a, DateFolder b) + { + if (a.mYear < b.mYear) + { + return true; + } + else if (a.mYear > b.mYear) + { + return false; + } + else if (a.mYear == b.mYear) + { + if (a.mMonth < b.mMonth) + { + return true; + } + else if (a.mMonth > b.mMonth) + { + return false; + } + else if (a.mMonth == b.mMonth) + { + if (a.mDay < b.mDay) + { + return true; + } + else if (a.mDay > b.mDay) + { + return false; + } + else if (a.mDay == b.mDay) + { + + } + } + } + + return false; + } + + //负数值:当前对象小于参数对象; + //正数值:当前对象大于参数对象; + //零:两个对象在比较时相等; + public int CompareTo(object obj)//IComparable接口 + { + DateFolder df = (DateFolder)obj; + + if (this.mYear < df.mYear) + { + return -1; + } + else if (this.mYear > df.mYear) + { + return 1; + } + else if (this.mYear == df.mYear) + { + if (this.mMonth < df.mMonth) + { + return -1; + } + else if (this.mMonth > df.mMonth) + { + return 1; + } + else if (this.mMonth == df.mMonth) + { + if (this.mDay < df.mDay) + { + return -1; + } + else if (this.mDay > df.mDay) + { + return 1; + } + else if (this.mDay == df.mDay) + { + + } + } + } + + return 0; + } + + + } + public class ProjectManager { public ProjectManager(string xx) @@ -20,7 +178,10 @@ namespace mainProgram private string mMetadataPath; private string mRawPath; private string mRadPath; - private string mSifPath; + public string mSifPath; + public string mSifTmpPath; + + private int mCsvFileCount; public string ProjectPath { @@ -34,7 +195,7 @@ namespace mainProgram } } - public void CreateProject(string dataPath) + public void CreateProject(string calFilePath, string dataPath) { if (mProjectPath.Length == 0) { @@ -43,7 +204,11 @@ namespace mainProgram DelectDir(mProjectPath);//删除工程路径下的所有内容 CreateProjectStructure(); - CopyFileToFile(dataPath);//复制原始数据文件到工程结构对应文件夹 + CopyCalFiles2Project(calFilePath);//复制定标文件到工程结构对应文件夹 + CopyFiles2Project(dataPath);//复制原始数据文件到工程结构对应文件夹 + + + ////创建工程元数据 //string myXMLFilePath = mMetadataPath + "/metadata.xml"; @@ -61,15 +226,17 @@ namespace mainProgram } - public void OpenProject(string projectPath) + public void OpenProject() { - mProjectPath = projectPath; - mMetadataPath = Path.Combine(mProjectPath, ".project"); mRawPath = Path.Combine(mProjectPath, "1raw"); mRadPath = Path.Combine(mProjectPath, "2rad"); mSifPath = Path.Combine(mProjectPath, "3sif"); + BinaryReader br = new BinaryReader(new FileStream(Path.Combine(mMetadataPath, "CsvFileCount.dat"), FileMode.Open)); + mCsvFileCount = br.ReadInt32(); + br.Close(); + //if (false == Directory.Exists(mMetadataPath)) //{ // Directory.CreateDirectory(mMetadataPath); @@ -275,16 +442,57 @@ namespace mainProgram } //文件复制实现:https://www.cnblogs.com/sun-shadow/p/7553556.html - public void CopyFileToFile(string sourceFolderName)//CopyFileToFile + public void CopyFiles2Project(string sourceFolderName)// { if (Directory.Exists(mRawPath)) { DelectDir(mRawPath); } - CopySubFun(sourceFolderName, mRawPath, true); + mCsvFileCount = 0; + CopySubFun(sourceFolderName, mRawPath, true);//因为此函数会递归,所以把它摘出来 + } - private void CopySubFun(string sourceFolderName, string destFolderName, bool overwrite) + public void CopyCalFiles2Project(string sourceFolderName) + { + if (!Directory.Exists(sourceFolderName)) + { + return; + } + if (!Directory.Exists(mMetadataPath)) + { + Directory.CreateDirectory(mMetadataPath); + } + + string[] sourceFilesPath = Directory.GetFileSystemEntries(sourceFolderName); + + for (int i = 0; i < sourceFilesPath.Length; i++) + { + string sourceFilePath = sourceFilesPath[i]; + string[] forlders = sourceFilePath.Split('\\'); + + if (File.Exists(sourceFilePath))//是文件,直接拷贝 + { + string dest = mMetadataPath; + string sourceFileName = Path.GetFileName(sourceFilePath);//获取文件名 + File.Copy(sourceFilePath, Path.Combine(dest, sourceFileName), true); + } + else if (Directory.Exists(sourceFilePath))//是文件夹,拷贝文件夹;并递归 + { + string lastDirectory = forlders[forlders.Length - 1]; + string dest = Path.Combine(mMetadataPath, lastDirectory); + + if (!Directory.Exists(dest)) + { + Directory.CreateDirectory(dest); + } + CopySubFun(sourceFilePath, dest, true); + } + } + + } + + private void CopySubFun(string sourceFolderName, string destFolderName, bool overwrite)//因为此函数会递归,所以把它摘出来 { if (!Directory.Exists(sourceFolderName)) { @@ -307,6 +515,9 @@ namespace mainProgram string dest = destFolderName; string sourceFileName = Path.GetFileName(sourceFilePath);//获取文件名 File.Copy(sourceFilePath, Path.Combine(dest, sourceFileName), overwrite); + + //统计文件个数 + mCsvFileCount++; } else if (Directory.Exists(sourceFilePath))//是文件夹,拷贝文件夹;并递归 { @@ -320,6 +531,11 @@ namespace mainProgram CopySubFun(sourceFilePath, dest, overwrite); } } + + //将文件个数写入到可执行文件所在目录 → 打开工程时需要读取 + BinaryWriter bw = new BinaryWriter(new FileStream(Path.Combine(mMetadataPath, "CsvFileCount.dat"), FileMode.Create)); + bw.Write(mCsvFileCount); + bw.Close(); } private void DelectDir(string srcPath) @@ -388,13 +604,13 @@ namespace mainProgram return txtFileCount; } - public int getDatFileCount() + public int getCalFileCount() { string[] metaFilesPath = Directory.GetFileSystemEntries(mMetadataPath); int datFileCount = 0; for (int i = 0; i < metaFilesPath.Length; i++)// { - if (metaFilesPath[i].Contains("dat")) + if (metaFilesPath[i].Contains("cal")) { datFileCount++; } @@ -403,11 +619,14 @@ namespace mainProgram return datFileCount; } + public UpdateProgressBarInfoDelegate UpdateProgressBarInfo;// + //处理工程中的数据 public void Rad() { + int counter = 0; //读取标定文件:辐射定标文件 + 非线性校正文件 - int datFileCount = getDatFileCount(); + int datFileCount = getCalFileCount(); int txtFileCount = getTxtFileCount(); CalData[] calDatas = new CalData[datFileCount]; @@ -422,7 +641,7 @@ namespace mainProgram nonLinearDatas[d1] = ReadNonLinearFile(metaFilesPath[i]); d1++; } - else if (metaFilesPath[i].Contains("dat")) + else if (metaFilesPath[i].Contains("cal")) { calDatas[d2] = ReadCalFile(metaFilesPath[i]); d2++; @@ -447,14 +666,12 @@ namespace mainProgram Directory.CreateDirectory(dest); } - //福亮度转换 string[] rawFiles = Directory.GetFileSystemEntries(Path.Combine(mRawPath, lastDirectory)); - foreach (string rawFileName in rawFiles)//日期文件夹下的文件 { string[] nameTmp = rawFileName.Split('\\'); - string name = nameTmp[nameTmp.Length - 1]; + SpectralDataReaderWriter spectralDataReaderWriter = new SpectralDataReaderWriter(rawFileName); for (int j = 1; j <= spectralDataReaderWriter.TotalSpectralCount; j++)//处理 csv文件中的每条光谱 { @@ -469,9 +686,9 @@ namespace mainProgram { sp.NonLinearCorrection(nonLinearDatas[nonLinearData_index].nonLinearData, spectralData.spectral, spectralData.spectralDataLength); } - if (nonLinearData_index >= 0)//福亮度转换 + if (calData_index >= 0)//福亮度转换 { - sp.NonLinearCorrection(nonLinearDatas[nonLinearData_index].nonLinearData, spectralData.spectral, spectralData.spectralDataLength); + sp.RadCorrection(calDatas[calData_index].gain, calDatas[calData_index].exposureTime, spectralData.spectral, spectralData.exposureTime, spectralData.spectralDataLength); } spectralDataReaderWriter.UpdateSpectral(j, spectralData); } @@ -479,8 +696,15 @@ namespace mainProgram string destFileName = Path.Combine(dest, name); spectralDataReaderWriter.SaveCSV(destFileName); + counter++; + float tmp1 = (float)counter / (float)mCsvFileCount; + float tmp2 = tmp1 * 100; + + UpdateProgressBarInfo((int)tmp2, name + "\r\n"); } } + + //福亮度转换完成后,需要做得动作 } /* @@ -505,7 +729,7 @@ namespace mainProgram { for (int i = 0; i < calData.GetLength(0); i++) { - if (calData[i].SN.Contains(spectralData.SN)) + if (calData[i].SN.Contains(spectralData.SN) && calData[i].position==spectralData.position) { return i; } @@ -519,15 +743,24 @@ namespace mainProgram CalData calFile; string[] forlders = calFilePath.Split('\\'); - calFile.SN = forlders[forlders.Length - 1]; + + string filename = forlders[forlders.Length - 1].Split('.')[0]; + string[] xx = filename.Split('_'); + + calFile.SN = xx[0]; + //string tmp = xx[1][xx[1].Length - 1]; + + int s = int.Parse(xx[1]); + calFile.position = s; FileStream fs2 = new FileStream(calFilePath, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs2); - calFile.exposureTime = br.ReadInt32(); + calFile.exposureTime = br.ReadUInt16(); + calFile.temperature = br.ReadSingle(); calFile.pixelCount = br.ReadInt32(); - calFile.temperature = br.ReadInt32(); calFile.waveLengthInNM = new float[calFile.pixelCount]; calFile.gain = new double[calFile.pixelCount]; + calFile.offset = new double[calFile.pixelCount]; for (int ii = 0; ii < calFile.pixelCount; ii++) { @@ -537,6 +770,10 @@ namespace mainProgram { calFile.gain[ii] = br.ReadDouble(); } + for (int ii = 0; ii < calFile.pixelCount; ii++) + { + calFile.offset[ii] = br.ReadDouble(); + } return calFile; } @@ -545,7 +782,7 @@ namespace mainProgram { NonLinearData nonLinearData; string[] forlders = nonLinearFilePath.Split('\\'); - nonLinearData.SN = forlders[forlders.Length - 1]; + nonLinearData.SN = forlders[forlders.Length - 1].Split('.')[0]; int lineCount = FindMaxRowCount(nonLinearFilePath); @@ -583,5 +820,123 @@ namespace mainProgram return maxColunmCount; } + + DateFolder[] df; + public void FindTimespan()//因为此函数会递归,所以把它摘出来 + { + if (!Directory.Exists(mRadPath)) + { + return; + } + + string[] dateFolders = Directory.GetFileSystemEntries(mRadPath); + + df = new DateFolder[dateFolders.Length]; + + for (int i = 0; i < dateFolders.Length; i++) + { + string dateFolder = dateFolders[i]; + + if (Directory.Exists(dateFolder))//是文件夹 + { + string[] splitPath = dateFolder.Split('\\');// + string lastDirectory = splitPath[splitPath.Length - 1]; + + df[i] = new DateFolder(lastDirectory); + } + } + + Array.Sort(df); + } + + public string GetMinDate() + { + return df[0].mDateFolder; + } + + public string GetMaxDate() + { + return df[df.Length - 1].mDateFolder; + } + + public void CopyWantedFiles(string minTime, string maxTime) + { + mSifTmpPath = Path.Combine(mProjectPath, "sifTmp");//mSifTmpPath + + if (false == Directory.Exists(mSifTmpPath)) + { + Directory.CreateDirectory(mSifTmpPath); + } + + DelectDir(mSifTmpPath);//删除文件夹中的内容 + + //遍历,复制文件夹[minTime,maxTime]中的文件到mSifTmpPath + DateFolder minDateFolder = new DateFolder(minTime); + DateFolder maxDateFolder = new DateFolder(maxTime); + foreach (DateFolder currentFolder in df) + { + if (minDateFolder > currentFolder | currentFolder > maxDateFolder) + { + continue; + } + + //复制文件 + string sourcePath = Path.Combine(mRadPath, currentFolder.mDateFolder); + + CopyWithModifyName(sourcePath, mSifTmpPath, true); + } + } + + private void CopyWithModifyName(string sourceFolderPath, string destFolderPath, bool overwrite)// + { + if (!Directory.Exists(sourceFolderPath)) + { + return; + } + if (!Directory.Exists(destFolderPath)) + { + Directory.CreateDirectory(destFolderPath); + } + + string[] sourceFilesPath = Directory.GetFileSystemEntries(sourceFolderPath); + + for (int i = 0; i < sourceFilesPath.Length; i++) + { + string sourceFilePath = sourceFilesPath[i]; + + //构建文件名 + string destFileName=""; + string[] forlders = sourceFilePath.Split('\\'); + + string sourceFolderName = forlders[forlders.Length - 2];//获取文件所在目录的目录名 + string sourceFileName = forlders[forlders.Length - 1];//获取文件名sourceFileName + //string sourceFileName = Path.GetFileName(sourceFilePath); + + int firstIndex = sourceFileName.IndexOf("_"); + int lastIndex = sourceFileName.LastIndexOf("_"); + if (firstIndex != -1) + { + destFileName = sourceFileName.Substring(firstIndex); + } + + + if (File.Exists(sourceFilePath))//是文件,直接拷贝 + { + File.Copy(sourceFilePath, Path.Combine(destFolderPath, sourceFolderName + destFileName), overwrite); + } + else if (Directory.Exists(sourceFilePath))//是文件夹,拷贝文件夹;并递归 → 减而治之 + { + string lastDirectory = forlders[forlders.Length - 1]; + string dest = Path.Combine(destFolderPath, lastDirectory); + + if (!Directory.Exists(dest)) + { + Directory.CreateDirectory(dest); + } + CopySubFun(sourceFilePath, dest, overwrite); + } + } + } + } } diff --git a/mainProgram/SpectralProcessor.cs b/mainProgram/SpectralProcessor.cs index 6f8606b..b6f7d73 100644 --- a/mainProgram/SpectralProcessor.cs +++ b/mainProgram/SpectralProcessor.cs @@ -37,11 +37,16 @@ namespace mainProgram } - public void RadCorrection(double[] calData, int i1,double[] rawData, int i2, int bandnumber) + public void RadCorrection(double[] calData, int integrationTime_cal, double[] targetData, int integrationTime_target, int bandnumber) { for (int i = 0; i < bandnumber; i++) { - rawData[i] = rawData[i] * calData[i] * (i1 * 1.0) / (i2 * 1.0); + targetData[i] = calData[i] * targetData[i] * (integrationTime_cal * 1.0) / (integrationTime_target * 1.0); + + if (targetData[i] < 0)//如果福亮度为负值,则设置为0 + { + targetData[i] = 0; + } } } @@ -54,6 +59,7 @@ namespace mainProgram { public DataStatus dataStatus; public string SN; + public int position; public int exposureTime; public int spectralDataLength; public double[] spectral;//long or double ????????????????????????? @@ -63,10 +69,12 @@ namespace mainProgram { public int exposureTime; public int pixelCount; - public int temperature; + public float temperature; public float[] waveLengthInNM; public double[] gain; + public double[] offset; public string SN; + public int position; } public struct NonLinearData @@ -206,6 +214,8 @@ namespace mainProgram spectralData.SN = mSN[wavelengthCountIndex]; + spectralData.position = GetPosition(index); + spectralData.spectralDataLength = mWavelengthCountOfSpectrometers[wavelengthCountIndex]; spectralData.exposureTime = int.Parse(mDataTable.Rows[index - 1 + rowOffset][2].ToString()); @@ -242,6 +252,26 @@ namespace mainProgram return wavelengthCountIndex; } + public int GetPosition(int index) + { + index -= 1;//因为0基索引,所以减1 + int position; + + int chushu = index / mSpectralCountOfOneSpectrometer; + int yushu = index % mSpectralCountOfOneSpectrometer; + + if (yushu == 0) + { + position = mSpectralCountOfOneSpectrometer; + } + else + { + position = yushu; + } + + return position; + } + public void SaveCSV(string fullPath)//table数据写入csv { FileInfo fi = new FileInfo(fullPath); diff --git a/mainProgram/bin/Debug/mainProgram.exe b/mainProgram/bin/Debug/mainProgram.exe index 8b41702..b6302db 100644 Binary files a/mainProgram/bin/Debug/mainProgram.exe and b/mainProgram/bin/Debug/mainProgram.exe differ diff --git a/mainProgram/bin/Debug/mainProgram.pdb b/mainProgram/bin/Debug/mainProgram.pdb index 9abaaeb..caf5be9 100644 Binary files a/mainProgram/bin/Debug/mainProgram.pdb and b/mainProgram/bin/Debug/mainProgram.pdb differ diff --git a/mainProgram/mainProgram.csproj b/mainProgram/mainProgram.csproj index d48a42d..98b22cd 100644 --- a/mainProgram/mainProgram.csproj +++ b/mainProgram/mainProgram.csproj @@ -102,6 +102,12 @@ RadCorrectionWindow.cs + + Form + + + SVDWindows.cs + Form1.cs @@ -126,6 +132,9 @@ RadCorrectionWindow.cs + + SVDWindows.cs + SettingsSingleFileGenerator diff --git a/mainProgram/obj/Debug/mainProgram.csproj.CoreCompileInputs.cache b/mainProgram/obj/Debug/mainProgram.csproj.CoreCompileInputs.cache index daf15c3..d39950b 100644 --- a/mainProgram/obj/Debug/mainProgram.csproj.CoreCompileInputs.cache +++ b/mainProgram/obj/Debug/mainProgram.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -023a461d68b4dca20dabec5434f4046ae8e60704 +979e07cd03d7ac36cca89d2ab128b7842b424b08 diff --git a/mainProgram/obj/Debug/mainProgram.csproj.FileListAbsolute.txt b/mainProgram/obj/Debug/mainProgram.csproj.FileListAbsolute.txt index 91516ce..f84c7d8 100644 --- a/mainProgram/obj/Debug/mainProgram.csproj.FileListAbsolute.txt +++ b/mainProgram/obj/Debug/mainProgram.csproj.FileListAbsolute.txt @@ -27,3 +27,4 @@ D:\csharp_vs2017\easySif\mainProgram\bin\Debug\Microsoft.Scripting.xml D:\csharp_vs2017\easySif\mainProgram\bin\Debug\Microsoft.Scripting.Metadata.xml D:\csharp_vs2017\easySif\mainProgram\obj\Debug\mainProgram.csproj.CopyComplete D:\csharp_vs2017\easySif\mainProgram\obj\Debug\mainProgram.RadCorrectionWindow.resources +D:\csharp_vs2017\easySif\mainProgram\obj\Debug\mainProgram.SVDWindows.resources diff --git a/mainProgram/obj/Debug/mainProgram.csproj.GenerateResource.cache b/mainProgram/obj/Debug/mainProgram.csproj.GenerateResource.cache index 81187e3..dfe4772 100644 Binary files a/mainProgram/obj/Debug/mainProgram.csproj.GenerateResource.cache and b/mainProgram/obj/Debug/mainProgram.csproj.GenerateResource.cache differ diff --git a/mainProgram/obj/Debug/mainProgram.exe b/mainProgram/obj/Debug/mainProgram.exe index 8b41702..b6302db 100644 Binary files a/mainProgram/obj/Debug/mainProgram.exe and b/mainProgram/obj/Debug/mainProgram.exe differ diff --git a/mainProgram/obj/Debug/mainProgram.pdb b/mainProgram/obj/Debug/mainProgram.pdb index 9abaaeb..caf5be9 100644 Binary files a/mainProgram/obj/Debug/mainProgram.pdb and b/mainProgram/obj/Debug/mainProgram.pdb differ