| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224 | 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 CefSharp;using OTSDataType;using OTSModelSharp;using OTSModelSharp.ResourceManage;using static OTSDataType.otsdataconst;using System.Diagnostics;using OTSModelSharp.ServiceInterface;namespace OTSMeasureApp {  public  enum MessageState    {        StartMeasure = 0,       //开始测量        ShotBSEPicture = 1,      //拍摄样品孔图片        MeasureBSEPicture = 2     //拍摄测量区域图片    };    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 = "未知工作窗口";        //国际化        OTSSysMgrTools.Language lan;        Hashtable table;        public  OTSRibbonFun m_RibbonFun = null;        //判断信息来源  拍摄样品孔图片 或是 测量开始        public MessageState m_MessageStates = (int)MessageState.StartMeasure;        // 初始化日志类               NLog.Logger log ;              //  Control m_ControlWindow = null;        public OTSMeasureResultWindow m_MeasureRetWindow = null;        public OTSMeasureStatusWindow m_MessureStatuWindow = null;        public OTSSamplespaceWindow m_SamplepaceWindow = null;        public OTSMeasureOutputNlog m_OTSMeasureOutputNlog = null;                    public COTSMeasureParam m_ProjParam = null;        public COTSMsrPrjResultData m_ProjData;        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 OTSIncAMeasureAppForm()        {            InitializeComponent();            //国际化            lan = new OTSSysMgrTools.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_MeasureRetWindow = new OTSMeasureResultWindow(this);            m_MeasureRetWindow.Text = m_MeasureRetWindowName;            m_MessureStatuWindow = new OTSMeasureStatusWindow(this);            m_MessureStatuWindow.Text = m_MeasureStauWindowName;            m_SamplepaceWindow = new OTSSamplespaceWindow(this);            m_SamplepaceWindow.Text = m_SamplespaceWindowName;                 //和DataMgr进行数据交互类            m_ProjParam = new COTSMeasureParam(this);            m_ProjData = m_ProjParam.m_ResultData;            //初始化Ribbon类,操作Ribbon按钮的可用或者不可用            m_RibbonFun = new OTSRibbonFun(this);            //初始化测量线程            m_MsrThreadWrapper = new CMeasureThreadWrapper(this);//must be the last sentence of this procedure.        }        private void OTSIncAMeasureAppForm_Load(object sender, EventArgs e)        {                       try            {                ArrangWorkspaceWindow();                log = NLog.LogManager.GetCurrentClassLogger();                            if (m_ProjParam.LoadParamFile() && m_ProjParam.LoadStageParamFile())                {                    if (m_ProjParam.InitResultData())                    {                        m_RibbonFun.SetAllRibbonButnStatus(true);                                       m_SamplepaceWindow.InitStageDisplay(m_ProjData.GetStage(),m_ProjData.GetSEMStageData());                        //添加启动系统界面显示                        if (m_ProjParam.m_DefaultParam.m_nPackId.ToString() == "IncA")                        {                            this.Text += " -- Inclusion Analysis System";                        }                        else if (m_ProjParam.m_DefaultParam.m_nPackId.ToString() == "CleanlinessA")                        {                            this.Text += " -- Cleanliness Analysis System";                        }                    }                    else                    {                        log.Error("(OTSIncAMeasureAppForm.OTSIncAMeasureAppForm_Load)  this.CheckMeasureSysFileExist() = false");                    }                }                else                {                    log.Error("(OTSIncAMeasureAppForm.OTSIncAMeasureAppForm_Load)  (m_DataMgrFun.CheckParamFile() && m_DataMgrFun.CheckStageFile()) = false");                }            }            catch (Exception ex)            {                log.Error("(OTSIncAMeasureAppForm.OTSIncAMeasureAppForm_Load) OTSIncAMeasureAppForm_Load:" + ex.ToString());            }                   }        public void ArrangWorkspaceWindow()        {            //Show 样品台窗口            m_SamplepaceWindow.Show(dockPanel);            //Show 测量状态窗口             m_MessureStatuWindow.Show(dockPanel);            //Show 测量结果窗口           m_MeasureRetWindow.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 Rev_SoluWindowReqSwitchWSample_Event(string sNewWorkSampleName)        {            if (!m_ProjParam.SetWorkSample(sNewWorkSampleName))            {                m_SolutionWindows.Rev_MeasureApp_SwitchSample_Event(m_ProjParam.GetWorkSampleName());                return;            }            //获取新的样品名称            string sNewName = m_ProjParam.GetWorkSampleName();            if ("" == sNewName)            {                m_SolutionWindows.Rev_MeasureApp_SwitchSample_Event(sNewWorkSampleName);                return;            }            //获取新工作样品属性值            OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();            if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))            {                m_SolutionWindows.Rev_MeasureApp_SwitchSample_Event(sNewWorkSampleName);                return;            }            //设置获取帧图状态            m_MessageStates = (int)MessageState.StartMeasure;            m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);            //发送新的样品名给Treeview            m_SolutionWindows.Rev_MeasureApp_SwitchSample_Event(sNewName);            //发送想你的样品名给Sample            m_SamplepaceWindow.Rev_MeasureApp_SwitchWorkSample_Event(sNewName);            //根据节点设置样品台窗口中所选择的样品名称            OTSSamplespaceWindow.m_SampleSelectName = sNewName;        }        //OTSSolutionWindow 给 MeasureApp 发送样品checkbox发生变化事件        //string sSampleName : 样品名;  bool bCheckBoxStatu:  样品名对应的CheckBox发生变化的值(选中/不选中)        public void Rev_SoluWindowReqCheckBosStatuChange_Event(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值            OTSSamplePropertyInfo SMeasurenfo = new OTSSamplePropertyInfo();            if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMeasurenfo))            {                return;            }            m_SPropertyWindows.DisplaySampleMeasureInfo(SMeasurenfo);        }        // string sSampleOldName  :  样品名原名        //string  sSampleNewName  :   样品名新名        public bool EditWorkSampleName(string sSampleOldName, string sSampleNewName)        {            if (!m_ProjParam.ChangeWorkSampleName(sSampleNewName))            {                return false;            }            // 获取修改名称后的工作样品属性值            OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();            if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))            {                return false;            }            //获取修改名称后的工作样品属性值发送给Grid显示            m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);            //给样品台发送新的工作样品名称            m_SamplepaceWindow.Rev_MeasureApp_ChangeWorkSampleName_Event(sSampleNewName);            return true;        }        //OTSSolutionWindow窗口给MeasureApp窗口添加样品请求        public void Rev_SoluwindowReqAddSample_Event()        {            //Treeview右键点击添加新样品            this.AddNewSampleMeasure();        }        //移动工作样品到其他样品孔,样品孔名称和测量区域都要改变,重新设置工作样品参数        //SampleMeasurePara SMeasurePara:        public SampleMeasurePara SetWorkSamplHoleAndMeasureArea(SampleMeasurePara SMeasurePara)        {            return m_ProjParam.SetWorkSampleHoleNameAndMeasureArea(SMeasurePara);        }        //当 SampleMeasurePara SetWorkSamplHoleAndMeasureArea(SampleMeasurePara SMeasurePara) 移动成功之后,需要调用此函数更新Grid的显示        public void UpdateTreeSampleAndGridSampleVal()        {            OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();            if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))            {                return;            }            //更新Grid的工作样品属性值            m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);        }                // 更新样品属性值        public void UpDataSamplePropVal()        {            OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();            if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))            {                log.Error("(OTSIncAMeasureAppForm.UpDataSamplePropVal)  m_DataMgrFun.GetWorkSamplePropertyVal(m_DataMgrFun.GetWorkSample(), ref SMInfo) = false Failed !");                return;            }            //更新Grid的工作样品属性值            m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);        }        private void OTSIncAMeasureAppForm_FormClosing(object sender, FormClosingEventArgs e)        {            try            {                    if (m_MsrThreadWrapper.BGWorkThreadIsRunning ())    //当前正在测量                {                    e.Cancel = true;                    return;                }                //判断测量结果文件修改后是否保存                if (m_ProjData.IsModified())                {                   string message = table["message2"].ToString();                    DialogResult lsdr = MessageBox.Show(message, "Tip", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);                    if (lsdr == DialogResult.Yes)                    {                        //保存,退出                        m_ProjData.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());            }            //CloseAllContents();                       //m_MsrThreadWrapper.freeHw();            Process.GetCurrentProcess().Kill();                               //Application.ExitThread();            //Application.Exit();        }        //打开指定路径的文件        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_RibbonFun.SetAllRibbonButnStatus(true);            //清除TREEVIEW和GRID上的显示的已经保存的样品信息            m_SolutionWindows.m_TreeViewBase.DeleteAllTreeNode();            m_SPropertyWindows.m_SampleGrid.HideGrid();            //设置报告按钮            rbPReport.Enabled = false;            rbReport.Enabled = false;            rbReClassify.Enabled = false;            //新建项目时,设置属性窗体中的两个按钮也为不可用状态            m_SPropertyWindows.TSLoad.Enabled = false;            m_SPropertyWindows.TSSaveAs.Enabled = false;            //绘制样品台            m_SamplepaceWindow.InitStageDisplay(m_ProjData.GetStage(), m_ProjData.GetSEMStageData());            //隐藏XrayTable控件            m_MessureStatuWindow.HideXRayTable();            //新建时重新初始化结果窗体结果            m_MeasureRetWindow.SetInit();        }        // 新建样品时提示保存样品信息Messagebox         public int ShowSaveInfoMsgBox()        {            string message = table["message4"].ToString();            //    DialogResult.OK            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> SampleMeasureAreaList = new List<SampleMeasurePara>();                    int iSampleCount = m_ProjData.GetSampleList().Count;            if (0 == iSampleCount)            {                return false;            }            for (int i = 0; i < iSampleCount; i++)            {                CTreeSampleParam CTSampleParam = new CTreeSampleParam();                COTSSample SampleClr = (m_ProjData.GetSampleList())[i];                             CTSampleParam.sSampleTitleName = m_ProjData.GetFileName();                CTSampleParam.sWorkSampleName = SampleClr.GetName();                CTSampleParam.bSwitch = SampleClr.GetSwitch();                CTSampleParam.bParamLock = SampleClr.GetParamLock();                TSampleParamList.Add(CTSampleParam);            }                     //获取工作样品            OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();            if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.m_ResultData.GetWorkingSample(), ref SMInfo))            {                log.Error("(OTSIncAMeasureAppForm.OpenExistSampleFile)  m_DataMgrFun.GetSamplePropertyVal(m_DataMgrFun.GetWorkSample(), ref SMInfo) = false Failed !");                return false;            }            // MeasureApp 窗口给 OTSPropertyWindow窗口 Grid显示的样品属性信息            m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);            // MeasureApp 给 OTSSolutionWindow 发送打开已保存的工作样品文件            m_SolutionWindows.Rev_MeasureApp_OpenExistSampleFile_Event(TSampleParamList, SMInfo.TSampleParam);            //MeasureApp 给 OTSSamplespaceWindow 发送已保存的工作样品文件            if (!OpenExistSampleMeasureArea(ref SampleMeasureAreaList))            {                log.Error("(OTSIncAMeasureAppForm.OpenExistSampleFile)  m_DataMgrFun.OpenExistSampleMeasureArea(ref SampleMeasureAreaList) = false Failed !");                return false;            }            //打开已保存的样品后,将所有样品发送给样品台            string sWSampleName = m_ProjParam.GetWorkSampleName();            if (SMInfo.sSampleSoluName != "")            {                string str = table[this.Name.ToLower()].ToString();                //this.Text = str + "-" + SMInfo.sSampleSoluName;                if (m_ProjParam.m_ResultData.m_nPackId.ToString() == "IncA")                {                    this.Text = str + " -- Inclusion Analysis System";                }                else if (m_ProjParam.m_ResultData.m_nPackId.ToString() == "CleanlinessA")                {                    this.Text = str + " -- Cleanliness Analysis System";                }            }            if ("" == sWSampleName)            {                log.Error("(OTSIncAMeasureAppForm.OpenExistSampleFile)  m_DataMgrFun.GetWorkSampleName() = null Failed !");                return false;            }                     m_SamplepaceWindow.Rev_MeasureApp_OpenExistSampleFile_Event(m_ProjData.GetStage(), m_ProjData.GetSEMStageData(), SampleMeasureAreaList, sWSampleName);            return true;        }        public bool OpenExistSampleMeasureArea(ref List<SampleMeasurePara> SampleMeasureAreaList)        {            int iSListCount = m_ProjData.GetSampleList().Count;            if (0 == iSListCount)            {                return false;            }            for (int i = 0; i < iSListCount; i++)            {                SampleMeasurePara SampleMeasureArea = new SampleMeasurePara();                //获取样品的测量区域信息                 //获取样品名称                SampleMeasureArea.sSampleName = (m_ProjData.GetSampleList())[i].GetName();                // 获取测量区域形状                SampleMeasureArea.iShape = (int)(m_ProjData.GetSampleList())[i].GetMsrArea().GetShape();                //获取样品孔名称                SampleMeasureArea.sHoleName = (m_ProjData.GetSampleList())[i].GetSampleHoleName();                //样品测量区域                SampleMeasureArea.MeasureRect = (Rectangle)(m_ProjData.GetSampleList())[i].GetMsrArea().GetRectDomain();                //多边形点集合                SampleMeasureArea.PolygonPointRegion = (m_ProjData.GetSampleList())[i].GetMsrArea().GetPolygonPoint();                List<PointF> PointRegionF = new List<PointF>();                List<Point> PolygonPoint = m_ProjData.GetSampleList()[i].GetMsrArea().GetPolygonPoint();                if (PolygonPoint != null)                {                    foreach (var item in m_ProjData.GetSampleList()[i].GetMsrArea().GetPolygonPoint())                    {                        PointRegionF.Add(new PointF(item.X, item.Y));                    }                }                SampleMeasureArea.PolygonPointRegionF = PointRegionF;                SampleMeasureArea.DrawPolygonPointRegionF = PointRegionF;                SampleMeasureAreaList.Add(SampleMeasureArea);            }            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))            {                //删除样品成功                if (!this.DeleteSample(sWSampleName))                {                    log.Error("(OTSIncAMeasureAppForm.rbDeleteSample_Click)  DeleteSample(sWSampleName) = false Failed, sWSampleName = " + sWSampleName);                    return;                }                //m_MeasureRetWindow.SetInit();                sWSampleName = m_ProjParam.GetWorkSampleName();                if ("" == sWSampleName)                {                    log.Error("(OTSIncAMeasureAppForm.rbDeleteSample_Click)  m_DataMgrFun.GetWorkSampleName() = null Failed");                    return;                }                m_SolutionWindows.m_TreeViewBase.GetTreeWorkSampleNode(sWSampleName);                m_SolutionWindows.treeView1.Focus();            }                    }        //返回删除的工作样品名        public bool DeleteSample(string sDeleteWSampleName = "")        {            if (!m_ProjParam.DeleteWorkSample(sDeleteWSampleName))            {                log.Error("(OTSIncAMeasureAppForm.DeleteSample)  m_DataMgrFun.DeleteWorkSample(sDeleteWSampleName) Failed, sDeleteWSampleName = " + sDeleteWSampleName);                //return false;            }            // 设置 开始 ,停止 和检查参数 按钮状态            m_RibbonFun.SetMeasureRibbonButnStatu();            //设置 删除,复位,圆形,矩形 按钮状态            m_RibbonFun.SetSampleRibbonButnStatus();            // 更新报告ribbon按钮状态            m_RibbonFun.SetAllRibbonButnStatus(true);            int iSampleCount = m_ProjParam.GetSampleCount();            if (0 == iSampleCount)            {                //给工作样品台发送删除样品和新的工作样品名称                m_SamplepaceWindow.Rev_MeasureApp_DeleteWorkSample_Event(sDeleteWSampleName, "");                //清空样品对象列表                if (OTSSamplespaceWindow.m_SampleGDIObjects != null)                {                    //清空样品台窗口中样品、测量区域、帧图、照片位置对象列表                    OTSSamplespaceWindow.m_SampleGDIObjects.Clear();                    OTSSamplespaceWindow.m_MeasureGDIObjects.Clear();                    OTSSamplespaceWindow.m_MeasurePathGDIObjects.Clear();                    m_SamplepaceWindow.ClearImageAndSingleGDIObjects();                }                //样品全部删除完,将Treeview 和Grid 显示内容清空                m_SPropertyWindows.PropGrid.Hide();                m_SolutionWindows.treeView1.Nodes.Clear();                m_MessureStatuWindow.HideXRayTable();                m_MeasureRetWindow.SetInit();                return true;            }            //获取新工作样品名称            string sNewWSName = m_ProjParam.GetWorkSampleName();            if ("" == sNewWSName)            {                log.Error("(OTSIncAMeasureAppForm.DeleteSample)  m_DataMgrFun.GetWorkSampleName() = null Failed");                return true;            }            //获取新的工作样品属性值            OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();            if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))            {                log.Error("(OTSIncAMeasureAppForm.DeleteSample)  m_DataMgrFun.GetSamplePropertyVal(m_DataMgrFun.GetWorkSample(),ref SMInfo) = false Failed");                return false;            }            //给SolutionWindow 发送新的工作样品名称            m_SolutionWindows.Rev_MeasureApp_DeletSample_Event(m_ProjParam.GetWorkSampleName());            //给工作样品台发送删除样品和新的工作样品名称            m_SamplepaceWindow.Rev_MeasureApp_DeleteWorkSample_Event(sDeleteWSampleName, sNewWSName);            // MeasureApp 窗口给 OTSPropertyWindow窗口 Grid显示的样品属性信息            m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);                        return true;        }        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 = "")        {            //样品的属性值            OTSSamplePropertyInfo SamplePropParam ;            SamplePropParam = m_ProjParam.AddNewSampleMeasure(sSampleHoleName);            if (null == SamplePropParam)            {                // 设置 开始 ,停止 和检查参数 按钮状态                m_RibbonFun.SetMeasureRibbonButnStatu();                log.Error("(OTSIncAMeasureAppForm.AddNewSample)  m_DataMgrFun.AddNewSample(sSampleHoleName) = null ");                return;            }            m_SPropertyWindows.TSSaveAs.Enabled = true;            m_SPropertyWindows.TSLoad.Enabled = true;            //给SampleWindow 发送样品信息            OTSSamplePropertyInfo SMInfo = SamplePropParam;            m_SamplepaceWindow.AddOneSampleArea(SMInfo.SMeasurePara);            //给PropWindow 发送工作样品属性信息            m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);            //给SoluWindow 发送样品显示信息            m_SolutionWindows.AddSampleMeasure(SMInfo.TSampleParam);            // 设置 开始 ,停止 和检查参数 按钮状态            m_RibbonFun.SetMeasureRibbonButnStatu();            //设置 删除,复位,圆形,矩形 按钮状态            m_RibbonFun.SetSampleRibbonButnStatus();            //清空帧图信息            m_MessageStates = (int)MessageState.StartMeasure;            m_SamplepaceWindow.ClearImageAndSingleGDIObjects();            m_SamplepaceWindow.Invalidate();        }              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())            {                //m_DataMgrFun.SetSysPartSTDData(ProgMgrForm.GetCPartSTDDataClr());                //检查\\Config\\SysData 是否有OTSProgMgrParam.pmf文件                if (m_ProjParam.LoadParamFile() && m_ProjParam.LoadStageParamFile())                {                    //检查\\Config\\SysData 是否有OTSProgMgrParam.pmf文件                    if (m_ProjParam.InitResultData())                    {                        m_RibbonFun.SetAllRibbonButnStatus(true);                        //当样品台上有样品,则不更新样品台数据                        if (0 == m_ProjParam.GetSampleCount())                        {                            //通过委托事件将样品台数据发送给SamplespaceWindwo                                                      m_SamplepaceWindow.InitStageDisplay(m_ProjData.GetStage(), m_ProjData.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;            //    TSGrayVal.Text = sGrayVal;            statusStrip1.Refresh();        }        //// 主Windows框右下角显示鼠标点的灰度值(测量图)        public void ShowGrayVal(string sGrayVal)        {            TSGrayVal.Text = sGrayVal;            statusStrip1.Refresh();        }               //获取工作样品测量锁        public bool GetWorkSampleParamLock(ref CTreeSampleParam TSParamLock)        {            OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();            if (!m_ProjParam.GetWSampleParaLock(ref SMInfo))            {                return false;            }            TSParamLock = SMInfo.TSampleParam;            return true;        }            /// <summary>        /// 更新属性窗口        /// </summary>        public void UpdatePropertyVal()        {            //获取新的工作样品属性值            OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();            if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))            {                log.Error("(OTSIncAMeasureAppForm.SetSEMData)  m_DataMgrFun.GetSamplePropertyVal(m_DataMgrFun.GetWorkSample(),ref SMInfo) = false Failed");            }            // MeasureApp 窗口给 OTSPropertyWindow窗口 Grid显示的样品属性信息            m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);        }           //获取BSE图        //int iWidth: 宽        //int iHeigh: 高        //byte bImageData: 图像数据        //返回 图像数据长度 = iWidth*iHeigh        //bool bSimulatFlag :  True 仿真状态        public int GetImageData(int iWidth, int iHeight, ref byte[] ImageData, bool bSimulatFlag = false)        {            //获取BSE图片数据            OTSBSEImageFun m_GetBseImage = new OTSBSEImageFun();            return m_GetBseImage.GetScanImage(iWidth, iHeight, ref ImageData);        }        private void ribbonOrbMenuItemSaveAs_Click(object sender, EventArgs e)        {            bool iRev = m_ProjData.SaveAs();            if (!iRev)            {                //log.Trace("(OTSIncAMeasureAppForm.ribbonOrbMenuItemSaveAs_Click)  m_DataMgrFun.SaveAsFile()  Failed !");                return;            }        }        private void rbSaveFile_Click(object sender, EventArgs e)        {            bool iRev = m_ProjData.Save();            if (!iRev)            {                //log.Trace("(OTSIncAMeasureAppForm.rbSaveFile_Click)  m_DataMgrFun.SaveFile()  Failed !");                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.Rev_DDrawCircleMeasure_MeasureAppToSampleWindow_Event();        }        //绘制矩形测量区域        private void ribRectangle_Click(object sender, EventArgs e)        {            //修改工作样品的测量区域为矩形            m_SamplepaceWindow.Rev_DDrawRectangleMeasure_MeasureAppToSampleWindow_Event();        }        private void rbExitApp_Click(object sender, EventArgs e)        {            this.Close();        }        /// <summary>        /// 执行样品孔中照片后台线程        /// </summary>        private void StartSampleHoleImageBGWorkThread()        {                  if (!m_MsrThreadWrapper.BGWorkThreadIsRunning())            {                m_MessageStates = MessageState.ShotBSEPicture;                m_MsrThreadWrapper.SetDoRunType((int)MSR_THREAD_RunSTATUS.RUNSampleHoleImage);                m_MsrThreadWrapper.StartBGWorkThread();                m_RibbonFun.SetMeasureRibbonButnStatu();            }        }         private void rbStart_Click(object sender, EventArgs e)        {            if (!m_ProjParam.CheckSampleParam(false))            {                return;            }            if (!m_MsrThreadWrapper.BGWorkThreadIsRunning())            {                //设置消息类型 拍摄样品孔                m_MessageStates = (int)MessageState.StartMeasure;                m_MsrThreadWrapper.SetDoRunType((int)MSR_THREAD_RunSTATUS.RUNMEASURE);                m_MsrThreadWrapper.StartBGWorkThread();                m_RibbonFun.SetMeasureRibbonButnStatu();            }        }        public void SetStartMeasureRibbonStatus()        {            //this.PropertyMeasureThreadRunFlag = true;            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;            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);            }        }        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()        {            //this.PropertyMeasureThreadRunFlag = false;            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;            rbStop.Enabled = false;            rbCheckParam.Enabled = true;        }              public bool SwitchMeasureSample(string sMsrSampleName)        {            if (!m_ProjParam.SetWorkSample(sMsrSampleName))            {                log.Error("(OTSIncAMeasureAppForm.SwitchMeasureSample)  SetWorkSample(sMsrSampleName =" + sMsrSampleName + ") Failed !");                return false;            }            OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();            if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))            {                log.Error("(OTSIncAMeasureAppForm.SwitchMeasureSample)  m_DataMgrFun.GetSamplePropertyVal(m_DataMgrFun.GetWorkSample(), ref SMInfo) = false Failed !");                return false;            }            // MeasureApp 窗口给 OTSPropertyWindow窗口 Grid显示的样品属性信息            m_SolutionWindows.Rev_MeasureApp_SwitchSample_Event(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(int doRunType, int HoleID, CDomain c_DomainMessure)        {            //线程执行类型 1:测量类型 2:获取样品孔图片类型            m_MsrThreadWrapper.SetDoRunType(doRunType);            //设置获取样品孔中照片所需的参数            m_MsrThreadWrapper.SetHoleImagePreview(HoleID, c_DomainMessure);            StartSampleHoleImageBGWorkThread();        }        #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_MeasureRetWindow.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_MeasureRetWindow.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((int)ShapeType.CIRCUL);            //修改工作样品的测量区域为圆形            m_SamplepaceWindow.changeShape((int)ShapeType.CIRCUL);        }        private void rbMeasureRectangle_Click(object sender, EventArgs e)        {            m_ProjParam.SetMeasureAreaShape((int)ShapeType.RECTANGLE);            //修改工作样品的测量区域为矩形            m_SamplepaceWindow.changeShape((int)ShapeType.RECTANGLE);        }        //ctrl+s组合键进行保存        private void OTSIncAMeasureAppForm_KeyDown(object sender, KeyEventArgs e)        {            if (e.KeyCode == Keys.S && e.Modifiers == Keys.Control)            {                bool iRev = m_ProjData.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());                }            }        }          private void ribPolygon_Click(object sender, EventArgs e)        {            //修改工作样品的测量区域为矩形            m_SamplepaceWindow.Rev_DDrawPolygonMeasure_MeasureAppToSampleWindow_Event();        }        private void rbReClassify_Click(object sender, EventArgs e)        {            if (m_ProjData.Reclassify())            {                m_ProjData.Save();                MessageBox.Show("reclassification success");            }            else            {                MessageBox.Show("reclassification failed");            }        }        /// <summary>        /// 打开测量项目文件        /// </summary>        private void OpenMeasureProjectFile()        {            bool bOpenFlag=false;            COTSMsrPrjResultData ProjDataMgr = new COTSMsrPrjResultData();                        if (ProjDataMgr.Load())            {                m_ProjParam.m_ResultData = ProjDataMgr;                m_ProjParam.InitResultData();                m_ProjData = ProjDataMgr;                bOpenFlag = true;            }                        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();        }    }}
 |