12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Windows.Forms;
- using OTS.WinFormsUI.Docking;
- using System.Runtime.InteropServices;
- using System.Collections;
- using OTSDataType;
- using OTSModelSharp;
- using OTSModelSharp.ResourceManage;
- using static OTSDataType.otsdataconst;
- using System.Diagnostics;
- using OTSModelSharp.ServiceCenter;
- //using OTSMeasureApp._0_OTSModel.Measure.ParamData;
- using OTSCLRINTERFACE;
- using System.IO;
- using System.Management;
- using System.Xml;
- using System.Linq;
- using System.Text;
- using System.Runtime.Remoting.Channels.Ipc;
- using System.Runtime.Remoting.Channels;
- using System.Runtime.Remoting;
- using OTSMeasureApp.ServiceCenter;
- namespace OTSMeasureApp
- {
- public enum ShapeType
- {
- CIRCUL = 0, //圆形
- RECTANGLE = 1 //矩形
- };
-
- enum MessageBoxRev
- {
- DIALOG_YES = 0,
- DIALOG_NO = 1,
- DIALOG_CANCEL = 2
- }
- public partial class OTSIncAMeasureAppForm : Form
- {
- 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;
- public OTSRibbonFun m_RibbonFun = null;
- // 初始化日志类
- NLog.Logger log ;
- private PostLogMsg m_LogMsg;
- public const int MsgID = 0x0464;
- public const int LogMsgID = 0x0465;
- // Control m_ControlWindow = null;
- 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(); }
- public MSR_RUN_TYPE GetRunType()
- {
- return m_MsrThreadWrapper.GetDoRunType();
- }
- public void SetRunType(MSR_RUN_TYPE value)
- {
- m_MsrThreadWrapper.SetDoRunType(value);
- }
- public FileSystemWatcher fileWatcher = new FileSystemWatcher(Application.StartupPath+ @"\Config\SysData");
- public OTSIncAMeasureAppForm()
- {
- 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();
- //初始化Ribbon类,操作Ribbon按钮的可用或者不可用
- m_RibbonFun = new OTSRibbonFun(this);
- //初始化测量线程
- m_MsrThreadWrapper = new CMeasureThreadWrapper(this);//must be the last sentence of this procedure.
- fileWatcher.Changed += FileWatcher_Changed;
-
- fileWatcher.EnableRaisingEvents=true;
- }
- private void FileWatcher_Changed(object sender, FileSystemEventArgs e)
- {
- if (e.Name == "SpecialGrayConfig.xml")
- {
- m_ProjParam.SpecialRanges.IsInited = false;
- foreach (var s in this.m_ProjRstData.GetSampleList())
- {
- s.GetMsrParams().GetSpecialGrayRangeParam().IsInited = false;
- }
- }
- }
- private void OTSIncAMeasureAppForm_Load(object sender, EventArgs e)
- {
- try
- {
- ArrangWorkspaceWindow();
- log = NLog.LogManager.GetCurrentClassLogger();
-
- if (m_ProjParam.LoadParamFile() && m_ProjParam.LoadStageParamFile())
- {
- m_ProjParam.LoadSpecialGrayRangeParamFile();
-
- if (m_ProjParam.InitResultData())
- {
- m_RibbonFun.SetAllRibbonButnStatus(true);
-
- m_SamplepaceWindow.InitStageDisplay(m_ProjRstData.GetStage(),m_ProjRstData.GetSEMStageData());
- //添加启动系统界面显示
- if (m_ProjParam.GetDefaultParam().SystemTypeId == OTS_SysType_ID.IncA)
- {
- this.Text += "(Inclusion)";
- }
- else if (m_ProjParam.GetDefaultParam().SystemTypeId == OTS_SysType_ID.CleannessA)
- {
- this.Text += "(Cleanness)";
- }
-
- }
- else
- {
- log.Error(" InitResultData() failed");
- }
-
- }
- 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());
- }
-
- }
- 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();
- }
- private void rbReport_Click(object sender, EventArgs e)
- {
-
- //测量结果文件路径列表
- List<string> mrFilePathList = new List<string>();
- //获取测量结果文件路径列表
- 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;
- }
- // 设置 开始 ,停止 和检查参数 按钮状态
- m_RibbonFun.SetMeasureRibbonButnStatu();
- //修改Grid工作样品的SWITCH值
- OTSSampleVisualPropertyInfo SMeasurenfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(),m_ProjParam.GetDefaultParam().GetSysType());
-
- m_SPropertyWindows.DisplaySampleMeasureInfo(SMeasurenfo);
- }
-
- 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();
- //UpdatePropertyVal();
- }
- //新建样品工作文件
- 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_RibbonFun.SetAllRibbonButnStatus(true);
- //清除TREEVIEW和GRID上的显示的已经保存的样品信息
- m_SolutionWindows.m_TreeViewBase.DeleteAllTreeNode();
- m_SPropertyWindows.m_SampleGrid.HideGrid();
- //设置报告按钮
- rbPReport.Enabled = false;
- rbReport.Enabled = false;
- rbReClassify.Enabled = true;
- //新建项目时,设置属性窗体中的两个按钮也为不可用状态
- m_SPropertyWindows.TSLoad.Enabled = false;
- m_SPropertyWindows.TSSaveAs.Enabled = false;
- //绘制样品台
- m_SamplepaceWindow.InitStageDisplay(m_ProjRstData.GetStage(), 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<CTreeSampleParam> TSampleParamList = new List<CTreeSampleParam>();
- List<SampleMeasurePara> SampleMeasureParaList = new List<SampleMeasurePara>();
-
- 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.GetStage(), m_ProjRstData.GetSEMStageData());
- m_SamplepaceWindow.DisplayExistSamples( SampleMeasureParaList);
-
- m_MeasureResultWindow.UpdateResultInfoBySampleName(sWSampleName);
- return true;
- }
- public bool InitExistSampleMeasureParam(ref List<SampleMeasurePara> 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 DeleteSample(string sDeleteWSampleName = "")
- {
- if (m_MsrThreadWrapper.m_measure.mapSmplMsr.ContainsKey(sDeleteWSampleName))
- {
- m_MsrThreadWrapper.m_measure.mapSmplMsr.Remove(sDeleteWSampleName);
- }
- m_ProjParam.DeleteWorkSample(sDeleteWSampleName);
-
- // 设置 开始 ,停止 和检查参数 按钮状态
- m_RibbonFun.SetMeasureRibbonButnStatu();
- //设置 删除,复位,圆形,矩形 按钮状态
- m_RibbonFun.SetSampleRibbonButnStatus();
- // 更新报告ribbon按钮状态
- m_RibbonFun.SetAllRibbonButnStatus(true);
- int iSampleCount = m_ProjParam.GetSampleCount();
- if (0 == iSampleCount)
- {
- //给工作样品台发送删除样品和新的工作样品名称
- m_SamplepaceWindow.DeleteWorkSample(sDeleteWSampleName);
-
- m_SPropertyWindows.PropGrid.Hide();
- m_SolutionWindows.treeView1.Nodes.Clear();
- m_MessureStatuWindow.HideXRayTable();
- 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)
- {
- // 设置 开始 ,停止 和检查参数 按钮状态
- m_RibbonFun.SetMeasureRibbonButnStatu();
- log.Error("(OTSIncAMeasureAppForm.AddNewSample) m_DataMgrFun.AddNewSample(sSampleHoleName) = null ");
- return;
- }
- m_SPropertyWindows.TSSaveAs.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);
- // 设置 开始 ,停止 和检查参数 按钮状态
- m_RibbonFun.SetMeasureRibbonButnStatu();
- //设置 删除,复位,圆形,矩形 按钮状态
- m_RibbonFun.SetSampleRibbonButnStatus();
- //清空帧图信息
- SetRunType(MSR_RUN_TYPE.RUNMEASURE);
-
- }
- public void InitCurrentSampleState()
- {
-
- OTSSampleVisualPropertyInfo SMInfo = m_ProjParam.GetWorkingSampleVisualPropertyInfo();
- if (null == SMInfo)
- {
- // 设置 开始 ,停止 和检查参数 按钮状态
- m_RibbonFun.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);
-
- // 设置 开始 ,停止 和检查参数 按钮状态
- m_RibbonFun.SetMeasureRibbonButnStatu();
- //设置 删除,复位,圆形,矩形 按钮状态
- m_RibbonFun.SetSampleRibbonButnStatus();
- //清空帧图信息
- SetRunType(MSR_RUN_TYPE.RUNMEASURE);
- }
-
- private void rbSelectDlg_Click(object sender, EventArgs e)
- {
-
- //判断样品台是否有样品,如果有样品则不能设置默认参数
- if (m_ProjParam.GetSampleCount() > 0)
- {
- MessageBox.Show("Cann't setup preference parameter,for you have added some samples!");
- return;
- }
- ProgMgrInfoForm ProgMgrForm = new ProgMgrInfoForm();
-
- if (DialogResult.OK == ProgMgrForm.ShowDialog())
- {
-
- if (m_ProjParam.LoadParamFile() && m_ProjParam.LoadStageParamFile())
- {
-
- if (m_ProjParam.InitResultData())
- {
- m_RibbonFun.SetAllRibbonButnStatus(true);
- //当样品台上有样品,则不更新样品台数据
- if (0 == m_ProjParam.GetSampleCount())
- {
-
-
- m_SamplepaceWindow.InitStageDisplay(m_ProjRstData.GetStage(), 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;
- }
-
- /// <summary>
- /// 更新属性窗口
- /// </summary>
- 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;
- }
- m_ProjParam.InitWorkingSampleData(0);
- this.InitCurrentSampleState();
- m_MeasureResultWindow.SetInit();
- m_SamplepaceWindow. PrepareMeasureField(m_SamplepaceWindow.GetWorkingVisualSample(), MSR_RUN_TYPE.RUNMEASURE);
- }
- private void rbSaveFile_Click(object sender, EventArgs e)
- {
- bool iRev = m_ProjRstData.Save();
- if (!iRev)
- {
-
- return;
- }
- }
- 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.ResetWorkSampleMeasure();
- }
- //绘制圆形测量区域
- 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())
- {
- SetRunType(MSR_RUN_TYPE.RUNMEASURE);
-
- m_MsrThreadWrapper.StartBGWorkThread();
- m_RibbonFun.SetMeasureRibbonButnStatu();
- }
- else //thread is in pausing state
- {
- SetRunType(MSR_RUN_TYPE.RUNMEASURE);
-
- m_MsrThreadWrapper.SetMeasureThreadStatus(OTS_MSR_THREAD_STATUS.INPROCESS);
- m_RibbonFun.SetMeasureRibbonButnStatu();
- }
- }
- public void SetStartMeasureRibbonStatus()
- {
-
- ribView.Enabled = false;
- m_RibbonFun.SetToolButnStatu(false);
- //false: 将其他ribbon按钮设置为灰色
- rbPanelFile.Enabled = false;
- rbPanelSample.Enabled = false;
- m_SolutionWindows.Enabled = false;
- m_SPropertyWindows.Enabled = false;
- rbStart.Enabled = false;
- //rbPause.Enabled = true;
- rbStop.Enabled = true;
- rbCheckParam.Enabled = false;
- }
- 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.GetMsrThreadStatus() .GetStatus()== OTS_MSR_THREAD_STATUS.PAUSED)
- {
- foreach (KeyValuePair<string, CSmplMeasure> smpl in m_MsrThreadWrapper.m_measure.mapSmplMsr)
- {
- if (smpl.Value.GetSample().GetMsrStatus().GetStatus() == OTS_MSR_SAMPLE_STATUS.PAUSED)
- {
- smpl.Value.TheLastWorkOfSampleMeasure();
- 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;
- m_RibbonFun.SetToolButnStatu(true);
- rbPanelFile.Enabled = true;
- rbPanelSample.Enabled = true;
- m_RibbonFun.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;
- m_RibbonFun.SetToolButnStatu(true);
- rbPanelFile.Enabled = true;
- rbPanelSample.Enabled = true;
- m_RibbonFun.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 开始获取样品孔中的照片
- /// <summary>
- /// 开始获取样品孔中的照片
- /// </summary>
- /// <param name="doRunType"></param>
- /// <param name="HoleID"></param>
- /// <param name="c_DomainMessure"></param>
- public void StartSampleHoleBSEImage()
- {
-
- if (!m_MsrThreadWrapper.BGWorkThreadIsRunning())
- {
-
- m_MsrThreadWrapper.StartBGWorkThread();
- m_RibbonFun.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.CIRCUL);
- //修改工作样品的测量区域为圆形
- m_SamplepaceWindow.changeShape(ShapeType.CIRCUL);
- }
- 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 rbReClassify_Click(object sender, EventArgs e)
- {
- this.Cursor = Cursors.WaitCursor;
- if (m_ProjRstData.Reclassify())
- {
- m_ProjRstData.Save();
- MessageBox.Show("reclassification success");
- }
- else
- {
- MessageBox.Show("reclassification failed");
- }
- this.Cursor = Cursors.Default;
- }
- /// <summary>
- /// 打开测量项目文件
- /// </summary>
- private void OpenMeasureProjectFile()
- {
-
- bool bOpenFlag=false;
- COTSMsrPrjResultData ProjDataMgr = new COTSMsrPrjResultData();
- string strPathName;
-
-
- // file open dialog
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "Probject Files (*.prj)|*.prj";
- if (openFileDialog.ShowDialog() != DialogResult.OK)
- {
- return ;
- }
- strPathName = openFileDialog.FileName;
- 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;
- }
- m_RibbonFun.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)
- {
- About m_about = new About();
- m_about.ShowDialog();
- }
- 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)
- {
-
- }
- }
- }
|