123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844 |
- using PaintDotNet.Annotation.Enum;
- using PaintDotNet.Annotation.relationModel;
- using PaintDotNet.Base.SettingModel;
- using PaintDotNet.Base.CommTool;
- using PaintDotNet.Setting.LabelComponent;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.IO;
- using System.Windows.Forms;
- using PaintDotNet.Base;
- namespace PaintDotNet.Setting
- {
- /// <summary>
- /// 设置->标注设置
- /// </summary>
- internal class LabelSettingDialog : PdnBaseForm
- {
- /// <summary>
- /// 标注一二级关系
- /// </summary>
- private static List<LabelRelationModel> list;
- /// <summary>
- /// 当前选中的二级标注
- /// </summary>
- private DrawToolType drawToolType;
- /// <summary>
- /// 标注的样式
- /// </summary>
- private LabelStyleModel labelStyleModel = Startup.instance.labelStyleModel;
- /// <summary>
- /// 主配置文件的model
- /// </summary>
- private ConfigModel configModel = Startup.instance.configModel;
- /// <summary>
- /// 操作样式下拉数据
- /// </summary>
- private List<string> files = new List<string>();
- /// <summary>
- /// 另存为弹出框显示
- /// </summary>
- private CreateNameDialog dialog;
- /// <summary>
- /// 另存为文件名
- /// </summary>
- private string newName;
- private int initflag = 0;
- //各页面组件
- private LabelTextControl textControl;
- private LabelMarkDateControl dateMarkControl;
- private LabelMarkTimeControl timeMarkControl;
- private LabelMarkPointControl pointMarkControl;
- private LabelMarkNumberControl numberMarkControl;
- private LabelMarkGainNumberControl gainNumberControl;
- private LabelStraightLineControl straightLineControl;
- private LabelStraightLineSegmentControl segmentLineControl;
- private LabelCurvePencilControl pencilControl;
- private LabelCurvePolylineControl polylineControl;
- private LabelCurveControl curveControl;
- private LabelCurveClosedControl closedCurveControl;
- private LabelArrowOneWayControl oneWayArrowControl;
- private LabelArrowTwoWayControl twoWayArrowControl;
- private LabelCircleControl circleControl;
- private LabelCircleOvalControl ovalControl;
- private LabelPolygonRectangleControl polygonRectangleControl;
- private LabelPolygonControl polygonControl;
- private LabelPolygonRoundedControl roundedRectangleControl;
- private GroupBox groupBox4;
- private System.Windows.Forms.Label label71;
- private NumericUpDown numericUpDown71;
- private ConfigModel config = Startup.instance.configModel;
- private AppWorkspace appWorkspace;
- #region 控件
- private System.Windows.Forms.GroupBox groupBox1;
- private System.Windows.Forms.GroupBox groupBox2;
- private System.Windows.Forms.GroupBox groupBox3;
- private System.Windows.Forms.Panel panel1;
- private System.Windows.Forms.ListBox listBox1;
- private Button button3;
- private Button button2;
- private Button button4;
- private ComboBox comboBox1;
- private Label label1;
- private Button button5;
- #endregion
- public LabelSettingDialog(AppWorkspace appWorkspace)
- {
- if (list == null)
- {
- list = InvariantData.GetLabelRelations();
- }
- this.appWorkspace = appWorkspace;
- InitializeComponent();
- InitializeLanguageText();
- InitializeData();
- }
- private void InitializeLanguageText()
- {
- this.label1.Text = PdnResources.GetString("Menu.Currentoperationstyle.text") + ":";
- this.button4.Text = PdnResources.GetString("Menu.Edit.Delete.Text");
- this.button3.Text = PdnResources.GetString("Menu.File.SaveAs.Text");
- this.button2.Text = PdnResources.GetString("Menu.File.Save.Text");
- this.groupBox2.Text = PdnResources.GetString("Menu.Setting.Text");
- this.groupBox4.Text = PdnResources.GetString("Menu.Setting.Text");
- this.groupBox3.Text = PdnResources.GetString("Menu.Type.text");
- this.button5.Text = PdnResources.GetString("Menu.File.SaveAll.Text");
- this.Text = PdnResources.GetString("Menu.Setting.LabelSetting.Text");
- }
- private void InitializeComponent()
- {
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.label1 = new System.Windows.Forms.Label();
- this.comboBox1 = new System.Windows.Forms.ComboBox();
- this.button4 = new System.Windows.Forms.Button();
- this.button3 = new System.Windows.Forms.Button();
- this.button2 = new System.Windows.Forms.Button();
- this.groupBox2 = new System.Windows.Forms.GroupBox();
- this.groupBox3 = new System.Windows.Forms.GroupBox();
- this.listBox1 = new System.Windows.Forms.ListBox();
- this.panel1 = new System.Windows.Forms.Panel();
- this.button5 = new System.Windows.Forms.Button();
- this.groupBox4 = new System.Windows.Forms.GroupBox();
- this.numericUpDown71 = new System.Windows.Forms.NumericUpDown();
- this.label71 = new System.Windows.Forms.Label();
- this.groupBox4.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown71)).BeginInit();
- this.groupBox1.SuspendLayout();
- this.groupBox3.SuspendLayout();
- this.SuspendLayout();
- //
- // groupBox1
- //
- this.groupBox1.Controls.Add(this.label1);
- this.groupBox1.Controls.Add(this.comboBox1);
- this.groupBox1.Controls.Add(this.button4);
- this.groupBox1.Controls.Add(this.button3);
- this.groupBox1.Controls.Add(this.button2);
- this.groupBox1.Location = new System.Drawing.Point(134, 13);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(638, 58);
- this.groupBox1.TabIndex = 1;
- this.groupBox1.TabStop = false;
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.Location = new System.Drawing.Point(176, 25);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(89, 12);
- this.label1.TabIndex = 5;
- this.label1.Text = "当前操作样式:";
- //
- // comboBox1
- //
- this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.comboBox1.FormattingEnabled = true;
- this.comboBox1.Location = new System.Drawing.Point(271, 21);
- this.comboBox1.Name = "comboBox1";
- this.comboBox1.Size = new System.Drawing.Size(116, 20);
- this.comboBox1.TabIndex = 4;
- this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
- //
- // button4
- //
- this.button4.Location = new System.Drawing.Point(393, 20);
- this.button4.Name = "button4";
- this.button4.Size = new System.Drawing.Size(75, 23);
- this.button4.TabIndex = 3;
- this.button4.Text = "删除";
- this.button4.UseVisualStyleBackColor = true;
- this.button4.Click += new System.EventHandler(this.button4_Click);
- //
- // button3
- //
- this.button3.Location = new System.Drawing.Point(474, 20);
- 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(555, 20);
- 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);
- //
- // groupBox2
- //
- this.groupBox2.Location = new System.Drawing.Point(134, 120);
- this.groupBox2.Name = "groupBox2";
- this.groupBox2.Size = new System.Drawing.Size(633, 235);
- this.groupBox2.TabIndex = 2;
- this.groupBox2.TabStop = false;
- this.groupBox2.Text = "设置";
- //
- // groupBox4
- //
- this.groupBox4.Controls.Add(this.label71);
- this.groupBox4.Controls.Add(this.numericUpDown71);
- //this.groupBox4.Location = new System.Drawing.Point(137, 118);
- this.groupBox4.Location = new System.Drawing.Point(137, 76);
- this.groupBox4.Name = "groupBox4";
- this.groupBox4.Size = new System.Drawing.Size(716, 277);
- this.groupBox4.TabIndex = 6;
- this.groupBox4.TabStop = false;
- this.groupBox4.Text = "设置";
- this.groupBox4.Visible = false;
- //
- // label71
- //
- this.label71.AutoSize = true;
- this.label71.Location = new System.Drawing.Point(13, 23);
- this.label71.Name = "label71";
- this.label71.Size = new System.Drawing.Size(77, 12);
- this.label71.TabIndex = 0;
- this.label71.Text = "标记点大小:";
- //
- // numericUpDown71
- //
- this.numericUpDown71.Location = new System.Drawing.Point(91, 23);
- this.numericUpDown71.Maximum = new decimal(new int[] {
- 100000,
- 0,
- 0,
- 0});
- this.numericUpDown71.Name = "numericUpDown71";
- this.numericUpDown71.Size = new System.Drawing.Size(152, 21);
- this.numericUpDown71.TabIndex = 14;
- //
- // groupBox3
- //
- this.groupBox3.Controls.Add(this.listBox1);
- this.groupBox3.Location = new System.Drawing.Point(13, 13);
- this.groupBox3.Name = "groupBox3";
- this.groupBox3.Size = new System.Drawing.Size(115, 342);
- this.groupBox3.TabIndex = 3;
- this.groupBox3.TabStop = false;
- this.groupBox3.Text = "类型";
- //
- // listBox1
- //
- this.listBox1.FormattingEnabled = true;
- this.listBox1.ItemHeight = 12;
- this.listBox1.Location = new System.Drawing.Point(6, 20);
- this.listBox1.Name = "listBox1";
- this.listBox1.Size = new System.Drawing.Size(103, 316);
- this.listBox1.TabIndex = 0;
- this.listBox1.SelectedValueChanged += new System.EventHandler(this.listBox1_SelectedValueChanged);
- //
- // panel1
- //
- this.panel1.Location = new System.Drawing.Point(134, 78);
- this.panel1.Name = "panel1";
- this.panel1.Size = new System.Drawing.Size(556, 36);
- this.panel1.TabIndex = 5;
- //
- // button5
- //
- this.button5.Location = new System.Drawing.Point(692, 78);
- this.button5.Name = "button5";
- this.button5.Size = new System.Drawing.Size(75, 23);
- this.button5.TabIndex = 4;
- this.button5.Text = "保存全部";
- this.button5.UseVisualStyleBackColor = true;
- this.button5.Click += new System.EventHandler(this.button5_Click);
- //
- // LabelSettingDialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(776, 366);
- this.Controls.Add(this.button5);
- this.Controls.Add(this.panel1);
- this.Controls.Add(this.groupBox3);
- this.Controls.Add(this.groupBox4);
- this.Controls.Add(this.groupBox2);
- this.Controls.Add(this.groupBox1);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
- this.MaximizeBox = false;
- this.MinimizeBox = false;
- this.Name = "LabelSettingDialog";
- this.Text = "标注设置";
- this.Controls.SetChildIndex(this.groupBox1, 0);
- this.Controls.SetChildIndex(this.groupBox2, 0);
- this.Controls.SetChildIndex(this.groupBox4, 0);
- this.Controls.SetChildIndex(this.groupBox3, 0);
- this.Controls.SetChildIndex(this.panel1, 0);
- this.Controls.SetChildIndex(this.button5, 0);
- this.groupBox1.ResumeLayout(false);
- this.groupBox1.PerformLayout();
- this.groupBox3.ResumeLayout(false);
- this.groupBox4.ResumeLayout(false);
- this.groupBox4.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown71)).EndInit();
- this.ResumeLayout(false);
- }
- /// <summary>
- /// 初始化数据
- /// </summary>
- private void InitializeData()
- {
- //绑定左侧listbox数据
- this.listBox1.Items.Clear();
- foreach (LabelRelationModel model in list)
- {
- this.listBox1.Items.Add(model.name);
- }
- this.listBox1.SelectedIndex = 0;
- //绑定样式下拉
- if (initflag++ == 0)
- {
- InitializeStyleName();
- }
- //更新右侧设置界面
- UpdateRightSettingUI();
- this.numericUpDown71.Value = this.config.MarkpointWidth;
- }
- /// <summary>
- /// 初始化样式下拉
- /// </summary>
- private void InitializeStyleName()
- {
- List<string> fileNames = FileOperationHelper.GetFileList(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Label\\");
- files.Clear();
- foreach (string fileName in fileNames)
- {
- string name = fileName.Substring(0, fileName.LastIndexOf("."));
- files.Add(name);
- }
- this.comboBox1.SelectedIndexChanged -= this.comboBox1_SelectedIndexChanged;
- this.comboBox1.DataSource = null;
- this.comboBox1.DataSource = files;
- string nowModelName = Startup.instance.configModel.Watermark.Substring(0, Startup.instance.configModel.Watermark.LastIndexOf("."));
- this.comboBox1.SelectedIndex = files.FindIndex(a => a.Equals(nowModelName));
- this.labelStyleModel = XmlSerializeHelper.DESerializer<LabelStyleModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Label\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open));
- this.comboBox1.SelectedIndexChanged += new EventHandler(this.comboBox1_SelectedIndexChanged);
- }
- /// <summary>
- /// 当前操作样式 下拉选切换
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- this.labelStyleModel = XmlSerializeHelper.DESerializer<LabelStyleModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Label\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open));
- InitializeData();
- }
- /// <summary>
- /// 左侧listbox选择事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void listBox1_SelectedValueChanged(object sender, EventArgs e)
- {
- //首先更新右侧分类部分
- UpdateRightCatalog();
- //更新右侧设置界面
- UpdateRightSettingUI();
- //刷新右侧预览
- UpdateRightPreview();
- }
- /// <summary>
- /// 更新右侧分类
- /// </summary>
- private void UpdateRightCatalog()
- {
- this.panel1.Controls.Clear();
- LabelRelationModel model = list[this.listBox1.SelectedIndex];
- int postion = 0;
- if (model.id == 8)
- {
- groupBox2.Visible = false;
- panel1.Visible = false;
- button5.Visible = false;
- groupBox4.Visible = true;
- comboBox1.Visible = false;
- button4.Visible = false;
- button3.Visible = false;
- label1.Visible = false;
- }
- else {
- groupBox2.Visible = true;
- panel1.Visible = true;
- button5.Visible = true;
- groupBox4.Visible = false;
- comboBox1.Visible = true;
- button4.Visible = true;
- button3.Visible = true;
- label1.Visible = true;
- }
- foreach (LabelRelationModel.ChildLabel child in model.childLabel)
- {
- Button button = new Button();
- button.Size = new Size(75, 23);
- button.Location = new Point(postion * 75 + 5, 0);
- button.Text = child.name;
- button.Tag = child;
- button.Click += new EventHandler(ChildButton_Click);
- this.panel1.Controls.Add(button);
- if (postion == 0)
- {
- this.drawToolType = child.drawToolType;
- button.Focus();
- }
- postion++;
- }
- }
- /// <summary>
- /// 二级分类按钮点击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ChildButton_Click(object sender, EventArgs e)
- {
- Button button = (Button)sender;
- LabelRelationModel.ChildLabel child = (LabelRelationModel.ChildLabel)button.Tag;
- this.drawToolType = child.drawToolType;
- this.UpdateRightSettingUI();
- }
- /// <summary>
- /// 更新右侧设置
- /// </summary>
- private void UpdateRightSettingUI()
- {
- this.groupBox2.Controls.Clear();
- switch (this.drawToolType)
- {
- case DrawToolType.DrawTextString: //文本
- textControl = new LabelTextControl(this.labelStyleModel.text);
- textControl.Location = new Point(10, 15);
- this.groupBox2.Controls.Add(textControl);
- break;
- case DrawToolType.DrawDateMark: //标记-日期
- dateMarkControl = new LabelMarkDateControl(this.labelStyleModel.dateMark);
- dateMarkControl.Location = new Point(10, 15);
- this.groupBox2.Controls.Add(dateMarkControl);
- break;
- case DrawToolType.DrawTimeMark: //标记-时间
- timeMarkControl = new LabelMarkTimeControl(this.labelStyleModel.timeMark);
- timeMarkControl.Location = new Point(10, 15);
- this.groupBox2.Controls.Add(timeMarkControl);
- break;
- case DrawToolType.DrawPointMark: //标记-点标记
- pointMarkControl = new LabelMarkPointControl(this.labelStyleModel.pointMark);
- pointMarkControl.Location = new Point(10, 15);
- this.groupBox2.Controls.Add(pointMarkControl);
- break;
- case DrawToolType.DrawNumberMark: //标记-数字标记
- numberMarkControl = new LabelMarkNumberControl(this.labelStyleModel.numberMark);
- numberMarkControl.Location = new Point(10, 15);
- this.groupBox2.Controls.Add(numberMarkControl);
- break;
- case DrawToolType.DrawGainNumber: //标记-放大倍数
- gainNumberControl = new LabelMarkGainNumberControl(this.labelStyleModel.gainNumber);
- gainNumberControl.Location = new Point(10, 15);
- this.groupBox2.Controls.Add(gainNumberControl);
- break;
- case DrawToolType.DrawLine: //直线->直线
- straightLineControl = new LabelStraightLineControl(this.labelStyleModel.lineChildLine);
- straightLineControl.Location = new Point(10, 15);
- this.groupBox2.Controls.Add(straightLineControl);
- break;
- case DrawToolType.DrawLineSegment: //直线->线段
- segmentLineControl = new LabelStraightLineSegmentControl(this.labelStyleModel.lineChildLineSegment);
- segmentLineControl.Location = new Point(10, 15);
- this.groupBox2.Controls.Add(segmentLineControl);
- break;
- case DrawToolType.DrawPencil: //曲线->铅笔
- pencilControl = new LabelCurvePencilControl(this.labelStyleModel.pencilModel);
- pencilControl.Location = new Point(10, 15);
- this.groupBox2.Controls.Add(pencilControl);
- break;
- case DrawToolType.DrawPolygonLine: //曲线->折线
- polylineControl = new LabelCurvePolylineControl(this.labelStyleModel.polylineModel);
- polylineControl.Location = new Point(10, 15);
- this.groupBox2.Controls.Add(polylineControl);
- break;
- case DrawToolType.DrawCurve: //曲线->曲线
- curveControl = new LabelCurveControl(this.labelStyleModel.curveModel);
- curveControl.Location = new Point(10, 15);
- this.groupBox2.Controls.Add(curveControl);
- break;
- case DrawToolType.DrawClosedCurve: //曲线->闭合曲线
- closedCurveControl = new LabelCurveClosedControl(this.labelStyleModel.closedCurveModel);
- closedCurveControl.Location = new Point(10, 15);
- this.groupBox2.Controls.Add(closedCurveControl);
- break;
- case DrawToolType.DrawOneArrowLine: //箭头->单向箭头
- oneWayArrowControl = new LabelArrowOneWayControl(this.labelStyleModel.oneWayArrowModel);
- oneWayArrowControl.Location = new Point(10, 15);
- this.groupBox2.Controls.Add(oneWayArrowControl);
- break;
- case DrawToolType.DrawTwoArrowLine: //箭头->双向箭头
- twoWayArrowControl = new LabelArrowTwoWayControl(this.labelStyleModel.twoWayArrowModel);
- twoWayArrowControl.Location = new Point(10, 15);
- this.groupBox2.Controls.Add(twoWayArrowControl);
- break;
- case DrawToolType.DrawCircle: //圆->圆
- circleControl = new LabelCircleControl(this.labelStyleModel.circleModel);
- circleControl.Location = new Point(10, 15);
- this.groupBox2.Controls.Add(circleControl);
- break;
- case DrawToolType.DrawEllipse: //圆->椭圆
- ovalControl = new LabelCircleOvalControl(this.labelStyleModel.ovalModel);
- ovalControl.Location = new Point(10, 15);
- this.groupBox2.Controls.Add(ovalControl);
- break;
- case DrawToolType.DrawRectangle: //多边形->矩形
- polygonRectangleControl = new LabelPolygonRectangleControl(this.labelStyleModel.polygonRectangle);
- polygonRectangleControl.Location = new Point(10, 15);
- this.groupBox2.Controls.Add(polygonRectangleControl);
- break;
- case DrawToolType.DrawPolygon: //多边形->多边形
- polygonControl = new LabelPolygonControl(this.labelStyleModel.polygonPolygon);
- polygonControl.Location = new Point(10, 15);
- this.groupBox2.Controls.Add(polygonControl);
- break;
- case DrawToolType.DrawRoundRectangle: //多边形->圆角矩形
- roundedRectangleControl = new LabelPolygonRoundedControl(this.labelStyleModel.roundedRectangle);
- roundedRectangleControl.Location = new Point(10, 15);
- this.groupBox2.Controls.Add(roundedRectangleControl);
- break;
- }
- }
- /// <summary>
- /// 刷新右侧预览图
- /// </summary>
- private void UpdateRightPreview()
- {
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button4_Click(object sender, EventArgs e)
- {
- if ("Default".Equals(this.comboBox1.Text))
- {
- MessageBox.Show(PdnResources.GetString("Menu.efaultstylecannotbedelete.Text"), PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.nfirmthedeleti.Text"), PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
- if (dr == DialogResult.OK)
- {
- int newIndex = 0;
- int selectIndex = this.comboBox1.SelectedIndex;
- int tall = files.Count - 1;
- if (selectIndex < tall)
- {
- newIndex = selectIndex;
- }
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Label\\" + this.comboBox1.Text + ".xml";
- FileInfo fileInfo = new FileInfo(filePath);
- fileInfo.Delete();
- InitializeStyleName();
- this.comboBox1.SelectedIndex = newIndex;
- this.labelStyleModel = XmlSerializeHelper.DESerializer<LabelStyleModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Label\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open));
- InitializeData();
- }
- else if (dr == DialogResult.Cancel)
- {
- }
- }
- /// <summary>
- /// 另存为 出弹窗
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button3_Click(object sender, EventArgs e)
- {
- dialog = new CreateNameDialog(this);
- dialog.Text = PdnResources.GetString("Menu.Set.Watermarksettings.Newstyle.text");
- dialog.StartPosition = FormStartPosition.CenterParent;
- dialog.ShowDialog();
- }
- /// <summary>
- /// 另存为弹窗 确定保存
- /// </summary>
- /// <param name="name"></param>
- public override void GetCreateName(string name)
- {
- string currentcomboBox = this.comboBox1.Text;
- this.newName = name;
- if (files.Contains(this.newName))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Stylenamecannotberepeated.text"), PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- LabelStyleModel newModel = this.labelStyleModel;
- modelSave(newModel);
- //另存为
- string stageModelXml = XmlSerializeHelper.XmlSerialize<LabelStyleModel>(newModel);
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Label\\" + this.newName + ".xml";
- FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create);
- InitializeStyleName();
- this.comboBox1.Text = currentcomboBox;
- dialog.Close();
- }
- /// <summary>
- /// 保存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button2_Click(object sender, EventArgs e)
- {
- this.labelStyleModel = modelSave(this.labelStyleModel);
- //以下保存xml文件信息
- string stageModelXml = XmlSerializeHelper.XmlSerialize<LabelStyleModel>(this.labelStyleModel);
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Label\\" + this.comboBox1.Text + ".xml";
- FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create);
- this.config.MarkpointWidth = Convert.ToInt32(this.numericUpDown71.Value);
- string configModelXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
- FileOperationHelper.WriteStringToFile(configModelXml, Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml", FileMode.Create);
- MarkPointRect.markPointRectWidth = configModel.MarkpointWidth;
- if (this.appWorkspace.DocumentWorkspaces != null)
- {
- foreach (var item in this.appWorkspace.DocumentWorkspaces)
- {
- if (item != null && item.GraphicsList != null)
- foreach (var graObject in item.GraphicsList.graphicsList)
- {
- graObject.smallRectangleWidth = this.config.MarkpointWidth;
- }
- item.Refresh();
- }
- }
- ApplicationSetting();
- }
- /// <summary>
- /// 各个子页面的model保存方法
- /// </summary>
- private LabelStyleModel modelSave(LabelStyleModel model)
- {
- switch (this.drawToolType)
- {
- case DrawToolType.DrawTextString: //文本
- model.text = textControl.getNowModel(this.labelStyleModel.text);
- break;
- case DrawToolType.DrawDateMark: //标记-日期
- model.dateMark = dateMarkControl.getNowModel(this.labelStyleModel.dateMark);
- break;
- case DrawToolType.DrawTimeMark: //标记-时间
- model.timeMark = timeMarkControl.getNowModel(this.labelStyleModel.timeMark);
- break;
- case DrawToolType.DrawPointMark: //标记-点标记
- model.pointMark = pointMarkControl.getNowModel(this.labelStyleModel.pointMark);
- break;
- case DrawToolType.DrawNumberMark: //标记-数字标记
- model.numberMark = numberMarkControl.getNowModel(this.labelStyleModel.numberMark);
- break;
- case DrawToolType.DrawGainNumber: //标记-放大倍数
- model.gainNumber = gainNumberControl.getNowModel(this.labelStyleModel.gainNumber);
- break;
- case DrawToolType.DrawLine: //直线->直线
- model.lineChildLine = straightLineControl.getNowModel(this.labelStyleModel.lineChildLine);
- break;
- case DrawToolType.DrawLineSegment: //直线->线段
- model.lineChildLineSegment = segmentLineControl.getNowModel(this.labelStyleModel.lineChildLineSegment);
- break;
- case DrawToolType.DrawPencil: //曲线->铅笔
- model.pencilModel = pencilControl.getNowModel(this.labelStyleModel.pencilModel);
- break;
- case DrawToolType.DrawPolygonLine: //曲线->折线
- model.polylineModel = polylineControl.getNowModel(this.labelStyleModel.polylineModel);
- break;
- case DrawToolType.DrawCurve: //曲线->曲线
- model.curveModel = curveControl.getNowModel(this.labelStyleModel.curveModel);
- break;
- case DrawToolType.DrawClosedCurve: //曲线->闭合曲线
- model.closedCurveModel = closedCurveControl.getNowModel(this.labelStyleModel.closedCurveModel);
- break;
- case DrawToolType.DrawOneArrowLine: //箭头->单向箭头
- model.oneWayArrowModel = oneWayArrowControl.getNowModel(this.labelStyleModel.oneWayArrowModel);
- break;
- case DrawToolType.DrawTwoArrowLine: //箭头->双向箭头
- model.twoWayArrowModel = twoWayArrowControl.getNowModel(this.labelStyleModel.twoWayArrowModel);
- break;
- case DrawToolType.DrawCircle: //圆->圆
- model.circleModel = circleControl.getNowModel(this.labelStyleModel.circleModel);
- break;
- case DrawToolType.DrawEllipse: //圆->椭圆
- model.ovalModel = ovalControl.getNowModel(this.labelStyleModel.ovalModel);
- break;
- case DrawToolType.DrawRectangle: //多边形->矩形
- model.polygonRectangle = polygonRectangleControl.getNowModel(this.labelStyleModel.polygonRectangle);
- break;
- case DrawToolType.DrawPolygon: //多边形->多边形
- model.polygonPolygon = polygonControl.getNowModel(this.labelStyleModel.polygonPolygon);
- break;
- case DrawToolType.DrawRoundRectangle: //多边形->圆角矩形
- model.roundedRectangle = roundedRectangleControl.getNowModel(this.labelStyleModel.roundedRectangle);
- break;
- }
- return model;
- }
- /// <summary>
- /// 应用
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ApplicationSetting()
- {
- //修改缓存中的样式数据
- Startup.instance.labelStyleModel = this.labelStyleModel;
- //修改主配置文件中的值
- configModel.LabelStyle = this.comboBox1.Text + ".xml";
- //修改主配置文件的xml
- string configModelXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(this.configModel);
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
- FileOperationHelper.WriteStringToFile(configModelXml, filePath, FileMode.Create);
- MessageBox.Show(PdnResources.GetString("Menu.Successfullysaved.text"));
- }
- /// <summary>
- /// 应用全部
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button5_Click(object sender, EventArgs e)
- {
- switch (this.drawToolType)
- {
- case DrawToolType.DrawTextString: //文本
- this.labelStyleModel.text = textControl.getNowModel(this.labelStyleModel.text);
- break;
- case DrawToolType.DrawDateMark: //标记-日期
- this.labelStyleModel = dateMarkControl.ApplyAll(this.labelStyleModel);
- break;
- case DrawToolType.DrawTimeMark: //标记-时间
- this.labelStyleModel = timeMarkControl.ApplyAll(this.labelStyleModel);
- break;
- case DrawToolType.DrawNumberMark: //标记-数字标记
- this.labelStyleModel = numberMarkControl.ApplyAll(this.labelStyleModel);
- break;
- case DrawToolType.DrawGainNumber: //标记-放大倍数
- this.labelStyleModel = gainNumberControl.ApplyAll(this.labelStyleModel);
- break;
- case DrawToolType.DrawLine: //直线->直线
- this.labelStyleModel = straightLineControl.ApplyAll(this.labelStyleModel);
- break;
- case DrawToolType.DrawLineSegment: //直线->线段
- this.labelStyleModel = segmentLineControl.ApplyAll(this.labelStyleModel);
- break;
- case DrawToolType.DrawPencil: //曲线->铅笔
- this.labelStyleModel = pencilControl.ApplyAll(this.labelStyleModel);
- break;
- case DrawToolType.DrawPolygonLine: //曲线->折线
- this.labelStyleModel = polylineControl.ApplyAll(this.labelStyleModel);
- break;
- case DrawToolType.DrawCurve: //曲线->曲线
- this.labelStyleModel = curveControl.ApplyAll(this.labelStyleModel);
- break;
- case DrawToolType.DrawClosedCurve: //曲线->闭合曲线
- this.labelStyleModel = closedCurveControl.ApplyAll(this.labelStyleModel);
- break;
- case DrawToolType.DrawOneArrowLine: //箭头->单向箭头
- this.labelStyleModel = oneWayArrowControl.ApplyAll(this.labelStyleModel);
- break;
- case DrawToolType.DrawTwoArrowLine: //箭头->双向箭头
- this.labelStyleModel = twoWayArrowControl.ApplyAll(this.labelStyleModel);
- break;
- case DrawToolType.DrawCircle: //圆->圆
- this.labelStyleModel = circleControl.ApplyAll(this.labelStyleModel);
- break;
- case DrawToolType.DrawEllipse: //圆->椭圆
- this.labelStyleModel = ovalControl.ApplyAll(this.labelStyleModel);
- break;
- case DrawToolType.DrawRectangle: //多边形->矩形
- this.labelStyleModel = polygonRectangleControl.ApplyAll(this.labelStyleModel);
- break;
- case DrawToolType.DrawPolygon: //多边形->多边形
- this.labelStyleModel = polygonControl.ApplyAll(this.labelStyleModel);
- break;
- case DrawToolType.DrawRoundRectangle: //多边形->圆角矩形
- this.labelStyleModel = roundedRectangleControl.ApplyAll(this.labelStyleModel);
- break;
- }
- //以下保存xml文件信息
- string stageModelXml = XmlSerializeHelper.XmlSerialize<LabelStyleModel>(this.labelStyleModel);
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Label\\" + this.comboBox1.Text + ".xml";
- FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create);
- ApplicationSetting();
- }
- }
- }
|