OTSIncAMeasureAppForm.cs 49 KB

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