OTSPropertyWindow.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. using System;
  2. using System.Drawing;
  3. using System.Linq;
  4. using System.Windows.Forms;
  5. using OTS.WinFormsUI.Docking;
  6. using OTSDataType;
  7. using OTSMeasureApp._3_OTSDisplaySourceGridData;
  8. using OTSModelSharp.ResourceManage;
  9. using System.Collections.Generic;
  10. using OTSMeasureApp._7_OTSProgMgrInfo;
  11. namespace OTSMeasureApp
  12. {
  13. public partial class OTSPropertyWindow : DockContent
  14. {
  15. public OTSIncAMeasureAppForm m_MeasureAppForm = null;
  16. public OTSDisplaySampleGrid m_SampleGrid = null;
  17. frmMeasureStopMode frmStopModeDialog;
  18. OtherSelectionForm otherSelectionForm;
  19. public OTSPropertyWindow(OTSIncAMeasureAppForm MeasureAppForm)
  20. {
  21. InitializeComponent();
  22. m_MeasureAppForm = MeasureAppForm;
  23. m_SampleGrid = new OTSDisplaySampleGrid(this);
  24. //国际化
  25. OTSCommon.Language lan = new OTSCommon.Language(this);
  26. }
  27. //接收 MeasureApp 发送的样品属性数据,通过Grid显示在properyWindow上
  28. public void DisplaySampleMeasureInfo(OTSSampleVisualPropertyInfo SampleInfo)
  29. {
  30. SampleInfo.InitPropItemGrps();
  31. SampleInfo.UpdatePropertyData();
  32. PropGrid.Show();
  33. m_SampleGrid.m_ClickRow = 0;
  34. m_SampleGrid.m_ClickColumn = 0;
  35. if (PropGrid.Rows.Count() > 0)
  36. {
  37. PropGrid.Rows.Clear();
  38. PropGrid.Redim(OTSDisplaySampleGrid.Const_Grid_Row, OTSDisplaySampleGrid.Const_Grid_Column);
  39. }
  40. m_SampleGrid.InitGrid();
  41. m_SampleGrid.ShowSampleInfoGrid(SampleInfo);
  42. int iPropertyDisplayMode = m_MeasureAppForm.m_ProjParam.GetDefaultParam().GetCommonParam().PropertyDisplayMode();
  43. if (iPropertyDisplayMode == 1)
  44. {
  45. for (int i = 6; i < PropGrid.Rows.Count(); i++)
  46. {
  47. PropGrid.Rows.HideRow(i);
  48. }
  49. }
  50. else if (iPropertyDisplayMode == 0)
  51. {
  52. for (int i = 6; i < PropGrid.Rows.Count(); i++)
  53. {
  54. PropGrid.Rows.ShowRow(i);
  55. }
  56. }
  57. toolStripButton_refresh.Enabled = true;
  58. PropGrid.Refresh();
  59. PropGrid.Invalidate();
  60. }
  61. private void OTSPropertyWindow_Load(object sender, EventArgs e)
  62. {
  63. }
  64. private void OTSPropertyWindow_Resize(object sender, EventArgs e)
  65. {
  66. if (null != m_SampleGrid)
  67. {
  68. m_SampleGrid.m_PropWindow_X = this.Width;
  69. m_SampleGrid.InitGridTitlet();
  70. }
  71. }
  72. public void SampleGridInfoChange(OTS_SAMPLE_PROP_GRID_ITEMS SampleId, OTS_ITEM_TYPES ValType, object ObjVal)
  73. {
  74. var PropertyMeasureThreadRunFlag = m_MeasureAppForm.m_MsrThreadWrapper.BGWorkThreadIsRunning();
  75. var measureTreadIsPaused = m_MeasureAppForm.m_MsrThreadWrapper.BgWorkIsPaused();
  76. if (measureTreadIsPaused == false && PropertyMeasureThreadRunFlag == true)
  77. {
  78. return;
  79. }
  80. var m_measurePara = m_MeasureAppForm.m_ProjParam;
  81. var sample = m_measurePara.GetWorkSample();
  82. var stype = m_measurePara.GetDefaultParam().GetSysType();
  83. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(sample, stype);
  84. switch (SampleId)
  85. {
  86. case OTS_SAMPLE_PROP_GRID_ITEMS.STD_FILE_NAME:
  87. if (SMInfo.SetSTDFileName((int)ObjVal))
  88. {
  89. DisplaySampleMeasureInfo(SMInfo);
  90. return;
  91. }
  92. break;
  93. case OTS_SAMPLE_PROP_GRID_ITEMS.SAMPLE_NAME:
  94. string strNewName = (string)ObjVal;
  95. strNewName = strNewName.Trim();
  96. string oldName = m_measurePara.GetWorkSampleName();
  97. if (!m_measurePara.CheckSampleNameIsValid(strNewName))
  98. {
  99. //update source grid,recover to the original value
  100. DisplaySampleMeasureInfo(SMInfo);
  101. return;
  102. }
  103. m_measurePara.SetSampleParamVal(OTS_SAMPLE_PROP_GRID_ITEMS.SAMPLE_NAME, OTS_ITEM_TYPES.STRING, strNewName);
  104. //update visual stage
  105. m_MeasureAppForm.m_SamplepaceWindow.ChangeWorkSampleName(strNewName);
  106. var m_SolutionWindows = m_MeasureAppForm.m_SolutionWindows;
  107. //update the project sample list on the left of the main gui interface.
  108. m_SolutionWindows.m_TreeViewBase.EditTreeWorkSampleName(oldName, strNewName);
  109. //update source grid
  110. DisplaySampleMeasureInfo(SMInfo);
  111. break;
  112. case OTS_SAMPLE_PROP_GRID_ITEMS.STOP_MODE:
  113. if (!m_measurePara.SetSampleParamVal(OTS_SAMPLE_PROP_GRID_ITEMS.STOP_PARAM_FIELD, OTS_ITEM_TYPES.INT, frmStopModeDialog.FieldMode)) // Prop值变化,修改样品值成功
  114. {
  115. DisplaySampleMeasureInfo(SMInfo);
  116. return;
  117. }
  118. if (!m_measurePara.SetSampleParamVal(OTS_SAMPLE_PROP_GRID_ITEMS.STOP_PARAM_TIME, OTS_ITEM_TYPES.INT, frmStopModeDialog.TimeMode)) // Prop值变化,修改样品值成功
  119. {
  120. DisplaySampleMeasureInfo(SMInfo);
  121. return;
  122. }
  123. if (!m_measurePara.SetSampleParamVal(OTS_SAMPLE_PROP_GRID_ITEMS.STOP_PARAM_PARTICLE, OTS_ITEM_TYPES.INT, frmStopModeDialog.ParticleMode)) // Prop值变化,修改样品值成功
  124. {
  125. DisplaySampleMeasureInfo(SMInfo);
  126. return;
  127. }
  128. if (!m_measurePara.SetSampleParamVal(OTS_SAMPLE_PROP_GRID_ITEMS.STOP_PARAM_AREA, OTS_ITEM_TYPES.INT, frmStopModeDialog.AreaMode)) // Prop值变化,修改样品值成功
  129. {
  130. DisplaySampleMeasureInfo(SMInfo);
  131. return;
  132. }
  133. if (!m_measurePara.SetSampleParamVal(OTS_SAMPLE_PROP_GRID_ITEMS.STOP_MODE, OTS_ITEM_TYPES.STRING, frmStopModeDialog.StopMode)) // Prop值变化,修改样品值成功
  134. {
  135. DisplaySampleMeasureInfo(SMInfo);
  136. return;
  137. }
  138. break;
  139. case OTS_SAMPLE_PROP_GRID_ITEMS.OtherSelection:
  140. if (!m_measurePara.SetSampleParamVal(OTS_SAMPLE_PROP_GRID_ITEMS.OtherSelection, OTS_ITEM_TYPES.STRING, otherSelectionForm.OtherSelection)) // Prop值变化,修改样品值成功
  141. {
  142. DisplaySampleMeasureInfo(SMInfo);
  143. return;
  144. }
  145. break;
  146. default:
  147. if (!m_measurePara.SetSampleParamVal(SampleId, ValType, ObjVal)) // Prop值变化,修改样品值成功
  148. {
  149. DisplaySampleMeasureInfo(SMInfo);
  150. return;
  151. }
  152. break;
  153. }
  154. //---after modify the value of current sample properties,update the corresponding value of GUI.---
  155. if (
  156. OTS_SAMPLE_PROP_GRID_ITEMS.MAGNIFICATION == SampleId
  157. || OTS_SAMPLE_PROP_GRID_ITEMS.PIXEL_SIZE == SampleId
  158. || OTS_SAMPLE_PROP_GRID_ITEMS.START_PHOTO_MODE == SampleId
  159. || OTS_SAMPLE_PROP_GRID_ITEMS.XRAYSCAN_MODE == SampleId
  160. )
  161. {
  162. var sam = m_MeasureAppForm.m_SamplepaceWindow.GetWorkingVisualSample();
  163. m_MeasureAppForm.m_SamplepaceWindow.PrepareVisualMeasureField(sam);
  164. DisplaySampleMeasureInfo(SMInfo);
  165. return;
  166. }
  167. if (OTS_SAMPLE_PROP_GRID_ITEMS.SWITCH == SampleId)
  168. {
  169. m_MeasureAppForm.m_SolutionWindows.Rev_MeasureApp_CheckboxStatuChange_Event(m_measurePara.GetWorkSampleName(), SMInfo.TSampleParam.bSwitch);
  170. // 设置 开始 ,停止 和检查参数 按钮状态
  171. m_MeasureAppForm.SetMeasureRibbonButnStatu();
  172. }
  173. //update the source grid value
  174. DisplaySampleMeasureInfo(SMInfo);
  175. }
  176. private void toolStrip1_Paint(object sender, PaintEventArgs e)
  177. {
  178. if ((sender as ToolStrip).RenderMode == ToolStripRenderMode.System)
  179. {
  180. Rectangle rect = new Rectangle(0, 0, this.TSGridTitle.Width - 5, this.TSGridTitle.Height - 5);
  181. e.Graphics.SetClip(rect);
  182. }
  183. }
  184. private void PropGrid_Click_1(object sender, EventArgs e)
  185. {
  186. SourceGrid.Grid ls_gd = (SourceGrid.Grid)sender;
  187. ls_gd.Focus();
  188. m_SampleGrid.m_ClickRow = ls_gd.Selection.ActivePosition.Row;
  189. m_SampleGrid.m_ClickColumn = ls_gd.Selection.ActivePosition.Column;
  190. /// 保证鼠标点击的GRID行和列是有效的
  191. if (m_SampleGrid.m_ClickRow >= 0 && m_SampleGrid.m_ClickColumn >= 0)
  192. {
  193. m_SampleGrid.SetGridTitleStatus();
  194. if (PropGrid.Rows[m_SampleGrid.m_ClickRow].Tag == null)
  195. {
  196. return;
  197. }
  198. if ((OTS_SAMPLE_PROP_GRID_ITEMS)PropGrid.Rows[m_SampleGrid.m_ClickRow].Tag == OTS_SAMPLE_PROP_GRID_ITEMS.STOP_MODE && m_SampleGrid.m_ClickColumn == 2)
  199. {
  200. frmStopModeDialog = new frmMeasureStopMode();
  201. frmStopModeDialog.FieldMode = int.Parse(PropGrid[m_SampleGrid.m_ClickRow + 2, m_SampleGrid.m_ClickColumn].Value.ToString());
  202. frmStopModeDialog.TimeMode = int.Parse(PropGrid[m_SampleGrid.m_ClickRow + 3, m_SampleGrid.m_ClickColumn].Value.ToString());
  203. frmStopModeDialog.ParticleMode = int.Parse(PropGrid[m_SampleGrid.m_ClickRow + 1, m_SampleGrid.m_ClickColumn].Value.ToString());
  204. frmStopModeDialog.StopMode = PropGrid[m_SampleGrid.m_ClickRow, m_SampleGrid.m_ClickColumn].Value.ToString();
  205. frmStopModeDialog.AreaMode = int.Parse(PropGrid[m_SampleGrid.m_ClickRow + 4, m_SampleGrid.m_ClickColumn].Value.ToString());
  206. DialogResult result = frmStopModeDialog.ShowDialog();
  207. if (result == DialogResult.OK)
  208. {
  209. string str = PropGrid[0, 0].Value.ToString();
  210. PropGrid[m_SampleGrid.m_ClickRow, m_SampleGrid.m_ClickColumn].Value = frmStopModeDialog.StopMode;
  211. PropGrid[m_SampleGrid.m_ClickRow + 2, m_SampleGrid.m_ClickColumn].Value = frmStopModeDialog.FieldMode;
  212. PropGrid[m_SampleGrid.m_ClickRow + 3, m_SampleGrid.m_ClickColumn].Value = frmStopModeDialog.TimeMode;
  213. PropGrid[m_SampleGrid.m_ClickRow + 1, m_SampleGrid.m_ClickColumn].Value = frmStopModeDialog.ParticleMode;
  214. PropGrid[m_SampleGrid.m_ClickRow + 4, m_SampleGrid.m_ClickColumn].Value = frmStopModeDialog.AreaMode;
  215. PropGrid[0, 0].Value = str;
  216. PropGrid.Refresh();
  217. PropGrid.Invalidate();
  218. }
  219. }
  220. else if ((OTS_SAMPLE_PROP_GRID_ITEMS)PropGrid.Rows[m_SampleGrid.m_ClickRow].Tag == OTS_SAMPLE_PROP_GRID_ITEMS.OtherSelection && m_SampleGrid.m_ClickColumn == 2)
  221. {
  222. otherSelectionForm = new OtherSelectionForm();
  223. if (PropGrid[m_SampleGrid.m_ClickRow, m_SampleGrid.m_ClickColumn].Value.ToString() != "NoFilter")
  224. {
  225. otherSelectionForm.OtherSelection = PropGrid[m_SampleGrid.m_ClickRow, m_SampleGrid.m_ClickColumn].Value.ToString();
  226. }
  227. else
  228. {
  229. otherSelectionForm.OtherSelection = "";
  230. }
  231. DialogResult result = otherSelectionForm.ShowDialog();
  232. if (result == DialogResult.OK)
  233. {
  234. string str = PropGrid[0, 0].Value.ToString();
  235. if (otherSelectionForm.OtherSelection == "")
  236. {
  237. PropGrid[m_SampleGrid.m_ClickRow, m_SampleGrid.m_ClickColumn].Value = "NoFilter";
  238. }
  239. else
  240. {
  241. PropGrid[m_SampleGrid.m_ClickRow, m_SampleGrid.m_ClickColumn].Value = otherSelectionForm.OtherSelection;
  242. }
  243. PropGrid[0, 0].Value = str;
  244. PropGrid.Refresh();
  245. PropGrid.Invalidate();
  246. }
  247. }
  248. }
  249. }
  250. private void TSSaveAs_Click(object sender, EventArgs e)
  251. {
  252. OTSModelSharp.COTSDefaultParam m_cotsprogmgrparamfile = m_MeasureAppForm.m_ProjParam.GetDefaultParam();
  253. COTSSample WSample = m_MeasureAppForm.m_ProjParam.GetResultData().GetWorkingSample();
  254. m_cotsprogmgrparamfile.SetImageProcParam(WSample.GetMsrParams().GetImageProcessParam().Duplicate());
  255. m_cotsprogmgrparamfile.SetImageScanParam(WSample.GetMsrParams().GetImageScanParam().Duplicate());
  256. m_cotsprogmgrparamfile.SetXRayParam(WSample.GetMsrParams().GetXRayParam().Duplicate());
  257. m_cotsprogmgrparamfile.SpecialGrayRangeParam = WSample.GetMsrParams().GetSpecialGrayRangeParam().Duplicate();
  258. OTSModelSharp.COTSCommonParam m_cgenparam = m_cotsprogmgrparamfile.GetCommonParam();
  259. m_cgenparam.SetEngineType(WSample.GetMsrParams().GetEngineType());
  260. m_cgenparam.SetSteelTechnology((int)WSample.GetMsrParams().GetSteelTechnology());
  261. m_cgenparam.SetSTDSelect(WSample.GetMsrParams().GetSTDName().ToString());
  262. m_cotsprogmgrparamfile.SetCommonParam(m_cgenparam.duplicate());
  263. if (m_cotsprogmgrparamfile.SaveInfoToProgMgrFile())
  264. {
  265. //MessageBox.Show("Already saved!", "Tip");
  266. }
  267. m_MeasureAppForm.m_ProjParam.SetDefaultParam(m_cotsprogmgrparamfile);
  268. }
  269. private void TSEdit_Click(object sender, EventArgs e)
  270. {
  271. }
  272. private void TSLoad_Click(object sender, EventArgs e)
  273. {
  274. if (m_SampleGrid.m_ClickRow <= 0)
  275. {
  276. m_MeasureAppForm.m_ProjParam.LoadWorkMeasureFile();
  277. return;
  278. }
  279. if (OTS_SAMPLE_PROP_GRID_ITEMS.STD_FILE_NAME == (OTS_SAMPLE_PROP_GRID_ITEMS)PropGrid.Rows[m_SampleGrid.m_ClickRow].Tag)
  280. {
  281. return;
  282. }
  283. else
  284. {
  285. m_MeasureAppForm.m_ProjParam.LoadWorkMeasureFile();
  286. return;
  287. }
  288. }
  289. private void toolStripButton_refresh_Click(object sender, EventArgs e)
  290. {
  291. var sample = m_MeasureAppForm.m_ProjParam.GetWorkSample();
  292. var stype = m_MeasureAppForm.m_ProjParam.GetDefaultParam().GetSysType();
  293. OTSSampleVisualPropertyInfo MeasureInfo = new OTSSampleVisualPropertyInfo(sample, stype);
  294. DisplaySampleMeasureInfo(MeasureInfo);
  295. }
  296. }
  297. }