diff --git a/EDSEditorGUI/Form1.cs b/EDSEditorGUI/Form1.cs index 3a5f3278..63c45481 100644 --- a/EDSEditorGUI/Form1.cs +++ b/EDSEditorGUI/Form1.cs @@ -621,7 +621,7 @@ void dosave(DeviceView dv, string FileName, bool xddfileVersion_1_1, bool stripp break; case ".md": - DocumentationGen docgen = new DocumentationGen(); + DocumentationGenMarkup docgen = new DocumentationGenMarkup(); docgen.genmddoc(FileName, dv.eds, this.gitVersion); dv.eds.mdfilename = FileName; break; @@ -1028,9 +1028,10 @@ private void documentationToolStripMenuItem_Click(object sender, EventArgs e) this.UseWaitCursor = true; - DocumentationGen docgen = new DocumentationGen(); - docgen.genhtmldoc(temp, dv.eds); - docgen.genmddoc(temp2, dv.eds, this.gitVersion); + DocumentationGenHtml docgenHtml = new DocumentationGenHtml(); + docgenHtml.genhtmldoc(temp, dv.eds); + DocumentationGenMarkup docgenMarkup = new DocumentationGenMarkup(); + docgenMarkup.genmddoc(temp2, dv.eds, this.gitVersion); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("cmd", $"/c start {temp2}")); @@ -1092,7 +1093,7 @@ private void saveExportAllToolStripMenuItem_Click(object sender, EventArgs e) if (dv.eds.mdfilename != null && dv.eds.mdfilename != "") { - DocumentationGen docgen = new DocumentationGen(); + DocumentationGenMarkup docgen = new DocumentationGenMarkup(); docgen.genmddoc(dv.eds.mdfilename, dv.eds, this.gitVersion); cnt++; } diff --git a/libEDSsharp/DocumentationGenHtml.cs b/libEDSsharp/DocumentationGenHtml.cs new file mode 100644 index 00000000..a2717025 --- /dev/null +++ b/libEDSsharp/DocumentationGenHtml.cs @@ -0,0 +1,193 @@ +/* + This file is part of libEDSsharp. + + libEDSsharp is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + libEDSsharp is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with libEDSsharp. If not, see . + + Copyright(c) 2016 - 2019 Robin Cornelius + Copyright(c) 2020 Janez Paternoster +*/ + +using System; +using System.Collections.Generic; +using System.IO; + +namespace libEDSsharp +{ + /// + /// Documentation generator + /// + public class DocumentationGenHtml + { + StreamWriter file = null; + + /// + /// Generate html documentation + /// + /// where the documentation should be saved + /// data to generate the documentation from + public void genhtmldoc(string filepath, EDSsharp eds) + { + + file = new StreamWriter(filepath, false); + file.NewLine = "\n"; + + file.Write(""); + + file.Write(string.Format("

{0} Documentation

",eds.di.ProductName)); + + file.Write("

Device Information

"); + + file.Write(""); + write2linetableheader("Product name", eds.di.ProductName); + write2linetableheader("Product number", eds.di.ProductNumber); + write2linetableheader("Revision number", eds.di.RevisionNumber); + write2linetableheader("Vendor name", eds.di.VendorName); + file.Write("
"); + + file.Write("

Mandatory objects

"); + + foreach (KeyValuePair kvp in eds.ods) + { + ODentry od = kvp.Value; + if (od.prop.CO_disabled == true) + continue; + + if (od.Index == 0x1000 || od.Index == 0x1001 || od.Index == 0x1018) + { + writeODentryhtml(od); + } + } + + file.Write("

Optional objects

"); + + foreach (KeyValuePair kvp in eds.ods) + { + ODentry od = kvp.Value; + if (od.prop.CO_disabled == true) + continue; + + if ((od.Index > 0x1001 && od.Index != 0x1018 && od.Index<0x2000) || od.Index>=0x6000) + { + writeODentryhtml(od); + } + } + + file.Write("

Manufacturer specific objects

"); + + foreach (KeyValuePair kvp in eds.ods) + { + ODentry od = kvp.Value; + if (od.prop.CO_disabled == true) + continue; + + if (od.Index >= 0x2000 && od.Index<0x6000) + { + writeODentryhtml(od); + } + } + + + file.Write(""); + + file.Close(); + + + } + /// + /// Write a object dictionary html entry to file + /// + /// Object dictionary entry + void writeODentryhtml(ODentry od) + { + if (od.parent == null) + { + file.Write("
"); + file.Write(String.Format("

0x{0:x4} - {1}

", od.Index, od.parameter_name)); + } + else + { + file.Write(String.Format("

0x{0:x4} sub 0x{2:x2} - {1}

", od.Index, od.parameter_name,od.Subindex)); + } + + file.Write(""); + write2linetableheader("Parameter", "Value"); + + ObjectType ot = od.objecttype; + if (ot == ObjectType.UNKNOWN && od.parent != null) + ot = od.parent.objecttype; + + write2linetablerow("Object Type", ot.ToString()); + + DataType dt = od.datatype; + if (dt == DataType.UNKNOWN && od.parent != null) + dt = od.parent.datatype; + + write2linetablerow("Data Type", dt.ToString()); + write2linetablerow("Default Value", od.defaultvalue); + + write2linetablerow("Location", od.prop.CO_storageGroup); + write2linetablerow("Access type", od.accesstype.ToString()); + write2linetablerow("PDO mapping", od.PDOMapping); + write2linetablerow("No Sub index", od.Nosubindexes); + + file.Write("
"); + + string description = od.Description; + file.Write(string.Format("
{0}
", description)); + + foreach (KeyValuePair sub in od.subobjects) + { + ODentry subod = sub.Value; + writeODentryhtml(subod); + } + + } + /// + /// Write a html table row with 2 elements to file + /// + /// element a + /// element b + void write2linetablerow(string a,object b) + { + if (b == null) + b = ""; + file.Write("{0}{1}", a, b.ToString()); + } + /// + /// Write a html table header with 2 elements to file + /// + /// + /// + void write2linetableheader(string a, object b) + { + file.Write("{0}{1}",a,b.ToString()); + } + /// + /// Returns the datatype of a object dictionary + /// + /// the object dictionary entry + /// datatype of the OD entry + string PrintDataType(ODentry od) + { + string dt = od.datatype.ToString(); + if ((od.datatype == DataType.VISIBLE_STRING || od.datatype == DataType.UNICODE_STRING) + && od.prop.CO_stringLengthMin > od.defaultvalue.Length) + { + dt += $" (len={od.prop.CO_stringLengthMin})"; + } + + return dt; + } + } +} diff --git a/libEDSsharp/DocumentationGen.cs b/libEDSsharp/DocumentationGenMarkup.cs similarity index 71% rename from libEDSsharp/DocumentationGen.cs rename to libEDSsharp/DocumentationGenMarkup.cs index b5aef6a1..798dbf39 100644 --- a/libEDSsharp/DocumentationGen.cs +++ b/libEDSsharp/DocumentationGenMarkup.cs @@ -27,152 +27,10 @@ namespace libEDSsharp /// /// Documentation generator /// - public class DocumentationGen + public class DocumentationGenMarkup { StreamWriter file = null; - /// - /// Generate html documentation - /// - /// where the documentation should be saved - /// data to generate the documentation from - public void genhtmldoc(string filepath, EDSsharp eds) - { - - file = new StreamWriter(filepath, false); - file.NewLine = "\n"; - - file.Write(""); - - file.Write(string.Format("

{0} Documentation

",eds.di.ProductName)); - - file.Write("

Device Information

"); - - file.Write(""); - write2linetableheader("Product name", eds.di.ProductName); - write2linetableheader("Product number", eds.di.ProductNumber); - write2linetableheader("Revision number", eds.di.RevisionNumber); - write2linetableheader("Vendor name", eds.di.VendorName); - file.Write("
"); - - file.Write("

Mandatory objects

"); - - foreach (KeyValuePair kvp in eds.ods) - { - ODentry od = kvp.Value; - if (od.prop.CO_disabled == true) - continue; - - if (od.Index == 0x1000 || od.Index == 0x1001 || od.Index == 0x1018) - { - writeODentryhtml(od); - } - } - - file.Write("

Optional objects

"); - - foreach (KeyValuePair kvp in eds.ods) - { - ODentry od = kvp.Value; - if (od.prop.CO_disabled == true) - continue; - - if ((od.Index > 0x1001 && od.Index != 0x1018 && od.Index<0x2000) || od.Index>=0x6000) - { - writeODentryhtml(od); - } - } - - file.Write("

Manufacturer specific objects

"); - - foreach (KeyValuePair kvp in eds.ods) - { - ODentry od = kvp.Value; - if (od.prop.CO_disabled == true) - continue; - - if (od.Index >= 0x2000 && od.Index<0x6000) - { - writeODentryhtml(od); - } - } - - - file.Write(""); - - file.Close(); - - - } - /// - /// Write a object dictionary html entry to file - /// - /// Object dictionary entry - void writeODentryhtml(ODentry od) - { - if (od.parent == null) - { - file.Write("
"); - file.Write(String.Format("

0x{0:x4} - {1}

", od.Index, od.parameter_name)); - } - else - { - file.Write(String.Format("

0x{0:x4} sub 0x{2:x2} - {1}

", od.Index, od.parameter_name,od.Subindex)); - } - - file.Write(""); - write2linetableheader("Parameter", "Value"); - - ObjectType ot = od.objecttype; - if (ot == ObjectType.UNKNOWN && od.parent != null) - ot = od.parent.objecttype; - - write2linetablerow("Object Type", ot.ToString()); - - DataType dt = od.datatype; - if (dt == DataType.UNKNOWN && od.parent != null) - dt = od.parent.datatype; - - write2linetablerow("Data Type", dt.ToString()); - write2linetablerow("Default Value", od.defaultvalue); - - write2linetablerow("Location", od.prop.CO_storageGroup); - write2linetablerow("Access type", od.accesstype.ToString()); - write2linetablerow("PDO mapping", od.PDOMapping); - write2linetablerow("No Sub index", od.Nosubindexes); - - file.Write("
"); - - string description = od.Description; - file.Write(string.Format("
{0}
", description)); - - foreach (KeyValuePair sub in od.subobjects) - { - ODentry subod = sub.Value; - writeODentryhtml(subod); - } - - } - /// - /// Write a html table row with 2 elements to file - /// - /// element a - /// element b - void write2linetablerow(string a,object b) - { - if (b == null) - b = ""; - file.Write("{0}{1}", a, b.ToString()); - } - /// - /// Write a html table header with 2 elements to file - /// - /// - /// - void write2linetableheader(string a, object b) - { - file.Write("{0}{1}",a,b.ToString()); - } /// /// Generate markup documentation ///