OTSIncAMeasureAppForm.cs 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using OTS.WinFormsUI.Docking;
  6. using System.Runtime.InteropServices;
  7. using System.Collections;
  8. using OTSDataType;
  9. using OTSModelSharp;
  10. using OTSModelSharp.ResourceManage;
  11. using static OTSDataType.otsdataconst;
  12. using System.Diagnostics;
  13. using OTSModelSharp.ServiceCenter;
  14. //using OTSMeasureApp._0_OTSModel.Measure.ParamData;
  15. using OTSCLRINTERFACE;
  16. using System.IO;
  17. using System.Management;
  18. using System.Xml;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Runtime.Remoting.Channels.Ipc;
  22. using System.Runtime.Remoting.Channels;
  23. using System.Runtime.Remoting;
  24. using OTSMeasureApp.ServiceCenter;
  25. using OTSMeasureApp._1_OTSMeasure;
  26. namespace OTSMeasureApp
  27. {
  28. public enum ShapeType
  29. {
  30. CIRCUL = 0, //圆形
  31. RECTANGLE = 1 //矩形
  32. };
  33. enum MessageBoxRev
  34. {
  35. DIALOG_YES = 0,
  36. DIALOG_NO = 1,
  37. DIALOG_CANCEL = 2
  38. }
  39. public partial class OTSIncAMeasureAppForm : Form
  40. {
  41. public static string m_SamplespaceWindowName = "样品台";
  42. public static string m_MeasureStauWindowName = "测量状态";
  43. public static string m_MeasureRetWindowName = "测量结果";
  44. public static string m_NoWindowName = "未知工作窗口";
  45. //国际化
  46. OTSCommon.Language lan;
  47. Hashtable table;
  48. public OTSRibbonFun m_RibbonFun = null;
  49. // 初始化日志类
  50. NLog.Logger log ;
  51. private PostLogMsg m_LogMsg;
  52. public const int MsgID = 0x0464;
  53. public const int LogMsgID = 0x0465;
  54. // Control m_ControlWindow = null;
  55. //public OTSMeasureResultWindow m_MeasureResultWindow = null;
  56. //public OTSMeasureStatusWindow m_MessureStatuWindow = null;
  57. public OTSSamplespaceWindow m_SamplepaceWindow = null;
  58. public OTSMeasureOutputNlog m_OTSMeasureOutputNlog = null;
  59. public SubMidWindow m_SubMidWindow = null;
  60. public COTSMeasureParam m_ProjParam = null;
  61. public COTSMsrPrjResultData m_ProjData;
  62. public OTSSolutionWindow m_SolutionWindows = null;
  63. public OTSPropertyWindow m_SPropertyWindows = null;
  64. //测量线程对象
  65. public CMeasureThreadWrapper m_MsrThreadWrapper = null;
  66. // 测量线程当前状态 True: 正在测量; False: 测量结束
  67. public bool MeasureThreadRunFlag { get => m_MsrThreadWrapper.BGWorkThreadIsRunning(); }
  68. public MSR_RUN_TYPE GetRunType()
  69. {
  70. return m_MsrThreadWrapper.GetDoRunType();
  71. }
  72. public void SetRunType(MSR_RUN_TYPE value)
  73. {
  74. m_MsrThreadWrapper.SetDoRunType(value);
  75. }
  76. public FileSystemWatcher fileWatcher = new FileSystemWatcher(Application.StartupPath+ @"\Config\SysData");
  77. public OTSIncAMeasureAppForm()
  78. {
  79. InitializeComponent();
  80. //国际化
  81. lan = new OTSCommon.Language(this);
  82. table = lan.GetNameTable(this.Name);
  83. m_SamplespaceWindowName = table["m_samplespacewindowname"].ToString();
  84. m_MeasureStauWindowName = table["m_measurestauwindowname"].ToString();
  85. m_MeasureRetWindowName = table["m_measureretwindowname"].ToString();
  86. m_NoWindowName = table["m_nowindowname"].ToString();
  87. m_OTSMeasureOutputNlog = new OTSMeasureOutputNlog();
  88. m_OTSMeasureOutputNlog.Show();
  89. // 初始化Docpanle
  90. m_SolutionWindows = new OTSSolutionWindow(this);
  91. m_SPropertyWindows = new OTSPropertyWindow(this);
  92. m_SubMidWindow = new SubMidWindow();
  93. m_SubMidWindow.m_MeasureResultWindow = new OTSMeasureResultWindow(this);
  94. m_SubMidWindow.m_MeasureResultWindow.Text = m_MeasureRetWindowName;
  95. m_SubMidWindow.m_MessureStatuWindow = new OTSMeasureStatusWindow(this);
  96. m_SubMidWindow.m_MessureStatuWindow.Text = m_MeasureStauWindowName;
  97. m_SamplepaceWindow = new OTSSamplespaceWindow(this);
  98. m_SamplepaceWindow.Text = m_SamplespaceWindowName;
  99. //和DataMgr进行数据交互类
  100. m_ProjParam = new COTSMeasureParam(this);
  101. m_ProjData = m_ProjParam.GetResultData();
  102. //初始化Ribbon类,操作Ribbon按钮的可用或者不可用
  103. m_RibbonFun = new OTSRibbonFun(this);
  104. //初始化测量线程
  105. m_MsrThreadWrapper = new CMeasureThreadWrapper(this);//must be the last sentence of this procedure.
  106. fileWatcher.Changed += FileWatcher_Changed;
  107. fileWatcher.EnableRaisingEvents=true;
  108. }
  109. private void FileWatcher_Changed(object sender, FileSystemEventArgs e)
  110. {
  111. if (e.Name == "SpecialGrayConfig.xml")
  112. {
  113. m_ProjParam.SpecialRanges.IsInited = false;
  114. foreach (var s in this.m_ProjData.GetSampleList())
  115. {
  116. s.GetMsrParams().GetSpecialGrayRangeParam().IsInited = false;
  117. }
  118. }
  119. }
  120. private void OTSIncAMeasureAppForm_Load(object sender, EventArgs e)
  121. {
  122. try
  123. {
  124. ArrangWorkspaceWindow();
  125. log = NLog.LogManager.GetCurrentClassLogger();
  126. if (m_ProjParam.LoadParamFile() && m_ProjParam.LoadStageParamFile())
  127. {
  128. m_ProjParam.LoadSpecialGrayRangeParamFile();
  129. if (m_ProjParam.InitResultData())
  130. {
  131. m_RibbonFun.SetAllRibbonButnStatus(true);
  132. m_SamplepaceWindow.InitStageDisplay(m_ProjData.GetStage(),m_ProjData.GetSEMStageData());
  133. //添加启动系统界面显示
  134. if (m_ProjParam.GetDefaultParam().SystemTypeId == OTS_SysType_ID.IncA)
  135. {
  136. this.Text += "(Inclusion)";
  137. }
  138. else if (m_ProjParam.GetDefaultParam().SystemTypeId == OTS_SysType_ID.CleannessA)
  139. {
  140. this.Text += "(Cleanness)";
  141. }
  142. }
  143. else
  144. {
  145. log.Error(" InitResultData() failed");
  146. }
  147. }
  148. else
  149. {
  150. log.Error("(OTSIncAMeasureAppForm.OTSIncAMeasureAppForm_Load) (LoadParamFile() && LoadStageParamFile()) failed");
  151. }
  152. if (!m_MsrThreadWrapper.ConnectSEM())
  153. {
  154. MessageBox.Show("Connect SEM failed!Please goto the SysMgrApp.exe to setup the proper parameter or check other parameter of the EDS software");
  155. System.Diagnostics.ProcessStartInfo process = new System.Diagnostics.ProcessStartInfo();
  156. process.FileName = "OTSSysMgrApp.exe";//打开app的路径
  157. process.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
  158. System.Diagnostics.Process.Start(process);
  159. this.rbConnectHardware.Enabled = true;
  160. this.rbDisconnectHardware.Enabled = false;
  161. }
  162. this.rbConnectHardware.Enabled = false;
  163. this.rbDisconnectHardware.Enabled = true;
  164. log.Warn("SEM connect success!");
  165. PrepareIpcServer();
  166. log.Info("Ipc server start success!");
  167. //----------------------Test Code, Don't delete
  168. //var f = new BaseFunctionTest();
  169. //f.ShowDialog();
  170. //----------------------
  171. }
  172. catch (Exception ex)
  173. {
  174. log.Error(" OTSIncAMeasureAppForm_Load:" + ex.ToString());
  175. }
  176. }
  177. public void ArrangWorkspaceWindow()
  178. {
  179. //Show 样品台窗口
  180. m_SamplepaceWindow.Show(dockPanel, DockState.Document);
  181. // //Show 测量状态窗口
  182. //m_MessureStatuWindow.Show(dockPanel);
  183. // //Show 测量结果窗口
  184. //m_MeasureResultWindow.Show(dockPanel);
  185. m_SubMidWindow.Show(dockPanel, DockState.DockBottom);
  186. m_SolutionWindows.Show(dockPanel);
  187. //Show 测量过程中Log显示窗口
  188. m_OTSMeasureOutputNlog.Show(dockPanel, DockState.DockRight);
  189. dockPanel.DockRightPortion = 365;
  190. dockPanel.DockBottomPortion = 400;
  191. m_SPropertyWindows.Show(dockPanel);
  192. m_SamplepaceWindow.Activate();
  193. }
  194. private void rbReport_Click(object sender, EventArgs e)
  195. {
  196. //测量结果文件路径列表
  197. List<string> mrFilePathList = new List<string>();
  198. //获取测量结果文件路径列表
  199. bool result = m_ProjParam.GetCompletedMeasureFileName(ref mrFilePathList);
  200. if (result)
  201. {
  202. for (int i = 0; i < mrFilePathList.Count; i++)
  203. {
  204. mrFilePathList[i] = mrFilePathList[i].Replace(" ", "^");
  205. }
  206. //转换为数组
  207. string[] resultFilePath = mrFilePathList.ToArray();
  208. System.Diagnostics.ProcessStartInfo process = new System.Diagnostics.ProcessStartInfo();
  209. process.FileName = "OTSIncAReportApp.exe";//打开app的路径
  210. string FilePath = string.Join(" ", resultFilePath);
  211. process.Arguments = FilePath;//多个参数用空格隔开
  212. process.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
  213. System.Diagnostics.Process.Start(process);
  214. }
  215. }
  216. // sNewWorkSampleName: 新工作样品名
  217. public void SwitchWSample(string sNewWorkSampleName)
  218. {
  219. m_ProjParam.SetWorkSample(sNewWorkSampleName);
  220. m_SolutionWindows.SwitchSample(sNewWorkSampleName);
  221. //获取新工作样品属性值
  222. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(),m_ProjParam.GetDefaultParam().GetSysType());
  223. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  224. //发送想你的样品名给Sample
  225. m_SamplepaceWindow.SwitchWorkSample(sNewWorkSampleName);
  226. }
  227. public void Rev_SoluWindowReqCheckBosStatuChange_Event(string sSampleName, bool bCheckBoxStatu)
  228. {
  229. string sWSampleName = m_ProjParam.GetWorkSampleName();
  230. if ("" == sWSampleName)
  231. {
  232. //不修改Tteeview 的工作样品属性值
  233. m_SolutionWindows.Rev_MeasureApp_CheckboxStatuChange_Event(sSampleName, !bCheckBoxStatu);
  234. return;
  235. }
  236. //Treeview更改的工作样品数的CHECKBOX 状态
  237. if (!m_ProjParam.SetSampleParamVal(OTS_SAMPLE_PROP_GRID_ITEMS.SWITCH, OTS_ITEM_TYPES.BOOL, bCheckBoxStatu))
  238. {
  239. //不修改Tteeview 的工作样品属性值
  240. m_SolutionWindows.Rev_MeasureApp_CheckboxStatuChange_Event(sSampleName, !bCheckBoxStatu);
  241. return;
  242. }
  243. // 设置 开始 ,停止 和检查参数 按钮状态
  244. m_RibbonFun.SetMeasureRibbonButnStatu();
  245. //修改Grid工作样品的SWITCH值
  246. OTSSampleVisualPropertyInfo SMeasurenfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(),m_ProjParam.GetDefaultParam().GetSysType());
  247. m_SPropertyWindows.DisplaySampleMeasureInfo(SMeasurenfo);
  248. }
  249. public bool EditWorkSampleName(string sSampleOldName, string sSampleNewName)
  250. {
  251. if (!m_ProjParam.ChangeWorkSampleName(sSampleNewName))
  252. {
  253. return false;
  254. }
  255. // 获取修改名称后的工作样品属性值
  256. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(),m_ProjParam.GetDefaultParam().GetSysType());
  257. //获取修改名称后的工作样品属性值发送给Grid显示
  258. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  259. //给样品台发送新的工作样品名称
  260. m_SamplepaceWindow.ChangeWorkSampleName(sSampleNewName);
  261. return true;
  262. }
  263. public void SoluwindowReqAddSample()
  264. {
  265. //Treeview右键点击添加新样品
  266. this.AddNewSampleMeasure();
  267. }
  268. private void OTSIncAMeasureAppForm_FormClosing(object sender, FormClosingEventArgs e)
  269. {
  270. try
  271. {
  272. if (m_MsrThreadWrapper.BGWorkThreadIsRunning ()) //当前正在测量
  273. {
  274. e.Cancel = true;
  275. return;
  276. }
  277. if (m_MsrThreadWrapper.IsHavingNotCompleteSamples()) //当前正在测量
  278. {
  279. e.Cancel = true;
  280. MessageBox.Show("There is one sample is still in pausing state,please stop it!");
  281. return;
  282. }
  283. //判断测量结果文件修改后是否保存
  284. if (m_ProjData.IsModified())
  285. {
  286. string message = table["message2"].ToString();
  287. DialogResult lsdr = MessageBox.Show(message, "Tip", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
  288. if (lsdr == DialogResult.Yes)
  289. {
  290. //保存,退出
  291. m_ProjData.Save();
  292. //保存,直接退出
  293. Application.ExitThread();
  294. }
  295. else if (lsdr == DialogResult.No)
  296. {
  297. //不保存,直接退出
  298. Application.ExitThread();
  299. }
  300. else if (lsdr == DialogResult.Cancel)
  301. {
  302. //取消
  303. e.Cancel = true;
  304. return;
  305. }
  306. }
  307. log.Info("Disconnect SEM!");
  308. m_MsrThreadWrapper.DisconnectSEM();
  309. m_MsrThreadWrapper.SetWorkThreadPending();
  310. }
  311. catch (Exception ex)
  312. {
  313. string message = table["message3"].ToString();
  314. log.Error("OTSIncAMeasureAppForm_FormClosing-"+ message + ":" + ex.ToString());
  315. }
  316. Process.GetCurrentProcess().Kill();
  317. }
  318. //打开指定路径的文件
  319. private void ribbonOrbMenuItem1_OpenWorkspace_Click(object sender, EventArgs e)
  320. {
  321. OpenMeasureProjectFile();
  322. //UpdatePropertyVal();
  323. }
  324. //新建样品工作文件
  325. private void ribbonOrbMenuItem3_CreateWorkspace_Click(object sender, EventArgs e)
  326. {
  327. int iCreateNewFileResult = m_ProjParam.CreateNewFile();
  328. if (iCreateNewFileResult == 0)
  329. {
  330. log.Error("(OTSIncAMeasureAppForm.rbNew_CreateWorkspace_Click) m_DataMgrFun.CreateNewFile() Failed !");
  331. return;
  332. }
  333. else if(iCreateNewFileResult == 2)
  334. {
  335. log.Info("(OTSIncAMeasureAppForm.rbNew_CreateWorkspace_Click) m_DataMgrFun.CreateNewFile() Cancel !");
  336. return;
  337. }
  338. m_RibbonFun.SetAllRibbonButnStatus(true);
  339. //清除TREEVIEW和GRID上的显示的已经保存的样品信息
  340. m_SolutionWindows.m_TreeViewBase.DeleteAllTreeNode();
  341. m_SPropertyWindows.m_SampleGrid.HideGrid();
  342. //设置报告按钮
  343. rbPReport.Enabled = false;
  344. rbReport.Enabled = false;
  345. rbReClassify.Enabled = true;
  346. //新建项目时,设置属性窗体中的两个按钮也为不可用状态
  347. m_SPropertyWindows.TSLoad.Enabled = false;
  348. m_SPropertyWindows.TSSaveAs.Enabled = false;
  349. //绘制样品台
  350. m_SamplepaceWindow.InitStageDisplay(m_ProjData.GetStage(), m_ProjData.GetSEMStageData());
  351. //隐藏XrayTable控件
  352. m_SubMidWindow.m_MessureStatuWindow.HideXRayTable();
  353. //新建时重新初始化结果窗体结果
  354. m_SubMidWindow.m_MeasureResultWindow.SetInit();
  355. }
  356. // 新建样品时提示保存样品信息Messagebox
  357. public int ShowSaveInfoMsgBox()
  358. {
  359. string message = table["message4"].ToString();
  360. DialogResult dResult = MessageBox.Show(message, "Tip", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
  361. if (dResult == DialogResult.Yes)
  362. {
  363. return (int)MessageBoxRev.DIALOG_YES;
  364. }
  365. else if (dResult == DialogResult.No)
  366. {
  367. return (int)MessageBoxRev.DIALOG_NO;
  368. }
  369. else
  370. {
  371. return (int)MessageBoxRev.DIALOG_CANCEL;
  372. }
  373. }
  374. //打开已经保存的工作文件
  375. private bool DisplayExistSampleFile()
  376. {
  377. List<CTreeSampleParam> TSampleParamList = new List<CTreeSampleParam>();
  378. List<SampleMeasurePara> SampleMeasureAreaList = new List<SampleMeasurePara>();
  379. int iSampleCount = m_ProjData.GetSampleList().Count;
  380. if (0 == iSampleCount)
  381. {
  382. return false;
  383. }
  384. for (int i = 0; i < iSampleCount; i++)
  385. {
  386. CTreeSampleParam CTSampleParam = new CTreeSampleParam();
  387. COTSSample SampleClr = (m_ProjData.GetSampleList())[i];
  388. CTSampleParam.sSampleTitleName = m_ProjData.GetFileName();
  389. CTSampleParam.sWorkSampleName = SampleClr.GetName();
  390. CTSampleParam.bSwitch = SampleClr.GetSwitch();
  391. //CTSampleParam.bParamLock = SampleClr.GetParamLock();
  392. TSampleParamList.Add(CTSampleParam);
  393. }
  394. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(),m_ProjParam.GetDefaultParam().GetSysType());
  395. //if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetResultData().GetWorkingSample(), ref SMInfo))
  396. //{
  397. // log.Error("(OTSIncAMeasureAppForm.OpenExistSampleFile) m_DataMgrFun.GetSamplePropertyVal(m_DataMgrFun.GetWorkSample(), ref SMInfo) = false Failed !");
  398. // return false;
  399. //}
  400. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  401. m_SolutionWindows.OpenExistSampleFile(TSampleParamList, SMInfo.TSampleParam);
  402. if (!OpenExistSampleMeasureArea(ref SampleMeasureAreaList))
  403. {
  404. log.Error(" OpenExistSampleMeasureArea(ref SampleMeasureAreaList) Failed !");
  405. return false;
  406. }
  407. string sWSampleName = m_ProjParam.GetWorkSampleName();
  408. if ("" == sWSampleName)
  409. {
  410. log.Error("(OTSIncAMeasureAppForm.OpenExistSampleFile) m_DataMgrFun.GetWorkSampleName() = null !");
  411. return false;
  412. }
  413. m_SamplepaceWindow.OpenExistSampleFile(m_ProjData.GetStage(), m_ProjData.GetSEMStageData(), SampleMeasureAreaList);
  414. return true;
  415. }
  416. public bool OpenExistSampleMeasureArea(ref List<SampleMeasurePara> SampleMeasureParaList)
  417. {
  418. int iSListCount = m_ProjData.GetSampleList().Count;
  419. if (0 == iSListCount)
  420. {
  421. return false;
  422. }
  423. for (int i = 0; i < iSListCount; i++)
  424. {
  425. SampleMeasurePara SampleMeasureArea = new SampleMeasurePara();
  426. //获取样品的测量区域信息
  427. //获取样品名称
  428. SampleMeasureArea.sSampleName = (m_ProjData.GetSampleList())[i].GetName();
  429. // 获取测量区域形状
  430. SampleMeasureArea.iShape = (ShapeType)m_ProjData.GetSampleList()[i].GetMsrDomain().GetShape();
  431. //获取样品孔名称
  432. SampleMeasureArea.sampleHoleName = (m_ProjData.GetSampleList())[i].GetSampleHoleName();
  433. //样品测量区域
  434. SampleMeasureArea.MeasureRect =(m_ProjData.GetSampleList())[i].GetMsrDomain().GetRectDomain();
  435. //多边形点集合
  436. List<PointF> PointRegionF = new List<PointF>();
  437. List<Point> PolygonPoint = m_ProjData.GetSampleList()[i].GetMsrDomain().GetPolygonPoint();
  438. if (PolygonPoint != null)
  439. {
  440. foreach (var item in m_ProjData.GetSampleList()[i].GetMsrDomain().GetPolygonPoint())
  441. {
  442. PointRegionF.Add(new PointF(item.X, item.Y));
  443. }
  444. }
  445. SampleMeasureArea.DrawPolygonPointList = PointRegionF;
  446. SampleMeasureParaList.Add(SampleMeasureArea);
  447. }
  448. return true;
  449. }
  450. //打开指定路径的文件
  451. private void rbOpen_Click(object sender, EventArgs e)
  452. {
  453. OpenMeasureProjectFile();
  454. }
  455. private void rbDeleteSample_Click(object sender, EventArgs e)
  456. {
  457. //删除样品(样品必须先选中)
  458. string sWSampleName = m_ProjParam.GetWorkSampleName();
  459. if ("" == sWSampleName)
  460. {
  461. log.Error("(OTSIncAMeasureAppForm.rbDeleteSample_Click) m_DataMgrFun.GetWorkSampleName() = null Failed");
  462. return;
  463. }
  464. string message = table["message5"].ToString();
  465. string message6 = table["message6"].ToString();
  466. string sDeleteSampleName = message;
  467. sDeleteSampleName += sWSampleName;
  468. sDeleteSampleName += message6;
  469. if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Tip", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
  470. {
  471. //删除样品成功
  472. DeleteSample(sWSampleName);
  473. sWSampleName = m_ProjParam.GetWorkSampleName();
  474. if ("" != sWSampleName)
  475. {
  476. m_SolutionWindows.m_TreeViewBase.GetTreeWorkSampleNode(sWSampleName);
  477. m_SolutionWindows.treeView1.Focus();
  478. }
  479. }
  480. }
  481. //返回删除的工作样品名
  482. public void DeleteSample(string sDeleteWSampleName = "")
  483. {
  484. if (m_MsrThreadWrapper.m_measure.mapSmplMsr.ContainsKey(sDeleteWSampleName))
  485. {
  486. m_MsrThreadWrapper.m_measure.mapSmplMsr.Remove(sDeleteWSampleName);
  487. }
  488. m_ProjParam.DeleteWorkSample(sDeleteWSampleName);
  489. // 设置 开始 ,停止 和检查参数 按钮状态
  490. m_RibbonFun.SetMeasureRibbonButnStatu();
  491. //设置 删除,复位,圆形,矩形 按钮状态
  492. m_RibbonFun.SetSampleRibbonButnStatus();
  493. // 更新报告ribbon按钮状态
  494. m_RibbonFun.SetAllRibbonButnStatus(true);
  495. int iSampleCount = m_ProjParam.GetSampleCount();
  496. if (0 == iSampleCount)
  497. {
  498. //给工作样品台发送删除样品和新的工作样品名称
  499. m_SamplepaceWindow.DeleteWorkSample(sDeleteWSampleName);
  500. m_SPropertyWindows.PropGrid.Hide();
  501. m_SolutionWindows.treeView1.Nodes.Clear();
  502. m_SubMidWindow.m_MessureStatuWindow.HideXRayTable();
  503. m_SubMidWindow.m_MeasureResultWindow.SetInit();
  504. return ;
  505. }
  506. else
  507. {
  508. string sNewWSName = m_ProjParam.GetWorkSampleName();
  509. if ("" == sNewWSName)
  510. {
  511. log.Error("(OTSIncAMeasureAppForm.DeleteSample) m_DataMgrFun.GetWorkSampleName() = null Failed");
  512. return ;
  513. }
  514. m_SolutionWindows.DeletCurrentSampleNode();
  515. m_SolutionWindows.DisplaySample(sNewWSName);
  516. //将测量状态初始化
  517. m_SubMidWindow.m_MessureStatuWindow.SetMeasureStatusInit();
  518. //给工作样品台发送删除样品和新的工作样品名称
  519. m_SamplepaceWindow.DeleteWorkSample(sDeleteWSampleName);
  520. //设置工作样品
  521. SwitchWSample(sNewWSName);
  522. }
  523. return ;
  524. }
  525. private void rbAddSample_Click(object sender, EventArgs e)
  526. {
  527. this.AddNewSampleMeasure();//the system will choose the empty hole one by one according to the holeNo sequence.
  528. }
  529. public void AddNewSampleMeasure(string sSampleHoleName = "")
  530. {
  531. OTSSampleVisualPropertyInfo SMInfo = m_ProjParam.AddNewSampleMeasure(sSampleHoleName);
  532. if (null == SMInfo)
  533. {
  534. // 设置 开始 ,停止 和检查参数 按钮状态
  535. m_RibbonFun.SetMeasureRibbonButnStatu();
  536. log.Error("(OTSIncAMeasureAppForm.AddNewSample) m_DataMgrFun.AddNewSample(sSampleHoleName) = null ");
  537. return;
  538. }
  539. m_SPropertyWindows.TSSaveAs.Enabled = true;
  540. m_SPropertyWindows.TSLoad.Enabled = true;
  541. m_SPropertyWindows.TSEdit.Enabled = false;
  542. m_SPropertyWindows.TSEdit.Visible = false;
  543. //给SampleWindow 发送样品信息
  544. m_SamplepaceWindow.AddSampleArea(SMInfo.SMeasurePara);
  545. m_SamplepaceWindow.ReadSEMDataAndSetToCurrentSample();
  546. //给PropWindow 发送工作样品属性信息
  547. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  548. //给SoluWindow 发送样品显示信息
  549. m_SolutionWindows.AddSampleMeasure(SMInfo.TSampleParam);
  550. // 设置 开始 ,停止 和检查参数 按钮状态
  551. m_RibbonFun.SetMeasureRibbonButnStatu();
  552. //设置 删除,复位,圆形,矩形 按钮状态
  553. m_RibbonFun.SetSampleRibbonButnStatus();
  554. //清空帧图信息
  555. SetRunType(MSR_RUN_TYPE.RUNMEASURE);
  556. }
  557. public void DeleteCurrentSampleData()
  558. {
  559. OTSSampleVisualPropertyInfo SMInfo = m_ProjParam.DeleteCurrentSampleData();
  560. if (null == SMInfo)
  561. {
  562. // 设置 开始 ,停止 和检查参数 按钮状态
  563. m_RibbonFun.SetMeasureRibbonButnStatu();
  564. log.Error("(OTSIncAMeasureAppForm.AddNewSample) m_DataMgrFun.AddNewSample(sSampleHoleName) = null ");
  565. return;
  566. }
  567. m_SPropertyWindows.TSSaveAs.Enabled = true;
  568. m_SPropertyWindows.TSLoad.Enabled = true;
  569. //给SampleWindow 发送样品信息
  570. //m_SamplepaceWindow.AddSampleArea(SMInfo.SMeasurePara);
  571. m_SamplepaceWindow.ReadSEMDataAndSetToCurrentSample();
  572. //给PropWindow 发送工作样品属性信息
  573. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  574. //给SoluWindow 发送样品显示信息
  575. //m_SolutionWindows.AddSampleMeasure(SMInfo.TSampleParam);
  576. // 设置 开始 ,停止 和检查参数 按钮状态
  577. m_RibbonFun.SetMeasureRibbonButnStatu();
  578. //设置 删除,复位,圆形,矩形 按钮状态
  579. m_RibbonFun.SetSampleRibbonButnStatus();
  580. //清空帧图信息
  581. SetRunType(MSR_RUN_TYPE.RUNMEASURE);
  582. }
  583. private void rbSelectDlg_Click(object sender, EventArgs e)
  584. {
  585. //判断样品台是否有样品,如果有样品则不能设置默认参数
  586. if (m_ProjParam.GetSampleCount() > 0)
  587. {
  588. MessageBox.Show("Cann't setup preference parameter,for you have added some samples!");
  589. return;
  590. }
  591. ProgMgrInfoForm ProgMgrForm = new ProgMgrInfoForm();
  592. if (DialogResult.OK == ProgMgrForm.ShowDialog())
  593. {
  594. if (m_ProjParam.LoadParamFile() && m_ProjParam.LoadStageParamFile())
  595. {
  596. if (m_ProjParam.InitResultData())
  597. {
  598. m_RibbonFun.SetAllRibbonButnStatus(true);
  599. //当样品台上有样品,则不更新样品台数据
  600. if (0 == m_ProjParam.GetSampleCount())
  601. {
  602. m_SamplepaceWindow.InitStageDisplay(m_ProjData.GetStage(), m_ProjData.GetSEMStageData());
  603. }
  604. }
  605. else
  606. {
  607. log.Error("(OTSIncAMeasureAppForm.rbSelectDlg_Click) this.CheckMeasureSysFileExist() = false");
  608. }
  609. }
  610. else
  611. {
  612. log.Error("(OTSIncAMeasureAppForm.rbSelectDlg_Click) (m_DataMgrFun.CheckParamFile() && m_DataMgrFun.CheckStageFile()) = false");
  613. }
  614. }
  615. }
  616. // 主Windows框右下角显示鼠标点的SEM坐标(样品台)
  617. public void ShowSemCoordvAL(string sSemCoord)
  618. {
  619. STSemCoordinate.Text = sSemCoord;
  620. statusStrip1.Refresh();
  621. }
  622. //// 主Windows框右下角显示鼠标点的灰度值(测量图)
  623. public void ShowGrayVal(string sGrayVal)
  624. {
  625. TSGrayVal.Text = sGrayVal;
  626. statusStrip1.Refresh();
  627. }
  628. //获取工作样品测量锁
  629. public bool GetWorkSampleParamLock(ref CTreeSampleParam TSParamLock)
  630. {
  631. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(),m_ProjParam.GetDefaultParam().GetSysType());
  632. //if (!m_ProjParam.GetWSampleParaLock(ref SMInfo))
  633. //{
  634. // return false;
  635. //}
  636. TSParamLock = SMInfo.TSampleParam;
  637. return true;
  638. }
  639. /// <summary>
  640. /// 更新属性窗口
  641. /// </summary>
  642. public void UpdatePropertyVal()
  643. {
  644. //获取新的工作样品属性值
  645. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(),m_ProjParam.GetDefaultParam().GetSysType());
  646. //if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))
  647. //{
  648. // log.Error("(OTSIncAMeasureAppForm.SetSEMData) m_DataMgrFun.GetSamplePropertyVal(m_DataMgrFun.GetWorkSample(),ref SMInfo) = false Failed");
  649. //}
  650. // MeasureApp 窗口给 OTSPropertyWindow窗口 Grid显示的样品属性信息
  651. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  652. }
  653. private void ribbonOrbMenuItemSaveAs_Click(object sender, EventArgs e)
  654. {
  655. bool iRev = m_ProjData.SaveAs();
  656. if (!iRev)
  657. {
  658. return;
  659. }
  660. }
  661. private void rbSaveFile_Click(object sender, EventArgs e)
  662. {
  663. bool iRev = m_ProjData.Save();
  664. if (!iRev)
  665. {
  666. return;
  667. }
  668. }
  669. private void rbCheckParam_Click(object sender, EventArgs e)
  670. {
  671. //检查样品测量参数
  672. if (m_ProjParam.CheckSampleParam(true))
  673. {
  674. string message = table["message7"].ToString();
  675. MessageBox.Show(message, "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  676. }
  677. }
  678. private void ribReset_Click(object sender, EventArgs e)
  679. {
  680. //调用样品台窗口中的复位方法
  681. m_SamplepaceWindow.ResetWorkSampleMeasure();
  682. }
  683. //绘制圆形测量区域
  684. private void ribCircle_Click(object sender, EventArgs e)
  685. {
  686. //修改工作样品的测量区域为圆形
  687. m_SamplepaceWindow.DrawCircleMeasure();
  688. }
  689. private void rbThreePoints_Click(object sender, EventArgs e)
  690. {
  691. //修改工作样品的测量区域为圆形
  692. m_SamplepaceWindow.DrawCircleMeasureByThreePoints();
  693. }
  694. private void rbRingShape_Click(object sender, EventArgs e)
  695. {
  696. //修改工作样品的测量区域为圆形
  697. m_SamplepaceWindow.DrawRingShapeArea();
  698. }
  699. //绘制矩形测量区域
  700. private void ribRectangle_Click(object sender, EventArgs e)
  701. {
  702. //修改工作样品的测量区域为矩形
  703. m_SamplepaceWindow.DrawRectangleMeasure();
  704. }
  705. private void rbExitApp_Click(object sender, EventArgs e)
  706. {
  707. this.Close();
  708. }
  709. private void rbStart_Click(object sender, EventArgs e)
  710. {
  711. if (!m_ProjParam.CheckSampleParam(false))
  712. {
  713. return;
  714. }
  715. if (!m_MsrThreadWrapper.BGWorkThreadIsRunning() && !m_MsrThreadWrapper.BgWorkIsPaused())
  716. {
  717. SetRunType(MSR_RUN_TYPE.RUNMEASURE);
  718. //m_MsrThreadWrapper.SetDoRunType(MSR_RUN_TYPE.RUNMEASURE);
  719. m_MsrThreadWrapper.StartBGWorkThread();
  720. m_RibbonFun.SetMeasureRibbonButnStatu();
  721. }
  722. else //thread is in pausing state
  723. {
  724. SetRunType(MSR_RUN_TYPE.RUNMEASURE);
  725. //m_MsrThreadWrapper.SetDoRunType(MSR_RUN_TYPE.RUNMEASURE);
  726. m_MsrThreadWrapper.SetMeasureThreadStatus(OTS_MSR_THREAD_STATUS.INPROCESS);
  727. m_RibbonFun.SetMeasureRibbonButnStatu();
  728. }
  729. }
  730. public void SetStartMeasureRibbonStatus()
  731. {
  732. ribView.Enabled = false;
  733. m_RibbonFun.SetToolButnStatu(false);
  734. //false: 将其他ribbon按钮设置为灰色
  735. rbPanelFile.Enabled = false;
  736. rbPanelSample.Enabled = false;
  737. m_SolutionWindows.Enabled = false;
  738. m_SPropertyWindows.Enabled = false;
  739. rbStart.Enabled = false;
  740. //rbPause.Enabled = true;
  741. rbStop.Enabled = true;
  742. rbCheckParam.Enabled = false;
  743. }
  744. private void rbStop_Click(object sender, EventArgs e)
  745. {
  746. //如果当前正在测量,则停止测量线程
  747. if (MeasureThreadRunFlag)
  748. {
  749. //停止测量线程
  750. m_MsrThreadWrapper.SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.STOPPED);
  751. }
  752. else if (m_MsrThreadWrapper.m_measure.GetMsrThreadStatus() .GetStatus()== OTS_MSR_THREAD_STATUS.PAUSED)
  753. {
  754. foreach (KeyValuePair<string, CSmplMeasure> smpl in m_MsrThreadWrapper.m_measure.mapSmplMsr)
  755. {
  756. if (smpl.Value.GetSample().GetMsrStatus().GetStatus() == OTS_MSR_SAMPLE_STATUS.PAUSED)
  757. {
  758. smpl.Value.TheLastWorkOfSampleMeasure();
  759. return;
  760. }
  761. }
  762. }
  763. }
  764. private void rbPause_Click(object sender, EventArgs e)
  765. {
  766. //如果当前正在测量,则停止测量线程
  767. if (MeasureThreadRunFlag)
  768. {
  769. //停止测量线程
  770. m_MsrThreadWrapper.SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.PAUSED);
  771. }
  772. }
  773. private void rbRuler_Click(object sender, EventArgs e)
  774. {
  775. m_SamplepaceWindow.ShowRulerLocation();
  776. }
  777. private void rbSmapleName_Click(object sender, EventArgs e)
  778. {
  779. //m_SamplepaceWindow.ChangeSampleHoleFont();
  780. }
  781. private void rbSmaplePhoto_Click(object sender, EventArgs e)
  782. {
  783. m_SamplepaceWindow.ChangeSampleHoleImage();
  784. }
  785. //当点击Ribbon停止按钮时,设置Ribbon状态
  786. public void SetStopMeasureRibbonStatus()
  787. {
  788. ribView.Enabled = true;
  789. m_RibbonFun.SetToolButnStatu(true);
  790. rbPanelFile.Enabled = true;
  791. rbPanelSample.Enabled = true;
  792. m_RibbonFun.SetMeasureRibbonButnStatu();
  793. m_SolutionWindows.Enabled = true;
  794. m_SPropertyWindows.Enabled = true;
  795. rbStart.Enabled = true;
  796. rbPause.Enabled = false;
  797. rbStop.Enabled = false;
  798. rbCheckParam.Enabled = true;
  799. //激活跳转至报告程序按钮
  800. rbPReport.Enabled = true;
  801. rbReport.Enabled = true;
  802. }
  803. public void SetPauseMeasureRibbonStatus()
  804. {
  805. ribView.Enabled = true;
  806. m_RibbonFun.SetToolButnStatu(true);
  807. rbPanelFile.Enabled = true;
  808. rbPanelSample.Enabled = true;
  809. m_RibbonFun.SetMeasureRibbonButnStatu();
  810. m_SolutionWindows.Enabled = true;
  811. m_SPropertyWindows.Enabled = true;
  812. rbStart.Enabled = true;
  813. rbPause.Enabled = false;
  814. rbStop.Enabled = true;
  815. rbCheckParam.Enabled = false;
  816. //激活跳转至报告程序按钮
  817. rbPReport.Enabled = true;
  818. rbReport.Enabled = true;
  819. }
  820. public bool SwitchMeasureSample(string sMsrSampleName)
  821. {
  822. if (!m_ProjParam.SetWorkSample(sMsrSampleName))
  823. {
  824. log.Error("(OTSIncAMeasureAppForm.SwitchMeasureSample) SetWorkSample(sMsrSampleName =" + sMsrSampleName + ") Failed !");
  825. return false;
  826. }
  827. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(),m_ProjParam.GetDefaultParam().GetSysType());
  828. m_SolutionWindows.SwitchSample(sMsrSampleName);
  829. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  830. return true;
  831. }
  832. #region 开始获取样品孔中的照片
  833. /// <summary>
  834. /// 开始获取样品孔中的照片
  835. /// </summary>
  836. /// <param name="doRunType"></param>
  837. /// <param name="HoleID"></param>
  838. /// <param name="c_DomainMessure"></param>
  839. public void StartSampleHoleBSEImage(int HoleID)
  840. {
  841. //设置获取样品孔中照片所需的参数
  842. m_MsrThreadWrapper.SetHoleImagePreview(HoleID);
  843. if (!m_MsrThreadWrapper.BGWorkThreadIsRunning())
  844. {
  845. m_MsrThreadWrapper.StartBGWorkThread();
  846. m_RibbonFun.SetMeasureRibbonButnStatu();
  847. }
  848. }
  849. #endregion
  850. private void rbRecover_Click(object sender, EventArgs e)
  851. {
  852. //关闭所有内容
  853. CloseAllContents();
  854. //显示样品属性窗口与树结构窗口
  855. m_SolutionWindows.Show(dockPanel, DockState.DockLeft);
  856. m_SPropertyWindows.Show(dockPanel);
  857. //显示样品台窗口 测量状态与测量结果窗口
  858. m_SamplepaceWindow.Show(dockPanel);
  859. m_SubMidWindow.m_MessureStatuWindow.Show(dockPanel);
  860. m_SubMidWindow.m_MeasureResultWindow.Show(dockPanel);
  861. //此处将在父窗体选项卡上显示
  862. foreach (Form child in this.MdiChildren)
  863. {
  864. if (child.Name == "OTSSamplespaceWindow")
  865. {
  866. child.Activate();
  867. break;
  868. }
  869. }
  870. }
  871. private void CloseAllContents()
  872. {
  873. m_SolutionWindows.DockPanel = null;
  874. m_SPropertyWindows.DockPanel = null;
  875. m_SamplepaceWindow.DockPanel = null;
  876. m_SubMidWindow.m_MessureStatuWindow.DockPanel = null;
  877. m_SubMidWindow.m_MeasureResultWindow.DockPanel = null;
  878. CloseAllDocuments();
  879. }
  880. private void CloseAllDocuments()
  881. {
  882. if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
  883. {
  884. foreach (Form form in MdiChildren)
  885. form.Close();
  886. }
  887. else
  888. {
  889. IDockContent[] documents = dockPanel.DocumentsToArray();
  890. foreach (IDockContent content in documents)
  891. content.DockHandler.Close();
  892. }
  893. }
  894. private void rbMeasureCircle_Click(object sender, EventArgs e)
  895. {
  896. m_ProjParam.SetMeasureAreaShape(ShapeType.CIRCUL);
  897. //修改工作样品的测量区域为圆形
  898. m_SamplepaceWindow.changeShape(ShapeType.CIRCUL);
  899. }
  900. private void rbMeasureRectangle_Click(object sender, EventArgs e)
  901. {
  902. m_ProjParam.SetMeasureAreaShape(ShapeType.RECTANGLE);
  903. //修改工作样品的测量区域为矩形
  904. m_SamplepaceWindow.changeShape(ShapeType.RECTANGLE);
  905. }
  906. //ctrl+s组合键进行保存
  907. private void OTSIncAMeasureAppForm_KeyDown(object sender, KeyEventArgs e)
  908. {
  909. if (e.KeyCode == Keys.S && e.Modifiers == Keys.Control)
  910. {
  911. bool iRev = m_ProjData.Save();
  912. if (!iRev)
  913. {
  914. log.Error("(OTSIncAMeasureAppForm.rbSaveFile_Click) m_DataMgrFun.SaveFile() Failed !");
  915. return;
  916. }
  917. log.Error("(OTSIncAMeasureAppForm.rbSaveAs_Click) m_DataMgrFun.SaveFile() Success !");
  918. }
  919. }
  920. private void rbSTDEdit_Click_1(object sender, EventArgs e)
  921. {
  922. OpenFileDialog openFileDialog = new OpenFileDialog();
  923. openFileDialog.Filter = "(*.db)|*.db";
  924. openFileDialog.InitialDirectory = Application.StartupPath + "\\Config\\SysData\\";
  925. openFileDialog.RestoreDirectory = true;
  926. openFileDialog.FilterIndex = 1;
  927. if (openFileDialog.ShowDialog() == DialogResult.OK)
  928. {
  929. try
  930. {
  931. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSPartA_STDEditor.exe", "\""+openFileDialog.FileName+ "\"");
  932. p.WaitForExit();
  933. }
  934. catch (Exception ex)
  935. {
  936. log.Error("OTSPartA_STDEditor:" + ex.ToString());
  937. }
  938. }
  939. //reload the setup data just now
  940. foreach (var s in this.m_ProjData.GetSampleList())
  941. {
  942. var stdname= s.GetMsrParams().GetSTDName();
  943. if (stdname != "NoSTDDB")
  944. {
  945. if (!stdname.Contains(".db"))
  946. {
  947. stdname += ".db";
  948. }
  949. var m_classifyEngine = new COTSClassifyEngineClr(EngineType.ExpressionClassifyEng, stdname);
  950. m_classifyEngine.ReloadEngineDB();
  951. }
  952. }
  953. }
  954. private void rbSysMgrApp_Click(object sender, EventArgs e)
  955. {
  956. try
  957. {
  958. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSSysMgrApp.exe");
  959. p.WaitForExit();
  960. }
  961. catch (Exception ex)
  962. {
  963. log.Error("OTSSysMgrApp:" + ex.ToString());
  964. }
  965. }
  966. private void ribPolygon_Click(object sender, EventArgs e)
  967. {
  968. //修改工作样品的测量区域为矩形
  969. m_SamplepaceWindow.DrawPolygonMeasure();
  970. }
  971. private void rbReClassify_Click(object sender, EventArgs e)
  972. {
  973. this.Cursor = Cursors.WaitCursor;
  974. if (m_ProjData.Reclassify())
  975. {
  976. m_ProjData.Save();
  977. MessageBox.Show("reclassification success");
  978. }
  979. else
  980. {
  981. MessageBox.Show("reclassification failed");
  982. }
  983. this.Cursor = Cursors.Default;
  984. }
  985. /// <summary>
  986. /// 打开测量项目文件
  987. /// </summary>
  988. private void OpenMeasureProjectFile()
  989. {
  990. bool bOpenFlag=false;
  991. COTSMsrPrjResultData ProjDataMgr = new COTSMsrPrjResultData();
  992. string strPathName;
  993. // file open dialog
  994. OpenFileDialog openFileDialog = new OpenFileDialog();
  995. openFileDialog.Filter = "Probject Files (*.prj)|*.prj";
  996. if (openFileDialog.ShowDialog() != DialogResult.OK)
  997. {
  998. return ;
  999. }
  1000. strPathName = openFileDialog.FileName;
  1001. this.Cursor = Cursors.WaitCursor;
  1002. if (ProjDataMgr.Load(strPathName))
  1003. {
  1004. m_ProjData = ProjDataMgr;
  1005. m_ProjParam.SetResultData(m_ProjData);
  1006. m_ProjParam.InitResultData();
  1007. bOpenFlag = true;
  1008. }
  1009. this.Cursor = Cursors.Default;
  1010. if (bOpenFlag)
  1011. {
  1012. if (!DisplayExistSampleFile())
  1013. {
  1014. log.Error("(OTSIncAMeasureAppForm.rbOpen_Click) OpenExistSampleFile() = false Failed !");
  1015. return;
  1016. }
  1017. m_RibbonFun.SetAllRibbonButnStatus(true);
  1018. }
  1019. else
  1020. {
  1021. log.Error("(OTSIncAMeasureAppForm.rbOpen_Click) m_DataMgrFun.OpenExistSampleFile() Failed !");
  1022. }
  1023. }
  1024. private void OTSIncAMeasureAppForm_FormClosed(object sender, FormClosedEventArgs e)
  1025. {
  1026. }
  1027. private void rbAbout_Click(object sender, EventArgs e)
  1028. {
  1029. About m_about = new About();
  1030. m_about.ShowDialog();
  1031. }
  1032. protected override void DefWndProc(ref Message m)
  1033. {
  1034. switch (m.Msg)
  1035. {
  1036. case MsgID:
  1037. break;
  1038. case LogMsgID:
  1039. m_LogMsg = new PostLogMsg();
  1040. m_LogMsg = (PostLogMsg)Marshal.PtrToStructure(m.LParam, typeof(PostLogMsg));
  1041. var log = NLog.LogManager.GetCurrentClassLogger();
  1042. string s = GetString(m_LogMsg.logMessage);
  1043. switch (m_LogMsg.logLevel)
  1044. {
  1045. case 1:
  1046. log.Trace(s);
  1047. break;
  1048. case 2:
  1049. log.Debug(s);
  1050. break;
  1051. case 3:
  1052. log.Info(s);
  1053. break;
  1054. case 4:
  1055. log.Warn(s);
  1056. break;
  1057. case 5:
  1058. log.Error(s);
  1059. break;
  1060. case 6:
  1061. log.Fatal(s);
  1062. break;
  1063. }
  1064. break;
  1065. default:
  1066. base.DefWndProc(ref m);
  1067. break;
  1068. }
  1069. }
  1070. private string GetString(char[] csStr)
  1071. {
  1072. int ilen = csStr.Length;
  1073. string csName = new string(csStr); //MSTMsg.STMSampleStu.cSName
  1074. csName.IndexOf('\0');
  1075. csName = csName.Substring(0, csName.IndexOf('\0'));
  1076. return csName;
  1077. }
  1078. private void PrepareIpcServer()
  1079. {
  1080. //Instantiate our server channel.
  1081. IpcServerChannel channel = new IpcServerChannel("ServerChannel");
  1082. //Register the server channel.
  1083. ChannelServices.RegisterChannel(channel, false);
  1084. //Register this service type.
  1085. RemotingConfiguration.RegisterWellKnownServiceType(typeof(IpcSEMController), "RemoteObject", WellKnownObjectMode.Singleton);
  1086. }
  1087. private void rbConnectHardware_Click_1(object sender, EventArgs e)
  1088. {
  1089. if (!m_MsrThreadWrapper.IsSEMConnected())
  1090. {
  1091. if (!m_MsrThreadWrapper.ConnectSEM())
  1092. {
  1093. MessageBox.Show("Connect failed!");
  1094. return;
  1095. }
  1096. }
  1097. this.rbConnectHardware.Enabled = false;
  1098. this.rbDisconnectHardware.Enabled = true;
  1099. log.Warn("SEM connect success!");
  1100. }
  1101. private void rbDisconnectHardware_Click_1(object sender, EventArgs e)
  1102. {
  1103. if (m_MsrThreadWrapper.IsSEMConnected())
  1104. {
  1105. m_MsrThreadWrapper.DisconnectSEM();
  1106. }
  1107. this.rbDisconnectHardware.Enabled = false;
  1108. this.rbConnectHardware.Enabled = true;
  1109. log.Warn("SEM Disconnect!");
  1110. }
  1111. private void rbinterrupt_Click(object sender, EventArgs e)
  1112. {
  1113. if (m_MsrThreadWrapper.IsSEMConnected())
  1114. {
  1115. m_MsrThreadWrapper.StopXrayAcquisition();
  1116. }
  1117. log.Warn("StopXrayAcquisition!");
  1118. }
  1119. private void rbAutoBeamOff_Click(object sender, EventArgs e)
  1120. {
  1121. if (m_ProjData.GetGenParam().AutoBeamOff)
  1122. {
  1123. m_ProjData.GetGenParam().AutoBeamOff = false;
  1124. rbAutoBeamOff.Image = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_off;
  1125. rbAutoBeamOff.SmallImage = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_off;
  1126. }
  1127. else
  1128. {
  1129. m_ProjData.GetGenParam().AutoBeamOff = true;
  1130. rbAutoBeamOff.Image = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_on;
  1131. rbAutoBeamOff.SmallImage = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_on;
  1132. }
  1133. }
  1134. private void OTSIncAMeasureAppForm_Activated(object sender, EventArgs e)
  1135. {
  1136. }
  1137. }
  1138. }