HandSaveControl.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11. using PaintDotNet.Base.SettingModel;
  12. using PaintDotNet.Base.CommTool;
  13. namespace PaintDotNet.File.BatchSaveComponet
  14. {
  15. internal class HandSaveControl : UserControl
  16. {
  17. private AppWorkspace appWorkspace;
  18. public List<TextBox> textBoxes = new List<TextBox>();
  19. public List<ComboBox> comboBoxes = new List<ComboBox>();
  20. private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
  21. public System.Windows.Forms.CheckBox checkBox5;
  22. public System.Windows.Forms.CheckBox checkBox4;
  23. public System.Windows.Forms.CheckBox checkBox3;
  24. public System.Windows.Forms.CheckBox checkBox2;
  25. public System.Windows.Forms.CheckBox checkBox6;
  26. public NumericUpDown numericUpDown1;
  27. private Label label1;
  28. public System.Windows.Forms.CheckBox checkBox1;
  29. /// <summary>
  30. /// 文件 - 批量保存自动配置
  31. /// </summary>
  32. public BatchSaveAutoModel batchSaveAutoModel;
  33. public HandSaveControl(AppWorkspace appWorkspace)
  34. {
  35. this.appWorkspace = appWorkspace;
  36. textBoxes.Clear();
  37. comboBoxes.Clear();
  38. InitializeComponent();
  39. InitializeLanguageText();
  40. InitializeData();
  41. }
  42. private void InitializeLanguageText()
  43. {
  44. this.checkBox5.Text = PdnResources.GetString("Menu.Compressionratio.text");
  45. this.checkBox4.Text = PdnResources.GetString("Menu.Annotationandmddedintheimage.text");
  46. this.checkBox3.Text = PdnResources.GetString("Menu.Savegriddata.text");
  47. this.checkBox2.Text = PdnResources.GetString("Menu.Closeimageaftersaving.text");
  48. this.checkBox1.Text = PdnResources.GetString("Menu.Generateconfigurationfile.text");
  49. }
  50. /// <summary>
  51. /// 设计器支持所需的方法 - 不要修改
  52. /// 使用代码编辑器修改此方法的内容。
  53. /// </summary>
  54. private void InitializeComponent()
  55. {
  56. this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
  57. this.checkBox5 = new System.Windows.Forms.CheckBox();
  58. this.checkBox4 = new System.Windows.Forms.CheckBox();
  59. this.checkBox3 = new System.Windows.Forms.CheckBox();
  60. this.checkBox2 = new System.Windows.Forms.CheckBox();
  61. this.checkBox1 = new System.Windows.Forms.CheckBox();
  62. this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
  63. this.label1 = new System.Windows.Forms.Label();
  64. this.checkBox6 = new System.Windows.Forms.CheckBox();
  65. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
  66. this.SuspendLayout();
  67. //
  68. // flowLayoutPanel1
  69. //
  70. this.flowLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  71. | System.Windows.Forms.AnchorStyles.Right)));
  72. this.flowLayoutPanel1.AutoScroll = true;
  73. this.flowLayoutPanel1.BackColor = System.Drawing.Color.White;
  74. this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0);
  75. this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(0);
  76. this.flowLayoutPanel1.Name = "flowLayoutPanel1";
  77. this.flowLayoutPanel1.Size = new System.Drawing.Size(546, 258);
  78. this.flowLayoutPanel1.TabIndex = 16;
  79. //
  80. // checkBox5
  81. //
  82. this.checkBox5.AutoSize = true;
  83. this.checkBox5.Location = new System.Drawing.Point(1, 308);
  84. this.checkBox5.Name = "checkBox5";
  85. this.checkBox5.Size = new System.Drawing.Size(72, 16);
  86. this.checkBox5.TabIndex = 15;
  87. this.checkBox5.Text = "压缩比例";
  88. this.checkBox5.UseVisualStyleBackColor = true;
  89. //
  90. // checkBox4
  91. //
  92. this.checkBox4.AutoSize = true;
  93. this.checkBox4.Location = new System.Drawing.Point(230, 284);
  94. this.checkBox4.Name = "checkBox4";
  95. this.checkBox4.Size = new System.Drawing.Size(156, 16);
  96. this.checkBox4.TabIndex = 14;
  97. this.checkBox4.Text = "标注和测量信息嵌入图像";
  98. this.checkBox4.UseVisualStyleBackColor = true;
  99. //
  100. // checkBox3
  101. //
  102. this.checkBox3.AutoSize = true;
  103. this.checkBox3.Location = new System.Drawing.Point(1, 284);
  104. this.checkBox3.Name = "checkBox3";
  105. this.checkBox3.Size = new System.Drawing.Size(96, 16);
  106. this.checkBox3.TabIndex = 13;
  107. this.checkBox3.Text = "保存网格数据";
  108. this.checkBox3.UseVisualStyleBackColor = true;
  109. //
  110. // checkBox2
  111. //
  112. this.checkBox2.AutoSize = true;
  113. this.checkBox2.Location = new System.Drawing.Point(230, 261);
  114. this.checkBox2.Name = "checkBox2";
  115. this.checkBox2.Size = new System.Drawing.Size(108, 16);
  116. this.checkBox2.TabIndex = 12;
  117. this.checkBox2.Text = "保存后关闭图像";
  118. this.checkBox2.UseVisualStyleBackColor = true;
  119. //
  120. // checkBox1
  121. //
  122. this.checkBox1.AutoSize = true;
  123. this.checkBox1.Location = new System.Drawing.Point(1, 261);
  124. this.checkBox1.Name = "checkBox1";
  125. this.checkBox1.Size = new System.Drawing.Size(96, 16);
  126. this.checkBox1.TabIndex = 11;
  127. this.checkBox1.Text = "生成配置文件";
  128. this.checkBox1.UseVisualStyleBackColor = true;
  129. //
  130. // numericUpDown1
  131. //
  132. this.numericUpDown1.Location = new System.Drawing.Point(75, 306);
  133. this.numericUpDown1.Name = "numericUpDown1";
  134. this.numericUpDown1.Size = new System.Drawing.Size(36, 21);
  135. this.numericUpDown1.TabIndex = 17;
  136. //
  137. // label1
  138. //
  139. this.label1.AutoSize = true;
  140. this.label1.Location = new System.Drawing.Point(118, 310);
  141. this.label1.Name = "label1";
  142. this.label1.Size = new System.Drawing.Size(11, 12);
  143. this.label1.TabIndex = 18;
  144. this.label1.Text = "%";
  145. //
  146. // checkBox6
  147. //
  148. this.checkBox6.AutoSize = true;
  149. this.checkBox6.Location = new System.Drawing.Point(230, 307);
  150. this.checkBox6.Name = "checkBox6";
  151. this.checkBox6.Size = new System.Drawing.Size(108, 16);
  152. this.checkBox6.TabIndex = 19;
  153. this.checkBox6.Text = "相信息嵌入图像";
  154. this.checkBox6.UseVisualStyleBackColor = true;
  155. //
  156. // HandSaveControl
  157. //
  158. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  159. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  160. this.Controls.Add(this.checkBox6);
  161. this.Controls.Add(this.label1);
  162. this.Controls.Add(this.numericUpDown1);
  163. this.Controls.Add(this.flowLayoutPanel1);
  164. this.Controls.Add(this.checkBox5);
  165. this.Controls.Add(this.checkBox4);
  166. this.Controls.Add(this.checkBox3);
  167. this.Controls.Add(this.checkBox2);
  168. this.Controls.Add(this.checkBox1);
  169. this.Margin = new System.Windows.Forms.Padding(0);
  170. this.Name = "HandSaveControl";
  171. this.Size = new System.Drawing.Size(546, 327);
  172. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
  173. this.ResumeLayout(false);
  174. this.PerformLayout();
  175. }
  176. /// <summary>
  177. /// 初始化数据
  178. /// </summary>
  179. private void InitializeData()
  180. {
  181. int sum = 0;
  182. batchSaveAutoModel = XmlSerializeHelper.DESerializer<BatchSaveAutoModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + @"\Config\Default\File\BatchSaveAuto.xml", FileMode.Open));
  183. if (this.appWorkspace.DocumentWorkspaces != null
  184. && this.appWorkspace.DocumentWorkspaces.Length > 0)
  185. {
  186. if (batchSaveAutoModel.Whether)
  187. {
  188. foreach (DocumentWorkspace document in this.appWorkspace.DocumentWorkspaces)
  189. {
  190. PictureBox imageBox = new PictureBox();
  191. imageBox.Size = new Size(28, 28);
  192. imageBox.SizeMode = PictureBoxSizeMode.Zoom;
  193. imageBox.Image = document.CompositionSurface.Thumbnail;//CreateAliasedBitmap()
  194. imageBox.Margin = new Padding(3, 1, 0, 0);
  195. imageBox.Cursor = Cursors.Hand;
  196. imageBox.Tag = document;
  197. imageBox.Click += new EventHandler(Imagebox_Click);
  198. Label label = new Label();
  199. label.Size = new Size(150, 22);
  200. label.Text = document.GetFriendlyName();
  201. label.Margin = new Padding(3, 9, 0, 0);
  202. ComboBox comboBox = new ComboBox();
  203. comboBox.Size = new Size(144, 22);
  204. comboBox.Margin = new Padding(3, 4, 0, 0);
  205. comboBox.DataSource = new BindingSource(InvariantData.fileFormatDictionary, null);
  206. comboBox.Text = batchSaveAutoModel.format;
  207. comboBox.DisplayMember = "Value";
  208. comboBox.ValueMember = "Key";
  209. TextBox textBox = new TextBox();
  210. textBox.Size = new Size(200, 22);
  211. textBox.Text = batchSaveAutoModel.prefix + "_" + batchSaveAutoModel.fileName + "_" + (batchSaveAutoModel.startNum + sum) + "_" + batchSaveAutoModel.suffix;
  212. textBox.Margin = new Padding(3, 4, 0, 0);
  213. textBoxes.Add(textBox);
  214. comboBoxes.Add(comboBox);
  215. FlowLayoutPanel panel = new FlowLayoutPanel();
  216. panel.Size = new Size(545, 30);
  217. panel.Margin = new Padding(0, 0, 0, 0);
  218. panel.BorderStyle = BorderStyle.FixedSingle;
  219. panel.Controls.Add(imageBox);
  220. panel.Controls.Add(label);
  221. panel.Controls.Add(comboBox);
  222. panel.Controls.Add(textBox);
  223. this.flowLayoutPanel1.Controls.Add(panel);
  224. sum++;
  225. }
  226. checkBox1.Checked = batchSaveAutoModel.createConfig;
  227. checkBox2.Checked = batchSaveAutoModel.afterSaveClost;
  228. checkBox3.Checked = batchSaveAutoModel.saveGridLine;
  229. checkBox4.Checked = batchSaveAutoModel.implantLabelAndMeasure;
  230. checkBox5.Checked = batchSaveAutoModel.compress;
  231. numericUpDown1.Value = batchSaveAutoModel.compressRate;
  232. checkBox6.Checked = batchSaveAutoModel.implantPhase;
  233. }
  234. else
  235. {
  236. foreach (DocumentWorkspace document in this.appWorkspace.DocumentWorkspaces)
  237. {
  238. PictureBox imageBox = new PictureBox();
  239. imageBox.Size = new Size(28, 28);
  240. imageBox.SizeMode = PictureBoxSizeMode.Zoom;
  241. imageBox.Image = document.CompositionSurface.Thumbnail;//CreateAliasedBitmap()
  242. imageBox.Margin = new Padding(3, 1, 0, 0);
  243. imageBox.Cursor = Cursors.Hand;
  244. imageBox.Tag = document;
  245. imageBox.Click += new EventHandler(Imagebox_Click);
  246. Label label = new Label();
  247. label.Size = new Size(150, 22);
  248. label.Text = document.GetFriendlyName();
  249. label.Margin = new Padding(3, 9, 0, 0);
  250. ComboBox comboBox = new ComboBox();
  251. comboBox.Size = new Size(144, 22);
  252. comboBox.Margin = new Padding(3, 4, 0, 0);
  253. comboBox.DataSource = new BindingSource(InvariantData.fileFormatDictionary, null);
  254. comboBox.DisplayMember = "Value";
  255. comboBox.ValueMember = "Key";
  256. TextBox textBox = new TextBox();
  257. textBox.Size = new Size(200, 22);
  258. textBox.Text = Path.GetFileNameWithoutExtension(document.GetFriendlyName());
  259. textBox.Margin = new Padding(3, 4, 0, 0);
  260. textBoxes.Add(textBox);
  261. comboBoxes.Add(comboBox);
  262. FlowLayoutPanel panel = new FlowLayoutPanel();
  263. panel.Size = new Size(545, 30);
  264. panel.Margin = new Padding(0, 0, 0, 0);
  265. panel.BorderStyle = BorderStyle.FixedSingle;
  266. panel.Controls.Add(imageBox);
  267. panel.Controls.Add(label);
  268. panel.Controls.Add(comboBox);
  269. panel.Controls.Add(textBox);
  270. this.flowLayoutPanel1.Controls.Add(panel);
  271. }
  272. }
  273. }
  274. }
  275. private void Imagebox_Click(object sender, EventArgs e)
  276. {
  277. PictureBox imagebox = (PictureBox)sender;
  278. DocumentWorkspace document = (DocumentWorkspace)imagebox.Tag;
  279. if (imagebox.Image != null)
  280. {
  281. using (ImagePreviewDialog imagePreviewDialog = new ImagePreviewDialog(document.CompositionSurface.CreateAliasedBitmap(), this.appWorkspace))
  282. {
  283. if (!string.IsNullOrEmpty(document.GetFriendlyName()))
  284. {
  285. imagePreviewDialog.Text = document.GetFriendlyName();
  286. }
  287. imagePreviewDialog.StartPosition = FormStartPosition.CenterScreen;
  288. imagePreviewDialog.ShowDialog();
  289. }
  290. }
  291. }
  292. }
  293. }