Skip to content

Commit

Permalink
Added some extra error-checking and handline in FormFieldISOXML.cs as…
Browse files Browse the repository at this point in the history
… some new Fendt ISOXMLs weren't parsing correctly.
  • Loading branch information
lansalot committed Feb 8, 2025
1 parent 6246288 commit e587244
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions SourceCode/GPS/Forms/Field/FormFieldISOXML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private void FormFieldISOXML_Load(object sender, EventArgs e)
//First kind of Gudance GGP\GPN\LSG\PNT
foreach (XmlNode nodePart in fieldParts)
{
if (nodePart.Name == "GGP")
if (nodePart.Name == "GGP" && nodePart.ChildNodes[0].Attributes.GetNamedItem("B") != null && nodePart.ChildNodes[0].Attributes.GetNamedItem("C") != null)
{
//in GPN "B" is the name and "C" is the type
if (nodePart.ChildNodes[0].Attributes["C"].Value == "1")
Expand All @@ -139,12 +139,13 @@ private void FormFieldISOXML_Load(object sender, EventArgs e)
foreach (XmlNode nodePart in fieldParts)
{
//LSG with a "5" in [A] means Guidance line [B] is the name of line
if (nodePart.Name == "LSG" && nodePart.Attributes["A"].Value == "5")
if (nodePart.Name == "LSG" && nodePart.ChildNodes[0].Attributes.GetNamedItem("A") != null && nodePart.Attributes["A"].Value == "5")
{
if (nodePart.ChildNodes.Count < 3)
tree.Nodes[tree.Nodes.Count - 1].Nodes.Add("ABLine: " + nodePart.Attributes["B"].Value);
else
tree.Nodes[tree.Nodes.Count - 1].Nodes.Add("Curve: " + nodePart.Attributes["B"].Value);
if (nodePart.ChildNodes[0].Attributes.GetNamedItem("B") != null)
if (nodePart.ChildNodes.Count < 3)
tree.Nodes[tree.Nodes.Count - 1].Nodes.Add("ABLine: " + nodePart.Attributes["B"].Value);
else
tree.Nodes[tree.Nodes.Count - 1].Nodes.Add("Curve: " + nodePart.Attributes["B"].Value);
}
}
}
Expand Down Expand Up @@ -538,7 +539,10 @@ private void btnBuildFields_Click(object sender, EventArgs e)
if (nodePart.ChildNodes[0].ChildNodes[0].Attributes["A"].Value == "5") //Guidance Pattern
{
//get the name
if (nodePart.ChildNodes[0].Attributes.GetNamedItem("B") != null)
mf.ABLine.desName = nodePart.ChildNodes[0].Attributes["B"].Value;
else if(nodePart.ChildNodes[0].Attributes.GetNamedItem("A") != null)
mf.ABLine.desName = nodePart.Attributes["B"].Value; // fallback, if ChildNodes[0].Attributes["B"] is null

double.TryParse(nodePart.ChildNodes[0].ChildNodes[0].ChildNodes[0].Attributes["C"].Value, NumberStyles.Float, CultureInfo.InvariantCulture, out latK);
double.TryParse(nodePart.ChildNodes[0].ChildNodes[0].ChildNodes[0].Attributes["D"].Value, NumberStyles.Float, CultureInfo.InvariantCulture, out lonK);
Expand Down Expand Up @@ -587,7 +591,10 @@ private void btnBuildFields_Click(object sender, EventArgs e)
if (nodePart.ChildNodes[0].ChildNodes[0].Attributes["A"].Value == "5") //Guidance Pattern
{
//get the name
mf.curve.desName = nodePart.ChildNodes[0].Attributes["B"].Value;
if (nodePart.ChildNodes[0].Attributes.GetNamedItem("B") != null)
mf.curve.desName = nodePart.ChildNodes[0].Attributes["B"].Value;
else if (nodePart.ChildNodes[0].Attributes.GetNamedItem("A") != null)
mf.curve.desName = nodePart.Attributes["B"].Value; // fallback, if ChildNodes[0].Attributes["B"] is null

double.TryParse(nodePart.ChildNodes[0].ChildNodes[0].ChildNodes[0].Attributes["C"].Value, NumberStyles.Float, CultureInfo.InvariantCulture, out latK);
double.TryParse(nodePart.ChildNodes[0].ChildNodes[0].ChildNodes[0].Attributes["D"].Value, NumberStyles.Float, CultureInfo.InvariantCulture, out lonK);
Expand Down

0 comments on commit e587244

Please sign in to comment.