1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095 |
- using PaintDotNet.Actions;
- using PaintDotNet.Annotation;
- using PaintDotNet.Annotation.Enum;
- using PaintDotNet.Annotation.Label;
- using PaintDotNet.Base;
- using PaintDotNet.Base.CommTool;
- using PaintDotNet.Base.SettingModel;
- using PaintDotNet.File;
- using PaintDotNet.Setting;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Windows.Forms;
- using static PaintDotNet.Base.SettingModel.CustomTxtModel;
- namespace PaintDotNet.Instrument
- {
- /// <summary>
- /// 图像索引
- /// </summary>
- internal class ImageIndexDialog : FloatingToolForm
- {
- public static ImageIndexDialog imageIndexDialog;
- private PictureBox pictureBox1;
- private Panel panel1;
- public Label lblPreview;
- #region 控件
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.IContainer components = null;
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
- #region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.button10 = new System.Windows.Forms.Button();
- this.btn_Hide = new System.Windows.Forms.Button();
- this.listView1 = new System.Windows.Forms.ListView();
- this.imageList1 = new System.Windows.Forms.ImageList(this.components);
- this.button7 = new System.Windows.Forms.Button();
- this.button8 = new System.Windows.Forms.Button();
- this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
- this.groupBox2 = new System.Windows.Forms.GroupBox();
- this.lblPreview = new System.Windows.Forms.Label();
- this.btn_DelT3 = new System.Windows.Forms.Button();
- this.btn_DelT2 = new System.Windows.Forms.Button();
- this.btn_DelT1 = new System.Windows.Forms.Button();
- this.btn_AddT3 = new System.Windows.Forms.Button();
- this.btn_AddT2 = new System.Windows.Forms.Button();
- this.btn_AddT1 = new System.Windows.Forms.Button();
- this.label3 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.label1 = new System.Windows.Forms.Label();
- this.comboBox_T3 = new System.Windows.Forms.ComboBox();
- this.comboBox_T2 = new System.Windows.Forms.ComboBox();
- this.comboBox_T1 = new System.Windows.Forms.ComboBox();
- this.btn_SetUp = new System.Windows.Forms.Button();
- this.comboBox_Name = new System.Windows.Forms.ComboBox();
- this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
- this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
- this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem();
- this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem();
- this.toolStripMenuItem4 = new System.Windows.Forms.ToolStripMenuItem();
- this.splitContainer1 = new System.Windows.Forms.SplitContainer();
- this.pictureBox1 = new System.Windows.Forms.PictureBox();
- this.panel1 = new System.Windows.Forms.Panel();
- this.groupBox1.SuspendLayout();
- this.groupBox2.SuspendLayout();
- this.contextMenuStrip1.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
- this.splitContainer1.Panel1.SuspendLayout();
- this.splitContainer1.Panel2.SuspendLayout();
- this.splitContainer1.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
- this.panel1.SuspendLayout();
- this.SuspendLayout();
- //
- // groupBox1
- //
- this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox1.Controls.Add(this.button10);
- this.groupBox1.Controls.Add(this.btn_Hide);
- this.groupBox1.Controls.Add(this.listView1);
- this.groupBox1.Controls.Add(this.button7);
- this.groupBox1.Controls.Add(this.button8);
- this.groupBox1.Location = new System.Drawing.Point(5, 160);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(178, 367);
- this.groupBox1.TabIndex = 1;
- this.groupBox1.TabStop = false;
- this.groupBox1.Text = "索引列表";
- //
- // button10
- //
- this.button10.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.button10.Location = new System.Drawing.Point(116, 338);
- this.button10.Name = "button10";
- this.button10.Size = new System.Drawing.Size(25, 25);
- this.button10.TabIndex = 19;
- this.button10.UseVisualStyleBackColor = true;
- this.button10.Click += new System.EventHandler(this.button10_Click);
- //
- // btn_Hide
- //
- this.btn_Hide.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.btn_Hide.Location = new System.Drawing.Point(147, 338);
- this.btn_Hide.Name = "btn_Hide";
- this.btn_Hide.Size = new System.Drawing.Size(25, 25);
- this.btn_Hide.TabIndex = 18;
- this.btn_Hide.Text = ">>";
- this.btn_Hide.UseVisualStyleBackColor = true;
- this.btn_Hide.Click += new System.EventHandler(this.btn_Hide_Click);
- //
- // listView1
- //
- this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.listView1.HideSelection = false;
- this.listView1.LargeImageList = this.imageList1;
- this.listView1.Location = new System.Drawing.Point(7, 20);
- this.listView1.MultiSelect = false;
- this.listView1.Name = "listView1";
- this.listView1.ShowItemToolTips = true;
- this.listView1.Size = new System.Drawing.Size(165, 316);
- this.listView1.TabIndex = 0;
- this.listView1.UseCompatibleStateImageBehavior = false;
- this.listView1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseClick);
- this.listView1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseDoubleClick);
- //
- // imageList1
- //
- this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
- this.imageList1.ImageSize = new System.Drawing.Size(256, 256);
- this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
- //
- // button7
- //
- this.button7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.button7.Location = new System.Drawing.Point(54, 338);
- this.button7.Name = "button7";
- this.button7.Size = new System.Drawing.Size(25, 25);
- this.button7.TabIndex = 16;
- this.button7.UseVisualStyleBackColor = true;
- this.button7.Click += new System.EventHandler(this.button7_Click);
- //
- // button8
- //
- this.button8.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.button8.Location = new System.Drawing.Point(85, 338);
- this.button8.Name = "button8";
- this.button8.Size = new System.Drawing.Size(25, 25);
- this.button8.TabIndex = 15;
- this.button8.UseVisualStyleBackColor = true;
- this.button8.Click += new System.EventHandler(this.button8_Click);
- //
- // groupBox2
- //
- this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox2.Controls.Add(this.lblPreview);
- this.groupBox2.Controls.Add(this.btn_DelT3);
- this.groupBox2.Controls.Add(this.btn_DelT2);
- this.groupBox2.Controls.Add(this.btn_DelT1);
- this.groupBox2.Controls.Add(this.btn_AddT3);
- this.groupBox2.Controls.Add(this.btn_AddT2);
- this.groupBox2.Controls.Add(this.btn_AddT1);
- this.groupBox2.Controls.Add(this.label3);
- this.groupBox2.Controls.Add(this.label2);
- this.groupBox2.Controls.Add(this.label1);
- this.groupBox2.Controls.Add(this.comboBox_T3);
- this.groupBox2.Controls.Add(this.comboBox_T2);
- this.groupBox2.Controls.Add(this.comboBox_T1);
- this.groupBox2.Controls.Add(this.btn_SetUp);
- this.groupBox2.Controls.Add(this.comboBox_Name);
- this.groupBox2.Location = new System.Drawing.Point(5, 5);
- this.groupBox2.MaximumSize = new System.Drawing.Size(366, 149);
- this.groupBox2.Name = "groupBox2";
- this.groupBox2.Size = new System.Drawing.Size(178, 149);
- this.groupBox2.TabIndex = 25;
- this.groupBox2.TabStop = false;
- this.groupBox2.Text = "命名规则";
- //
- // lblPreview
- //
- this.lblPreview.AutoEllipsis = true;
- this.lblPreview.ForeColor = System.Drawing.SystemColors.ControlDarkDark;
- this.lblPreview.Location = new System.Drawing.Point(6, 44);
- this.lblPreview.Name = "lblPreview";
- this.lblPreview.Size = new System.Drawing.Size(166, 12);
- this.lblPreview.TabIndex = 29;
- this.lblPreview.Text = "lblPreview";
- //
- // btn_DelT3
- //
- this.btn_DelT3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.btn_DelT3.Location = new System.Drawing.Point(147, 118);
- this.btn_DelT3.Name = "btn_DelT3";
- this.btn_DelT3.Size = new System.Drawing.Size(25, 25);
- this.btn_DelT3.TabIndex = 28;
- this.btn_DelT3.Text = "-";
- this.btn_DelT3.UseVisualStyleBackColor = true;
- this.btn_DelT3.Click += new System.EventHandler(this.btn_DelT3_Click);
- //
- // btn_DelT2
- //
- this.btn_DelT2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.btn_DelT2.Location = new System.Drawing.Point(147, 93);
- this.btn_DelT2.Name = "btn_DelT2";
- this.btn_DelT2.Size = new System.Drawing.Size(25, 25);
- this.btn_DelT2.TabIndex = 27;
- this.btn_DelT2.Text = "-";
- this.btn_DelT2.UseVisualStyleBackColor = true;
- this.btn_DelT2.Click += new System.EventHandler(this.btn_DelT2_Click);
- //
- // btn_DelT1
- //
- this.btn_DelT1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.btn_DelT1.Location = new System.Drawing.Point(147, 68);
- this.btn_DelT1.Name = "btn_DelT1";
- this.btn_DelT1.Size = new System.Drawing.Size(25, 25);
- this.btn_DelT1.TabIndex = 26;
- this.btn_DelT1.Text = "-";
- this.btn_DelT1.UseVisualStyleBackColor = true;
- this.btn_DelT1.Click += new System.EventHandler(this.btn_DelT1_Click);
- //
- // btn_AddT3
- //
- this.btn_AddT3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.btn_AddT3.Location = new System.Drawing.Point(123, 118);
- this.btn_AddT3.Name = "btn_AddT3";
- this.btn_AddT3.Size = new System.Drawing.Size(25, 25);
- this.btn_AddT3.TabIndex = 25;
- this.btn_AddT3.Text = "+";
- this.btn_AddT3.UseVisualStyleBackColor = true;
- this.btn_AddT3.Click += new System.EventHandler(this.btn_AddT3_Click);
- //
- // btn_AddT2
- //
- this.btn_AddT2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.btn_AddT2.Location = new System.Drawing.Point(123, 93);
- this.btn_AddT2.Name = "btn_AddT2";
- this.btn_AddT2.Size = new System.Drawing.Size(25, 25);
- this.btn_AddT2.TabIndex = 24;
- this.btn_AddT2.Text = "+";
- this.btn_AddT2.UseVisualStyleBackColor = true;
- this.btn_AddT2.Click += new System.EventHandler(this.btn_AddT2_Click);
- //
- // btn_AddT1
- //
- this.btn_AddT1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.btn_AddT1.Location = new System.Drawing.Point(123, 68);
- this.btn_AddT1.Name = "btn_AddT1";
- this.btn_AddT1.Size = new System.Drawing.Size(25, 25);
- this.btn_AddT1.TabIndex = 23;
- this.btn_AddT1.Text = "+";
- this.btn_AddT1.UseVisualStyleBackColor = true;
- this.btn_AddT1.Click += new System.EventHandler(this.btn_AddT1_Click);
- //
- // label3
- //
- this.label3.AutoSize = true;
- this.label3.Location = new System.Drawing.Point(6, 123);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(23, 12);
- this.label3.TabIndex = 22;
- this.label3.Text = "T3:";
- //
- // label2
- //
- this.label2.AutoSize = true;
- this.label2.Location = new System.Drawing.Point(6, 99);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(23, 12);
- this.label2.TabIndex = 21;
- this.label2.Text = "T2:";
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.Location = new System.Drawing.Point(6, 74);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(23, 12);
- this.label1.TabIndex = 20;
- this.label1.Text = "T1:";
- //
- // comboBox_T3
- //
- this.comboBox_T3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
- this.comboBox_T3.FormattingEnabled = true;
- this.comboBox_T3.Location = new System.Drawing.Point(35, 120);
- this.comboBox_T3.Name = "comboBox_T3";
- this.comboBox_T3.Size = new System.Drawing.Size(82, 20);
- this.comboBox_T3.TabIndex = 19;
- this.comboBox_T3.TextUpdate += new System.EventHandler(this.comboBox_T3_TextUpdate);
- //
- // comboBox_T2
- //
- this.comboBox_T2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
- this.comboBox_T2.FormattingEnabled = true;
- this.comboBox_T2.Location = new System.Drawing.Point(35, 96);
- this.comboBox_T2.Name = "comboBox_T2";
- this.comboBox_T2.Size = new System.Drawing.Size(82, 20);
- this.comboBox_T2.TabIndex = 18;
- this.comboBox_T2.TextUpdate += new System.EventHandler(this.comboBox_T2_TextUpdate);
- //
- // comboBox_T1
- //
- this.comboBox_T1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
- this.comboBox_T1.FormattingEnabled = true;
- this.comboBox_T1.Location = new System.Drawing.Point(35, 71);
- this.comboBox_T1.Name = "comboBox_T1";
- this.comboBox_T1.Size = new System.Drawing.Size(82, 20);
- this.comboBox_T1.TabIndex = 17;
- this.comboBox_T1.TextUpdate += new System.EventHandler(this.comboBox_T1_TextUpdate);
- //
- // btn_SetUp
- //
- this.btn_SetUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.btn_SetUp.Location = new System.Drawing.Point(147, 16);
- this.btn_SetUp.Name = "btn_SetUp";
- this.btn_SetUp.Size = new System.Drawing.Size(25, 25);
- this.btn_SetUp.TabIndex = 16;
- this.btn_SetUp.Text = "*";
- this.btn_SetUp.UseVisualStyleBackColor = true;
- this.btn_SetUp.Click += new System.EventHandler(this.btn_SetUp_Click);
- //
- // comboBox_Name
- //
- this.comboBox_Name.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
- this.comboBox_Name.FormattingEnabled = true;
- this.comboBox_Name.Location = new System.Drawing.Point(7, 18);
- this.comboBox_Name.Name = "comboBox_Name";
- this.comboBox_Name.Size = new System.Drawing.Size(128, 20);
- this.comboBox_Name.TabIndex = 0;
- //
- // contextMenuStrip1
- //
- this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.toolStripMenuItem1,
- this.toolStripMenuItem2,
- this.toolStripMenuItem3,
- this.toolStripMenuItem4});
- this.contextMenuStrip1.Name = "contextMenuStrip1";
- this.contextMenuStrip1.Size = new System.Drawing.Size(125, 92);
- //
- // toolStripMenuItem1
- //
- this.toolStripMenuItem1.Name = "toolStripMenuItem1";
- this.toolStripMenuItem1.Size = new System.Drawing.Size(124, 22);
- this.toolStripMenuItem1.Text = "保存";
- this.toolStripMenuItem1.Click += new System.EventHandler(this.toolStripMenuItem1_Click);
- //
- // toolStripMenuItem2
- //
- this.toolStripMenuItem2.Name = "toolStripMenuItem2";
- this.toolStripMenuItem2.Size = new System.Drawing.Size(124, 22);
- this.toolStripMenuItem2.Text = "另存";
- this.toolStripMenuItem2.Click += new System.EventHandler(this.toolStripMenuItem2_Click);
- //
- // toolStripMenuItem3
- //
- this.toolStripMenuItem3.Name = "toolStripMenuItem3";
- this.toolStripMenuItem3.Size = new System.Drawing.Size(124, 22);
- this.toolStripMenuItem3.Text = "强制关闭";
- this.toolStripMenuItem3.Click += new System.EventHandler(this.toolStripMenuItem3_Click);
- //
- // toolStripMenuItem4
- //
- this.toolStripMenuItem4.Name = "toolStripMenuItem4";
- this.toolStripMenuItem4.Size = new System.Drawing.Size(124, 22);
- this.toolStripMenuItem4.Text = "复制";
- this.toolStripMenuItem4.Click += new System.EventHandler(this.toolStripMenuItem4_Click);
- //
- // splitContainer1
- //
- this.splitContainer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
- this.splitContainer1.Location = new System.Drawing.Point(0, 0);
- this.splitContainer1.Name = "splitContainer1";
- //
- // splitContainer1.Panel1
- //
- this.splitContainer1.Panel1.Controls.Add(this.groupBox2);
- this.splitContainer1.Panel1.Controls.Add(this.groupBox1);
- this.splitContainer1.Panel1.SizeChanged += new System.EventHandler(this.splitContainer1_Panel1_SizeChanged);
- this.splitContainer1.Panel1MinSize = 188;
- //
- // splitContainer1.Panel2
- //
- this.splitContainer1.Panel2.Controls.Add(this.pictureBox1);
- this.splitContainer1.Panel2MinSize = 0;
- this.splitContainer1.Size = new System.Drawing.Size(810, 532);
- this.splitContainer1.SplitterDistance = 188;
- this.splitContainer1.TabIndex = 26;
- //
- // pictureBox1
- //
- this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.pictureBox1.Location = new System.Drawing.Point(3, 3);
- this.pictureBox1.Name = "pictureBox1";
- this.pictureBox1.Size = new System.Drawing.Size(610, 524);
- this.pictureBox1.TabIndex = 2;
- this.pictureBox1.TabStop = false;
- this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
- this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
- this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);
- //
- // panel1
- //
- this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)));
- this.panel1.Controls.Add(this.splitContainer1);
- this.panel1.Location = new System.Drawing.Point(4, 5);
- this.panel1.Name = "panel1";
- this.panel1.Size = new System.Drawing.Size(810, 532);
- this.panel1.TabIndex = 27;
- this.panel1.SizeChanged += new System.EventHandler(this.panel1_SizeChanged);
- //
- // ImageIndexDialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(818, 542);
- this.Controls.Add(this.panel1);
- this.MinimumSize = new System.Drawing.Size(212, 489);
- this.Name = "ImageIndexDialog";
- this.Text = "图像索引";
- this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ImageIndexDialog_FormClosing);
- this.SizeChanged += new System.EventHandler(this.ImageIndexDialog_SizeChanged);
- this.Resize += new System.EventHandler(this.ImageIndexDialog_Resize);
- this.Controls.SetChildIndex(this.panel1, 0);
- this.groupBox1.ResumeLayout(false);
- this.groupBox2.ResumeLayout(false);
- this.groupBox2.PerformLayout();
- this.contextMenuStrip1.ResumeLayout(false);
- this.splitContainer1.Panel1.ResumeLayout(false);
- this.splitContainer1.Panel2.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
- this.splitContainer1.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
- this.panel1.ResumeLayout(false);
- this.ResumeLayout(false);
- }
- #endregion
- private System.Windows.Forms.GroupBox groupBox1;
- public System.Windows.Forms.ListView listView1;
- private System.Windows.Forms.ImageList imageList1;
- #endregion
- private AppWorkspace AppWorkspace;
- private ConfigModel config = Startup.instance.configModel;
- /// <summary>
- /// 当前document的图片
- /// </summary>
- private Bitmap imageMat;
- /// <summary>
- /// picturebox中图片对应矩形
- /// </summary>
- private Rectangle imageRect;
- /// <summary>
- /// picturebox中红框对应矩形
- /// </summary>
- private Rectangle zoomRect;
- /// <summary>
- /// picturebox中红框的最小宽度(原图放大3200%)
- /// </summary>
- private int minRectWidth;
- /// <summary>
- /// picturebox中红框的最小高度(原图放大3200%)
- /// </summary>
- private int minRectHeight;
- /// <summary>
- /// 当前document窗口与其缩放后的图片宽度比例
- /// </summary>
- private double widthRatio;
- /// <summary>
- /// 当前document窗口与其缩放后的图片高度比例
- /// </summary>
- private double heightRatio;
- /// <summary>
- /// picturebox中缩略图与document中缩放后图片的宽度比例(计算滚动条使用)
- /// </summary>
- private double scRatioWidth;
- /// <summary>
- /// picturebox中缩略图与document中缩放后图片的高度比例(计算滚动条使用)
- /// </summary
- private double scRatioHeight;
- /// <summary>
- /// 是否重置picturebox中的矩形尺寸
- /// </summary>
- private bool isFirst = true;
- /// <summary>
- /// 是否为拖动picturebox中的矩形框
- /// </summary>
- private bool isMoved = false;
- /// <summary>
- /// 是否为修改picturebox中的矩形框大小
- /// </summary>
- private bool isResized = false;
- /// <summary>
- /// 1-T1,2-T2,3-T3
- /// </summary>
- private int CurrentLocation = -1;
- /// <summary>
- /// 折叠状态,拉伸窗体,最小宽度等于最大宽度时延展宽度
- /// </summary>
- public int extendWidth = 200;
- /// <summary>
- /// 折叠后,最小宽度与最大宽度相等时,固定展开宽度值
- /// </summary>
- public int fixedWidth = 834;
- private Button button8;
- private Button button7;
- private ToolTip toolTip1;
- private Button btn_Hide;
- private GroupBox groupBox2;
- private Button btn_DelT3;
- private Button btn_DelT2;
- private Button btn_DelT1;
- private Button btn_AddT3;
- private Button btn_AddT2;
- private Button btn_AddT1;
- private Label label3;
- private Label label2;
- private Label label1;
- public ComboBox comboBox_T3;
- public ComboBox comboBox_T2;
- public ComboBox comboBox_T1;
- private Button btn_SetUp;
- private ComboBox comboBox_Name;
- private Button button10;
- private ContextMenuStrip contextMenuStrip1;
- private ToolStripMenuItem toolStripMenuItem1;
- private ToolStripMenuItem toolStripMenuItem2;
- private ToolStripMenuItem toolStripMenuItem3;
- private ToolStripMenuItem toolStripMenuItem4;
- public SplitContainer splitContainer1;
- /// <summary>
- /// 辅助计算偏移量
- /// </summary>
- private Point lastPoint = new Point(0, 0);
- public int fromMaxSize = 0;//折叠前窗体宽度
- public int fromMinSize = 0;//折叠后窗体宽度
- public ImageIndexDialog(AppWorkspace AppWorkspace)
- {
- imageIndexDialog = this;
- //this.fromMaxSize = this.Width;
- this.AppWorkspace = AppWorkspace;
- InitializeComponent();
- CollapseUnfold();
- InitializeButtonBackgroudImage();
- InitializeToolTipAndEvent();
-
- this.Text = PdnResources.GetString("Menu.Tools.ImageIndex.Text");
- this.groupBox1.Text = PdnResources.GetString("Menu.tool.Imageindex.Indexlist.text");
- this.groupBox2.Text = PdnResources.GetString("Menu.Set.Generalsettings.Namingrules.text");
- //
- // dialog
- //
- this.StartPosition = FormStartPosition.CenterScreen;
- this.Text = PdnResources.GetString("Menu.Tools.ImageIndex.Text");
- //
- // 设置listview事件
- //
- this.listView1.SelectedIndexChanged += new EventHandler(ListViewSelectedIndexChanged);
- comboBox_Name_Refresh();
- NamingInitialization();
- //
- // 初始化数据
- //
- this.InitData();
- this.listView1.View = View.LargeIcon;
- //PreviewRefresh();
- //SplitContainerSize();
- PreviewRefresh(config.CaptureSaveMode);
- }
- //初始化折叠与展开初始值
- private void CollapseUnfold()
- {
- this.fromMinSize = splitContainer1.Panel1.Width;
- this.fromMaxSize = this.Width;
- if (btn_Hide.Text == "<<")
- this.MaximumSize = new Size(0, 0);
- else
- this.MaximumSize = new Size(400, Screen.PrimaryScreen.Bounds.Height);
- this.groupBox1.MaximumSize = new Size(366, Screen.PrimaryScreen.Bounds.Height);
- }
- private void InitializeButtonBackgroudImage()
- {
- this.button7.FlatStyle = FlatStyle.Flat;
- this.button7.FlatAppearance.BorderSize = 0;
- this.button7.BackgroundImageLayout = ImageLayout.Center;
- this.button7.BackgroundImage = PdnResources.GetImageResource("Icons.ProjectEngineering.ListMode.png").Reference;
- this.button8.FlatStyle = FlatStyle.Flat;
- this.button8.FlatAppearance.BorderSize = 0;
- this.button8.BackgroundImageLayout = ImageLayout.Center;
- this.button8.BackgroundImage = PdnResources.GetImageResource("Icons.ProjectEngineering.PicMode.png").Reference;
- this.button10.FlatStyle = FlatStyle.Flat;
- this.button10.FlatAppearance.BorderSize = 0;
- this.button10.BackgroundImageLayout = ImageLayout.Center;
- this.button10.BackgroundImage = PdnResources.GetImageResource("Icons.MenuFileBulkSaveIcon.png").Reference;
- this.toolStripMenuItem1.Image = PdnResources.GetImageResource("Icons.MenuFileSaveIcon.png").Reference;
-
- this.toolStripMenuItem2.Image = PdnResources.GetImageResource("Icons.MenuFileSaveAsIcon.png").Reference;
-
- this.toolStripMenuItem3.Image = PdnResources.GetImageResource("Icons.MenuFileCloseIcon.png").Reference;
-
- this.toolStripMenuItem4.Image = PdnResources.GetImageResource("Icons.MenuEditCopyIcon.png").Reference;
- }
- /// <summary>
- /// 初始化提示信息及按钮事件
- /// </summary>
- private void InitializeToolTipAndEvent()
- {
- this.toolTip1 = new ToolTip();
- this.toolTip1.SetToolTip(this.button7, PdnResources.GetString("Menu.tool.Templatemanent.Listmode.text"));
- this.toolTip1.SetToolTip(this.button8, PdnResources.GetString("Menu.tool.Templategement.Thumbnailmode.text"));
- this.toolTip1.SetToolTip(this.button10, "批量保存");
- this.toolTip1.SetToolTip(this.btn_Hide, "折叠&展开");
- this.toolTip1.ShowAlways = true;
- }
- /// <summary>
- /// ListView选择事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ListViewSelectedIndexChanged(object sender, EventArgs e)
- {
- if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Selected)
- {
- if (AppWorkspace.toInitImageIndexDialogFlag != 1)
- {
- AppWorkspace.toInitImageIndexDialogFlag = 2;
- AppWorkspace.ActiveDocumentWorkspace = AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index];
- }
- this.imageMat = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap();
- isFirst = true;
- lastPoint.X = 0;
- lastPoint.Y = 0;
- refreshSizeMode();
- }
- }
- /// <summary>
- /// 初始化图片列表数据
- /// </summary>
- public void InitData()
- {//需要优化调用的时机,隐藏时切换图片不需要切换,显示时显示图片。并且隐藏时置为null,显示时读取当前mat。
- //return;
- this.imageList1.Images.Clear();
- this.listView1.Items.Clear();
- this.listView1.Columns.Clear();
- //this.pictureBox1.Image = null;
- if (AppWorkspace.DocumentWorkspaces.Length == 0 || AppWorkspace.ActiveDocumentWorkspace == null)
- {
- this.listView1.Refresh();
- this.pictureBox1.Image = null;
- return;
- }
- int typeLenth = 70;
- int nameLenth = 100;
- if (this.listView1.Width > 310)
- {
- typeLenth = this.listView1.Width / 5;
- nameLenth = this.listView1.Width * 2 / 5;
- if (typeLenth > 70)
- {
- typeLenth = 70;
- nameLenth = this.listView1.Width - 215;
- }
- }
- ColumnHeader header = new ColumnHeader();
- header.Text = PdnResources.GetString("Menu.File.Text");
- header.Width = nameLenth;
- this.listView1.Columns.Add(header);
- header = new ColumnHeader();
- header.Text = PdnResources.GetString("Menu.Type.text");
- header.Width = typeLenth;
- this.listView1.Columns.Add(header);
- header = new ColumnHeader();
- header.Text = PdnResources.GetString("Menu.size.text");
- header.Width = typeLenth;
- this.listView1.Columns.Add(header);
- header = new ColumnHeader();
- header.Text = PdnResources.GetString("MeasurementUnit.Pixel");
- header.Width = typeLenth;
- this.listView1.Columns.Add(header);
- this.imageList1.ImageSize = new Size(this.listView1.Width - 91 > 250 ? 250 : this.listView1.Width - 91, this.listView1.Width - 91 > 250 ? 250 : this.listView1.Width - 91);
- //初始化图片列表
- for (int i = 0; i < AppWorkspace.DocumentWorkspaces.Length; i++)
- {
- DocumentWorkspace iDocumentWorkspace = AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - i];
- //added begin by songxk
- //added end by songxk
- this.imageList1.Images.Add("img" + i, OpenCvSharp.Extensions.BitmapConverter.ToBitmap(iDocumentWorkspace.BoxMat));
- this.listView1.Items.Add("", i);
- this.listView1.Items[i].ImageIndex = i;
- this.listView1.Items[i].Text = iDocumentWorkspace.GetFriendlyName();
- this.listView1.Items[i].Name = iDocumentWorkspace.GetFriendlyName();
- string type = "";
- if (iDocumentWorkspace.GetFriendlyName().IndexOf('.') > -1)
- {
- type = iDocumentWorkspace.GetFriendlyName().Substring(iDocumentWorkspace.GetFriendlyName().LastIndexOf('.') + 1, iDocumentWorkspace.GetFriendlyName().Length - iDocumentWorkspace.GetFriendlyName().LastIndexOf('.') - 1);
- }
- else
- {
- type = "";
- }
-
- this.imageMat = iDocumentWorkspace.CompositionSurface.CreateAliasedBitmap();
- //图片类型
- this.listView1.Items[i].SubItems.Add(type);
- //获取图片路径
- string fileName;
- //FileType fileType;
- //SaveConfigToken saveConfigToken;
- iDocumentWorkspace.GetDocumentSaveOptions(out fileName/*, out fileType, out saveConfigToken*/);
- //获取图片信息
- if (fileName != null)
- {
- //获取图片对应xml
- PicConfigModel configModel = null;
- try
- {
- string path = Path.GetDirectoryName(fileName);
- string xmlPath = path + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".xml";
- //如果xml存在
- if (System.IO.File.Exists(xmlPath))
- {
- configModel = XmlSerializeHelper.DESerializer<PicConfigModel>(FileOperationHelper.ReadStringFromFile(xmlPath, FileMode.Open));
- if (configModel != null)
- {
- //图片大小
- this.listView1.Items[i].SubItems.Add(configModel.meta.imageSize);
- }
- }
- else
- {
- //获取图片信息
- if (System.IO.File.Exists(fileName))
- {
- FileInfo fi = new FileInfo(fileName);
- //图片大小
- this.listView1.Items[i].SubItems.Add(FileOperationHelper.GetLength(fi.Length));
- }
- }
- }
- catch (Exception)
- {
- }
- }
- else
- {
- //图像若没有信息像素计算
- double length = imageMat.Width * imageMat.Height;
- double lengthKb = length * 24 /8 / 1024 / 4.77;
- double lengthMb = length * 24/ 8 / 1024 / 1024 / 4.77;
- if (lengthKb >= 1024)
- {
- this.listView1.Items[i].SubItems.Add(lengthMb.ToString("f2") + "M");
- }
- else
- {
- this.listView1.Items[i].SubItems.Add(lengthKb.ToString("f0") + "KB");
- }
- }
- //图片像素
- this.listView1.Items[i].SubItems.Add(imageMat.Width.ToString() + "*" + imageMat.Height.ToString());
- }
- if (index != -1)
- {
- this.listView1.Items[index].Focused = true;
- this.listView1.Items[index].Selected = true;
- }
- else
- {
- if (this.listView1.Items.Count > 0 && AppWorkspace.DocumentWorkspaces.Length > 0 && AppWorkspace.ActiveDocumentWorkspace != null)
- {
- this.listView1.Items[0].Focused = true;
- this.listView1.Items[0].Selected = true;
- }
- }
- }
- /// <summary>
- /// 根据图片尺寸判断picturebox的显示模式并刷新图片
- /// </summary>
- private void refreshSizeMode()
- {
- if (imageMat != null)
- {
- if (imageMat.Width > pictureBox1.Size.Width || imageMat.Height > pictureBox1.Size.Height)
- {
- pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
- }
- else
- {
- pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
- }
- this.pictureBox1.Image = imageMat;
- }
-
- }
- /// <summary>
- /// 窗体尺寸改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ImageIndexDialog_Resize(object sender, EventArgs e)
- {
- lastPoint.X = 0;
- lastPoint.Y = 0;
- isFirst = true;
- refreshSizeMode();
- }
- /// <summary>
- /// 绘制picturebox
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void pictureBox1_Paint(object sender, PaintEventArgs e)
- {
- if (this.pictureBox1.Image != null)
- {
- if (isFirst)
- {
- //获取缩略图对应矩形
- PropertyInfo _ImageRectanglePropert = this.pictureBox1.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic);
- imageRect = (Rectangle)_ImageRectanglePropert.GetValue(this.pictureBox1, null);
- Size size = AppWorkspace.ActiveDocumentWorkspace.panel.ClientSize;//document窗体尺寸
- double ratio = AppWorkspace.ActiveDocumentWorkspace.ScaleRatio;
- if (size.Width < this.imageMat.Width * ratio)
- widthRatio = size.Width / (this.imageMat.Width * ratio);
- else
- widthRatio = 1;
- if (size.Height < this.imageMat.Height * ratio)
- heightRatio = size.Height / (this.imageMat.Height * ratio);
- else
- heightRatio = 1;
- Point scPoint = AppWorkspace.ActiveDocumentWorkspace.PanelScrollPosition;//当前滚动条位置
- scRatioWidth = imageRect.Width / (imageMat.Width * ratio);
- scRatioHeight = imageRect.Height / (imageMat.Height * ratio);
- //缩略图中红框选中区域
- zoomRect = new Rectangle(imageRect.X + (int)(scPoint.X * scRatioWidth), imageRect.Y + (int)(scPoint.Y * scRatioHeight),
- (int)(imageRect.Width * widthRatio), (int)(imageRect.Height * heightRatio));
- //红框矩形的最小尺寸,即原图放大3200%
- double minWidthRatio = size.Width / (this.imageMat.Width * 32d);
- double minHeightRatio = size.Height / (this.imageMat.Height * 32d);
- minRectWidth = (int)(Math.Round(imageRect.Width * minWidthRatio));
- minRectHeight = (int)(Math.Round(imageRect.Height * minHeightRatio));
- }
- e.Graphics.DrawRectangle(new Pen(Color.Red), zoomRect.X, zoomRect.Y, zoomRect.Width - 1, zoomRect.Height - 1);
- e.Graphics.FillRectangle(new SolidBrush(Color.Black), new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 9, 9));
- }
- }
- /// <summary>
- /// picturebox的鼠标按下事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
- {
- lastPoint.X = e.X;
- lastPoint.Y = e.Y;
- //是否平移
- if (zoomRect.Contains(e.Location) && !new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 9, 9).Contains(e.Location))
- isMoved = true;
- else
- isMoved = false;
- //是否放大缩小
- if (new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 9, 9).Contains(e.Location))
- isResized = true;
- else
- isResized = false;
- }
- /// <summary>
- /// pocturebox的鼠标移动事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
- {
- //修改鼠标形状
- this.pictureBox1.Cursor = Cursors.Default;
- if (zoomRect != null)
- {
- if (zoomRect.Contains(e.Location) && !new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 9, 9).Contains(e.Location))
- {
- this.pictureBox1.Cursor = Cursors.SizeAll;
- }
- if (new Rectangle(zoomRect.Right - 4, zoomRect.Bottom - 4, 7, 7).Contains(e.Location))
- {
- this.pictureBox1.Cursor = Cursors.SizeNWSE;
- }
- }
- if (e.Button != MouseButtons.Left)
- return;
- //拖拽
- if (zoomRect != null && isMoved)
- {
- isFirst = false;
- Point p = e.Location;
- int dx = p.X - lastPoint.X;
- int dy = p.Y - lastPoint.Y;
- lastPoint.X = p.X;
- lastPoint.Y = p.Y;
- zoomRect.X += dx;
- zoomRect.Y += dy;
- //控制矩形框不超过缩略图尺寸
- int xc = (this.pictureBox1.Width - this.imageRect.Width) / 2;
- int yc = (this.pictureBox1.Height - this.imageRect.Height) / 2;
- if (zoomRect.X < xc) zoomRect.X = xc;
- if (zoomRect.Y < yc) zoomRect.Y = yc;
- if (zoomRect.X + zoomRect.Width > imageRect.Width + xc) zoomRect.X = imageRect.Width - zoomRect.Width + xc;
- if (zoomRect.Y + zoomRect.Height > imageRect.Height + yc) zoomRect.Y = imageRect.Height - zoomRect.Height + yc;
- this.pictureBox1.Refresh();
- //修改document的滚动条
- Point scPoint = AppWorkspace.ActiveDocumentWorkspace.PanelScrollPosition;
- double scrollDx = dx / scRatioWidth;
- double scrollDy = dy / scRatioHeight;
- Point newScPoint = new Point(scPoint.X + Convert.ToInt32(Math.Round(scrollDx)), scPoint.Y + Convert.ToInt32(Math.Round(scrollDy)));
- AppWorkspace.ActiveDocumentWorkspace.PanelScrollPosition = newScPoint;
- }
- //缩放
- if (zoomRect != null && isResized)
- {
- isFirst = false;
- Point p = e.Location;
- int dx = p.X - lastPoint.X;
- int dy = p.Y - lastPoint.Y;
- lastPoint.X = p.X;
- lastPoint.Y = p.Y;
- //偏移量取横坐标与纵坐标中绝对值大的
- int delta = dx;
- if (Math.Abs(dy) > Math.Abs(dx))
- delta = dy;
- Size size = AppWorkspace.ActiveDocumentWorkspace.panel.ClientSize;//document尺寸
- double ratio = AppWorkspace.ActiveDocumentWorkspace.ScaleRatio;//缩放比
- //图片缩放后的宽和高都小于document窗口尺寸
- if (size.Width > this.imageMat.Width * ratio && size.Height > this.imageMat.Height * ratio)
- {
- AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;//修改缩放模式
-
- //只修改缩放比,不改变缩略图矩形框尺寸
- ratio += (-delta / 100d);
- ratio = GetMinRatio(ratio);
- RefreshActiveDocumentScaleFactor(ratio);
- }
- //图片缩放后的宽和高大于等于doucment窗口尺寸
- else
- {
- double aspectRatio = size.Width / (size.Height * 1d);//宽高比
- int maxResizedWidth = imageRect.Right - zoomRect.Right;//正向最大拖动宽度
- int maxResizedHeigth = imageRect.Bottom - zoomRect.Bottom;//正向最大拖动高度
- int maxRectWidth = maxResizedWidth + zoomRect.Width;//小矩形可放大到的最大宽度
- int maxRectHeight = maxResizedHeigth + zoomRect.Height;//小矩形可放大到的最大高度
- double newScaleRatio = 0;//计算后新的缩放比
- double newScPointX = 0;//计算后新的滚动条横坐标
- double newScPointY = 0;//计算后新的滚动条纵坐标
- //图片缩放后只有宽小于ducument窗口尺寸
- if (size.Width > this.imageMat.Width * ratio && size.Height <= this.imageMat.Height * ratio)
- {
- int minHeight = (int)Math.Round(imageRect.Width / aspectRatio);//矩形框可拖动的最小高度
- zoomRect.Height += delta;
- if (zoomRect.Height > maxRectHeight)
- {
- zoomRect.Height = maxRectHeight;
- //矩形框的起始点不在缩略图的起始点上时,高度达到默认可变的最大值后,同时修改纵坐标和高度
- if (maxRectHeight < imageRect.Height)
- {
- zoomRect.Y -= delta;
- if (zoomRect.Y < imageRect.Y)
- zoomRect.Y = imageRect.Y;
- zoomRect.Height += delta;
- if (zoomRect.Height > imageRect.Height)
- zoomRect.Height = imageRect.Height;
- this.pictureBox1.Refresh();
- newScaleRatio = Math.Round(size.Height / heightRatio / this.imageMat.Height, 2);//重新计算缩放比
- newScaleRatio = GetMinRatio(newScaleRatio);
- //重新计算滚轮所需比例
- scRatioWidth = imageRect.Width / (imageMat.Width * newScaleRatio);
- scRatioHeight = imageRect.Height / (imageMat.Height * newScaleRatio);
- //重新计算document的滚动条横坐标与纵坐标
- newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
- newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
- RefreshActiveDocumentScaleFactorAndScroll(ratio, new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY)));
- return;
- }
-
- //高度达到极限,只改变缩放比
- this.pictureBox1.Refresh();
- ratio += (-delta / 100d);
- ratio = GetMinRatio(ratio);
- RefreshActiveDocumentScaleFactor(ratio);
- return;
- }
-
- if (zoomRect.Height < minHeight)
- zoomRect.Height = minHeight;
- this.pictureBox1.Refresh();
- heightRatio = zoomRect.Height / (imageRect.Height * 1d);
- heightRatio = GetMaxDocumentWithBitmapRatio(heightRatio);
- newScaleRatio = Math.Round(size.Height / heightRatio / this.imageMat.Height, 2);//重新计算缩放比
- }
- //图片缩放后只有高小于ducument窗口尺寸
- if (size.Width <= this.imageMat.Width * ratio && size.Height > this.imageMat.Height * ratio)
- {
- int minWidth = (int)Math.Round(imageRect.Height * aspectRatio);//矩形框可拖动的最小宽度
- zoomRect.Width += delta;
- if (zoomRect.Width > maxRectWidth)
- {
- zoomRect.Width = maxRectWidth;
- //矩形框的起始点不在缩略图的起始点上时,宽度达到默认可变的最大值后,同时修改横坐标和宽度
- if (maxRectWidth < imageRect.Width)
- {
- zoomRect.X -= delta;
- if (zoomRect.X < imageRect.X)
- zoomRect.X = imageRect.X;
- zoomRect.Width += delta;
- if (zoomRect.Width > imageRect.Width)
- zoomRect.Width = imageRect.Width;
- this.pictureBox1.Refresh();
- newScaleRatio = Math.Round(size.Width / widthRatio / this.imageMat.Width, 2);//重新计算缩放比
- newScaleRatio = GetMinRatio(newScaleRatio);
- //重新计算滚轮所需比例
- scRatioWidth = imageRect.Width / (imageMat.Width * newScaleRatio);
- scRatioHeight = imageRect.Height / (imageMat.Height * newScaleRatio);
- //重新计算document的滚动条横坐标与纵坐标
- newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
- newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
- RefreshActiveDocumentScaleFactorAndScroll(newScaleRatio, new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY)));
- return;
- }
-
- //宽度达到极限,改变缩放比
- this.pictureBox1.Refresh();
- ratio += (-delta / 100d);
- ratio = GetMinRatio(ratio);
- RefreshActiveDocumentScaleFactor(ratio);
- return;
- }
- if (zoomRect.Width < minWidth)
- zoomRect.Width = minWidth;
- this.pictureBox1.Refresh();
- widthRatio = zoomRect.Width / (imageRect.Width * 1d);
- widthRatio = GetMaxDocumentWithBitmapRatio(widthRatio);
- newScaleRatio = Math.Round(size.Width / widthRatio / this.imageMat.Width, 2);//重新计算缩放比
- }
- //图片缩放后的宽和高都不小于document窗体尺寸
- if (size.Width <= this.imageMat.Width * ratio && size.Height <= this.imageMat.Height * ratio)
- {
- if (maxResizedWidth < maxResizedHeigth)
- {
- zoomRect.Width += delta;
- if (zoomRect.Width > maxRectWidth)
- {
- zoomRect.Width = maxRectWidth;
- //矩形框的宽度与缩略图宽度相同时才可改变高度并调整缩放比
- if(zoomRect.Width >= imageRect.Width)
- {
- zoomRect.Height += delta;
- this.pictureBox1.Refresh();
- heightRatio = zoomRect.Height / (imageRect.Height * 1d);
- heightRatio = GetMaxDocumentWithBitmapRatio(heightRatio);
- newScaleRatio = Math.Round(size.Height / heightRatio / this.imageMat.Height, 2);//重新计算缩放比
- newScaleRatio = GetMinRatio(newScaleRatio);
- //重新计算滚轮所需比例
- scRatioWidth = imageRect.Width / (imageMat.Width * newScaleRatio);
- scRatioHeight = imageRect.Height / (imageMat.Height * newScaleRatio);
- //重新计算document的滚动条横坐标与纵坐标
- newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
- newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
- RefreshActiveDocumentScaleFactorAndScroll(newScaleRatio, new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY)));
- return;
- }
- }
- if (zoomRect.Width < minRectWidth)
- zoomRect.Width = minRectWidth;
- zoomRect.Height = (int)Math.Round(zoomRect.Width / aspectRatio);
- }
- else
- {
- zoomRect.Height += delta;
- if (zoomRect.Height > maxRectHeight)
- {
- zoomRect.Height = maxRectHeight;
- //矩形框的高度与缩略图高度相同时才可改变宽度并调整缩放比
- if (zoomRect.Height >= imageRect.Height)
- {
- zoomRect.Width += delta;
- this.pictureBox1.Refresh();
- widthRatio = zoomRect.Width / (imageRect.Width * 1d);
- widthRatio = GetMaxDocumentWithBitmapRatio(widthRatio);
- newScaleRatio = Math.Round(size.Width / widthRatio / this.imageMat.Width, 2);//重新计算缩放比
- newScaleRatio = GetMinRatio(newScaleRatio);
- //重新计算滚轮所需比例
- scRatioWidth = imageRect.Width / (imageMat.Width * newScaleRatio);
- scRatioHeight = imageRect.Height / (imageMat.Height * newScaleRatio);
- //重新计算document的滚动条横坐标与纵坐标
- newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
- newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
- RefreshActiveDocumentScaleFactorAndScroll(newScaleRatio, new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY)));
- return;
- }
- }
- if (zoomRect.Height < minRectHeight)
- zoomRect.Height = minRectHeight;
- zoomRect.Width = (int)Math.Round(zoomRect.Height * aspectRatio);
- }
- this.pictureBox1.Refresh();
- //重新计算比例
- widthRatio = zoomRect.Width / (imageRect.Width * 1d);
- widthRatio = GetMaxDocumentWithBitmapRatio(widthRatio);
- heightRatio = zoomRect.Height / (imageRect.Height * 1d);
- heightRatio = GetMaxDocumentWithBitmapRatio(heightRatio);
- //计算document的缩放比,宽和高的计算结果会有细微差异
- double scaleW = Math.Round(size.Width / widthRatio / this.imageMat.Width, 2);
- double scaleH = Math.Round(size.Height / heightRatio / this.imageMat.Height, 2);
- //取大的值作为新的缩放比?不确定
- if (scaleW >= scaleH)
- newScaleRatio = scaleW;
- else
- newScaleRatio = scaleH;
- }
- //重新计算滚轮所需比例
- scRatioWidth = imageRect.Width / (imageMat.Width * newScaleRatio);
- scRatioHeight = imageRect.Height / (imageMat.Height * newScaleRatio);
- //重新计算document的滚动条横坐标与纵坐标
- newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
- newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
- RefreshActiveDocumentScaleFactorAndScroll(newScaleRatio, new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY)));
- }
- }
- }
- /// <summary>
- /// 控制缩放比的最小值为1%
- /// </summary>
- /// <param name="ratio"></param>
- /// <returns></returns>
- private double GetMinRatio(double ratio)
- {
- if (ratio < 0.01)
- ratio = 0.01;
- return ratio;
- }
- /// <summary>
- /// 控制document窗口与缩放后图片比例,最大值为1
- /// </summary>
- /// <param name="ratio"></param>
- /// <returns></returns>
- private double GetMaxDocumentWithBitmapRatio(double ratio)
- {
- if (ratio > 1)
- ratio = 1;
- return ratio;
- }
- /// <summary>
- /// 刷新当前激活document的缩放比
- /// </summary>
- /// <param name="scaleRatio"></param>
- /// <returns></returns>
- private bool RefreshActiveDocumentScaleFactor(double scaleRatio)
- {
- AppWorkspace.ActiveDocumentWorkspace.ScaleFactor = ScaleFactor.FromDouble(scaleRatio);
- AppWorkspace.ActiveDocumentWorkspace.Refresh();
- return true;
- }
- /// <summary>
- /// 刷新当前激活document的缩放比与滚动条
- /// </summary>
- /// <param name="scaleRatio"></param>
- /// <returns></returns>
- private bool RefreshActiveDocumentScaleFactorAndScroll(double scaleRatio, Point point)
- {
- AppWorkspace.ActiveDocumentWorkspace.ScaleFactor = ScaleFactor.FromDouble(scaleRatio);
- AppWorkspace.ActiveDocumentWorkspace.PanelScrollPosition = point;
- AppWorkspace.ActiveDocumentWorkspace.Refresh();
- return true;
- }
- private void button7_Click(object sender, EventArgs e)
- {
- if (this.listView1.View == View.Details)
- return;
- for (int i = 0; i < this.listView1.Items.Count; i++)
- {
- if (AppWorkspace.DocumentWorkspaces[i].GetFriendlyName().IndexOf('.') > -1)
- {
- this.listView1.Items[i].Text = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName().Substring(0, AppWorkspace.DocumentWorkspaces[i].GetFriendlyName().LastIndexOf('.'));
- this.listView1.Items[i].Name = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName().Substring(0, AppWorkspace.DocumentWorkspaces[i].GetFriendlyName().LastIndexOf('.'));
- }
- else
- {
- this.listView1.Items[i].Text = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName();
- this.listView1.Items[i].Name = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName();
- }
- }
- //string ssss = "333.44.555.666.jpg";
- //int n = ssss.LastIndexOf(".");
- //InitData();
- this.listView1.View = View.Details;
- }
- private void button8_Click(object sender, EventArgs e)
- {
- if (this.listView1.View == View.LargeIcon)
- return;
- ////初始化图片列表
- //for (int i = 0; i < this.listView1.Items.Count; i++)
- //{
- // this.listView1.Items[i].Text = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName();
- // this.listView1.Items[i].Name = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName();
- //}
-
- this.imageList1.ImageSize = new Size(this.listView1.Width-91 > 250? 250: this.listView1.Width-91, this.listView1.Width-91 > 250 ? 250 : this.listView1.Width-91);
- //InitData();
- this.listView1.View = View.LargeIcon;
- }
- /// <summary>
- /// 折叠展开
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_Hide_Click(object sender, EventArgs e)
- {
- if (btn_Hide.Text == ">>" && this.fromMinSize == this.fromMaxSize)
- {
- this.fromMaxSize = fixedWidth;
- }
- if (this.Width == this.fromMinSize)
- {
- btn_Hide.Text = "<<";
- this.MaximumSize = new Size(0,0);
- this.Width = this.fromMaxSize;
- }
- else
- {
- btn_Hide.Text = ">>";
-
- this.fromMaxSize = this.Width;
- this.fromMinSize = splitContainer1.SplitterDistance +24;
- this.Width = this.fromMinSize;
- this.MaximumSize = new Size(400, this.Height);
- //this.fromMinSize = this.Width;
- }
- }
-
- /// <summary>
- /// 配合折叠展开
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ImageIndexDialog_SizeChanged(object sender, EventArgs e)
- {
- if (this.btn_Hide.Text == ">>")
- {
- splitContainer1.IsSplitterFixed = true;
- splitContainer1.FixedPanel = FixedPanel.Panel1;
- if (this.Width >= this.fromMaxSize)
- {
- panel1.Width = this.Width + extendWidth;
- this.fromMaxSize = this.Width + extendWidth +24;
- }
-
- //if (this.Width <= this.fromMinSize)
- //{
- // panel1.Width = this.Width + 550;
- // this.fromMaxSize = this.Width + 574;
- //}
- splitContainer1.SplitterDistance = this.Width - 24;
- this.fromMinSize = this.Width;
- return;
- }
- if (this.btn_Hide.Text == "<<")
- {
- splitContainer1.IsSplitterFixed = false;
- splitContainer1.FixedPanel = FixedPanel.None;
- splitContainer1.SplitterDistance = this.fromMinSize - 24;
- this.fromMaxSize = this.Width;
- }
- if (this.Width > this.fromMinSize)
- {
- this.btn_Hide.Text = "<<";
- if (this.MaximumSize.Width == 400)
- this.MaximumSize = new Size(0, 0);
- }
- else
- {
- this.btn_Hide.Text = ">>";
- if (this.MaximumSize.Width != 400)
- this.MaximumSize = new Size(400, this.Height);
- }
- if (this.Width - 24 > panel1.Width || btn_Hide.Text == "<<" || this.Width > this.fromMinSize)
- panel1.Width = this.Width - 24;
-
- //if (this.btn_Hide.Text == ">>")
- //{
- // splitContainer1.IsSplitterFixed = true;
- // splitContainer1.FixedPanel = FixedPanel.Panel1;
- // //splitContainer1.SplitterDistance = this.Width - 24;
- //}
- //else
- //{
- // splitContainer1.IsSplitterFixed = false;
- // splitContainer1.FixedPanel = FixedPanel.None;
- //}
- }
- private void panel1_SizeChanged(object sender, EventArgs e)
- {
- splitContainer1.SplitterDistance = this.fromMinSize - 24;
- }
- private int index =-1;
- private void splitContainer1_Panel1_SizeChanged(object sender, EventArgs e)
- {
- if (this.fromMinSize != splitContainer1.SplitterDistance + 24)
- {
- this.fromMinSize = splitContainer1.SplitterDistance + 24;
- if (this.listView1.FocusedItem != null)
- {
- index = this.listView1.FocusedItem.Index;
- InitData();
- index = -1;
- }
- }
- if (splitContainer1.SplitterDistance > 376)
- {
- splitContainer1.SplitterDistance = 376;
- }
- lblPreview.Width = splitContainer1.SplitterDistance - 22;
- }
- private void button10_Click(object sender, EventArgs e)
- {
- using (BatchSaveDialog dialog = new BatchSaveDialog(AppWorkspace))
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- dialog.StartPosition = FormStartPosition.CenterScreen;
- dialog.ShowDialog();
- }
- }
- /// <summary>
- /// 命名规则设置
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_SetUp_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- using (GeneralSettingDialog af = new GeneralSettingDialog(AppWorkspace))
- {
- af.groupBox1.Visible = false;
-
- af.groupBox2.Location = new Point(6,13);
- af.groupBox5.Location = new Point(6, 136);
- af.groupBox19.Location = new Point(6, 74);
- af.Width = af.Width - af.groupBox1.Width;
- af.StartPosition = FormStartPosition.CenterScreen;
- af.ShowDialog(AppWorkspace);
-
- }
- }
- public void PreviewRefresh(int mode = 0)
- {
- config.Txt1 = comboBox_T1.Text;
- config.Txt2 = comboBox_T2.Text;
- config.Txt3 = comboBox_T2.Text;
- string photoName;
- if (Startup.instance.ruleDB == null)
- photoName = NamingRuleHelper.GetNameFromXml(Startup.instance.configModel, "默认标尺", "0", mode);
- else
- photoName = NamingRuleHelper.GetNameFromXml(Startup.instance.configModel, Startup.instance.ruleDB.ruler_name, Startup.instance.ruleDB.gain_multiple.ToString(), mode);
- lblPreview.Text = photoName;
- }
- private void comboBox_T1_TextUpdate(object sender, EventArgs e)
- {
- PreviewRefresh(config.CaptureSaveMode);
- }
- private void comboBox_T2_TextUpdate(object sender, EventArgs e)
- {
- PreviewRefresh(config.CaptureSaveMode);
- }
- private void comboBox_T3_TextUpdate(object sender, EventArgs e)
- {
- PreviewRefresh(config.CaptureSaveMode);
- }
- /// <summary>
- /// 刷新条目名称
- /// </summary>
- public void comboBox_Name_Refresh(int mode = 0)
- {
- this.comboBox_Name.SelectedIndexChanged -= new System.EventHandler(this.comboBox_Name_SelectedIndexChanged);
- string[] lstName = config.LstNaming.Select(a => a.name).ToArray();
- this.comboBox_Name.DataSource = lstName;
- this.comboBox_Name.Text = config.CurrentName;
- this.comboBox_Name.SelectedIndexChanged += new System.EventHandler(this.comboBox_Name_SelectedIndexChanged);
- PreviewRefresh(mode);
- }
- /// <summary>
- /// 添加自定义文本1
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_AddT1_Click(object sender, EventArgs e)
- {
- if (comboBox_T1.Text.Trim() == "")
- {
- MessageBox.Show("参数不能为空!");
- return;
- };
- CurrentLocation = 1;
- CustomTxt customTxt = new CustomTxt();
- customTxt.customT = comboBox_T1.Text.Trim();
-
- if (config.LstCustomTxt == null) config.LstCustomTxt = new CustomTxtModel();
- if (config.LstCustomTxt.customTxts1 == null) config.LstCustomTxt.customTxts1 = new List<CustomTxt>();
- if (Inspect())
- {
- MessageBox.Show("名称重复!");
- return;
- }
- config.LstCustomTxt.customTxts1.Add(customTxt);
- config.Txt1 = comboBox_T1.Text.Trim();
-
- string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
- if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
- MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
- if (config.LstCustomTxt.customTxts1 != null && config.LstCustomTxt.customTxts1.Count > 0)
- {
- string[] lstName = config.LstCustomTxt.customTxts1.Select(a => a.customT).ToArray();
- this.comboBox_T1.DataSource = lstName;
- if (lstName.Length > 0) this.comboBox_T1.Text = customTxt.customT;
- }
- else this.comboBox_T1.DataSource = null;
- }
- /// <summary>
- /// 添加自定义文本2
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_AddT2_Click(object sender, EventArgs e)
- {
-
- if (comboBox_T2.Text.Trim() == "")
- {
- MessageBox.Show("参数不能为空!");
- return;
- };
- CurrentLocation = 2;
- CustomTxt customTxt = new CustomTxt();
- customTxt.customT = comboBox_T2.Text.Trim();
- if (config.LstCustomTxt == null) config.LstCustomTxt = new CustomTxtModel();
- if (config.LstCustomTxt.customTxts2 == null) config.LstCustomTxt.customTxts2 = new List<CustomTxt>();
- if (Inspect())
- {
- MessageBox.Show("名称重复!");
- return;
- }
-
- config.LstCustomTxt.customTxts2.Add(customTxt);
- config.Txt2 = comboBox_T2.Text.Trim();
-
- string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
- if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
- MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
- if (config.LstCustomTxt.customTxts2 != null && config.LstCustomTxt.customTxts2.Count > 0)
- {
- string[] lstName = config.LstCustomTxt.customTxts2.Select(a => a.customT).ToArray();
- this.comboBox_T2.DataSource = lstName;
- if (lstName.Length > 0) this.comboBox_T2.Text = customTxt.customT;
- }
- else this.comboBox_T2.DataSource = null;
- }
- private void TxtAssignment()
- {
- config.Txt1 = comboBox_T1.Text.Trim();
- config.Txt2 = comboBox_T2.Text.Trim();
- config.Txt3 = comboBox_T3.Text.Trim();
- string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
- if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
- MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
- }
- /// <summary>
- /// 添加自定义文本3
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_AddT3_Click(object sender, EventArgs e)
- {
- if (comboBox_T3.Text.Trim() == "")
- {
- MessageBox.Show("参数不能为空!");
- return;
- };
- CurrentLocation = 3;
- CustomTxt customTxt = new CustomTxt();
- customTxt.customT = comboBox_T3.Text.Trim();
- if (config.LstCustomTxt == null) config.LstCustomTxt = new CustomTxtModel();
- if (config.LstCustomTxt.customTxts3 == null) config.LstCustomTxt.customTxts3 = new List<CustomTxt>();
- if (Inspect())
- {
- MessageBox.Show("名称重复!");
- return;
- }
- config.LstCustomTxt.customTxts3.Add(customTxt);
- config.Txt3 = comboBox_T3.Text.Trim();
- string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
- if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
- MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
- if (config.LstCustomTxt.customTxts3 != null && config.LstCustomTxt.customTxts3.Count > 0)
- {
- string[] lstName = config.LstCustomTxt.customTxts3.Select(a => a.customT).ToArray();
- this.comboBox_T3.DataSource = lstName;
- if (lstName.Length > 0) this.comboBox_T3.Text = customTxt.customT;
- }
- else this.comboBox_T3.DataSource = null;
- }
- //文本检查
- private bool Inspect()
- {
- bool chek = false;
- string name = string.Empty;
- switch (CurrentLocation)
- {
- case 1:
- name = comboBox_T1.Text.Trim();
- if (config.LstCustomTxt.customTxts1.Count > 0)
- {
- string[] lstName = config.LstCustomTxt.customTxts1.Select(a => a.customT).ToArray();
- chek = ((IList)lstName).Contains(name);
- }
- break;
- case 2:
- name = comboBox_T2.Text.Trim();
- if (config.LstCustomTxt.customTxts2.Count > 0)
- {
- string[] lstName = config.LstCustomTxt.customTxts2.Select(a => a.customT).ToArray();
- chek = ((IList)lstName).Contains(name);
- }
- break;
- case 3:
- name = comboBox_T3.Text.Trim();
- if (config.LstCustomTxt.customTxts3.Count > 0)
- {
- string[] lstName = config.LstCustomTxt.customTxts3.Select(a => a.customT).ToArray();
- chek = ((IList)lstName).Contains(name);
- }
- break;
- default:
- break;
- }
- CurrentLocation = -1;
- return chek;
- }
- /// <summary>
- /// 初始化
- /// </summary>
- public void NamingInitialization()
- {
- if (config.LstCustomTxt != null )
- {
- if (config.LstCustomTxt.customTxts1 != null && config.LstCustomTxt.customTxts1.Count > 0)
- {
- string[] lstName = config.LstCustomTxt.customTxts1.Select(a => a.customT).ToArray();
- this.comboBox_T1.DataSource = lstName;
- if (lstName.Length > 0) this.comboBox_T1.Text = config.Txt1;
- }
- else this.comboBox_T1.DataSource = null;
- if (config.LstCustomTxt.customTxts2 != null && config.LstCustomTxt.customTxts2.Count > 0)
- {
- string[] lstName = config.LstCustomTxt.customTxts2.Select(a => a.customT).ToArray();
- this.comboBox_T2.DataSource = lstName;
- if (lstName.Length > 0) this.comboBox_T2.Text = config.Txt2;
- }
- else this.comboBox_T2.DataSource = null;
- if (config.LstCustomTxt.customTxts3 != null && config.LstCustomTxt.customTxts3.Count > 0)
- {
- string[] lstName = config.LstCustomTxt.customTxts3.Select(a => a.customT).ToArray();
- this.comboBox_T3.DataSource = lstName;
- if (lstName.Length > 0) this.comboBox_T3.Text = config.Txt3;
- }
- else this.comboBox_T3.DataSource = null;
- }
- this.comboBox_T1.SelectedIndexChanged += new System.EventHandler(this.comboBox_T1_SelectedIndexChanged);
- this.comboBox_T2.SelectedIndexChanged += new System.EventHandler(this.comboBox_T2_SelectedIndexChanged);
- this.comboBox_T3.SelectedIndexChanged += new System.EventHandler(this.comboBox_T3_SelectedIndexChanged);
- }
- private void btn_DelT1_Click(object sender, EventArgs e)
- {
- if (comboBox_T1.Text.Trim() == "")
- {
- MessageBox.Show("参数不能为空!");
- return;
- };
- DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretcteddata.text") + "?", PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
- if (dr == DialogResult.Cancel) return;
- CurrentLocation = 1;
- if (config.LstCustomTxt == null || config.LstCustomTxt.customTxts1 == null || !Inspect())
- {
- MessageBox.Show("不存在此文本!");
- return;
- }
- for (int i = 0; i < config.LstCustomTxt.customTxts1.Count; i++)
- {
- if (comboBox_T1.Text.Trim().Equals(config.LstCustomTxt.customTxts1[i].customT))
- config.LstCustomTxt.customTxts1.Remove(config.LstCustomTxt.customTxts1[i]);
- }
-
- string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
- if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
- MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
- if (config.LstCustomTxt.customTxts1 != null && config.LstCustomTxt.customTxts1.Count > 0)
- {
- string[] lstName = config.LstCustomTxt.customTxts1.Select(a => a.customT).ToArray();
- this.comboBox_T1.DataSource = lstName;
- }
- else this.comboBox_T1.DataSource = null;
- }
- private void btn_DelT2_Click(object sender, EventArgs e)
- {
- if (comboBox_T2.Text.Trim() == "")
- {
- MessageBox.Show("参数不能为空!");
- return;
- };
- DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretcteddata.text") + "?", PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
- if (dr == DialogResult.Cancel) return;
- CurrentLocation = 2;
- if (config.LstCustomTxt == null || config.LstCustomTxt.customTxts2 == null || !Inspect())
- {
- MessageBox.Show("不存在此文本!");
- return;
- }
- for (int i = 0; i < config.LstCustomTxt.customTxts2.Count; i++)
- {
- if (comboBox_T2.Text.Trim().Equals(config.LstCustomTxt.customTxts2[i].customT))
- config.LstCustomTxt.customTxts2.Remove(config.LstCustomTxt.customTxts2[i]);
- }
- string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
- if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
- MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
- if (config.LstCustomTxt.customTxts2 != null && config.LstCustomTxt.customTxts2.Count > 0)
- {
- string[] lstName = config.LstCustomTxt.customTxts2.Select(a => a.customT).ToArray();
- this.comboBox_T2.DataSource = lstName;
- }
- else this.comboBox_T2.DataSource = null;
- }
- private void btn_DelT3_Click(object sender, EventArgs e)
- {
- if (comboBox_T3.Text.Trim() == "")
- {
- MessageBox.Show("参数不能为空!");
- return;
- };
- DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretcteddata.text") + "?", PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
- if (dr == DialogResult.Cancel) return;
- CurrentLocation = 3;
- if (config.LstCustomTxt == null || config.LstCustomTxt.customTxts3 == null || !Inspect())
- {
- MessageBox.Show("不存在此文本!");
- return;
- }
- for (int i = 0; i < config.LstCustomTxt.customTxts3.Count; i++)
- {
- if (comboBox_T3.Text.Trim().Equals(config.LstCustomTxt.customTxts3[i].customT))
- config.LstCustomTxt.customTxts3.Remove(config.LstCustomTxt.customTxts3[i]);
- }
- string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
- if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
- MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
- if (config.LstCustomTxt.customTxts3 != null && config.LstCustomTxt.customTxts3.Count > 0)
- {
- string[] lstName = config.LstCustomTxt.customTxts3.Select(a => a.customT).ToArray();
- this.comboBox_T3.DataSource = lstName;
- }
- else this.comboBox_T3.DataSource = null;
- }
- /// <summary>
- /// 鼠标事件-右键
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void listView1_MouseClick(object sender, MouseEventArgs e)
- {
- ListView listView = (ListView)sender;
- ListViewItem item = listView.GetItemAt(e.X, e.Y);
- if (item != null && e.Button == MouseButtons.Right)
- {
- this.contextMenuStrip1.Show(listView, e.X, e.Y);
- }
- }
- /// <summary>
- /// 右键保存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void toolStripMenuItem1_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- AppWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
- AppWorkspace.ActiveDocumentWorkspace.DoSaveNew();
- }
- InitData();
- }
- /// <summary>
- /// 右键另存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void toolStripMenuItem2_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- AppWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
- AppWorkspace.ActiveDocumentWorkspace.DoSaveAsNew();
- }
- InitData();
- }
- /// <summary>
- /// 右键强制关闭
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void toolStripMenuItem3_Click(object sender, EventArgs e)
- {
- if (this.AppWorkspace.DocumentWorkspaces.Length > 0 && this.AppWorkspace.ActiveDocumentWorkspace != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- this.AppWorkspace.ActiveDocumentWorkspace.Document.Dirty = false;
- this.AppWorkspace.PerformAction(new CloseWorkspaceAction());
- }
- InitData();
- }
- private Bitmap copyedBitmap;//复制的图片
- private int nameNum = 0;//命名使用
- /// <summary>
- /// 右键复制图片
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void toolStripMenuItem4_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null && AppWorkspace.ActiveDocumentWorkspace.CompositionSurface != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- Bitmap temp = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap();
- copyedBitmap = new Bitmap(temp.Width, temp.Height);
- Graphics graphics = Graphics.FromImage(copyedBitmap);
- graphics.DrawImage(temp, 0, 0, temp.Width, temp.Height);
- if (AppWorkspace.ActiveDocumentWorkspace.GraphicsList.IsExsitSpecificObject(DrawToolType.ImageCut))
- {
- //获取裁剪的矩形区域
- List<DrawObject> objList = AppWorkspace.ActiveDocumentWorkspace.GraphicsList.GetDrawToolTypeList(DrawToolType.ImageCut);
- ImageCutDraw imageCutDraw = (ImageCutDraw)objList[0];
- RectangleF cutRectangle = imageCutDraw.Rectangle;
- copyedBitmap = DrawRulerHelper.KiCut(copyedBitmap, (int)cutRectangle.X, (int)cutRectangle.Y, (int)cutRectangle.Width, (int)cutRectangle.Height);
- }
- }
- if (copyedBitmap != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
- Document document = Document.FromImageMat(Camera.Tools.ToMat(copyedBitmap));
- dw.Document = document;
- //图片命名
- nameNum++;
- int numLength = nameNum.ToString().Length;
- string joinName = "";
- switch (numLength)
- {
- case 1:
- joinName = "00" + nameNum;
- break;
- case 2:
- joinName = "0" + nameNum;
- break;
- default:
- joinName = nameNum.ToString();
- break;
- }
- dw.xmlSaveModel = AppWorkspace.ActiveDocumentWorkspace.xmlSaveModel;
- dw.rules = AppWorkspace.ActiveDocumentWorkspace.rules;
- dw.fileText = PdnResources.GetString("Menu.Copythepicture.Text") + "-" + joinName;
- AppWorkspace.ActiveDocumentWorkspace = dw;
- }
- InitData();
- }
- private void SplitContainerSize()
- {
- splitContainer1.Size = new Size(800, 450);
- }
- private void comboBox_T1_SelectedIndexChanged(object sender, EventArgs e)
- {
- TxtAssignment();
- PreviewRefresh(config.CaptureSaveMode);
- }
- private void comboBox_T2_SelectedIndexChanged(object sender, EventArgs e)
- {
- TxtAssignment();
- PreviewRefresh(config.CaptureSaveMode);
- }
- private void comboBox_T3_SelectedIndexChanged(object sender, EventArgs e)
- {
- TxtAssignment();
- PreviewRefresh(config.CaptureSaveMode);
- }
- private void comboBox_Name_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (comboBox_Name.Text.Trim() == "")
- {
- MessageBox.Show("参数不能为空!");
- return;
- }
- config.CurrentName = comboBox_Name.Text.Trim();
- comboBox_Name_SelectedIndex();
- string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
- if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
- MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
- PreviewRefresh(config.CaptureSaveMode);
- }
- private void comboBox_Name_SelectedIndex()
- {
- string CurrentName = config.CurrentName;
- if (config.LstNaming.Count > 0)
- {
- foreach (NamingMethod item in config.LstNaming)
- {
- if (CurrentName.Equals(item.name))
- {
- config.NamePrefix = item.NamePrefix;
- config.NameFormat = item.NameFormat;
- config.NumberNum = item.NumberNum;
- config.NameStatus = item.NameStatus;
- config.ContinueNum = item.ContinueNum;
- }
- }
- }
- }
- CreateNameDialog dialog;
- public string imgType = string.Empty;
- private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
- {
- string imgName = this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].GetFriendlyName();
- int index = 0;
- if (imgName.Contains('.'))
- {
- index = imgName.LastIndexOf('.');
- imgType = imgName.Substring(index);
- //从下一个索引开始截取
- imgName = imgName.Substring(0, index);
- }
- else
- {
- imgType = "";
- }
- dialog = new CreateNameDialog(this);
- dialog.Text = "重命名";
- dialog.StartPosition = FormStartPosition.CenterParent;
- dialog.SetTextBoxValue(imgName);
- dialog.textBox1.MaxLength = 999;
- dialog.ShowDialog();
- }
- /// <summary>
- /// 新建文件夹的结果函数
- /// </summary>
- /// <param name="name"></param>
- public override void GetCreateName(string name)
- {
- DocumentWorkspace iDocumentWorkspace = AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index];
- string imgName = iDocumentWorkspace.GetFriendlyName();
- int index = 0;
- if (imgName.Contains('.'))
- {
- index = imgName.LastIndexOf('.');
- imgName = imgName.Substring(0, index);
- }
- //获取图片路径
- string fileName;
- //FileType fileType;
- //SaveConfigToken saveConfigToken;
- iDocumentWorkspace.GetDocumentSaveOptions(out fileName/*, out fileType, out saveConfigToken*/);
- string path = Path.GetDirectoryName(fileName);
- string filePath = path == null? "" : path + "\\" + name + imgType;
- string xmlName = path == null ? "" : path + "\\" + imgName + ".xml";
- string xmlPath = path == null ? "" : path + "\\" + name + ".xml";
- if (System.IO.File.Exists(fileName)) System.IO.File.Move(fileName, filePath);//更改图片名称
- if (System.IO.File.Exists(xmlName)) System.IO.File.Move(xmlName, xmlPath);//更改xml文件名称
- this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].fileText = name + imgType;
- this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].UpdateDw2buttonName(name + imgType);
- if (path != null)
- {
- this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].picName = name + imgType;
- this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].filePath = filePath;
- this.listView1.Items[this.listView1.FocusedItem.Index].Text = name + imgType;
- }
- this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].Refresh();
- this.listView1.Items[this.listView1.FocusedItem.Index].Name = name + imgType;
- //InitData();
- dialog.Close();
- }
- private void ImageIndexDialog_FormClosing(object sender, FormClosingEventArgs e)
- {
- this.AppWorkspace.toolBar.RefreshBtnSelect(false, "ImageIndex");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(false, "ImageIndex");
- config.Txt1 = comboBox_T1.Text;
- config.Txt2 = comboBox_T2.Text;
- config.Txt3 = comboBox_T2.Text;
- }
- }
- }
|