123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- using PaintDotNet.Annotation.Enum;
- using PaintDotNet.Base.CommTool;
- using PaintDotNet.DbOpreate.DbBll;
- using PaintDotNet.DbOpreate.DbModel;
- using PaintDotNet.Base.SettingModel.LVMModel;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Windows.Forms;
- namespace PaintDotNet.FieldView
- {
- /// <summary>
- /// 保存视场
- /// </summary>
- internal class SaveViewDialog : Form
- {
- #region 控件
- private RichTextBox richTextBox1;
- private Button button1;
- private Label label1;
- private Label label2;
- private PictureBox panel1;
- private GroupBox groupBox1;
- private GroupBox groupBox2;
- private Panel panel2;
- private TextBox textBox1;
- private Panel panel3;
- #endregion
- private AppWorkspace appWorkspace;
- private Region region;
- private Bitmap bitmap;
- private RectangleF rectangleF;
- public SaveViewDialog(AppWorkspace appWorkspace, Region region, Bitmap bitmap)
- {
- this.appWorkspace = appWorkspace;
- InitializeComponent();
- InitializeLanguageText();
- InitializeHint();
- //视场预览
- this.region = region;
- this.bitmap = bitmap;
- this.panel1.Image = panel1_Paint();
- }
- /// <summary>
- /// 绘制视场到图片
- /// </summary>
- /// <returns></returns>
- private Bitmap panel1_Paint()
- {
- Graphics graphic = Graphics.FromImage(bitmap);
- rectangleF = region.GetBounds(graphic);
-
- int width = (int)rectangleF.Width;
- int height = (int)rectangleF.Height;
- Rectangle rect = new Rectangle(0, 0, width, height);
- Bitmap dstBitmap = new Bitmap(width, height);
- BitmapData dstBmData = dstBitmap.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
- IntPtr dstScan = dstBmData.Scan0;
- unsafe
- {
- byte* dstP = (byte*)(void*)dstScan;
- int dstOffset = dstBmData.Stride - width * 4;
- for (int y = 0; y < height; y++)
- {
- for (int x = 0; x < width; x++, dstP += 4)
- {
- if (region.IsVisible(new Point(x + (int)(rectangleF.X), y + (int)(rectangleF.Y))))
- {
- dstP[0] = 255;
- dstP[1] = 255;
- dstP[2] = 255;
- dstP[3] = 255;
- }
- else
- {
- dstP[0] = 0;
- dstP[1] = 0;
- dstP[2] = 0;
- dstP[3] = 255;
- }
- }
- dstP += dstOffset;
- }
- }
- dstBitmap.UnlockBits(dstBmData);
- return dstBitmap;
- }
- private void InitializeLanguageText()
- {
- this.button1.Text = PdnResources.GetString("Menu.File.Save.Text");
- this.label1.Text = PdnResources.GetString("Menu.viewname.text") + ":";
- this.label2.Text = PdnResources.GetString("Menu.viewsetting.Saveview.viewdescription.text") + ":";
- this.groupBox1.Text = PdnResources.GetString("Menu.viewsetting.Saveview.viewpreview.text");
- this.groupBox2.Text = PdnResources.GetString("Menu.viewsetting.Saveview.viewinformation.text");
- this.Text = PdnResources.GetString("Menu.ViewSetting.SaveFieldOfView.Text");
- }
- private void InitializeComponent()
- {
- this.textBox1 = new System.Windows.Forms.TextBox();
- this.richTextBox1 = new System.Windows.Forms.RichTextBox();
- this.button1 = new System.Windows.Forms.Button();
- this.label1 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.panel1 = new System.Windows.Forms.PictureBox();
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.panel3 = new System.Windows.Forms.Panel();
- this.groupBox2 = new System.Windows.Forms.GroupBox();
- this.panel2 = new System.Windows.Forms.Panel();
- ((System.ComponentModel.ISupportInitialize)(this.panel1)).BeginInit();
- this.groupBox1.SuspendLayout();
- this.panel3.SuspendLayout();
- this.groupBox2.SuspendLayout();
- this.SuspendLayout();
- //
- // textBox1
- //
- this.textBox1.Location = new System.Drawing.Point(8, 38);
- this.textBox1.MaxLength = 10;
- this.textBox1.Name = "textBox1";
- this.textBox1.Size = new System.Drawing.Size(177, 21);
- this.textBox1.TabIndex = 0;
- //
- // richTextBox1
- //
- this.richTextBox1.Location = new System.Drawing.Point(8, 88);
- this.richTextBox1.MaxLength = 30;
- this.richTextBox1.Name = "richTextBox1";
- this.richTextBox1.Size = new System.Drawing.Size(177, 105);
- this.richTextBox1.TabIndex = 1;
- this.richTextBox1.Text = "";
- //
- // button1
- //
- this.button1.Location = new System.Drawing.Point(339, 231);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(75, 23);
- this.button1.TabIndex = 2;
- this.button1.Text = "保存";
- this.button1.UseVisualStyleBackColor = true;
- this.button1.Click += new System.EventHandler(this.button1_Click);
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.Location = new System.Drawing.Point(6, 19);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(65, 12);
- this.label1.TabIndex = 3;
- this.label1.Text = "视场名称:";
- //
- // label2
- //
- this.label2.AutoSize = true;
- this.label2.Location = new System.Drawing.Point(6, 67);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(65, 12);
- this.label2.TabIndex = 4;
- this.label2.Text = "视场描述:";
- //
- // panel1
- //
- this.panel1.BackColor = System.Drawing.Color.Black;
- this.panel1.Location = new System.Drawing.Point(3, 3);
- this.panel1.Name = "panel1";
- this.panel1.Size = new System.Drawing.Size(187, 173);
- this.panel1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
- this.panel1.TabIndex = 5;
- this.panel1.TabStop = false;
- //
- // groupBox1
- //
- this.groupBox1.Controls.Add(this.panel3);
- this.groupBox1.Location = new System.Drawing.Point(209, 12);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(205, 205);
- this.groupBox1.TabIndex = 6;
- this.groupBox1.TabStop = false;
- this.groupBox1.Text = "视场预览";
- //
- // panel3
- //
- this.panel3.BackColor = System.Drawing.Color.Black;
- this.panel3.Controls.Add(this.panel1);
- this.panel3.Location = new System.Drawing.Point(6, 20);
- this.panel3.Name = "panel3";
- this.panel3.Size = new System.Drawing.Size(193, 179);
- this.panel3.TabIndex = 5;
- //
- // groupBox2
- //
- this.groupBox2.Controls.Add(this.label2);
- this.groupBox2.Controls.Add(this.textBox1);
- this.groupBox2.Controls.Add(this.richTextBox1);
- this.groupBox2.Controls.Add(this.label1);
- this.groupBox2.Location = new System.Drawing.Point(12, 12);
- this.groupBox2.Name = "groupBox2";
- this.groupBox2.Size = new System.Drawing.Size(191, 205);
- this.groupBox2.TabIndex = 7;
- this.groupBox2.TabStop = false;
- this.groupBox2.Text = "视场信息";
- //
- // panel2
- //
- this.panel2.BackColor = System.Drawing.Color.Gainsboro;
- this.panel2.Location = new System.Drawing.Point(13, 224);
- this.panel2.Name = "panel2";
- this.panel2.Size = new System.Drawing.Size(401, 1);
- this.panel2.TabIndex = 8;
- //
- // SaveViewDialog
- //
- this.ClientSize = new System.Drawing.Size(426, 266);
- this.Controls.Add(this.panel2);
- this.Controls.Add(this.groupBox2);
- this.Controls.Add(this.groupBox1);
- this.Controls.Add(this.button1);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
- this.Name = "SaveViewDialog";
- this.Text = "保存视场";
- ((System.ComponentModel.ISupportInitialize)(this.panel1)).EndInit();
- this.groupBox1.ResumeLayout(false);
- this.panel3.ResumeLayout(false);
- this.groupBox2.ResumeLayout(false);
- this.groupBox2.PerformLayout();
- this.ResumeLayout(false);
- }
- /// <summary>
- /// 设置提示文字
- /// </summary>
- private void InitializeHint()
- {
- SystemLayer.SafeNativeMethods.SetCueText(this.textBox1, PdnResources.GetString("Menu.Pleaseenterthenameofview.text"));
- SystemLayer.SafeNativeMethods.SetCueText(this.richTextBox1, PdnResources.GetString("Menu.Pleasenterthefieldfviewremarks.Text"));
- }
- /// <summary>
- /// 保存视场
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button1_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrWhiteSpace(this.textBox1.Text))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterthenameofview.text"));
- return;
- }
- else
- {
- //判断视场名称是否重复
- List<mic_view_infos> list = mic_view_infos_BLL.FindDefaultByName(this.textBox1.Text);
- if (list.Count>0)
- {
- MessageBox.Show(PdnResources.GetString("Menu.viewnamerepeated,pleaserename.text"));
- return;
- }
- ViewListModel viewListModel = new ViewListModel();
- viewListModel.RectangleFX = (int)rectangleF.X;
- viewListModel.RectangleFY = (int)rectangleF.Y;
- viewListModel.RectangleFW = (int)rectangleF.Width;
- viewListModel.RectangleFH = (int)rectangleF.Height;
- viewListModel.Views = this.appWorkspace.ActiveDocumentWorkspace.GetXmlFromViewOrLabelOrMeasure(DrawClass.View);
-
- mic_view_infos info = new mic_view_infos();
- info.view_name = this.textBox1.Text;
- info.view_descrption = this.richTextBox1.Text;
- info.view_xml = XmlSerializeHelper.XmlSerialize<ViewListModel>(viewListModel);
- mic_view_infos_BLL.Add(info);
- this.Close();
- }
- }
- }
- }
|