LabelSettingDialog.cs 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. using PaintDotNet.Annotation.Enum;
  2. using PaintDotNet.Annotation.relationModel;
  3. using PaintDotNet.Base.SettingModel;
  4. using PaintDotNet.Base.CommTool;
  5. using PaintDotNet.Setting.LabelComponent;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Windows.Forms;
  11. using PaintDotNet.Base;
  12. namespace PaintDotNet.Setting
  13. {
  14. /// <summary>
  15. /// 设置->标注设置
  16. /// </summary>
  17. internal class LabelSettingDialog : PdnBaseForm
  18. {
  19. /// <summary>
  20. /// 标注一二级关系
  21. /// </summary>
  22. private static List<LabelRelationModel> list;
  23. /// <summary>
  24. /// 当前选中的二级标注
  25. /// </summary>
  26. private DrawToolType drawToolType;
  27. /// <summary>
  28. /// 标注的样式
  29. /// </summary>
  30. private LabelStyleModel labelStyleModel = Startup.instance.labelStyleModel;
  31. /// <summary>
  32. /// 主配置文件的model
  33. /// </summary>
  34. private ConfigModel configModel = Startup.instance.configModel;
  35. /// <summary>
  36. /// 操作样式下拉数据
  37. /// </summary>
  38. private List<string> files = new List<string>();
  39. /// <summary>
  40. /// 另存为弹出框显示
  41. /// </summary>
  42. private CreateNameDialog dialog;
  43. /// <summary>
  44. /// 另存为文件名
  45. /// </summary>
  46. private string newName;
  47. private int initflag = 0;
  48. //各页面组件
  49. private LabelTextControl textControl;
  50. private LabelMarkDateControl dateMarkControl;
  51. private LabelMarkTimeControl timeMarkControl;
  52. private LabelMarkPointControl pointMarkControl;
  53. private LabelMarkNumberControl numberMarkControl;
  54. private LabelMarkGainNumberControl gainNumberControl;
  55. private LabelStraightLineControl straightLineControl;
  56. private LabelStraightLineSegmentControl segmentLineControl;
  57. private LabelCurvePencilControl pencilControl;
  58. private LabelCurvePolylineControl polylineControl;
  59. private LabelCurveControl curveControl;
  60. private LabelCurveClosedControl closedCurveControl;
  61. private LabelArrowOneWayControl oneWayArrowControl;
  62. private LabelArrowTwoWayControl twoWayArrowControl;
  63. private LabelCircleControl circleControl;
  64. private LabelCircleOvalControl ovalControl;
  65. private LabelPolygonRectangleControl polygonRectangleControl;
  66. private LabelPolygonControl polygonControl;
  67. private LabelPolygonRoundedControl roundedRectangleControl;
  68. private GroupBox groupBox4;
  69. private System.Windows.Forms.Label label71;
  70. private NumericUpDown numericUpDown71;
  71. private ConfigModel config = Startup.instance.configModel;
  72. private AppWorkspace appWorkspace;
  73. #region 控件
  74. private System.Windows.Forms.GroupBox groupBox1;
  75. private System.Windows.Forms.GroupBox groupBox2;
  76. private System.Windows.Forms.GroupBox groupBox3;
  77. private System.Windows.Forms.Panel panel1;
  78. private System.Windows.Forms.ListBox listBox1;
  79. private Button button3;
  80. private Button button2;
  81. private Button button4;
  82. private ComboBox comboBox1;
  83. private Label label1;
  84. private Button button5;
  85. #endregion
  86. public LabelSettingDialog(AppWorkspace appWorkspace)
  87. {
  88. if (list == null)
  89. {
  90. list = InvariantData.GetLabelRelations();
  91. }
  92. this.appWorkspace = appWorkspace;
  93. InitializeComponent();
  94. InitializeLanguageText();
  95. InitializeData();
  96. }
  97. private void InitializeLanguageText()
  98. {
  99. this.label1.Text = PdnResources.GetString("Menu.Currentoperationstyle.text") + ":";
  100. this.button4.Text = PdnResources.GetString("Menu.Edit.Delete.Text");
  101. this.button3.Text = PdnResources.GetString("Menu.File.SaveAs.Text");
  102. this.button2.Text = PdnResources.GetString("Menu.File.Save.Text");
  103. this.groupBox2.Text = PdnResources.GetString("Menu.Setting.Text");
  104. this.groupBox4.Text = PdnResources.GetString("Menu.Setting.Text");
  105. this.groupBox3.Text = PdnResources.GetString("Menu.Type.text");
  106. this.button5.Text = PdnResources.GetString("Menu.File.SaveAll.Text");
  107. this.Text = PdnResources.GetString("Menu.Setting.LabelSetting.Text");
  108. }
  109. private void InitializeComponent()
  110. {
  111. this.groupBox1 = new System.Windows.Forms.GroupBox();
  112. this.label1 = new System.Windows.Forms.Label();
  113. this.comboBox1 = new System.Windows.Forms.ComboBox();
  114. this.button4 = new System.Windows.Forms.Button();
  115. this.button3 = new System.Windows.Forms.Button();
  116. this.button2 = new System.Windows.Forms.Button();
  117. this.groupBox2 = new System.Windows.Forms.GroupBox();
  118. this.groupBox3 = new System.Windows.Forms.GroupBox();
  119. this.listBox1 = new System.Windows.Forms.ListBox();
  120. this.panel1 = new System.Windows.Forms.Panel();
  121. this.button5 = new System.Windows.Forms.Button();
  122. this.groupBox4 = new System.Windows.Forms.GroupBox();
  123. this.numericUpDown71 = new System.Windows.Forms.NumericUpDown();
  124. this.label71 = new System.Windows.Forms.Label();
  125. this.groupBox4.SuspendLayout();
  126. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown71)).BeginInit();
  127. this.groupBox1.SuspendLayout();
  128. this.groupBox3.SuspendLayout();
  129. this.SuspendLayout();
  130. //
  131. // groupBox1
  132. //
  133. this.groupBox1.Controls.Add(this.label1);
  134. this.groupBox1.Controls.Add(this.comboBox1);
  135. this.groupBox1.Controls.Add(this.button4);
  136. this.groupBox1.Controls.Add(this.button3);
  137. this.groupBox1.Controls.Add(this.button2);
  138. this.groupBox1.Location = new System.Drawing.Point(134, 13);
  139. this.groupBox1.Name = "groupBox1";
  140. this.groupBox1.Size = new System.Drawing.Size(638, 58);
  141. this.groupBox1.TabIndex = 1;
  142. this.groupBox1.TabStop = false;
  143. //
  144. // label1
  145. //
  146. this.label1.AutoSize = true;
  147. this.label1.Location = new System.Drawing.Point(176, 25);
  148. this.label1.Name = "label1";
  149. this.label1.Size = new System.Drawing.Size(89, 12);
  150. this.label1.TabIndex = 5;
  151. this.label1.Text = "当前操作样式:";
  152. //
  153. // comboBox1
  154. //
  155. this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  156. this.comboBox1.FormattingEnabled = true;
  157. this.comboBox1.Location = new System.Drawing.Point(271, 21);
  158. this.comboBox1.Name = "comboBox1";
  159. this.comboBox1.Size = new System.Drawing.Size(116, 20);
  160. this.comboBox1.TabIndex = 4;
  161. this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
  162. //
  163. // button4
  164. //
  165. this.button4.Location = new System.Drawing.Point(393, 20);
  166. this.button4.Name = "button4";
  167. this.button4.Size = new System.Drawing.Size(75, 23);
  168. this.button4.TabIndex = 3;
  169. this.button4.Text = "删除";
  170. this.button4.UseVisualStyleBackColor = true;
  171. this.button4.Click += new System.EventHandler(this.button4_Click);
  172. //
  173. // button3
  174. //
  175. this.button3.Location = new System.Drawing.Point(474, 20);
  176. this.button3.Name = "button3";
  177. this.button3.Size = new System.Drawing.Size(75, 23);
  178. this.button3.TabIndex = 2;
  179. this.button3.Text = "另存为";
  180. this.button3.UseVisualStyleBackColor = true;
  181. this.button3.Click += new System.EventHandler(this.button3_Click);
  182. //
  183. // button2
  184. //
  185. this.button2.Location = new System.Drawing.Point(555, 20);
  186. this.button2.Name = "button2";
  187. this.button2.Size = new System.Drawing.Size(75, 23);
  188. this.button2.TabIndex = 1;
  189. this.button2.Text = "保存";
  190. this.button2.UseVisualStyleBackColor = true;
  191. this.button2.Click += new System.EventHandler(this.button2_Click);
  192. //
  193. // groupBox2
  194. //
  195. this.groupBox2.Location = new System.Drawing.Point(134, 120);
  196. this.groupBox2.Name = "groupBox2";
  197. this.groupBox2.Size = new System.Drawing.Size(633, 235);
  198. this.groupBox2.TabIndex = 2;
  199. this.groupBox2.TabStop = false;
  200. this.groupBox2.Text = "设置";
  201. //
  202. // groupBox4
  203. //
  204. this.groupBox4.Controls.Add(this.label71);
  205. this.groupBox4.Controls.Add(this.numericUpDown71);
  206. //this.groupBox4.Location = new System.Drawing.Point(137, 118);
  207. this.groupBox4.Location = new System.Drawing.Point(137, 76);
  208. this.groupBox4.Name = "groupBox4";
  209. this.groupBox4.Size = new System.Drawing.Size(716, 277);
  210. this.groupBox4.TabIndex = 6;
  211. this.groupBox4.TabStop = false;
  212. this.groupBox4.Text = "设置";
  213. this.groupBox4.Visible = false;
  214. //
  215. // label71
  216. //
  217. this.label71.AutoSize = true;
  218. this.label71.Location = new System.Drawing.Point(13, 23);
  219. this.label71.Name = "label71";
  220. this.label71.Size = new System.Drawing.Size(77, 12);
  221. this.label71.TabIndex = 0;
  222. this.label71.Text = "标记点大小:";
  223. //
  224. // numericUpDown71
  225. //
  226. this.numericUpDown71.Location = new System.Drawing.Point(91, 23);
  227. this.numericUpDown71.Maximum = new decimal(new int[] {
  228. 100000,
  229. 0,
  230. 0,
  231. 0});
  232. this.numericUpDown71.Name = "numericUpDown71";
  233. this.numericUpDown71.Size = new System.Drawing.Size(152, 21);
  234. this.numericUpDown71.TabIndex = 14;
  235. //
  236. // groupBox3
  237. //
  238. this.groupBox3.Controls.Add(this.listBox1);
  239. this.groupBox3.Location = new System.Drawing.Point(13, 13);
  240. this.groupBox3.Name = "groupBox3";
  241. this.groupBox3.Size = new System.Drawing.Size(115, 342);
  242. this.groupBox3.TabIndex = 3;
  243. this.groupBox3.TabStop = false;
  244. this.groupBox3.Text = "类型";
  245. //
  246. // listBox1
  247. //
  248. this.listBox1.FormattingEnabled = true;
  249. this.listBox1.ItemHeight = 12;
  250. this.listBox1.Location = new System.Drawing.Point(6, 20);
  251. this.listBox1.Name = "listBox1";
  252. this.listBox1.Size = new System.Drawing.Size(103, 316);
  253. this.listBox1.TabIndex = 0;
  254. this.listBox1.SelectedValueChanged += new System.EventHandler(this.listBox1_SelectedValueChanged);
  255. //
  256. // panel1
  257. //
  258. this.panel1.Location = new System.Drawing.Point(134, 78);
  259. this.panel1.Name = "panel1";
  260. this.panel1.Size = new System.Drawing.Size(556, 36);
  261. this.panel1.TabIndex = 5;
  262. //
  263. // button5
  264. //
  265. this.button5.Location = new System.Drawing.Point(692, 78);
  266. this.button5.Name = "button5";
  267. this.button5.Size = new System.Drawing.Size(75, 23);
  268. this.button5.TabIndex = 4;
  269. this.button5.Text = "保存全部";
  270. this.button5.UseVisualStyleBackColor = true;
  271. this.button5.Click += new System.EventHandler(this.button5_Click);
  272. //
  273. // LabelSettingDialog
  274. //
  275. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  276. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  277. this.ClientSize = new System.Drawing.Size(776, 366);
  278. this.Controls.Add(this.button5);
  279. this.Controls.Add(this.panel1);
  280. this.Controls.Add(this.groupBox3);
  281. this.Controls.Add(this.groupBox4);
  282. this.Controls.Add(this.groupBox2);
  283. this.Controls.Add(this.groupBox1);
  284. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  285. this.MaximizeBox = false;
  286. this.MinimizeBox = false;
  287. this.Name = "LabelSettingDialog";
  288. this.Text = "标注设置";
  289. this.Controls.SetChildIndex(this.groupBox1, 0);
  290. this.Controls.SetChildIndex(this.groupBox2, 0);
  291. this.Controls.SetChildIndex(this.groupBox4, 0);
  292. this.Controls.SetChildIndex(this.groupBox3, 0);
  293. this.Controls.SetChildIndex(this.panel1, 0);
  294. this.Controls.SetChildIndex(this.button5, 0);
  295. this.groupBox1.ResumeLayout(false);
  296. this.groupBox1.PerformLayout();
  297. this.groupBox3.ResumeLayout(false);
  298. this.groupBox4.ResumeLayout(false);
  299. this.groupBox4.PerformLayout();
  300. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown71)).EndInit();
  301. this.ResumeLayout(false);
  302. }
  303. /// <summary>
  304. /// 初始化数据
  305. /// </summary>
  306. private void InitializeData()
  307. {
  308. //绑定左侧listbox数据
  309. this.listBox1.Items.Clear();
  310. foreach (LabelRelationModel model in list)
  311. {
  312. this.listBox1.Items.Add(model.name);
  313. }
  314. this.listBox1.SelectedIndex = 0;
  315. //绑定样式下拉
  316. if (initflag++ == 0)
  317. {
  318. InitializeStyleName();
  319. }
  320. //更新右侧设置界面
  321. UpdateRightSettingUI();
  322. this.numericUpDown71.Value = this.config.MarkpointWidth;
  323. }
  324. /// <summary>
  325. /// 初始化样式下拉
  326. /// </summary>
  327. private void InitializeStyleName()
  328. {
  329. List<string> fileNames = FileOperationHelper.GetFileList(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Label\\");
  330. files.Clear();
  331. foreach (string fileName in fileNames)
  332. {
  333. string name = fileName.Substring(0, fileName.LastIndexOf("."));
  334. files.Add(name);
  335. }
  336. this.comboBox1.SelectedIndexChanged -= this.comboBox1_SelectedIndexChanged;
  337. this.comboBox1.DataSource = null;
  338. this.comboBox1.DataSource = files;
  339. string nowModelName = Startup.instance.configModel.Watermark.Substring(0, Startup.instance.configModel.Watermark.LastIndexOf("."));
  340. this.comboBox1.SelectedIndex = files.FindIndex(a => a.Equals(nowModelName));
  341. this.labelStyleModel = XmlSerializeHelper.DESerializer<LabelStyleModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Label\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open));
  342. this.comboBox1.SelectedIndexChanged += new EventHandler(this.comboBox1_SelectedIndexChanged);
  343. }
  344. /// <summary>
  345. /// 当前操作样式 下拉选切换
  346. /// </summary>
  347. /// <param name="sender"></param>
  348. /// <param name="e"></param>
  349. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  350. {
  351. this.labelStyleModel = XmlSerializeHelper.DESerializer<LabelStyleModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Label\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open));
  352. InitializeData();
  353. }
  354. /// <summary>
  355. /// 左侧listbox选择事件
  356. /// </summary>
  357. /// <param name="sender"></param>
  358. /// <param name="e"></param>
  359. private void listBox1_SelectedValueChanged(object sender, EventArgs e)
  360. {
  361. //首先更新右侧分类部分
  362. UpdateRightCatalog();
  363. //更新右侧设置界面
  364. UpdateRightSettingUI();
  365. //刷新右侧预览
  366. UpdateRightPreview();
  367. }
  368. /// <summary>
  369. /// 更新右侧分类
  370. /// </summary>
  371. private void UpdateRightCatalog()
  372. {
  373. this.panel1.Controls.Clear();
  374. LabelRelationModel model = list[this.listBox1.SelectedIndex];
  375. int postion = 0;
  376. if (model.id == 8)
  377. {
  378. groupBox2.Visible = false;
  379. panel1.Visible = false;
  380. button5.Visible = false;
  381. groupBox4.Visible = true;
  382. comboBox1.Visible = false;
  383. button4.Visible = false;
  384. button3.Visible = false;
  385. label1.Visible = false;
  386. }
  387. else {
  388. groupBox2.Visible = true;
  389. panel1.Visible = true;
  390. button5.Visible = true;
  391. groupBox4.Visible = false;
  392. comboBox1.Visible = true;
  393. button4.Visible = true;
  394. button3.Visible = true;
  395. label1.Visible = true;
  396. }
  397. foreach (LabelRelationModel.ChildLabel child in model.childLabel)
  398. {
  399. Button button = new Button();
  400. button.Size = new Size(75, 23);
  401. button.Location = new Point(postion * 75 + 5, 0);
  402. button.Text = child.name;
  403. button.Tag = child;
  404. button.Click += new EventHandler(ChildButton_Click);
  405. this.panel1.Controls.Add(button);
  406. if (postion == 0)
  407. {
  408. this.drawToolType = child.drawToolType;
  409. button.Focus();
  410. }
  411. postion++;
  412. }
  413. }
  414. /// <summary>
  415. /// 二级分类按钮点击事件
  416. /// </summary>
  417. /// <param name="sender"></param>
  418. /// <param name="e"></param>
  419. private void ChildButton_Click(object sender, EventArgs e)
  420. {
  421. Button button = (Button)sender;
  422. LabelRelationModel.ChildLabel child = (LabelRelationModel.ChildLabel)button.Tag;
  423. this.drawToolType = child.drawToolType;
  424. this.UpdateRightSettingUI();
  425. }
  426. /// <summary>
  427. /// 更新右侧设置
  428. /// </summary>
  429. private void UpdateRightSettingUI()
  430. {
  431. this.groupBox2.Controls.Clear();
  432. switch (this.drawToolType)
  433. {
  434. case DrawToolType.DrawTextString: //文本
  435. textControl = new LabelTextControl(this.labelStyleModel.text);
  436. textControl.Location = new Point(10, 15);
  437. this.groupBox2.Controls.Add(textControl);
  438. break;
  439. case DrawToolType.DrawDateMark: //标记-日期
  440. dateMarkControl = new LabelMarkDateControl(this.labelStyleModel.dateMark);
  441. dateMarkControl.Location = new Point(10, 15);
  442. this.groupBox2.Controls.Add(dateMarkControl);
  443. break;
  444. case DrawToolType.DrawTimeMark: //标记-时间
  445. timeMarkControl = new LabelMarkTimeControl(this.labelStyleModel.timeMark);
  446. timeMarkControl.Location = new Point(10, 15);
  447. this.groupBox2.Controls.Add(timeMarkControl);
  448. break;
  449. case DrawToolType.DrawPointMark: //标记-点标记
  450. pointMarkControl = new LabelMarkPointControl(this.labelStyleModel.pointMark);
  451. pointMarkControl.Location = new Point(10, 15);
  452. this.groupBox2.Controls.Add(pointMarkControl);
  453. break;
  454. case DrawToolType.DrawNumberMark: //标记-数字标记
  455. numberMarkControl = new LabelMarkNumberControl(this.labelStyleModel.numberMark);
  456. numberMarkControl.Location = new Point(10, 15);
  457. this.groupBox2.Controls.Add(numberMarkControl);
  458. break;
  459. case DrawToolType.DrawGainNumber: //标记-放大倍数
  460. gainNumberControl = new LabelMarkGainNumberControl(this.labelStyleModel.gainNumber);
  461. gainNumberControl.Location = new Point(10, 15);
  462. this.groupBox2.Controls.Add(gainNumberControl);
  463. break;
  464. case DrawToolType.DrawLine: //直线->直线
  465. straightLineControl = new LabelStraightLineControl(this.labelStyleModel.lineChildLine);
  466. straightLineControl.Location = new Point(10, 15);
  467. this.groupBox2.Controls.Add(straightLineControl);
  468. break;
  469. case DrawToolType.DrawLineSegment: //直线->线段
  470. segmentLineControl = new LabelStraightLineSegmentControl(this.labelStyleModel.lineChildLineSegment);
  471. segmentLineControl.Location = new Point(10, 15);
  472. this.groupBox2.Controls.Add(segmentLineControl);
  473. break;
  474. case DrawToolType.DrawPencil: //曲线->铅笔
  475. pencilControl = new LabelCurvePencilControl(this.labelStyleModel.pencilModel);
  476. pencilControl.Location = new Point(10, 15);
  477. this.groupBox2.Controls.Add(pencilControl);
  478. break;
  479. case DrawToolType.DrawPolygonLine: //曲线->折线
  480. polylineControl = new LabelCurvePolylineControl(this.labelStyleModel.polylineModel);
  481. polylineControl.Location = new Point(10, 15);
  482. this.groupBox2.Controls.Add(polylineControl);
  483. break;
  484. case DrawToolType.DrawCurve: //曲线->曲线
  485. curveControl = new LabelCurveControl(this.labelStyleModel.curveModel);
  486. curveControl.Location = new Point(10, 15);
  487. this.groupBox2.Controls.Add(curveControl);
  488. break;
  489. case DrawToolType.DrawClosedCurve: //曲线->闭合曲线
  490. closedCurveControl = new LabelCurveClosedControl(this.labelStyleModel.closedCurveModel);
  491. closedCurveControl.Location = new Point(10, 15);
  492. this.groupBox2.Controls.Add(closedCurveControl);
  493. break;
  494. case DrawToolType.DrawOneArrowLine: //箭头->单向箭头
  495. oneWayArrowControl = new LabelArrowOneWayControl(this.labelStyleModel.oneWayArrowModel);
  496. oneWayArrowControl.Location = new Point(10, 15);
  497. this.groupBox2.Controls.Add(oneWayArrowControl);
  498. break;
  499. case DrawToolType.DrawTwoArrowLine: //箭头->双向箭头
  500. twoWayArrowControl = new LabelArrowTwoWayControl(this.labelStyleModel.twoWayArrowModel);
  501. twoWayArrowControl.Location = new Point(10, 15);
  502. this.groupBox2.Controls.Add(twoWayArrowControl);
  503. break;
  504. case DrawToolType.DrawCircle: //圆->圆
  505. circleControl = new LabelCircleControl(this.labelStyleModel.circleModel);
  506. circleControl.Location = new Point(10, 15);
  507. this.groupBox2.Controls.Add(circleControl);
  508. break;
  509. case DrawToolType.DrawEllipse: //圆->椭圆
  510. ovalControl = new LabelCircleOvalControl(this.labelStyleModel.ovalModel);
  511. ovalControl.Location = new Point(10, 15);
  512. this.groupBox2.Controls.Add(ovalControl);
  513. break;
  514. case DrawToolType.DrawRectangle: //多边形->矩形
  515. polygonRectangleControl = new LabelPolygonRectangleControl(this.labelStyleModel.polygonRectangle);
  516. polygonRectangleControl.Location = new Point(10, 15);
  517. this.groupBox2.Controls.Add(polygonRectangleControl);
  518. break;
  519. case DrawToolType.DrawPolygon: //多边形->多边形
  520. polygonControl = new LabelPolygonControl(this.labelStyleModel.polygonPolygon);
  521. polygonControl.Location = new Point(10, 15);
  522. this.groupBox2.Controls.Add(polygonControl);
  523. break;
  524. case DrawToolType.DrawRoundRectangle: //多边形->圆角矩形
  525. roundedRectangleControl = new LabelPolygonRoundedControl(this.labelStyleModel.roundedRectangle);
  526. roundedRectangleControl.Location = new Point(10, 15);
  527. this.groupBox2.Controls.Add(roundedRectangleControl);
  528. break;
  529. }
  530. }
  531. /// <summary>
  532. /// 刷新右侧预览图
  533. /// </summary>
  534. private void UpdateRightPreview()
  535. {
  536. }
  537. /// <summary>
  538. /// 删除
  539. /// </summary>
  540. /// <param name="sender"></param>
  541. /// <param name="e"></param>
  542. private void button4_Click(object sender, EventArgs e)
  543. {
  544. if ("Default".Equals(this.comboBox1.Text))
  545. {
  546. MessageBox.Show(PdnResources.GetString("Menu.efaultstylecannotbedelete.Text"), PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
  547. return;
  548. }
  549. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.nfirmthedeleti.Text"), PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  550. if (dr == DialogResult.OK)
  551. {
  552. int newIndex = 0;
  553. int selectIndex = this.comboBox1.SelectedIndex;
  554. int tall = files.Count - 1;
  555. if (selectIndex < tall)
  556. {
  557. newIndex = selectIndex;
  558. }
  559. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Label\\" + this.comboBox1.Text + ".xml";
  560. FileInfo fileInfo = new FileInfo(filePath);
  561. fileInfo.Delete();
  562. InitializeStyleName();
  563. this.comboBox1.SelectedIndex = newIndex;
  564. this.labelStyleModel = XmlSerializeHelper.DESerializer<LabelStyleModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Label\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open));
  565. InitializeData();
  566. }
  567. else if (dr == DialogResult.Cancel)
  568. {
  569. }
  570. }
  571. /// <summary>
  572. /// 另存为 出弹窗
  573. /// </summary>
  574. /// <param name="sender"></param>
  575. /// <param name="e"></param>
  576. private void button3_Click(object sender, EventArgs e)
  577. {
  578. dialog = new CreateNameDialog(this);
  579. dialog.Text = PdnResources.GetString("Menu.Set.Watermarksettings.Newstyle.text");
  580. dialog.StartPosition = FormStartPosition.CenterParent;
  581. dialog.ShowDialog();
  582. }
  583. /// <summary>
  584. /// 另存为弹窗 确定保存
  585. /// </summary>
  586. /// <param name="name"></param>
  587. public override void GetCreateName(string name)
  588. {
  589. string currentcomboBox = this.comboBox1.Text;
  590. this.newName = name;
  591. if (files.Contains(this.newName))
  592. {
  593. MessageBox.Show(PdnResources.GetString("Menu.Stylenamecannotberepeated.text"), PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
  594. return;
  595. }
  596. LabelStyleModel newModel = this.labelStyleModel;
  597. modelSave(newModel);
  598. //另存为
  599. string stageModelXml = XmlSerializeHelper.XmlSerialize<LabelStyleModel>(newModel);
  600. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Label\\" + this.newName + ".xml";
  601. FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create);
  602. InitializeStyleName();
  603. this.comboBox1.Text = currentcomboBox;
  604. dialog.Close();
  605. }
  606. /// <summary>
  607. /// 保存
  608. /// </summary>
  609. /// <param name="sender"></param>
  610. /// <param name="e"></param>
  611. private void button2_Click(object sender, EventArgs e)
  612. {
  613. this.labelStyleModel = modelSave(this.labelStyleModel);
  614. //以下保存xml文件信息
  615. string stageModelXml = XmlSerializeHelper.XmlSerialize<LabelStyleModel>(this.labelStyleModel);
  616. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Label\\" + this.comboBox1.Text + ".xml";
  617. FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create);
  618. this.config.MarkpointWidth = Convert.ToInt32(this.numericUpDown71.Value);
  619. string configModelXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
  620. FileOperationHelper.WriteStringToFile(configModelXml, Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml", FileMode.Create);
  621. MarkPointRect.markPointRectWidth = configModel.MarkpointWidth;
  622. if (this.appWorkspace.DocumentWorkspaces != null)
  623. {
  624. foreach (var item in this.appWorkspace.DocumentWorkspaces)
  625. {
  626. if (item != null && item.GraphicsList != null)
  627. foreach (var graObject in item.GraphicsList.graphicsList)
  628. {
  629. graObject.smallRectangleWidth = this.config.MarkpointWidth;
  630. }
  631. item.Refresh();
  632. }
  633. }
  634. ApplicationSetting();
  635. }
  636. /// <summary>
  637. /// 各个子页面的model保存方法
  638. /// </summary>
  639. private LabelStyleModel modelSave(LabelStyleModel model)
  640. {
  641. switch (this.drawToolType)
  642. {
  643. case DrawToolType.DrawTextString: //文本
  644. model.text = textControl.getNowModel(this.labelStyleModel.text);
  645. break;
  646. case DrawToolType.DrawDateMark: //标记-日期
  647. model.dateMark = dateMarkControl.getNowModel(this.labelStyleModel.dateMark);
  648. break;
  649. case DrawToolType.DrawTimeMark: //标记-时间
  650. model.timeMark = timeMarkControl.getNowModel(this.labelStyleModel.timeMark);
  651. break;
  652. case DrawToolType.DrawPointMark: //标记-点标记
  653. model.pointMark = pointMarkControl.getNowModel(this.labelStyleModel.pointMark);
  654. break;
  655. case DrawToolType.DrawNumberMark: //标记-数字标记
  656. model.numberMark = numberMarkControl.getNowModel(this.labelStyleModel.numberMark);
  657. break;
  658. case DrawToolType.DrawGainNumber: //标记-放大倍数
  659. model.gainNumber = gainNumberControl.getNowModel(this.labelStyleModel.gainNumber);
  660. break;
  661. case DrawToolType.DrawLine: //直线->直线
  662. model.lineChildLine = straightLineControl.getNowModel(this.labelStyleModel.lineChildLine);
  663. break;
  664. case DrawToolType.DrawLineSegment: //直线->线段
  665. model.lineChildLineSegment = segmentLineControl.getNowModel(this.labelStyleModel.lineChildLineSegment);
  666. break;
  667. case DrawToolType.DrawPencil: //曲线->铅笔
  668. model.pencilModel = pencilControl.getNowModel(this.labelStyleModel.pencilModel);
  669. break;
  670. case DrawToolType.DrawPolygonLine: //曲线->折线
  671. model.polylineModel = polylineControl.getNowModel(this.labelStyleModel.polylineModel);
  672. break;
  673. case DrawToolType.DrawCurve: //曲线->曲线
  674. model.curveModel = curveControl.getNowModel(this.labelStyleModel.curveModel);
  675. break;
  676. case DrawToolType.DrawClosedCurve: //曲线->闭合曲线
  677. model.closedCurveModel = closedCurveControl.getNowModel(this.labelStyleModel.closedCurveModel);
  678. break;
  679. case DrawToolType.DrawOneArrowLine: //箭头->单向箭头
  680. model.oneWayArrowModel = oneWayArrowControl.getNowModel(this.labelStyleModel.oneWayArrowModel);
  681. break;
  682. case DrawToolType.DrawTwoArrowLine: //箭头->双向箭头
  683. model.twoWayArrowModel = twoWayArrowControl.getNowModel(this.labelStyleModel.twoWayArrowModel);
  684. break;
  685. case DrawToolType.DrawCircle: //圆->圆
  686. model.circleModel = circleControl.getNowModel(this.labelStyleModel.circleModel);
  687. break;
  688. case DrawToolType.DrawEllipse: //圆->椭圆
  689. model.ovalModel = ovalControl.getNowModel(this.labelStyleModel.ovalModel);
  690. break;
  691. case DrawToolType.DrawRectangle: //多边形->矩形
  692. model.polygonRectangle = polygonRectangleControl.getNowModel(this.labelStyleModel.polygonRectangle);
  693. break;
  694. case DrawToolType.DrawPolygon: //多边形->多边形
  695. model.polygonPolygon = polygonControl.getNowModel(this.labelStyleModel.polygonPolygon);
  696. break;
  697. case DrawToolType.DrawRoundRectangle: //多边形->圆角矩形
  698. model.roundedRectangle = roundedRectangleControl.getNowModel(this.labelStyleModel.roundedRectangle);
  699. break;
  700. }
  701. return model;
  702. }
  703. /// <summary>
  704. /// 应用
  705. /// </summary>
  706. /// <param name="sender"></param>
  707. /// <param name="e"></param>
  708. private void ApplicationSetting()
  709. {
  710. //修改缓存中的样式数据
  711. Startup.instance.labelStyleModel = this.labelStyleModel;
  712. //修改主配置文件中的值
  713. configModel.LabelStyle = this.comboBox1.Text + ".xml";
  714. //修改主配置文件的xml
  715. string configModelXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(this.configModel);
  716. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  717. FileOperationHelper.WriteStringToFile(configModelXml, filePath, FileMode.Create);
  718. MessageBox.Show(PdnResources.GetString("Menu.Successfullysaved.text"));
  719. }
  720. /// <summary>
  721. /// 应用全部
  722. /// </summary>
  723. /// <param name="sender"></param>
  724. /// <param name="e"></param>
  725. private void button5_Click(object sender, EventArgs e)
  726. {
  727. switch (this.drawToolType)
  728. {
  729. case DrawToolType.DrawTextString: //文本
  730. this.labelStyleModel.text = textControl.getNowModel(this.labelStyleModel.text);
  731. break;
  732. case DrawToolType.DrawDateMark: //标记-日期
  733. this.labelStyleModel = dateMarkControl.ApplyAll(this.labelStyleModel);
  734. break;
  735. case DrawToolType.DrawTimeMark: //标记-时间
  736. this.labelStyleModel = timeMarkControl.ApplyAll(this.labelStyleModel);
  737. break;
  738. case DrawToolType.DrawNumberMark: //标记-数字标记
  739. this.labelStyleModel = numberMarkControl.ApplyAll(this.labelStyleModel);
  740. break;
  741. case DrawToolType.DrawGainNumber: //标记-放大倍数
  742. this.labelStyleModel = gainNumberControl.ApplyAll(this.labelStyleModel);
  743. break;
  744. case DrawToolType.DrawLine: //直线->直线
  745. this.labelStyleModel = straightLineControl.ApplyAll(this.labelStyleModel);
  746. break;
  747. case DrawToolType.DrawLineSegment: //直线->线段
  748. this.labelStyleModel = segmentLineControl.ApplyAll(this.labelStyleModel);
  749. break;
  750. case DrawToolType.DrawPencil: //曲线->铅笔
  751. this.labelStyleModel = pencilControl.ApplyAll(this.labelStyleModel);
  752. break;
  753. case DrawToolType.DrawPolygonLine: //曲线->折线
  754. this.labelStyleModel = polylineControl.ApplyAll(this.labelStyleModel);
  755. break;
  756. case DrawToolType.DrawCurve: //曲线->曲线
  757. this.labelStyleModel = curveControl.ApplyAll(this.labelStyleModel);
  758. break;
  759. case DrawToolType.DrawClosedCurve: //曲线->闭合曲线
  760. this.labelStyleModel = closedCurveControl.ApplyAll(this.labelStyleModel);
  761. break;
  762. case DrawToolType.DrawOneArrowLine: //箭头->单向箭头
  763. this.labelStyleModel = oneWayArrowControl.ApplyAll(this.labelStyleModel);
  764. break;
  765. case DrawToolType.DrawTwoArrowLine: //箭头->双向箭头
  766. this.labelStyleModel = twoWayArrowControl.ApplyAll(this.labelStyleModel);
  767. break;
  768. case DrawToolType.DrawCircle: //圆->圆
  769. this.labelStyleModel = circleControl.ApplyAll(this.labelStyleModel);
  770. break;
  771. case DrawToolType.DrawEllipse: //圆->椭圆
  772. this.labelStyleModel = ovalControl.ApplyAll(this.labelStyleModel);
  773. break;
  774. case DrawToolType.DrawRectangle: //多边形->矩形
  775. this.labelStyleModel = polygonRectangleControl.ApplyAll(this.labelStyleModel);
  776. break;
  777. case DrawToolType.DrawPolygon: //多边形->多边形
  778. this.labelStyleModel = polygonControl.ApplyAll(this.labelStyleModel);
  779. break;
  780. case DrawToolType.DrawRoundRectangle: //多边形->圆角矩形
  781. this.labelStyleModel = roundedRectangleControl.ApplyAll(this.labelStyleModel);
  782. break;
  783. }
  784. //以下保存xml文件信息
  785. string stageModelXml = XmlSerializeHelper.XmlSerialize<LabelStyleModel>(this.labelStyleModel);
  786. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Label\\" + this.comboBox1.Text + ".xml";
  787. FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create);
  788. ApplicationSetting();
  789. }
  790. }
  791. }