OTSPropertyWindow.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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 OTSModelSharp.ResourceManage;
  8. namespace OTSMeasureApp
  9. {
  10. public partial class OTSPropertyWindow : DockContent
  11. {
  12. public OTSIncAMeasureAppForm m_MeasureAppForm = null;
  13. public OTSDisplaySampleGrid m_SampleGrid = null;
  14. public OTSPropertyWindow(OTSIncAMeasureAppForm MeasureAppForm)
  15. {
  16. InitializeComponent();
  17. m_MeasureAppForm = MeasureAppForm;
  18. //this.InitDelegateEvent();
  19. m_SampleGrid = new OTSDisplaySampleGrid(this);
  20. //国际化
  21. OTSSysMgrTools.Language lan = new OTSSysMgrTools.Language(this);
  22. }
  23. //接收 MeasureApp 发送的样品属性数据,通过Grid显示在properyWindow上
  24. public void DisplaySampleMeasureInfo(OTSSamplePropertyInfo SampleInfo)
  25. {
  26. //当点击事件响应结束后,将之前点击的行数和列数清0,避免选择工作样品重新赋值响应CELL值改变事件
  27. PropGrid.Show();
  28. m_SampleGrid.m_ClickRow = 0;
  29. m_SampleGrid.m_ClickColumn = 0;
  30. if(PropGrid.Rows.Count()>0)
  31. {
  32. PropGrid.Rows.Clear();
  33. PropGrid.Redim(OTSDisplaySampleGrid.Const_Grid_Row, OTSDisplaySampleGrid.Const_Grid_Column);
  34. }
  35. m_SampleGrid.InitGrid();
  36. m_SampleGrid.ShowSampleInfoGrid(SampleInfo);
  37. ;
  38. int iPropertyDisplayMode = m_MeasureAppForm.m_ProjParam.m_DefaultParam.GetGenParam().PropertyDisplayMode();
  39. if (iPropertyDisplayMode == 1)
  40. {
  41. for (int i = 6; i < PropGrid.Rows.Count(); i++)
  42. {
  43. PropGrid.Rows.HideRow(i);
  44. }
  45. }
  46. else if (iPropertyDisplayMode == 0)
  47. {
  48. for (int i = 6; i < PropGrid.Rows.Count(); i++)
  49. {
  50. PropGrid.Rows.ShowRow(i);
  51. }
  52. }
  53. PropGrid.Refresh();
  54. PropGrid.Invalidate();
  55. }
  56. private void OTSPropertyWindow_Load(object sender, EventArgs e)
  57. {
  58. int WFormWidth = this.Width;
  59. int Height = this.Height;
  60. // m_SampleGrid.TestShowGrid();
  61. }
  62. private void OTSPropertyWindow_Resize(object sender, EventArgs e)
  63. {
  64. {
  65. if (null != m_SampleGrid )
  66. {
  67. m_SampleGrid.m_PropWindow_X = this.Width;
  68. m_SampleGrid.InitGridTitlet();
  69. }
  70. }
  71. }
  72. public void SampleGridInfoChange(OTS_SAMPLE_PROP_GRID_ITEMS SampleId, OTS_ITEM_TYPES ValType, object ObjVal)
  73. {
  74. var PropertyMeasureThreadRunFlag = m_MeasureAppForm.MeasureThreadRunFlag;
  75. var m_SolutionWindows = m_MeasureAppForm.m_SolutionWindows;
  76. //设置样品属性参数成功
  77. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  78. var m_DataMgr = m_MeasureAppForm.m_ProjParam;
  79. //当前正在测量
  80. if (PropertyMeasureThreadRunFlag)
  81. {
  82. goto HERE;
  83. }
  84. string sWSampleName = m_DataMgr.GetWorkSampleName();
  85. if ("" == sWSampleName)
  86. {
  87. return;
  88. }
  89. //更新 MEASURE_PARAM_FILE_NAME FILE_LIST
  90. if (OTS_SAMPLE_PROP_GRID_ITEMS.MEASURE_PARAM_FILE_NAME == SampleId)
  91. {
  92. if (!m_DataMgr.SetMeasrueParamFileName((int)ObjVal))
  93. {
  94. //重新获取原来工作样品值重新设置
  95. if (!m_DataMgr.GetWorkSamplePerameter(m_DataMgr.GetWorkSample(), ref SMInfo))
  96. {
  97. return;
  98. }
  99. //Prop重新获显示工作样品的原来值
  100. DisplaySampleMeasureInfo(SMInfo);
  101. return;
  102. }
  103. }
  104. //更新 STD_FILE_NAME FILE_LIST
  105. else if (OTS_SAMPLE_PROP_GRID_ITEMS.STD_FILE_NAME == SampleId)
  106. {
  107. if (m_DataMgr.SetSTDFileName((int)ObjVal))
  108. {
  109. //重新获取原来工作样品值重新设置
  110. if (!m_DataMgr.GetWorkSamplePerameter(m_DataMgr.GetWorkSample(), ref SMInfo))
  111. {
  112. //系统工作文件出错,设置样品属性失败
  113. return;
  114. }
  115. //Prop重新获显示工作样品的原来值
  116. DisplaySampleMeasureInfo(SMInfo);
  117. return;
  118. }
  119. }
  120. else
  121. {
  122. if (OTS_SAMPLE_PROP_GRID_ITEMS.SAMPLE_NAME == SampleId)
  123. {
  124. //去除修改GRID的样品名的前后空格
  125. string str = (string)ObjVal;
  126. str = str.Trim();
  127. ObjVal = str;
  128. if (!m_DataMgr.CheckSampleNameIsValid((string)ObjVal))
  129. {
  130. //重新获取原来工作样品值重新设置
  131. if (!m_DataMgr.GetWorkSamplePerameter(m_DataMgr.GetWorkSample(), ref SMInfo))
  132. {
  133. return;
  134. }
  135. //Prop重新获显示工作样品的原来值
  136. DisplaySampleMeasureInfo(SMInfo);
  137. return;
  138. }
  139. }
  140. //更新COMBBOX值
  141. if (!m_DataMgr.SetSampleParamVal(SampleId, ValType, ObjVal)) // Prop值变化,修改样品值成功
  142. {
  143. string sLog = "SampleId = " + SampleId.ToString() + "," + "ValType = " + ValType.ToString() + "," + "ObjVal = " + ObjVal.ToString();
  144. //重新获取原来工作样品值重新设置
  145. if (!m_DataMgr.GetWorkSamplePerameter(m_DataMgr.GetWorkSample(), ref SMInfo))
  146. {
  147. return;
  148. }
  149. //Prop重新获显示工作样品的原来值
  150. DisplaySampleMeasureInfo(SMInfo);
  151. return;
  152. }
  153. }
  154. //更新GROUPID和ITEMID的变化
  155. OTS_SAMPLE_PROP_GRID_ITEMS ItemID = (OTS_SAMPLE_PROP_GRID_ITEMS)SampleId;
  156. m_DataMgr.UpdateGroupValAndItemVal(ItemID);
  157. //修改Treeview 工作样品名字
  158. if (OTS_SAMPLE_PROP_GRID_ITEMS.SAMPLE_NAME == SampleId)
  159. {
  160. m_SolutionWindows.m_TreeViewBase.EditTreeWorkSampleName(sWSampleName, (string)ObjVal);
  161. //将已存在的帧图修改为重命名
  162. if (OTSSamplespaceWindow.m_ALLSingleGDIObjects != null)
  163. {
  164. if (OTSSamplespaceWindow.m_ALLSingleGDIObjects.Count > 0)
  165. {
  166. OTSSamplespaceGraphicsPanelFun.EditWorkSampleName(OTSSamplespaceWindow.m_ALLSingleGDIObjects, sWSampleName, (string)ObjVal);
  167. }
  168. }
  169. }
  170. HERE:
  171. if (!m_DataMgr.GetWorkSamplePerameter(m_DataMgr.GetWorkSample(), ref SMInfo))
  172. {
  173. //系统工作文件出错,设置样品属性失败
  174. return;
  175. }
  176. // 修改TREEVIEW 工作样品的CHECKBOX值
  177. if (OTS_SAMPLE_PROP_GRID_ITEMS.SWITCH == SampleId)
  178. {
  179. //修改TREEVIEW对应的样品的CHECKBOX值
  180. m_SolutionWindows.Rev_MeasureApp_CheckboxStatuChange_Event(m_DataMgr.GetWorkSampleName(), SMInfo.TSampleParam.bSwitch);
  181. // 设置 开始 ,停止 和检查参数 按钮状态
  182. m_MeasureAppForm. m_RibbonFun.SetMeasureRibbonButnStatu();
  183. }
  184. //设置SampleWindow新的工作样品
  185. sWSampleName = m_DataMgr.GetWorkSampleName();
  186. if (!("" == sWSampleName))
  187. {
  188. m_MeasureAppForm. m_SamplepaceWindow.ChangeWorkSampleName(sWSampleName);
  189. }
  190. //GRID重新获取工作样品属性值
  191. DisplaySampleMeasureInfo(SMInfo);
  192. //当修改了 样品图尺寸、放大倍数和样品图的Pix大小,SAMPLEWINDOW需要重新绘制样品台
  193. if (OTS_SAMPLE_PROP_GRID_ITEMS.IMAGE_GRP_MAX == SampleId || OTS_SAMPLE_PROP_GRID_ITEMS.MAGNIFICATION == SampleId
  194. || OTS_SAMPLE_PROP_GRID_ITEMS.PIXEL_SIZE == SampleId)
  195. {
  196. m_MeasureAppForm. m_SamplepaceWindow.Rev_DDDrawSampleStage_EventHandler_Event();
  197. }
  198. }
  199. private void toolStrip1_Paint(object sender, PaintEventArgs e)
  200. {
  201. if ((sender as ToolStrip).RenderMode == ToolStripRenderMode.System)
  202. {
  203. Rectangle rect = new Rectangle(0, 0, this.TSGridTitle.Width - 5, this.TSGridTitle.Height - 5);
  204. e.Graphics.SetClip(rect);
  205. }
  206. }
  207. private void PropGrid_Click_1(object sender, EventArgs e)
  208. {
  209. SourceGrid.Grid ls_gd = (SourceGrid.Grid)sender;
  210. ls_gd.Focus();
  211. m_SampleGrid.m_ClickRow = ls_gd.Selection.ActivePosition.Row;
  212. m_SampleGrid.m_ClickColumn = ls_gd.Selection.ActivePosition.Column;
  213. /// 保证鼠标点击的GRID行和列是有效的
  214. if(m_SampleGrid.m_ClickRow>=0 && m_SampleGrid.m_ClickColumn>=0)
  215. {
  216. m_SampleGrid.SetGridTitleStatus();
  217. }
  218. }
  219. private void TSSaveAs_Click(object sender, EventArgs e)
  220. {
  221. m_MeasureAppForm.m_ProjParam.SaveWorkMeasureFile();
  222. }
  223. private void TSEdit_Click(object sender, EventArgs e)
  224. {
  225. }
  226. private void TSLoad_Click(object sender, EventArgs e)
  227. {
  228. if (m_SampleGrid.m_ClickRow <= 0)
  229. {
  230. m_MeasureAppForm.m_ProjParam.LoadWorkMeasureFile();
  231. return;
  232. }
  233. if (OTS_SAMPLE_PROP_GRID_ITEMS.STD_FILE_NAME == (OTS_SAMPLE_PROP_GRID_ITEMS)PropGrid.Rows[m_SampleGrid.m_ClickRow].Tag)
  234. {
  235. return;
  236. }
  237. else
  238. {
  239. m_MeasureAppForm.m_ProjParam.LoadWorkMeasureFile();
  240. return;
  241. }
  242. }
  243. }
  244. }