using OTS.WinFormsUI.Docking; using OTSCLRINTERFACE; using OTSDataType; using OTSMeasureApp._1_OTSMeasure.Measure.ParamData; using OTSMeasureApp._10_OTSSplashScreen; using OTSMeasureApp.ServiceCenter; using OTSModelSharp; using OTSModelSharp.ResourceManage; using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Ipc; using System.Threading; using System.Windows.Forms; using System.Xml; using static OTSDataType.otsdataconst; namespace OTSMeasureApp { enum MessageBoxRev { DIALOG_YES = 0, DIALOG_NO = 1, DIALOG_CANCEL = 2 } public partial class OTSIncAMeasureAppForm : Form { Thread th; public static string m_SamplespaceWindowName = "样品台"; public static string m_MeasureStauWindowName = "测量状态"; public static string m_MeasureRetWindowName = "测量结果"; public static string m_NoWindowName = "未知工作窗口"; //国际化 OTSCommon.Language lan; Hashtable table; // 初始化日志类 NLog.Logger log; private PostLogMsg m_LogMsg; public const int MsgID = 0x0464; public const int LogMsgID = 0x0465; public OTSMeasureResultWindow m_MeasureResultWindow = null; public OTSMeasureStatusWindow m_MessureStatuWindow = null; public OTSSamplespaceWindow m_SamplepaceWindow = null; public OTSMeasureOutputNlog m_OTSMeasureOutputNlog = null; public COTSMeasureParam m_ProjParam = null; public COTSMsrPrjResultData m_ProjRstData; public OTSSolutionWindow m_SolutionWindows = null; public OTSPropertyWindow m_SPropertyWindows = null; //测量线程对象 public CMeasureThreadWrapper m_MsrThreadWrapper = null; // 测量线程当前状态 True: 正在测量; False: 测量结束 public bool MeasureThreadRunFlag { get => m_MsrThreadWrapper.BGWorkThreadIsRunning(); } private OTSCommon.CHistoryPrj historyPrj = new OTSCommon.CHistoryPrj(); Form sp; private Panel dropHintPanel; public OTSIncAMeasureAppForm() { th = new Thread(new ThreadStart(DoSplash)); th.Start(); InitializeComponent(); //国际化 lan = new OTSCommon.Language(this); table = lan.GetNameTable(this.Name); m_SamplespaceWindowName = table["m_samplespacewindowname"].ToString(); m_MeasureStauWindowName = table["m_measurestauwindowname"].ToString(); m_MeasureRetWindowName = table["m_measureretwindowname"].ToString(); m_NoWindowName = table["m_nowindowname"].ToString(); m_OTSMeasureOutputNlog = new OTSMeasureOutputNlog(); m_OTSMeasureOutputNlog.Show(); // 初始化Docpanle m_SolutionWindows = new OTSSolutionWindow(this); m_SPropertyWindows = new OTSPropertyWindow(this); m_MeasureResultWindow = new OTSMeasureResultWindow(this); m_MeasureResultWindow.Text = m_MeasureRetWindowName; m_MessureStatuWindow = new OTSMeasureStatusWindow(this); m_MessureStatuWindow.Text = m_MeasureStauWindowName; m_SamplepaceWindow = new OTSSamplespaceWindow(this); m_SamplepaceWindow.Text = m_SamplespaceWindowName; m_ProjParam = new COTSMeasureParam(this); m_ProjRstData = m_ProjParam.GetResultData(); //初始化测量线程 m_MsrThreadWrapper = new CMeasureThreadWrapper(this);//must be the last sentence of this procedure. this.AllowDrop = true; // 初始化拖拽提示面板 InitializeDropHintPanel(); } public void SetAllRibbonButnStatus(bool bRibStstu) { rbPanelSample.Enabled = bRibStstu; //rbPanelFunction.Enabled = bRibStstu; //rbMenu.Tabs[0].Panels[0].Enabled = bRibStstu; rbMenu.Tabs[1].Panels[0].Enabled = bRibStstu; //下拉菜单中的 新建,打开,保存,另存为 //rbNewDocument.Enabled = bRibStstu; menuOpenprj.Enabled = bRibStstu; menuSaveprj.Enabled = bRibStstu; menuSaveAsprj.Enabled = bRibStstu; menuOpenprj.Enabled = true; rbOpen.Enabled = true; //if (bRibStstu) //{ //设置开始,停止,检查参数按钮 SetMeasureRibbonButnStatu(); //设置 删除,复位,圆形,矩形 按钮状态 SetSampleRibbonButnStatus(); //设置 跳转至报告 按钮状态 SetReprotRibbonButnStatu(); //} } private void OTSIncAMeasureAppForm_Load(object sender, EventArgs e) { try { ArrangWorkspaceWindow(); log = NLog.LogManager.GetCurrentClassLogger(); if (m_ProjParam.LoadParamFile()) { if (m_ProjParam.InitResultData()) { SetAllRibbonButnStatus(false); m_SamplepaceWindow.InitStageDisplay(m_ProjRstData.GetStageHolder(), m_ProjRstData.GetSEMStageData()); //添加启动系统界面显示 var SystemType = m_ProjParam.GetDefaultParam().SystemTypeId; if (SystemType == OTS_SysType_ID.IncA) { this.Text += "(IncA)"; } else if (SystemType == OTS_SysType_ID.TCCleannessA) { this.Text += "(TCCleannessA)"; } else if (SystemType == OTS_SysType_ID.BatteryCleannessA) { this.Text += "(BatteryCleannessA)"; } else { this.Text += "(SteelMineral)"; } } else { log.Error(" InitResultData() failed"); } m_MsrThreadWrapper.m_measure.m_pMeasureParam = m_ProjParam; } else { log.Error("(OTSIncAMeasureAppForm.OTSIncAMeasureAppForm_Load) (LoadParamFile() && LoadStageParamFile()) failed"); } if (!m_MsrThreadWrapper.ConnectSEM()) { MessageBox.Show("Connect SEM failed!Please goto the SysMgrApp.exe to setup the proper parameter or check other parameter of the EDS software"); System.Diagnostics.ProcessStartInfo process = new System.Diagnostics.ProcessStartInfo(); process.FileName = "OTSSysMgrApp.exe";//打开app的路径 process.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; System.Diagnostics.Process.Start(process); this.rbConnectHardware.Enabled = true; this.rbDisconnectHardware.Enabled = false; } this.rbConnectHardware.Enabled = false; this.rbDisconnectHardware.Enabled = true; log.Warn("SEM connect success!"); PrepareIpcServer(); log.Info("Ipc server start success!"); //----------------------Test Code, Don't delete //var f = new BaseFunctionTest(); //f.ShowDialog(); //---------------------- } catch (Exception ex) { log.Error(" OTSIncAMeasureAppForm_Load:" + ex.ToString()); } sp.Close(); this.Activate(); } public void ArrangWorkspaceWindow() { //Show 样品台窗口 m_SamplepaceWindow.Show(dockPanel); //Show 测量状态窗口 m_MessureStatuWindow.Show(dockPanel); //Show 测量结果窗口 m_MeasureResultWindow.Show(dockPanel); m_SolutionWindows.Show(dockPanel, DockState.DockLeft); //Show 测量过程中Log显示窗口 m_OTSMeasureOutputNlog.Show(dockPanel, DockState.DockRight); dockPanel.DockRightPortion = 365; m_SPropertyWindows.Show(dockPanel); m_SamplepaceWindow.Activate(); InitHistoryPrjDisplay(); } private void InitHistoryPrjDisplay() { //加载历史工作文件列表 historyPrj.loadHistoryPath(); List prjPathList = historyPrj.GetPrjPathList(); if (prjPathList.Count == 0) { menuHistoryPrj.Enabled = false; return; } menuHistoryPrj.Enabled = true; menuHistoryPrj.DropDownItems.Clear(); for (int i = 0; i < prjPathList.Count; i++) { RibbonOrbMenuItem tsmi = new RibbonOrbMenuItem(); tsmi.Text = prjPathList[i]; tsmi.Click += new EventHandler(this.menuHistoryPrj_Click); menuHistoryPrj.DropDownItems.Add(tsmi); } } private void saveHistoryPrj(string strPrjPath) { //保存历史工作文件列表 historyPrj.loadHistoryPath(); historyPrj.AddPrjPath(strPrjPath); historyPrj.saveHistoryPath(); InitHistoryPrjDisplay(); } private void menuHistoryPrj_Click(object sender, EventArgs e) { RibbonOrbMenuItem itm = sender as RibbonOrbMenuItem; OpenMeasureProjectFile(itm.Text); } private void DoSplash() { string path = @".\Config\SysData\OTSProgMgrParam.pmf"; XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(path); XmlNode node = xmlDocument.SelectSingleNode("XMLData"); XmlElement xe = (XmlElement)node; string str = xe.GetAttribute("SysType"); if (str == "IncA") { sp = new OTSSplashScreen_IncA(); sp.ShowDialog(); } else if (str == "TCCleannessA" || str == "BatteryCleannessA") { sp = new OTSSplashScreen_Cleanness(); sp.ShowDialog(); } else if (str == "SteelMineral") { sp = new OTSSplashScreen_SteelMineral(); sp.ShowDialog(); } } private void rbReport_Click(object sender, EventArgs e) { //测量结果文件路径列表 List mrFilePathList = new List(); //获取测量结果文件路径列表 bool result = m_ProjParam.GetCompletedMeasureFileName(ref mrFilePathList); if (result) { for (int i = 0; i < mrFilePathList.Count; i++) { mrFilePathList[i] = mrFilePathList[i].Replace(" ", "^"); } //转换为数组 string[] resultFilePath = mrFilePathList.ToArray(); System.Diagnostics.ProcessStartInfo process = new System.Diagnostics.ProcessStartInfo(); process.FileName = "OTSIncAReportApp.exe";//打开app的路径 string FilePath = string.Join(" ", resultFilePath); process.Arguments = FilePath;//多个参数用空格隔开 process.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; System.Diagnostics.Process.Start(process); } } // sNewWorkSampleName: 新工作样品名 public void SwitchWSample(string sNewWorkSampleName) { m_ProjParam.SetWorkSample(sNewWorkSampleName); m_SolutionWindows.SwitchSample(sNewWorkSampleName); //获取新工作样品属性值 OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(), m_ProjParam.GetDefaultParam().GetSysType()); m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo); //发送想你的样品名给Sample m_SamplepaceWindow.SwitchWorkSample(sNewWorkSampleName); } public void SoluWindowCheckBoxStatuChange(string sSampleName, bool bCheckBoxStatu) { string sWSampleName = m_ProjParam.GetWorkSampleName(); if ("" == sWSampleName) { //不修改Tteeview 的工作样品属性值 m_SolutionWindows.Rev_MeasureApp_CheckboxStatuChange_Event(sSampleName, !bCheckBoxStatu); return; } //Treeview更改的工作样品数的CHECKBOX 状态 if (!m_ProjParam.SetSampleParamVal(OTS_SAMPLE_PROP_GRID_ITEMS.SWITCH, OTS_ITEM_TYPES.BOOL, bCheckBoxStatu)) { //不修改Tteeview 的工作样品属性值 m_SolutionWindows.Rev_MeasureApp_CheckboxStatuChange_Event(sSampleName, !bCheckBoxStatu); return; } // 设置 开始 ,停止 和检查参数 按钮状态 SetMeasureRibbonButnStatu(); //修改Grid工作样品的SWITCH值 OTSSampleVisualPropertyInfo SMeasurenfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(), m_ProjParam.GetDefaultParam().GetSysType()); m_SPropertyWindows.DisplaySampleMeasureInfo(SMeasurenfo); } public void SetMeasureRibbonButnStatu() { bool bSampleCheckBoxFalg = m_ProjParam.GetSampleCheckBoxStatus(); if (!bSampleCheckBoxFalg) { rbStart.Enabled = false; rbPause.Enabled = false; rbStop.Enabled = false; rbCheckParam.Enabled = false; return; } if (MeasureThreadRunFlag) //当正在测量时,开始按钮变灰色 { rbStart.Enabled = false;} else {rbStart.Enabled = true;} if (MeasureThreadRunFlag) //当前正在运行的时候,才可以点击暂停 { rbPause.Enabled = true; } else { rbPause.Enabled = false; } if (MeasureThreadRunFlag) //当前正在运行的时候,才可以点击停止 { rbStop.Enabled = true; } else { rbStop.Enabled = false; } if (MeasureThreadRunFlag) { rbCheckParam.Enabled = false; } else { rbCheckParam.Enabled = true; } } public bool EditWorkSampleName(string sSampleOldName, string sSampleNewName) { if (!m_ProjParam.ChangeWorkSampleName(sSampleNewName)) { return false; } OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(), m_ProjParam.GetDefaultParam().GetSysType()); m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo); m_SamplepaceWindow.ChangeWorkSampleName(sSampleNewName); return true; } public void SoluwindowReqAddSample() { //Treeview右键点击添加新样品 this.AddNewSampleMeasure(); } private void OTSIncAMeasureAppForm_FormClosing(object sender, FormClosingEventArgs e) { try { if (m_MsrThreadWrapper.BGWorkThreadIsRunning()) //当前正在测量 { e.Cancel = true; return; } if (m_MsrThreadWrapper.IsHavingNotCompleteSamples()) //当前正在测量 { e.Cancel = true; MessageBox.Show("There is one sample is still in pausing state,please stop it!"); return; } //判断测量结果文件修改后是否保存 if (m_ProjRstData.IsModified()) { string message = table["message2"].ToString(); DialogResult lsdr = MessageBox.Show(message, "Tip", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information); if (lsdr == DialogResult.Yes) { //保存,退出 m_ProjRstData.Save(); //保存,直接退出 Application.ExitThread(); } else if (lsdr == DialogResult.No) { //不保存,直接退出 Application.ExitThread(); } else if (lsdr == DialogResult.Cancel) { //取消 e.Cancel = true; return; } } log.Info("Disconnect SEM!"); m_MsrThreadWrapper.DisconnectSEM(); m_MsrThreadWrapper.SetWorkThreadPending(); } catch (Exception ex) { string message = table["message3"].ToString(); log.Error("OTSIncAMeasureAppForm_FormClosing-" + message + ":" + ex.ToString()); } Process.GetCurrentProcess().Kill(); } //打开指定路径的文件 private void ribbonOrbMenuItem1_OpenWorkspace_Click(object sender, EventArgs e) { OpenMeasureProjectFile(); } //新建样品工作文件 private void ribbonOrbMenuItem3_CreateWorkspace_Click(object sender, EventArgs e) { int iCreateNewFileResult = m_ProjParam.CreateNewFile(); if (iCreateNewFileResult == 0) { log.Error("(OTSIncAMeasureAppForm.rbNew_CreateWorkspace_Click) m_DataMgrFun.CreateNewFile() Failed !"); return; } else if (iCreateNewFileResult == 2) { log.Info("(OTSIncAMeasureAppForm.rbNew_CreateWorkspace_Click) m_DataMgrFun.CreateNewFile() Cancel !"); return; } m_ProjRstData = m_ProjParam.GetResultData(); SetAllRibbonButnStatus(true); //清除TREEVIEW和GRID上的显示的已经保存的样品信息 m_SolutionWindows.m_TreeViewBase.DeleteAllTreeNode(); m_SPropertyWindows.m_SampleGrid.HideGrid(); //设置报告按钮 rbPReport.Enabled = false; rbReport.Enabled = false; menuHistoryPrj.Enabled = true; //新建项目时,设置属性窗体中的两个按钮也为不可用状态 m_SPropertyWindows.TSLoad.Enabled = false; m_SPropertyWindows.TSSaveAs.Enabled = false; //绘制样品台 m_SamplepaceWindow.InitStageDisplay(m_ProjRstData.GetStageHolder(), m_ProjRstData.GetSEMStageData()); //隐藏XrayTable控件 m_MessureStatuWindow.HideXRayTable(); //新建时重新初始化结果窗体结果 m_MeasureResultWindow.SetInit(); } // 新建样品时提示保存样品信息Messagebox public int ShowSaveInfoMsgBox() { string message = table["message4"].ToString(); DialogResult dResult = MessageBox.Show(message, "Tip", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (dResult == DialogResult.Yes) { return (int)MessageBoxRev.DIALOG_YES; } else if (dResult == DialogResult.No) { return (int)MessageBoxRev.DIALOG_NO; } else { return (int)MessageBoxRev.DIALOG_CANCEL; } } //打开已经保存的工作文件 private bool DisplayExistSampleFile() { List TSampleParamList = new List(); List SampleMeasureParaList = new List(); int iSampleCount = m_ProjRstData.GetSampleList().Count; if (0 == iSampleCount) { return false; } for (int i = 0; i < iSampleCount; i++) { CTreeSampleParam CTSampleParam = new CTreeSampleParam(); COTSSample SampleClr = (m_ProjRstData.GetSampleList())[i]; CTSampleParam.sSampleTitleName = m_ProjRstData.GetFileName(); CTSampleParam.sWorkSampleName = SampleClr.GetName(); CTSampleParam.bSwitch = SampleClr.GetSwitch(); TSampleParamList.Add(CTSampleParam); } OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(), m_ProjParam.GetDefaultParam().GetSysType()); m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo); m_SolutionWindows.DisplayExistSampleFile(TSampleParamList, SMInfo.TSampleParam); if (!InitExistSampleMeasureParam(ref SampleMeasureParaList)) { log.Error(" OpenExistSampleMeasureArea(ref SampleMeasureAreaList) Failed !"); return false; } string sWSampleName = m_ProjParam.GetWorkSampleName(); if ("" == sWSampleName) { log.Error("(OTSIncAMeasureAppForm.OpenExistSampleFile) m_DataMgrFun.GetWorkSampleName() = null !"); return false; } m_SamplepaceWindow.DisplayVisualStage(m_ProjRstData.GetStageHolder(), m_ProjRstData.GetSEMStageData()); m_SamplepaceWindow.DisplayExistSamples(SampleMeasureParaList); m_MeasureResultWindow.UpdateResultInfoBySampleName(sWSampleName); return true; } public bool InitExistSampleMeasureParam(ref List SampleMeasureParaList) { int iSListCount = m_ProjRstData.GetSampleList().Count; if (0 == iSListCount) { return false; } for (int i = 0; i < iSListCount; i++) { SampleMeasurePara SampleMeasureParam = new SampleMeasurePara(m_ProjRstData.GetSampleList()[i]); SampleMeasureParaList.Add(SampleMeasureParam); } return true; } //打开指定路径的文件 private void rbOpen_Click(object sender, EventArgs e) { OpenMeasureProjectFile(); } private void rbDeleteSample_Click(object sender, EventArgs e) { //删除样品(样品必须先选中) string sWSampleName = m_ProjParam.GetWorkSampleName(); if ("" == sWSampleName) { log.Error("(OTSIncAMeasureAppForm.rbDeleteSample_Click) m_DataMgrFun.GetWorkSampleName() = null Failed"); return; } string message = table["message5"].ToString(); string message6 = table["message6"].ToString(); string sDeleteSampleName = message; sDeleteSampleName += sWSampleName; sDeleteSampleName += message6; if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Tip", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)) { //删除样品成功 DeleteSample(sWSampleName); sWSampleName = m_ProjParam.GetWorkSampleName(); if ("" != sWSampleName) { m_SolutionWindows.m_TreeViewBase.GetTreeWorkSampleNode(sWSampleName); m_SolutionWindows.treeView1.Focus(); } } } public void SetRibbonButonWorkListStatu(List RibbonButnIDList, bool bFlag) { if (RibbonButnIDList.Count == 0) { return; } for (int i = 0; i < RibbonButnIDList.Count; i++) { if (RibbonButnIDList[i] == (int)RibbonButnID.NewDocment) { menuNewDocument.Enabled = bFlag; continue; } if (RibbonButnIDList[i] == (int)RibbonButnID.File_NewDocment) { rbNew.Enabled = bFlag; continue; } if (RibbonButnIDList[i] == (int)RibbonButnID.OpenDocment) { menuOpenprj.Enabled = bFlag; continue; } if (RibbonButnIDList[i] == (int)RibbonButnID.File_OpenDocment) { rbOpen.Enabled = bFlag; continue; } if (RibbonButnIDList[i] == (int)RibbonButnID.Save) { menuSaveprj.Enabled = bFlag; continue; } if (RibbonButnIDList[i] == (int)RibbonButnID.File_Save) { rbSave.Enabled = bFlag; continue; } if (RibbonButnIDList[i] == (int)RibbonButnID.SaveAs) { menuSaveAsprj.Enabled = bFlag; continue; } if (RibbonButnIDList[i] == (int)RibbonButnID.File_SaveAs) { rbSaveAs.Enabled = bFlag; continue; } if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_Reset) { ribInvers.Enabled = bFlag; continue; } if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_DrawCircle) { ribCircle.Enabled = bFlag; continue; } if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_DrawRectang) { ribRectangle.Enabled = bFlag; continue; } if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_DrawPolygon) { ribPolygon.Enabled = bFlag; continue; } if (RibbonButnIDList[i] == (int)RibbonButnID.View_Ruler) { rbRuler.Enabled = bFlag; continue; } if (RibbonButnIDList[i] == (int)RibbonButnID.View_SPhoto) { rbSmaplePhoto.Enabled = bFlag; continue; } if (RibbonButnIDList[i] == (int)RibbonButnID.View_SName) { rbSmapleName.Enabled = bFlag; continue; } if (RibbonButnIDList[i] == (int)RibbonButnID.View_Recover) { rbRecover.Enabled = bFlag; continue; } if (RibbonButnIDList[i] == (int)RibbonButnID.File_Base) { rbMenu.Tabs[0].Panels[0].Enabled = bFlag; continue; } if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_Base) { rbPanelSample.Enabled = bFlag; continue; } if (RibbonButnIDList[i] == (int)RibbonButnID.Funciton_Base) { rbPanelFunction.Enabled = bFlag; continue; } if (RibbonButnIDList[i] == (int)RibbonButnID.View_Base) { rbMenu.Tabs[1].Panels[0].Enabled = bFlag; continue; } if (RibbonButnIDList[i] == (int)RibbonButnID.Fun_Report) { rbMenu.Tabs[1].Panels[0].Enabled = bFlag; continue; } if (RibbonButnIDList[i] == (int)RibbonButnID.ShotImage) { ribonBtnShot.Enabled = bFlag; continue; } } } //设置 删除,复位,圆形,矩形 按钮状态 public void SetSampleRibbonButnStatus() { List RibbonIdList = new List(); RibbonIdList.Add((int)RibbonButnID.Sample_DeleteSample); RibbonIdList.Add((int)RibbonButnID.Sample_Reset); RibbonIdList.Add((int)RibbonButnID.Sample_DrawCircle); RibbonIdList.Add((int)RibbonButnID.Sample_DrawRectang); RibbonIdList.Add((int)RibbonButnID.Sample_DrawPolygon); RibbonIdList.Add((int)RibbonButnID.ShotImage); if (0 == m_ProjParam.GetSampleCount()) { rbPanelSample.Enabled = false; //rbPanelFunction.Enabled = false; rbMenu.Tabs[0].Panels[0].Enabled = true; rbOpen.Enabled = true; menuOpenprj.Enabled = true; rbSave.Enabled = false; menuSaveprj.Enabled = false; menuSaveAsprj.Enabled = false; menuHistoryPrj.Enabled = true; SetRibbonButonWorkListStatu(RibbonIdList, false); } else { rbPanelSample.Enabled = true; //rbPanelFunction.Enabled = true; rbOpen.Enabled = false; menuOpenprj.Enabled = false; rbSave.Enabled = true; menuSaveAsprj.Enabled = true; menuHistoryPrj.Enabled = false; rbMenu.Tabs[1].Panels[0].Enabled = true; SetRibbonButonWorkListStatu(RibbonIdList, true); } } public void SetReprotRibbonButnStatu() { //设置跳转至报告程序按钮状态 rbPReport.Enabled = false; rbReport.Enabled = false; //判断打开的文件是否存在测量结果文件路径 List mrFilePathList = new List(); bool result = m_ProjParam.GetCompletedMeasureFileName(ref mrFilePathList); //根据结果设置报告按钮启用状态 if (result) { rbPReport.Enabled = true; rbReport.Enabled = true; } else { rbPReport.Enabled = false; rbReport.Enabled = false; } } //返回删除的工作样品名 public void DeleteSample(string sDeleteWSampleName = "") { if (m_MsrThreadWrapper.m_measure.mapSmplMsr.ContainsKey(sDeleteWSampleName)) { m_MsrThreadWrapper.m_measure.mapSmplMsr.Remove(sDeleteWSampleName); } m_ProjParam.DeleteWorkSample(sDeleteWSampleName); // 设置 开始 ,停止 和检查参数 按钮状态 SetMeasureRibbonButnStatu(); //设置 删除,复位,圆形,矩形 按钮状态 SetSampleRibbonButnStatus(); // 更新报告ribbon按钮状态 SetAllRibbonButnStatus(true); int iSampleCount = m_ProjParam.GetSampleCount(); if (0 == iSampleCount) { //给工作样品台发送删除样品和新的工作样品名称 m_SamplepaceWindow.DeleteWorkSample(sDeleteWSampleName); m_SPropertyWindows.PropGrid.Hide(); m_SPropertyWindows.toolStripButton_refresh.Enabled = false; m_SPropertyWindows.TSSaveAs.Enabled = false; m_SolutionWindows.treeView1.Nodes.Clear(); m_MessureStatuWindow.HideXRayTable(); m_ProjRstData.Cleanup(); m_MeasureResultWindow.SetInit(); return; } else { string sNewWSName = m_ProjParam.GetWorkSampleName(); if ("" == sNewWSName) { log.Error("(OTSIncAMeasureAppForm.DeleteSample) m_DataMgrFun.GetWorkSampleName() = null Failed"); return; } m_SolutionWindows.DeletCurrentSampleNode(); m_SolutionWindows.DisplaySample(sNewWSName); //将测量状态初始化 m_MessureStatuWindow.SetMeasureStatusInit(); //给工作样品台发送删除样品和新的工作样品名称 m_SamplepaceWindow.DeleteWorkSample(sDeleteWSampleName); //设置工作样品 SwitchWSample(sNewWSName); } return; } private void rbAddSample_Click(object sender, EventArgs e) { this.AddNewSampleMeasure();//the system will choose the empty hole one by one according to the holeNo sequence. } public void AddNewSampleMeasure(string sSampleHoleName = "") { OTSSampleVisualPropertyInfo SMInfo = m_ProjParam.AddNewSampleMeasure(sSampleHoleName); if (null == SMInfo) { // 设置 开始 ,停止 和检查参数 按钮状态 SetMeasureRibbonButnStatu(); log.Error("(OTSIncAMeasureAppForm.AddNewSample) m_DataMgrFun.AddNewSample(sSampleHoleName) = null "); return; } m_SPropertyWindows.TSSaveAs.Enabled = true; this.menuSaveprj.Enabled = true; this.rbSaveAs.Enabled = true; m_SPropertyWindows.TSLoad.Enabled = true; m_SPropertyWindows.TSEdit.Enabled = false; m_SPropertyWindows.TSEdit.Visible = false; //给SampleWindow 发送样品信息 m_SamplepaceWindow.AddSampleArea(SMInfo.SMeasurePara); m_SamplepaceWindow.ReadSEMDataAndSetToCurrentSample(); //给PropWindow 发送工作样品属性信息 m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo); //给SoluWindow 发送样品显示信息 m_SolutionWindows.AddSampleMeasure(SMInfo.TSampleParam); // 设置 开始 ,停止 和检查参数 按钮状态 SetMeasureRibbonButnStatu(); //设置 删除,复位,圆形,矩形 按钮状态 SetSampleRibbonButnStatus(); } public void InitCurrentSampleState() { OTSSampleVisualPropertyInfo SMInfo = m_ProjParam.GetWorkingSampleVisualPropertyInfo(); if (null == SMInfo) { // 设置 开始 ,停止 和检查参数 按钮状态 SetMeasureRibbonButnStatu(); log.Error("(OTSIncAMeasureAppForm.AddNewSample) m_DataMgrFun.AddNewSample(sSampleHoleName) = null "); return; } m_SPropertyWindows.TSSaveAs.Enabled = true; m_SPropertyWindows.TSLoad.Enabled = true; m_SamplepaceWindow.ReadSEMDataAndSetToCurrentSample(); //给PropWindow 发送工作样品属性信息 m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo); // 设置 开始 ,停止 和检查参数 按钮状态 SetMeasureRibbonButnStatu(); //设置 删除,复位,圆形,矩形 按钮状态 SetSampleRibbonButnStatus(); } private void rbSelectDlg_Click(object sender, EventArgs e) { ProgMgrInfoForm ProgMgrForm = new ProgMgrInfoForm(); if (DialogResult.OK == ProgMgrForm.ShowDialog()) { if (m_ProjParam.LoadParamFile()) { if (m_ProjParam.InitResultData()) { SetAllRibbonButnStatus(true); //当样品台上有样品,则不更新样品台数据 if (0 == m_ProjParam.GetSampleCount()) { m_SamplepaceWindow.InitStageDisplay(m_ProjRstData.GetStageHolder(), m_ProjRstData.GetSEMStageData()); } } else { log.Error("(OTSIncAMeasureAppForm.rbSelectDlg_Click) this.CheckMeasureSysFileExist() = false"); } } else { log.Error("(OTSIncAMeasureAppForm.rbSelectDlg_Click) (m_DataMgrFun.CheckParamFile() && m_DataMgrFun.CheckStageFile()) = false"); } } } // 主Windows框右下角显示鼠标点的SEM坐标(样品台) public void ShowSemCoordvAL(string sSemCoord) { STSemCoordinate.Text = sSemCoord; statusStrip1.Refresh(); } //// 主Windows框右下角显示鼠标点的灰度值(测量图) public void ShowGrayVal(string sGrayVal) { TSGrayVal.Text = sGrayVal; statusStrip1.Refresh(); } //获取工作样品测量锁 public bool GetWorkSampleParamLock(ref CTreeSampleParam TSParamLock) { OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(), m_ProjParam.GetDefaultParam().GetSysType()); TSParamLock = SMInfo.TSampleParam; return true; } /// /// 更新属性窗口 /// public void UpdatePropertyVal() { //获取新的工作样品属性值 OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(), m_ProjParam.GetDefaultParam().GetSysType()); m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo); } private void ribbonOrbMenuItemSaveAs_Click(object sender, EventArgs e) { bool iRev = m_ProjRstData.SaveAs(); if (!iRev) { return; } foreach (var spl in m_ProjParam.MeasureSampleList) { m_SamplepaceWindow.InitSampleMeasure(spl, 0); } m_SamplepaceWindow.PrepareVisualMeasureField(m_SamplepaceWindow.GetWorkingVisualSample()); m_SamplepaceWindow.InitSampleMeasure(m_ProjParam.GetWorkSample(), 0); } private void rbSaveFile_Click(object sender, EventArgs e) { bool iRev = m_ProjRstData.Save(); if (!iRev) { return; } saveHistoryPrj(m_ProjRstData.GetPathName()); } private void rbCheckParam_Click(object sender, EventArgs e) { //检查样品测量参数 if (m_ProjParam.CheckSampleParam(true)) { string message = table["message7"].ToString(); MessageBox.Show(message, "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void ribReset_Click(object sender, EventArgs e) { //调用样品台窗口中的复位方法 m_SamplepaceWindow.InverseSelectWorkSampleMeasure(); } //绘制圆形测量区域 private void ribCircle_Click(object sender, EventArgs e) { //修改工作样品的测量区域为圆形 m_SamplepaceWindow.DrawCircleMeasure(); } private void rbThreePoints_Click(object sender, EventArgs e) { //修改工作样品的测量区域为圆形 m_SamplepaceWindow.DrawCircleMeasureByThreePoints(); } private void rbRingShape_Click(object sender, EventArgs e) { //修改工作样品的测量区域为圆形 m_SamplepaceWindow.DrawRingShapeArea(); } //绘制矩形测量区域 private void ribRectangle_Click(object sender, EventArgs e) { //修改工作样品的测量区域为矩形 m_SamplepaceWindow.DrawRectangleMeasure(); } private void rbExitApp_Click(object sender, EventArgs e) { this.Close(); } private void rbStart_Click(object sender, EventArgs e) { if (!m_ProjParam.CheckSampleParam(false)) { return; } if (!m_MsrThreadWrapper.BGWorkThreadIsRunning() && !m_MsrThreadWrapper.BgWorkIsPaused()) { m_MsrThreadWrapper.StartBGWorkThread(); SetMeasureRibbonButnStatu(); } else //thread is in pausing state { m_MsrThreadWrapper.SetMeasureThreadStatus(OTS_MSR_THREAD_STATUS.INPROCESS); SetMeasureRibbonButnStatu(); } } public void SetStartMeasureRibbonStatus() { ribView.Enabled = false; SetToolButnStatu(false); //false: 将其他ribbon按钮设置为灰色 //rbPanelFile.Enabled = false; //rbPanelSample.Enabled = false; m_SolutionWindows.Enabled = false; m_SPropertyWindows.Enabled = false; rbStart.Enabled = false; rbStop.Enabled = true; rbCheckParam.Enabled = false; } public void SetToolButnStatu(bool bStatu) { menuNewDocument.Enabled = bStatu; menuOpenprj.Enabled = bStatu; menuSaveprj.Enabled = bStatu; menuSaveAsprj.Enabled = bStatu; menuExitApp.Enabled = bStatu; rbSelectDlg.Enabled = bStatu; } private void rbStop_Click(object sender, EventArgs e) { //如果当前正在测量,则停止测量线程 if (MeasureThreadRunFlag) { //停止测量线程 m_MsrThreadWrapper.SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.STOPPED); } else if (m_MsrThreadWrapper.m_measure.GetMsrThreadStatusobj().GetStatus() == OTS_MSR_THREAD_STATUS.PAUSED) { m_MsrThreadWrapper.SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.STOPPED); foreach (KeyValuePair smpl in m_MsrThreadWrapper.m_measure.mapSmplMsr) { if (smpl.Value.GetSample().GetMsrStatus().GetStatus() == OTS_MSR_SAMPLE_STATUS.PAUSED) { smpl.Value.TheLastWorkOfSampleMeasure(); SetStopMeasureRibbonStatus(); return; } } } } private void rbPause_Click(object sender, EventArgs e) { //如果当前正在测量,则停止测量线程 if (MeasureThreadRunFlag) { //停止测量线程 m_MsrThreadWrapper.SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.PAUSED); } } private void rbRuler_Click(object sender, EventArgs e) { m_SamplepaceWindow.ShowRulerLocation(); } private void rbSmapleName_Click(object sender, EventArgs e) { //m_SamplepaceWindow.ChangeSampleHoleFont(); } private void rbSmaplePhoto_Click(object sender, EventArgs e) { m_SamplepaceWindow.ChangeSampleHoleImage(); } //当点击Ribbon停止按钮时,设置Ribbon状态 public void SetStopMeasureRibbonStatus() { ribView.Enabled = true; SetToolButnStatu(true); rbPanelFile.Enabled = true; rbPanelSample.Enabled = true; SetMeasureRibbonButnStatu(); m_SolutionWindows.Enabled = true; m_SPropertyWindows.Enabled = true; rbStart.Enabled = true; rbPause.Enabled = false; rbStop.Enabled = false; rbCheckParam.Enabled = true; //激活跳转至报告程序按钮 rbPReport.Enabled = true; rbReport.Enabled = true; } public void SetPauseMeasureRibbonStatus() { ribView.Enabled = true; SetToolButnStatu(true); rbPanelFile.Enabled = true; rbPanelSample.Enabled = true; SetMeasureRibbonButnStatu(); m_SolutionWindows.Enabled = true; m_SPropertyWindows.Enabled = true; rbStart.Enabled = true; rbPause.Enabled = false; rbStop.Enabled = true; rbCheckParam.Enabled = false; //激活跳转至报告程序按钮 rbPReport.Enabled = true; rbReport.Enabled = true; } public bool SwitchDisplayMeasureSample(string sMsrSampleName) { OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(), m_ProjParam.GetDefaultParam().GetSysType()); m_SolutionWindows.SwitchSample(sMsrSampleName); m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo); return true; } #region 开始获取样品孔中的照片 /// /// 开始获取样品孔中的照片 /// /// /// /// public void StartSampleHoleBSEImage() { if (!m_MsrThreadWrapper.BGWorkThreadIsRunning()) { m_MsrThreadWrapper.StartBGWorkThread(); SetMeasureRibbonButnStatu(); } } #endregion private void rbRecover_Click(object sender, EventArgs e) { //关闭所有内容 CloseAllContents(); //显示样品属性窗口与树结构窗口 m_SolutionWindows.Show(dockPanel, DockState.DockLeft); m_SPropertyWindows.Show(dockPanel); //显示样品台窗口 测量状态与测量结果窗口 m_SamplepaceWindow.Show(dockPanel); m_MessureStatuWindow.Show(dockPanel); m_MeasureResultWindow.Show(dockPanel); //此处将在父窗体选项卡上显示 foreach (Form child in this.MdiChildren) { if (child.Name == "OTSSamplespaceWindow") { child.Activate(); break; } } } private void CloseAllContents() { m_SolutionWindows.DockPanel = null; m_SPropertyWindows.DockPanel = null; m_SamplepaceWindow.DockPanel = null; m_MessureStatuWindow.DockPanel = null; m_MeasureResultWindow.DockPanel = null; CloseAllDocuments(); } private void CloseAllDocuments() { if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi) { foreach (Form form in MdiChildren) form.Close(); } else { IDockContent[] documents = dockPanel.DocumentsToArray(); foreach (IDockContent content in documents) content.DockHandler.Close(); } } private void rbMeasureCircle_Click(object sender, EventArgs e) { m_ProjParam.SetMeasureAreaShape(ShapeType.CIRCLE); //修改工作样品的测量区域为圆形 m_SamplepaceWindow.changeShape(ShapeType.CIRCLE); } private void rbMeasureRectangle_Click(object sender, EventArgs e) { m_ProjParam.SetMeasureAreaShape(ShapeType.RECTANGLE); //修改工作样品的测量区域为矩形 m_SamplepaceWindow.changeShape(ShapeType.RECTANGLE); } //ctrl+s组合键进行保存 private void OTSIncAMeasureAppForm_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.S && e.Modifiers == Keys.Control) { bool iRev = m_ProjRstData.Save(); if (!iRev) { log.Error("(OTSIncAMeasureAppForm.rbSaveFile_Click) m_DataMgrFun.SaveFile() Failed !"); return; } log.Error("(OTSIncAMeasureAppForm.rbSaveAs_Click) m_DataMgrFun.SaveFile() Success !"); } } private void rbSTDEdit_Click_1(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "(*.db)|*.db"; openFileDialog.InitialDirectory = Application.StartupPath + "\\Config\\SysData\\"; openFileDialog.RestoreDirectory = true; openFileDialog.FilterIndex = 1; if (openFileDialog.ShowDialog() == DialogResult.OK) { try { System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSPartA_STDEditor.exe", "\"" + openFileDialog.FileName + "\""); p.WaitForExit(); } catch (Exception ex) { log.Error("OTSPartA_STDEditor:" + ex.ToString()); } } //reload the setup data just now foreach (var s in this.m_ProjRstData.GetSampleList()) { var stdname = s.GetMsrParams().GetSTDName(); if (stdname != "NoSTDDB") { if (!stdname.Contains(".db")) { stdname += ".db"; } var m_classifyEngine = new COTSClassifyEngineClr(EngineType.ExpressionClassifyEng, stdname); m_classifyEngine.ReloadEngineDB(); } } } private void rbSysMgrApp_Click(object sender, EventArgs e) { try { System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSSysMgrApp.exe"); p.WaitForExit(); } catch (Exception ex) { log.Error("OTSSysMgrApp:" + ex.ToString()); } } private void ribPolygon_Click(object sender, EventArgs e) { //修改工作样品的测量区域为矩形 m_SamplepaceWindow.DrawPolygonMeasure(); } /// /// 打开测量项目文件 /// private void OpenMeasureProjectFile(string strPathName = "") { if (strPathName == "") { //string strPathName; // file open dialog OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Probject Files (*.prj)|*.prj"; openFileDialog.InitialDirectory = historyPrj.GetLatestPrjFolder(); if (openFileDialog.ShowDialog() != DialogResult.OK) { return; } strPathName = openFileDialog.FileName; } COTSMsrPrjResultData ProjDataMgr = new COTSMsrPrjResultData(); bool bOpenFlag = false; this.Cursor = Cursors.WaitCursor; if (ProjDataMgr.Load(strPathName)) { m_ProjRstData = ProjDataMgr; m_ProjParam.SetResultData(m_ProjRstData); m_ProjParam.InitResultData(); bOpenFlag = true; } this.Cursor = Cursors.Default; if (bOpenFlag) { if (!DisplayExistSampleFile()) { log.Error("(OTSIncAMeasureAppForm.rbOpen_Click) OpenExistSampleFile() = false Failed !"); return; } SetAllRibbonButnStatus(true); } else { log.Error("(OTSIncAMeasureAppForm.rbOpen_Click) m_DataMgrFun.OpenExistSampleFile() Failed !"); } } private void OTSIncAMeasureAppForm_FormClosed(object sender, FormClosedEventArgs e) { } private void rbAbout_Click(object sender, EventArgs e) { var SystemType = m_ProjParam.GetDefaultParam().SystemTypeId; if (SystemType == OTS_SysType_ID.IncA) { OTSSplashScreen_IncA m_about = new OTSSplashScreen_IncA(); m_about.TopMost = false; m_about.ShowInTaskbar = true; m_about.Show(); } else if (SystemType == OTS_SysType_ID.TCCleannessA || SystemType == OTS_SysType_ID.BatteryCleannessA) { OTSSplashScreen_Cleanness m_about = new OTSSplashScreen_Cleanness(); m_about.TopMost = false; m_about.ShowInTaskbar = true; m_about.Show(); } else if (SystemType == OTS_SysType_ID.SteelMineral) { OTSSplashScreen_SteelMineral m_about = new OTSSplashScreen_SteelMineral(); m_about.TopMost = false; m_about.ShowInTaskbar = true; m_about.Show(); } } protected override void DefWndProc(ref Message m) { switch (m.Msg) { case MsgID: break; case LogMsgID: m_LogMsg = new PostLogMsg(); m_LogMsg = (PostLogMsg)Marshal.PtrToStructure(m.LParam, typeof(PostLogMsg)); var log = NLog.LogManager.GetCurrentClassLogger(); string s = GetString(m_LogMsg.logMessage); switch (m_LogMsg.logLevel) { case 1: log.Trace(s); break; case 2: log.Debug(s); break; case 3: log.Info(s); break; case 4: log.Warn(s); break; case 5: log.Error(s); break; case 6: log.Fatal(s); break; } break; default: base.DefWndProc(ref m); break; } } private string GetString(char[] csStr) { int ilen = csStr.Length; string csName = new string(csStr); //MSTMsg.STMSampleStu.cSName csName.IndexOf('\0'); csName = csName.Substring(0, csName.IndexOf('\0')); return csName; } private void PrepareIpcServer() { //Instantiate our server channel. IpcServerChannel channel = new IpcServerChannel("ServerChannel"); //Register the server channel. ChannelServices.RegisterChannel(channel, false); //Register this service type. RemotingConfiguration.RegisterWellKnownServiceType(typeof(IpcSEMController), "RemoteObject", WellKnownObjectMode.Singleton); } private void rbConnectHardware_Click_1(object sender, EventArgs e) { if (!m_MsrThreadWrapper.IsSEMConnected()) { if (!m_MsrThreadWrapper.ConnectSEM()) { MessageBox.Show("Connect failed!"); return; } } this.rbConnectHardware.Enabled = false; this.rbDisconnectHardware.Enabled = true; log.Warn("SEM connect success!"); } private void rbDisconnectHardware_Click_1(object sender, EventArgs e) { if (m_MsrThreadWrapper.IsSEMConnected()) { m_MsrThreadWrapper.DisconnectSEM(); } this.rbDisconnectHardware.Enabled = false; this.rbConnectHardware.Enabled = true; log.Warn("SEM Disconnect!"); } private void rbinterrupt_Click(object sender, EventArgs e) { if (m_MsrThreadWrapper.IsSEMConnected()) { m_MsrThreadWrapper.StopXrayAcquisition(); } log.Warn("StopXrayAcquisition!"); } private void rbAutoBeamOff_Click(object sender, EventArgs e) { if (m_ProjRstData.GetGenParam().AutoBeamOff) { m_ProjRstData.GetGenParam().AutoBeamOff = false; rbAutoBeamOff.Image = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_off; rbAutoBeamOff.SmallImage = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_off; } else { m_ProjRstData.GetGenParam().AutoBeamOff = true; rbAutoBeamOff.Image = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_on; rbAutoBeamOff.SmallImage = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_on; } } private void OTSIncAMeasureAppForm_Activated(object sender, EventArgs e) { } private void ribbonButton2_Click(object sender, EventArgs e) { frmReclassifyCondition reCon = new frmReclassifyCondition(); reCon.ShowDialog(); this.Cursor = Cursors.WaitCursor; if (reCon.DialogResult == DialogResult.OK) { if (m_ProjRstData.Reclassify(reCon.ignoreUserModify)) { m_ProjRstData.Save(); MessageBox.Show("reclassification success"); } else { MessageBox.Show("reclassification failed"); } } this.Cursor = Cursors.Default; } private void ribonBtnShot_Click(object sender, EventArgs e) { m_SamplepaceWindow.DrawOnlyShotMeasure(); } private void ribbonButton4_Click(object sender, EventArgs e) { m_SamplepaceWindow.DrawRectangleBytTwoPoint(); } private void OTSIncAMeasureAppForm_DragEnter(object sender, DragEventArgs e) { try { // 检查拖放的数据是否包含文件 if (e.Data.GetDataPresent(DataFormats.FileDrop)) { // 获取拖放的文件 string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); // 检查是否有有效的.prj文件 bool hasValidFile = files.Any(f =>!string.IsNullOrEmpty(Path.GetExtension(f)) && Path.GetExtension(f).ToLower() == ".prj"); if (hasValidFile) { dropHintPanel.Visible = true; dropHintPanel.BringToFront(); e.Effect = DragDropEffects.Copy; return; } } } catch (Exception ex) { log?.Warn($"DragEnter处理异常: {ex.Message}"); } dropHintPanel.Visible = false; e.Effect = DragDropEffects.None; } private void OTSIncAMeasureAppForm_DragDrop(object sender, DragEventArgs e) { dropHintPanel.Visible = false; try { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); string prjFile = files.FirstOrDefault(f =>!string.IsNullOrEmpty(Path.GetExtension(f)) &&Path.GetExtension(f).ToLower() == ".prj"); if (!string.IsNullOrEmpty(prjFile)) { if(menuOpenprj.Enabled) { this.Cursor = Cursors.WaitCursor; try { OpenMeasureProjectFile(prjFile); } finally { this.Cursor = Cursors.Default; } } else { MessageBox.Show("测量程序只能打开一个 .prj 项目文件", "提示",MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("请拖拽有效的 .prj 项目文件", "提示",MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { this.Cursor = Cursors.Default; log?.Error($"处理拖拽文件时发生错误: {ex.Message}", ex); MessageBox.Show($"处理文件时发生错误: {ex.Message}", "错误",MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void InitializeDropHintPanel() { dropHintPanel = new Panel(); dropHintPanel.Name = "dropHintPanel"; dropHintPanel.BackColor = Color.FromArgb(180, Color.RoyalBlue); dropHintPanel.Dock = DockStyle.Fill; dropHintPanel.Visible = false; dropHintPanel.BorderStyle = BorderStyle.None; Label hintLabel = new Label(); hintLabel.Text = "拖拽 .prj 文件到此处打开项目"; hintLabel.AutoSize = false; hintLabel.TextAlign = ContentAlignment.MiddleCenter; hintLabel.Font = new Font(this.Font.FontFamily, 18, FontStyle.Bold); hintLabel.ForeColor = Color.White; hintLabel.Dock = DockStyle.Fill; hintLabel.BackColor = Color.Transparent; Label subLabel = new Label(); subLabel.Text = "Release mouse button to open the file"; subLabel.AutoSize = false; subLabel.TextAlign = ContentAlignment.MiddleCenter; subLabel.Font = new Font(this.Font.FontFamily, 12, FontStyle.Regular); subLabel.ForeColor = Color.LightGray; subLabel.Dock = DockStyle.Bottom; subLabel.Height = 30; subLabel.BackColor = Color.Transparent; dropHintPanel.Controls.Add(hintLabel); dropHintPanel.Controls.Add(subLabel); this.Controls.Add(dropHintPanel); dropHintPanel.BringToFront(); } private void OTSIncAMeasureAppForm_DragLeave(object sender, EventArgs e) { dropHintPanel.Visible = false; } private void OTSIncAMeasureAppForm_DragOver(object sender, DragEventArgs e) { if (dropHintPanel.Visible){e.Effect = DragDropEffects.Copy;} else{e.Effect = DragDropEffects.None;} } private void rbFixedpoint_Click(object sender, EventArgs e) { m_SamplepaceWindow.DrawCircleByFixedpoint(); } } }