using OpenCvSharp;
using PaintDotNet.Annotation;
using PaintDotNet.Base.CommTool;
using PaintDotNet.Base.Functionodel;
using PaintDotNet.Base.SettingModel;
using PaintDotNet.CustomControl;
using PaintDotNet.DbOpreate.DbModel;
using PaintDotNet.Instrument;
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using Point = System.Drawing.Point;
using PaintDotNet.DedicatedAnalysis.GrainSizeStandard.IntegrationClass;
namespace PaintDotNet.DedicatedAnalysis.GrainSize
{
internal class GrainSizeStandardDialog : PdnBaseForm
{
///
/// 用于适配有色金属标准(包括GBT4296_2004、YST347_2004、GBT32461_2012的截距法和面积法)
///
protected bool isOtherGrainSizeStandardDialog = false;
#region 属性
///
/// 主控件
///
private AppWorkspace appWorkspace;
//二值化集成1
BinaryClass binaryClass;
///
/// 公共按钮
///
private CommonControlButtons commonControlButtons;
///
/// 图像面板
///
protected DocumentWorkspaceWindow documentWorkspace;
///
/// 当前选择的图片
///
protected Bitmap bitmap;
///
/// 当前选择的图片
///
protected Mat matOrg;
protected string oldSelectItem;
public bool comboboxChange = true;
//截点样式集成
protected GrainPointStyleClass styleClass = new GrainPointStyleClass();
///
/// 图形上所有的点
///
protected List linePointList = new List();
protected bool isAreaType = false;
///
/// 辅助线集成
///
protected GrainSizeGuideClass guideClass = new GrainSizeGuideClass();
///
/// 用于编号的坐标点集合
///
protected List massLabelPoints = new List();
///
/// 矩形内的连通域
///
protected int within = 0;
private PointF m_StartPoint = Point.Empty;
protected bool m_canMove;
///
/// 调色板
///
private ColorsForm colorsFormGrid;
//分析结果列表的头标题
///
/// PdnResources.GetString("Menu.picture.Text"), PdnResources.GetString("Menu.Tools.GridLine.Text"), "网格面积", PdnResources.GetString("Menu.Numberofgrains.text"), PdnResources.GetString("Menu.Averagegrainsizegrade.text")
///
List contentHead;
///
/// 保存用于生成报告的图片
///
protected List bitList;
///
/// 储存点击保存结果后的所有原图与分析图
///
protected Dictionary> bitDic = new Dictionary>();
///
/// 中间数据
///
protected List tempDataModel = new List();
///
/// 分析结果暂存
///
protected List dataTables = new List();
///
/// 全部显示
///
protected bool allShow = false;
#endregion
#region 组件
private GroupBox groupBox_operating;
protected GroupBox groupBox_img;
private ListView lstView_img;
private ImageList imageList_img;
private IContainer components;
protected GroupBox groupBox_review;
protected GroupBox groupBox_report;
private Label label_resultPrecision;
private Button button_exportResults;
private Button button_generateReport;
protected GroupBox groupBox6groupBox_analysisResult2;
protected GroupBox groupBox_analysisResult1;
private Button button_setting;
private CheckBox checkBox_generateReport_opensetting;
private GroupBox groupBox4;
private Panel panel1;
private Button button3;
private Label label8;
private NumericUpDown numericUpDown2;
private NumericUpDown numericUpDown1;
private CheckBox checkBox2;
private TextBox textBox6;
private Label label7;
private ComboBox comboBox3;
private Label label6;
private ComboBox comboBox2;
private Label label1;
private CheckBox checkBox1;
private GroupBox groupBox3;
private Button button9;
protected ComboBox comboBox1;
protected DataGridView dataGridView2;
protected ListView listView2;
private Button button16;
private Button button12;
private Button button11;
private NumericUpDown numericUpDown1_0;
private Button button1;
private BinaryControlSmaller bc;
private DataGridViewTextBoxColumn Column1;
private DataGridViewTextBoxColumn Column2;
private DataGridViewTextBoxColumn Column3;
private DataGridViewTextBoxColumn Column4;
private DataGridViewTextBoxColumn Column5;
private Button btn_saveresult;
#endregion
#region 构造函数
public GrainSizeStandardDialog(AppWorkspace appWorkspace, bool isAreaType, bool isOtherGrainSizeStandardDialog = false)
{
this.appWorkspace = appWorkspace;
this.Icon = PdnInfo.AppIcon;
this.Load += new System.EventHandler(this.GrainSizeStandardDialog_Load);
this.colorsFormGrid = new ColorsForm();
this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
this.isAreaType = isAreaType;
this.isOtherGrainSizeStandardDialog = isOtherGrainSizeStandardDialog;
if (isAreaType)
guideClass.createGuideAreaClassModelsNamed(getModelName());
else
guideClass.createGuideClassModelsNamed(getModelName());
InitializeComponent();
if (isOtherGrainSizeStandardDialog)
contentHead = new List() { PdnResources.GetString("Menu.picture.Text"), PdnResources.GetString("Menu.Tools.GridLine.Text"), PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.Gridsize.text") + "(μm)", PdnResources.GetString("Menu.Numberofgrains.text"), PdnResources.GetString("Menu.Averagegrainsizegrade.text") };
this.binaryClass = new BinaryClass();
if (isOtherGrainSizeStandardDialog)
InitializeCustomControl();
InitializeLanguageText();
Initialize();
SubclassInitialize();
//初始化头
this.listView2.View = View.Details;
ColumnHeader header0 = new ColumnHeader();
header0.Text = "";
header0.Width = 180;
this.listView2.Columns.Add(header0);
//二值化集成2
bc.OriginCheckedChangedAction += new EventHandler(this.bcOriginCheckedChanged);//初始化原图勾选改变事件
binaryClass.createDocumentItemsSmaller(new string[] { PdnResources.GetString("Menu.BinaryAction.BinaryExtraction.Text"), PdnResources.GetString("Menu.Grainboundarytoreproduce.text"), PdnResources.GetString("Menu.Thegrainsareshownindifferentcolors.text") }
, this.bc, this.appWorkspace, this.documentWorkspace, this.lstView_img);//初始化相的工作结构
binaryClass.BinaryImplFinishAction += new EventHandler(this.bClassBinaryImplFinishAction);//二值化后续处理事件
InitComboboxValue(null);
this.button11.Visible = true;
this.button16.Visible = false;
SetAnalyzeModelFromXml(getTemplateName());
}
public GrainSizeStandardDialog()
{
InitializeComponent();
}
#endregion
#region 初始化组件
private void InitializeLanguageText()
{
this.Column5.HeaderText = PdnResources.GetString("Menu.Averagegrainsizegrade.text");
this.Column4.HeaderText = PdnResources.GetString("Menu.Numberofgrains.text");
this.Column3.HeaderText = PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.Gridsize.text") + "(μm)";
this.Column2.HeaderText = PdnResources.GetString("Menu.Tools.GridLine.Text");
this.Column1.HeaderText = PdnResources.GetString("Menu.picture.Text");
this.button9.Text = PdnResources.GetString("Menu.Auxiliarylinesettings.text");
this.groupBox3.Text = PdnResources.GetString("Menu.Tools.GridLine.Text");
this.checkBox1.Text = PdnResources.GetString("Menu.Grainboundarytoreproduce.text");
this.label1.Text = PdnResources.GetString("Menu.Grainboundarytype.text") + ":";
this.label6.Text = PdnResources.GetString("Menu.Denoisingtype.text") + ":";
this.label7.Text = PdnResources.GetString("Menu.Image.Sigma.Text") + ":";
this.checkBox2.Text = PdnResources.GetString("Menu.Grainboundaryenhancement.text");
this.label8.Text = PdnResources.GetString("Menu.Grainboundarysize.text") + ":";
this.button3.Text = PdnResources.GetString("Menu.Grainboundaryedit.text");
this.groupBox4.Text = PdnResources.GetString("Menu.Grainboundarytoreproduce.text");
this.button12.Text = PdnResources.GetString("Menu.Edit.Delete.Text");
this.button16.Text = PdnResources.GetString("Menu.Cancelshowall.text");
this.button11.Text = PdnResources.GetString("Menu.Showall.text");
this.groupBox_analysisResult1.Text = PdnResources.GetString("Menu.Analysisresult.text");
this.button_generateReport.Text = PdnResources.GetString("Menu.Tools.CreateReport.Text");
this.button_exportResults.Text = PdnResources.GetString("Menu.Exportresults.text");
this.label_resultPrecision.Text = PdnResources.GetString("Menu.Decimal.text") + ":";
this.button1.Text = PdnResources.GetString("Menu.Exportproject.text");
this.groupBox_review.Text = PdnResources.GetString("Menu.Preview.text");
this.groupBox_img.Text = PdnResources.GetString("Menu.Tools.ImageIndex.Text");
this.btn_saveresult.Text = PdnResources.GetString("Menu.Saveresult.text");
this.button_setting.Text = PdnResources.GetString("Menu.Setting.Text");
this.checkBox_generateReport_opensetting.Text = PdnResources.GetString("Menu.Opensettingsatingreport.text");
this.groupBox_operating.Text = PdnResources.GetString("Menu.operation.text");
this.comboBox3.Items.AddRange(new object[] {
PdnResources.GetString("Menu.Gaussiansmoothing.text"),
PdnResources.GetString("Menu.directionalsmoothing.text")});
this.comboBox2.Items.AddRange(new object[] {
PdnResources.GetString("Menu.Brightgrainboundary.text"),
PdnResources.GetString("Menu.Darkgrainboundary.text"),
PdnResources.GetString("Menu.gradient.text")});
}
private void InitializeCustomControl()
{
//
// bc
//
this.bc = new PaintDotNet.CustomControl.BinaryControlSmaller();
this.bc.BinaryBackColor = System.Drawing.Color.Red;
this.bc.BinaryChecked = false;
this.bc.BinaryStyle = 1;
this.bc.Location = new System.Drawing.Point(176, 70);
this.bc.Name = "bc";
this.bc.OriginChecked = false;
this.bc.scope1End = 0D;
this.bc.scope1Start = 0D;
this.bc.scope2End = 0D;
this.bc.scope2Start = 0D;
this.bc.scope3End = 0D;
this.bc.scope3Start = 0D;
this.bc.Size = new System.Drawing.Size(360, 247);
this.bc.TabIndex = 38;
this.Controls.Add(this.bc);
this.Controls.SetChildIndex(this.bc, 0);
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
this.groupBox_operating = new System.Windows.Forms.GroupBox();
this.checkBox_generateReport_opensetting = new System.Windows.Forms.CheckBox();
this.button_setting = new System.Windows.Forms.Button();
this.btn_saveresult = new System.Windows.Forms.Button();
this.groupBox_img = new System.Windows.Forms.GroupBox();
this.lstView_img = new System.Windows.Forms.ListView();
this.imageList_img = new System.Windows.Forms.ImageList(this.components);
this.groupBox_review = new System.Windows.Forms.GroupBox();
this.groupBox_report = new System.Windows.Forms.GroupBox();
this.button1 = new System.Windows.Forms.Button();
this.numericUpDown1_0 = new System.Windows.Forms.NumericUpDown();
this.label_resultPrecision = new System.Windows.Forms.Label();
this.button_exportResults = new System.Windows.Forms.Button();
this.button_generateReport = new System.Windows.Forms.Button();
this.groupBox6groupBox_analysisResult2 = new System.Windows.Forms.GroupBox();
this.dataGridView2 = new System.Windows.Forms.DataGridView();
this.groupBox_analysisResult1 = new System.Windows.Forms.GroupBox();
this.button11 = new System.Windows.Forms.Button();
this.listView2 = new System.Windows.Forms.ListView();
this.button16 = new System.Windows.Forms.Button();
this.button12 = new System.Windows.Forms.Button();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.panel1 = new System.Windows.Forms.Panel();
this.button3 = new System.Windows.Forms.Button();
this.label8 = new System.Windows.Forms.Label();
this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.textBox6 = new System.Windows.Forms.TextBox();
this.label7 = new System.Windows.Forms.Label();
this.comboBox3 = new System.Windows.Forms.ComboBox();
this.label6 = new System.Windows.Forms.Label();
this.comboBox2 = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.button9 = new System.Windows.Forms.Button();
this.comboBox1 = new System.Windows.Forms.ComboBox();
if (isOtherGrainSizeStandardDialog)
{
this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
}
this.groupBox_operating.SuspendLayout();
this.groupBox_img.SuspendLayout();
this.groupBox_report.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).BeginInit();
this.groupBox6groupBox_analysisResult2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).BeginInit();
this.groupBox_analysisResult1.SuspendLayout();
this.groupBox4.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
this.groupBox3.SuspendLayout();
this.SuspendLayout();
//
// groupBox_operating
//
this.groupBox_operating.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox_operating.Controls.Add(this.checkBox_generateReport_opensetting);
this.groupBox_operating.Controls.Add(this.button_setting);
this.groupBox_operating.Controls.Add(this.btn_saveresult);
this.groupBox_operating.Location = new System.Drawing.Point(13, 12);
this.groupBox_operating.Name = "groupBox_operating";
this.groupBox_operating.Size = new System.Drawing.Size(1102, 53);
this.groupBox_operating.TabIndex = 12;
this.groupBox_operating.TabStop = false;
//
// checkBox_generateReport_opensetting
//
this.checkBox_generateReport_opensetting.AutoSize = true;
this.checkBox_generateReport_opensetting.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
this.checkBox_generateReport_opensetting.Location = new System.Drawing.Point(91, 24);
this.checkBox_generateReport_opensetting.Name = "checkBox_generateReport_opensetting";
this.checkBox_generateReport_opensetting.Size = new System.Drawing.Size(132, 16);
this.checkBox_generateReport_opensetting.TabIndex = 6;
this.checkBox_generateReport_opensetting.UseVisualStyleBackColor = true;
//
// button_setting
//
this.button_setting.Location = new System.Drawing.Point(6, 20);
this.button_setting.Name = "button_setting";
this.button_setting.Size = new System.Drawing.Size(75, 23);
this.button_setting.TabIndex = 4;
this.button_setting.UseVisualStyleBackColor = true;
this.button_setting.Click += new System.EventHandler(this.button_setting_Click);
//
// btn_saveresult
//
this.btn_saveresult.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btn_saveresult.Location = new System.Drawing.Point(992, 20);
this.btn_saveresult.Name = "btn_saveresult";
this.btn_saveresult.Size = new System.Drawing.Size(75, 23);
this.btn_saveresult.TabIndex = 2;
this.btn_saveresult.UseVisualStyleBackColor = true;
this.btn_saveresult.Click += new System.EventHandler(this.btn_saveresult_Click);
//
// groupBox_img
//
this.groupBox_img.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.groupBox_img.Controls.Add(this.lstView_img);
this.groupBox_img.Location = new System.Drawing.Point(13, 72);
this.groupBox_img.Margin = new System.Windows.Forms.Padding(4);
this.groupBox_img.Name = "groupBox_img";
this.groupBox_img.Padding = new System.Windows.Forms.Padding(4);
this.groupBox_img.Size = new System.Drawing.Size(158, 552);
this.groupBox_img.TabIndex = 13;
this.groupBox_img.TabStop = false;
//
// lstView_img
//
this.lstView_img.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.lstView_img.HideSelection = false;
this.lstView_img.LargeImageList = this.imageList_img;
this.lstView_img.Location = new System.Drawing.Point(8, 26);
this.lstView_img.Margin = new System.Windows.Forms.Padding(4);
this.lstView_img.MultiSelect = false;
this.lstView_img.Name = "lstView_img";
this.lstView_img.Size = new System.Drawing.Size(140, 518);
this.lstView_img.TabIndex = 0;
this.lstView_img.UseCompatibleStateImageBehavior = false;
this.lstView_img.SelectedIndexChanged += new System.EventHandler(this.lstView_img_SelectedIndexChanged);
//
// imageList_img
//
this.imageList_img.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
this.imageList_img.ImageSize = new System.Drawing.Size(64, 64);
this.imageList_img.TransparentColor = System.Drawing.Color.Transparent;
//
// groupBox_review
//
this.groupBox_review.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.groupBox_review.Location = new System.Drawing.Point(541, 72);
this.groupBox_review.Name = "groupBox_review";
this.groupBox_review.Size = new System.Drawing.Size(575, 552);
this.groupBox_review.TabIndex = 30;
this.groupBox_review.TabStop = false;
//
// groupBox_report
//
this.groupBox_report.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.groupBox_report.Controls.Add(this.button1);
this.groupBox_report.Controls.Add(this.numericUpDown1_0);
this.groupBox_report.Controls.Add(this.label_resultPrecision);
this.groupBox_report.Controls.Add(this.button_exportResults);
this.groupBox_report.Controls.Add(this.button_generateReport);
this.groupBox_report.Location = new System.Drawing.Point(974, 630);
this.groupBox_report.Name = "groupBox_report";
this.groupBox_report.Size = new System.Drawing.Size(142, 188);
this.groupBox_report.TabIndex = 33;
this.groupBox_report.TabStop = false;
//
// button1
//
this.button1.Location = new System.Drawing.Point(29, 102);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 23;
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// numericUpDown1_0
//
this.numericUpDown1_0.Location = new System.Drawing.Point(63, 150);
this.numericUpDown1_0.Maximum = new decimal(new int[] {
10,
0,
0,
0});
this.numericUpDown1_0.Name = "numericUpDown1_0";
this.numericUpDown1_0.Size = new System.Drawing.Size(56, 21);
this.numericUpDown1_0.TabIndex = 22;
this.numericUpDown1_0.Value = new decimal(new int[] {
2,
0,
0,
0});
this.numericUpDown1_0.ValueChanged += new System.EventHandler(this.numericUpDown1_0_ValueChanged);
//
// label_resultPrecision
//
this.label_resultPrecision.AutoSize = true;
this.label_resultPrecision.Location = new System.Drawing.Point(26, 154);
this.label_resultPrecision.Name = "label_resultPrecision";
this.label_resultPrecision.Size = new System.Drawing.Size(29, 12);
this.label_resultPrecision.TabIndex = 3;
//
// button_exportResults
//
this.button_exportResults.Location = new System.Drawing.Point(29, 63);
this.button_exportResults.Name = "button_exportResults";
this.button_exportResults.Size = new System.Drawing.Size(75, 23);
this.button_exportResults.TabIndex = 1;
this.button_exportResults.UseVisualStyleBackColor = true;
this.button_exportResults.Click += new System.EventHandler(this.button_exportResults_Click);
//
// button_generateReport
//
this.button_generateReport.Location = new System.Drawing.Point(29, 24);
this.button_generateReport.Name = "button_generateReport";
this.button_generateReport.Size = new System.Drawing.Size(75, 23);
this.button_generateReport.TabIndex = 0;
this.button_generateReport.UseVisualStyleBackColor = true;
this.button_generateReport.Click += new System.EventHandler(this.button_generateReport_Click);
//
// groupBox6groupBox_analysisResult2
//
this.groupBox6groupBox_analysisResult2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox6groupBox_analysisResult2.Controls.Add(this.dataGridView2);
this.groupBox6groupBox_analysisResult2.Location = new System.Drawing.Point(242, 630);
this.groupBox6groupBox_analysisResult2.Name = "groupBox6groupBox_analysisResult2";
this.groupBox6groupBox_analysisResult2.Size = new System.Drawing.Size(719, 188);
this.groupBox6groupBox_analysisResult2.TabIndex = 32;
this.groupBox6groupBox_analysisResult2.TabStop = false;
//
// dataGridView2
//
this.dataGridView2.AllowUserToAddRows = false;
this.dataGridView2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGridView2.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
this.dataGridView2.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle1.Font = new System.Drawing.Font("宋体", 9F);
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.dataGridView2.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
this.dataGridView2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView2.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Column1,
this.Column2,
this.Column3,
this.Column4,
this.Column5});
this.dataGridView2.Location = new System.Drawing.Point(13, 17);
this.dataGridView2.Name = "dataGridView2";
this.dataGridView2.ReadOnly = true;
this.dataGridView2.RowHeadersVisible = false;
this.dataGridView2.RowTemplate.Height = 23;
this.dataGridView2.Size = new System.Drawing.Size(693, 160);
this.dataGridView2.TabIndex = 16;
//
// groupBox_analysisResult1
//
this.groupBox_analysisResult1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.groupBox_analysisResult1.Controls.Add(this.button11);
this.groupBox_analysisResult1.Controls.Add(this.listView2);
this.groupBox_analysisResult1.Controls.Add(this.button16);
this.groupBox_analysisResult1.Controls.Add(this.button12);
this.groupBox_analysisResult1.Location = new System.Drawing.Point(12, 630);
this.groupBox_analysisResult1.Name = "groupBox_analysisResult1";
this.groupBox_analysisResult1.Size = new System.Drawing.Size(224, 188);
this.groupBox_analysisResult1.TabIndex = 31;
this.groupBox_analysisResult1.TabStop = false;
//
// button11
//
this.button11.BackColor = System.Drawing.SystemColors.Control;
this.button11.Location = new System.Drawing.Point(19, 22);
this.button11.Name = "button11";
this.button11.Size = new System.Drawing.Size(63, 26);
this.button11.TabIndex = 27;
this.button11.UseVisualStyleBackColor = false;
this.button11.Click += new System.EventHandler(this.button11_Click);
//
// listView2
//
this.listView2.FullRowSelect = true;
this.listView2.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
this.listView2.HideSelection = false;
this.listView2.Location = new System.Drawing.Point(19, 58);
this.listView2.Name = "listView2";
this.listView2.Size = new System.Drawing.Size(181, 124);
this.listView2.TabIndex = 26;
this.listView2.UseCompatibleStateImageBehavior = false;
this.listView2.SelectedIndexChanged += new System.EventHandler(this.listview2_SelectedIndexChanged);
//
// button16
//
this.button16.BackColor = System.Drawing.SystemColors.Control;
this.button16.Location = new System.Drawing.Point(19, 21);
this.button16.Name = "button16";
this.button16.Size = new System.Drawing.Size(93, 26);
this.button16.TabIndex = 25;
this.button16.UseVisualStyleBackColor = false;
this.button16.Click += new System.EventHandler(this.button16_Click);
//
// button12
//
this.button12.BackColor = System.Drawing.SystemColors.Control;
this.button12.Location = new System.Drawing.Point(149, 21);
this.button12.Name = "button12";
this.button12.Size = new System.Drawing.Size(52, 26);
this.button12.TabIndex = 24;
this.button12.UseVisualStyleBackColor = false;
this.button12.Click += new System.EventHandler(this.button12_Click);
//
// groupBox4
//
this.groupBox4.Controls.Add(this.panel1);
this.groupBox4.Controls.Add(this.button3);
this.groupBox4.Controls.Add(this.label8);
this.groupBox4.Controls.Add(this.numericUpDown2);
this.groupBox4.Controls.Add(this.numericUpDown1);
this.groupBox4.Controls.Add(this.checkBox2);
this.groupBox4.Controls.Add(this.textBox6);
this.groupBox4.Controls.Add(this.label7);
this.groupBox4.Controls.Add(this.comboBox3);
this.groupBox4.Controls.Add(this.label6);
this.groupBox4.Controls.Add(this.comboBox2);
this.groupBox4.Controls.Add(this.label1);
this.groupBox4.Controls.Add(this.checkBox1);
this.groupBox4.Location = new System.Drawing.Point(179, 330);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(356, 155);
this.groupBox4.TabIndex = 37;
this.groupBox4.TabStop = false;
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.Red;
this.panel1.Location = new System.Drawing.Point(89, 19);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(72, 21);
this.panel1.TabIndex = 20;
this.panel1.Click += new System.EventHandler(this.panel1_Click);
//
// button3
//
this.button3.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.button3.Location = new System.Drawing.Point(259, 18);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 31;
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(6, 124);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(65, 12);
this.label8.TabIndex = 30;
//
// numericUpDown2
//
this.numericUpDown2.DecimalPlaces = 2;
this.numericUpDown2.Location = new System.Drawing.Point(164, 120);
this.numericUpDown2.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDown2.Name = "numericUpDown2";
this.numericUpDown2.Size = new System.Drawing.Size(61, 21);
this.numericUpDown2.TabIndex = 29;
this.numericUpDown2.Tag = "max";
this.numericUpDown2.Value = new decimal(new int[] {
500,
0,
0,
0});
//
// numericUpDown1
//
this.numericUpDown1.DecimalPlaces = 2;
this.numericUpDown1.Location = new System.Drawing.Point(85, 120);
this.numericUpDown1.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(61, 21);
this.numericUpDown1.TabIndex = 28;
this.numericUpDown1.Tag = "min";
this.numericUpDown1.Value = new decimal(new int[] {
1,
0,
0,
131072});
//
// checkBox2
//
this.checkBox2.AutoSize = true;
this.checkBox2.Checked = true;
this.checkBox2.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBox2.Location = new System.Drawing.Point(8, 55);
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(72, 16);
this.checkBox2.TabIndex = 26;
this.checkBox2.UseVisualStyleBackColor = true;
//
// textBox6
//
this.textBox6.Location = new System.Drawing.Point(65, 87);
this.textBox6.Name = "textBox6";
this.textBox6.Size = new System.Drawing.Size(45, 21);
this.textBox6.TabIndex = 25;
this.textBox6.Text = "0.5";
this.textBox6.TextChanged += new System.EventHandler(this.textBox6_TextChanged);
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(6, 91);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(53, 12);
this.label7.TabIndex = 24;
//
// comboBox3
//
this.comboBox3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox3.FormattingEnabled = true;
this.comboBox3.Location = new System.Drawing.Point(201, 88);
this.comboBox3.Name = "comboBox3";
this.comboBox3.Size = new System.Drawing.Size(133, 20);
this.comboBox3.TabIndex = 23;
this.comboBox3.SelectedIndexChanged += new System.EventHandler(this.comboBox3_SelectedIndexChanged);
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(136, 91);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(65, 12);
this.label6.TabIndex = 22;
//
// comboBox2
//
this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox2.FormattingEnabled = true;
this.comboBox2.Location = new System.Drawing.Point(201, 53);
this.comboBox2.Name = "comboBox2";
this.comboBox2.Size = new System.Drawing.Size(133, 20);
this.comboBox2.TabIndex = 11;
this.comboBox2.SelectedIndexChanged += new System.EventHandler(this.comboBox2_SelectedIndexChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(136, 56);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(65, 12);
this.label1.TabIndex = 21;
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(8, 23);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(72, 16);
this.checkBox1.TabIndex = 7;
this.checkBox1.UseVisualStyleBackColor = true;
this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
//
// groupBox3
//
this.groupBox3.Controls.Add(this.button9);
this.groupBox3.Controls.Add(this.comboBox1);
this.groupBox3.Location = new System.Drawing.Point(179, 491);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(355, 58);
this.groupBox3.TabIndex = 34;
this.groupBox3.TabStop = false;
//
// button9
//
this.button9.BackColor = System.Drawing.SystemColors.Control;
this.button9.Location = new System.Drawing.Point(241, 19);
this.button9.Name = "button9";
this.button9.Size = new System.Drawing.Size(92, 26);
this.button9.TabIndex = 10;
this.button9.UseVisualStyleBackColor = false;
this.button9.Click += new System.EventHandler(this.button9_Click);
//
// comboBox1
//
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(15, 22);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(220, 20);
this.comboBox1.TabIndex = 0;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// Column1
//
this.Column1.Name = "Column1";
this.Column1.ReadOnly = true;
//
// Column2
//
this.Column2.Name = "Column2";
this.Column2.ReadOnly = true;
//
// Column3
//
this.Column3.Name = "Column3";
this.Column3.ReadOnly = true;
//
// Column4
//
this.Column4.Name = "Column4";
this.Column4.ReadOnly = true;
//
// Column5
//
this.Column5.Name = "Column5";
this.Column5.ReadOnly = true;
//
// GrainSizeStandardDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.ClientSize = new System.Drawing.Size(1127, 830);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox_report);
this.Controls.Add(this.groupBox6groupBox_analysisResult2);
this.Controls.Add(this.groupBox_analysisResult1);
this.Controls.Add(this.groupBox_review);
this.Controls.Add(this.groupBox_img);
this.Controls.Add(this.groupBox_operating);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "GrainSizeStandardDialog";
this.Controls.SetChildIndex(this.groupBox_operating, 0);
this.Controls.SetChildIndex(this.groupBox_img, 0);
this.Controls.SetChildIndex(this.groupBox_review, 0);
this.Controls.SetChildIndex(this.groupBox_analysisResult1, 0);
this.Controls.SetChildIndex(this.groupBox6groupBox_analysisResult2, 0);
this.Controls.SetChildIndex(this.groupBox_report, 0);
this.Controls.SetChildIndex(this.groupBox3, 0);
this.Controls.SetChildIndex(this.groupBox4, 0);
this.groupBox_operating.ResumeLayout(false);
this.groupBox_operating.PerformLayout();
this.groupBox_img.ResumeLayout(false);
this.groupBox_report.ResumeLayout(false);
this.groupBox_report.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).EndInit();
this.groupBox6groupBox_analysisResult2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).EndInit();
this.groupBox_analysisResult1.ResumeLayout(false);
this.groupBox4.ResumeLayout(false);
this.groupBox4.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
this.groupBox3.ResumeLayout(false);
this.ResumeLayout(false);
}
public void Initialize()
{
//初始化图片列表
for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Length; i++)
{
this.imageList_img.Images.Add("img" + i, this.appWorkspace.DocumentWorkspaces[i].BinarizationThumbnail);
this.lstView_img.Items.Add("", i);
this.lstView_img.Items[i].ImageIndex = i;
this.lstView_img.Items[i].Text = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
this.lstView_img.Items[i].Name = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
}
//
//初始化图像控件
//
this.documentWorkspace = new DocumentWorkspaceWindow(this.appWorkspace);
this.documentWorkspace.Cursor = Cursors.Default;
this.documentWorkspace.Dock = DockStyle.Fill;
this.documentWorkspace.HookMouseEvents();
this.documentWorkspace.AuxiliaryLineEnabled = false;
this.documentWorkspace.Visible = true;
this.documentWorkspace.panel.MouseDown += OnMouseDown;
this.documentWorkspace.panel.Paint += Panel_Paint;
this.documentWorkspace.panel.MouseMove += onMouseMove;
this.documentWorkspace.panel.MouseUp += onMouseUp;
this.groupBox_review.Controls.Add(this.documentWorkspace);
//
//初始化操作按钮
//
this.commonControlButtons = new CommonControlButtons();
this.commonControlButtons.Dock = DockStyle.Top;
this.commonControlButtons.Height = 30;
this.commonControlButtons.HideZoomToWindowAndActualSize();
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);
groupBox_review.Controls.Add(this.commonControlButtons);
}
#endregion
#region 事件
#region 公共按钮
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.InclusionNoEffect;
}
private void mobileModeButton_Click(object sender, EventArgs e)
{
this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
}
#endregion
///
/// 设置
///
///
///
private void button_setting_Click(object sender, EventArgs e)
{
string templateName = getTemplateName();
AnalyzeSettingDialog metallographicMethodSetDialog = new AnalyzeSettingDialog(this, templateName);
if (metallographicMethodSetDialog.hasModule)
{
metallographicMethodSetDialog.StartPosition = FormStartPosition.CenterScreen;
metallographicMethodSetDialog.ShowDialog();
}
else
{
metallographicMethodSetDialog = null;
}
}
private void btn_saveresult_Click(object sender, EventArgs e)
{
buildListBox_analysisResult();
}
private void lstView_img_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.lstView_img.FocusedItem != null && this.lstView_img.FocusedItem.Selected)
{
this.bitmap = this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
//二值化集成4
binaryClass.listView1_SelectedIndexChanged(this.bitmap);
//if (!this.documentWorkspace.PhaseModels[0].choise)
// this.checkBox10.Checked = false;//#
bool existViewFlag = this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index].GraphicsList.IsExsitView();
if (!existViewFlag)
{
matOrg = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap);
}
else
{
matOrg = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index].GetFullSizeWithRegion());
}
if (this.checkBox1.Checked)
{
this.applyDect();
}
//this.histogramControl1.CreateHistogram(this.bitmap, true, 339, 130, 0);
guideClass.loctation = new PointF(this.documentWorkspace.CompositionSurface.Width / 2, this.documentWorkspace.CompositionSurface.Height / 2);
InitRectangleF();
AddRectangleToRectangleFCaps();
refreshWhileImgChanged();
}
}
#region 矩形拖动
///
/// 鼠标按下
///
///
///
protected virtual void OnMouseDown(object sender, MouseEventArgs e)
{
if (isAreaType)
{
if (this.documentWorkspace.CompositionSurface == null)
return;
// 换算后的点
PointF pointArea = documentWorkspace.GetScalePoint(e.Location);
//辅助线缩放
guideClass.OnMouseDown(pointArea, sender, e);
//辅助线移动
if (e.Button == MouseButtons.Left && e.Clicks == 1)
{
if (guideClass.RectangleFLine.Contains(pointArea))
{
m_canMove = true;
this.m_StartPoint = pointArea;
}
}
return;
}
// 换算后的点
PointF point1 = documentWorkspace.GetScalePoint(e.Location);
if (e.Button == MouseButtons.Left && e.Clicks == 1)
{
if (guideClass.RectangleFLine.Contains(point1))
{
m_canMove = true;
this.m_StartPoint = point1;
}
}
}
///
/// 移动
///
///
///
protected virtual void onMouseMove(object sender, MouseEventArgs e)
{
this.documentWorkspace.Refresh();
// 换算后的点
PointF point1 = documentWorkspace.GetScalePoint(e.Location);
if (!isAreaType && this.documentWorkspace.CompositionSurface != null && guideClass.onMouseMove(point1, this.comboBox1.SelectedItem, e, this.documentWorkspace.CompositionSurface.Width, this.documentWorkspace.CompositionSurface.Height, getCurrentWorkspace().GetRuler(MeasurementUnit.Micron))
|| isAreaType && this.documentWorkspace.CompositionSurface != null && guideClass.onMouseAreaMove(point1, this.comboBox1.SelectedItem, e, this.documentWorkspace.CompositionSurface.Width, this.documentWorkspace.CompositionSurface.Height))// 矩形缩放
{
guideClass.loctation = new PointF(guideClass.RectangleFLine.X + guideClass.RectangleFLine.Width / 2, guideClass.RectangleFLine.Y + guideClass.RectangleFLine.Height / 2);
this.AddRectangleToRectangleFCaps();
this.documentWorkspace.Refresh();
}
else if (e.Button == MouseButtons.Left && m_canMove)
{
// 矩形偏移
guideClass.rectangleFLine.Offset(point1.X - this.m_StartPoint.X, point1.Y - this.m_StartPoint.Y);
guideClass.loctation = new PointF(guideClass.RectangleFLine.X + guideClass.RectangleFLine.Width / 2, guideClass.RectangleFLine.Y + guideClass.RectangleFLine.Height / 2);
this.m_StartPoint = point1;
this.AddRectangleToRectangleFCaps();
this.documentWorkspace.Refresh();
}
}
///
/// 鼠标抬起
///
///
///
private void onMouseUp(object sender, MouseEventArgs e)
{
m_canMove = false;
guideClass.onMouseUp(sender, e);
}
#endregion
///
/// 画布绘制
///
///
///
private void Panel_Paint(object sender, PaintEventArgs e)
{
if (this.documentWorkspace.CompositionSurface != null)
{
//
// 以下是计算绘制图片的位置和大小并绘制图片
//
System.Drawing.Rectangle rc = this.documentWorkspace.panel.ClientRectangle;
int width = (int)(this.documentWorkspace.CompositionSurface.Width * this.documentWorkspace.ScaleFactor.Ratio);
int height = (int)(this.documentWorkspace.CompositionSurface.Height * this.documentWorkspace.ScaleFactor.Ratio);
int x = (rc.Width < width) ? this.documentWorkspace.panel.AutoScrollPosition.X : (rc.Width - width) / 2;
int y = (rc.Height < height) ? this.documentWorkspace.panel.AutoScrollPosition.Y : (rc.Height - height) / 2;
//
// 以下是绘制网格、标注、测量、视场等开始
//
e.Graphics.TranslateTransform(x, y);
e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio);
Draw(e.Graphics);
e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio);
e.Graphics.TranslateTransform(-x, -y);
}
}
///
/// 绘制
///
private void Draw(Graphics graphics)
{
// 抗锯齿
graphics.SmoothingMode = SmoothingMode.AntiAlias;
drawSubclass(graphics);
}
///
/// 切换辅助线
///
///
///
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.comboBox1.DataSource != null && this.comboBox1.SelectedIndex >= 0)
{
UpdateGuideStyle();
if (this.bitmap != null)
{
if (this.comboboxChange)
{
guideClass.loctation = new PointF(this.documentWorkspace.CompositionSurface.Width / 2, this.documentWorkspace.CompositionSurface.Height / 2);
}
InitRectangleF();
this.comboboxChange = true;
}
this.documentWorkspace.Refresh();
}
}
#endregion
#region 内部方法
///
/// 导出项目
///
///
///
private void button1_Click(object sender, EventArgs e)
{
if (this.listView2.Items.Count == 0)
{
MessageBox.Show(PdnResources.GetString("Menu.Noresults.text"));
return;
}
if (this.checkBox_generateReport_opensetting.Checked)
this.button_setting.PerformClick();
if (this.analyzeSettingModel != null && !string.IsNullOrEmpty(this.analyzeSettingModel.analyzeClassify))
{
//获取项目工程内的文件夹路径
ProjectEngineering.NodeItem nodeItem = this.appWorkspace.GetInsertProjectPath(2, getProjectEngineeringName(), this.analyzeSettingModel.savePath);
if (nodeItem == null) return;
//获取word书签与excel单元格的关系,以字典方式存储
List mic_module_infos = PaintDotNet.DbOpreate.DbBll.mic_module_infos_BLL.FindAll().FindAll(a => a.analyze_classify == this.analyzeSettingModel.analyzeClassify);
Dictionary tagInfos = new Dictionary();
if (mic_module_infos != null && mic_module_infos.Count > 0)
{
foreach (mic_module_infos info in mic_module_infos)
{
tagInfos.Add(info.tag_name, info.cell_position);
}
}
//分析结果
List> analysisContent = new List>();
analysisContent.Add(contentHead);
foreach (DataGridViewRow item in this.dataGridView2.Rows)
{
List content = new List();
for (int i = 0; i < contentHead.Count; i++)
{
content.Add(item.Cells[i].Value.ToString());
}
analysisContent.Add(content);
}
//图片
bitList = new List();
//中间数据
List exportModel = new List();
if (this.allShow)
{
foreach (KeyValuePair> kv in this.bitDic)
{
bitList.Add(kv.Value[0]);
bitList.Add(kv.Value[1]);
}
//中间数据
foreach (ExportProjectModel model in this.tempDataModel)
{
ExportProjectModel tempModel = new ExportProjectModel();
tempModel.tagName = model.tagName;
tempModel.picName = model.picName;
tempModel.dataList = model.dataList;
exportModel.Add(tempModel);
}
}
else
{
if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0)
{
foreach (ListViewItem item in this.listView2.SelectedItems)
{
if (bitDic.ContainsKey(item.Name))
{
bitList.Add(bitDic[item.Name][0]);
bitList.Add(bitDic[item.Name][1]);
}
else if (bitDic.ContainsKey(item.Tag.ToString()))
{
bitList.Add(bitDic[item.Tag.ToString()][0]);
bitList.Add(bitDic[item.Tag.ToString()][1]);
}
}
//中间数据
foreach (ListViewItem rowItem in this.listView2.SelectedItems)
{
foreach (ExportProjectModel model in this.tempDataModel)
{
if (model.tagName.Equals(rowItem.Name))
{
ExportProjectModel tempModel = new ExportProjectModel();
tempModel.tagName = model.tagName;
tempModel.picName = model.picName;
tempModel.dataList = model.dataList;
exportModel.Add(tempModel);
break;
}
else if (model.tagName.Equals(rowItem.Tag.ToString()))
{
ExportProjectModel tempModel = new ExportProjectModel();
tempModel.tagName = model.tagName;
tempModel.picName = model.picName;
tempModel.dataList = model.dataList;
exportModel.Add(tempModel);
break;
}
}
}
}
else if (this.listView2.Items.Count > 0)
{
ListViewItem rowItem = this.listView2.Items[0];
if (bitDic.ContainsKey(rowItem.Name))
{
bitList.Add(bitDic[rowItem.Name][0]);
bitList.Add(bitDic[rowItem.Name][1]);
}
else if (bitDic.ContainsKey(rowItem.Tag.ToString()))
{
bitList.Add(bitDic[rowItem.Tag.ToString()][0]);
bitList.Add(bitDic[rowItem.Tag.ToString()][1]);
}
//中间数据
foreach (ExportProjectModel model in this.tempDataModel)
{
if (model.tagName.Equals(rowItem.Name))
{
ExportProjectModel tempModel = new ExportProjectModel();
tempModel.tagName = model.tagName;
tempModel.picName = model.picName;
tempModel.dataList = model.dataList;
exportModel.Add(tempModel);
break;
}
else if (model.tagName.Equals(rowItem.Tag.ToString()))
{
ExportProjectModel tempModel = new ExportProjectModel();
tempModel.tagName = model.tagName;
tempModel.picName = model.picName;
tempModel.dataList = model.dataList;
exportModel.Add(tempModel);
break;
}
}
}
}
this.appWorkspace.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, exportModel, bitList, tagInfos, nodeItem.path, nodeItem.code);
//保存项目信息到数据库
this.appWorkspace.InsertIntoDB(this.analyzeSettingModel, nodeItem);
}
else
MessageBox.Show(PdnResources.GetString("Menu.Pleasesettheanalysisreportfirst.text")+"!");
}
///
/// 导出结果
///
///
///
private void button_exportResults_Click(object sender, EventArgs e)
{
if (this.listView2.Items.Count > 0)
{
SaveFileDialog exe = new SaveFileDialog();
exe.Filter = "Execl files (*.xlsx)|*.xlsx";
exe.FilterIndex = 0;
exe.RestoreDirectory = true;
exe.Title = "Export Excel File";
exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
exe.FileName = this.Text + PdnResources.GetString("Menu.Analysisresult.text") + DateTime.Now.ToString("yyyyMMddHHmmss");
DialogResult dr = exe.ShowDialog();
if (dr != DialogResult.OK)
{
return;
}
System.Data.DataTable dtb = new System.Data.DataTable();
foreach (var item in this.contentHead)
{
dtb.Columns.Add(item);
}
for (int i = 0; i < this.dataGridView2.Rows.Count; i++)
{
System.Data.DataRow dataRow = dtb.NewRow();
for (int k = 0; k < this.contentHead.Count; k++)
{
dataRow[this.contentHead[k]] = this.dataGridView2.Rows[i].Cells[k].Value;
}
dtb.Rows.Add(dataRow);
}
List list = new List();
list.Add(dtb);
///#########################################
this.appWorkspace.ExportDataToExcelWithProgress(list, exe.FileName, false, false, true);
}
else
MessageBox.Show(PdnResources.GetString("Menu.Noanalysineratereport.text")+"!");
}
///
/// 辅助线设置
///
///
///
private void button9_Click(object sender, EventArgs e)
{
if (this.bitmap == null)
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!");
return;
}
this.oldSelectItem = (string)this.comboBox1.SelectedItem;
GrainGuideSettingsDialog grainGuideStyleSettingsDialog = new GrainGuideSettingsDialog(isAreaType ? 1 : 0, getModelName(), getTypeNames(), this.bitmap, this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index].GetRuler(MeasurementUnit.Micron));
grainGuideStyleSettingsDialog.StartPosition = FormStartPosition.CenterScreen;
grainGuideStyleSettingsDialog.ShowDialog(this);
}
//二值化集成3
#region 二值化相关方法
///
/// 添加参数改变的监听
///
///
///
private void GrainSizeStandardDialog_Load(object sender, EventArgs e)
{
this.comboBox3.Text = PdnResources.GetString("Menu.pdenoisingtype.Text");
this.comboBox3.SelectedIndex = 1;
this.comboBox2.Text = PdnResources.GetString("Menu.electthegrainboundarytype.Text");
this.comboBox2.SelectedIndex = 1;
this.binaryClass.loadParams();
this.binaryClass.comboBox1 = this.comboBox1;//##
}
private bool bcBinaryChecked()
{
return bc != null && bc.BinaryChecked;
}
private bool bcOriginChecked()
{
return bc != null && bc.OriginChecked;
}
///
/// 参数改变时,重新处理图像
///
///
///
private void bClassBinaryImplFinishAction(object sender, EventArgs e)
{
this.documentWorkspace.Refresh();
}
///
/// 显示原图/原图+二值图
///
///
///
private void bcOriginCheckedChanged(object sender, EventArgs e)
{
if (!bcOriginChecked())
{
if (bcBinaryChecked())
this.documentWorkspace.PhaseModels[0].choise = true;
if (this.toshowPhoseModelAt(1))
this.documentWorkspace.PhaseModels[1].choise = true;
this.refreshPhaseModelChoise();
}
else
{
this.documentWorkspace.PhaseModels[0].choise = false;
this.documentWorkspace.PhaseModels[1].choise = false;
}
this.documentWorkspace.Refresh();
}
#endregion
///
/// 晶界编辑
///
///
///
private void button3_Click(object sender, EventArgs e)
{
if (this.documentWorkspace.PhaseModels.Count < 2 || /*this.documentWorkspace.PhaseModels[1].choise == true && */this.documentWorkspace.PhaseModels[1].mat == null)
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseperformuctionfirst.text"));
return;
}
//1013###19326 晶粒度的晶界编辑页面,需要把辅助线带过去(客户编辑只处理辅助线位置的晶界)
GrainSizeStandard.IntegrationClass.GrainBoundaryEditingDialog boundaryEditingDialog = new GrainSizeStandard.IntegrationClass.GrainBoundaryEditingDialog(this.appWorkspace, this.lstView_img.FocusedItem.Index, this.panel1.BackColor
, this.documentWorkspace.PhaseModels[1].mat.Clone());
boundaryEditingDialog.GuideClass = this.guideClass;
boundaryEditingDialog.SelectedItem = this.comboBox1.SelectedItem;
if (boundaryEditingDialog.ShowDialog() == DialogResult.OK)
{
this.documentWorkspace.PhaseModels[1].mat = boundaryEditingDialog.PhaseMat.Clone();
this.documentWorkspace.Refresh();
}
}
///
/// 晶界重现
///
///
///
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (this.checkBox1.Checked && !bcOriginChecked())
{
this.documentWorkspace.PhaseModels[1].choise = true;
}
else
{
this.documentWorkspace.PhaseModels[1].choise = false;
this.documentWorkspace.Refresh();
}
if (this.checkBox1.Checked)
{
this.applyDect();
}
else
AddRectangleToRectangleFCaps();//1009###18946
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.checkBox1.Checked)
{
this.applyDect();
}
}
private void textBox6_TextChanged(object sender, EventArgs e)
{
if (this.checkBox1.Checked)
{
this.applyDect();
}
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.checkBox1.Checked)
{
this.applyDect();
}
}
ProgressThreadProcClass procClass;
double sigma = 0.5;
Mat OrgImg;// = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap);// OpenCvSharp.Cv2.ImRead(inputImageFile);
int dark;// = this.comboBox2.SelectedIndex;// 2;//指定晶界类型,暗晶界dark=1, 否则dark=0, dark=2梯度
int smooth_type;// = this.comboBox3.SelectedIndex;// 1;//去噪类型: 高斯平滑: smooth_type=0; 方向平滑: smooth_type=1
//double sigma = double.Parse(textBox6.Text);// 0.5;//如果是高斯平滑,则指定高斯sigma,如果是方向平滑 则忽略此参数
int enhance;// = this.checkBox2.Checked ? 1 : 0;// 1;//是否增强晶界?不增强:enhance=0; 增强: enhance=1
double[] cell_size;// = new double[2] { (double)numericUpDown1.Value, (double)numericUpDown2.Value }; ;// new double[2] { 0.01, 500 };//晶界大小
Mat OrgImg0;
private void applyDect()
{
if (this.bitmap == null)
{
return;
}
if (!double.TryParse(textBox6.Text, out sigma))
{
return;
}
//string inputImageFile = "原始图片1.jpg";// "j1.JPG";
////char[] inputImageFile2 = inputImageFile.ToCharArray();
/*Mat */OrgImg = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap);// OpenCvSharp.Cv2.ImRead(inputImageFile);
/*int */dark = this.comboBox2.SelectedIndex;// 2;//指定晶界类型,暗晶界dark=1, 否则dark=0, dark=2梯度
/*int */smooth_type = this.comboBox3.SelectedIndex;// 1;//去噪类型: 高斯平滑: smooth_type=0; 方向平滑: smooth_type=1
//double sigma = double.Parse(textBox6.Text);// 0.5;//如果是高斯平滑,则指定高斯sigma,如果是方向平滑 则忽略此参数
/*int */enhance = this.checkBox2.Checked ? 1 : 0;// 1;//是否增强晶界?不增强:enhance=0; 增强: enhance=1
/*double[] */cell_size = new double[2] { (double)numericUpDown1.Value, (double)numericUpDown2.Value }; ;// new double[2] { 0.01, 500 };//晶界大小
procClass = new ProgressThreadProcClass();
procClass.StartProgressAutoAction(this, new System.Threading.ThreadStart(applyDectAction), PdnResources.GetString("Menu.Grainboundarytoreproduce.text"));
if (OrgImg0 != null)
{
this.documentWorkspace.PhaseModels[1].mat = OrgImg0.Clone();
this.documentWorkspace.Refresh();
OrgImg0 = null;
}
if (OrgImg != null)
{
OrgImg.Dispose();
OrgImg = null;
}
//this.runDect(OrgImg, dark, smooth_type, sigma, enhance, cell_size);
}
private void applyDectAction()
{
OrgImg0 = this.runDect(OrgImg, dark, smooth_type, sigma, enhance, cell_size);
if (procClass != null) procClass.DismissProgressAction(this);
}
private Mat runDect(Mat OrgImg0, int dark, int smooth_type, double sigma, int enhance, double[] cell_size)
{
Mat GryImg = new Mat();
Mat OrgImg = new Mat();
/////
if (4 == OrgImg0.Channels())
{
Cv2.CvtColor(OrgImg0, OrgImg, ColorConversionCodes.BGRA2BGR);
}
else
{
OrgImg = OrgImg0.Clone();
}
GrainSizeStandard.IntegrationClass.In5segmsurf prm = new GrainSizeStandard.IntegrationClass.In5segmsurf();
prm.OrgImg = OrgImg;
/////
//Cv2.ImShow("src", OrgImg);//kkkkk
////Cv2.WaitKey(0);//kkkkk
//转为为灰度?
if (3 == OrgImg.Channels() || 4 == OrgImg.Channels())
{
Cv2.CvtColor(OrgImg, GryImg, ColorConversionCodes.RGB2GRAY);
}
else
{
if (1 == OrgImg.Channels())
{
GryImg = OrgImg.Clone();
}
else
{
return null;
}
}
if (1 == dark)
{
int Rows = GryImg.Rows;
int Cols = GryImg.Cols;
int[] point = new int[2];
//单通道图像的反色
for (point[0] = 0; point[0] < Rows; point[0]++)
{
for (point[1] = 0; point[1] < Cols; point[1]++)
{
byte bTemp = (byte)(255 - GryImg.At(point[0], point[1]));
GryImg.Set(point, bTemp);//mmmmm
}
}
}
if (2 == dark)
{
Mat TempImg = GryImg.Clone();
Cv2.Sobel(TempImg, GryImg, -1, 2, 2, 3);//mmmmm
}
//Cv2.ImShow("src", GryImg);//kkkkk
//Cv2.WaitKey(0);//kkkkk
//去噪
if (0 == smooth_type)
{
prm.smoothim_method = "gaussian";
}
else
{
if (1 == smooth_type)
{
prm.smoothim_method = "dirced";
}
else
{
return null;
}
}
//晶界增强
if (1 == enhance)
{
prm.filterridges = 1;
}
else
{
prm.filterridges = 0;
}
//调用算法
prm.gaussian_stdev = sigma;
prm.LEVEL = ".3";
prm.classifycells_convexarea = 0.50;
prm.classifycells_convexperim = 0.45;
GrainSizeStandard.IntegrationClass.OLDcellsegm cellsegm = new GrainSizeStandard.IntegrationClass.OLDcellsegm();
string[] namehere = new string[1] { "prm" };
GrainSizeStandard.IntegrationClass.In6segmsurf IN6BNImgs = new GrainSizeStandard.IntegrationClass.In6segmsurf();
GrainSizeStandard.IntegrationClass.OUTsegmsurf RSTss = cellsegm.mf_segmsurf_progress_auto(GryImg, cell_size[0], cell_size[1], namehere, prm, IN6BNImgs, this.panel1.BackColor, this);
//cell_size = null;
//cellsegm = null;
//namehere = null;
Cv2.CvtColor(RSTss.wat, OrgImg0, ColorConversionCodes.BGR2BGRA);
////Cv2.ImShow("dst", OrgImg0);//kkkkk
//////Cv2.WaitKey(0);//kkkkk
//this.documentWorkspace.PhaseModels[1].mat = OrgImg0;// RSTss.wat;// action.PerformProcess(
//// OpenCvSharp.Extensions.BitmapConverter.ToMat(this.documentWorkspace.GetFullSizeWithRegion()),
//// OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap));
//////this.documentWorkspace.PhaseModels[1].color = this.panel2.BackColor.ToArgb();
//this.documentWorkspace.Refresh();
//return RSTss.wat;
//string filename = "D:\\result11.jpg";
//Cv2.ImWrite(filename, RSTss.wat);
return OrgImg0;
}
private void panel1_Click(object sender, EventArgs e)
{
this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(this.panel1.BackColor);
this.colorsFormGrid.ShowDialog();
}
///
/// Panel2的调色板颜色改变
///
///
///
private void gridColorChanged(object sender, EventArgs e)
{
Color color = this.colorsFormGrid.UserPrimaryColor.ToColor();
//更改背景色,触发事件
this.panel1.BackColor = color;
this.documentWorkspace.PhaseModels[1].color = this.panel1.BackColor.ToArgb();
//this.applyDect();//#
this.documentWorkspace.Refresh();
//关闭色板
this.colorsFormGrid.Close();
}
#endregion
#region 可调用方法
///
/// 是否显示原图
///
///
protected Boolean showOrimat()
{
return bcOriginChecked();
}
///
/// 是否能取到二值的结果
///
///
protected Boolean getBinaryChecked()
{
return (bcBinaryChecked() && this.documentWorkspace.PhaseModels[0].mat != null);
}
///
/// 是否能取到晶界重现的结果
///
///
protected Boolean getGrainBoundryChecked()
{
return (this.checkBox1.Checked && this.documentWorkspace.PhaseModels[1].mat != null);
}
///
/// 返回当前选择的辅助线名称
///
///
protected string getCurrentGuideName()
{
return this.comboBox1.SelectedItem != null ? this.comboBox1.SelectedItem.ToString() : "";
}
///
/// 返回当前选择的图片内容
///
///
protected DocumentWorkspace getCurrentWorkspace()
{
return this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem != null ? this.lstView_img.FocusedItem.Index : this.lstView_img.SelectedItems[0].Index];// this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index];
}
///
/// 返回当前选择的图片tag
///
///
protected string getCurrentWorkTag()
{
return this.imageList_img.Images.Keys[this.lstView_img.FocusedItem.Index];
}
///
/// 获取面积法显示编号的颜色
///
///
protected Color getGrainBoundryColor()
{
return this.panel1.BackColor;
}
#endregion
///
/// 更新截点样式
///
public void UpdateCupOffPointStyle()
{
styleClass.UpdateCupOffPointStyle();
AddRectangleToRectangleFCaps();
}
#region 需继承方法
protected virtual Boolean toshowPhoseModelAt(int index)
{
if (index == 1)
{
return (this.checkBox1.Checked && !bcOriginChecked());
}
return true;
}
///
/// 图片索引改变后调用的事件
///
protected virtual void refreshWhileImgChanged()
{
}
protected virtual void refreshPhaseModelChoise()
{
}
protected virtual void buildListBox_analysisResult()
{
//this.listBox_analysisResult.Items.Clear();
////foreach (var item in analysisResults.Keys)
////{
//// this.listBox_analysisResult.Items.Add(new LocalListViewItem(item, item.GetFriendlyName()));
////}
////buildListView_analysisResult();
}
protected virtual void SubclassInitialize()
{
throw new NotImplementedException();
}
///
/// 辅助线类型
///
///
protected virtual string[] getTypeNames()
{
return new string[] {
"",
""};
}
///
/// 辅助线配置文件名称
///
///
protected virtual string getModelName()
{
throw new NotImplementedException();
}
///
/// 报告模板命名
///
///
protected virtual string getTemplateName()
{
throw new NotImplementedException();
}
///
/// 项目工程内的文件夹路径名称
///
///
protected virtual string getProjectEngineeringName()
{
throw new NotImplementedException();
}
///
/// 是否绘制辅助线
///
///
///
protected virtual bool drawGuideLines()
{
return false;
}
///
/// 是否绘制截点
///
///
///
protected virtual bool drawGuidePoints()
{
return false;
}
///
/// 是否绘制编号
///
///
///
protected virtual bool drawMassLabelPoints()
{
return false;
}
protected virtual void drawSubclass(Graphics graphics)
{
//显示辅助线
if (drawGuideLines())
if (isAreaType)
guideClass.DrawAreaGuide(graphics, this.comboBox1.SelectedItem);
else
guideClass.DrawGuideLines(graphics, this.comboBox1.SelectedItem);
//显示截点
if (drawGuidePoints())
styleClass.DrawGuidePoints(graphics);
//显示编号
if (drawMassLabelPoints() && massLabelPoints.Count > 0)
{
int index = 0;
Font myFont = new Font("宋体", 12);
Brush bush = new SolidBrush(getGrainBoundryColor());//填充的颜色
foreach (var item in massLabelPoints)
{
graphics.DrawString("" + (++index), myFont, bush, (float)item.X - 5, (float)item.Y - 5);
}
}
}
///
/// 刷新图形边线点集合
///
protected virtual void AddRectangleToRectangleFCaps()
{
if (isAreaType)
{
if (this.bitmap == null)
return;
this.linePointList.Clear();
//获取图形上所有的点
this.linePointList.AddRange(guideClass.getGuideAreaPointList(this.bitmap, this.getCurrentGuideName(), getCurrentWorkspace().GetRuler(MeasurementUnit.Micron)));
this.documentWorkspace.Refresh();
return;
}
Mat mat;
if (!getGrainBoundryChecked() && !getBinaryChecked())
{
mat = matOrg;
}
else
{
if (getGrainBoundryChecked())
{
if (this.documentWorkspace.PhaseModels[1].mat != null)
mat = this.documentWorkspace.PhaseModels[1].mat;
else
return;
}
else if (this.documentWorkspace.PhaseModels[0].mat != null)
{
mat = this.documentWorkspace.PhaseModels[0].mat;
}
else
return;
}
if (mat == null)
return;
this.linePointList.Clear();
//获取图形上所有的点
this.linePointList.AddRange(guideClass.getGuidePointList(mat, this.comboBox1.SelectedItem));
//垂直辅助线 / 水平辅助线
bool vGuideStylesOrHGuideStyles = guideClass.IsVGuideStylesOrHGuideStyles(this.comboBox1.SelectedItem);
int matLevel = 0;
if (getGrainBoundryChecked())
matLevel = 2;
else if (getBinaryChecked())
matLevel = 1;
else if (!getGrainBoundryChecked() && !getBinaryChecked())
matLevel = 0;
//自动添加截点
styleClass.AddRectangleToRectangleFCaps(mat, matLevel, this.linePointList, vGuideStylesOrHGuideStyles, this.documentWorkspace.CompositionSurface.Width
, this.documentWorkspace.CompositionSurface.Height);
this.documentWorkspace.Refresh();
}
///
/// 初始化矩形
///
protected virtual void InitRectangleF()
{
if (this.matOrg != null)
{
bool foundItem;
if (isAreaType)
guideClass.RectangleFLine = guideClass.guideAreaRectLine(this.comboBox1.SelectedItem, out foundItem, true, getCurrentWorkspace().GetRuler(MeasurementUnit.Micron));
else
guideClass.RectangleFLine = guideClass.guideRectLine(this.comboBox1.SelectedItem, out foundItem, true, getCurrentWorkspace().GetRuler(MeasurementUnit.Micron));
if (foundItem)
this.AddRectangleToRectangleFCaps();
}
}
///
/// 更新辅助线及其样式
///
protected virtual void UpdateGuideStyle()
{
// 更新辅助线及其样式
if (isAreaType)
guideClass.UpdateGuideAreaStyle(this.bitmap, this.comboBox1.SelectedItem, this.comboBox1.SelectedIndex > 0, getCurrentWorkspace().GetRuler(MeasurementUnit.Micron));
else
guideClass.UpdateGuideStyle(matOrg, this.comboBox1.SelectedItem, true, getCurrentWorkspace().GetRuler(MeasurementUnit.Micron));
}
///
/// 辅助线维护
///
public virtual void InitComboboxValue(ArrayList arrayList)
{
UpdateCupOffPointStyle();
if (isAreaType)
guideClass.createGuideAreaClassModelsNamed(getModelName());
else
guideClass.createGuideClassModelsNamed(getModelName());
this.comboBox1.DataSource = null;
if (arrayList != null && arrayList.Count > 0)
{
this.comboboxChange = false;
arrayList.Insert(0, PdnResources.GetString("Menu.Pleaseselecttheauxiliarylineused.text"));
this.comboBox1.DataSource = arrayList;
this.comboboxChange = false;
int oldSelectIndex = -1;
for (int i = 0; i < this.comboBox1.Items.Count; i++)
{
if (this.oldSelectItem.Equals(this.comboBox1.Items[i]))
{
oldSelectIndex = i;
}
}
if (oldSelectIndex > -1)
this.comboBox1.SelectedIndex = oldSelectIndex;
else if (this.comboBox1.Items.Count > 0)
this.comboBox1.SelectedIndex = 0;
}
else
{
ArrayList arrayList1;
if (isAreaType)
arrayList1 = guideClass.getComboboxArrayAreaList1();
else
arrayList1 = guideClass.getComboboxArrayList1();
if (arrayList1.Count > 0)
{
this.comboBox1.DataSource = arrayList1;
this.comboBox1.SelectedIndex = 0;
}
}
UpdateGuideStyle();
this.documentWorkspace.Refresh();
}
#endregion
#region 内部类
internal class LocalListViewItem
{
public DocumentWorkspace Value { get; }
public string Display { get; }
public LocalListViewItem(DocumentWorkspace Value, string Display)
{
this.Value = Value;
this.Display = Display;
}
}
internal class DocumentItem
{
public Bitmap bitmap;
public GraphicsList graphicsList;
public List phaseModels;
//public AnalysisResult analysisResult;
public DocumentItem(Bitmap bitmap, GraphicsList graphicsList, List phaseModels)
{
this.bitmap = bitmap;
this.graphicsList = graphicsList;
this.phaseModels = phaseModels;
}
}
#endregion
private void button16_Click(object sender, EventArgs e)
{
this.button11.Visible = true;
this.button16.Visible = false;
this.button11.Focus();
this.allShow = false;
if (this.listView2.SelectedItems.Count <= 0)
return;
this.dataGridView2.Rows.Clear();
for (int i = 0; i < this.listView2.SelectedItems.Count; i++)
{
System.Data.DataTable dataTable1 = new System.Data.DataTable();
foreach (var dataTable in this.dataTables)
{
if (this.listView2.SelectedItems.Count > 0)
{
if (this.listView2.SelectedItems[i].Tag.Equals(dataTable.TableName))
dataTable1 = dataTable;
}
else
{
if (this.listView2.Items[0].Tag.Equals(dataTable.TableName))
dataTable1 = dataTable;
}
}
DataGridViewRow dgvr = new DataGridViewRow();
foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
{
dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
}
for (int c = 0; c < dataTable1.Columns.Count; c++)
{
dgvr.Cells[c].Value = dataTable1.Rows[0][c].ToString();
}
this.dataGridView2.Rows.Add(dgvr);
}
this.RefreshDataGridView4();
}
///
/// 刷新分析结果数据 //#############
///
protected void RefreshDataGridView4()
{
if (!this.allShow)
{
if (this.listView2.SelectedItems.Count > 0)
{
this.dataGridView2.Rows.Clear();
for (int j = 0; j < this.listView2.SelectedItems.Count; j++)
{
int dataTableIndex = 0;
for (int i = 0; i < this.dataTables.Count; i++)
{
if (this.dataTables[i].TableName.Equals(this.listView2.SelectedItems[j].Tag))
dataTableIndex = i;
}
if (this.dataTables.Count > dataTableIndex && this.dataTables[dataTableIndex].Rows.Count > 0)
{
for (int r = 0; r < this.dataTables[dataTableIndex].Rows.Count; r++)
{
DataGridViewRow dgvr = new DataGridViewRow();
foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
{
dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
}
for (int c = 0; c < this.dataTables[dataTableIndex].Columns.Count; c++)
{
if (c == 2 || c == 3)
dgvr.Cells[c].Value = Math.Round(double.Parse(string.IsNullOrEmpty(this.dataTables[dataTableIndex].Rows[r][c].ToString()) ? "0" :
this.dataTables[dataTableIndex].Rows[r][c].ToString()), Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
else if (c == 4)
{
double outValue;
if (double.TryParse(string.IsNullOrEmpty(this.dataTables[dataTableIndex].Rows[r][c].ToString()) ? "0" :
this.dataTables[dataTableIndex].Rows[r][c].ToString(), out outValue))
{
dgvr.Cells[c].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
}
else
dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString();
}
else
dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString();
}
this.dataGridView2.Rows.Add(dgvr);
}
}
}
}
else if (this.listView2.Items.Count > 0)
{
this.dataGridView2.Rows.Clear();
var firstTag = this.listView2.Items[0].Tag;
int dataTableIndex = 0;
for (int i = 0; i < this.dataTables.Count; i++)
{
if (this.dataTables[i].TableName.Equals(firstTag))
dataTableIndex = i;
}
if (this.dataTables[dataTableIndex].Rows.Count > 0)
{
for (int r = 0; r < this.dataTables[dataTableIndex].Rows.Count; r++)
{
DataGridViewRow dgvr = new DataGridViewRow();
foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
{
dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
}
for (int c = 0; c < this.dataTables[dataTableIndex].Columns.Count; c++)
{
if (c == 2 || c == 3)
dgvr.Cells[c].Value = Math.Round(double.Parse(string.IsNullOrEmpty(this.dataTables[dataTableIndex].Rows[r][c].ToString()) ? "0" :
this.dataTables[dataTableIndex].Rows[r][c].ToString()), Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
else if (c == 4)
{
double outValue;
if (double.TryParse(string.IsNullOrEmpty(this.dataTables[dataTableIndex].Rows[r][c].ToString()) ? "0" :
this.dataTables[dataTableIndex].Rows[r][c].ToString(), out outValue))
{
dgvr.Cells[c].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
}
else
dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString();
}
else
dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString();
}
this.dataGridView2.Rows.Add(dgvr);
}
}
}
}
else
{
this.dataGridView2.Rows.Clear();
System.Data.DataTable dataTable = new System.Data.DataTable();
for (int i = this.dataTables.Count - 1; i >= 0; i--)
{
dataTable = this.dataTables[i];
for (int r = 0; r < dataTable.Rows.Count; r++)
{
DataGridViewRow dgvr = new DataGridViewRow();
foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
{
dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
}
for (int c = 0; c < dataTable.Columns.Count; c++)
{
if (c == 2 || c == 3)
dgvr.Cells[c].Value = Math.Round(double.Parse(string.IsNullOrEmpty(dataTable.Rows[r][c].ToString()) ? "0" :
dataTable.Rows[r][c].ToString()), Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
else if (c == 4)
{
double outValue;
if (double.TryParse(string.IsNullOrEmpty(dataTable.Rows[r][c].ToString()) ? "0" :
dataTable.Rows[r][c].ToString(), out outValue))
{
dgvr.Cells[c].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
}
else
dgvr.Cells[c].Value = dataTable.Rows[r][c].ToString();
}
else
dgvr.Cells[c].Value = dataTable.Rows[r][c].ToString();
}
this.dataGridView2.Rows.Add(dgvr);
}
}
}
}
///
/// 切换分析结果
///
///
///
private void listview2_SelectedIndexChanged(object sender, EventArgs e)
{
if (!this.allShow)
{
if (this.listView2.SelectedItems.Count <= 0)
return;
this.dataGridView2.Rows.Clear();
for (int i = 0; i < this.listView2.SelectedItems.Count; i++)
{
System.Data.DataTable dataTable1 = new System.Data.DataTable();
foreach (var dataTable in this.dataTables)
{
if (this.listView2.SelectedItems[i].Tag.Equals(dataTable.TableName))
dataTable1 = dataTable;
}
DataGridViewRow dgvr = new DataGridViewRow();
foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
{
dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
}
for (int c = 0; c < dataTable1.Columns.Count; c++)
{
dgvr.Cells[c].Value = dataTable1.Rows[0][c].ToString();
}
this.dataGridView2.Rows.Add(dgvr);
}
this.RefreshDataGridView4();
}
}
///
/// 全部显示
///
///
///
private void button11_Click(object sender, EventArgs e)
{
if (this.listView2.Items.Count > 0)
{
this.button11.Visible = false;
this.button16.Visible = true;
this.button16.Focus();
this.allShow = true;
this.dataGridView2.Rows.Clear();
for (int i = 0; i < this.dataTables.Count; i++)
{
DataGridViewRow dgvr = new DataGridViewRow();
foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
{
dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
}
for (int c = 0; c < this.dataTables[i].Columns.Count; c++)
{
dgvr.Cells[c].Value = this.dataTables[i].Rows[0][c].ToString();
}
this.dataGridView2.Rows.Add(dgvr);
}
this.RefreshDataGridView4();
}
else
{
MessageBox.Show(PdnResources.GetString("Menu.nodata.text")+"!");
}
}
private void button12_Click(object sender, EventArgs e)
{
if (this.listView2.Items.Count > 0)
{
if (this.listView2.SelectedItems.Count > 0)
{
DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretcteddata.text")+"?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (dr == DialogResult.OK)
{
if (this.listView2.SelectedItems.Count <= 0)
return;
for (int i = this.listView2.SelectedItems.Count - 1; i >= 0; i--)
{
int selectIndex = this.listView2.SelectedItems[i].Index;
foreach (var dataTable in this.dataTables)
{
if (dataTable.TableName.Equals(this.listView2.SelectedItems[i].Tag))
{
this.dataTables.Remove(dataTable);
break;
}
}
if (bitDic.ContainsKey((string)this.listView2.SelectedItems[i].Tag))
bitDic.Remove((string)this.listView2.SelectedItems[i].Tag);
foreach (ExportProjectModel model in this.tempDataModel)
{
if (model.tagName.Equals((string)this.listView2.SelectedItems[i].Tag))
{
this.tempDataModel.Remove(model);
break;
}
}
this.listView2.Items.RemoveAt(selectIndex);
}
if (this.listView2.Items.Count == 0)
this.dataGridView2.Rows.Clear();
else
RefreshDataGridView4();
}
}
else
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectthedatatobedeleted.text")+"!");
}
}
else
{
MessageBox.Show(PdnResources.GetString("Menu.nodata.text")+"!");
}
}
private void numericUpDown1_0_ValueChanged(object sender, EventArgs e)
{
this.RefreshDataGridView4();
}
///
/// 生成报告
///
///
///
private void button_generateReport_Click(object sender, EventArgs e)
{
if (this.listView2.Items.Count == 0)
{
MessageBox.Show(PdnResources.GetString("Menu.Noresults.text"));
return;
}
if (this.checkBox_generateReport_opensetting.Checked)
this.button_setting.PerformClick();
if (this.analyzeSettingModel != null && !string.IsNullOrEmpty(this.analyzeSettingModel.analyzeClassify))
{
//获取word书签与excel单元格的关系,以字典方式存储
List mic_module_infos = PaintDotNet.DbOpreate.DbBll.mic_module_infos_BLL.FindAll().FindAll(a => a.analyze_classify == this.analyzeSettingModel.analyzeClassify);
Dictionary tagInfos = new Dictionary();
if (mic_module_infos != null && mic_module_infos.Count > 0)
{
foreach (mic_module_infos info in mic_module_infos)
{
tagInfos.Add(info.tag_name, info.cell_position);
}
}
//分析结果
List> analysisContent = new List>();
analysisContent.Add(contentHead);
foreach (DataGridViewRow item in this.dataGridView2.Rows)
{
List content = new List();
for (int i = 0; i < contentHead.Count; i++)
{
content.Add(item.Cells[i].Value.ToString());
}
analysisContent.Add(content);
}
//图片
bitList = new List();
if (this.allShow)
{
foreach (KeyValuePair> kv in this.bitDic)
{
bitList.Add(kv.Value[0]);
bitList.Add(kv.Value[1]);
}
}
else
{
if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0)
{
foreach (ListViewItem item in this.listView2.SelectedItems)
{
if (bitDic.ContainsKey(item.Name))
{
bitList.Add(bitDic[item.Name][0]);
bitList.Add(bitDic[item.Name][1]);
}
else if (bitDic.ContainsKey(item.Tag.ToString()))
{
bitList.Add(bitDic[item.Tag.ToString()][0]);
bitList.Add(bitDic[item.Tag.ToString()][1]);
}
}
}
else if (this.listView2.Items.Count > 0)
{
ListViewItem item = this.listView2.Items[0];
if (bitDic.ContainsKey(item.Name))
{
bitList.Add(bitDic[item.Name][0]);
bitList.Add(bitDic[item.Name][1]);
}
else if (bitDic.ContainsKey(item.Tag.ToString()))
{
bitList.Add(bitDic[item.Tag.ToString()][0]);
bitList.Add(bitDic[item.Tag.ToString()][1]);
}
}
}
this.appWorkspace.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, bitList, tagInfos);
}
else
MessageBox.Show(PdnResources.GetString("Menu.Pleasesettheanalysisreportfirst.text")+"!");
}
}
}