| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578 | using PaintDotNet.Annotation.Enum;using PaintDotNet.Annotation.FieldView;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.Drawing2D;using System.Drawing.Imaging;using System.Windows.Forms;namespace PaintDotNet.FieldView{    internal class OpenViewDialog : PdnBaseForm    {        #region 控件        private GroupBox groupBox1;        private GroupBox groupBox2;        private GroupBox groupBox3;        private GroupBox groupBox4;        private ListView listView1;        private Panel panel1;        private PictureBox pictureBox1;        private AppWorkspace appWorkspace;        private Button button4;        private Button button3;        private Button button2;        private Button button1;        private Label label1;        #endregion        /// <summary>        /// 重命名        /// </summary>        private EditViewDialog createNameDialog;        /// <summary>        /// 选定的视场在listview的items内的下标        /// </summary>        private int index = -1;        /// <summary>        /// 视场数据        /// </summary>        private List<mic_view_infos> list;        /// <summary>        /// 选定的视场数据的model        /// </summary>        private ViewListModel viewListModel;        public OpenViewDialog(AppWorkspace appWorkspace)        {            this.appWorkspace = appWorkspace;            InitializeComponent();            InitializeLanguageText();            InitListViewHeader();            InitViewData();        }        private void InitListViewHeader()        {            this.listView1.View = View.Details;            ColumnHeader header0 = new ColumnHeader();            header0.Text = "";            header0.Width = 25;            this.listView1.Columns.Add(header0);            ColumnHeader header = new ColumnHeader();            header.Text = PdnResources.GetString("Menu.viewname.text");            header.Width = 150;            this.listView1.Columns.Add(header);        }        private void InitViewData()        {            this.listView1.Items.Clear();            list = mic_view_infos_BLL.FindAll();            if (list != null)            {                for (int i = 0; i < list.Count; i++)                {                    mic_view_infos view = list[i];                    ListViewItem item = new ListViewItem();                    item.Tag = view.id;                    item.Text = "";                    item.SubItems.Add(view.view_name);                    this.listView1.Items.Add(item);                }            }        }        private void InitializeLanguageText()        {            this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");            this.button4.Text = PdnResources.GetString("Menu.Rename.text");            this.button3.Text = PdnResources.GetString("Menu.viewsetting.Openview.Openrecord.text");            this.button2.Text = PdnResources.GetString("Menu.viewsetting.Openview.DeleteRecord.text");            this.button1.Text = PdnResources.GetString("Menu.Applyall.text");            this.groupBox2.Text = PdnResources.GetString("Menu.viewsetting.Openview.List.text");            this.groupBox3.Text = PdnResources.GetString("Menu.Preview.text");            this.groupBox4.Text = PdnResources.GetString("Menu.viewsetting.Openview.brief.text");            this.Text = PdnResources.GetString("Menu.ViewSetting.OpenFieldOfView.Text");        }        private void InitializeComponent()        {            this.groupBox1 = new System.Windows.Forms.GroupBox();            this.button4 = new System.Windows.Forms.Button();            this.button3 = new System.Windows.Forms.Button();            this.button2 = new System.Windows.Forms.Button();            this.button1 = new System.Windows.Forms.Button();            this.groupBox2 = new System.Windows.Forms.GroupBox();            this.listView1 = new System.Windows.Forms.ListView();            this.groupBox3 = new System.Windows.Forms.GroupBox();            this.panel1 = new System.Windows.Forms.Panel();            this.pictureBox1 = new System.Windows.Forms.PictureBox();            this.groupBox4 = new System.Windows.Forms.GroupBox();            this.label1 = new System.Windows.Forms.Label();            this.groupBox1.SuspendLayout();            this.groupBox2.SuspendLayout();            this.groupBox3.SuspendLayout();            this.panel1.SuspendLayout();            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();            this.groupBox4.SuspendLayout();            this.SuspendLayout();            //             // groupBox1            //             this.groupBox1.Controls.Add(this.button4);            this.groupBox1.Controls.Add(this.button3);            this.groupBox1.Controls.Add(this.button2);            this.groupBox1.Controls.Add(this.button1);            this.groupBox1.Location = new System.Drawing.Point(13, 13);            this.groupBox1.Name = "groupBox1";            this.groupBox1.Size = new System.Drawing.Size(526, 46);            this.groupBox1.TabIndex = 1;            this.groupBox1.TabStop = false;            this.groupBox1.Text = "操作";            //             // button4            //             this.button4.Location = new System.Drawing.Point(445, 14);            this.button4.Name = "button4";            this.button4.Size = new System.Drawing.Size(75, 23);            this.button4.TabIndex = 1;            this.button4.Text = "重命名";            this.button4.UseVisualStyleBackColor = true;            this.button4.Click += new System.EventHandler(this.button4_Click);            //             // button3            //             this.button3.Location = new System.Drawing.Point(364, 14);            this.button3.Name = "button3";            this.button3.Size = new System.Drawing.Size(75, 23);            this.button3.TabIndex = 2;            this.button3.Text = "打开记录";            this.button3.UseVisualStyleBackColor = true;            this.button3.Click += new System.EventHandler(this.button3_Click);            //             // button2            //             this.button2.Location = new System.Drawing.Point(283, 14);            this.button2.Name = "button2";            this.button2.Size = new System.Drawing.Size(75, 23);            this.button2.TabIndex = 1;            this.button2.Text = "删除记录";            this.button2.UseVisualStyleBackColor = true;            this.button2.Click += new System.EventHandler(this.button2_Click);            //             // button1            //             this.button1.Location = new System.Drawing.Point(202, 14);            this.button1.Name = "button1";            this.button1.Size = new System.Drawing.Size(75, 23);            this.button1.TabIndex = 0;            this.button1.Text = "应用全部";            this.button1.UseVisualStyleBackColor = true;            this.button1.Click += new System.EventHandler(this.button1_Click);            //             // groupBox2            //             this.groupBox2.Controls.Add(this.listView1);            this.groupBox2.Location = new System.Drawing.Point(13, 66);            this.groupBox2.Name = "groupBox2";            this.groupBox2.Size = new System.Drawing.Size(200, 295);            this.groupBox2.TabIndex = 2;            this.groupBox2.TabStop = false;            this.groupBox2.Text = "列表";            //             // listView1            //             this.listView1.FullRowSelect = true;            this.listView1.HideSelection = false;            this.listView1.Location = new System.Drawing.Point(7, 21);            this.listView1.MultiSelect = false;            this.listView1.Name = "listView1";            this.listView1.Size = new System.Drawing.Size(187, 268);            this.listView1.TabIndex = 0;            this.listView1.UseCompatibleStateImageBehavior = false;            this.listView1.ItemSelectionChanged += new System.Windows.Forms.ListViewItemSelectionChangedEventHandler(this.listView1_ItemSelectionChanged);            //             // groupBox3            //             this.groupBox3.Controls.Add(this.panel1);            this.groupBox3.Location = new System.Drawing.Point(220, 66);            this.groupBox3.Name = "groupBox3";            this.groupBox3.Size = new System.Drawing.Size(319, 295);            this.groupBox3.TabIndex = 3;            this.groupBox3.TabStop = false;            this.groupBox3.Text = "预览";            //             // panel1            //             this.panel1.BackColor = System.Drawing.Color.Black;            this.panel1.Controls.Add(this.pictureBox1);            this.panel1.Location = new System.Drawing.Point(7, 21);            this.panel1.Name = "panel1";            this.panel1.Size = new System.Drawing.Size(306, 268);            this.panel1.TabIndex = 0;            //             // pictureBox1            //             this.pictureBox1.BackColor = System.Drawing.Color.Black;            this.pictureBox1.Location = new System.Drawing.Point(3, 3);            this.pictureBox1.Name = "pictureBox1";            this.pictureBox1.Size = new System.Drawing.Size(300, 262);            this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;            this.pictureBox1.TabIndex = 0;            this.pictureBox1.TabStop = false;            //             // groupBox4            //             this.groupBox4.Controls.Add(this.label1);            this.groupBox4.Location = new System.Drawing.Point(13, 368);            this.groupBox4.Name = "groupBox4";            this.groupBox4.Size = new System.Drawing.Size(526, 64);            this.groupBox4.TabIndex = 4;            this.groupBox4.TabStop = false;            this.groupBox4.Text = "简介";            //             // label1            //             this.label1.AutoSize = true;            this.label1.Dock = System.Windows.Forms.DockStyle.Fill;            this.label1.Location = new System.Drawing.Point(3, 17);            this.label1.Name = "label1";            this.label1.Size = new System.Drawing.Size(0, 12);            this.label1.TabIndex = 0;            //             // OpenViewDialog            //             this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);            this.ClientSize = new System.Drawing.Size(551, 444);            this.Controls.Add(this.groupBox4);            this.Controls.Add(this.groupBox3);            this.Controls.Add(this.groupBox2);            this.Controls.Add(this.groupBox1);            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;            this.MaximizeBox = false;            this.Name = "OpenViewDialog";            this.Text = "打开视场";            this.Controls.SetChildIndex(this.groupBox1, 0);            this.Controls.SetChildIndex(this.groupBox2, 0);            this.Controls.SetChildIndex(this.groupBox3, 0);            this.Controls.SetChildIndex(this.groupBox4, 0);            this.groupBox1.ResumeLayout(false);            this.groupBox2.ResumeLayout(false);            this.groupBox3.ResumeLayout(false);            this.panel1.ResumeLayout(false);            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();            this.groupBox4.ResumeLayout(false);            this.groupBox4.PerformLayout();            this.ResumeLayout(false);        }        /// <summary>        /// listView1 ItemSelectionChanged事件        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)        {            listView1.FullRowSelect = true;            if (this.listView1.SelectedItems.Count > 0)            {                listView1.SelectedItems[0].SubItems[0].ForeColor = Color.Blue;                //先清除原有格式                foreach (ListViewItem item in listView1.Items)                {                    item.ForeColor = Color.Black;                }                foreach (ListViewItem item in listView1.Items)                {                    item.BackColor = Color.White;                    Font f = new Font(Control.DefaultFont, FontStyle.Regular);                    item.Font = f;                }                //加粗字体                Font f2 = new Font(Control.DefaultFont, FontStyle.Bold);                listView1.SelectedItems[0].SubItems[0].Font = f2;                //设置选中行背景颜色                listView1.SelectedItems[0].BackColor = Color.LightBlue;                listView1.SelectedItems[0].Selected = true;                //赋值当前选中索引                this.index = e.ItemIndex;                //处理UI                this.label1.Text = "  " + list.Find(a => a.id == (int)(listView1.SelectedItems[0].Tag)).view_descrption;                //获得model                this.viewListModel = XmlSerializeHelper.DESerializer<ViewListModel>(list.Find(a => a.id == (int)(listView1.SelectedItems[0].Tag)).view_xml);                //绘制右侧预览                this.pictureBox1.Image = this.panel1_Paint(viewListModel);            }        }        /// <summary>        /// 绘制视场到图片        /// </summary>        /// <returns></returns>        private Bitmap panel1_Paint(ViewListModel viewListModel)        {            Region a = null;            for (int i = 0; i < viewListModel.Views.Count; i++)            {                if (viewListModel.Views[i].Type != null)                {                    GraphicsPath path = new GraphicsPath();                    DrawToolType type = (DrawToolType)Enum.Parse(typeof(DrawToolType), viewListModel.Views[i].Type);                    if (type == DrawToolType.ViewCircle)                    {                        path.AddEllipse(viewListModel.Views[i].Rectangle);                    }                    else if (type == DrawToolType.ViewOval)                    {                        path.AddClosedCurve(viewListModel.Views[i].Points.ToArray());                    }                    else                    {                        path.AddPolygon(viewListModel.Views[i].Points.ToArray());                    }                    if (a == null)                    {                        a = new Region(path);                    }                    else                    {                        if ((CombineMode)Enum.Parse(typeof(CombineMode), viewListModel.Views[i].CombineMode) == CombineMode.Union)                            a.Union(path);                        else                            a.Exclude(path);                    }                }            }            int width = (int)viewListModel.RectangleFW;            int height = (int)viewListModel.RectangleFH;            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 (a.IsVisible(new Point(x + (int)(viewListModel.RectangleFX), y + (int)(viewListModel.RectangleFY))))                        {                            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;        }        /// <summary>        /// 应用全部        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button1_Click(object sender, EventArgs e)        {            if (viewListModel != null && viewListModel.Views.Count > 0                && this.appWorkspace.DocumentWorkspaces != null                && this.appWorkspace.DocumentWorkspaces.Length > 0)            {                foreach (DocumentWorkspace dw in this.appWorkspace.DocumentWorkspaces)                {                    for (int i = 0; i < viewListModel.Views.Count; i++)                    {                        DrawToolType type = (DrawToolType)Enum.Parse(typeof(DrawToolType), viewListModel.Views[i].Type);                        ViewBase line = null;                        switch (type)                        {                            case DrawToolType.ViewOval:                                line = new ViewOval(viewListModel.Views[i].Points);                                break;                            case DrawToolType.ViewCircle:                                line = new ViewCircle(viewListModel.Views[i].Points);                                break;                            case DrawToolType.ViewRectangle:                                line = new ViewRectangle(viewListModel.Views[i].Points);                                break;                            case DrawToolType.ViewTriangle:                                line = new ViewTriangle(viewListModel.Views[i].Points);                                break;                            case DrawToolType.ViewSquare:                                line = new ViewSquare(viewListModel.Views[i].Points);                                break;                            case DrawToolType.ViewRectangleEx:                                line = new ViewRectangleEx(viewListModel.Views[i].Points);                                break;                            case DrawToolType.ViewPolygon:                                line = new ViewPolygon(viewListModel.Views[i].Points);                                break;                            case DrawToolType.ViewTriangleEx:                                line = new ViewTriangleEx(viewListModel.Views[i].Points);                                break;                        }                        if (line != null)                        {                            line.ISurfaceBox = dw;                            line.combineMode = (CombineMode)Enum.Parse(typeof(CombineMode), viewListModel.Views[i].CombineMode);                            line.Selected = true;                            dw.AddGraphicsFromForm(line);                        }                    }                }            }        }        /// <summary>        /// 删除记录        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button2_Click(object sender, EventArgs e)        {            if (this.listView1.SelectedItems != null && this.listView1.SelectedItems.Count > 0)            {                DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretodeletethefie.text") + "?", PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);                if (dr == DialogResult.OK)                {                    int id = (int)(this.listView1.SelectedItems[0].Tag);                    if (id > 0)                    {                        //删除数据库文件                        mic_view_infos_BLL.Del(id);                        InitViewData();                    }                }            }        }        /// <summary>        /// 打开记录        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button3_Click(object sender, EventArgs e)        {            //将所有的视场反向还原到surface中            if (viewListModel != null && viewListModel.Views.Count > 0 && this.appWorkspace.ActiveDocumentWorkspace != null                && this.appWorkspace.ActiveDocumentWorkspace.CompositionSurface != null                && this.appWorkspace.ActiveDocumentWorkspace.GraphicsList != null)            {                for (int i = 0; i < viewListModel.Views.Count; i++)                {                    DrawToolType type = (DrawToolType)Enum.Parse(typeof(DrawToolType), viewListModel.Views[i].Type);                    ViewBase line = null;                    switch (type)                    {                        case DrawToolType.ViewOval:                            line = new ViewOval(viewListModel.Views[i].Points);                            break;                        case DrawToolType.ViewCircle:                            line = new ViewCircle(viewListModel.Views[i].Points);                            break;                        case DrawToolType.ViewRectangle:                            line = new ViewRectangle(viewListModel.Views[i].Points);                            break;                        case DrawToolType.ViewRectangleEx:                            line = new ViewRectangleEx(viewListModel.Views[i].Points);                            break;                        case DrawToolType.ViewTriangle:                            line = new ViewTriangle(viewListModel.Views[i].Points);                            break;                        case DrawToolType.ViewSquare:                            line = new ViewSquare(viewListModel.Views[i].Points);                            break;                        case DrawToolType.ViewPolygon:                            line = new ViewPolygon(viewListModel.Views[i].Points);                            break;                        case DrawToolType.ViewTriangleEx:                            line = new ViewTriangleEx(viewListModel.Views[i].Points);                            break;                    }                    if (line != null)                    {                        line.ISurfaceBox = this.appWorkspace.ActiveDocumentWorkspace;                        line.combineMode = (CombineMode)Enum.Parse(typeof(CombineMode), viewListModel.Views[i].CombineMode);                        line.Selected = true;                        this.appWorkspace.ActiveDocumentWorkspace.AddGraphicsFromForm(line);                    }                }            }        }        /// <summary>        /// 重命名        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button4_Click(object sender, EventArgs e)        {            if (this.listView1.SelectedItems != null && this.listView1.SelectedItems.Count > 0)            {                createNameDialog = new EditViewDialog(this);                createNameDialog.Text = PdnResources.GetString("Menu.Rename.text");                createNameDialog.textBox1.Text = list[this.index].view_name;                createNameDialog.richTextBox1.Text = list[this.index].view_descrption;                createNameDialog.StartPosition = FormStartPosition.CenterParent;                createNameDialog.ShowDialog();            }        }        /// <summary>        /// 另存为弹窗 确定保存        /// </summary>        /// <param name="name"></param>        public override void GetCreateName(string name, string desc)        {            mic_view_infos model = list[this.index];            mic_view_infos query = list.Find(a => a.view_name.Equals(name));            if (query != null)            {                if (model.id != query.id)                {                    MessageBox.Show(PdnResources.GetString("Menu.viewnamerepeated,pleaserename.text"));                    return;                }            }            model.view_name = name;            model.view_descrption = desc;            mic_view_infos_BLL.Update(model);            createNameDialog.Close();            InitViewData();        }    }}
 |