123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214 |
- using OpenCvSharp;
- using PaintDotNet.Annotation;
- using PaintDotNet.Annotation.Enum;
- using PaintDotNet.Base.CommTool;
- using PaintDotNet.Base.Functionodel;
- using PaintDotNet.Base.SettingModel;
- using PaintDotNet.CustomControl;
- using PaintDotNet.DbOpreate.DbBll;
- using PaintDotNet.DbOpreate.DbModel;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Configuration;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace PaintDotNet.DedicatedAnalysis.Battery
- {
- internal partial class BatterySectionPorosityDialog : PdnBaseForm
- {
- #region 属性
- //二值化集成1
- BinaryClassForB binaryClass;
- private int menuId;
- /// <summary>
- /// 选中图片的bitmap
- /// </summary>
- private Bitmap bitmap;
- /// <summary>
- /// 存在视场标记
- /// </summary>
- private bool existViewFlag = false;
-
-
-
- private int changeCount;
- /// <summary>
- /// 主空间
- /// </summary>
- private AppWorkspace appWorkspace;
-
- /// <summary>
- /// 图像面板
- /// </summary>
- private DocumentWorkspaceWindow documentWorkspace;
- /// <summary>
- /// 公共控件
- /// </summary>
- private GeneralAnalysisCommonControlButtons commonControlButtons;
- /// <summary>
- /// 图片测量记录
- /// </summary>
- private List<DataTable> pictureDataTables = new List<DataTable>();
-
- /// <summary>
- /// 网格Xml
- /// </summary>
- private GrainSizePointCountingMethodModel grainSizePointCountingMethodModel;
-
- /// <summary>
- /// 数据变化
- /// </summary>
- private bool saveSuccess = false;
-
- private BinaryControlSmaller bc;
- #endregion 属性
- #region 数据属性
-
- /// <summary>
- /// 折线点的集合
- /// </summary>
- public List<System.Drawing.Point> pointArray = new List<System.Drawing.Point>();
- /// <summary>
- /// 存储所有轮廓线的点集合
- /// </summary>
- private List<PointF> pointList = new List<PointF>();
- /// <summary>
- /// 存储所有轮廓线集合
- /// </summary>
- private List<List<PointF>> lineList = new List<List<PointF>>();
- /// <summary>
- /// 存储所有孔隙线的点集合
- /// </summary>
- private List<PointF> kongPointList = new List<PointF>();
- /// <summary>
- /// 存储所有孔隙线集合
- /// </summary>
- private List<List<PointF>> kongLineList = new List<List<PointF>>();
- /// <summary>
- /// 存储所有删除孔隙线的点集合
- /// </summary>
- private List<PointF> delPointList = new List<PointF>();
- /// <summary>
- /// 存储所有删除孔隙线集合
- /// </summary>
- private List<List<PointF>> delLineList = new List<List<PointF>>();
- //轮廓修改状态
- bool isLunKuo = false;
- //添加孔隙状态
- bool isAddKong = false;
- //删除孔隙状态
- bool isDelKong = false;
- //绘制轮廓
- bool isDrwKuo = false;
- //绘制轮廓结束
- bool DrwDone = false;
- //设置圆心
- bool DrwCenter = false;
- //画圆
- bool DrwCircle = false;
- /// <summary>
- /// 0:添加 1:选择 2:删除
- /// </summary>
- private int operationK = -1;
- /// <summary>
- /// 被选择的线
- /// </summary>
- private int selected = -1;
- /// <summary>
- /// 起止点
- /// </summary>
- private System.Drawing.PointF startPoint, endPoint;
- /// <summary>
- /// 存储所有线的点集合
- /// </summary>
- private List<PointF[]> pointList1 = new List<PointF[]>();
- /// <summary>
- /// 存储当前线的点集合
- /// </summary>
- private PointF[] nowLine;
- /// <summary>
- /// 辅助计算偏移量-移动线两端的点
- /// </summary>
- private PointF lastPoint = new PointF(0, 0);
- /// <summary>
- /// 辅助计算偏移量-移动线中间的点
- /// </summary>
- private PointF tempPoint = new PointF(0, 0);
- /// <summary>
- /// 判断图形是否可移动
- /// </summary>
- private bool canMove = false;
- /// <summary>
- /// 测量点
- /// </summary>
- public List<RectangleF> rectangleFList = new List<RectangleF>();
- /// <summary>
- /// 移动线上的哪一个点
- /// </summary>
- private int movePointIndex = -1;
- /// <summary>
- /// 线的总数
- /// </summary>
- private int lineCount = 0;
- /// <summary>
- /// 单位标尺
- /// </summary>
- private double unitLength = 1;
- /// <summary>
- /// 画圆外点
- /// </summary>
- private PointF tempCirclePoint = new PointF(0, 0);
- /// <summary>
- /// 同心圆半径
- /// </summary>
- private List<int> ListRadius = new List<int>();
- /// <summary>
- /// 同心圆颜色
- /// </summary>
- private Dictionary<int, Color> ListRadiusColor = new Dictionary<int, Color>();
- private List<Color> colorList = new List<Color>() { Color.FromArgb(255, 0, 0), Color.FromArgb(0, 255, 0), Color.FromArgb(139, 0, 0), Color.FromArgb(128, 0, 128), Color.FromArgb(122, 160, 255) };
- #endregion
- /// <summary>
- ///
- /// </summary>
- /// <param name="appWorkspace"></param>
- public BatterySectionPorosityDialog(AppWorkspace appWorkspace, int menuId)
- {
- this.KeyPreview = true;
- this.KeyDown += OnKeyDown;
- this.menuId = menuId;
- binaryClass = new BinaryClassForB(menuId);
-
- InitializeComponent();
- InitializeLanguageText();
-
- ColumnHeader header0 = new ColumnHeader();
- header0.Text = "";
- header0.Width = 180;
- this.appWorkspace = appWorkspace;
-
- this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
- this.documentWorkspace.Dock = DockStyle.Fill;
- this.documentWorkspace.HookMouseEvents();
- this.documentWorkspace.AuxiliaryLineEnabled = false;
- this.documentWorkspace.Visible = false;
- this.documentWorkspace.panel.Paint += Panel_Paint;
- this.documentWorkspace.panel.MouseDown += OnMouseDown;
-
- this.documentWorkspace.panel.MouseUp += OnMouseUp;
- this.documentWorkspace.panel.Paint += Panel_Paint;
- this.documentWorkspace.panel.MouseMove += onMouseMove;
- this.documentWorkspace.activeTool = DrawToolType.Pointer;
- this.groupBox7.Controls.Add(this.documentWorkspace);
- this.commonControlButtons = new GeneralAnalysisCommonControlButtons();
- this.commonControlButtons.Dock = DockStyle.Top;
- this.commonControlButtons.Height = 30;
- this.commonControlButtons.HideZoomToWindowAndActualSize();
- this.commonControlButtons.trackLabel.Text = "单击开始画线,右键停止。";
- this.commonControlButtons.trackLabel.Visible = true;
- this.commonControlButtons.trackLabel.Width = 300;
- this.commonControlButtons.Visible = false;
- this.groupBox7.Controls.Add(commonControlButtons);
- //获取
- //Startup.instance.rules.TryGetValue(MeasurementUnit.Micron, out ruleValue);
- //double ruleValue = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetRuler(MeasurementUnit.Micron);
- ////double physical_area_length_Micron = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron);
- //二值化集成2
- bc.OriginCheckedChangedAction += new EventHandler(this.bcOriginCheckedChanged);//初始化原图勾选改变事件
- rb_RightCircle.CheckedChanged += new EventHandler(this.RightCircleCheckedChanged);
- txt_RightLineWeight.SelectedIndexChanged += new EventHandler(this.RightCircleCheckedChanged);
- numericMax.ValueChanged += new EventHandler(this.RightCircleCheckedChanged);
- binaryClass.imageType = 1;
- binaryClass.createDocumentItemsSmaller(new string[] { "bp1" }, this.bc, this.appWorkspace, this.documentWorkspace, this.listView1);//初始化相的工作结构
- binaryClass.CilCount = Convert.ToInt32(txt_RightLineWeight.Text);
- InitCommonButtonEvent();
- InitGridStyle();
- InitPicList();
- // SetAnalyzeModelFromXml(getModelName());
- }
- private void ShowImgEvent(object sender, EventArgs e)
- {
- if (this.listView1.Items.Count == 0)
- {
- return;
- }
- listView1.Focus();
-
- this.listView1.Items[0].Focused = true;
- this.listView1.Items[0].Selected = true;
-
- }
- #region 二值化相关方法
- private void InclusionsStandardDialog_FormClosing(object sender, FormClosingEventArgs e)
- {
- binaryClass.saveParams();
- }
- private void ShownChoiseItemAndInitData(object sender, EventArgs e)
- {
- binaryClass.RefreshHistogramControl1Values();
- }
- /// <summary>
- /// 添加参数改变的监听
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void GrainSizePointCountingMethodDialog_Load(object sender, EventArgs e)
- {
- for (int i = 0; i < this.dataGridView1.Columns.Count; i++)
- {
- this.dataGridView1.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
- }
- this.dataGridView4.SortCompare += DataGridView4_SortCompare;
- this.binaryClass.loadParams();
- }
- private bool bcBinaryChecked()
- {
- return bc != null && bc.BinaryChecked;
- }
- private bool bcOriginChecked()
- {
- return bc != null && bc.OriginChecked;
- }
- /// <summary>
- /// 显示原图/原图+二值图
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void bcOriginCheckedChanged(object sender, EventArgs e)
- {
- if (!bcOriginChecked())
- {
- if (bcBinaryChecked())
- this.documentWorkspace.PhaseModels[0].choise = true;
- }
- else
- this.documentWorkspace.PhaseModels[0].choise = false;
- this.documentWorkspace.Refresh();
- }
- #endregion
- /// <summary>
- /// 初始化画面数据
- /// </summary>
- private void InitGridStyle()
- {
- grainSizePointCountingMethodModel = XmlSerializeHelper.DESerializer<GrainSizePointCountingMethodModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizePointCountingMethodModel.xml", FileMode.Open));
- if (grainSizePointCountingMethodModel.GridStyleList != null)
- {
- ArrayList arrayList = new ArrayList();
- foreach (var GridStyle in grainSizePointCountingMethodModel.GridStyleList)
- {
- arrayList.Add(GridStyle.gridName);
- }
- if (grainSizePointCountingMethodModel.GridStyleList.Count == 0)
- {
-
- }
- }
- }
-
- /// <summary>
- /// 初始化图片列表数据
- /// </summary>
- public void InitPicList()
- {
- //初始化图片列表
- for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Length; i++)
- {
- this.imageList1.Images.Add("img" + i, this.appWorkspace.DocumentWorkspaces[i].BinarizationThumbnail);
- this.listView1.Items.Add("", i);
- this.listView1.Items[i].ImageIndex = i;
- this.listView1.Items[i].Text = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
- this.listView1.Items[i].Name = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
- }
- this.Shown += ShowImgEvent;
- }
- #region 初始化
- private void InitializeLanguageText()
- {
- this.bc = new PaintDotNet.CustomControl.BinaryControlSmaller();
- //
- // bc
- //
- this.bc.BinaryBackColor = System.Drawing.Color.Red;
- this.bc.BinaryChecked = false;
- this.bc.BinaryStyle = 1;
- this.bc.Location = new System.Drawing.Point(152, 7);
- 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 = 3;
- this.Controls.Add(this.bc);
- this.Controls.SetChildIndex(this.bc, 0);
-
- }
- #endregion
- #region 公共按钮
- 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;
- }
- #endregion
-
-
- private void listView1_MouseDown(object sender, MouseEventArgs e)
- {
- this.changeCount = 0;
- }
- private void DataGridView4_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
- {
- // 如果是数据的列,则按浮点数处理
- if (e.Column.Index > 1)//###20186
- {
- e.SortResult = (Convert.ToDouble(e.CellValue1) - Convert.ToDouble(e.CellValue2) > 0) ? 1 : (Convert.ToDouble(e.CellValue1) - Convert.ToDouble(e.CellValue2) < 0) ? -1 : 0;
- }
- //否则,按字符串比较
- else
- {
- e.SortResult = System.String.Compare(Convert.ToString(e.CellValue1), Convert.ToString(e.CellValue2));
- }
- e.Handled = true;//不能省掉,不然没效果
- }
- private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
- {
- bool change = false;
- if (this.changeCount == 0)
- {
- if (this.dataGridView1.Rows.Count > 0)
- {
- if (this.saveSuccess)
- {
- DialogResult dt = MessageBox.Show(PdnResources.GetString("Menu.Whethertosavetherrentpicture.text") + "?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.YesNo, MessageBoxIcon.Question);
- if (dt == DialogResult.Yes)
- {
- string imgName = this.appWorkspace.DocumentWorkspaces[e.ItemIndex].GetFriendlyName();
- string tag = this.imageList1.Images.Keys[e.ItemIndex];
- if (this.dataGridView1.Rows.Count == 0)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseaddtype.text") + "!");
- return;
- }
- }
- }
- }
- }
- else
- {
- if (change)
- SelectedIndexChanged();
- }
- if (unitLength == 1)
- unitLength = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetRuler(MeasurementUnit.Micron);
- this.changeCount++;
- }
- /// <summary>
- /// 切换图片
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void listView1_SelectedIndexChanged(object sender, EventArgs e)
- {
-
-
- SelectedIndexChanged();
- }
- List<PointF> list = new List<PointF>();
- /// <summary>
- /// 切换图片
- /// </summary>
- private void SelectedIndexChanged()
- {
- if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Selected)
- {
- existViewFlag = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GraphicsList.IsExsitView();
- this.bitmap = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
-
- lineList.Clear();
- pointList.Clear();
- kongLineList.Clear();
- kongPointList.Clear();
- delLineList.Clear();
- delPointList.Clear();
- pointList1.Clear();
- binaryClass.SetCenter = new OpenCvSharp.Point(0, 0);
- binaryClass.R = 0;
- isLunKuo = false;
- isAddKong = false;
- isDelKong = false;
- isDrwKuo = false;
- DrwDone = false;
- DrwCenter = false;
- DrwCircle = false;
- this.documentWorkspace.Refresh();
- this.dataGridView1.Rows.Clear();
- this.dataGridView4.Rows.Clear();
-
- Init();
- this.documentWorkspace.GridRectangleEnabled = false;
- //getimage();
- //getbian(bitmap);
- binaryClass.CilCount = Convert.ToInt32(txt_RightLineWeight.Text);
- //二值化集成4
- binaryClass.listView1_SelectedIndexChanged(this.bitmap);
- binaryClass.bcDefault();
- // btnCircleDrawing_Click(null, null);
- this.documentWorkspace.Refresh();
- }
- }
- #region 原始事件
- private void Init()
- {
- this.commonControlButtons.Visible = true;
-
- this.dataGridView1.Rows.Clear();
- this.dataGridView4.Rows.Clear();
- this.documentWorkspace.phaseModels.Clear();
- }
-
- /// <summary>
- /// 画布绘制
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Panel_Paint(object sender, PaintEventArgs e)
- {
- if (this.documentWorkspace.CompositionSurface != null)
- {
- //
- // 以下是计算绘制图片的位置和大小并绘制图片
- //
- 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;
- //if (pointArray.Count > 1)
- //{
- // e.Graphics.DrawLines(new Pen(Color.FromArgb(0, 0, 0), 2), pointArray.ToArray());
- //}
- //
- // 以下是绘制网格、标注、测量、视场等开始
- //
- e.Graphics.TranslateTransform(x, y);
- e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio);
- Draw(e.Graphics);
- //e.Graphics.DrawLines(new Pen(this.panel1.BackColor, Convert.ToInt32(this.txt_LeftLineWeight.Text)), list.ToArray());
- e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio);
- e.Graphics.TranslateTransform(-x, -y);
-
-
- }
- if (bc.isedit)
- {
- bc.isedit = false;
- List<List<int>> CircleDate = bc.data;
- bindGrid(CircleDate);
- }
-
- }
- // <summary>
- /// 存储字号与颜色字典
- /// </summary>
- public Dictionary<string, Color> colourFont = new Dictionary<string, Color>() { { "20", Color.White } };
- /// <summary>
- /// 绘制
- /// </summary>
- private void Draw(Graphics graphics)
- {
- //轮廓手动干预线
- if (lineList.Count > 0)
- {
- for (int i = 0; i < lineList.Count; i++)
- {
- //graphics.DrawLines(new Pen(Color.FromArgb(30, 144,255), 2), lineList[i].ToArray());
- graphics.DrawLines(new Pen(Color.FromArgb(30, 144,255), 2), lineList[i].ToArray());
- }
- }
- if (pointList.Count > 1)
- {
- graphics.DrawLines(new Pen(Color.FromArgb(30, 144,255), 2), pointList.ToArray());
- //Pen _pen = new Pen(Color.FromArgb(99, 99, 99), 2);
- //_pen.DashStyle = DashStyle.Dash;
- //_pen.DashCap = DashCap.Triangle;
- //graphics.DrawLines(_pen, pointList.ToArray());
- }
- //孔隙手动干预线
- Color color = bc.BinaryBackColor;
- if (kongLineList.Count > 0)
- {
-
- for (int i = 0; i < kongLineList.Count; i++)
- {
-
- graphics.DrawLines(new Pen(color, 2), kongLineList[i].ToArray());
- }
- }
- if (kongPointList.Count > 1)
- {
- graphics.DrawLines(new Pen(color, 2), kongPointList.ToArray());
- }
- //手动画圆
- if(!rb_RightCircle.Checked)
- {
- if (ListRadius.Count > 0)
- {
- for (int i = 0; i < ListRadius.Count; i++)
- {
- Rectangle rect = new Rectangle(Convert.ToInt32(binaryClass.SetCenter.X - ListRadius[i]), Convert.ToInt32(binaryClass.SetCenter.Y - ListRadius[i]), Convert.ToInt32(ListRadius[i] * 2), Convert.ToInt32(ListRadius[i] * 2));
- graphics.DrawEllipse(new Pen(colorList[i], 2), rect);
- }
- }
- }
-
- if (DrwCircle && tempCirclePoint != null)
- {
- PointF diff = new PointF(tempCirclePoint.X - binaryClass.SetCenter.X, tempCirclePoint.Y - binaryClass.SetCenter.Y);
- double culength =Math.Sqrt(diff.X * diff.X + diff.Y * diff.Y);
- Rectangle rect = new Rectangle(Convert.ToInt32(binaryClass.SetCenter.X - culength), Convert.ToInt32(binaryClass.SetCenter.Y - culength), Convert.ToInt32(culength * 2), Convert.ToInt32(culength * 2));
- graphics.DrawLines(new Pen(colorList[ListRadius.Count], 2), new PointF[] { new PointF(binaryClass.SetCenter.X, binaryClass.SetCenter.Y), tempCirclePoint });
- graphics.DrawEllipse(new Pen(colorList[ListRadius.Count], 2),rect);
- }
- graphics.SmoothingMode = SmoothingMode.AntiAlias;
- Pen standardPen = new Pen(Color.FromArgb(0, 255, 0), 4);//基准线画笔
- Pen surfacePen = new Pen(Color.FromArgb(255, 0, 0), 4);//钢样表面画笔
- Pen completePen = new Pen(Color.FromArgb(0, 0, 255), 4);//完全脱碳层画笔
- Pen validPen = new Pen(Color.FromArgb(255, 255, 255), 4);//有效脱碳层画笔
- Pen partPen = new Pen(Color.FromArgb(0, 0, 0), 2);//部分脱碳层画笔
- Pen borderPen = new Pen(Color.Black);//填充点外圈
- SolidBrush insideBrush = new SolidBrush(Color.White);//填充点内圈
- Pen rectPen = new Pen(Color.Black);
- rectPen.DashStyle = DashStyle.Custom;
- float[] dashArray = { 2.0f, 3.0f };
- rectPen.DashPattern = dashArray;
- if (pointList1.Count > 0)
- {
- foreach (PointF[] pointFs in pointList1)
- {
- PointF[] pf = pointFs;
- if (pointFs.Count() > 1 && pointFs[0] != pointFs[1])
- {
- float lineLength = 12;
- double angle = Math.Round(BasicCalculationHelper.AngleText(pointFs[0], pointFs[1], new PointF(pointFs[0].X + lineLength, pointFs[0].Y)), 10);
- //判断第二个点相对于第一个点的象限
- int x2 = (int)(pointFs[1].X - pointFs[0].X);
- if (x2 == 0)
- x2 = 1;
- int y2 = (int)(pointFs[1].Y - pointFs[0].Y);
- if (y2 == 0)
- y2 = 1;
- int i2 = 0;
- if (x2 > 0 && y2 > 0) //第4象限
- {
- i2 = 4;
- }
- else if (x2 > 0 && y2 < 0) //第1象限
- {
- i2 = 1;
- }
- else if (x2 < 0 && y2 < 0) //第2象限
- {
- i2 = 2;
- }
- else if (x2 < 0 && y2 > 0) //第3象限
- {
- i2 = 3;
- }
- double sAngle1;
- double eAngle1;
- double sAngle2;
- double eAngle2;
- if (i2 == 1 || i2 == 2)
- {
- sAngle1 = 360 - angle;
- eAngle1 = 180 - angle;
- sAngle2 = 270 - angle;
- eAngle2 = 90 - angle;
- }
- else
- {
- sAngle1 = angle;
- eAngle1 = 180 + angle;
- sAngle2 = 270 + angle;
- eAngle2 = 90 + angle;
- }
- graphics.DrawLine(standardPen, pointFs[0], pointFs[1]);
- if (!double.IsNaN(sAngle1) && !double.IsNaN(eAngle1) && !double.IsNaN(sAngle2) && !double.IsNaN(eAngle2))
- {
- PointF assistPoint1 = BasicCalculationHelper.GetAnglePoint(new PointF((pointFs[0].X + lineLength), pointFs[0].Y), pointFs[0], sAngle2);
- PointF assistPoint2 = BasicCalculationHelper.GetAnglePoint(new PointF((pointFs[0].X + lineLength), pointFs[0].Y), pointFs[0], eAngle2);
- PointF assistPoint3 = BasicCalculationHelper.GetAnglePoint(new PointF((pointFs[1].X + lineLength), pointFs[1].Y), pointFs[1], sAngle2);
- PointF assistPoint4 = BasicCalculationHelper.GetAnglePoint(new PointF((pointFs[1].X + lineLength), pointFs[1].Y), pointFs[1], eAngle2);
- graphics.DrawLine(surfacePen, assistPoint1, assistPoint2);
- graphics.DrawLine(partPen, assistPoint3, assistPoint4);
- //PointF[] pf = pointFs;
- if (i2 == 1 || i2 == 2)
- {
- graphics.DrawString(Math.Round((BasicCalculationHelper.GetDistance(pf[1], pf[0], 4) * unitLength), 2).ToString(), new Font("宋体", float.Parse(colourFont.Keys.First()), System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))), new SolidBrush(colourFont.Values.First()), assistPoint4.X, assistPoint4.Y - 10);
- }
- else
- {
- graphics.DrawString(Math.Round((BasicCalculationHelper.GetDistance(pf[1], pf[0], 4) * unitLength), 2).ToString(), new Font("宋体", float.Parse(colourFont.Keys.First()), System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))), new SolidBrush(colourFont.Values.First()), assistPoint3.X, assistPoint3.Y - 10);
- }
- }
- }
- }
- if (selected > -1)
- {
- int tempLess = (int)(InvariantData.rectless * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1));
- int tempPlus = (int)(InvariantData.rectplus * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1));
- graphics.DrawRectangle(borderPen, new Rectangle((int)(pointList1[selected][0].X - tempLess), (int)(pointList1[selected][0].Y - tempLess), tempPlus, tempPlus));
- graphics.FillRectangle(insideBrush, new RectangleF(pointList1[selected][0].X - tempLess, pointList1[selected][0].Y - tempLess, tempPlus, tempPlus));
- graphics.DrawRectangle(borderPen, new Rectangle((int)(pointList1[selected][1].X - tempLess), (int)(pointList1[selected][1].Y - tempLess), tempPlus, tempPlus));
- graphics.FillRectangle(insideBrush, new RectangleF(pointList1[selected][1].X - tempLess, pointList1[selected][1].Y - tempLess, tempPlus, tempPlus));
- graphics.DrawRectangle(rectPen, rectangleFList[selected].X, rectangleFList[selected].Y, rectangleFList[selected].Width, rectangleFList[selected].Height);
- }
- }
- standardPen.Dispose();
- surfacePen.Dispose();
- completePen.Dispose();
- validPen.Dispose();
- partPen.Dispose();
- borderPen.Dispose();
- insideBrush.Dispose();
- rectPen.Dispose();
- }
- /// <summary>
- /// 画同心圆
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnCircleDrawing_Click(object sender, EventArgs e)
- {
- if (this.listView1.Items.Count == 0)
- {
- return;
- }
- if (rb_RightCircle.Checked)
- {
- binaryClass.R = Convert.ToInt32(numericMax.Value);
- List<List<int>> CircleDate = binaryClass.getCircleDate(Convert.ToInt32(txt_RightLineWeight.Text));
- bindGrid(CircleDate);
- }
- else
- {
- List<List<int>> CircleDate = binaryClass.getCircleDate(0);
- bindGrid(CircleDate);
- }
-
- }
- /// <summary>
- /// 自动绘制
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RightCircleCheckedChanged(object sender, EventArgs e)
- {
- if (this.listView1.Items.Count == 0)
- {
- return;
- }
- if (rb_RightCircle.Checked)
- ListRadius.Clear();
- ListRadiusColor.Clear();
- if (!rb_RightCircle.Checked)
- {
- List<List<int>> CircleDate = binaryClass.getCircleDate(0);
- bindGrid(CircleDate);
- }
- else
- {
- binaryClass.R = Convert.ToInt32(numericMax.Value);
- List<List<int>> CircleDate = binaryClass.getCircleDate(Convert.ToInt32(txt_RightLineWeight.Text));
- bindGrid(CircleDate);
- }
-
- }
- private void bindGrid(List<List<int>> dataList)
- {
- if (dataList==null)
- {
- return;
- }
- if (dataList.Count < 1)
- {
- return;
- }
- List<int> CircleDate = dataList[0];
- if (CircleDate.Count < 2)
- {
- return;
- }
- //半径
- numericMax.Value = binaryClass.R;
- //标尺 微米/像素
- double d = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetRuler(MeasurementUnit.Micron);
- //图像自动识别标尺x微米/像素
- //double q= binaryClass.GetRuler();
- //孔隙率信息列表
- dataGridView1.Rows.Clear();
- List<Color> colorList = new List<Color>() { Color.FromArgb(255, 0, 0), Color.FromArgb(0, 255, 0), Color.FromArgb(139, 0, 0), Color.FromArgb(128, 0, 128), Color.FromArgb(122, 160, 255) };
- //最大面积
- double maxArea =(double)CircleDate[CircleDate.Count - 1];
- //孔隙率
- double k = (double)CircleDate[CircleDate.Count - 2] / maxArea;
- //孔面积
- double totalArea = CircleDate[CircleDate.Count - 2] * d * d;
- int newrow = dataGridView1.Rows.Add();
- dataGridView1.Rows[newrow].Cells[0].Value = "整体";
- dataGridView1.Rows[newrow].Cells[1].Value = Math.Round(totalArea, 2).ToString();
- dataGridView1.Rows[newrow].Cells[2].Value = Math.Round(maxArea * d * d, 2).ToString();
- dataGridView1.Rows[newrow].Cells[3].Value = Math.Round(k * 100, 2).ToString() + "%";
- int n = CircleDate.Count - 2;
- //方差
- double sd = 0;
- //标准方差
- double rsd = 0;
- //平均值
- double x = 0;
- //半径
- int r = binaryClass.r;
- List<double> tlist = new List<double>();
- double nArea = 0;
- Dictionary<int, Color> listradiuscolor = ListRadiusColor.OrderBy(c => c.Key).ToDictionary(pair => pair.Key, pair => pair.Value);
- //圆环面积
- List<double> ListArea = new List<double>();
- for (int i = 0; i < listradiuscolor.Count; i++)
- {
- if (i == listradiuscolor.Count - 1)
- {
- double Ar = listradiuscolor.ElementAt(i - 1).Key ;
- double ar = maxArea - Math.PI * Ar * Ar;
- ListArea.Add(ar * d * d);
- }
- else if (i > 0)
- {
- double Ar = listradiuscolor.ElementAt(i - 1).Key * d;
- double Br = listradiuscolor.ElementAt(i).Key * d;
- double ar = Math.PI * (Br + Ar) * (Br - Ar);
- ListArea.Add(ar);
- }
- else if (i == 0)
- {
- double Ar = listradiuscolor.ElementAt(i).Key * d;
- double ar = Math.PI * Ar * Ar;
- ListArea.Add(ar);
- }
-
- }
- if (listradiuscolor.Count > 0)
- {
- for (int i = 0; i < n; i++)
- {
- double t = (double)CircleDate[i] / maxArea;
- if (i == n - 1)
- {
- t = (CircleDate[CircleDate.Count - 2] - nArea) / maxArea;
- }
- double curArea = (double)CircleDate[i] * d * d;
- if (i == n - 1)
- {
- curArea = (CircleDate[CircleDate.Count - 2] - nArea) * d * d;
- }
- newrow = dataGridView1.Rows.Add();
- if (i == n - 1)
- {
- dataGridView1.Rows[newrow].Cells[0].Value = "剩余部分";
- }
- else
- {
- dataGridView1.Rows[newrow].Cells[0].Value = "同心圆" + (i + 1).ToString();
- }
- dataGridView1.Rows[newrow].Cells[1].Value = Math.Round(curArea, 2).ToString();
- dataGridView1.Rows[newrow].Cells[2].Value = Math.Round(ListArea[i], 2).ToString();
- dataGridView1.Rows[newrow].Cells[3].Value = Math.Round(t * 100, 2).ToString() + "%";
-
-
- dataGridView1.Rows[newrow].DefaultCellStyle.ForeColor = listradiuscolor.ElementAt(i).Value;
-
- tlist.Add(t);
- nArea = nArea + (double)CircleDate[i];
- x = x + t;
- }
- }
- else
- {
- for (int i = 0; i < n; i++)
- {
- double t = 0;
- double ar = Math.PI * r * r * ((i + 1) * (i + 1) - i * i);
- if (i == n - 1)
- {
- ar = maxArea - Math.PI * i * r * i * r;
- }
- t = (double)CircleDate[i] / maxArea;
- if (i == n - 1)
- {
- t = (CircleDate[CircleDate.Count - 2] - nArea) / maxArea;
- }
- double curArea = (double)CircleDate[i] * d * d;
- if (i == n - 1)
- {
- curArea = (CircleDate[CircleDate.Count - 2] - nArea) * d * d;
- }
- newrow = dataGridView1.Rows.Add();
- if (i == n - 1)
- {
- dataGridView1.Rows[newrow].Cells[0].Value = "剩余部分";
- }
- else
- {
- dataGridView1.Rows[newrow].Cells[0].Value = "同心圆" + (i + 1).ToString();
- }
- dataGridView1.Rows[newrow].Cells[1].Value = Math.Round(curArea, 2).ToString();
- dataGridView1.Rows[newrow].Cells[2].Value = Math.Round(ar * d * d, 2).ToString();
- dataGridView1.Rows[newrow].Cells[3].Value = Math.Round(t * 100, 2).ToString() + "%";
- dataGridView1.Rows[newrow].DefaultCellStyle.ForeColor = colorList[i];
-
- tlist.Add(t);
- nArea = nArea + (double)CircleDate[i];
- x = x + t;
- }
- }
-
- x = x / n;
- for (int i = 0; i < n; i++)
- {
- double t = tlist[i];
- sd = sd + (t - x) * (t - x);
- }
- sd = Math.Sqrt(sd / (n - 1));
- rsd = sd / x;
- newrow = dataGridView1.Rows.Add();
- dataGridView1.Rows[newrow].Cells[0].Value = "同心圆孔隙率RSD";
- dataGridView1.Rows[newrow].Cells[1].Value = Math.Round(rsd * 100, 0).ToString() + "%";
- dataGridView1.Rows[newrow].Cells[2].Value ="";
- dataGridView1.Rows[newrow].Cells[3].Value = "";
- //孔隙信息列表
- dataGridView4.Rows.Clear();
- for (int i = 1; i < dataList.Count-1; i++)
- {
- if(dataList[i].Count<6)
- { continue; }
- int newPo = dataGridView4.Rows.Add();
- //序号
- dataGridView4.Rows[newPo].Cells[0].Value = (newPo+1).ToString();
- //X
- dataGridView4.Rows[newPo].Cells[1].Value = dataList[i][0];
- //Y
- dataGridView4.Rows[newPo].Cells[2].Value = dataList[i][1];
- //长
- dataGridView4.Rows[newPo].Cells[3].Value =Math.Round( Convert.ToDouble( dataList[i][2])*d,2).ToString();
- //宽
- dataGridView4.Rows[newPo].Cells[4].Value = Math.Round(Convert.ToDouble(dataList[i][3]) * d, 2).ToString();
- //面积
- dataGridView4.Rows[newPo].Cells[5].Value = Math.Round(Convert.ToDouble(dataList[i][4]) * d*d, 2).ToString();
- //标识
- dataGridView4.Rows[newPo].Cells[6].Value = dataList[i][5];
- }
- }
-
- #region 手动干预
- /// <summary>
- /// 修改轮廓
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnLunkuo_Click(object sender, EventArgs e)
- {
- isLunKuo = true;
- isAddKong = false;
- isDelKong = false;
- isDrwKuo = false;
- DrwCenter = false;
- DrwCircle = false;
- operationK = -1;
- }
- /// <summary>
- /// 添加孔隙
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnAddKong_Click(object sender, EventArgs e)
- {
- isLunKuo = false;
- isAddKong = true;
- isDelKong = false;
- isDrwKuo = false;
- DrwCenter = false;
- DrwCircle = false;
- operationK = -1;
- }
- /// <summary>
- /// 删除孔隙
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnDelKong_Click(object sender, EventArgs e)
- {
- isLunKuo = false;
- isAddKong = false;
- isDelKong = true;
- isDrwKuo = false;
- DrwCenter = false;
- DrwCircle = false;
- operationK = -1;
- }
- /// <summary>
- /// 绘制轮廓
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnDrwKuo_Click(object sender, EventArgs e)
- {
- isLunKuo = false;
- isAddKong = false;
- isDelKong = false;
- isDrwKuo = true;
- DrwDone = true;
- DrwCenter = false;
- DrwCircle = false;
- operationK = -1;
- lineList.Clear();
- }
- /// <summary>
- /// 设置圆心
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnbtnSetCenter_Click(object sender, EventArgs e)
- {
- isLunKuo = false;
- isAddKong = false;
- isDelKong = false;
- isDrwKuo = false;
- DrwDone = false;
- DrwCenter = true;
- DrwCircle = false;
- operationK = -1;
- }
- /// <summary>
- /// 画圆
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnDrwCircle_Click(object sender, EventArgs e)
- {
- if (rb_RightCircle.Checked)
- {
- MessageBox.Show("请取消自动绘制!");
- }
- else
- {
- if (ListRadius.Count == 5)
- {
- MessageBox.Show("同心圆最多绘制5个!");
- return;
- }
- isLunKuo = false;
- isAddKong = false;
- isDelKong = false;
- isDrwKuo = false;
- DrwDone = false;
- DrwCenter = false;
- DrwCircle = true;
- operationK = -1;
- }
-
- }
- /// <summary>
- /// 重新统计
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnReDrw_Click(object sender, EventArgs e)
- {
- Recalculation();
- }
- private void Recalculation()
- {
- if (pointList.Count > 1)
- {
- List<PointF> pointFs = new List<PointF>(pointList.ToArray());
- lineList.Add(pointFs);
- pointList.Clear();
- }
- if (kongPointList.Count > 1)
- {
- List<PointF> pointFs = new List<PointF>(kongPointList.ToArray());
- kongLineList.Add(pointFs);
- kongPointList.Clear();
- }
- if (delPointList.Count > 1)
- {
- }
- List<List<int>> CircleDate = new List<List<int>>();
- if (DrwDone)
- {
- CircleDate = binaryClass.DrwLunKuoNew(lineList, kongLineList, delPointList);
- }
- else
- {
- CircleDate = binaryClass.DrwLunKuo(lineList, kongLineList, delPointList);
- }
- bindGrid(CircleDate);
- isLunKuo = false;
- isAddKong = false;
- isDelKong = false;
- isDrwKuo = false;
- DrwCenter = false;
- DrwCircle = false;
- operationK = -1;
- }
- /// <summary>
- /// 计算外接矩形
- /// </summary>
- private RectangleF CalcOtherRectangle(PointF p1, PointF p2)
- {
- RectangleF rectangleF = new RectangleF();
- if (p1.X > p2.X)
- rectangleF.X = p2.X;
- else
- rectangleF.X = p1.X;
- if (p1.Y > p2.Y)
- rectangleF.Y = p2.Y;
- else
- rectangleF.Y = p1.Y;
- rectangleF.Width = Math.Abs(p2.X - p1.X);
- rectangleF.Height = Math.Abs(p2.Y - p1.Y);
- int tempLess = (int)(InvariantData.rectless * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1)) * 5;
- int tempPlus = (int)(InvariantData.rectplus * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1)) * 5;
- return new RectangleF(rectangleF.X - tempLess, rectangleF.Y - tempLess, rectangleF.Width + tempPlus, rectangleF.Height + tempPlus);
- }
- /// <summary>
- /// 移动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void onMouseMove(object sender, MouseEventArgs e)
- {
- if (operationK >= 0 && e.Button == MouseButtons.Left)
- {
- PointF movePoint = this.documentWorkspace.GetScalePoint(e.Location);
- if (operationK == 0)
- {
- this.endPoint = movePoint;
- pointList1[lineCount][1] = endPoint;
- }
- else if (operationK == 1 && selected > -1 && canMove)
- {
- float dx = movePoint.X - lastPoint.X;
- float dy = movePoint.Y - lastPoint.Y;
- float dxTemp = movePoint.X - tempPoint.X;
- float dyTemp = movePoint.Y - tempPoint.Y;
- lastPoint.X = movePoint.X;
- lastPoint.Y = movePoint.Y;
- if (movePointIndex == -1)
- {
- RectangleF rectangleF = new RectangleF();
- rectangleF = rectangleFList[selected];
- if (rectangleF.Contains(movePoint))
- this.documentWorkspace.panel.Cursor = Cursors.SizeAll;
- rectangleF.X += dx;
- rectangleF.Y += dy;
- rectangleFList[selected] = rectangleF;
- for (int i = 0; i < pointList1[selected].Count(); i++)
- {
- if (pointList1[selected][i] == PointF.Empty)
- continue;
- pointList1[selected][i].X += dx;
- pointList1[selected][i].Y += dy;
- }
- }
- else if (movePointIndex == 0)
- {
- pointList1[selected][0].X += dx;
- pointList1[selected][0].Y += dy;
- rectangleFList[selected] = CalcOtherRectangle(pointList1[selected][0], pointList1[selected][1]);
- }
- else if (movePointIndex == 1)
- {
- pointList1[selected][1].X += dx;
- pointList1[selected][1].Y += dy;
- rectangleFList[selected] = CalcOtherRectangle(pointList1[selected][0], pointList1[selected][1]);
- }
- }
- this.documentWorkspace.Refresh();
- }
- else
- {
- if (isLunKuo)
- {
- int cou = pointList.Count;
- if (cou > 0)
- { // 换算后的点
- PointF movePoint = this.documentWorkspace.GetScalePoint(e.Location);
- pointList[cou - 1] = movePoint;
- }
- }
- if (isAddKong)
- {
- if (kongPointList.Count > 0)
- { // 换算后的点
- PointF movePoint = this.documentWorkspace.GetScalePoint(e.Location);
- kongPointList[kongPointList.Count - 1] = movePoint;
- }
- }
- if (isDelKong)
- {
- //if (delPointList.Count > 0)
- //{ // 换算后的点
- // PointF movePoint = this.documentWorkspace.GetScalePoint(e.Location);
- // delPointList[delPointList.Count - 1] = movePoint;
- //}
- }
- if (isDrwKuo)
- {
- int cou = pointList.Count;
- if (cou > 0)
- { // 换算后的点
- PointF movePoint = this.documentWorkspace.GetScalePoint(e.Location);
- pointList[cou - 1] = movePoint;
- }
- }
- if (DrwCircle)
- {
- tempCirclePoint = this.documentWorkspace.GetScalePoint(e.Location);
- }
- }
-
- this.documentWorkspace.Refresh();
- // }
- }
- /// <summary>
- /// 鼠标抬起
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OnMouseUp(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- if (operationK == 0)
- {
- if (startPoint != null && endPoint != null && startPoint != endPoint)
- {
- RectangleF rectangleF = CalcOtherRectangle(pointList1[lineCount][0], pointList1[lineCount][1]);
- rectangleFList.Add(rectangleF);
- lineCount++;
- // AddContentToDataGridView();
- }
- else
- {
- if (pointList1.Count > 0)
- {
- pointList1.RemoveAt(pointList1.Count - 1);
- this.documentWorkspace.Refresh();
- return;
- }
- }
- lastPoint.X = endPoint.X;
- lastPoint.Y = endPoint.Y;
- tempPoint.X = endPoint.X;
- tempPoint.Y = endPoint.Y;
- for (int i = rectangleFList.Count - 1; i >= 0; i--)
- {
- if (rectangleFList[i].Contains(endPoint))
- {
- selected = i;
- canMove = true;
- }
- }
- if (selected > -1 && pointList1 != null && pointList1.Count > 0)
- {
- int tempLess = (int)(InvariantData.rectless * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1)) * 5;
- int tempPlus = (int)(InvariantData.rectplus * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1)) * 5;
- if (new RectangleF(pointList1[selected][0].X - tempLess, pointList1[selected][0].Y - tempLess, tempPlus, tempPlus).Contains(endPoint))
- movePointIndex = 0;
- else if (new RectangleF(pointList1[selected][1].X - tempLess, pointList1[selected][1].Y - tempLess, tempPlus, tempPlus).Contains(endPoint))
- movePointIndex = 1;
- else
- movePointIndex = -1;
- this.documentWorkspace.Refresh();
- }
- operationK = 1;
- if (canMove)
- return;
-
- selected = -1;
- //this.documentWorkspace.Refresh();
- }
- else if (operationK == 1)
- {
- canMove = false;
- movePointIndex = -1;
- // RefreshDataGridView1();
- }
- else if (isAddKong && kongLineList.Count > 0)
- {
- //if (kongLineList[kongLineList.Count - 1].Count > 3)
- //{
- // isAddKong = false;
- // List<List<int>> CircleDate = binaryClass.DeleteCrystal(delPointList, kongLineList);
- // bindGrid(CircleDate);
- //}
- //else
- //{
- // kongLineList.RemoveAt(kongLineList.Count - 1);
- //}
- }
-
- }
- if (operationK >= 0 && e.Button == MouseButtons.Left)
- {
- PointF downPoint = this.documentWorkspace.GetScalePoint(e.Location);
- if (operationK == 0)
- {
- //startPoint = endPoint = downPoint;
- pointList1[lineCount - 1][1] = downPoint;
- }
- else if (operationK == 1)
- {
- lastPoint.X = downPoint.X;
- lastPoint.Y = downPoint.Y;
- tempPoint.X = downPoint.X;
- tempPoint.Y = downPoint.Y;
- for (int i = rectangleFList.Count - 1; i >= 0; i--)
- {
- if (rectangleFList[i].Contains(downPoint))
- {
- selected = i;
- canMove = true;
- }
- }
- if (selected > -1 && pointList1 != null && pointList1.Count > 0)
- {
- int tempLess = (int)(InvariantData.rectless * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1)) * 5;
- int tempPlus = (int)(InvariantData.rectplus * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1)) * 5;
- if (new RectangleF(pointList1[selected][0].X - tempLess, pointList1[selected][0].Y - tempLess, tempPlus, tempPlus).Contains(downPoint))
- movePointIndex = 0;
- else if (new RectangleF(pointList1[selected][1].X - tempLess, pointList1[selected][1].Y - tempLess, tempPlus, tempPlus).Contains(downPoint))
- movePointIndex = 1;
- else
- movePointIndex = -1;
- this.documentWorkspace.Refresh();
- }
- if (canMove)
- return;
- selected = -1;
- }
- }
- }
- /// <summary>
- /// 鼠标按下
- /// </summary>
- /// <param name="drawArea"></param>
- /// <param name="e"></param>
- private void OnMouseDown(object sender, MouseEventArgs e)
- {
- PointF downPoint = this.documentWorkspace.GetScalePoint(e.Location);
- if (operationK >= 0 && e.Button == MouseButtons.Left)
- {
- if (operationK == 0)
- {
- startPoint = endPoint = downPoint;
- nowLine = new PointF[4];
- nowLine[0] = startPoint;
- nowLine[1] = endPoint;
- pointList1.Add(nowLine);
- }
- else if (operationK == 1)
- {
- lastPoint.X = downPoint.X;
- lastPoint.Y = downPoint.Y;
- tempPoint.X = downPoint.X;
- tempPoint.Y = downPoint.Y;
- for (int i = rectangleFList.Count - 1; i >= 0; i--)
- {
- if (rectangleFList[i].Contains(downPoint))
- {
- selected = i;
- canMove = true;
- }
- }
- if (selected > -1 && pointList1 != null && pointList1.Count > 0)
- {
- int tempLess = (int)(InvariantData.rectless * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1)) * 5;
- int tempPlus = (int)(InvariantData.rectplus * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1)) * 5;
- if (new RectangleF(pointList1[selected][0].X - tempLess, pointList1[selected][0].Y - tempLess, tempPlus, tempPlus).Contains(downPoint))
- movePointIndex = 0;
- else if (new RectangleF(pointList1[selected][1].X - tempLess, pointList1[selected][1].Y - tempLess, tempPlus, tempPlus).Contains(downPoint))
- movePointIndex = 1;
- else
- movePointIndex = -1;
- this.documentWorkspace.Refresh();
- }
- if (canMove)
- return;
- selected = -1;
- }
- }
- else if (e.Button == MouseButtons.Left)
- {
- if (isLunKuo)
- {
- if (pointList.Count == 0)
- {
- pointList.Add(downPoint);
- pointList.Add(downPoint);
- }
- else
- {
- pointList.Add(downPoint);
- }
- }
- else if (isAddKong)
- {
- if (kongPointList.Count == 0)
- {
- kongPointList.Add(downPoint);
- kongPointList.Add(downPoint);
- }
- else
- {
- kongPointList.Add(downPoint);
- }
- }
- else if (isDelKong)
- {
- //if (delPointList.Count == 0)
- //{
- // delPointList.Add(downPoint);
- // delPointList.Add(downPoint);
- //}
- //else
- //{
- // delPointList.Add(downPoint);
- //}
- delPointList.Add(downPoint);
- List<List<int>> CircleDate = new List<List<int>>();
- if (DrwDone)
- {
- CircleDate = binaryClass.DrwLunKuoNew(lineList, kongLineList, delPointList);
- }
- else
- {
- binaryClass.DrwLunKuo(lineList, kongLineList, delPointList);
- }
- bindGrid(CircleDate);
- }
- else if (isDrwKuo)
- {
- if (pointList.Count == 0)
- {
- pointList.Add(downPoint);
- pointList.Add(downPoint);
- }
- else
- {
- pointList.Add(downPoint);
- }
- }
- else if (DrwCenter)
- {
- binaryClass.SetCenter = new OpenCvSharp.Point() { X =Convert.ToInt32( downPoint.X), Y = Convert.ToInt32(downPoint.Y) };
- binaryClass.R = Convert.ToInt32(numericMax.Value);
- if (!rb_RightCircle.Checked)
- {
- List<List<int>> CircleDate = binaryClass.getCircleDate(0);
- bindGrid(CircleDate);
- DrwCenter = false;
- }
- else
- {
- List<List<int>> CircleDate = binaryClass.getCircleDate(Convert.ToInt32(txt_RightLineWeight.Text));
- bindGrid(CircleDate);
- DrwCenter = false;
- }
- }
- else if (DrwCircle)
- {
- //binaryClass.SetCenter = new OpenCvSharp.Point() { X = Convert.ToInt32(downPoint.X), Y = Convert.ToInt32(downPoint.Y) };
- //binaryClass.R = Convert.ToInt32(numericMax.Value);
- //if (rb_RightCircle.Checked)
- //{
- // List<List<int>> CircleDate = binaryClass.getCircleDate(Convert.ToInt32(txt_RightLineWeight.Text));
- // bindGrid(CircleDate);
- // DrwCircle = false;
- //}
- float x = Math.Abs(downPoint.X - binaryClass.SetCenter.X);
- float y = Math.Abs(downPoint.Y - binaryClass.SetCenter.Y);
- int radius = (int)Math.Sqrt(x * x + y * y);
- ListRadius.Add(radius);
- ListRadiusColor.Add(radius, colorList[ListRadius.Count-1]);
- DrwCircle = false;
- if (ListRadiusColor.Count > 1)
- {
- List<List<int>> CircleDate = binaryClass.getCircleDate(ListRadiusColor);
- bindGrid(CircleDate);
- }
-
- }
- }
- if (e.Button == MouseButtons.Right)
- {
-
- if (isLunKuo)
- {
- if (pointList.Count > 2)
- {
- pointList.RemoveAt(pointList.Count - 1);
- List<PointF> pointFs = new List<PointF>(pointList.ToArray());
- lineList.Add(pointFs);
- }
- pointList.Clear();
- Recalculation();
- lineList.Clear();
- }
- if (isAddKong)
- {
- if (kongPointList.Count > 2)
- {
- kongPointList.RemoveAt(kongPointList.Count - 1);
- List<PointF> pointFs = new List<PointF>(kongPointList.ToArray());
- kongLineList.Add(pointFs);
- }
- kongPointList.Clear();
- }
- if (isDelKong)
- {
- //if (delPointList.Count > 2)
- //{
- // delPointList.RemoveAt(delPointList.Count - 1);
- // List<PointF> pointFs = new List<PointF>(delPointList.ToArray());
- // delLineList.Add(pointFs);
- //}
- //delPointList.Clear();
- }
- if (isDrwKuo)
- {
- if (pointList.Count > 2)
- {
- pointList.RemoveAt(pointList.Count - 1);
- List<PointF> pointFs = new List<PointF>(pointList.ToArray());
- lineList.Add(pointFs);
- }
- pointList.Clear();
- Recalculation();
- }
- isLunKuo = false;
- isAddKong = false;
- isDelKong = false;
- isDrwKuo = false;
- }
- }
- /// <summary>
- /// Ctrl+z
- /// </summary>
- private void OnKeyDown(object sender, KeyEventArgs e)
- {
- if (e.Control && e.KeyCode == Keys.Z)
- {
- if (isLunKuo)
- {
- int cou = pointList.Count;
- if (cou > 1)
- {
- if (cou == 2)
- {
- pointList.Clear();
- }
- else
- {
- pointList.RemoveAt(cou - 1);
- }
- }
- else if (lineList.Count > 0)
- {
- pointList = lineList[lineList.Count - 1];
- lineList.RemoveAt(lineList.Count - 1);
- pointList.RemoveAt(pointList.Count - 1);
- }
-
- }
- if (isAddKong)
- {
- int cou =kongPointList.Count;
- if (cou > 1)
- {
- if (cou == 2)
- {
- kongPointList.Clear();
- }
- else
- {
- kongPointList.RemoveAt(cou - 1);
- }
- }
- else if (kongLineList.Count > 0)
- {
- kongPointList = kongLineList[kongLineList.Count - 1];
- kongLineList.RemoveAt(kongLineList.Count - 1);
- kongPointList.RemoveAt(kongPointList.Count - 1);
- }
- }
- if (isDelKong)
- {
- int cou = delPointList.Count;
- if (cou > 0)
- {
- delPointList.RemoveAt(cou - 1);
- }
- List<List<int>> CircleDate = new List<List<int>>();
- if (DrwDone)
- {
- CircleDate = binaryClass.DrwLunKuoNew(lineList, kongLineList, delPointList);
- }
- else
- {
- binaryClass.DrwLunKuo(lineList, kongLineList, delPointList);
- }
- bindGrid(CircleDate);
- //if (cou > 1)
- //{
- // if (cou == 2)
- // {
- // delPointList.Clear();
- // }
- // else
- // {
- // delPointList.RemoveAt(cou - 1);
- // }
- //}
- //else if (delLineList.Count > 0)
- //{
- // delPointList = delLineList[delLineList.Count - 1];
- // delLineList.RemoveAt(delLineList.Count - 1);
- // delPointList.RemoveAt(delPointList.Count - 1);
- //}
- }
- this.documentWorkspace.Refresh();
- }
- else if ( e.KeyCode == Keys.Delete)
- {
- if (selected > -1)
- {
- DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretodmeasurementline.text") + "?", PdnResources.GetString("Menu.alert.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
- if (dr == DialogResult.OK)
- {
- this.pointList1.Remove(this.pointList1[selected]);
- this.rectangleFList.Remove(this.rectangleFList[selected]);
- selected = -1;
- lineCount--;
- this.documentWorkspace.Refresh();
- }
- }
- }
- }
- #endregion
- #region 辅助测量
- /// <summary>
- /// 添加测量线
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnAddCeliang_Click(object sender, EventArgs e)
- {
- operationK = 0;
- selected = -1;
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 选择测量线
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSelCeliang_Click(object sender, EventArgs e)
- {
- operationK = 1;
- }
- /// <summary>
- /// 删除测量线
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnDelCeliang_Click(object sender, EventArgs e)
- {
- if (selected > -1)
- {
- DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretodmeasurementline.text") + "?", PdnResources.GetString("Menu.alert.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
- if (dr == DialogResult.OK)
- {
- this.pointList1.Remove(this.pointList1[selected]);
- this.rectangleFList.Remove(this.rectangleFList[selected]);
- selected = -1;
- lineCount--;
- this.documentWorkspace.Refresh();
- }
- }
- else
- MessageBox.Show("请先选择测量线");
- }
-
- #endregion
- /// <summary>
- /// 导出孔隙信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button14_Click(object sender, EventArgs e)
- {
-
- SaveFileDialog exe = new SaveFileDialog();
- exe.Filter = "Execl files (*.xlsx)|*.xlsx";
- exe.FilterIndex = 0;
- exe.RestoreDirectory = true;
- //exe.CreatePrompt = true;
- exe.Title = "Export Excel File";
- exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
- exe.FileName = DateTime.Now.ToString("yyyyMMddhhmmss") +"孔隙信息";
- DialogResult dr = exe.ShowDialog();
- if (dr != DialogResult.OK)
- {
- return;
- }
- DataTable dtb = new DataTable();
- foreach (DataGridViewColumn c in this.dataGridView4.Columns)
- {
- dtb.Columns.Add(c.HeaderText);
- }
- for (int r = 0; r < this.dataGridView4.Rows.Count; r++)
- {
- DataRow dataRow = dtb.NewRow();
- for (int c = 0; c < this.dataGridView4.Rows[r].Cells.Count; c++)
- {
- dataRow[this.dataGridView4.Columns[c].HeaderText] = (string)this.dataGridView4.Rows[r].Cells[c].Value.ToString();
- }
- dtb.Rows.Add(dataRow);
- //this.dataGridView4.Rows[r].Cells[1].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
- }
- List<DataTable> list = new List<DataTable>();
- list.Add(dtb);
-
- this.appWorkspace.ExportDataToExcelWithProgress(list, exe.FileName, true, false, true);
-
- }
- /// <summary>
- /// 不可点击空白区域
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void listView1_MouseUp(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- if (listView1.SelectedItems.Count > 0)
- {
- }
- else if (listView1.SelectedItems.Count <= 0)//点击空白区
- {
- if (this.listView1.FocusedItem != null)
- {
- ListViewItem item = this.listView1.GetItemAt(e.X, e.Y);
- if (item == null)
- {
- this.listView1.FocusedItem.Selected = true;
- }
- }
- }
- }
- }
-
-
- /// <summary>
- /// 生成孔隙率
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button13_Click(object sender, EventArgs e)
- {
- //string path = string.Empty;
- //System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
- //fbd.Description = "请选择文件夹";
- //String str = System.Configuration.ConfigurationManager.AppSettings["FolderSelectedPath"];
- //if (!string.IsNullOrEmpty(str))
- //{
- // fbd.SelectedPath = str;
- //}
- //if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- //{
- // path = fbd.SelectedPath;
- // PrintReport(path);
- // Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
- // cfa.AppSettings.Settings["FolderSelectedPath"].Value = path;
- // cfa.Save();
- // System.Configuration.ConfigurationManager.RefreshSection("appSettings");
- //}
- string name = this.listView1.FocusedItem.Name.Split('.')[0] + "-";
- SaveFileDialog exe = new SaveFileDialog();
- exe.Filter = "Execl files (*.xlsx)|*.xlsx";
- exe.FilterIndex = 0;
- exe.RestoreDirectory = true;
- //exe.CreatePrompt = true;
- exe.Title = "Export Excel File";
- // exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
- exe.FileName = name;
- //String str = System.Configuration.ConfigurationManager.AppSettings["FolderSelectedPath"];
- DialogResult dr = exe.ShowDialog();
- if (dr != DialogResult.OK)
- {
- return;
- }
- DataTable dtb = new DataTable();
- foreach (DataGridViewColumn c in this.dataGridView1.Columns)
- {
- dtb.Columns.Add(c.HeaderText);
- }
- for (int r = 0; r < this.dataGridView1.Rows.Count; r++)
- {
- DataRow dataRow = dtb.NewRow();
- for (int c = 0; c < this.dataGridView1.Rows[r].Cells.Count; c++)
- {
- dataRow[this.dataGridView1.Columns[c].HeaderText] = (string)this.dataGridView1.Rows[r].Cells[c].Value.ToString();
- }
- dtb.Rows.Add(dataRow);
- //this.dataGridView4.Rows[r].Cells[1].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
- }
- int index = exe.FileName.LastIndexOf('\\');
- List<DataTable> list = new List<DataTable>();
- list.Add(dtb);
- DataTable dtb1 = new DataTable();
- for (int r = 0; r < this.dataGridView4.Columns.Count-1; r++)
- {
- DataGridViewColumn c = dataGridView4.Columns[r];
- dtb1.Columns.Add(c.HeaderText);
- }
- for (int r = 0; r < this.dataGridView4.Rows.Count-1; r++)
- {
- DataRow dataRow = dtb1.NewRow();
- for (int c = 0; c < this.dataGridView4.Rows[r].Cells.Count-1; c++)
- {
- dataRow[this.dataGridView4.Columns[c].HeaderText] = (string)this.dataGridView4.Rows[r].Cells[c].Value.ToString();
- }
- dtb1.Rows.Add(dataRow);
- //this.dataGridView4.Rows[r].Cells[1].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
- }
- list.Add(dtb1);
- //保存处理后的图片
- double pantographRatio = (double)this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetRulerMultiple(MeasurementUnit.Micron);//标尺*放大倍数
- List<Bitmap> tempBit = new List<Bitmap>();
- Bitmap originalBit = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
- originalBit.Tag = pantographRatio;
- tempBit.Add(originalBit);
- Bitmap processedBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
- Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
- Graphics graphics = Graphics.FromImage(newBit);
- graphics.DrawImage(processedBit, new PointF(0, 0));
- Draw(graphics);
- newBit.Tag = pantographRatio;
- tempBit.Add(newBit);
- string GR_Path = exe.FileName.Remove(index) + "\\" + name + ".jpg";
- newBit.Save(GR_Path);
- List<string> pics = new List<string>() { GR_Path + ",10,150," + newBit.Width / 2 + "," + newBit.Height / 2 };
- this.appWorkspace.ExportDataToExcelWithProgress(list, exe.FileName, true, false, true, null, null, pics);
- }
- /// <summary>
- /// 导出报告
- /// </summary>
- private void PrintReport(string savePath)
- {
-
- List<List<string>> analysisContent = new List<List<string>>();
- for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
- {
- List<string> content1 = new List<string>();
- if (i == 0)
- {
- content1.Add(this.dataGridView1.Columns[0].HeaderText);
- content1.Add(this.dataGridView1.Columns[1].HeaderText);
- content1.Add(this.dataGridView1.Columns[2].HeaderText);
-
- analysisContent.Add(content1);
- }
- content1 = new List<string>();
- content1.Add(this.dataGridView1.Rows[i].Cells[0].Value.ToString());
- content1.Add(this.dataGridView1.Rows[i].Cells[1].Value.ToString());
- content1.Add(this.dataGridView1.Rows[i].Cells[2].Value.ToString());
-
- analysisContent.Add(content1);
- }
- List<string> content2 = new List<string>();
- analysisContent.Add(content2);
- for (int i = 0; i < this.dataGridView4.Rows.Count; i++)
- {
- List<string> content1 = new List<string>();
- if (i == 0)
- {
- content1.Add(this.dataGridView4.Columns[0].HeaderText);
- content1.Add(this.dataGridView4.Columns[1].HeaderText);
- content1.Add(this.dataGridView4.Columns[2].HeaderText);
- content1.Add(this.dataGridView4.Columns[3].HeaderText);
- content1.Add(this.dataGridView4.Columns[4].HeaderText);
- content1.Add(this.dataGridView4.Columns[5].HeaderText);
- content1.Add(this.dataGridView4.Columns[6].HeaderText);
-
- analysisContent.Add(content1);
- }
- content1 = new List<string>();
- content1.Add(this.dataGridView4.Rows[i].Cells[0].Value.ToString());
- content1.Add(this.dataGridView4.Rows[i].Cells[1].Value.ToString());
- content1.Add(this.dataGridView4.Rows[i].Cells[2].Value.ToString());
- content1.Add(this.dataGridView4.Rows[i].Cells[3].Value.ToString());
- content1.Add(this.dataGridView4.Rows[i].Cells[4].Value.ToString());
- content1.Add(this.dataGridView4.Rows[i].Cells[5].Value.ToString());
- content1.Add(this.dataGridView4.Rows[i].Cells[6].Value.ToString());
-
- analysisContent.Add(content1);
- }
- //保存处理后的图片
- double pantographRatio = (double)this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetRulerMultiple(MeasurementUnit.Micron);//标尺*放大倍数
- List<Bitmap> tempBit = new List<Bitmap>();
- Bitmap originalBit = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
- originalBit.Tag = pantographRatio;
- tempBit.Add(originalBit);
- Bitmap processedBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
- Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
- Graphics graphics = Graphics.FromImage(newBit);
- graphics.DrawImage(processedBit, new PointF(0, 0));
- Draw(graphics);
- newBit.Tag = pantographRatio;
- tempBit.Add(newBit);
-
- List<Bitmap> bitList = new List<Bitmap>();
- bitList.Add(tempBit[0]);
- bitList.Add(tempBit[1]);
- Dictionary<string, string> tagInfos = new Dictionary<string, string>();
- // this.analyzeSettingModel.analyzeClassify
- AnalyzeSettingModel model = new AnalyzeSettingModel();
- string filePath = Application.StartupPath + "\\ModuleManage\\Dedicated\\MicrostructureBand_ASTME1268\\截面孔隙.docx";//获取文档路径
- string filePath2 = "E:\\图形处理\\Metisvision20210204\\RBDC\\Metisvision\\bin\\Debug\\ModuleManage\\Dedicated\\MicrostructureBand_ASTME1268\\截面孔隙.docx";
-
- model.modulePath = filePath;
- model.savePath = savePath;
- //model.itemNumber = this.textBox2.Text;
- //model.ratingDate = this.dateTimePicker1.Value;
- //model.inspectionPerson = this.textBox4.Text;
- model.contact = "";
- //model.inspectionDepartment = this.textBox5.Text;
- //model.inspectionDate = this.dateTimePicker2.Value;
- string name = this.listView1.FocusedItem.Name.Split('.')[0];
- model.analyzeClassify = name;
- this.analyzeSettingModel = new AnalyzeSettingModel();
- //this.analyzeSettingModel.modelItems = new List<AnalyzeSavedModel.ModelItem>();
- //this.analyzeSettingModel = new AnalyzeSavedModel.ModelItem();
- //this.analyzeSettingModel.languageName = this.languageName;
- this.analyzeSettingModel = model;
- //this.analyzeSettingModel.modelItems.Add(analyzeModel);
- this.appWorkspace.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, bitList, tagInfos);
-
- }
- /// 导出图片
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnImageOut_Click(object sender, EventArgs e)
- {
- SaveFileDialog exe = new SaveFileDialog();
- exe.Filter = "Image Files (*.jpg)|*.jpg";
- exe.FilterIndex = 0;
- exe.RestoreDirectory = true;
- //exe.CreatePrompt = true;
- exe.Title = "Image Files";
- exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
- exe.FileName = DateTime.Now.ToString("yyyyMMddhhmmss") + "孔隙率";
- DialogResult dr = exe.ShowDialog();
- if (dr != DialogResult.OK)
- {
- return;
- }
- Mat mat = binaryClass.MargMat();
- if (Cv2.ImWrite(exe.FileName, mat))
- {
- MessageBox.Show("保存成功!");
- }
- //List<DataTable> list = new List<DataTable>();
- //list.Add(dtb);
- //this.appWorkspace.ExportDataToExcelWithProgress(list, exe.FileName, true, false, true);
- }
-
- /// <summary>
- /// 准备用来处理单个颗粒的选中事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dataGridView4_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- //当点击表头部的列时,e.RowIndex==-1
- if (e.RowIndex > -1)
- {
- int index= Convert.ToInt32(dataGridView4.Rows[e.RowIndex].Cells[6].Value);
- int x = Convert.ToInt32(dataGridView4.Rows[e.RowIndex].Cells[0].Value);
- int y = Convert.ToInt32(dataGridView4.Rows[e.RowIndex].Cells[1].Value);
- PointF select = new PointF() { X = x, Y = y };
- binaryClass.DrwLunKuoSel(index);
- // binaryClass.DrwLunKuoLie1Selected(select);
- this.documentWorkspace.Refresh();
- }
- }
- #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<PhaseModel> phaseModels;
- //public AnalysisResult analysisResult;
- public DocumentItem(Bitmap bitmap, GraphicsList graphicsList, List<PhaseModel> phaseModels)
- {
- this.bitmap = bitmap;
- this.graphicsList = graphicsList;
- this.phaseModels = phaseModels;
- }
- }
- #endregion
- #endregion
- }
- }
|