Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using Euresys.Open_eVision_2_5;
- using System.Diagnostics;
- using OfficeOpenXml;
- using System.IO;
- using System.Reflection;
- namespace WindowsFormsApp1
- {
- public partial class Form2 : Form
- {
- PictureBox p;
- Euresys.Open_eVision_2_5.EWorldShape shape1;
- Euresys.Open_eVision_2_5.EImageBW8 srcImage;
- List<EShape> shapes;
- int length;
- List<EImageBW8> images;
- string modelPath;
- public Form2(string modelPath, List<EImageBW8> images)
- {
- InitializeComponent();
- this.modelPath = modelPath;
- this.images = images;
- /*groupBoxPoint.Controls.Add(NumMeasuredPoints);
- groupBoxPoint.Controls.Add(Tolerance);
- groupBoxPoint.Controls.Add(Angle);
- groupBoxLine.Controls.Add(LCenterX);
- groupBoxLine.Controls.Add(LCenterY);
- groupBoxLine.Controls.Add(LAngle);
- groupBoxCircle.Controls.Add(CenterX);
- groupBoxCircle.Controls.Add(CenterY);
- groupBoxCircle.Controls.Add(Diameter);
- groupBoxRectangle.Controls.Add(RCenterX);
- groupBoxRectangle.Controls.Add(RCenterY);
- groupBoxRectangle.Controls.Add(RAngle);
- groupBoxRectangle.Controls.Add(RSizeX);
- groupBoxRectangle.Controls.Add(RSizeY);
- groupBoxWedge.Controls.Add(WCenterX);
- groupBoxWedge.Controls.Add(WCenterY);
- groupBoxWedge.Controls.Add(WBreadth);
- groupBoxWedge.Controls.Add(WAngle);
- groupBoxWedge.Controls.Add(WAmplitude);*/
- /*p = new PictureBox();
- p.Location = new Point(102, 36);
- p.Size = new Size(250, 375);
- this.Controls.Add(p);
- p.Load();*/
- }
- //public PictureBox GetPictureBox { get => pictureBox1; }
- /* EImageBW8 Draw(List<EImageBW8> images)
- {
- foreach (EImageBW8 img in images)
- {
- Graphics graphics = Graphics.FromImage(img.);
- }
- return Drawresults(img);
- }*/
- void Draw(string ImageName, int imIdx, EShape eShape)
- {
- Bitmap b = new Bitmap(ImageName);
- //Bitmap b = new Bitmap("C:\\Users\\csiky.dora\\Desktop\\GyakornokiTeszt\\p.bmp");
- Graphics g = Graphics.FromImage(b);
- ECircleGauge c = new ECircleGauge();
- eShape.Draw(g);
- b.Save("C:\\Users\\csiky.dora\\Desktop\\miniteszt\\proba2" + imIdx + ".bmp");
- //b.s
- //g.DrawImage(b, ulCorner);
- }
- private void Save_Click(object sender, EventArgs e)
- {
- //try
- //{
- SaveFileDialog sfd = new SaveFileDialog(); // select the model file
- sfd.Filter = "Excel files|*.xls;*xlsx;*.xlsm";
- if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- FileInfo fi = new FileInfo(sfd.FileName);
- ProcessModel(images, fi);
- }
- //}
- /*catch (Exception en)
- {
- Console.WriteLine("Select );
- }*/
- }
- public void ProcessModel(List<EImageBW8> images, FileInfo outputFile)
- {
- EWorldShape shape = new EWorldShape();
- shape.Load(modelPath, true);
- //EImageEncoder e = new EImageEncoder();
- //ECodedImage2 cim = new ECodedImage2();
- //e.Encode(images[0], cim);
- //Image img = Image.FromHbitmap(images[0].GetImagePtr());
- int rowIdx = 2;
- int imIdx = 0;
- //Draw(images[imIdx].Title);
- using (ExcelPackage package = new ExcelPackage())
- {
- ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Results");
- foreach (var im in images)
- {
- shape.Process(im, true);
- List<EShape> ShapeList = DepthSearch(shape);
- //shape.lo
- Draw(images[imIdx].Title, imIdx + 1, ShapeList[0]);
- fillData(package, ShapeList, images[imIdx].Title, rowIdx);
- rowIdx++;
- imIdx++;
- }
- //package.Save();
- package.SaveAs(outputFile);
- }
- }
- private List<EShape> DepthSearch(EShape start)
- {
- var visited = new HashSet<EShape>();
- EShape act;
- var stack = new Stack<EShape>();
- stack.Push(start);
- List<EShape> shapeList = new List<EShape>();
- while (stack.Count > 0)
- {
- var vertex = stack.Pop();
- if (visited.Contains(vertex))
- continue;
- visited.Add(vertex);
- shapeList.Add(vertex);
- //Debug.WriteLine(vertex.Name);
- //search for not visited gauges
- for (uint i = 0; i < vertex.NumDaughters; i++)
- {
- act = vertex.GetDaughter(i);
- if (!visited.Contains(act))
- stack.Push(act);
- }
- }
- return shapeList;
- //int length = images.Count();
- //open Form2
- //Form2 Results = new Form2(shapeList, length, images);
- //Results.ShowDialog();
- }
- // private void fillData(List<string> propertyNames, FileInfo fileName, List<EShape> ShapeList)
- public void fillData(ExcelPackage package, List<EShape> ShapeList, string imName, int row)
- {
- // Add a new worksheet to the empty workbook
- ExcelWorksheet worksheet = package.Workbook.Worksheets["Results"];
- /* //Add the headers
- for (int i = 0; i < propertyNames.Count; i++)
- {
- worksheet.Cells[1, i + 1].Value = propertyNames[i];
- }*/
- //fill records
- // int actIdx = 2;
- //int p = 2;
- worksheet.Cells[row, 1].Value = imName;
- int cols = 1;
- GroupBox gb = new GroupBox();
- int o = 1;
- foreach (var pic in ShapeList)
- {
- PropertyInfo[] pi;// = typeof(EShape).GetProperties();
- List<PropertyInfo> prop = new List<PropertyInfo>();// = pi.ToList();
- Type actType = pic.GetType();
- if (pic is EPointGauge)
- {
- pi = typeof(EPointGauge).GetProperties();
- prop = pi.ToList();
- actType = typeof(EPointGauge);
- gb = groupBoxPoint;
- }
- else if (pic is ELineGauge)
- {
- pi = typeof(ELineGauge).GetProperties();
- prop = pi.ToList();
- actType = typeof(ELineGauge);
- gb = groupBoxLine;
- }
- else if (pic is ECircleGauge)
- {
- pi = typeof(ECircleGauge).GetProperties();
- prop = pi.ToList();
- actType = typeof(ECircleGauge);
- gb = groupBoxCircle;
- }
- else if (pic is ERectangleGauge)
- {
- pi = typeof(ERectangleGauge).GetProperties();
- prop = pi.ToList();
- actType = typeof(ERectangleGauge);
- gb = groupBoxRectangle;
- }
- else if (pic is EWedgeGauge)
- {
- pi = typeof(EWedgeGauge).GetProperties();
- prop = pi.ToList();
- actType = typeof(EWedgeGauge);
- gb = groupBoxWedge;
- }
- else continue;
- List<string> proplist = new List<string>();
- List<int> ixlist = new List<int>();
- var checkboxes = gb.Controls.OfType<CheckBox>();
- foreach (var cb in checkboxes)
- {
- if (cb.Checked == true)
- {
- proplist.Add(cb.Text);
- }
- }
- // var asd = this.Controls.OfType<GroupBox>();
- // properties of the current shape to a list
- for (int i = 0; i < prop.Count; i++)
- {
- if (prop[i].Name.StartsWith("Measured"))
- {
- cols++;
- var measuredObj = prop[i].GetValue(pic);
- var pi2 = measuredObj.GetType().GetProperties();
- for (int propIdx = 0; propIdx < pi2.Length; propIdx++)
- {
- if (row == 2)
- {
- if (proplist.Contains(pi2[propIdx].Name))
- {
- string name = pic.Name + "." + pi2[propIdx].Name;
- worksheet.Cells[1, cols].Value = name;
- ixlist.Add(propIdx);
- // if (pi2[propIdx].CanRead)
- // {
- }
- }
- // if (ixlist.Contains(propIdx))
- if (proplist.Contains(pi2[propIdx].Name))
- {
- var measuredVal = pi2[propIdx].GetValue(measuredObj);
- worksheet.Cells[row, cols].Value = measuredVal;
- cols++;
- }
- // }
- //worksheet.Cells[o, cols].Value =
- /* if (pi2[propIdx].CanRead)
- {
- var measuredVal = pi2[propIdx].GetValue(measuredObj);
- worksheet.Cells[row, cols].Value = measuredVal;
- }*/
- // PropertyInfo value = pi2[propIdx].GetValue();
- // worksheet.Cells[1, cols].Value = value;
- }
- // and if its checkbox is checked
- //PropertyInfo pi2 = actType.getpt
- // worksheet.Cells[2, j + 1].Value =
- }
- /* PropertyInfo pi = typeof(EShape).GetProperty(propertyNames[i]);
- object obj = pi.GetValue(pic);
- if (obj != null)
- {
- worksheet.Cells[actIdx, i + 1].Value = pi.GetValue(pic);
- }*/
- }
- // actIdx++;
- }
- //o += 2;
- //p += 3;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement