Torna al Thread

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Text.RegularExpressions; namespace _VirtualCnc { public partial class frmMain : Form { public frmMain() { InitializeComponent(); } List<PointF> PointList = new List<PointF>(); int pointIndex = 0; private void ApriProgramma_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); open.Filter = "File di Testo (*.txt)|*.txt|File Cnc(*.cnc)|*.cnc"; if (open.ShowDialog() == DialogResult.OK) { tbCode.Text = File.ReadAllText(open.FileName) + ""; // Aggiunta codice alla listbox sbp_file.Text = "" + open.FileName + ""; // barra di stato per recuperare il file. } tbCode.Enabled = false; }// ApriProgramma_Click private void Simula_Click(object sender, EventArgs e) { Elabora_.Enabled = true; List<PointF> pt = new List<PointF>(); Regex coord = new Regex(@"X(?<CoordX>\d+)Y(?<CoordY>\d+)"); MatchCollection mc = coord.Matches(tbCode.Text); foreach (Match m in mc) { int x = int.Parse(m.Groups["CoordX"].Value); int y = int.Parse(m.Groups["CoordY"].Value); PointF p = new PointF(x, y); pt.Add(p); } // Get Points From Line(s) float curDist = 0; float distance = 0; for (int i = 0; i < pt.Count - 1; i++) { PointF ptA = pt[i]; PointF ptB = pt[i + 1]; float deltaX = ptB.X - ptA.X; float deltaY = ptB.Y - ptA.Y; curDist = 0; distance = (float)Math.Sqrt(Math.Pow(deltaX, 2) + Math.Pow(deltaY, 2)); while (curDist < distance) { curDist++; float offsetX = (float)((double)curDist / (double)distance * (double)deltaX); float offsetY = (float)((double)curDist / (double)distance * (double)deltaY); PointList.Add(new PointF(ptA.X + offsetX, ptA.Y + offsetY)); } } } // Simula_Click private void FermaElaborazione_Click(object sender, EventArgs e) { this.box.Refresh(); pBelaboarazione.Value = 0; this.Elabora_.Enabled = false; pointIndex = 0; }// FermaElaborazione_Click private void MenuFileEsci_Click(object sender, EventArgs e) { this.Close(); }// MenuFileEsci_Click private void Edita__Click(object sender, EventArgs e) { tbCode.Enabled = true; } private void frmMain_Load(object sender, EventArgs e) { tbCode.Enabled = false; }// Edita__Click private void SalvaProgramma_Click(object sender, EventArgs e) { }// SalvaProgramma_Click private void MenuAbout_Click(object sender, EventArgs e) { AboutBox1 about = new AboutBox1(); about.Show(); }// MenuAbout_Click private void Elabora__Tick(object sender, EventArgs e) { if (pointIndex < PointList.Count - 1) { pointIndex++; this.Refresh(); } } // Elabora_Tick private void box_Paint(object sender, PaintEventArgs e) { for (int i = 0; i < pointIndex; i++) { e.Graphics.PageUnit = GraphicsUnit.Pixel; e.Graphics.DrawLine(Pens.Black, PointList[i].X, PointList[i].Y, PointList[i + 1].X, PointList[i + 1].Y); } } // Box Paint. } }
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5