using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
public partial class lash : Form
private void button1_Click(object sender, EventArgs e)
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
txtFile.Text = ofd.FileName;
private void button2_Click(object sender, EventArgs e)
if (!File.Exists(txtFile.Text))
MessageBox.Show("File does not exist.");
double xLash = double.Parse(txtX.Text) / 2;
double yLash = double.Parse(txtY.Text) / 2;
StreamReader fileLash = new StreamReader(txtFile.Text);
if (txtFile.Text.IndexOf("_export") > -1)
fileNew = new StreamWriter(txtFile.Text.Replace("_export", "_nolash"));
string strNew = Path.GetDirectoryName(txtFile.Text) +
Path.DirectorySeparatorChar +
Path.GetFileNameWithoutExtension(txtFile.Text) + "_nolash" +
Path.GetExtension(txtFile.Text);
fileNew = new StreamWriter(strNew);
while (!fileLash.EndOfStream)
string strLine = fileLash.ReadLine();
int intIndex = strLine.IndexOf(" ");
strCommand = strLine.Remove(strLine.IndexOf(" "));
switch (strCommand.ToUpper())
string strCountermeasure = string.Empty;
xPos = repairCommand(xPos, ref xDir, "X", xLash, ref strLine, ref strCountermeasure);
yPos = repairCommand(yPos, ref yDir, "Y", yLash, ref strLine, ref strCountermeasure);
if (strCountermeasure.Length > 0)
fileNew.WriteLine(strCountermeasure);
fileNew.WriteLine(strLine);
private double repairCommand(double currentPos, ref int currentDir, string axis, double lash, ref string command, ref string countermeasure)
int intCmd = command.IndexOf(axis);
int intCmdEnd = command.IndexOf(" ", intCmd);
intCmdEnd = command.IndexOf(";", intCmd);
int intComment = command.IndexOf(";", intCmd);
if (intComment > -1) intCmdEnd = Math.Min(intCmdEnd, intComment);
if (intCmdEnd == -1) intCmdEnd = command.Length;
string strPos = command.Substring(intCmd + 1, intCmdEnd - intCmd - 1);
double newPos = double.Parse(strPos);
if (comparePositions(currentPos, newPos, currentDir) == false)
currentDir = -currentDir;
double calc = currentPos + lash * currentDir;
if (countermeasure.Length == 0)
countermeasure += " " + axis + calc.ToString();
recalc = newPos + lash * currentDir;
command = command.Remove(intCmd) + axis + recalc.ToString() + command.Substring(intCmdEnd);
private bool comparePositions(double currentPos, double newPos, int currentDir)
else if (currentPos > newPos)
return (newDir == currentDir);