OTSPropertyWindow.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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. || OTS_SAMPLE_PROP_GRID_ITEMS.FIELD_DISTRIBUTION_MODE == SampleId
  161. )
  162. {
  163. var sam = m_MeasureAppForm.m_SamplepaceWindow.GetWorkingVisualSample();
  164. m_MeasureAppForm.m_SamplepaceWindow.PrepareVisualMeasureField(sam);
  165. DisplaySampleMeasureInfo(SMInfo);
  166. return;
  167. }
  168. if (OTS_SAMPLE_PROP_GRID_ITEMS.SWITCH == SampleId)
  169. {
  170. m_MeasureAppForm.m_SolutionWindows.Rev_MeasureApp_CheckboxStatuChange_Event(m_measurePara.GetWorkSampleName(), SMInfo.TSampleParam.bSwitch);
  171. // 设置 开始 ,停止 和检查参数 按钮状态
  172. m_MeasureAppForm.SetMeasureRibbonButnStatu();
  173. }
  174. //update the source grid value
  175. DisplaySampleMeasureInfo(SMInfo);
  176. }
  177. private void toolStrip1_Paint(object sender, PaintEventArgs e)
  178. {
  179. if ((sender as ToolStrip).RenderMode == ToolStripRenderMode.System)
  180. {
  181. Rectangle rect = new Rectangle(0, 0, this.TSGridTitle.Width - 5, this.TSGridTitle.Height - 5);
  182. e.Graphics.SetClip(rect);
  183. }
  184. }
  185. private void PropGrid_Click_1(object sender, EventArgs e)
  186. {
  187. SourceGrid.Grid ls_gd = (SourceGrid.Grid)sender;
  188. ls_gd.Focus();
  189. m_SampleGrid.m_ClickRow = ls_gd.Selection.ActivePosition.Row;
  190. m_SampleGrid.m_ClickColumn = ls_gd.Selection.ActivePosition.Column;
  191. /// 保证鼠标点击的GRID行和列是有效的
  192. if (m_SampleGrid.m_ClickRow >= 0 && m_SampleGrid.m_ClickColumn >= 0)
  193. {
  194. m_SampleGrid.SetGridTitleStatus();
  195. if (PropGrid.Rows[m_SampleGrid.m_ClickRow].Tag == null)
  196. {
  197. return;
  198. }
  199. 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)
  200. {
  201. frmStopModeDialog = new frmMeasureStopMode();
  202. frmStopModeDialog.FieldMode = int.Parse(PropGrid[m_SampleGrid.m_ClickRow + 2, m_SampleGrid.m_ClickColumn].Value.ToString());
  203. frmStopModeDialog.TimeMode = int.Parse(PropGrid[m_SampleGrid.m_ClickRow + 3, m_SampleGrid.m_ClickColumn].Value.ToString());
  204. frmStopModeDialog.ParticleMode = int.Parse(PropGrid[m_SampleGrid.m_ClickRow + 1, m_SampleGrid.m_ClickColumn].Value.ToString());
  205. frmStopModeDialog.StopMode = PropGrid[m_SampleGrid.m_ClickRow, m_SampleGrid.m_ClickColumn].Value.ToString();
  206. frmStopModeDialog.AreaMode = int.Parse(PropGrid[m_SampleGrid.m_ClickRow + 4, m_SampleGrid.m_ClickColumn].Value.ToString());
  207. DialogResult result = frmStopModeDialog.ShowDialog();
  208. if (result == DialogResult.OK)
  209. {
  210. string str = PropGrid[0, 0].Value.ToString();
  211. PropGrid[m_SampleGrid.m_ClickRow, m_SampleGrid.m_ClickColumn].Value = frmStopModeDialog.StopMode;
  212. PropGrid[m_SampleGrid.m_ClickRow + 2, m_SampleGrid.m_ClickColumn].Value = frmStopModeDialog.FieldMode;
  213. PropGrid[m_SampleGrid.m_ClickRow + 3, m_SampleGrid.m_ClickColumn].Value = frmStopModeDialog.TimeMode;
  214. PropGrid[m_SampleGrid.m_ClickRow + 1, m_SampleGrid.m_ClickColumn].Value = frmStopModeDialog.ParticleMode;
  215. PropGrid[m_SampleGrid.m_ClickRow + 4, m_SampleGrid.m_ClickColumn].Value = frmStopModeDialog.AreaMode;
  216. PropGrid[0, 0].Value = str;
  217. PropGrid.Refresh();
  218. PropGrid.Invalidate();
  219. }
  220. }
  221. 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)
  222. {
  223. otherSelectionForm = new OtherSelectionForm();
  224. if (PropGrid[m_SampleGrid.m_ClickRow, m_SampleGrid.m_ClickColumn].Value.ToString() != "NoFilter")
  225. {
  226. otherSelectionForm.OtherSelection = PropGrid[m_SampleGrid.m_ClickRow, m_SampleGrid.m_ClickColumn].Value.ToString();
  227. }
  228. else
  229. {
  230. otherSelectionForm.OtherSelection = "";
  231. }
  232. DialogResult result = otherSelectionForm.ShowDialog();
  233. if (result == DialogResult.OK)
  234. {
  235. string str = PropGrid[0, 0].Value.ToString();
  236. if (otherSelectionForm.OtherSelection == "")
  237. {
  238. PropGrid[m_SampleGrid.m_ClickRow, m_SampleGrid.m_ClickColumn].Value = "NoFilter";
  239. }
  240. else
  241. {
  242. PropGrid[m_SampleGrid.m_ClickRow, m_SampleGrid.m_ClickColumn].Value = otherSelectionForm.OtherSelection;
  243. }
  244. PropGrid[0, 0].Value = str;
  245. PropGrid.Refresh();
  246. PropGrid.Invalidate();
  247. }
  248. }
  249. }
  250. }
  251. private void TSSaveAs_Click(object sender, EventArgs e)
  252. {
  253. OTSModelSharp.COTSDefaultParam m_cotsprogmgrparamfile = m_MeasureAppForm.m_ProjParam.GetDefaultParam();
  254. COTSSample WSample = m_MeasureAppForm.m_ProjParam.GetResultData().GetWorkingSample();
  255. m_cotsprogmgrparamfile.SetImageProcParam(WSample.GetMsrParams().GetImageProcessParam().Duplicate());
  256. m_cotsprogmgrparamfile.SetImageScanParam(WSample.GetMsrParams().GetImageScanParam().Duplicate());
  257. m_cotsprogmgrparamfile.SetXRayParam(WSample.GetMsrParams().GetXRayParam().Duplicate());
  258. m_cotsprogmgrparamfile.SpecialGrayRangeParam = WSample.GetMsrParams().GetImageProcessParam().GetSpecialGreyRangeParam().Duplicate();
  259. OTSModelSharp.COTSCommonParam m_cgenparam = m_cotsprogmgrparamfile.GetCommonParam();
  260. m_cgenparam.SetEngineType(WSample.GetMsrParams().GetEngineType());
  261. m_cgenparam.SetSteelTechnology((int)WSample.GetMsrParams().GetSteelTechnology());
  262. m_cgenparam.SetSTDSelect(WSample.GetMsrParams().GetSTDName().ToString());
  263. m_cotsprogmgrparamfile.SetCommonParam(m_cgenparam.duplicate());
  264. if (m_cotsprogmgrparamfile.SaveInfoToProgMgrFile())
  265. {
  266. //MessageBox.Show("Already saved!", "Tip");
  267. }
  268. m_MeasureAppForm.m_ProjParam.SetDefaultParam(m_cotsprogmgrparamfile);
  269. }
  270. private void TSEdit_Click(object sender, EventArgs e)
  271. {
  272. }
  273. private void TSLoad_Click(object sender, EventArgs e)
  274. {
  275. if (m_SampleGrid.m_ClickRow <= 0)
  276. {
  277. m_MeasureAppForm.m_ProjParam.LoadWorkMeasureFile();
  278. return;
  279. }
  280. if (OTS_SAMPLE_PROP_GRID_ITEMS.STD_FILE_NAME == (OTS_SAMPLE_PROP_GRID_ITEMS)PropGrid.Rows[m_SampleGrid.m_ClickRow].Tag)
  281. {
  282. return;
  283. }
  284. else
  285. {
  286. m_MeasureAppForm.m_ProjParam.LoadWorkMeasureFile();
  287. return;
  288. }
  289. }
  290. private void toolStripButton_refresh_Click(object sender, EventArgs e)
  291. {
  292. var sample = m_MeasureAppForm.m_ProjParam.GetWorkSample();
  293. var stype = m_MeasureAppForm.m_ProjParam.GetDefaultParam().GetSysType();
  294. OTSSampleVisualPropertyInfo MeasureInfo = new OTSSampleVisualPropertyInfo(sample, stype);
  295. DisplaySampleMeasureInfo(MeasureInfo);
  296. }
  297. }
  298. }