DlgStageMgr.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using OTSDataType;
  11. using static OTSModelSharp.ResourceManage.ResourceID;
  12. using static OTSModelSharp.ResourceManage.ResourceData;
  13. using System.Drawing.Drawing2D;
  14. namespace OTSModelSharp.Measure.GetStageInfo
  15. {
  16. public partial class DlgStageMgr : Form
  17. {
  18. public static NLog.Logger loger = NLog.LogManager.GetCurrentClassLogger();
  19. otsdataconst model = new otsdataconst();
  20. // stage file
  21. CStageParam m_pStageFile;
  22. // stage list value
  23. int m_nListBoxStageListIndex=0;
  24. // flag if the stage should be re-paint
  25. bool m_bShowFlag;
  26. // boundary
  27. CDomain m_poBourary;
  28. const int RATIO_RECT_LEFT = 22; //ratio rect left edge
  29. const int PIC_EDGE = 12; //edge width
  30. const int RATIO_RECT_HEIGHT = 30; //ratio rect height
  31. const int RATIO_RECT_DOWN = 10; //ratio rect down edge
  32. const int LTGRAY_BRUSH = 1;
  33. const int BLACK_BRUSH = 4;
  34. const int WHITE_BRUSH = 0;
  35. const int ROUND_VALUE = 20; //round rect angle
  36. public struct BLENDFUNCTION
  37. {
  38. public Byte BlendOp;
  39. public Byte BlendFlags;
  40. public Byte SourceConstantAlpha;
  41. public Byte AlphaFormat;
  42. }
  43. public DlgStageMgr(CStageParam m_cstagefile)
  44. {
  45. InitializeComponent();
  46. m_pStageFile = m_cstagefile;
  47. }
  48. private void DlgStageMgr_Load(object sender, EventArgs e)
  49. {
  50. // 加载样品台文件; \Config\SysData\OTSStage.stg
  51. if (!m_pStageFile.Load( true, false))
  52. {
  53. return;
  54. }
  55. SetStageListControlData();
  56. m_ctrlListBoxStageList.Text = XmlResourceData.GetInstance().GetStringByKey(GrpOtherParam, DlgStageMgr_StageList);
  57. m_ctrlBtnApply.Text = XmlResourceData.GetInstance().GetStringByKey(GrpOtherParam, DlgStageMgr_Apply);
  58. m_ctrlBtnDelete.Text = XmlResourceData.GetInstance().GetStringByKey(GrpOtherParam, DlgStageMgr_Delete);
  59. m_ctrlBtnRename.Text=XmlResourceData.GetInstance().GetStringByKey(GrpOtherParam, DlgStageMgr_Rename);
  60. IDC_BTN_IMPORT.Text= XmlResourceData.GetInstance().GetStringByKey(GrpOtherParam, DlgStageMgr_Import);
  61. m_ctrlBtnExport.Text=XmlResourceData.GetInstance().GetStringByKey(GrpOtherParam, DlgStageMgr_Export);
  62. this.Text=XmlResourceData.GetInstance().GetStringByKey(GrpOtherParam, DlgStageMgr_Title);
  63. }
  64. // CDlgStageMgr message map
  65. public void OnClickedBtnImport(object sender, EventArgs e)
  66. {
  67. loger.Trace("OnClickedBtnImport: import a stage from txt file.");
  68. String strDlgTitle = "";
  69. if (strDlgTitle == "")
  70. {
  71. // file open dialog
  72. OpenFileDialog openFileDialog = new OpenFileDialog();
  73. // get file pathname
  74. openFileDialog.Filter = "txt files(*.txt)|*.txt|All files(*.*)|*.*";
  75. strDlgTitle = openFileDialog.FileName;
  76. DialogResult dresult = openFileDialog.ShowDialog();
  77. if (dresult == DialogResult.OK)
  78. {
  79. String strPathName = openFileDialog.FileName;
  80. if (strPathName == "")
  81. {
  82. loger.Error("OnClickedBtnImport: input an empty path.");
  83. return;
  84. }
  85. CSEMStageData a_pCSEMStageData = new CSEMStageData();
  86. //获取配置文件中 StageData 内容
  87. COTSDefaultParam m_DefaultParam = new COTSDefaultParam();
  88. m_DefaultParam.LoadInfoFromProgMgrFile();
  89. a_pCSEMStageData = m_DefaultParam.GetStageDataParam();
  90. // load a stage from txt file
  91. if (!m_pStageFile.LoadStageFromTextFile(strPathName, a_pCSEMStageData))
  92. {
  93. loger.Error("OnClickedBtnImport: failed to import a stage.");
  94. return;
  95. }
  96. // set modify flag
  97. m_pStageFile.SetModify(true);
  98. // the new stage insert to stage list
  99. SetStageListControlData();
  100. loger.Trace("OnClickedBtnImport: a stage has been import.");
  101. }
  102. }
  103. else
  104. {
  105. loger.Error("OnClickedBtnImport: import action has been cancled.");
  106. return;
  107. }
  108. // show the stage
  109. m_bShowFlag = false;
  110. }
  111. public void OnClickedBtnAply(object sender, EventArgs e)
  112. {
  113. loger.Info("OnClickedBtnAply: the selected stage will be the working stage.");
  114. UpdateStageFileData(true);
  115. //create stage manager file
  116. if (m_pStageFile.IsModified())
  117. {
  118. if (!m_pStageFile.Save())
  119. {
  120. loger.Error("OnClickedBtnAply: save a stage file failed.");
  121. return;
  122. }
  123. }
  124. this.Close(); //CDialog::OnOK();
  125. }
  126. public void OnClickedBtnDel(object sender, EventArgs e)
  127. {
  128. loger.Info("OnClickedBtnDel: the selected stage will be deleted.");
  129. if (DialogResult.Cancel == MessageBox.Show("Are you sure to delete this sample station?", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
  130. {
  131. loger.Info("OnClickedBtnDel: user cancled.");
  132. return;
  133. }
  134. UpdateStageFileData(true);
  135. // remove the stage
  136. if (m_pStageFile.GetStagesList().Count() > 0)
  137. {
  138. m_pStageFile.GetStagesList().RemoveAt(m_nListBoxStageListIndex);
  139. // set new working stage
  140. m_nListBoxStageListIndex = 0;
  141. m_pStageFile.SetWorkingStageId(m_nListBoxStageListIndex);
  142. m_pStageFile.SetModify();
  143. //m_nListBoxStageList--;
  144. Invalidate();
  145. }
  146. SetStageListControlData();
  147. }
  148. public void OnClickedBtnExport(object sender, EventArgs e)
  149. {
  150. loger.Info("OnClickedBtnExport: the selected stage will be export stage into a txt.");
  151. UpdateStageFileData(true);
  152. // export a stage into text file
  153. SaveFileDialog saveFileDialog = new SaveFileDialog();
  154. saveFileDialog.DefaultExt = null;
  155. saveFileDialog.InitialDirectory = null;
  156. saveFileDialog.CheckPathExists = true;
  157. saveFileDialog.Filter = "txt files(*.txt)|*.txt|All files(*.*)|*.*";
  158. DialogResult dr = saveFileDialog.ShowDialog();
  159. if (dr == System.Windows.Forms.DialogResult.OK)
  160. {
  161. string strPathName = saveFileDialog.FileName;
  162. if (string.IsNullOrEmpty(strPathName))
  163. {
  164. loger.Error("OnClickedBtnExport: empty path.");
  165. return;
  166. }
  167. m_pStageFile.SaveStageIntoTextFile(m_nListBoxStageListIndex, strPathName);
  168. }
  169. else
  170. {
  171. loger.Error("OnClickedBtnExport: export action is cancled.");
  172. return;
  173. }
  174. SetStageListControlData();
  175. }
  176. public void OnClickedBtnRename(object sender, EventArgs e)
  177. {
  178. loger.Trace("OnClickedBtnRename: the selected stage will be renamed.");
  179. UpdateStageFileData(true);
  180. CStage pStage = m_pStageFile.GetStagesList()[m_nListBoxStageListIndex];
  181. DlgStageRename dlg = new DlgStageRename();
  182. dlg.m_sEditName = pStage.GetName();
  183. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  184. {
  185. pStage.SetName(dlg.m_sStageName);
  186. m_pStageFile.SetModify();
  187. }
  188. else
  189. {
  190. loger.Error("OnClickedBtnRename: rename action is cancled.");
  191. return;
  192. }
  193. SetStageListControlData();
  194. }
  195. void OnSelchangeListStage(object sender, EventArgs e)
  196. {
  197. m_nListBoxStageListIndex = m_ctrlListBoxStageList.SelectedIndex;
  198. //UpdateStageFileData(true); 为避免关闭界面仍然保存当前选择的样品台,此处注销了
  199. m_ctrlStagePicture.Refresh();
  200. DrawStage();
  201. }
  202. void OnPaint(object sender, PaintEventArgs e)
  203. {
  204. //CPaintDC dc(this); // device context for painting
  205. if (!m_bShowFlag)
  206. {
  207. DrawStage();
  208. }
  209. }
  210. public void SetStageListControlData()
  211. {
  212. if (m_ctrlListBoxStageList.Items.Count > 0)
  213. {
  214. m_ctrlListBoxStageList.Items.Clear();
  215. }
  216. // there is stage in the stage file?
  217. if (m_pStageFile.GetStagesList().Count > 0)
  218. {
  219. // there is sample on the work stage
  220. //if (m_pStageFile.GetInUse() == true)
  221. //{
  222. // // can't change working stage
  223. // m_ctrlBtnApply.Enabled = false;
  224. // // if working stage id == selected id
  225. // if (m_nListBoxStageListIndex == m_pStageFile.GetWorkingStageId())
  226. // {
  227. // // can't delete and rename the woking stage
  228. // m_ctrlBtnDelete.Enabled = false;
  229. // m_ctrlBtnRename.Enabled = false;
  230. // }
  231. // else
  232. // {
  233. // m_ctrlBtnDelete.Enabled = true;
  234. // m_ctrlBtnRename.Enabled = true;
  235. // }
  236. //}
  237. //else
  238. //{
  239. m_ctrlBtnApply.Enabled = true;
  240. m_ctrlBtnDelete.Enabled = true;
  241. m_ctrlBtnRename.Enabled = true;
  242. //}
  243. foreach (var pStage in m_pStageFile.GetStagesList())
  244. {
  245. string sCurrentName = pStage.GetName();
  246. int findIndex = m_ctrlListBoxStageList.FindString(sCurrentName);
  247. if (findIndex < 0)
  248. {
  249. m_ctrlListBoxStageList.Items.Add(sCurrentName);
  250. }
  251. }
  252. //default is the first item
  253. m_ctrlListBoxStageList.SelectedIndex = m_nListBoxStageListIndex;
  254. m_ctrlBtnExport.Enabled = true;
  255. }
  256. else
  257. {
  258. // the control can't be used because there is no stage in the file
  259. m_ctrlBtnApply.Enabled = false;
  260. m_ctrlBtnApply.Enabled = false;
  261. m_ctrlBtnDelete.Enabled = false;
  262. m_ctrlBtnExport.Enabled = false;
  263. m_ctrlBtnRename.Enabled = false;
  264. }
  265. }
  266. public void UpdateStageFileData(bool a_bUpdateData/* = TRUE*/)
  267. {
  268. if (a_bUpdateData)
  269. {
  270. UpdateData(true);
  271. }
  272. // if there is sample on the stage, the working stage can't be changed.
  273. m_pStageFile.SetWorkingStageId(m_nListBoxStageListIndex);
  274. }
  275. public bool UpdateData(bool bSaveAndValidate)
  276. {
  277. return true;
  278. }
  279. public void DrawStage()
  280. {
  281. if (m_nListBoxStageListIndex < 0 || m_nListBoxStageListIndex > (int)(m_pStageFile.GetStagesList().Count))
  282. {
  283. return;
  284. }
  285. Rectangle rc = new Rectangle(m_ctrlStagePicture.Location, m_ctrlStagePicture.Size);
  286. Rectangle re = new Rectangle(m_ctrlStagePicture.Location, m_ctrlStagePicture.Size);
  287. int pWnd = GetDlgItem(otsdataconst.IDC_PIC_STAGE);
  288. int nWidth = (int)rc.Width;
  289. int nHeight = (int)rc.Height;
  290. Object pDC = new Object();
  291. bool DeleteObject = false;
  292. //paint the DC with white
  293. Brush pOldBrush = new SolidBrush(Color.FromArgb(50, Color.White));
  294. //Draw stage
  295. if (m_pStageFile.GetStagesList().Count > 0)
  296. {
  297. m_ctrlStagePicture.Refresh();
  298. //Image img = (Image)new Bitmap(m_ctrlStagePicture.Width, m_ctrlStagePicture.Height);
  299. //Graphics graphics = m_ctrlStagePicture.CreateGraphics();// Graphics.FromImage(img);
  300. //graphics.FillRectangle(new SolidBrush(Color.Beige), re);
  301. pDC = m_ctrlStagePicture.CreateGraphics();
  302. //消除锯齿
  303. ((Graphics)pDC).SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  304. ((Graphics)pDC).InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  305. ((Graphics)pDC).CompositingQuality = CompositingQuality.HighQuality;//再加一点
  306. //get stage information
  307. List<CStage> pStage = m_pStageFile.GetStagesList();//get curretn working stage
  308. CDomain pBoundery = pStage[m_nListBoxStageListIndex].GetBoundary();// GetBoundary();
  309. System.Drawing.Rectangle BounderyRect = pBoundery.GetDomainRect();
  310. int nBounderyWidth = (int)(BounderyRect.Width);//um,,pixle is (nWidth - PIC_EDGE * 2 )
  311. int nBounderyHeight = (int)(BounderyRect.Height);
  312. double PixSize = 0;
  313. if (nBounderyWidth > nBounderyHeight)
  314. {
  315. PixSize = (long)((double)nBounderyWidth / (double)(nWidth - PIC_EDGE * 2));
  316. }
  317. else
  318. {
  319. PixSize = (long)((double)nBounderyHeight / (double)(nHeight - PIC_EDGE * 2));
  320. }
  321. //draw boundery
  322. Brush pLTGrayBrush = new SolidBrush(Color.FromArgb(255, 0, 0));
  323. DrawStageBoundery(pStage[m_nListBoxStageListIndex], nWidth, nHeight, pDC, PixSize);
  324. ////draw STD
  325. //Brush pBlackBrush = new SolidBrush(Color.FromArgb(255, 0, 0)); ;
  326. //DrawStageSTD(pStage[m_nListBoxStageListIndex], nWidth, nHeight, pDC, PixSize);
  327. ////draw holes
  328. //Brush pWriteBrush = new SolidBrush(Color.FromArgb(255, 0, 0)); ;
  329. DrawStageHole(pStage[m_nListBoxStageListIndex], nWidth, nHeight, pDC, PixSize);
  330. // draw ratio
  331. DrawRatio(nBounderyWidth, nWidth, nHeight, pDC, (IntPtr)pWnd, rc);
  332. pLTGrayBrush.Dispose();
  333. //pBlackBrush.Dispose();
  334. //pWriteBrush.Dispose();
  335. //graphics.Dispose();
  336. //((Graphics)pDC).Dispose();
  337. }
  338. else
  339. {
  340. // paint the stage
  341. m_bShowFlag = true;
  342. }
  343. pOldBrush.Dispose();
  344. }
  345. public int GetDlgItem(int nID)
  346. {
  347. return nID;
  348. }
  349. //// stage file get and set
  350. //public CStageParam GetStageFile()
  351. //{
  352. // return m_pStageFile;
  353. //}
  354. //public void SetStageFile(CStageParam a_pStageFile)
  355. //{
  356. // m_pStageFile = a_pStageFile;
  357. //}
  358. //// soft pack id get and set
  359. //public otsdataconst.OTS_SysType_ID GetPackId() { return m_nPackId; }
  360. //public void SetPackId(otsdataconst.OTS_SysType_ID a_nPackId) { m_nPackId = a_nPackId; }
  361. // draw shape
  362. public void DrawShape(Rectangle a_PixRect, Object a_pDC, otsdataconst.DOMAIN_SHAPE a_nShape, bool a_bIsRand)
  363. {
  364. if (a_pDC == null)
  365. {
  366. return;
  367. }
  368. Graphics graphicsShape = (Graphics)a_pDC;
  369. switch ((int)a_nShape)
  370. {
  371. case (int)otsdataconst.DOMAIN_SHAPE.ROUND:
  372. graphicsShape.DrawEllipse(new Pen(Color.Black),a_PixRect);
  373. break;
  374. case (int)otsdataconst.DOMAIN_SHAPE.RECTANGLE:
  375. if (a_bIsRand)
  376. {
  377. //graphicsShape.DrawRectangle(new Pen(Color.Black), a_PixRect, new Point(ROUND_VALUE, ROUND_VALUE));
  378. graphicsShape.DrawRectangle(new Pen(Color.Black), a_PixRect);
  379. }
  380. else
  381. {
  382. graphicsShape.DrawEllipse(new Pen(Color.Black), a_PixRect);
  383. }
  384. break;
  385. }
  386. }
  387. // get pixle rect
  388. public bool GetPixRect(CDomain a_pDomain, int a_nWidth, int a_nHeight, double a_dPixSize,ref Rectangle PixRect)
  389. {
  390. if (a_pDomain == null)
  391. {
  392. return false;
  393. }
  394. Rectangle DomainRect = a_pDomain.GetDomainRect();
  395. int CenterX = a_nWidth / 2; //pixle center
  396. int CenterY = a_nHeight / 2;
  397. Point DomainCenter = a_pDomain.GetDomainCenter(); // um center
  398. Point PixCenter = new Point();
  399. PixCenter.X = (int)((double)DomainCenter.X / a_dPixSize);
  400. PixCenter.Y = (int)((double)DomainCenter.Y / a_dPixSize); // um to pixle
  401. int PixRectCenterX = CenterX + PixCenter.X;
  402. int PixRectCenterY = CenterY - PixCenter.Y;//OTS y dirction is different with pixle direction
  403. int delteX = PixRectCenterX - PixCenter.X;
  404. int delteY = PixRectCenterY - PixCenter.Y;
  405. int Left = (int)(DomainRect.Left / a_dPixSize + delteX);
  406. int Top = (int)(DomainRect.Top / a_dPixSize + delteY);
  407. int Right = (int)(DomainRect.Right / a_dPixSize + delteX);
  408. int Bottom = (int)(DomainRect.Bottom / a_dPixSize + delteY);
  409. PixRect.Location = new Point(Left, Top);
  410. PixRect.Size = new Size(Math.Abs(Right - Left), Math.Abs(Bottom - Top));
  411. return true;
  412. }
  413. // draw stage boundery
  414. public void DrawStageBoundery(CStage a_pStage, int a_nWidth, int a_nHeight, Object pDC, double a_dPixSize)
  415. {
  416. if (a_pStage == null)
  417. {
  418. return;
  419. }
  420. CDomain pBoundery = a_pStage.GetBoundary();
  421. otsdataconst.DOMAIN_SHAPE nShape = (otsdataconst.DOMAIN_SHAPE)(-1);
  422. nShape = pBoundery.GetShape();
  423. Rectangle PixRect = new Rectangle();
  424. GetPixRect(pBoundery, a_nWidth, a_nHeight, a_dPixSize,ref PixRect);
  425. DrawShape(PixRect, pDC, nShape, true);
  426. }
  427. public void DrawStageSTD(CStage a_pStage, int a_nWidth, int a_nHeight, Object pDC, double a_dPixSize)
  428. {
  429. if (a_pStage == null)
  430. {
  431. return;
  432. }
  433. CDomain pSTD = a_pStage.GetSTD();
  434. otsdataconst.DOMAIN_SHAPE nShape = (otsdataconst.DOMAIN_SHAPE)(-1);
  435. nShape = pSTD.GetShape();
  436. Rectangle PixRect = new Rectangle();
  437. GetPixRect(pSTD, a_nWidth, a_nHeight, a_dPixSize,ref PixRect);
  438. DrawShape(PixRect, pDC, nShape, false);
  439. }
  440. // draw stage hole
  441. public void DrawStageHole(CStage a_pStage, int a_nWidth, int a_nHeight, Object pDC, double a_dPixSize)
  442. {
  443. if (a_pStage == null)
  444. {
  445. return;
  446. }
  447. if (a_pStage.GetHoleList().Count == 0)
  448. {
  449. return;
  450. }
  451. foreach (var pHole in a_pStage.GetHoleList())
  452. {
  453. otsdataconst.DOMAIN_SHAPE nShape = (otsdataconst.DOMAIN_SHAPE)(-1);
  454. nShape = pHole.GetShape();
  455. Rectangle PixRect = new Rectangle();
  456. GetPixRect(pHole, a_nWidth, a_nHeight, a_dPixSize,ref PixRect);
  457. DrawShape(PixRect, pDC, nShape, false);
  458. int nHeight = PixRect.Height * 2 / 3;
  459. //设置文字对齐方式
  460. StringFormat sf = new StringFormat();
  461. sf.Alignment = StringAlignment.Center;
  462. sf.LineAlignment = StringAlignment.Center;
  463. //文字颜色
  464. string ColorStr = "#90ee90";
  465. Color myColor = ColorTranslator.FromHtml(ColorStr);
  466. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  467. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(50, Color.Black));
  468. //字体大小 根据样品孔Rectangle大小
  469. float fontSize = PixRect.Width / 4;
  470. Font font = new Font("宋体", fontSize, FontStyle.Regular);
  471. if (fontSize == 0)
  472. {
  473. font = new Font("宋体", fontSize, FontStyle.Regular);
  474. }
  475. //绘制文字阴影
  476. Rectangle rectFont = PixRect;
  477. rectFont.X += 2;
  478. rectFont.Y += 2;
  479. ((Graphics)pDC).DrawString(pHole.GetName(), font, solidBrush, rectFont, sf);
  480. ((Graphics)pDC).DrawString(pHole.GetName(), font, sampleBrush, PixRect, sf);
  481. }
  482. }
  483. // draw ratio
  484. public void DrawRatio(int a_nBounderyWidth, int a_nWidth, int a_nHeight, Object pDC, IntPtr pWnd, Rectangle rc)
  485. {
  486. if (pDC == null)
  487. {
  488. return;
  489. }
  490. if (pWnd == null)
  491. {
  492. return;
  493. }
  494. int nRatio = a_nBounderyWidth * (a_nWidth / 2 - RATIO_RECT_LEFT - 10) / (a_nWidth - PIC_EDGE * 2) / 1000; //显示在标尺上的mm数
  495. string sRatio;
  496. Point oRatioStart = new Point();
  497. oRatioStart.X = RATIO_RECT_LEFT;
  498. oRatioStart.Y = a_nHeight - RATIO_RECT_HEIGHT - RATIO_RECT_DOWN;
  499. Point oRatioEnd = new Point();
  500. oRatioEnd.X = a_nWidth / 2;
  501. oRatioEnd.Y = a_nHeight - RATIO_RECT_DOWN;
  502. //标尺
  503. //Pen pen = new Pen(Color.Black, 10f);
  504. //((Graphics)pDC).DrawLine(pen,new Point(oRatioStart.X + 5, oRatioStart.Y + 5),new Point(oRatioStart.X + 5, oRatioEnd.Y - 15));
  505. //((Graphics)pDC).DrawLine(pen, new Point(oRatioStart.X + 5, oRatioStart.Y + 10),new Point(oRatioEnd.X - 5, oRatioStart.Y + 10));
  506. //((Graphics)pDC).DrawLine(pen, new Point(oRatioEnd.X - 5, oRatioStart.Y + 5),new Point(oRatioEnd.X - 5, oRatioEnd.Y - 15));
  507. //pDC->MoveTo(CPoint(oRatioStart.x + 5, oRatioStart.y + 5));
  508. //pDC->LineTo(CPoint(oRatioStart.x + 5, oRatioEnd.y - 15));
  509. //pDC->MoveTo(CPoint(oRatioStart.x + 5, oRatioStart.y + 10));
  510. //pDC->LineTo(CPoint(oRatioEnd.x - 5, oRatioStart.y + 10));
  511. //pDC->MoveTo(CPoint(oRatioEnd.x - 5, oRatioStart.y + 5));
  512. //pDC->LineTo(CPoint(oRatioEnd.x - 5, oRatioEnd.y - 15));
  513. //CFont font;
  514. //VERIFY(font.CreateFont(
  515. // 12, // nHeight
  516. // 0, // nWidth
  517. // 0, // nEscapement
  518. // 0, // nOrientation
  519. // FW_THIN, // nWeight
  520. // FALSE, // bItalic
  521. // FALSE, // bUnderline
  522. // 0, // cStrikeOut
  523. // ANSI_CHARSET, // nCharSet
  524. // OUT_DEFAULT_PRECIS, // nOutPrecision
  525. // CLIP_DEFAULT_PRECIS, // nClipPrecision
  526. // DEFAULT_QUALITY, // nQuality
  527. // DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
  528. // _T("Arial"))); // lpszFacename
  529. //CFont* def_font = pDC->SelectObject(&font);
  530. //pDC->TextOut(oRatioStart.x + 70, oRatioStart.y + 15, sRatio);
  531. //pDC->SelectObject(def_font);
  532. //// Done with the font. Delete the font object.
  533. //font.DeleteObject();
  534. //CRect oRect(oRatioStart, oRatioEnd);
  535. //HDC hDC;
  536. //hDC = ::GetDC(pWnd->m_hWnd);
  537. //HDC hBitmapDC = CreateCompatibleDC(hDC);
  538. //HBITMAP hBitmap = CreateCompatibleBitmap(hDC, rc.Width(), rc.Height());
  539. //SelectObject(hBitmapDC, hBitmap);
  540. //BLENDFUNCTION bf;
  541. //bf.BlendOp = AC_SRC_OVER;
  542. //bf.BlendFlags = 0;
  543. //bf.AlphaFormat = 0;
  544. //bf.SourceConstantAlpha = 10;
  545. //AlphaBlend(hDC, oRect.left, oRect.top, oRect.Width(), oRect.Height(), hBitmapDC, 0, 0, oRect.Width(), oRect.Height(), bf);
  546. }
  547. //public Brush GetStockObject(int i) {
  548. // BrushConverter brushConverter = new BrushConverter(Color.Brown);
  549. // return (Brush)brushConverter.ConvertFromString(LTGRAY_BRUSH.ToString());
  550. //}
  551. public Brush GetStockObject(int i)
  552. {
  553. return null;
  554. }
  555. // boundary
  556. public CDomain GetBoundary()
  557. {
  558. return m_poBourary;
  559. }
  560. public Brush SelectObject(Brush pBrush)
  561. {
  562. return pBrush;
  563. }
  564. public void DrawRatio(int a_nBounderyWidth, int a_nWidth, int a_nHeight, int pDC, int pWnd, Rectangle rc)
  565. {
  566. if (pDC == 0)
  567. {
  568. return;
  569. }
  570. if (pWnd == 0)
  571. {
  572. return;
  573. }
  574. int nRatio = a_nBounderyWidth * (a_nWidth / 2 - RATIO_RECT_LEFT - 10) / (a_nWidth - PIC_EDGE * 2) / 1000; //显示在标尺上的mm数
  575. String.Format("%dcm", nRatio);
  576. System.Drawing.Point oRatioStart = new System.Drawing.Point();
  577. oRatioStart.X = RATIO_RECT_LEFT;
  578. oRatioStart.Y = a_nHeight - RATIO_RECT_HEIGHT - RATIO_RECT_DOWN;
  579. System.Drawing.Point oRatioEnd = new System.Drawing.Point();
  580. oRatioEnd.X = a_nWidth / 2;
  581. oRatioEnd.Y = a_nHeight - RATIO_RECT_DOWN;
  582. Control control = new Control();
  583. //标尺
  584. FontDialog fontdialog = new FontDialog();
  585. fontdialog.ShowDialog();
  586. control.Font = fontdialog.Font;
  587. control.Font = new System.Drawing.Font("华文新魏", 22.2f, FontStyle.Bold);
  588. System.Drawing.Font def_font = new System.Drawing.Font(control.Font, FontStyle.Regular);
  589. BLENDFUNCTION bf = new BLENDFUNCTION();
  590. bf.BlendOp = 1;
  591. bf.BlendFlags = 0;
  592. bf.AlphaFormat = 0;
  593. bf.SourceConstantAlpha = 10;
  594. }
  595. //public CStageParam ShowStageMgrDialog(otsdataconst.OTS_SysType_ID a_nPackId, CStageParam a_pStageFile)
  596. //{
  597. // if (a_pStageFile == null)
  598. // {
  599. // //LogErrorTrace(__FILE__, __LINE__, _T("ShowStageMgrDialog:invalid stage file."));
  600. // loger.Error("ShowStageMgrDialog:invalid stage file.");
  601. // return null;
  602. // }
  603. // //show the dialog
  604. // DlgStageMgr dlg = new DlgStageMgr(a_pStageFile);
  605. // dlg.SetStageFile(a_pStageFile);
  606. // dlg.SetPackId(a_nPackId);
  607. // dlg.ShowDialog();
  608. // CStageParam pStageFile = dlg.GetStageFile();
  609. // //ASSERT(pStageFile);
  610. // if (pStageFile == null)
  611. // {
  612. // //LogErrorTrace(__FILE__, __LINE__, _T("ShowStageMgrDialog: Load stage from stage manager dlg failed."));
  613. // loger.Error("ShowStageMgrDialog: Load stage from stage manager dlg failed.");
  614. // return null;
  615. // }
  616. // return pStageFile;
  617. //}
  618. }
  619. }