Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CultureInfo.InvariantCulture to all parse functions for float and... #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/CNCInfusion/CustomPanel/CustomPanel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;

using System;
using System.Globalization;

namespace Utility.Panel
{

Expand Down Expand Up @@ -349,8 +350,8 @@ public static void DrawBorder3D(System.Drawing.Graphics graphics, System.Drawing
}

public static int DoubleToInt(double value)
{
return System.Decimal.ToInt32(System.Decimal.Floor(System.Decimal.Parse((value).ToString())));
{
return System.Decimal.ToInt32(System.Decimal.Floor(System.Decimal.Parse((value).ToString(), CultureInfo.InvariantCulture)));
}
}
}
21 changes: 11 additions & 10 deletions src/CNCInfusion/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Drawing;
using System.Drawing;
using System.Globalization;
using System.Windows.Forms;
using System.Collections.Generic;

Expand Down Expand Up @@ -113,15 +114,15 @@ string convertUnits(string readvalue, string setting)

try {
if(setting.Contains("steps/mm")) {
double fval = double.Parse(readvalue)*(1.0/TOINCHES);
convert = fval.ToString();
double fval = double.Parse(readvalue, CultureInfo.InvariantCulture)*(1.0/TOINCHES);
convert = fval.ToString(CultureInfo.InvariantCulture);
}
else if(setting.Contains("mm")) {
double fval = double.Parse(readvalue)*TOINCHES;
convert = fval.ToString();
else if(setting.Contains("mm")) {
double fval = double.Parse(readvalue, CultureInfo.InvariantCulture) * TOINCHES;
convert = fval.ToString(CultureInfo.InvariantCulture);
}
else if(setting.Contains("binary")) {
int fval = int.Parse(readvalue);
else if(setting.Contains("binary")) {
int fval = int.Parse(readvalue, CultureInfo.InvariantCulture);
convert = GetIntBinaryString(fval);
}
else {
Expand Down Expand Up @@ -181,8 +182,8 @@ void DataGridView1CellValidating(object sender, DataGridViewCellValidatingEventA
// int.Parse(sVal);

// TODO error checking is weak
try {
enteredValue = float.Parse(e.FormattedValue.ToString());
try {
enteredValue = float.Parse(e.FormattedValue.ToString(), CultureInfo.InvariantCulture);
}
catch {
MessageBox.Show("The value must be a non-negative number. You entered '" +
Expand Down
71 changes: 36 additions & 35 deletions src/CNCInfusion/clsProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Text;
using MacGen;
Expand Down Expand Up @@ -440,7 +441,7 @@ private float FormatAxis(string sVal, int precision)
{
//decimal place
if (sVal.Contains(".")) {
return float.Parse(sVal);
return float.Parse(sVal, CultureInfo.InvariantCulture);
}
else {
return (float)(float.Parse(sVal) * (Math.Pow(10, - precision)));//convert a number from a 4 place
Expand All @@ -453,52 +454,52 @@ public void ProcessFile(string ncFile, List<clsMotionRecord> gfxRecs)
mGfxRecs = gfxRecs;
mCodefile = ncFile;
{
mMotion.SubCall.Label = mCurMachine.Subcall[0];
mMotion.SubCall.Value = int.Parse(mCurMachine.Subcall.Substring(1));
mMotion.SubCall.Label = mCurMachine.Subcall[0];
mMotion.SubCall.Value = int.Parse(mCurMachine.Subcall.Substring(1), CultureInfo.InvariantCulture);

mMotion.SubReturn.Label = mCurMachine.SubReturn[0];
mMotion.SubReturn.Value = int.Parse(mCurMachine.SubReturn.Substring(1));
mMotion.SubReturn.Label = mCurMachine.SubReturn[0];
mMotion.SubReturn.Value = int.Parse(mCurMachine.SubReturn.Substring(1), CultureInfo.InvariantCulture);

mMotion.Abs.Label = mCurMachine.Absolute[0];
mMotion.Abs.Value = int.Parse(mCurMachine.Absolute.Substring(1));
mMotion.CCArc.Label = mCurMachine.CCArc[0];
mMotion.CCArc.Value = int.Parse(mCurMachine.CCArc.Substring(1));
mMotion.CWArc.Label = mCurMachine.CWArc[0];
mMotion.CWArc.Value = int.Parse(mCurMachine.CWArc.Substring(1));
mMotion.Abs.Label = mCurMachine.Absolute[0];
mMotion.Abs.Value = int.Parse(mCurMachine.Absolute.Substring(1), CultureInfo.InvariantCulture);
mMotion.CCArc.Label = mCurMachine.CCArc[0];
mMotion.CCArc.Value = int.Parse(mCurMachine.CCArc.Substring(1), CultureInfo.InvariantCulture);
mMotion.CWArc.Label = mCurMachine.CWArc[0];
mMotion.CWArc.Value = int.Parse(mCurMachine.CWArc.Substring(1), CultureInfo.InvariantCulture);

mMotion.Inc.Label = mCurMachine.Incremental[0];
mMotion.Inc.Value = int.Parse(mCurMachine.Incremental.Substring(1));
mMotion.Inc.Label = mCurMachine.Incremental[0];
mMotion.Inc.Value = int.Parse(mCurMachine.Incremental.Substring(1), CultureInfo.InvariantCulture);

mMotion.Linear.Label = mCurMachine.Linear[0];
mMotion.Linear.Value = int.Parse(mCurMachine.Linear.Substring(1));
mMotion.Linear.Label = mCurMachine.Linear[0];
mMotion.Linear.Value = int.Parse(mCurMachine.Linear.Substring(1), CultureInfo.InvariantCulture);

mMotion.Rapid.Label = mCurMachine.Rapid[0];
mMotion.Rapid.Value = int.Parse(mCurMachine.Rapid.Substring(1));
mMotion.Rapid.Label = mCurMachine.Rapid[0];
mMotion.Rapid.Value = int.Parse(mCurMachine.Rapid.Substring(1), CultureInfo.InvariantCulture);

mMotion.Rotary.Label = mCurMachine.Rotary[0];
mMotion.Rotary.Value = 0;

mMotion.DrillRapid.Label = mCurMachine.DrillRapid[0];
mMotion.DrillRapid.Value = 0;

mMotion.Plane[0].Label = mCurMachine.XYplane[0];
mMotion.Plane[0].Value = int.Parse(mCurMachine.XYplane.Substring(1));
mMotion.Plane[1].Label = mCurMachine.XZplane[0];
mMotion.Plane[1].Value = int.Parse(mCurMachine.XZplane.Substring(1));
mMotion.Plane[2].Label = mCurMachine.YZplane[0];
mMotion.Plane[2].Value = int.Parse(mCurMachine.YZplane.Substring(1));
mMotion.Plane[0].Label = mCurMachine.XYplane[0];
mMotion.Plane[0].Value = int.Parse(mCurMachine.XYplane.Substring(1), CultureInfo.InvariantCulture);
mMotion.Plane[1].Label = mCurMachine.XZplane[0];
mMotion.Plane[1].Value = int.Parse(mCurMachine.XZplane.Substring(1), CultureInfo.InvariantCulture);
mMotion.Plane[2].Label = mCurMachine.YZplane[0];
mMotion.Plane[2].Value = int.Parse(mCurMachine.YZplane.Substring(1), CultureInfo.InvariantCulture);

mMotion.ReturnLevel[0].Label = mCurMachine.ReturnLevel[0][0];
mMotion.ReturnLevel[0].Value = int.Parse(mCurMachine.ReturnLevel[0].Substring(1));
mMotion.ReturnLevel[1].Label = mCurMachine.ReturnLevel[1][0];
mMotion.ReturnLevel[1].Value = int.Parse(mCurMachine.ReturnLevel[1].Substring(1));
mMotion.ReturnLevel[0].Label = mCurMachine.ReturnLevel[0][0];
mMotion.ReturnLevel[0].Value = int.Parse(mCurMachine.ReturnLevel[0].Substring(1), CultureInfo.InvariantCulture);
mMotion.ReturnLevel[1].Label = mCurMachine.ReturnLevel[1][0];
mMotion.ReturnLevel[1].Value = int.Parse(mCurMachine.ReturnLevel[1].Substring(1), CultureInfo.InvariantCulture);

for (int r = 0; r <= mMotion.Drills.Length - 1; r++)
{
if (mCurMachine.Drills[r].Length > 2)
{
mMotion.Drills[r].Label = mCurMachine.Drills[r][0];
mMotion.Drills[r].Value = int.Parse(mCurMachine.Drills[r].Substring(1));
mMotion.Drills[r].Label = mCurMachine.Drills[r][0];
mMotion.Drills[r].Value = int.Parse(mCurMachine.Drills[r].Substring(1), CultureInfo.InvariantCulture);
}
}
}
Expand Down Expand Up @@ -563,8 +564,8 @@ public void ProcessFile(string ncFile, List<clsMotionRecord> gfxRecs)
p = new clsProg();
p.Main = false;
p.Index = thisIndex;
p.Label = Char.ToUpper(m.Value[0]).ToString();
p.Value = int.Parse(m.Groups[1].Value);
p.Label = Char.ToUpper(m.Value[0]).ToString();
p.Value = int.Parse(m.Groups[1].Value, CultureInfo.InvariantCulture);
mNcProgs.Add(p);
lastIndex = m.Index;
}
Expand Down Expand Up @@ -643,11 +644,11 @@ private void ProcessSubWords(clsProg p)
//Word
mCurAddress.Label = Char.ToUpper(ncWord.Value[0]);
mCurAddress.StringValue = ncWord.Groups[1].Value;
mCurAddress.Value = float.Parse(ncWord.Groups[1].Value);
mCurAddress.Value = float.Parse(ncWord.Groups[1].Value, CultureInfo.InvariantCulture);
if (mCurAddress.Matches(mMotion.SubCall))
{
//M98 P. Use the next word value as the sub name
clsProg retProg = FindSubByValue(int.Parse(ncWord.NextMatch().Groups[1].Value));
//M98 P. Use the next word value as the sub name
clsProg retProg = FindSubByValue(int.Parse(ncWord.NextMatch().Groups[1].Value, CultureInfo.InvariantCulture));
if ((retProg != null))
{
if (retProg.TimesCalled > 100) return;//Prevent infinite loop
Expand Down
21 changes: 11 additions & 10 deletions src/CNCInfusion/clsSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Xml;
using MacGen;
Expand Down Expand Up @@ -101,7 +102,7 @@ public void LoadMachine(string sName)
xReader.MoveToContent();
xReader.ReadToDescendant("Name");
Machine.Name = xReader.ReadElementContentAsString();
Machine.Description = xReader.ReadElementContentAsString();
Machine.Description = xReader.ReadElementContentAsString();
Machine.AbsArcCenter = bool.Parse(xReader.ReadElementContentAsString());
Machine.LatheMinus = bool.Parse(xReader.ReadElementContentAsString());
Machine.HelixPitch = bool.Parse(xReader.ReadElementContentAsString());
Expand All @@ -110,18 +111,18 @@ public void LoadMachine(string sName)
Machine.Endmain = xReader.ReadElementContentAsString();
Machine.MachineType = (MachineType)Enum.Parse(typeof(MachineType), xReader.ReadElementContentAsString());
Machine.RotaryAxis = (Axis)Enum.Parse(typeof(Axis), xReader.ReadElementContentAsString());
Machine.RotaryDir = (RotaryDirection)Enum.Parse(typeof(RotaryDirection), xReader.ReadElementContentAsString());
Machine.Precision = int.Parse(xReader.ReadElementContentAsString());
Machine.RotaryDir = (RotaryDirection)Enum.Parse(typeof(RotaryDirection), xReader.ReadElementContentAsString());
Machine.Precision = int.Parse(xReader.ReadElementContentAsString(), CultureInfo.InvariantCulture);
Machine.ProgramId = xReader.ReadElementContentAsString();
Machine.SubReturn = xReader.ReadElementContentAsString();
Machine.RotPrecision = int.Parse(xReader.ReadElementContentAsString());
Machine.SubReturn = xReader.ReadElementContentAsString();
Machine.RotPrecision = int.Parse(xReader.ReadElementContentAsString(), CultureInfo.InvariantCulture);
Machine.RotaryType = (RotaryMotionType)Enum.Parse(typeof(RotaryMotionType), xReader.ReadElementContentAsString());
Machine.Searchstring = xReader.ReadElementContentAsString();
for (r = 0; r <= Machine.ViewAngles.Length - 1; r++) {
Machine.ViewAngles[r] = float.Parse(xReader.ReadElementContentAsString());
for (r = 0; r <= Machine.ViewAngles.Length - 1; r++) {
Machine.ViewAngles[r] = float.Parse(xReader.ReadElementContentAsString(), CultureInfo.InvariantCulture);
}
for (r = 0; r <= Machine.ViewShift.Length - 1; r++) {
Machine.ViewShift[r] = float.Parse(xReader.ReadElementContentAsString());
for (r = 0; r <= Machine.ViewShift.Length - 1; r++) {
Machine.ViewShift[r] = float.Parse(xReader.ReadElementContentAsString(), CultureInfo.InvariantCulture);
}
Machine.Absolute = xReader.ReadElementContentAsString();
Machine.Incremental = xReader.ReadElementContentAsString();
Expand Down
17 changes: 9 additions & 8 deletions src/CNCInfusion/frmViewer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;
using System.Windows.Forms;
using System.Diagnostics;
Expand Down Expand Up @@ -737,13 +738,13 @@ private void UpdatePositionLEDS(string str)

//Debug.WriteLine(str + "\r\n");

try {
mx = double.Parse(groups[1].Value.ToString());
my = double.Parse(groups[2].Value.ToString());
mz = double.Parse(groups[3].Value.ToString());
wx = double.Parse(groups[4].Value.ToString());
wy = double.Parse(groups[5].Value.ToString());
wz = double.Parse(groups[6].Value.ToString());
try {
mx = double.Parse(groups[1].Value, CultureInfo.InvariantCulture);
my = double.Parse(groups[2].Value, CultureInfo.InvariantCulture);
mz = double.Parse(groups[3].Value, CultureInfo.InvariantCulture);
wx = double.Parse(groups[4].Value, CultureInfo.InvariantCulture);
wy = double.Parse(groups[5].Value, CultureInfo.InvariantCulture);
wz = double.Parse(groups[6].Value, CultureInfo.InvariantCulture);

if(GrblReportsInches) {
mx = mx * TOINCHES;
Expand Down
9 changes: 6 additions & 3 deletions src/CNCInfusion/grblPreprocessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;
using System.Windows.Forms;
using System.Diagnostics;
Expand Down Expand Up @@ -51,8 +52,10 @@ private bool GrblPreprocess(string line)
MatchCollection matches = rgx.Matches(line);

if (matches.Count > 0) {
foreach (Match match in matches) {
arg = double.Parse(match.Value.Substring(1));
foreach (Match match in matches)
{
string valueStr = match.Value.Substring(1, match.Value.Length - 1);
arg = double.Parse(valueStr,CultureInfo.InvariantCulture);
switch(match.Value[0]) {
case 'G':
// explicitly supported G codes
Expand Down