OTSIncAMeasureAppForm.cs 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845
  1. using OTS.WinFormsUI.Docking;
  2. using OTSCLRINTERFACE;
  3. using OTSDataType;
  4. using OTSMeasureApp._1_OTSMeasure.Measure.ParamData;
  5. using OTSMeasureApp._10_OTSSplashScreen;
  6. using OTSMeasureApp.ServiceCenter;
  7. using OTSModelSharp;
  8. using OTSModelSharp.ResourceManage;
  9. using System;
  10. using System.Collections;
  11. using System.Collections.Generic;
  12. using System.Diagnostics;
  13. using System.Drawing;
  14. using System.IO;
  15. using System.Linq;
  16. using System.Runtime.InteropServices;
  17. using System.Runtime.Remoting;
  18. using System.Runtime.Remoting.Channels;
  19. using System.Runtime.Remoting.Channels.Ipc;
  20. using System.Threading;
  21. using System.Windows.Forms;
  22. using System.Xml;
  23. using static OTSDataType.otsdataconst;
  24. namespace OTSMeasureApp
  25. {
  26. enum MessageBoxRev
  27. {
  28. DIALOG_YES = 0,
  29. DIALOG_NO = 1,
  30. DIALOG_CANCEL = 2
  31. }
  32. public partial class OTSIncAMeasureAppForm : Form
  33. {
  34. Thread th;
  35. public static string m_SamplespaceWindowName = "样品台";
  36. public static string m_MeasureStauWindowName = "测量状态";
  37. public static string m_MeasureRetWindowName = "测量结果";
  38. public static string m_NoWindowName = "未知工作窗口";
  39. //国际化
  40. OTSCommon.Language lan;
  41. Hashtable table;
  42. // 初始化日志类
  43. NLog.Logger log;
  44. private PostLogMsg m_LogMsg;
  45. public const int MsgID = 0x0464;
  46. public const int LogMsgID = 0x0465;
  47. public OTSMeasureResultWindow m_MeasureResultWindow = null;
  48. public OTSMeasureStatusWindow m_MessureStatuWindow = null;
  49. public OTSSamplespaceWindow m_SamplepaceWindow = null;
  50. public OTSMeasureOutputNlog m_OTSMeasureOutputNlog = null;
  51. public COTSMeasureParam m_ProjParam = null;
  52. public COTSMsrPrjResultData m_ProjRstData;
  53. public OTSSolutionWindow m_SolutionWindows = null;
  54. public OTSPropertyWindow m_SPropertyWindows = null;
  55. //测量线程对象
  56. public CMeasureThreadWrapper m_MsrThreadWrapper = null;
  57. // 测量线程当前状态 True: 正在测量; False: 测量结束
  58. public bool MeasureThreadRunFlag { get => m_MsrThreadWrapper.BGWorkThreadIsRunning(); }
  59. private OTSCommon.CHistoryPrj historyPrj = new OTSCommon.CHistoryPrj();
  60. Form sp;
  61. private Panel dropHintPanel;
  62. public OTSIncAMeasureAppForm()
  63. {
  64. th = new Thread(new ThreadStart(DoSplash));
  65. th.Start();
  66. InitializeComponent();
  67. //国际化
  68. lan = new OTSCommon.Language(this);
  69. table = lan.GetNameTable(this.Name);
  70. m_SamplespaceWindowName = table["m_samplespacewindowname"].ToString();
  71. m_MeasureStauWindowName = table["m_measurestauwindowname"].ToString();
  72. m_MeasureRetWindowName = table["m_measureretwindowname"].ToString();
  73. m_NoWindowName = table["m_nowindowname"].ToString();
  74. m_OTSMeasureOutputNlog = new OTSMeasureOutputNlog();
  75. m_OTSMeasureOutputNlog.Show();
  76. // 初始化Docpanle
  77. m_SolutionWindows = new OTSSolutionWindow(this);
  78. m_SPropertyWindows = new OTSPropertyWindow(this);
  79. m_MeasureResultWindow = new OTSMeasureResultWindow(this);
  80. m_MeasureResultWindow.Text = m_MeasureRetWindowName;
  81. m_MessureStatuWindow = new OTSMeasureStatusWindow(this);
  82. m_MessureStatuWindow.Text = m_MeasureStauWindowName;
  83. m_SamplepaceWindow = new OTSSamplespaceWindow(this);
  84. m_SamplepaceWindow.Text = m_SamplespaceWindowName;
  85. m_ProjParam = new COTSMeasureParam(this);
  86. m_ProjRstData = m_ProjParam.GetResultData();
  87. //初始化测量线程
  88. m_MsrThreadWrapper = new CMeasureThreadWrapper(this);//must be the last sentence of this procedure.
  89. this.AllowDrop = true;
  90. // 初始化拖拽提示面板
  91. InitializeDropHintPanel();
  92. }
  93. public void SetAllRibbonButnStatus(bool bRibStstu)
  94. {
  95. rbPanelSample.Enabled = bRibStstu;
  96. //rbPanelFunction.Enabled = bRibStstu;
  97. //rbMenu.Tabs[0].Panels[0].Enabled = bRibStstu;
  98. rbMenu.Tabs[1].Panels[0].Enabled = bRibStstu;
  99. //下拉菜单中的 新建,打开,保存,另存为
  100. //rbNewDocument.Enabled = bRibStstu;
  101. menuOpenprj.Enabled = bRibStstu;
  102. menuSaveprj.Enabled = bRibStstu;
  103. menuSaveAsprj.Enabled = bRibStstu;
  104. menuOpenprj.Enabled = true;
  105. rbOpen.Enabled = true;
  106. //if (bRibStstu)
  107. //{
  108. //设置开始,停止,检查参数按钮
  109. SetMeasureRibbonButnStatu();
  110. //设置 删除,复位,圆形,矩形 按钮状态
  111. SetSampleRibbonButnStatus();
  112. //设置 跳转至报告 按钮状态
  113. SetReprotRibbonButnStatu();
  114. //}
  115. }
  116. private void OTSIncAMeasureAppForm_Load(object sender, EventArgs e)
  117. {
  118. try
  119. {
  120. ArrangWorkspaceWindow();
  121. log = NLog.LogManager.GetCurrentClassLogger();
  122. if (m_ProjParam.LoadParamFile())
  123. {
  124. if (m_ProjParam.InitResultData())
  125. {
  126. SetAllRibbonButnStatus(false);
  127. m_SamplepaceWindow.InitStageDisplay(m_ProjRstData.GetStageHolder(), m_ProjRstData.GetSEMStageData());
  128. //添加启动系统界面显示
  129. var SystemType = m_ProjParam.GetDefaultParam().SystemTypeId;
  130. if (SystemType == OTS_SysType_ID.IncA)
  131. {
  132. this.Text += "(IncA)";
  133. }
  134. else if (SystemType == OTS_SysType_ID.TCCleannessA)
  135. {
  136. this.Text += "(TCCleannessA)";
  137. }
  138. else if (SystemType == OTS_SysType_ID.BatteryCleannessA)
  139. {
  140. this.Text += "(BatteryCleannessA)";
  141. }
  142. else
  143. {
  144. this.Text += "(SteelMineral)";
  145. }
  146. }
  147. else
  148. {
  149. log.Error(" InitResultData() failed");
  150. }
  151. m_MsrThreadWrapper.m_measure.m_pMeasureParam = m_ProjParam;
  152. }
  153. else
  154. {
  155. log.Error("(OTSIncAMeasureAppForm.OTSIncAMeasureAppForm_Load) (LoadParamFile() && LoadStageParamFile()) failed");
  156. }
  157. if (!m_MsrThreadWrapper.ConnectSEM())
  158. {
  159. MessageBox.Show("Connect SEM failed!Please goto the SysMgrApp.exe to setup the proper parameter or check other parameter of the EDS software");
  160. System.Diagnostics.ProcessStartInfo process = new System.Diagnostics.ProcessStartInfo();
  161. process.FileName = "OTSSysMgrApp.exe";//打开app的路径
  162. process.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
  163. System.Diagnostics.Process.Start(process);
  164. this.rbConnectHardware.Enabled = true;
  165. this.rbDisconnectHardware.Enabled = false;
  166. }
  167. this.rbConnectHardware.Enabled = false;
  168. this.rbDisconnectHardware.Enabled = true;
  169. log.Warn("SEM connect success!");
  170. PrepareIpcServer();
  171. log.Info("Ipc server start success!");
  172. //----------------------Test Code, Don't delete
  173. //var f = new BaseFunctionTest();
  174. //f.ShowDialog();
  175. //----------------------
  176. }
  177. catch (Exception ex)
  178. {
  179. log.Error(" OTSIncAMeasureAppForm_Load:" + ex.ToString());
  180. }
  181. sp.Close();
  182. this.Activate();
  183. }
  184. public void ArrangWorkspaceWindow()
  185. {
  186. //Show 样品台窗口
  187. m_SamplepaceWindow.Show(dockPanel);
  188. //Show 测量状态窗口
  189. m_MessureStatuWindow.Show(dockPanel);
  190. //Show 测量结果窗口
  191. m_MeasureResultWindow.Show(dockPanel);
  192. m_SolutionWindows.Show(dockPanel, DockState.DockLeft);
  193. //Show 测量过程中Log显示窗口
  194. m_OTSMeasureOutputNlog.Show(dockPanel, DockState.DockRight);
  195. dockPanel.DockRightPortion = 365;
  196. m_SPropertyWindows.Show(dockPanel);
  197. m_SamplepaceWindow.Activate();
  198. InitHistoryPrjDisplay();
  199. }
  200. private void InitHistoryPrjDisplay()
  201. {
  202. //加载历史工作文件列表
  203. historyPrj.loadHistoryPath();
  204. List<string> prjPathList = historyPrj.GetPrjPathList();
  205. if (prjPathList.Count == 0)
  206. {
  207. menuHistoryPrj.Enabled = false;
  208. return;
  209. }
  210. menuHistoryPrj.Enabled = true;
  211. menuHistoryPrj.DropDownItems.Clear();
  212. for (int i = 0; i < prjPathList.Count; i++)
  213. {
  214. RibbonOrbMenuItem tsmi = new RibbonOrbMenuItem();
  215. tsmi.Text = prjPathList[i];
  216. tsmi.Click += new EventHandler(this.menuHistoryPrj_Click);
  217. menuHistoryPrj.DropDownItems.Add(tsmi);
  218. }
  219. }
  220. private void saveHistoryPrj(string strPrjPath)
  221. {
  222. //保存历史工作文件列表
  223. historyPrj.loadHistoryPath();
  224. historyPrj.AddPrjPath(strPrjPath);
  225. historyPrj.saveHistoryPath();
  226. InitHistoryPrjDisplay();
  227. }
  228. private void menuHistoryPrj_Click(object sender, EventArgs e)
  229. {
  230. RibbonOrbMenuItem itm = sender as RibbonOrbMenuItem;
  231. OpenMeasureProjectFile(itm.Text);
  232. }
  233. private void DoSplash()
  234. {
  235. string path = @".\Config\SysData\OTSProgMgrParam.pmf";
  236. XmlDocument xmlDocument = new XmlDocument();
  237. xmlDocument.Load(path);
  238. XmlNode node = xmlDocument.SelectSingleNode("XMLData");
  239. XmlElement xe = (XmlElement)node;
  240. string str = xe.GetAttribute("SysType");
  241. if (str == "IncA")
  242. {
  243. sp = new OTSSplashScreen_IncA();
  244. sp.ShowDialog();
  245. }
  246. else if (str == "TCCleannessA" || str == "BatteryCleannessA")
  247. {
  248. sp = new OTSSplashScreen_Cleanness();
  249. sp.ShowDialog();
  250. }
  251. else if (str == "SteelMineral")
  252. {
  253. sp = new OTSSplashScreen_SteelMineral();
  254. sp.ShowDialog();
  255. }
  256. }
  257. private void rbReport_Click(object sender, EventArgs e)
  258. {
  259. //测量结果文件路径列表
  260. List<string> mrFilePathList = new List<string>();
  261. //获取测量结果文件路径列表
  262. bool result = m_ProjParam.GetCompletedMeasureFileName(ref mrFilePathList);
  263. if (result)
  264. {
  265. for (int i = 0; i < mrFilePathList.Count; i++)
  266. {
  267. mrFilePathList[i] = mrFilePathList[i].Replace(" ", "^");
  268. }
  269. //转换为数组
  270. string[] resultFilePath = mrFilePathList.ToArray();
  271. System.Diagnostics.ProcessStartInfo process = new System.Diagnostics.ProcessStartInfo();
  272. process.FileName = "OTSIncAReportApp.exe";//打开app的路径
  273. string FilePath = string.Join(" ", resultFilePath);
  274. process.Arguments = FilePath;//多个参数用空格隔开
  275. process.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
  276. System.Diagnostics.Process.Start(process);
  277. }
  278. }
  279. // sNewWorkSampleName: 新工作样品名
  280. public void SwitchWSample(string sNewWorkSampleName)
  281. {
  282. m_ProjParam.SetWorkSample(sNewWorkSampleName);
  283. m_SolutionWindows.SwitchSample(sNewWorkSampleName);
  284. //获取新工作样品属性值
  285. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(), m_ProjParam.GetDefaultParam().GetSysType());
  286. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  287. //发送想你的样品名给Sample
  288. m_SamplepaceWindow.SwitchWorkSample(sNewWorkSampleName);
  289. }
  290. public void SoluWindowCheckBoxStatuChange(string sSampleName, bool bCheckBoxStatu)
  291. {
  292. string sWSampleName = m_ProjParam.GetWorkSampleName();
  293. if ("" == sWSampleName)
  294. {
  295. //不修改Tteeview 的工作样品属性值
  296. m_SolutionWindows.Rev_MeasureApp_CheckboxStatuChange_Event(sSampleName, !bCheckBoxStatu);
  297. return;
  298. }
  299. //Treeview更改的工作样品数的CHECKBOX 状态
  300. if (!m_ProjParam.SetSampleParamVal(OTS_SAMPLE_PROP_GRID_ITEMS.SWITCH, OTS_ITEM_TYPES.BOOL, bCheckBoxStatu))
  301. {
  302. //不修改Tteeview 的工作样品属性值
  303. m_SolutionWindows.Rev_MeasureApp_CheckboxStatuChange_Event(sSampleName, !bCheckBoxStatu);
  304. return;
  305. }
  306. // 设置 开始 ,停止 和检查参数 按钮状态
  307. SetMeasureRibbonButnStatu();
  308. //修改Grid工作样品的SWITCH值
  309. OTSSampleVisualPropertyInfo SMeasurenfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(), m_ProjParam.GetDefaultParam().GetSysType());
  310. m_SPropertyWindows.DisplaySampleMeasureInfo(SMeasurenfo);
  311. }
  312. public void SetMeasureRibbonButnStatu()
  313. {
  314. bool bSampleCheckBoxFalg = m_ProjParam.GetSampleCheckBoxStatus();
  315. if (!bSampleCheckBoxFalg)
  316. {
  317. rbStart.Enabled = false;
  318. rbPause.Enabled = false;
  319. rbStop.Enabled = false;
  320. rbCheckParam.Enabled = false;
  321. return;
  322. }
  323. if (MeasureThreadRunFlag) //当正在测量时,开始按钮变灰色
  324. { rbStart.Enabled = false;}
  325. else
  326. {rbStart.Enabled = true;}
  327. if (MeasureThreadRunFlag) //当前正在运行的时候,才可以点击暂停
  328. {
  329. rbPause.Enabled = true;
  330. }
  331. else
  332. {
  333. rbPause.Enabled = false;
  334. }
  335. if (MeasureThreadRunFlag) //当前正在运行的时候,才可以点击停止
  336. {
  337. rbStop.Enabled = true;
  338. }
  339. else
  340. {
  341. rbStop.Enabled = false;
  342. }
  343. if (MeasureThreadRunFlag)
  344. {
  345. rbCheckParam.Enabled = false;
  346. }
  347. else
  348. {
  349. rbCheckParam.Enabled = true;
  350. }
  351. }
  352. public bool EditWorkSampleName(string sSampleOldName, string sSampleNewName)
  353. {
  354. if (!m_ProjParam.ChangeWorkSampleName(sSampleNewName))
  355. {
  356. return false;
  357. }
  358. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(), m_ProjParam.GetDefaultParam().GetSysType());
  359. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  360. m_SamplepaceWindow.ChangeWorkSampleName(sSampleNewName);
  361. return true;
  362. }
  363. public void SoluwindowReqAddSample()
  364. {
  365. //Treeview右键点击添加新样品
  366. this.AddNewSampleMeasure();
  367. }
  368. private void OTSIncAMeasureAppForm_FormClosing(object sender, FormClosingEventArgs e)
  369. {
  370. try
  371. {
  372. if (m_MsrThreadWrapper.BGWorkThreadIsRunning()) //当前正在测量
  373. {
  374. e.Cancel = true;
  375. return;
  376. }
  377. if (m_MsrThreadWrapper.IsHavingNotCompleteSamples()) //当前正在测量
  378. {
  379. e.Cancel = true;
  380. MessageBox.Show("There is one sample is still in pausing state,please stop it!");
  381. return;
  382. }
  383. //判断测量结果文件修改后是否保存
  384. if (m_ProjRstData.IsModified())
  385. {
  386. string message = table["message2"].ToString();
  387. DialogResult lsdr = MessageBox.Show(message, "Tip", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
  388. if (lsdr == DialogResult.Yes)
  389. {
  390. //保存,退出
  391. m_ProjRstData.Save();
  392. //保存,直接退出
  393. Application.ExitThread();
  394. }
  395. else if (lsdr == DialogResult.No)
  396. {
  397. //不保存,直接退出
  398. Application.ExitThread();
  399. }
  400. else if (lsdr == DialogResult.Cancel)
  401. {
  402. //取消
  403. e.Cancel = true;
  404. return;
  405. }
  406. }
  407. log.Info("Disconnect SEM!");
  408. m_MsrThreadWrapper.DisconnectSEM();
  409. m_MsrThreadWrapper.SetWorkThreadPending();
  410. }
  411. catch (Exception ex)
  412. {
  413. string message = table["message3"].ToString();
  414. log.Error("OTSIncAMeasureAppForm_FormClosing-" + message + ":" + ex.ToString());
  415. }
  416. Process.GetCurrentProcess().Kill();
  417. }
  418. //打开指定路径的文件
  419. private void ribbonOrbMenuItem1_OpenWorkspace_Click(object sender, EventArgs e)
  420. {
  421. OpenMeasureProjectFile();
  422. }
  423. //新建样品工作文件
  424. private void ribbonOrbMenuItem3_CreateWorkspace_Click(object sender, EventArgs e)
  425. {
  426. int iCreateNewFileResult = m_ProjParam.CreateNewFile();
  427. if (iCreateNewFileResult == 0)
  428. {
  429. log.Error("(OTSIncAMeasureAppForm.rbNew_CreateWorkspace_Click) m_DataMgrFun.CreateNewFile() Failed !");
  430. return;
  431. }
  432. else if (iCreateNewFileResult == 2)
  433. {
  434. log.Info("(OTSIncAMeasureAppForm.rbNew_CreateWorkspace_Click) m_DataMgrFun.CreateNewFile() Cancel !");
  435. return;
  436. }
  437. m_ProjRstData = m_ProjParam.GetResultData();
  438. SetAllRibbonButnStatus(true);
  439. //清除TREEVIEW和GRID上的显示的已经保存的样品信息
  440. m_SolutionWindows.m_TreeViewBase.DeleteAllTreeNode();
  441. m_SPropertyWindows.m_SampleGrid.HideGrid();
  442. //设置报告按钮
  443. rbPReport.Enabled = false;
  444. rbReport.Enabled = false;
  445. menuHistoryPrj.Enabled = true;
  446. //新建项目时,设置属性窗体中的两个按钮也为不可用状态
  447. m_SPropertyWindows.TSLoad.Enabled = false;
  448. m_SPropertyWindows.TSSaveAs.Enabled = false;
  449. //绘制样品台
  450. m_SamplepaceWindow.InitStageDisplay(m_ProjRstData.GetStageHolder(), m_ProjRstData.GetSEMStageData());
  451. //隐藏XrayTable控件
  452. m_MessureStatuWindow.HideXRayTable();
  453. //新建时重新初始化结果窗体结果
  454. m_MeasureResultWindow.SetInit();
  455. }
  456. // 新建样品时提示保存样品信息Messagebox
  457. public int ShowSaveInfoMsgBox()
  458. {
  459. string message = table["message4"].ToString();
  460. DialogResult dResult = MessageBox.Show(message, "Tip", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
  461. if (dResult == DialogResult.Yes)
  462. {
  463. return (int)MessageBoxRev.DIALOG_YES;
  464. }
  465. else if (dResult == DialogResult.No)
  466. {
  467. return (int)MessageBoxRev.DIALOG_NO;
  468. }
  469. else
  470. {
  471. return (int)MessageBoxRev.DIALOG_CANCEL;
  472. }
  473. }
  474. //打开已经保存的工作文件
  475. private bool DisplayExistSampleFile()
  476. {
  477. List<CTreeSampleParam> TSampleParamList = new List<CTreeSampleParam>();
  478. List<SampleMeasurePara> SampleMeasureParaList = new List<SampleMeasurePara>();
  479. int iSampleCount = m_ProjRstData.GetSampleList().Count;
  480. if (0 == iSampleCount)
  481. {
  482. return false;
  483. }
  484. for (int i = 0; i < iSampleCount; i++)
  485. {
  486. CTreeSampleParam CTSampleParam = new CTreeSampleParam();
  487. COTSSample SampleClr = (m_ProjRstData.GetSampleList())[i];
  488. CTSampleParam.sSampleTitleName = m_ProjRstData.GetFileName();
  489. CTSampleParam.sWorkSampleName = SampleClr.GetName();
  490. CTSampleParam.bSwitch = SampleClr.GetSwitch();
  491. TSampleParamList.Add(CTSampleParam);
  492. }
  493. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(), m_ProjParam.GetDefaultParam().GetSysType());
  494. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  495. m_SolutionWindows.DisplayExistSampleFile(TSampleParamList, SMInfo.TSampleParam);
  496. if (!InitExistSampleMeasureParam(ref SampleMeasureParaList))
  497. {
  498. log.Error(" OpenExistSampleMeasureArea(ref SampleMeasureAreaList) Failed !");
  499. return false;
  500. }
  501. string sWSampleName = m_ProjParam.GetWorkSampleName();
  502. if ("" == sWSampleName)
  503. {
  504. log.Error("(OTSIncAMeasureAppForm.OpenExistSampleFile) m_DataMgrFun.GetWorkSampleName() = null !");
  505. return false;
  506. }
  507. m_SamplepaceWindow.DisplayVisualStage(m_ProjRstData.GetStageHolder(), m_ProjRstData.GetSEMStageData());
  508. m_SamplepaceWindow.DisplayExistSamples(SampleMeasureParaList);
  509. m_MeasureResultWindow.UpdateResultInfoBySampleName(sWSampleName);
  510. return true;
  511. }
  512. public bool InitExistSampleMeasureParam(ref List<SampleMeasurePara> SampleMeasureParaList)
  513. {
  514. int iSListCount = m_ProjRstData.GetSampleList().Count;
  515. if (0 == iSListCount)
  516. {
  517. return false;
  518. }
  519. for (int i = 0; i < iSListCount; i++)
  520. {
  521. SampleMeasurePara SampleMeasureParam = new SampleMeasurePara(m_ProjRstData.GetSampleList()[i]);
  522. SampleMeasureParaList.Add(SampleMeasureParam);
  523. }
  524. return true;
  525. }
  526. //打开指定路径的文件
  527. private void rbOpen_Click(object sender, EventArgs e)
  528. {
  529. OpenMeasureProjectFile();
  530. }
  531. private void rbDeleteSample_Click(object sender, EventArgs e)
  532. {
  533. //删除样品(样品必须先选中)
  534. string sWSampleName = m_ProjParam.GetWorkSampleName();
  535. if ("" == sWSampleName)
  536. {
  537. log.Error("(OTSIncAMeasureAppForm.rbDeleteSample_Click) m_DataMgrFun.GetWorkSampleName() = null Failed");
  538. return;
  539. }
  540. string message = table["message5"].ToString();
  541. string message6 = table["message6"].ToString();
  542. string sDeleteSampleName = message;
  543. sDeleteSampleName += sWSampleName;
  544. sDeleteSampleName += message6;
  545. if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Tip", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
  546. {
  547. //删除样品成功
  548. DeleteSample(sWSampleName);
  549. sWSampleName = m_ProjParam.GetWorkSampleName();
  550. if ("" != sWSampleName)
  551. {
  552. m_SolutionWindows.m_TreeViewBase.GetTreeWorkSampleNode(sWSampleName);
  553. m_SolutionWindows.treeView1.Focus();
  554. }
  555. }
  556. }
  557. public void SetRibbonButonWorkListStatu(List<int> RibbonButnIDList, bool bFlag)
  558. {
  559. if (RibbonButnIDList.Count == 0)
  560. {
  561. return;
  562. }
  563. for (int i = 0; i < RibbonButnIDList.Count; i++)
  564. {
  565. if (RibbonButnIDList[i] == (int)RibbonButnID.NewDocment)
  566. {
  567. menuNewDocument.Enabled = bFlag;
  568. continue;
  569. }
  570. if (RibbonButnIDList[i] == (int)RibbonButnID.File_NewDocment)
  571. {
  572. rbNew.Enabled = bFlag;
  573. continue;
  574. }
  575. if (RibbonButnIDList[i] == (int)RibbonButnID.OpenDocment)
  576. {
  577. menuOpenprj.Enabled = bFlag;
  578. continue;
  579. }
  580. if (RibbonButnIDList[i] == (int)RibbonButnID.File_OpenDocment)
  581. {
  582. rbOpen.Enabled = bFlag;
  583. continue;
  584. }
  585. if (RibbonButnIDList[i] == (int)RibbonButnID.Save)
  586. {
  587. menuSaveprj.Enabled = bFlag;
  588. continue;
  589. }
  590. if (RibbonButnIDList[i] == (int)RibbonButnID.File_Save)
  591. {
  592. rbSave.Enabled = bFlag;
  593. continue;
  594. }
  595. if (RibbonButnIDList[i] == (int)RibbonButnID.SaveAs)
  596. {
  597. menuSaveAsprj.Enabled = bFlag;
  598. continue;
  599. }
  600. if (RibbonButnIDList[i] == (int)RibbonButnID.File_SaveAs)
  601. {
  602. rbSaveAs.Enabled = bFlag;
  603. continue;
  604. }
  605. if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_Reset)
  606. {
  607. ribInvers.Enabled = bFlag;
  608. continue;
  609. }
  610. if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_DrawCircle)
  611. {
  612. ribCircle.Enabled = bFlag;
  613. continue;
  614. }
  615. if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_DrawRectang)
  616. {
  617. ribRectangle.Enabled = bFlag;
  618. continue;
  619. }
  620. if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_DrawPolygon)
  621. {
  622. ribPolygon.Enabled = bFlag;
  623. continue;
  624. }
  625. if (RibbonButnIDList[i] == (int)RibbonButnID.View_Ruler)
  626. {
  627. rbRuler.Enabled = bFlag;
  628. continue;
  629. }
  630. if (RibbonButnIDList[i] == (int)RibbonButnID.View_SPhoto)
  631. {
  632. rbSmaplePhoto.Enabled = bFlag;
  633. continue;
  634. }
  635. if (RibbonButnIDList[i] == (int)RibbonButnID.View_SName)
  636. {
  637. rbSmapleName.Enabled = bFlag;
  638. continue;
  639. }
  640. if (RibbonButnIDList[i] == (int)RibbonButnID.View_Recover)
  641. {
  642. rbRecover.Enabled = bFlag;
  643. continue;
  644. }
  645. if (RibbonButnIDList[i] == (int)RibbonButnID.File_Base)
  646. {
  647. rbMenu.Tabs[0].Panels[0].Enabled = bFlag;
  648. continue;
  649. }
  650. if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_Base)
  651. {
  652. rbPanelSample.Enabled = bFlag;
  653. continue;
  654. }
  655. if (RibbonButnIDList[i] == (int)RibbonButnID.Funciton_Base)
  656. {
  657. rbPanelFunction.Enabled = bFlag;
  658. continue;
  659. }
  660. if (RibbonButnIDList[i] == (int)RibbonButnID.View_Base)
  661. {
  662. rbMenu.Tabs[1].Panels[0].Enabled = bFlag;
  663. continue;
  664. }
  665. if (RibbonButnIDList[i] == (int)RibbonButnID.Fun_Report)
  666. {
  667. rbMenu.Tabs[1].Panels[0].Enabled = bFlag;
  668. continue;
  669. }
  670. if (RibbonButnIDList[i] == (int)RibbonButnID.ShotImage)
  671. {
  672. ribonBtnShot.Enabled = bFlag;
  673. continue;
  674. }
  675. }
  676. }
  677. //设置 删除,复位,圆形,矩形 按钮状态
  678. public void SetSampleRibbonButnStatus()
  679. {
  680. List<int> RibbonIdList = new List<int>();
  681. RibbonIdList.Add((int)RibbonButnID.Sample_DeleteSample);
  682. RibbonIdList.Add((int)RibbonButnID.Sample_Reset);
  683. RibbonIdList.Add((int)RibbonButnID.Sample_DrawCircle);
  684. RibbonIdList.Add((int)RibbonButnID.Sample_DrawRectang);
  685. RibbonIdList.Add((int)RibbonButnID.Sample_DrawPolygon);
  686. RibbonIdList.Add((int)RibbonButnID.ShotImage);
  687. if (0 == m_ProjParam.GetSampleCount())
  688. {
  689. rbPanelSample.Enabled = false;
  690. //rbPanelFunction.Enabled = false;
  691. rbMenu.Tabs[0].Panels[0].Enabled = true;
  692. rbOpen.Enabled = true;
  693. menuOpenprj.Enabled = true;
  694. rbSave.Enabled = false;
  695. menuSaveprj.Enabled = false;
  696. menuSaveAsprj.Enabled = false;
  697. menuHistoryPrj.Enabled = true;
  698. SetRibbonButonWorkListStatu(RibbonIdList, false);
  699. }
  700. else
  701. {
  702. rbPanelSample.Enabled = true;
  703. //rbPanelFunction.Enabled = true;
  704. rbOpen.Enabled = false;
  705. menuOpenprj.Enabled = false;
  706. rbSave.Enabled = true;
  707. menuSaveAsprj.Enabled = true;
  708. menuHistoryPrj.Enabled = false;
  709. rbMenu.Tabs[1].Panels[0].Enabled = true;
  710. SetRibbonButonWorkListStatu(RibbonIdList, true);
  711. }
  712. }
  713. public void SetReprotRibbonButnStatu()
  714. {
  715. //设置跳转至报告程序按钮状态
  716. rbPReport.Enabled = false;
  717. rbReport.Enabled = false;
  718. //判断打开的文件是否存在测量结果文件路径
  719. List<string> mrFilePathList = new List<string>();
  720. bool result = m_ProjParam.GetCompletedMeasureFileName(ref mrFilePathList);
  721. //根据结果设置报告按钮启用状态
  722. if (result)
  723. {
  724. rbPReport.Enabled = true;
  725. rbReport.Enabled = true;
  726. }
  727. else
  728. {
  729. rbPReport.Enabled = false;
  730. rbReport.Enabled = false;
  731. }
  732. }
  733. //返回删除的工作样品名
  734. public void DeleteSample(string sDeleteWSampleName = "")
  735. {
  736. if (m_MsrThreadWrapper.m_measure.mapSmplMsr.ContainsKey(sDeleteWSampleName))
  737. {
  738. m_MsrThreadWrapper.m_measure.mapSmplMsr.Remove(sDeleteWSampleName);
  739. }
  740. m_ProjParam.DeleteWorkSample(sDeleteWSampleName);
  741. // 设置 开始 ,停止 和检查参数 按钮状态
  742. SetMeasureRibbonButnStatu();
  743. //设置 删除,复位,圆形,矩形 按钮状态
  744. SetSampleRibbonButnStatus();
  745. // 更新报告ribbon按钮状态
  746. SetAllRibbonButnStatus(true);
  747. int iSampleCount = m_ProjParam.GetSampleCount();
  748. if (0 == iSampleCount)
  749. {
  750. //给工作样品台发送删除样品和新的工作样品名称
  751. m_SamplepaceWindow.DeleteWorkSample(sDeleteWSampleName);
  752. m_SPropertyWindows.PropGrid.Hide();
  753. m_SPropertyWindows.toolStripButton_refresh.Enabled = false;
  754. m_SPropertyWindows.TSSaveAs.Enabled = false;
  755. m_SolutionWindows.treeView1.Nodes.Clear();
  756. m_MessureStatuWindow.HideXRayTable();
  757. m_ProjRstData.Cleanup();
  758. m_MeasureResultWindow.SetInit();
  759. return;
  760. }
  761. else
  762. {
  763. string sNewWSName = m_ProjParam.GetWorkSampleName();
  764. if ("" == sNewWSName)
  765. {
  766. log.Error("(OTSIncAMeasureAppForm.DeleteSample) m_DataMgrFun.GetWorkSampleName() = null Failed");
  767. return;
  768. }
  769. m_SolutionWindows.DeletCurrentSampleNode();
  770. m_SolutionWindows.DisplaySample(sNewWSName);
  771. //将测量状态初始化
  772. m_MessureStatuWindow.SetMeasureStatusInit();
  773. //给工作样品台发送删除样品和新的工作样品名称
  774. m_SamplepaceWindow.DeleteWorkSample(sDeleteWSampleName);
  775. //设置工作样品
  776. SwitchWSample(sNewWSName);
  777. }
  778. return;
  779. }
  780. private void rbAddSample_Click(object sender, EventArgs e)
  781. {
  782. this.AddNewSampleMeasure();//the system will choose the empty hole one by one according to the holeNo sequence.
  783. }
  784. public void AddNewSampleMeasure(string sSampleHoleName = "")
  785. {
  786. OTSSampleVisualPropertyInfo SMInfo = m_ProjParam.AddNewSampleMeasure(sSampleHoleName);
  787. if (null == SMInfo)
  788. {
  789. // 设置 开始 ,停止 和检查参数 按钮状态
  790. SetMeasureRibbonButnStatu();
  791. log.Error("(OTSIncAMeasureAppForm.AddNewSample) m_DataMgrFun.AddNewSample(sSampleHoleName) = null ");
  792. return;
  793. }
  794. m_SPropertyWindows.TSSaveAs.Enabled = true;
  795. this.menuSaveprj.Enabled = true;
  796. this.rbSaveAs.Enabled = true;
  797. m_SPropertyWindows.TSLoad.Enabled = true;
  798. m_SPropertyWindows.TSEdit.Enabled = false;
  799. m_SPropertyWindows.TSEdit.Visible = false;
  800. //给SampleWindow 发送样品信息
  801. m_SamplepaceWindow.AddSampleArea(SMInfo.SMeasurePara);
  802. m_SamplepaceWindow.ReadSEMDataAndSetToCurrentSample();
  803. //给PropWindow 发送工作样品属性信息
  804. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  805. //给SoluWindow 发送样品显示信息
  806. m_SolutionWindows.AddSampleMeasure(SMInfo.TSampleParam);
  807. // 设置 开始 ,停止 和检查参数 按钮状态
  808. SetMeasureRibbonButnStatu();
  809. //设置 删除,复位,圆形,矩形 按钮状态
  810. SetSampleRibbonButnStatus();
  811. }
  812. public void InitCurrentSampleState()
  813. {
  814. OTSSampleVisualPropertyInfo SMInfo = m_ProjParam.GetWorkingSampleVisualPropertyInfo();
  815. if (null == SMInfo)
  816. {
  817. // 设置 开始 ,停止 和检查参数 按钮状态
  818. SetMeasureRibbonButnStatu();
  819. log.Error("(OTSIncAMeasureAppForm.AddNewSample) m_DataMgrFun.AddNewSample(sSampleHoleName) = null ");
  820. return;
  821. }
  822. m_SPropertyWindows.TSSaveAs.Enabled = true;
  823. m_SPropertyWindows.TSLoad.Enabled = true;
  824. m_SamplepaceWindow.ReadSEMDataAndSetToCurrentSample();
  825. //给PropWindow 发送工作样品属性信息
  826. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  827. // 设置 开始 ,停止 和检查参数 按钮状态
  828. SetMeasureRibbonButnStatu();
  829. //设置 删除,复位,圆形,矩形 按钮状态
  830. SetSampleRibbonButnStatus();
  831. }
  832. private void rbSelectDlg_Click(object sender, EventArgs e)
  833. {
  834. ProgMgrInfoForm ProgMgrForm = new ProgMgrInfoForm();
  835. if (DialogResult.OK == ProgMgrForm.ShowDialog())
  836. {
  837. if (m_ProjParam.LoadParamFile())
  838. {
  839. if (m_ProjParam.InitResultData())
  840. {
  841. SetAllRibbonButnStatus(true);
  842. //当样品台上有样品,则不更新样品台数据
  843. if (0 == m_ProjParam.GetSampleCount())
  844. {
  845. m_SamplepaceWindow.InitStageDisplay(m_ProjRstData.GetStageHolder(), m_ProjRstData.GetSEMStageData());
  846. }
  847. }
  848. else
  849. {
  850. log.Error("(OTSIncAMeasureAppForm.rbSelectDlg_Click) this.CheckMeasureSysFileExist() = false");
  851. }
  852. }
  853. else
  854. {
  855. log.Error("(OTSIncAMeasureAppForm.rbSelectDlg_Click) (m_DataMgrFun.CheckParamFile() && m_DataMgrFun.CheckStageFile()) = false");
  856. }
  857. }
  858. }
  859. // 主Windows框右下角显示鼠标点的SEM坐标(样品台)
  860. public void ShowSemCoordvAL(string sSemCoord)
  861. {
  862. STSemCoordinate.Text = sSemCoord;
  863. statusStrip1.Refresh();
  864. }
  865. //// 主Windows框右下角显示鼠标点的灰度值(测量图)
  866. public void ShowGrayVal(string sGrayVal)
  867. {
  868. TSGrayVal.Text = sGrayVal;
  869. statusStrip1.Refresh();
  870. }
  871. //获取工作样品测量锁
  872. public bool GetWorkSampleParamLock(ref CTreeSampleParam TSParamLock)
  873. {
  874. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(), m_ProjParam.GetDefaultParam().GetSysType());
  875. TSParamLock = SMInfo.TSampleParam;
  876. return true;
  877. }
  878. /// <summary>
  879. /// 更新属性窗口
  880. /// </summary>
  881. public void UpdatePropertyVal()
  882. {
  883. //获取新的工作样品属性值
  884. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(), m_ProjParam.GetDefaultParam().GetSysType());
  885. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  886. }
  887. private void ribbonOrbMenuItemSaveAs_Click(object sender, EventArgs e)
  888. {
  889. bool iRev = m_ProjRstData.SaveAs();
  890. if (!iRev)
  891. {
  892. return;
  893. }
  894. foreach (var spl in m_ProjParam.MeasureSampleList)
  895. {
  896. m_SamplepaceWindow.InitSampleMeasure(spl, 0);
  897. }
  898. m_SamplepaceWindow.PrepareVisualMeasureField(m_SamplepaceWindow.GetWorkingVisualSample());
  899. m_SamplepaceWindow.InitSampleMeasure(m_ProjParam.GetWorkSample(), 0);
  900. }
  901. private void rbSaveFile_Click(object sender, EventArgs e)
  902. {
  903. bool iRev = m_ProjRstData.Save();
  904. if (!iRev)
  905. {
  906. return;
  907. }
  908. saveHistoryPrj(m_ProjRstData.GetPathName());
  909. }
  910. private void rbCheckParam_Click(object sender, EventArgs e)
  911. {
  912. frmPre_measurementDetection frmPre_MeasurementDetection = new frmPre_measurementDetection(m_ProjParam);
  913. frmPre_MeasurementDetection.ShowDialog();
  914. }
  915. private void ribReset_Click(object sender, EventArgs e)
  916. {
  917. //调用样品台窗口中的复位方法
  918. m_SamplepaceWindow.InverseSelectWorkSampleMeasure();
  919. }
  920. //绘制圆形测量区域
  921. private void ribCircle_Click(object sender, EventArgs e)
  922. {
  923. //修改工作样品的测量区域为圆形
  924. m_SamplepaceWindow.DrawCircleMeasure();
  925. }
  926. private void rbThreePoints_Click(object sender, EventArgs e)
  927. {
  928. //修改工作样品的测量区域为圆形
  929. m_SamplepaceWindow.DrawCircleMeasureByThreePoints();
  930. }
  931. private void rbRingShape_Click(object sender, EventArgs e)
  932. {
  933. //修改工作样品的测量区域为圆形
  934. m_SamplepaceWindow.DrawRingShapeArea();
  935. }
  936. //绘制矩形测量区域
  937. private void ribRectangle_Click(object sender, EventArgs e)
  938. {
  939. //修改工作样品的测量区域为矩形
  940. m_SamplepaceWindow.DrawRectangleMeasure();
  941. }
  942. private void rbExitApp_Click(object sender, EventArgs e)
  943. {
  944. this.Close();
  945. }
  946. private void rbStart_Click(object sender, EventArgs e)
  947. {
  948. if (!m_ProjParam.CheckSampleParam(false))
  949. {
  950. return;
  951. }
  952. if (!m_MsrThreadWrapper.BGWorkThreadIsRunning() && !m_MsrThreadWrapper.BgWorkIsPaused())
  953. {
  954. m_MsrThreadWrapper.StartBGWorkThread();
  955. SetMeasureRibbonButnStatu();
  956. }
  957. else //thread is in pausing state
  958. {
  959. m_MsrThreadWrapper.SetMeasureThreadStatus(OTS_MSR_THREAD_STATUS.INPROCESS);
  960. SetMeasureRibbonButnStatu();
  961. }
  962. }
  963. public void SetStartMeasureRibbonStatus()
  964. {
  965. ribView.Enabled = false;
  966. SetToolButnStatu(false);
  967. //false: 将其他ribbon按钮设置为灰色
  968. //rbPanelFile.Enabled = false;
  969. //rbPanelSample.Enabled = false;
  970. m_SolutionWindows.Enabled = false;
  971. m_SPropertyWindows.Enabled = false;
  972. rbStart.Enabled = false;
  973. rbStop.Enabled = true;
  974. rbCheckParam.Enabled = false;
  975. }
  976. public void SetToolButnStatu(bool bStatu)
  977. {
  978. menuNewDocument.Enabled = bStatu;
  979. menuOpenprj.Enabled = bStatu;
  980. menuSaveprj.Enabled = bStatu;
  981. menuSaveAsprj.Enabled = bStatu;
  982. menuExitApp.Enabled = bStatu;
  983. rbSelectDlg.Enabled = bStatu;
  984. }
  985. private void rbStop_Click(object sender, EventArgs e)
  986. {
  987. //如果当前正在测量,则停止测量线程
  988. if (MeasureThreadRunFlag)
  989. {
  990. //停止测量线程
  991. m_MsrThreadWrapper.SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.STOPPED);
  992. }
  993. else if (m_MsrThreadWrapper.m_measure.GetMsrThreadStatusobj().GetStatus() == OTS_MSR_THREAD_STATUS.PAUSED)
  994. {
  995. m_MsrThreadWrapper.SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.STOPPED);
  996. foreach (KeyValuePair<string, CSmplMeasure> smpl in m_MsrThreadWrapper.m_measure.mapSmplMsr)
  997. {
  998. if (smpl.Value.GetSample().GetMsrStatus().GetStatus() == OTS_MSR_SAMPLE_STATUS.PAUSED)
  999. {
  1000. smpl.Value.TheLastWorkOfSampleMeasure();
  1001. SetStopMeasureRibbonStatus();
  1002. return;
  1003. }
  1004. }
  1005. }
  1006. }
  1007. private void rbPause_Click(object sender, EventArgs e)
  1008. {
  1009. //如果当前正在测量,则停止测量线程
  1010. if (MeasureThreadRunFlag)
  1011. {
  1012. //停止测量线程
  1013. m_MsrThreadWrapper.SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.PAUSED);
  1014. }
  1015. }
  1016. private void rbRuler_Click(object sender, EventArgs e)
  1017. {
  1018. m_SamplepaceWindow.ShowRulerLocation();
  1019. }
  1020. private void rbSmapleName_Click(object sender, EventArgs e)
  1021. {
  1022. //m_SamplepaceWindow.ChangeSampleHoleFont();
  1023. }
  1024. private void rbSmaplePhoto_Click(object sender, EventArgs e)
  1025. {
  1026. m_SamplepaceWindow.ChangeSampleHoleImage();
  1027. }
  1028. //当点击Ribbon停止按钮时,设置Ribbon状态
  1029. public void SetStopMeasureRibbonStatus()
  1030. {
  1031. ribView.Enabled = true;
  1032. SetToolButnStatu(true);
  1033. rbPanelFile.Enabled = true;
  1034. rbPanelSample.Enabled = true;
  1035. SetMeasureRibbonButnStatu();
  1036. m_SolutionWindows.Enabled = true;
  1037. m_SPropertyWindows.Enabled = true;
  1038. rbStart.Enabled = true;
  1039. rbPause.Enabled = false;
  1040. rbStop.Enabled = false;
  1041. rbCheckParam.Enabled = true;
  1042. //激活跳转至报告程序按钮
  1043. rbPReport.Enabled = true;
  1044. rbReport.Enabled = true;
  1045. }
  1046. public void SetPauseMeasureRibbonStatus()
  1047. {
  1048. ribView.Enabled = true;
  1049. SetToolButnStatu(true);
  1050. rbPanelFile.Enabled = true;
  1051. rbPanelSample.Enabled = true;
  1052. SetMeasureRibbonButnStatu();
  1053. m_SolutionWindows.Enabled = true;
  1054. m_SPropertyWindows.Enabled = true;
  1055. rbStart.Enabled = true;
  1056. rbPause.Enabled = false;
  1057. rbStop.Enabled = true;
  1058. rbCheckParam.Enabled = false;
  1059. //激活跳转至报告程序按钮
  1060. rbPReport.Enabled = true;
  1061. rbReport.Enabled = true;
  1062. }
  1063. public bool SwitchDisplayMeasureSample(string sMsrSampleName)
  1064. {
  1065. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(), m_ProjParam.GetDefaultParam().GetSysType());
  1066. m_SolutionWindows.SwitchSample(sMsrSampleName);
  1067. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  1068. return true;
  1069. }
  1070. #region 开始获取样品孔中的照片
  1071. /// <summary>
  1072. /// 开始获取样品孔中的照片
  1073. /// </summary>
  1074. /// <param name="doRunType"></param>
  1075. /// <param name="HoleID"></param>
  1076. /// <param name="c_DomainMessure"></param>
  1077. public void StartSampleHoleBSEImage()
  1078. {
  1079. if (!m_MsrThreadWrapper.BGWorkThreadIsRunning())
  1080. {
  1081. m_MsrThreadWrapper.StartBGWorkThread();
  1082. SetMeasureRibbonButnStatu();
  1083. }
  1084. }
  1085. #endregion
  1086. private void rbRecover_Click(object sender, EventArgs e)
  1087. {
  1088. //关闭所有内容
  1089. CloseAllContents();
  1090. //显示样品属性窗口与树结构窗口
  1091. m_SolutionWindows.Show(dockPanel, DockState.DockLeft);
  1092. m_SPropertyWindows.Show(dockPanel);
  1093. //显示样品台窗口 测量状态与测量结果窗口
  1094. m_SamplepaceWindow.Show(dockPanel);
  1095. m_MessureStatuWindow.Show(dockPanel);
  1096. m_MeasureResultWindow.Show(dockPanel);
  1097. //此处将在父窗体选项卡上显示
  1098. foreach (Form child in this.MdiChildren)
  1099. {
  1100. if (child.Name == "OTSSamplespaceWindow")
  1101. {
  1102. child.Activate();
  1103. break;
  1104. }
  1105. }
  1106. }
  1107. private void CloseAllContents()
  1108. {
  1109. m_SolutionWindows.DockPanel = null;
  1110. m_SPropertyWindows.DockPanel = null;
  1111. m_SamplepaceWindow.DockPanel = null;
  1112. m_MessureStatuWindow.DockPanel = null;
  1113. m_MeasureResultWindow.DockPanel = null;
  1114. CloseAllDocuments();
  1115. }
  1116. private void CloseAllDocuments()
  1117. {
  1118. if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
  1119. {
  1120. foreach (Form form in MdiChildren)
  1121. form.Close();
  1122. }
  1123. else
  1124. {
  1125. IDockContent[] documents = dockPanel.DocumentsToArray();
  1126. foreach (IDockContent content in documents)
  1127. content.DockHandler.Close();
  1128. }
  1129. }
  1130. private void rbMeasureCircle_Click(object sender, EventArgs e)
  1131. {
  1132. m_ProjParam.SetMeasureAreaShape(ShapeType.CIRCLE);
  1133. //修改工作样品的测量区域为圆形
  1134. m_SamplepaceWindow.changeShape(ShapeType.CIRCLE);
  1135. }
  1136. private void rbMeasureRectangle_Click(object sender, EventArgs e)
  1137. {
  1138. m_ProjParam.SetMeasureAreaShape(ShapeType.RECTANGLE);
  1139. //修改工作样品的测量区域为矩形
  1140. m_SamplepaceWindow.changeShape(ShapeType.RECTANGLE);
  1141. }
  1142. //ctrl+s组合键进行保存
  1143. private void OTSIncAMeasureAppForm_KeyDown(object sender, KeyEventArgs e)
  1144. {
  1145. if (e.KeyCode == Keys.S && e.Modifiers == Keys.Control)
  1146. {
  1147. bool iRev = m_ProjRstData.Save();
  1148. if (!iRev)
  1149. {
  1150. log.Error("(OTSIncAMeasureAppForm.rbSaveFile_Click) m_DataMgrFun.SaveFile() Failed !");
  1151. return;
  1152. }
  1153. log.Error("(OTSIncAMeasureAppForm.rbSaveAs_Click) m_DataMgrFun.SaveFile() Success !");
  1154. }
  1155. }
  1156. private void rbSTDEdit_Click_1(object sender, EventArgs e)
  1157. {
  1158. OpenFileDialog openFileDialog = new OpenFileDialog();
  1159. openFileDialog.Filter = "(*.db)|*.db";
  1160. openFileDialog.InitialDirectory = Application.StartupPath + "\\Config\\SysData\\";
  1161. openFileDialog.RestoreDirectory = true;
  1162. openFileDialog.FilterIndex = 1;
  1163. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1164. {
  1165. try
  1166. {
  1167. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSPartA_STDEditor.exe", "\"" + openFileDialog.FileName + "\"");
  1168. p.WaitForExit();
  1169. }
  1170. catch (Exception ex)
  1171. {
  1172. log.Error("OTSPartA_STDEditor:" + ex.ToString());
  1173. }
  1174. }
  1175. //reload the setup data just now
  1176. foreach (var s in this.m_ProjRstData.GetSampleList())
  1177. {
  1178. var stdname = s.GetMsrParams().GetSTDName();
  1179. if (stdname != "NoSTDDB")
  1180. {
  1181. if (!stdname.Contains(".db"))
  1182. {
  1183. stdname += ".db";
  1184. }
  1185. var m_classifyEngine = new COTSClassifyEngineClr(EngineType.ExpressionClassifyEng, stdname);
  1186. m_classifyEngine.ReloadEngineDB();
  1187. }
  1188. }
  1189. }
  1190. private void rbSysMgrApp_Click(object sender, EventArgs e)
  1191. {
  1192. try
  1193. {
  1194. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSSysMgrApp.exe");
  1195. p.WaitForExit();
  1196. }
  1197. catch (Exception ex)
  1198. {
  1199. log.Error("OTSSysMgrApp:" + ex.ToString());
  1200. }
  1201. }
  1202. private void ribPolygon_Click(object sender, EventArgs e)
  1203. {
  1204. //修改工作样品的测量区域为矩形
  1205. m_SamplepaceWindow.DrawPolygonMeasure();
  1206. }
  1207. /// <summary>
  1208. /// 打开测量项目文件
  1209. /// </summary>
  1210. private void OpenMeasureProjectFile(string strPathName = "")
  1211. {
  1212. if (strPathName == "")
  1213. {
  1214. //string strPathName;
  1215. // file open dialog
  1216. OpenFileDialog openFileDialog = new OpenFileDialog();
  1217. openFileDialog.Filter = "Probject Files (*.prj)|*.prj";
  1218. openFileDialog.InitialDirectory = historyPrj.GetLatestPrjFolder();
  1219. if (openFileDialog.ShowDialog() != DialogResult.OK)
  1220. {
  1221. return;
  1222. }
  1223. strPathName = openFileDialog.FileName;
  1224. }
  1225. COTSMsrPrjResultData ProjDataMgr = new COTSMsrPrjResultData();
  1226. bool bOpenFlag = false;
  1227. this.Cursor = Cursors.WaitCursor;
  1228. if (ProjDataMgr.Load(strPathName))
  1229. {
  1230. m_ProjRstData = ProjDataMgr;
  1231. m_ProjParam.SetResultData(m_ProjRstData);
  1232. m_ProjParam.InitResultData();
  1233. bOpenFlag = true;
  1234. }
  1235. this.Cursor = Cursors.Default;
  1236. if (bOpenFlag)
  1237. {
  1238. if (!DisplayExistSampleFile())
  1239. {
  1240. log.Error("(OTSIncAMeasureAppForm.rbOpen_Click) OpenExistSampleFile() = false Failed !");
  1241. return;
  1242. }
  1243. SetAllRibbonButnStatus(true);
  1244. }
  1245. else
  1246. {
  1247. log.Error("(OTSIncAMeasureAppForm.rbOpen_Click) m_DataMgrFun.OpenExistSampleFile() Failed !");
  1248. }
  1249. }
  1250. private void OTSIncAMeasureAppForm_FormClosed(object sender, FormClosedEventArgs e)
  1251. {
  1252. }
  1253. private void rbAbout_Click(object sender, EventArgs e)
  1254. {
  1255. var SystemType = m_ProjParam.GetDefaultParam().SystemTypeId;
  1256. if (SystemType == OTS_SysType_ID.IncA)
  1257. {
  1258. OTSSplashScreen_IncA m_about = new OTSSplashScreen_IncA();
  1259. m_about.TopMost = false;
  1260. m_about.ShowInTaskbar = true;
  1261. m_about.Show();
  1262. }
  1263. else if (SystemType == OTS_SysType_ID.TCCleannessA || SystemType == OTS_SysType_ID.BatteryCleannessA)
  1264. {
  1265. OTSSplashScreen_Cleanness m_about = new OTSSplashScreen_Cleanness();
  1266. m_about.TopMost = false;
  1267. m_about.ShowInTaskbar = true;
  1268. m_about.Show();
  1269. }
  1270. else if (SystemType == OTS_SysType_ID.SteelMineral)
  1271. {
  1272. OTSSplashScreen_SteelMineral m_about = new OTSSplashScreen_SteelMineral();
  1273. m_about.TopMost = false;
  1274. m_about.ShowInTaskbar = true;
  1275. m_about.Show();
  1276. }
  1277. }
  1278. protected override void DefWndProc(ref Message m)
  1279. {
  1280. switch (m.Msg)
  1281. {
  1282. case MsgID:
  1283. break;
  1284. case LogMsgID:
  1285. m_LogMsg = new PostLogMsg();
  1286. m_LogMsg = (PostLogMsg)Marshal.PtrToStructure(m.LParam, typeof(PostLogMsg));
  1287. var log = NLog.LogManager.GetCurrentClassLogger();
  1288. string s = GetString(m_LogMsg.logMessage);
  1289. switch (m_LogMsg.logLevel)
  1290. {
  1291. case 1:
  1292. log.Trace(s);
  1293. break;
  1294. case 2:
  1295. log.Debug(s);
  1296. break;
  1297. case 3:
  1298. log.Info(s);
  1299. break;
  1300. case 4:
  1301. log.Warn(s);
  1302. break;
  1303. case 5:
  1304. log.Error(s);
  1305. break;
  1306. case 6:
  1307. log.Fatal(s);
  1308. break;
  1309. }
  1310. break;
  1311. default:
  1312. base.DefWndProc(ref m);
  1313. break;
  1314. }
  1315. }
  1316. private string GetString(char[] csStr)
  1317. {
  1318. int ilen = csStr.Length;
  1319. string csName = new string(csStr); //MSTMsg.STMSampleStu.cSName
  1320. csName.IndexOf('\0');
  1321. csName = csName.Substring(0, csName.IndexOf('\0'));
  1322. return csName;
  1323. }
  1324. private void PrepareIpcServer()
  1325. {
  1326. //Instantiate our server channel.
  1327. IpcServerChannel channel = new IpcServerChannel("ServerChannel");
  1328. //Register the server channel.
  1329. ChannelServices.RegisterChannel(channel, false);
  1330. //Register this service type.
  1331. RemotingConfiguration.RegisterWellKnownServiceType(typeof(IpcSEMController), "RemoteObject", WellKnownObjectMode.Singleton);
  1332. }
  1333. private void rbConnectHardware_Click_1(object sender, EventArgs e)
  1334. {
  1335. if (!m_MsrThreadWrapper.IsSEMConnected())
  1336. {
  1337. if (!m_MsrThreadWrapper.ConnectSEM())
  1338. {
  1339. MessageBox.Show("Connect failed!");
  1340. return;
  1341. }
  1342. }
  1343. this.rbConnectHardware.Enabled = false;
  1344. this.rbDisconnectHardware.Enabled = true;
  1345. log.Warn("SEM connect success!");
  1346. }
  1347. private void rbDisconnectHardware_Click_1(object sender, EventArgs e)
  1348. {
  1349. if (m_MsrThreadWrapper.IsSEMConnected())
  1350. {
  1351. m_MsrThreadWrapper.DisconnectSEM();
  1352. }
  1353. this.rbDisconnectHardware.Enabled = false;
  1354. this.rbConnectHardware.Enabled = true;
  1355. log.Warn("SEM Disconnect!");
  1356. }
  1357. private void rbinterrupt_Click(object sender, EventArgs e)
  1358. {
  1359. if (m_MsrThreadWrapper.IsSEMConnected())
  1360. {
  1361. m_MsrThreadWrapper.StopXrayAcquisition();
  1362. }
  1363. log.Warn("StopXrayAcquisition!");
  1364. }
  1365. private void rbAutoBeamOff_Click(object sender, EventArgs e)
  1366. {
  1367. if (m_ProjRstData.GetGenParam().AutoBeamOff)
  1368. {
  1369. m_ProjRstData.GetGenParam().AutoBeamOff = false;
  1370. rbAutoBeamOff.Image = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_off;
  1371. rbAutoBeamOff.SmallImage = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_off;
  1372. }
  1373. else
  1374. {
  1375. m_ProjRstData.GetGenParam().AutoBeamOff = true;
  1376. rbAutoBeamOff.Image = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_on;
  1377. rbAutoBeamOff.SmallImage = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_on;
  1378. }
  1379. }
  1380. private void OTSIncAMeasureAppForm_Activated(object sender, EventArgs e)
  1381. {
  1382. }
  1383. private void ribbonButton2_Click(object sender, EventArgs e)
  1384. {
  1385. frmReclassifyCondition reCon = new frmReclassifyCondition();
  1386. reCon.ShowDialog();
  1387. this.Cursor = Cursors.WaitCursor;
  1388. if (reCon.DialogResult == DialogResult.OK)
  1389. {
  1390. if (m_ProjRstData.Reclassify(reCon.ignoreUserModify))
  1391. {
  1392. m_ProjRstData.Save();
  1393. MessageBox.Show("reclassification success");
  1394. }
  1395. else
  1396. {
  1397. MessageBox.Show("reclassification failed");
  1398. }
  1399. }
  1400. this.Cursor = Cursors.Default;
  1401. }
  1402. private void ribonBtnShot_Click(object sender, EventArgs e)
  1403. {
  1404. m_SamplepaceWindow.DrawOnlyShotMeasure();
  1405. }
  1406. private void ribbonButton4_Click(object sender, EventArgs e)
  1407. {
  1408. m_SamplepaceWindow.DrawRectangleBytTwoPoint();
  1409. }
  1410. private void OTSIncAMeasureAppForm_DragEnter(object sender, DragEventArgs e)
  1411. {
  1412. try
  1413. {
  1414. // 检查拖放的数据是否包含文件
  1415. if (e.Data.GetDataPresent(DataFormats.FileDrop))
  1416. {
  1417. // 获取拖放的文件
  1418. string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
  1419. // 检查是否有有效的.prj文件
  1420. bool hasValidFile = files.Any(f =>!string.IsNullOrEmpty(Path.GetExtension(f)) &&
  1421. Path.GetExtension(f).ToLower() == ".prj");
  1422. if (hasValidFile)
  1423. {
  1424. dropHintPanel.Visible = true;
  1425. dropHintPanel.BringToFront();
  1426. e.Effect = DragDropEffects.Copy;
  1427. return;
  1428. }
  1429. }
  1430. }
  1431. catch (Exception ex)
  1432. {
  1433. log?.Warn($"DragEnter处理异常: {ex.Message}");
  1434. }
  1435. dropHintPanel.Visible = false;
  1436. e.Effect = DragDropEffects.None;
  1437. }
  1438. private void OTSIncAMeasureAppForm_DragDrop(object sender, DragEventArgs e)
  1439. {
  1440. dropHintPanel.Visible = false;
  1441. try
  1442. {
  1443. if (e.Data.GetDataPresent(DataFormats.FileDrop))
  1444. {
  1445. string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
  1446. string prjFile = files.FirstOrDefault(f =>!string.IsNullOrEmpty(Path.GetExtension(f)) &&Path.GetExtension(f).ToLower() == ".prj");
  1447. if (!string.IsNullOrEmpty(prjFile))
  1448. {
  1449. if(menuOpenprj.Enabled)
  1450. {
  1451. this.Cursor = Cursors.WaitCursor;
  1452. try
  1453. {
  1454. OpenMeasureProjectFile(prjFile);
  1455. }
  1456. finally
  1457. {
  1458. this.Cursor = Cursors.Default;
  1459. }
  1460. }
  1461. else
  1462. {
  1463. MessageBox.Show("测量程序只能打开一个 .prj 项目文件", "提示",MessageBoxButtons.OK, MessageBoxIcon.Information);
  1464. }
  1465. }
  1466. else
  1467. {
  1468. MessageBox.Show("请拖拽有效的 .prj 项目文件", "提示",MessageBoxButtons.OK, MessageBoxIcon.Information);
  1469. }
  1470. }
  1471. }
  1472. catch (Exception ex)
  1473. {
  1474. this.Cursor = Cursors.Default;
  1475. log?.Error($"处理拖拽文件时发生错误: {ex.Message}", ex);
  1476. MessageBox.Show($"处理文件时发生错误: {ex.Message}", "错误",MessageBoxButtons.OK, MessageBoxIcon.Error);
  1477. }
  1478. }
  1479. private void InitializeDropHintPanel()
  1480. {
  1481. dropHintPanel = new Panel();
  1482. dropHintPanel.Name = "dropHintPanel";
  1483. dropHintPanel.BackColor = Color.FromArgb(180, Color.RoyalBlue);
  1484. dropHintPanel.Dock = DockStyle.Fill;
  1485. dropHintPanel.Visible = false;
  1486. dropHintPanel.BorderStyle = BorderStyle.None;
  1487. Label hintLabel = new Label();
  1488. hintLabel.Text = "拖拽 .prj 文件到此处打开项目";
  1489. hintLabel.AutoSize = false;
  1490. hintLabel.TextAlign = ContentAlignment.MiddleCenter;
  1491. hintLabel.Font = new Font(this.Font.FontFamily, 18, FontStyle.Bold);
  1492. hintLabel.ForeColor = Color.White;
  1493. hintLabel.Dock = DockStyle.Fill;
  1494. hintLabel.BackColor = Color.Transparent;
  1495. Label subLabel = new Label();
  1496. subLabel.Text = "Release mouse button to open the file";
  1497. subLabel.AutoSize = false;
  1498. subLabel.TextAlign = ContentAlignment.MiddleCenter;
  1499. subLabel.Font = new Font(this.Font.FontFamily, 12, FontStyle.Regular);
  1500. subLabel.ForeColor = Color.LightGray;
  1501. subLabel.Dock = DockStyle.Bottom;
  1502. subLabel.Height = 30;
  1503. subLabel.BackColor = Color.Transparent;
  1504. dropHintPanel.Controls.Add(hintLabel);
  1505. dropHintPanel.Controls.Add(subLabel);
  1506. this.Controls.Add(dropHintPanel);
  1507. dropHintPanel.BringToFront();
  1508. }
  1509. private void OTSIncAMeasureAppForm_DragLeave(object sender, EventArgs e)
  1510. {
  1511. dropHintPanel.Visible = false;
  1512. }
  1513. private void OTSIncAMeasureAppForm_DragOver(object sender, DragEventArgs e)
  1514. {
  1515. if (dropHintPanel.Visible){e.Effect = DragDropEffects.Copy;}
  1516. else{e.Effect = DragDropEffects.None;}
  1517. }
  1518. private void rbFixedpoint_Click(object sender, EventArgs e)
  1519. {
  1520. m_SamplepaceWindow.DrawCircleByFixedpoint();
  1521. }
  1522. private void ribbonButtonLengthAndWidth_Click(object sender, EventArgs e)
  1523. {
  1524. //m_SamplepaceWindow.DrawRectangleByLengthAndWidth();
  1525. }
  1526. }
  1527. }