using OpenCvSharp;
using PaintDotNet.Adjust.BaseImage;
using PaintDotNet.Base.CommTool;
using PaintDotNet.Base.SettingModel;
using PaintDotNet.CustomControl;
using PaintDotNet.DbOpreate.DbBll;
using PaintDotNet.DbOpreate.DbModel;
using PaintDotNet.ImageCollect;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Windows.Forms;
namespace PaintDotNet.Measuring
{
///
/// 标尺编辑/删除界面
///
internal class RuleAddForm : PdnBaseForm
{
///
/// 公共按钮
///
private CommonControlButtons commonControlButtons;
///
/// 在各种弹窗中使用
///
private DocumentWorkspaceWindow documentWorkspace;
///
/// 步骤
///
private byte step = 1;
///
/// 方向
///
private byte direction = 0;
///
/// 标尺图片
///
private Bitmap bitmap;
///
/// 起止点
///
private System.Drawing.Point startPoint, endPoint;
///
/// x、y轴数值
///
private int x, y;
///
/// 绘制标尺的线宽
///
private int width;
///
/// 字体
///
private Font font;
///
/// 笔刷
///
private Brush brush = new SolidBrush(Color.Red);
///
/// 标尺xml文件,编辑标尺时使用
///
public RulerFileModel ruleFileModel;
///
/// 标尺数据,编辑标尺时使用
///
public mic_rulers ruleModel;
///
/// 1新增 2编辑
///
public int status;
///
/// 调色板
///
PaintDotNet.ColorsForm colorsForm1;
// Create the outline for our custom end cap.
GraphicsPath hPath = new GraphicsPath();
// Construct the hook-shaped end cap.
CustomLineCap HookCap;
public AppWorkspace appWorkspace;
#region 像素跟踪
private Mat mat, ImageROI, bmat = new Mat();
///
/// rgb像素点
///
private Vec3b bgr;
///
/// hls像素点
///
private double h, s, v;
///
/// 缩放倍数
///
private int scale;
///
/// 中间十字和圆的颜色
/// 根据左侧的panel的被选中的背景色变化
///
private Color color = Color.Red;
///
/// 按下标记
///
private bool pressFlag;
#endregion
#region 控件
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button button9;
private System.Windows.Forms.Button button8;
private System.Windows.Forms.Button button7;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.NumericUpDown numericUpDown1;
private System.Windows.Forms.ColorDialog colorDialog1;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox6;
private System.Windows.Forms.TextBox textBox5;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.GroupBox groupBox5;
private System.Windows.Forms.TextBox textBox12;
private System.Windows.Forms.TextBox textBox11;
private System.Windows.Forms.TextBox textBox10;
private System.Windows.Forms.TextBox textBox9;
private System.Windows.Forms.TextBox textBox8;
private System.Windows.Forms.TextBox textBox7;
private System.Windows.Forms.Panel panel2;
private CustomControl.LinearColorPickerControl linearColorPickerControl1;
private PictureBox pictureBox1;
private Label label6;
private Label label5;
private Label label4;
private Label label3;
private Label label2;
private Label label8;
private Label label9;
private TrackBar trackBar1;
private NumericUpDown numericUpDown2;
private Label label10;
private Label label11;
private Label label17;
private Label label16;
private Label label15;
private Label label14;
private Label label13;
private Label label12;
private Label label23;
private Label label22;
private Label label21;
private Label label20;
private Label label19;
private Label label18;
private NumericUpDown numericUpDown3;
private Label label24;
private System.Windows.Forms.ComboBox comboBox1;
#endregion
#region Windows Form Designer generated code
private void InitializeLanguageText()
{
this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
this.button6.Text = PdnResources.GetString("Menu.Previous.text");
this.button5.Text = PdnResources.GetString("Menu.Nextstep.text");
this.button3.Text = PdnResources.GetString("Menu.thirdstep.text");
this.button2.Text = PdnResources.GetString("Menu.Secondstep.text");
this.button1.Text = PdnResources.GetString("Menu.firststep.text");
this.groupBox2.Text = PdnResources.GetString("Menu.Selectimagefrom.text");
this.label1.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
this.label7.Text = PdnResources.GetString("Menu.color.text") + ":";
this.button9.Text = PdnResources.GetString("Menu.Anydirection.text");
this.button8.Text = PdnResources.GetString("Menu.Verticaldirection.text");
this.button7.Text = PdnResources.GetString("Menu.horizontaldirection.text");
this.button4.Text = PdnResources.GetString("Menu.Openimage.text");
this.groupBox3.Text = PdnResources.GetString("Menu.Rulerimage.text");
this.groupBox4.Text = PdnResources.GetString("Menu.params.text");
this.label17.Text = PdnResources.GetString("Menu.Pixellength.text") + ":";
this.label16.Text = PdnResources.GetString("Menu.Physicallength.text") + ":";
this.label15.Text = PdnResources.GetString("Menu.Resolution.text") + ":";
this.label14.Text = PdnResources.GetString("Menu.unit.text") + ":";
this.label13.Text = PdnResources.GetString("Menu.LabelAction.DrawGainNumber.Text") + ":";
this.label12.Text = PdnResources.GetString("Menu.name.text") + ":";
this.groupBox5.Text = PdnResources.GetString("Menu.Expand.text");
this.label23.Text = PdnResources.GetString("Menu.microscope.text") + ":";
this.label22.Text = PdnResources.GetString("Menu.Objectlens.text") + ":";
this.label21.Text = PdnResources.GetString("Menu.thecamera.text") + ":";
this.label20.Text = PdnResources.GetString("Menu.oculars.text") + ":";
this.label19.Text = PdnResources.GetString("Menu.interface.text") + ":";
this.label18.Text = PdnResources.GetString("Menu.magnificationchanger.text") + ":";
this.label9.Text = PdnResources.GetString("Menu.Times.text");
this.label24.Text = PdnResources.GetString("Menu.Fontsize.text");
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.button6 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.label24 = new System.Windows.Forms.Label();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.numericUpDown3 = new System.Windows.Forms.NumericUpDown();
this.label1 = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel();
this.label7 = new System.Windows.Forms.Label();
this.button9 = new System.Windows.Forms.Button();
this.button8 = new System.Windows.Forms.Button();
this.button7 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.colorDialog1 = new System.Windows.Forms.ColorDialog();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.label17 = new System.Windows.Forms.Label();
this.label16 = new System.Windows.Forms.Label();
this.label15 = new System.Windows.Forms.Label();
this.label14 = new System.Windows.Forms.Label();
this.label13 = new System.Windows.Forms.Label();
this.label12 = new System.Windows.Forms.Label();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.textBox6 = new System.Windows.Forms.TextBox();
this.textBox5 = new System.Windows.Forms.TextBox();
this.textBox4 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.groupBox5 = new System.Windows.Forms.GroupBox();
this.label23 = new System.Windows.Forms.Label();
this.label22 = new System.Windows.Forms.Label();
this.label21 = new System.Windows.Forms.Label();
this.label20 = new System.Windows.Forms.Label();
this.label19 = new System.Windows.Forms.Label();
this.label18 = new System.Windows.Forms.Label();
this.textBox12 = new System.Windows.Forms.TextBox();
this.textBox11 = new System.Windows.Forms.TextBox();
this.textBox10 = new System.Windows.Forms.TextBox();
this.textBox9 = new System.Windows.Forms.TextBox();
this.textBox8 = new System.Windows.Forms.TextBox();
this.textBox7 = new System.Windows.Forms.TextBox();
this.panel2 = new System.Windows.Forms.Panel();
this.label10 = new System.Windows.Forms.Label();
this.label11 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.trackBar1 = new System.Windows.Forms.TrackBar();
this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
this.label6 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.linearColorPickerControl1 = new PaintDotNet.CustomControl.LinearColorPickerControl();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).BeginInit();
this.groupBox4.SuspendLayout();
this.groupBox5.SuspendLayout();
this.panel2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
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)));
this.groupBox1.Controls.Add(this.button6);
this.groupBox1.Controls.Add(this.button5);
this.groupBox1.Controls.Add(this.button3);
this.groupBox1.Controls.Add(this.button2);
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Location = new System.Drawing.Point(13, 13);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(115, 445);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
//
// button6
//
this.button6.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.button6.Location = new System.Drawing.Point(20, 383);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(75, 23);
this.button6.TabIndex = 4;
this.button6.Text = "上一步";
this.button6.UseVisualStyleBackColor = true;
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// button5
//
this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.button5.Location = new System.Drawing.Point(20, 412);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(75, 23);
this.button5.TabIndex = 3;
this.button5.Text = "下一步";
this.button5.UseVisualStyleBackColor = true;
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(20, 89);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 2;
this.button3.Text = "第三步";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(20, 59);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 1;
this.button2.Text = "第二步";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(20, 29);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "第一步";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// groupBox2
//
this.groupBox2.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.label24);
this.groupBox2.Controls.Add(this.numericUpDown1);
this.groupBox2.Controls.Add(this.numericUpDown3);
this.groupBox2.Controls.Add(this.label1);
this.groupBox2.Controls.Add(this.panel1);
this.groupBox2.Controls.Add(this.label7);
this.groupBox2.Controls.Add(this.button9);
this.groupBox2.Controls.Add(this.button8);
this.groupBox2.Controls.Add(this.button7);
this.groupBox2.Controls.Add(this.button4);
this.groupBox2.Location = new System.Drawing.Point(134, 13);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(779, 52);
this.groupBox2.TabIndex = 2;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "从...选择图像";
//
// label24
//
this.label24.AutoSize = true;
this.label24.Location = new System.Drawing.Point(278, 26);
this.label24.Name = "label24";
this.label24.Size = new System.Drawing.Size(41, 12);
this.label24.TabIndex = 16;
this.label24.Text = "字号:";
//
// numericUpDown1
//
this.numericUpDown1.Location = new System.Drawing.Point(181, 22);
this.numericUpDown1.Maximum = new decimal(new int[] {
99999,
0,
0,
0});
this.numericUpDown1.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(72, 21);
this.numericUpDown1.TabIndex = 15;
this.numericUpDown1.Value = new decimal(new int[] {
3,
0,
0,
0});
this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged);
//
// numericUpDown3
//
this.numericUpDown3.Location = new System.Drawing.Point(323, 22);
this.numericUpDown3.Maximum = new decimal(new int[] {
49000,
0,
0,
0});
this.numericUpDown3.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.numericUpDown3.Name = "numericUpDown3";
this.numericUpDown3.Size = new System.Drawing.Size(72, 21);
this.numericUpDown3.TabIndex = 17;
this.numericUpDown3.Value = new decimal(new int[] {
12,
0,
0,
0});
this.numericUpDown3.ValueChanged += new System.EventHandler(this.numericUpDown3_ValueChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(136, 26);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(41, 12);
this.label1.TabIndex = 4;
this.label1.Text = "线宽:";
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.Red;
this.panel1.Location = new System.Drawing.Point(55, 22);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(72, 21);
this.panel1.TabIndex = 14;
this.panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown);
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(13, 26);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(41, 12);
this.label7.TabIndex = 13;
this.label7.Text = "颜色:";
//
// button9
//
this.button9.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button9.Location = new System.Drawing.Point(617, 21);
this.button9.Name = "button9";
this.button9.Size = new System.Drawing.Size(75, 23);
this.button9.TabIndex = 3;
this.button9.Text = "任意方向";
this.button9.UseVisualStyleBackColor = true;
this.button9.Click += new System.EventHandler(this.button9_Click);
//
// button8
//
this.button8.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button8.Location = new System.Drawing.Point(535, 21);
this.button8.Name = "button8";
this.button8.Size = new System.Drawing.Size(75, 23);
this.button8.TabIndex = 2;
this.button8.Text = "垂直方向";
this.button8.UseVisualStyleBackColor = true;
this.button8.Click += new System.EventHandler(this.button8_Click);
//
// button7
//
this.button7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button7.Location = new System.Drawing.Point(453, 21);
this.button7.Name = "button7";
this.button7.Size = new System.Drawing.Size(75, 23);
this.button7.TabIndex = 1;
this.button7.Text = "水平方向";
this.button7.UseVisualStyleBackColor = true;
this.button7.Click += new System.EventHandler(this.button7_Click);
//
// button4
//
this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.button4.Location = new System.Drawing.Point(698, 21);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(75, 23);
this.button4.TabIndex = 0;
this.button4.Text = "保存标尺";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// groupBox3
//
this.groupBox3.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.groupBox3.Location = new System.Drawing.Point(135, 72);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(585, 386);
this.groupBox3.TabIndex = 3;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "标尺图像";
//
// groupBox4
//
this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.groupBox4.Controls.Add(this.label17);
this.groupBox4.Controls.Add(this.label16);
this.groupBox4.Controls.Add(this.label15);
this.groupBox4.Controls.Add(this.label14);
this.groupBox4.Controls.Add(this.label13);
this.groupBox4.Controls.Add(this.label12);
this.groupBox4.Controls.Add(this.comboBox1);
this.groupBox4.Controls.Add(this.textBox6);
this.groupBox4.Controls.Add(this.textBox5);
this.groupBox4.Controls.Add(this.textBox4);
this.groupBox4.Controls.Add(this.textBox2);
this.groupBox4.Controls.Add(this.textBox1);
this.groupBox4.Location = new System.Drawing.Point(726, 72);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(187, 189);
this.groupBox4.TabIndex = 4;
this.groupBox4.TabStop = false;
this.groupBox4.Visible = false;
//
// label17
//
this.label17.AutoSize = true;
this.label17.Location = new System.Drawing.Point(9, 164);
this.label17.Name = "label17";
this.label17.Size = new System.Drawing.Size(0, 12);
this.label17.TabIndex = 13;
//
// label16
//
this.label16.AutoSize = true;
this.label16.Location = new System.Drawing.Point(9, 136);
this.label16.Name = "label16";
this.label16.Size = new System.Drawing.Size(0, 12);
this.label16.TabIndex = 12;
//
// label15
//
this.label15.AutoSize = true;
this.label15.Location = new System.Drawing.Point(9, 108);
this.label15.Name = "label15";
this.label15.Size = new System.Drawing.Size(0, 12);
this.label15.TabIndex = 11;
//
// label14
//
this.label14.AutoSize = true;
this.label14.Location = new System.Drawing.Point(9, 80);
this.label14.Name = "label14";
this.label14.Size = new System.Drawing.Size(0, 12);
this.label14.TabIndex = 10;
//
// label13
//
this.label13.AutoSize = true;
this.label13.Location = new System.Drawing.Point(9, 52);
this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(0, 12);
this.label13.TabIndex = 9;
//
// label12
//
this.label12.AutoSize = true;
this.label12.Location = new System.Drawing.Point(9, 24);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(0, 12);
this.label12.TabIndex = 8;
//
// comboBox1
//
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(75, 76);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(106, 20);
this.comboBox1.TabIndex = 7;
//
// textBox6
//
this.textBox6.Location = new System.Drawing.Point(75, 160);
this.textBox6.Name = "textBox6";
this.textBox6.Size = new System.Drawing.Size(106, 21);
this.textBox6.TabIndex = 6;
//
// textBox5
//
this.textBox5.Location = new System.Drawing.Point(75, 132);
this.textBox5.Name = "textBox5";
this.textBox5.Size = new System.Drawing.Size(106, 21);
this.textBox5.TabIndex = 5;
//
// textBox4
//
this.textBox4.Location = new System.Drawing.Point(75, 104);
this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(106, 21);
this.textBox4.TabIndex = 4;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(76, 48);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(106, 21);
this.textBox2.TabIndex = 2;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(75, 20);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(106, 21);
this.textBox1.TabIndex = 1;
//
// groupBox5
//
this.groupBox5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.groupBox5.Controls.Add(this.label23);
this.groupBox5.Controls.Add(this.label22);
this.groupBox5.Controls.Add(this.label21);
this.groupBox5.Controls.Add(this.label20);
this.groupBox5.Controls.Add(this.label19);
this.groupBox5.Controls.Add(this.label18);
this.groupBox5.Controls.Add(this.textBox12);
this.groupBox5.Controls.Add(this.textBox11);
this.groupBox5.Controls.Add(this.textBox10);
this.groupBox5.Controls.Add(this.textBox9);
this.groupBox5.Controls.Add(this.textBox8);
this.groupBox5.Controls.Add(this.textBox7);
this.groupBox5.Location = new System.Drawing.Point(726, 267);
this.groupBox5.Name = "groupBox5";
this.groupBox5.Size = new System.Drawing.Size(187, 191);
this.groupBox5.TabIndex = 5;
this.groupBox5.TabStop = false;
this.groupBox5.Visible = false;
//
// label23
//
this.label23.AutoSize = true;
this.label23.Location = new System.Drawing.Point(9, 165);
this.label23.Name = "label23";
this.label23.Size = new System.Drawing.Size(0, 12);
this.label23.TabIndex = 11;
//
// label22
//
this.label22.AutoSize = true;
this.label22.Location = new System.Drawing.Point(9, 137);
this.label22.Name = "label22";
this.label22.Size = new System.Drawing.Size(0, 12);
this.label22.TabIndex = 10;
//
// label21
//
this.label21.AutoSize = true;
this.label21.Location = new System.Drawing.Point(9, 109);
this.label21.Name = "label21";
this.label21.Size = new System.Drawing.Size(0, 12);
this.label21.TabIndex = 9;
//
// label20
//
this.label20.AutoSize = true;
this.label20.Location = new System.Drawing.Point(9, 81);
this.label20.Name = "label20";
this.label20.Size = new System.Drawing.Size(0, 12);
this.label20.TabIndex = 8;
//
// label19
//
this.label19.AutoSize = true;
this.label19.Location = new System.Drawing.Point(9, 53);
this.label19.Name = "label19";
this.label19.Size = new System.Drawing.Size(0, 12);
this.label19.TabIndex = 7;
//
// label18
//
this.label18.AutoSize = true;
this.label18.Location = new System.Drawing.Point(9, 25);
this.label18.Name = "label18";
this.label18.Size = new System.Drawing.Size(0, 12);
this.label18.TabIndex = 6;
//
// textBox12
//
this.textBox12.Location = new System.Drawing.Point(75, 161);
this.textBox12.Name = "textBox12";
this.textBox12.Size = new System.Drawing.Size(106, 21);
this.textBox12.TabIndex = 5;
//
// textBox11
//
this.textBox11.Location = new System.Drawing.Point(75, 133);
this.textBox11.Name = "textBox11";
this.textBox11.Size = new System.Drawing.Size(106, 21);
this.textBox11.TabIndex = 4;
//
// textBox10
//
this.textBox10.Location = new System.Drawing.Point(75, 105);
this.textBox10.Name = "textBox10";
this.textBox10.Size = new System.Drawing.Size(106, 21);
this.textBox10.TabIndex = 3;
//
// textBox9
//
this.textBox9.Location = new System.Drawing.Point(75, 77);
this.textBox9.Name = "textBox9";
this.textBox9.Size = new System.Drawing.Size(106, 21);
this.textBox9.TabIndex = 2;
//
// textBox8
//
this.textBox8.Location = new System.Drawing.Point(75, 49);
this.textBox8.Name = "textBox8";
this.textBox8.Size = new System.Drawing.Size(106, 21);
this.textBox8.TabIndex = 1;
//
// textBox7
//
this.textBox7.Location = new System.Drawing.Point(75, 21);
this.textBox7.Name = "textBox7";
this.textBox7.Size = new System.Drawing.Size(106, 21);
this.textBox7.TabIndex = 0;
//
// panel2
//
this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel2.BackColor = System.Drawing.SystemColors.Control;
this.panel2.Controls.Add(this.label10);
this.panel2.Controls.Add(this.label11);
this.panel2.Controls.Add(this.label9);
this.panel2.Controls.Add(this.trackBar1);
this.panel2.Controls.Add(this.numericUpDown2);
this.panel2.Controls.Add(this.label6);
this.panel2.Controls.Add(this.label5);
this.panel2.Controls.Add(this.label4);
this.panel2.Controls.Add(this.label3);
this.panel2.Controls.Add(this.label2);
this.panel2.Controls.Add(this.label8);
this.panel2.Controls.Add(this.pictureBox1);
this.panel2.Controls.Add(this.linearColorPickerControl1);
this.panel2.Location = new System.Drawing.Point(726, 79);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(187, 379);
this.panel2.TabIndex = 0;
this.panel2.Visible = false;
//
// label10
//
this.label10.AutoSize = true;
this.label10.BackColor = System.Drawing.Color.Transparent;
this.label10.Location = new System.Drawing.Point(6, 22);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(17, 12);
this.label10.TabIndex = 30;
this.label10.Text = "Y=";
//
// label11
//
this.label11.AutoSize = true;
this.label11.BackColor = System.Drawing.Color.Transparent;
this.label11.Location = new System.Drawing.Point(6, 6);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(17, 12);
this.label11.TabIndex = 29;
this.label11.Text = "X=";
//
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(47, 113);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(0, 12);
this.label9.TabIndex = 28;
//
// trackBar1
//
this.trackBar1.Location = new System.Drawing.Point(70, 109);
this.trackBar1.Minimum = 1;
this.trackBar1.Name = "trackBar1";
this.trackBar1.Size = new System.Drawing.Size(91, 45);
this.trackBar1.TabIndex = 27;
this.trackBar1.TickStyle = System.Windows.Forms.TickStyle.None;
this.trackBar1.Value = 1;
this.trackBar1.ValueChanged += new System.EventHandler(this.trackBar1_ValueChanged);
//
// numericUpDown2
//
this.numericUpDown2.Location = new System.Drawing.Point(6, 109);
this.numericUpDown2.Maximum = new decimal(new int[] {
10,
0,
0,
0});
this.numericUpDown2.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.numericUpDown2.Name = "numericUpDown2";
this.numericUpDown2.Size = new System.Drawing.Size(37, 21);
this.numericUpDown2.TabIndex = 26;
this.numericUpDown2.Value = new decimal(new int[] {
1,
0,
0,
0});
this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged);
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(126, 90);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(11, 12);
this.label6.TabIndex = 25;
this.label6.Text = "V";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(126, 74);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(11, 12);
this.label5.TabIndex = 24;
this.label5.Text = "S";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(126, 58);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(11, 12);
this.label4.TabIndex = 23;
this.label4.Text = "H";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(126, 36);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(11, 12);
this.label3.TabIndex = 22;
this.label3.Text = "B";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(126, 20);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(11, 12);
this.label2.TabIndex = 21;
this.label2.Text = "G";
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(126, 4);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(35, 12);
this.label8.TabIndex = 20;
this.label8.Text = "R=255";
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(3, 3);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(100, 100);
this.pictureBox1.TabIndex = 19;
this.pictureBox1.TabStop = false;
this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
//
// linearColorPickerControl1
//
this.linearColorPickerControl1.Count = 1;
this.linearColorPickerControl1.CustomGradient = new System.Drawing.Color[] {
System.Drawing.Color.White,
System.Drawing.Color.Yellow,
System.Drawing.Color.Red,
System.Drawing.Color.Green,
System.Drawing.Color.Blue,
System.Drawing.Color.Black};
this.linearColorPickerControl1.DrawFarNub = true;
this.linearColorPickerControl1.DrawNearNub = true;
this.linearColorPickerControl1.Location = new System.Drawing.Point(106, 3);
this.linearColorPickerControl1.MaxColor = System.Drawing.Color.White;
this.linearColorPickerControl1.MinColor = System.Drawing.Color.Black;
this.linearColorPickerControl1.Name = "linearColorPickerControl1";
this.linearColorPickerControl1.Orientation = System.Windows.Forms.Orientation.Vertical;
this.linearColorPickerControl1.Size = new System.Drawing.Size(14, 100);
this.linearColorPickerControl1.TabIndex = 18;
this.linearColorPickerControl1.TabStop = false;
this.linearColorPickerControl1.Value = 153;
this.linearColorPickerControl1.ValueChanged += new PaintDotNet.IndexEventHandler(this.linearColorPickerControl1_ValueChanged);
//
// RuleAddForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(922, 467);
this.Controls.Add(this.panel2);
this.Controls.Add(this.groupBox5);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Name = "RuleAddForm";
this.Text = "新建标尺";
this.Controls.SetChildIndex(this.groupBox1, 0);
this.Controls.SetChildIndex(this.groupBox2, 0);
this.Controls.SetChildIndex(this.groupBox3, 0);
this.Controls.SetChildIndex(this.groupBox4, 0);
this.Controls.SetChildIndex(this.groupBox5, 0);
this.Controls.SetChildIndex(this.panel2, 0);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).EndInit();
this.groupBox4.ResumeLayout(false);
this.groupBox4.PerformLayout();
this.groupBox5.ResumeLayout(false);
this.groupBox5.PerformLayout();
this.panel2.ResumeLayout(false);
this.panel2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
}
#endregion
//
//初始化其他控件
//
private void InitOtherTools()
{
//
//调色板
//
this.colorsForm1 = new ColorsForm();
this.colorsForm1.StartPosition = FormStartPosition.CenterScreen;
this.colorsForm1.setSaveBtn_Click(new System.EventHandler(this.colorsForm1Changed));
//
//字号
//
font = new Font("常规", (int)this.numericUpDown3.Value);
}
private void colorsForm1Changed(object sender, EventArgs e)
{
this.panel1.BackColor = this.colorsForm1.UserPrimaryColor.ToColor();
this.colorsForm1.Close();
}
///
/// 像素跟踪的颜色控件
///
///
///
private void linearColorPickerControl1_ValueChanged(object sender, IndexEventArgs ce)
{
this.color = this.linearColorPickerControl1.ValueToColor(this.linearColorPickerControl1.Value);
this.pictureBox1.Refresh();
}
///
/// 构造函数
///
/// 1新增 2编辑
public RuleAddForm(int status, AppWorkspace appWorkspace)
{
this.status = status;
this.appWorkspace = appWorkspace;
InitializeComponent();
InitializeLanguageText();
InitOtherTools();
this.Text = PdnResources.GetString("Menu.Imagement.Rulersetting.Newruler.text");
//
//初始化图像控件
//
this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
this.documentWorkspace.Dock = DockStyle.Fill;
this.documentWorkspace.HookMouseEvents();
this.documentWorkspace.pixelTrackingEnabled = false;
//this.documentWorkspace.SurfaceBox.RemoveMouseEvent();
this.documentWorkspace.AuxiliaryLineEnabled = true;
this.documentWorkspace.Visible = false;
this.groupBox3.Controls.Add(documentWorkspace);
//
//初始化操作按钮
//
this.commonControlButtons = new CommonControlButtons();
this.commonControlButtons.Dock = DockStyle.Top;
this.commonControlButtons.Height = 30;
this.groupBox3.Controls.Add(commonControlButtons);
this.groupBox3.Width = this.groupBox3.Width + this.groupBox4.Width + 6;
InitializeUI();
this.comboBox1.Text = PdnResources.GetString("Menu.easeselectmeasurementunit.Text");
this.comboBox1.DataSource = new BindingSource(InvariantData.ruleUnitsDictionary, null);
this.comboBox1.DisplayMember = "Value";
this.comboBox1.ValueMember = "Key";
this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
this.comboBox1.SelectedIndex = 4;
InitializeHint();
this.width = (int)this.numericUpDown1.Value;
this.textBox4.ReadOnly = true;
InitCommonButtonEvent();
//自定义线形的线帽,已达到标尺垂线的效果
hPath.AddLine(new PointF(-6, 0), new PointF(6, 0));
HookCap = new CustomLineCap(null, hPath);
HookCap.SetStrokeCaps(LineCap.Flat, LineCap.Flat);
HookCap.WidthScale = 0.5f;
}
private void InitCommonButtonEvent()
{
this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
}
private void zoomInButton_Click(object sender, EventArgs e)
{
this.documentWorkspace.ZoomIn();
}
private void zoomOutButton_Click(object sender, EventArgs e)
{
this.documentWorkspace.ZoomOut();
}
private void zoomToWindowButton_Click(object sender, EventArgs e)
{
this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
}
private void actualSizeButton_Click(object sender, EventArgs e)
{
this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
}
private void pointerButton_Click(object sender, EventArgs e)
{
this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer;
}
private void mobileModeButton_Click(object sender, EventArgs e)
{
this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
}
///
/// 编辑时初始化数据
///
public void InitializeEditData()
{
//打开图片
if(ruleFileModel!=null && ruleFileModel.picBase64!=null)
{
//string base64Img = "data:image/png;base64," + ruleFileModel.picBase64;
bitmap = DrawRulerHelper.Base64StringToImage(ruleFileModel.picBase64);
Document document = Document.FromImage(bitmap);
documentWorkspace.Document = document;
this.documentWorkspace.Visible = true;
startPoint = new System.Drawing.Point(ruleFileModel.startPointX, ruleFileModel.startPointY);
endPoint = new System.Drawing.Point(ruleFileModel.endPointX, ruleFileModel.endPointY);
this.panel1.BackColor = Color.FromArgb(ruleFileModel.lineColor);
this.brush = new SolidBrush(this.panel1.BackColor);
this.numericUpDown1.Value = ruleFileModel.lineWidth;
this.numericUpDown3.Value = Math.Max(1, ruleFileModel.textSize);
AddPictureBoxEvent();
}
if(ruleModel != null)
{
this.textBox2.Text = ruleModel.gain_multiple.ToString();
this.textBox12.Text = ruleModel.microscope;
this.textBox11.Text = ruleModel.objective_lens;
this.textBox5.Text = ruleModel.physical_length.ToString();
this.textBox6.Text = ruleModel.pixel_length.ToString();
this.textBox10.Text = ruleModel.ruler_camera;
this.textBox8.Text = ruleModel.ruler_connector;
this.textBox9.Text = ruleModel.ruler_eyepiece;
this.textBox1.Text = ruleModel.ruler_name;
this.comboBox1.SelectedValue = ruleModel.ruler_units;
this.textBox7.Text = ruleModel.ruler_zoom;
this.textBox4.Text = ruleModel.ruler_width + "×" + ruleModel.ruler_height;
}
}
private void MouseDownHandler(object sender, MouseEventArgs e)
{
if (documentWorkspace != null)
{
//if (documentWorkspace.Tool != null)
// documentWorkspace.Tool.PerformMouseDown(e);
}
}
private void MouseMoveHandler(object sender, MouseEventArgs e)
{
if (documentWorkspace != null)
{
//if (documentWorkspace.Tool != null)
// documentWorkspace.Tool.PerformMouseMove(e);
}
}
private void MouseUpHandler(object sender, MouseEventArgs e)
{
if (documentWorkspace != null)
{
//if (documentWorkspace.Tool != null)
// documentWorkspace.Tool.PerformMouseUp(e);
}
}
///
/// 打开图片/保存标尺
/// 公用按钮
///
///
///
private void button4_Click(object sender, EventArgs e)
{
//保存标尺
if (step == 3)
{
if (this.textBox1.Text.Equals(""))
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterarulername.text"));
return;
}
if (this.textBox2.Text.Equals(""))
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterthemagnification.text"));
return;
}
if (this.textBox5.Text.Equals(""))
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterthephysicallength.text"));
return;
}
if (startPoint == endPoint)
{
MessageBox.Show(PdnResources.GetString("Menu.asereturntothesecondsteptodrawther.Text")+"!");
return;
}
if (this.status == 1)
{
try
{
//判断标尺是否存在
for (int i = 0; i < Startup.instance.mic_rulersAll.Count; i++)
{
if (Startup.instance.mic_rulersAll[i].ruler_name.Equals(this.textBox1.Text))
{
MessageBox.Show(PdnResources.GetString("Menu.hecurrentscalenamealreadyexists.Text"));
return;
}
}
//组织数据,保存到数据库
mic_rulers rule = new mic_rulers();
rule.gain_multiple = decimal.Parse(this.textBox2.Text);
if (rule.gain_multiple<1)
{
MessageBox.Show("放大倍数错误,请检查!");
return;
}
rule.microscope = this.textBox12.Text;
rule.objective_lens = this.textBox11.Text;
rule.physical_length = decimal.Parse(this.textBox5.Text);
rule.pixel_length = float.Parse(this.textBox6.Text);
rule.ruler_camera = this.textBox10.Text;
rule.ruler_connector = this.textBox8.Text;
rule.ruler_eyepiece = this.textBox9.Text;
rule.ruler_height = this.bitmap.Height;
rule.ruler_name = this.textBox1.Text;
rule.ruler_units = (int)this.comboBox1.SelectedValue;
rule.ruler_width = this.bitmap.Width;
rule.ruler_zoom = this.textBox7.Text;
rule.ruler_type = 1;
mic_rulers_BLL.Add(rule);
Startup.instance.mic_rulersAll.Add(rule);
//生成xml文件
ruleFileModel = new RulerFileModel();
ruleFileModel.startPointX = startPoint.X;
ruleFileModel.startPointY = startPoint.Y;
ruleFileModel.endPointX = endPoint.X;
ruleFileModel.endPointY = endPoint.Y;
ruleFileModel.lineColor = this.panel1.BackColor.ToArgb();
ruleFileModel.lineWidth = width;
ruleFileModel.textSize = this.numericUpDown3.Value;
ruleFileModel.picBase64 = DrawRulerHelper.ImgToBase64String(this.documentWorkspace.CompositionSurface.CreateAliasedBitmap());
//保存xml文件
string userInfoXml = XmlSerializeHelper.XmlSerialize(ruleFileModel);
string folderPath = Application.StartupPath + "\\RuleFile\\";
if (!Directory.Exists(folderPath)) Directory.CreateDirectory(folderPath);
string filePath = rule.id + ".xml";
FileOperationHelper.WriteStringToFile(userInfoXml, folderPath + filePath, FileMode.Create);
this.Close();
}
catch (Exception)
{
System.Console.WriteLine(e.ToString());
MessageBox.Show(PdnResources.GetString("Menu.Rulerinformationsavingfaile.Text"));
}
}
else if(this.status == 2)
{
try
{
//判断标尺是否存在
for (int i = 0; i < Startup.instance.mic_rulersAll.Count; i++)
{
if (Startup.instance.mic_rulersAll[i].id == ruleModel.id)
continue;
if (Startup.instance.mic_rulersAll[i].ruler_name.Equals(this.textBox1.Text))
{
MessageBox.Show(PdnResources.GetString("Menu.hecurrentscalenamealreadyexists.Text"));
return;
}
}
//组织数据,保存到数据库
ruleModel.gain_multiple = decimal.Parse(this.textBox2.Text);
if (ruleModel.gain_multiple < 1)
{
MessageBox.Show("放大倍数错误,请检查!");
return;
}
ruleModel.microscope = this.textBox12.Text;
ruleModel.objective_lens = this.textBox11.Text;
ruleModel.physical_length = decimal.Parse(this.textBox5.Text);
ruleModel.pixel_length = float.Parse(this.textBox6.Text);
ruleModel.ruler_camera = this.textBox10.Text;
ruleModel.ruler_connector = this.textBox8.Text;
ruleModel.ruler_eyepiece = this.textBox9.Text;
ruleModel.ruler_height = this.bitmap.Height;
ruleModel.ruler_name = this.textBox1.Text;
ruleModel.ruler_units = (int)this.comboBox1.SelectedValue;
ruleModel.ruler_width = this.bitmap.Width;
ruleModel.ruler_zoom = this.textBox7.Text;
ruleModel.ruler_type = 1;
mic_rulers_BLL.Update(ruleModel);
//生成xml文件
ruleFileModel = new RulerFileModel();
ruleFileModel.startPointX = startPoint.X;
ruleFileModel.startPointY = startPoint.Y;
ruleFileModel.endPointX = endPoint.X;
ruleFileModel.endPointY = endPoint.Y;
ruleFileModel.lineColor = this.panel1.BackColor.ToArgb();
ruleFileModel.lineWidth = width;
ruleFileModel.textSize = this.numericUpDown3.Value;
ruleFileModel.picBase64 = DrawRulerHelper.ImgToBase64String(this.documentWorkspace.CompositionSurface.CreateAliasedBitmap());
//保存xml文件
string userInfoXml = XmlSerializeHelper.XmlSerialize(ruleFileModel);
string filePath = Application.StartupPath + "\\RuleFile\\" + ruleModel.id + ".xml";
FileOperationHelper.WriteStringToFile(userInfoXml, filePath, FileMode.Create);
this.Close();
this.appWorkspace.RefreshActiveRuler();
}
catch (Exception)
{
System.Console.WriteLine(e.ToString());
MessageBox.Show(PdnResources.GetString("Menu.Rulerinformationsavingfaile.Text"));
}
}
//刷新标尺列表
this.appWorkspace.RefueshRuleList();
//刷新预览窗口
if (CameraPreviewDialog.cameraPreviewDialog != null)
CameraPreviewDialog.cameraPreviewDialog.BindingRule();
}
else
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "图像文件(*.gif;*.jpg;*.jpeg;*.png)|*.gif;*.jpg;*.jpeg;*.png";
dialog.ShowDialog();
if (dialog.FileName != String.Empty)
{
try
{
bitmap = new Bitmap(dialog.FileName);
Document document = Document.FromImage(bitmap);
documentWorkspace.Document = document;
this.documentWorkspace.Visible = true;
this.textBox4.Text = bitmap.Width + "×" + bitmap.Height;
this.mat = null;
this.startPoint = System.Drawing.Point.Empty;
this.endPoint = System.Drawing.Point.Empty;
RemoveDocEvent();
AddPictureBoxEvent();
}
catch(Exception)
{
MessageBox.Show("打开图像失败, 请确认");
}
}
}
}
///
/// 下一步
///
///
///
private void button5_Click(object sender, EventArgs e)
{
if (step == 1) {
if (bitmap == null)
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectrulerimage.Text")+"!");
return;
}
}
if (!this.panel2.Visible && !this.groupBox4.Visible)
{
this.groupBox3.Width = this.groupBox3.Width - this.groupBox4.Width - 3;
}
step++;
InitializeUI();
}
///
/// 上一步
///
///
///
private void button6_Click(object sender, EventArgs e)
{
step--;
if (step == 1)
{
if (this.panel2.Visible || this.groupBox4.Visible)
{
this.groupBox3.Width = this.groupBox3.Width + this.groupBox4.Width + 3;
}
this.panel2.Visible = false;
this.groupBox4.Visible = false;
this.groupBox5.Visible = false;
}
InitializeUI();
}
///
/// 初始化UI
///
private void InitializeUI() {
if (step == 1) {
this.label1.Visible = false;
this.panel1.Visible = false;
this.label7.Visible = false;
this.label24.Visible = false;
this.numericUpDown1.Visible = false;
this.numericUpDown3.Visible = false;
this.button7.Visible = false;
this.button8.Visible = false;
this.button9.Visible = false;
this.button5.Enabled = true;
this.button6.Enabled = false;
this.button4.Visible = true;
this.button4.Text = PdnResources.GetString("Menu.Openimage.text");
this.button1.BackColor = Color.Black;
this.button1.ForeColor = Color.White;
this.button2.BackColor = Color.White;
this.button2.ForeColor = Color.Black;
this.button3.BackColor = Color.White;
this.button3.ForeColor = Color.Black;
}
if (step == 2) {
this.label1.Visible = true;
this.panel1.Visible = true;
this.label7.Visible = true;
this.label24.Visible = true;
this.numericUpDown1.Visible = true;
this.numericUpDown3.Visible = true;
this.button7.Visible = true;
this.button8.Visible = true;
this.button9.Visible = true;
this.button6.Enabled = true;
this.button5.Enabled = true;
this.panel2.Visible = true;
this.groupBox4.Visible = false;
this.groupBox5.Visible = false;
this.button4.Visible = false;
this.button4.Text = PdnResources.GetString("Menu.Openimage.text");
this.button2.BackColor = Color.Black;
this.button2.ForeColor = Color.White;
this.button1.BackColor = Color.White;
this.button1.ForeColor = Color.Black;
this.button3.BackColor = Color.White;
this.button3.ForeColor = Color.Black;
}
if (step == 3) {
this.label1.Visible = false;
this.panel1.Visible = false;
this.label7.Visible = false;
this.label24.Visible = false;
this.numericUpDown1.Visible = false;
this.numericUpDown3.Visible = false;
this.button7.Visible = false;
this.button8.Visible = false;
this.button9.Visible = false;
this.button6.Enabled = true;
this.button5.Enabled = false;
this.button4.Visible = true;
this.button4.Text = PdnResources.GetString("Menu.Savetheruler.text");
this.panel2.Visible = false;
this.groupBox4.Visible = true;
this.groupBox5.Visible = true;
this.button3.BackColor = Color.Black;
this.button3.ForeColor = Color.White;
this.button1.BackColor = Color.White;
this.button1.ForeColor = Color.Black;
this.button2.BackColor = Color.White;
this.button2.ForeColor = Color.Black;
}
}
///
/// 初始化hint提示信息
///
private void InitializeHint()
{
SystemLayer.SafeNativeMethods.SetCueText(this.textBox1, PdnResources.GetString("Menu.Pleaseenterarulername.text"));
SystemLayer.SafeNativeMethods.SetCueText(this.textBox2, PdnResources.GetString("Menu.Pleaseenterthemagnification.text"));
SystemLayer.SafeNativeMethods.SetCueText(this.textBox4, PdnResources.GetString("Menu.Pleaseinputimageresolution.Text"));
SystemLayer.SafeNativeMethods.SetCueText(this.textBox5, PdnResources.GetString("Menu.Pleaseenterthephysicallength.text"));
SystemLayer.SafeNativeMethods.SetCueText(this.textBox6, PdnResources.GetString("Menu.Pixellength.text"));
SystemLayer.SafeNativeMethods.SetCueText(this.textBox7, PdnResources.GetString("Menu.Pleaseentetionchanger.text"));
SystemLayer.SafeNativeMethods.SetCueText(this.textBox8, PdnResources.GetString("Menu.Pleaseentertheinterface.text"));
SystemLayer.SafeNativeMethods.SetCueText(this.textBox9, PdnResources.GetString("Menu.Pleaseentertheeyepiece.text"));
SystemLayer.SafeNativeMethods.SetCueText(this.textBox10, PdnResources.GetString("Menu.Pleaseenterthecamera.text"));
SystemLayer.SafeNativeMethods.SetCueText(this.textBox11, PdnResources.GetString("Menu.Pleaseenterobjectlens.text"));
SystemLayer.SafeNativeMethods.SetCueText(this.textBox12, PdnResources.GetString("Menu.Pleaseenterthemicroscope.text"));
}
///
/// 第一步
///
///
///
private void button1_Click(object sender, EventArgs e)
{
if (this.panel2.Visible || this.groupBox4.Visible)
{
this.groupBox3.Width = this.groupBox3.Width + this.groupBox4.Width + 3;
}
this.panel2.Visible = false;
this.groupBox4.Visible = false;
this.groupBox5.Visible = false;
step = 1;
InitializeUI();
}
///
/// 第二步
///
///
///
private void button2_Click(object sender, EventArgs e)
{
if (bitmap==null) {
MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectrulerimage.Text")+"!");
return;
}
if (!this.panel2.Visible && !this.groupBox4.Visible)
{
this.groupBox3.Width = this.groupBox3.Width - this.groupBox4.Width - 3;
}
this.panel2.Visible = true;
this.groupBox4.Visible = false;
this.groupBox5.Visible = false;
this.button4.Text = PdnResources.GetString("Menu.Openimage.text");
step = 2;
InitializeUI();
}
///
/// 第三步
///
///
///
private void button3_Click(object sender, EventArgs e)
{
if (bitmap == null)
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectrulerimage.Text")+"!");
return;
}
if (!this.panel2.Visible && !this.groupBox4.Visible)
{
this.groupBox3.Width = this.groupBox3.Width - this.groupBox4.Width - 3;
}
this.panel2.Visible = false;
this.groupBox4.Visible = true;
this.groupBox5.Visible = true;
step = 3;
InitializeUI();
}
///
/// 颜色选择
///
///
///
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
this.colorsForm1.UserPrimaryColor = ColorBgra.FromColor(this.panel1.BackColor);
this.colorsForm1.ShowDialog();
}
///
/// 水平方向
///
///
///
private void button7_Click(object sender, EventArgs e)
{
direction = 1;
RemoveDocEvent();
AddPictureBoxEvent();
}
///
/// 垂直方向
///
///
///
private void button8_Click(object sender, EventArgs e)
{
direction = 2;
RemoveDocEvent();
AddPictureBoxEvent();
}
///
/// 任意方向
///
///
///
private void button9_Click(object sender, EventArgs e)
{
direction = 3;
RemoveDocEvent();
AddPictureBoxEvent();
}
///
/// 添加事件
///
private void AddPictureBoxEvent()
{
this.documentWorkspace.panel.MouseDown += new MouseEventHandler(this.BoxMouseDownHandler);
this.documentWorkspace.panel.MouseMove += new MouseEventHandler(this.BoxMouseMoveHandler);
this.documentWorkspace.panel.MouseUp += new MouseEventHandler(this.BoxMouseUpHandler);
this.documentWorkspace.panel.Paint += new PaintEventHandler(this.BoxPaintHandler);
}
///
/// 绘制事件
///
///
///
private void BoxPaintHandler(object sender, PaintEventArgs e)
{
if (startPoint!=null && endPoint!=null)
{
Rectangle rc = this.documentWorkspace.panel.ClientRectangle;
int width1 = (int)(this.documentWorkspace.CompositionSurface.Width * this.documentWorkspace.ScaleFactor.Ratio);
int height1 = (int)(this.documentWorkspace.CompositionSurface.Height * this.documentWorkspace.ScaleFactor.Ratio);
int x = (rc.Width < width1) ? this.documentWorkspace.panel.AutoScrollPosition.X : (rc.Width - width1) / 2;
int y = (rc.Height < height1) ? this.documentWorkspace.panel.AutoScrollPosition.Y : (rc.Height - height1) / 2;
double length = BasicCalculationHelper.GetDistance(startPoint, endPoint, 2);
e.Graphics.TranslateTransform(x, y);
e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio);
Pen linePen = new Pen(this.panel1.BackColor);
brush = new SolidBrush(this.panel1.BackColor);
linePen.Width = width;
linePen.CustomStartCap = HookCap;
linePen.CustomEndCap = HookCap;
e.Graphics.DrawLine(linePen, startPoint, endPoint);
linePen.Dispose();
//参考下,然后绘制带角度的文字https://www.jianshu.com/p/404ed85887e6
if (length > 0)
{
//计算需要旋转的角度
double angle = BasicCalculationHelper.Angle(startPoint, endPoint, new System.Drawing.Point(startPoint.X, endPoint.Y));
//原始旋转矩阵
Matrix mtxSave = e.Graphics.Transform;
Matrix matrix = e.Graphics.Transform;
matrix.RotateAt((float)angle, new PointF(startPoint.X, startPoint.Y));
e.Graphics.Transform = matrix;
e.Graphics.DrawString(length + "px", font, brush, startPoint.X, startPoint.Y);
//还原为原始旋转矩阵
e.Graphics.Transform = mtxSave;
this.textBox6.Text = length.ToString();//将像素长度传递至第三步
}
e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio);
e.Graphics.TranslateTransform(-x, -y);
}
}
private void BoxMouseUpHandler(object sender, MouseEventArgs e)
{
this.pressFlag = false;
if (e.Button == MouseButtons.Left)
direction = 0;
}
private void BoxMouseMoveHandler(object sender, MouseEventArgs e)
{
if (this.bitmap != null)
{
this.SetImageAndData(this.documentWorkspace.CalcPixelPoint(e.Location));
}
if (this.pressFlag && direction > 0 && e.Button == MouseButtons.Left) {
System.Drawing.Point point = e.Location;
if (direction == 1)
{
point.Y = y;
}
else if (direction == 2)
{
point.X = x;
}
this.endPoint = this.documentWorkspace.GetScalePoint(point);
this.documentWorkspace.Refresh();
}
}
private void numericUpDown2_ValueChanged(object sender, EventArgs e)
{
if (mat != null)
{
scale = (int)this.numericUpDown2.Value;
this.trackBar1.Value = scale;
}
}
private void trackBar1_ValueChanged(object sender, EventArgs e)
{
if (mat != null)
{
scale = this.trackBar1.Value;
this.numericUpDown2.Value = this.trackBar1.Value;
}
}
private void numericUpDown3_ValueChanged(object sender, EventArgs e)
{
font = new Font("常规", (int)this.numericUpDown3.Value);
this.documentWorkspace.Refresh();
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawLine(new Pen(color), 0, 50, 100, 50);
e.Graphics.DrawLine(new Pen(color), 50, 0, 50, 100);
e.Graphics.DrawEllipse(new Pen(color), new Rectangle(25, 25, 50, 50));
}
private void BoxMouseDownHandler(object sender, MouseEventArgs e)
{
this.pressFlag = true;
if (direction > 0 && e.Button == MouseButtons.Left) {
x = e.Location.X;
y = e.Location.Y;
startPoint = endPoint = this.documentWorkspace.GetScalePoint(e.Location);
}
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
this.width = (int)this.numericUpDown1.Value;
this.documentWorkspace.Refresh();
}
private void RemoveDocEvent()
{
this.documentWorkspace.DocumentMouseUp -= new MouseEventHandler(this.MouseUpHandler);
this.documentWorkspace.DocumentMouseMove -= new MouseEventHandler(this.MouseMoveHandler);
this.documentWorkspace.DocumentMouseDown -= new MouseEventHandler(this.MouseDownHandler);
}
///
/// 设置像素跟踪
///
///
public void SetImageAndData(System.Drawing.Point point)
{
if (this.documentWorkspace != null)
{
if (this.documentWorkspace.CompositionSurface != null)
{
scale = int.Parse(this.numericUpDown2.Value.ToString());
if (mat == null)
{
mat = this.documentWorkspace.CompositionSurface.CreatedAliasedMat().Clone();
Cv2.Resize(mat, bmat, new OpenCvSharp.Size(mat.Width * scale, mat.Height * scale));
Mat temp = new Mat(new OpenCvSharp.Size(bmat.Width + 100, bmat.Height + 100), bmat.Type());
Cv2.CopyMakeBorder(bmat, temp, 50, 50, 50, 50, BorderTypes.Constant, Scalar.All(255));
bmat = temp;
}
if (point.Y < 0) point.Y = 0;
if (point.X < 0) point.X = 0;
this.label11.Text = "X=" + point.X.ToString();
this.label10.Text = "Y=" + point.Y.ToString();
if (point.X< mat.Width && point.Y < mat.Height)
{
bgr = mat.At(point.Y, point.X);
this.label8.Text = "R=" + bgr[2];
this.label2.Text = "G=" + bgr[1];
this.label3.Text = "B=" + bgr[0];
BaseTools.RgbToHsv(bgr, out h, out s, out v);
this.label4.Text = "H=" + (int)(h / 2);
this.label5.Text = "S=" + (int)(s * 255);
this.label6.Text = "V=" + (int)(v * 255);
//设置源图像ROI
Rect roi = new Rect(point.X, point.Y, 100, 100);//首先要用个rect确定我们的兴趣区域在哪
ImageROI = new Mat(bmat, roi);
//按缩放比例截取小图像
Rect roi1 = new Rect((100 - 100 / scale) / 2, (100 - 100 / scale) / 2, 100 / scale, 100 / scale);
ImageROI = new Mat(ImageROI, roi1);
//按固定宽高放大图像
Cv2.Resize(ImageROI, ImageROI, new OpenCvSharp.Size(100, 100));
this.pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(ImageROI);
}
}
}
}
}
}