SaveViewDialog.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. using PaintDotNet.Annotation.Enum;
  2. using PaintDotNet.Base.CommTool;
  3. using PaintDotNet.DbOpreate.DbBll;
  4. using PaintDotNet.DbOpreate.DbModel;
  5. using PaintDotNet.Base.SettingModel.LVMModel;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Drawing;
  9. using System.Drawing.Imaging;
  10. using System.Windows.Forms;
  11. namespace PaintDotNet.FieldView
  12. {
  13. /// <summary>
  14. /// 保存视场
  15. /// </summary>
  16. internal class SaveViewDialog : Form
  17. {
  18. #region 控件
  19. private RichTextBox richTextBox1;
  20. private Button button1;
  21. private Label label1;
  22. private Label label2;
  23. private PictureBox panel1;
  24. private GroupBox groupBox1;
  25. private GroupBox groupBox2;
  26. private Panel panel2;
  27. private TextBox textBox1;
  28. private Panel panel3;
  29. #endregion
  30. private AppWorkspace appWorkspace;
  31. private Region region;
  32. private Bitmap bitmap;
  33. private RectangleF rectangleF;
  34. public SaveViewDialog(AppWorkspace appWorkspace, Region region, Bitmap bitmap)
  35. {
  36. this.appWorkspace = appWorkspace;
  37. InitializeComponent();
  38. InitializeLanguageText();
  39. InitializeHint();
  40. //视场预览
  41. this.region = region;
  42. this.bitmap = bitmap;
  43. this.panel1.Image = panel1_Paint();
  44. }
  45. /// <summary>
  46. /// 绘制视场到图片
  47. /// </summary>
  48. /// <returns></returns>
  49. private Bitmap panel1_Paint()
  50. {
  51. Graphics graphic = Graphics.FromImage(bitmap);
  52. rectangleF = region.GetBounds(graphic);
  53. int width = (int)rectangleF.Width;
  54. int height = (int)rectangleF.Height;
  55. Rectangle rect = new Rectangle(0, 0, width, height);
  56. Bitmap dstBitmap = new Bitmap(width, height);
  57. BitmapData dstBmData = dstBitmap.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
  58. IntPtr dstScan = dstBmData.Scan0;
  59. unsafe
  60. {
  61. byte* dstP = (byte*)(void*)dstScan;
  62. int dstOffset = dstBmData.Stride - width * 4;
  63. for (int y = 0; y < height; y++)
  64. {
  65. for (int x = 0; x < width; x++, dstP += 4)
  66. {
  67. if (region.IsVisible(new Point(x + (int)(rectangleF.X), y + (int)(rectangleF.Y))))
  68. {
  69. dstP[0] = 255;
  70. dstP[1] = 255;
  71. dstP[2] = 255;
  72. dstP[3] = 255;
  73. }
  74. else
  75. {
  76. dstP[0] = 0;
  77. dstP[1] = 0;
  78. dstP[2] = 0;
  79. dstP[3] = 255;
  80. }
  81. }
  82. dstP += dstOffset;
  83. }
  84. }
  85. dstBitmap.UnlockBits(dstBmData);
  86. return dstBitmap;
  87. }
  88. private void InitializeLanguageText()
  89. {
  90. this.button1.Text = PdnResources.GetString("Menu.File.Save.Text");
  91. this.label1.Text = PdnResources.GetString("Menu.viewname.text") + ":";
  92. this.label2.Text = PdnResources.GetString("Menu.viewsetting.Saveview.viewdescription.text") + ":";
  93. this.groupBox1.Text = PdnResources.GetString("Menu.viewsetting.Saveview.viewpreview.text");
  94. this.groupBox2.Text = PdnResources.GetString("Menu.viewsetting.Saveview.viewinformation.text");
  95. this.Text = PdnResources.GetString("Menu.ViewSetting.SaveFieldOfView.Text");
  96. }
  97. private void InitializeComponent()
  98. {
  99. this.textBox1 = new System.Windows.Forms.TextBox();
  100. this.richTextBox1 = new System.Windows.Forms.RichTextBox();
  101. this.button1 = new System.Windows.Forms.Button();
  102. this.label1 = new System.Windows.Forms.Label();
  103. this.label2 = new System.Windows.Forms.Label();
  104. this.panel1 = new System.Windows.Forms.PictureBox();
  105. this.groupBox1 = new System.Windows.Forms.GroupBox();
  106. this.panel3 = new System.Windows.Forms.Panel();
  107. this.groupBox2 = new System.Windows.Forms.GroupBox();
  108. this.panel2 = new System.Windows.Forms.Panel();
  109. ((System.ComponentModel.ISupportInitialize)(this.panel1)).BeginInit();
  110. this.groupBox1.SuspendLayout();
  111. this.panel3.SuspendLayout();
  112. this.groupBox2.SuspendLayout();
  113. this.SuspendLayout();
  114. //
  115. // textBox1
  116. //
  117. this.textBox1.Location = new System.Drawing.Point(8, 38);
  118. this.textBox1.MaxLength = 10;
  119. this.textBox1.Name = "textBox1";
  120. this.textBox1.Size = new System.Drawing.Size(177, 21);
  121. this.textBox1.TabIndex = 0;
  122. //
  123. // richTextBox1
  124. //
  125. this.richTextBox1.Location = new System.Drawing.Point(8, 88);
  126. this.richTextBox1.MaxLength = 30;
  127. this.richTextBox1.Name = "richTextBox1";
  128. this.richTextBox1.Size = new System.Drawing.Size(177, 105);
  129. this.richTextBox1.TabIndex = 1;
  130. this.richTextBox1.Text = "";
  131. //
  132. // button1
  133. //
  134. this.button1.Location = new System.Drawing.Point(339, 231);
  135. this.button1.Name = "button1";
  136. this.button1.Size = new System.Drawing.Size(75, 23);
  137. this.button1.TabIndex = 2;
  138. this.button1.Text = "保存";
  139. this.button1.UseVisualStyleBackColor = true;
  140. this.button1.Click += new System.EventHandler(this.button1_Click);
  141. //
  142. // label1
  143. //
  144. this.label1.AutoSize = true;
  145. this.label1.Location = new System.Drawing.Point(6, 19);
  146. this.label1.Name = "label1";
  147. this.label1.Size = new System.Drawing.Size(65, 12);
  148. this.label1.TabIndex = 3;
  149. this.label1.Text = "视场名称:";
  150. //
  151. // label2
  152. //
  153. this.label2.AutoSize = true;
  154. this.label2.Location = new System.Drawing.Point(6, 67);
  155. this.label2.Name = "label2";
  156. this.label2.Size = new System.Drawing.Size(65, 12);
  157. this.label2.TabIndex = 4;
  158. this.label2.Text = "视场描述:";
  159. //
  160. // panel1
  161. //
  162. this.panel1.BackColor = System.Drawing.Color.Black;
  163. this.panel1.Location = new System.Drawing.Point(3, 3);
  164. this.panel1.Name = "panel1";
  165. this.panel1.Size = new System.Drawing.Size(187, 173);
  166. this.panel1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
  167. this.panel1.TabIndex = 5;
  168. this.panel1.TabStop = false;
  169. //
  170. // groupBox1
  171. //
  172. this.groupBox1.Controls.Add(this.panel3);
  173. this.groupBox1.Location = new System.Drawing.Point(209, 12);
  174. this.groupBox1.Name = "groupBox1";
  175. this.groupBox1.Size = new System.Drawing.Size(205, 205);
  176. this.groupBox1.TabIndex = 6;
  177. this.groupBox1.TabStop = false;
  178. this.groupBox1.Text = "视场预览";
  179. //
  180. // panel3
  181. //
  182. this.panel3.BackColor = System.Drawing.Color.Black;
  183. this.panel3.Controls.Add(this.panel1);
  184. this.panel3.Location = new System.Drawing.Point(6, 20);
  185. this.panel3.Name = "panel3";
  186. this.panel3.Size = new System.Drawing.Size(193, 179);
  187. this.panel3.TabIndex = 5;
  188. //
  189. // groupBox2
  190. //
  191. this.groupBox2.Controls.Add(this.label2);
  192. this.groupBox2.Controls.Add(this.textBox1);
  193. this.groupBox2.Controls.Add(this.richTextBox1);
  194. this.groupBox2.Controls.Add(this.label1);
  195. this.groupBox2.Location = new System.Drawing.Point(12, 12);
  196. this.groupBox2.Name = "groupBox2";
  197. this.groupBox2.Size = new System.Drawing.Size(191, 205);
  198. this.groupBox2.TabIndex = 7;
  199. this.groupBox2.TabStop = false;
  200. this.groupBox2.Text = "视场信息";
  201. //
  202. // panel2
  203. //
  204. this.panel2.BackColor = System.Drawing.Color.Gainsboro;
  205. this.panel2.Location = new System.Drawing.Point(13, 224);
  206. this.panel2.Name = "panel2";
  207. this.panel2.Size = new System.Drawing.Size(401, 1);
  208. this.panel2.TabIndex = 8;
  209. //
  210. // SaveViewDialog
  211. //
  212. this.ClientSize = new System.Drawing.Size(426, 266);
  213. this.Controls.Add(this.panel2);
  214. this.Controls.Add(this.groupBox2);
  215. this.Controls.Add(this.groupBox1);
  216. this.Controls.Add(this.button1);
  217. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  218. this.Name = "SaveViewDialog";
  219. this.Text = "保存视场";
  220. ((System.ComponentModel.ISupportInitialize)(this.panel1)).EndInit();
  221. this.groupBox1.ResumeLayout(false);
  222. this.panel3.ResumeLayout(false);
  223. this.groupBox2.ResumeLayout(false);
  224. this.groupBox2.PerformLayout();
  225. this.ResumeLayout(false);
  226. }
  227. /// <summary>
  228. /// 设置提示文字
  229. /// </summary>
  230. private void InitializeHint()
  231. {
  232. SystemLayer.SafeNativeMethods.SetCueText(this.textBox1, PdnResources.GetString("Menu.Pleaseenterthenameofview.text"));
  233. SystemLayer.SafeNativeMethods.SetCueText(this.richTextBox1, PdnResources.GetString("Menu.Pleasenterthefieldfviewremarks.Text"));
  234. }
  235. /// <summary>
  236. /// 保存视场
  237. /// </summary>
  238. /// <param name="sender"></param>
  239. /// <param name="e"></param>
  240. private void button1_Click(object sender, EventArgs e)
  241. {
  242. if (string.IsNullOrWhiteSpace(this.textBox1.Text))
  243. {
  244. MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterthenameofview.text"));
  245. return;
  246. }
  247. else
  248. {
  249. //判断视场名称是否重复
  250. List<mic_view_infos> list = mic_view_infos_BLL.FindDefaultByName(this.textBox1.Text);
  251. if (list.Count>0)
  252. {
  253. MessageBox.Show(PdnResources.GetString("Menu.viewnamerepeated,pleaserename.text"));
  254. return;
  255. }
  256. ViewListModel viewListModel = new ViewListModel();
  257. viewListModel.RectangleFX = (int)rectangleF.X;
  258. viewListModel.RectangleFY = (int)rectangleF.Y;
  259. viewListModel.RectangleFW = (int)rectangleF.Width;
  260. viewListModel.RectangleFH = (int)rectangleF.Height;
  261. viewListModel.Views = this.appWorkspace.ActiveDocumentWorkspace.GetXmlFromViewOrLabelOrMeasure(DrawClass.View);
  262. mic_view_infos info = new mic_view_infos();
  263. info.view_name = this.textBox1.Text;
  264. info.view_descrption = this.richTextBox1.Text;
  265. info.view_xml = XmlSerializeHelper.XmlSerialize<ViewListModel>(viewListModel);
  266. mic_view_infos_BLL.Add(info);
  267. this.Close();
  268. }
  269. }
  270. }
  271. }