From ee64f26ad20b2065b7cc6abb4dfabe6ceef7a858 Mon Sep 17 00:00:00 2001 From: Robin Cornelius Date: Sun, 4 Dec 2016 17:16:21 +0000 Subject: [PATCH] Attempt to fix #33 Please ensure you backup your xml/eds files before running this the first few times Add save eds+xml+export option that will do all three operations to a single Device Move the filenames for xml and eds into separate variables to aid exporting and also be more user friendly when exporting by hand Also save the network filename/path so that is not dependent on the last save --- EDSTest/Form1.Designer.cs | 54 ++++++++++++++++++--------- EDSTest/Form1.cs | 78 ++++++++++++++++++++++++++++++++++++--- libEDSsharp/eds.cs | 9 +++-- 3 files changed, 115 insertions(+), 26 deletions(-) diff --git a/EDSTest/Form1.Designer.cs b/EDSTest/Form1.Designer.cs index e949b4b4..bf5024b7 100644 --- a/EDSTest/Form1.Designer.cs +++ b/EDSTest/Form1.Designer.cs @@ -53,6 +53,8 @@ private void InitializeComponent() this.documentationToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.networkPDOToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.tabControl1 = new System.Windows.Forms.TabControl(); + this.saveExportAllToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator7 = new System.Windows.Forms.ToolStripSeparator(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); // @@ -83,8 +85,10 @@ private void InitializeComponent() this.toolStripSeparator6, this.mnuRecentlyUsed, this.toolStripSeparator1, + this.saveExportAllToolStripMenuItem, this.exportCanOpenNodeToolStripMenuItem, this.toolStripSeparator2, + this.toolStripSeparator7, this.closeFileToolStripMenuItem, this.toolStripSeparator4, this.quitToolStripMenuItem}); @@ -96,7 +100,7 @@ private void InitializeComponent() // this.newToolStripMenuItem.Image = global::ODEditor.Properties.Resources.NewFile_6276; this.newToolStripMenuItem.Name = "newToolStripMenuItem"; - this.newToolStripMenuItem.Size = new System.Drawing.Size(210, 22); + this.newToolStripMenuItem.Size = new System.Drawing.Size(233, 22); this.newToolStripMenuItem.Text = "New"; this.newToolStripMenuItem.Click += new System.EventHandler(this.newToolStripMenuItem_Click); // @@ -104,7 +108,7 @@ private void InitializeComponent() // this.openEDSToolStripMenuItem.Image = global::ODEditor.Properties.Resources.Open_6529; this.openEDSToolStripMenuItem.Name = "openEDSToolStripMenuItem"; - this.openEDSToolStripMenuItem.Size = new System.Drawing.Size(210, 22); + this.openEDSToolStripMenuItem.Size = new System.Drawing.Size(233, 22); this.openEDSToolStripMenuItem.Text = "Open EDS"; this.openEDSToolStripMenuItem.Click += new System.EventHandler(this.openEDSToolStripMenuItem_Click); // @@ -113,20 +117,20 @@ private void InitializeComponent() this.saveEDSToolStripMenuItem.Enabled = false; this.saveEDSToolStripMenuItem.Image = global::ODEditor.Properties.Resources.Save_6530; this.saveEDSToolStripMenuItem.Name = "saveEDSToolStripMenuItem"; - this.saveEDSToolStripMenuItem.Size = new System.Drawing.Size(210, 22); + this.saveEDSToolStripMenuItem.Size = new System.Drawing.Size(233, 22); this.saveEDSToolStripMenuItem.Text = "Save EDS"; this.saveEDSToolStripMenuItem.Click += new System.EventHandler(this.saveEDSToolStripMenuItem_Click); // // toolStripSeparator3 // this.toolStripSeparator3.Name = "toolStripSeparator3"; - this.toolStripSeparator3.Size = new System.Drawing.Size(207, 6); + this.toolStripSeparator3.Size = new System.Drawing.Size(230, 6); // // openCanOpenNodeXMLToolStripMenuItem // this.openCanOpenNodeXMLToolStripMenuItem.Image = global::ODEditor.Properties.Resources.Open_6529; this.openCanOpenNodeXMLToolStripMenuItem.Name = "openCanOpenNodeXMLToolStripMenuItem"; - this.openCanOpenNodeXMLToolStripMenuItem.Size = new System.Drawing.Size(210, 22); + this.openCanOpenNodeXMLToolStripMenuItem.Size = new System.Drawing.Size(233, 22); this.openCanOpenNodeXMLToolStripMenuItem.Text = "Open Device XML"; this.openCanOpenNodeXMLToolStripMenuItem.Click += new System.EventHandler(this.openCanOpenNodeXMLToolStripMenuItem_Click); // @@ -135,20 +139,20 @@ private void InitializeComponent() this.saveProjectXMLToolStripMenuItem.Enabled = false; this.saveProjectXMLToolStripMenuItem.Image = global::ODEditor.Properties.Resources.Save_6530; this.saveProjectXMLToolStripMenuItem.Name = "saveProjectXMLToolStripMenuItem"; - this.saveProjectXMLToolStripMenuItem.Size = new System.Drawing.Size(210, 22); + this.saveProjectXMLToolStripMenuItem.Size = new System.Drawing.Size(233, 22); this.saveProjectXMLToolStripMenuItem.Text = "Save Device XML"; this.saveProjectXMLToolStripMenuItem.Click += new System.EventHandler(this.saveProjectXMLToolStripMenuItem_Click); // // toolStripSeparator5 // this.toolStripSeparator5.Name = "toolStripSeparator5"; - this.toolStripSeparator5.Size = new System.Drawing.Size(207, 6); + this.toolStripSeparator5.Size = new System.Drawing.Size(230, 6); // // loadNetworkXmlToolStripMenuItem // this.loadNetworkXmlToolStripMenuItem.Image = global::ODEditor.Properties.Resources.Open_6529; this.loadNetworkXmlToolStripMenuItem.Name = "loadNetworkXmlToolStripMenuItem"; - this.loadNetworkXmlToolStripMenuItem.Size = new System.Drawing.Size(210, 22); + this.loadNetworkXmlToolStripMenuItem.Size = new System.Drawing.Size(233, 22); this.loadNetworkXmlToolStripMenuItem.Text = "Open Network XML"; this.loadNetworkXmlToolStripMenuItem.Click += new System.EventHandler(this.loadNetworkXmlToolStripMenuItem_Click); // @@ -157,59 +161,59 @@ private void InitializeComponent() this.saveNetworkXmlToolStripMenuItem.Enabled = false; this.saveNetworkXmlToolStripMenuItem.Image = global::ODEditor.Properties.Resources.Save_6530; this.saveNetworkXmlToolStripMenuItem.Name = "saveNetworkXmlToolStripMenuItem"; - this.saveNetworkXmlToolStripMenuItem.Size = new System.Drawing.Size(210, 22); + this.saveNetworkXmlToolStripMenuItem.Size = new System.Drawing.Size(233, 22); this.saveNetworkXmlToolStripMenuItem.Text = "Save Network XML"; this.saveNetworkXmlToolStripMenuItem.Click += new System.EventHandler(this.saveNetworkXmlToolStripMenuItem_Click); // // toolStripSeparator6 // this.toolStripSeparator6.Name = "toolStripSeparator6"; - this.toolStripSeparator6.Size = new System.Drawing.Size(207, 6); + this.toolStripSeparator6.Size = new System.Drawing.Size(230, 6); // // mnuRecentlyUsed // this.mnuRecentlyUsed.Name = "mnuRecentlyUsed"; - this.mnuRecentlyUsed.Size = new System.Drawing.Size(210, 22); + this.mnuRecentlyUsed.Size = new System.Drawing.Size(233, 22); this.mnuRecentlyUsed.Text = "Recent Files"; // // toolStripSeparator1 // this.toolStripSeparator1.Name = "toolStripSeparator1"; - this.toolStripSeparator1.Size = new System.Drawing.Size(207, 6); + this.toolStripSeparator1.Size = new System.Drawing.Size(230, 6); // // exportCanOpenNodeToolStripMenuItem // this.exportCanOpenNodeToolStripMenuItem.Enabled = false; this.exportCanOpenNodeToolStripMenuItem.Image = global::ODEditor.Properties.Resources.Compile_191; this.exportCanOpenNodeToolStripMenuItem.Name = "exportCanOpenNodeToolStripMenuItem"; - this.exportCanOpenNodeToolStripMenuItem.Size = new System.Drawing.Size(210, 22); + this.exportCanOpenNodeToolStripMenuItem.Size = new System.Drawing.Size(233, 22); this.exportCanOpenNodeToolStripMenuItem.Text = "Export CanOpenNode c/h"; this.exportCanOpenNodeToolStripMenuItem.Click += new System.EventHandler(this.exportCanOpenNodeToolStripMenuItem_Click); // // toolStripSeparator2 // this.toolStripSeparator2.Name = "toolStripSeparator2"; - this.toolStripSeparator2.Size = new System.Drawing.Size(207, 6); + this.toolStripSeparator2.Size = new System.Drawing.Size(230, 6); // // closeFileToolStripMenuItem // this.closeFileToolStripMenuItem.Enabled = false; this.closeFileToolStripMenuItem.Image = global::ODEditor.Properties.Resources.Close_6519; this.closeFileToolStripMenuItem.Name = "closeFileToolStripMenuItem"; - this.closeFileToolStripMenuItem.Size = new System.Drawing.Size(210, 22); + this.closeFileToolStripMenuItem.Size = new System.Drawing.Size(233, 22); this.closeFileToolStripMenuItem.Text = "Close file"; this.closeFileToolStripMenuItem.Click += new System.EventHandler(this.closeFileToolStripMenuItem_Click); // // toolStripSeparator4 // this.toolStripSeparator4.Name = "toolStripSeparator4"; - this.toolStripSeparator4.Size = new System.Drawing.Size(207, 6); + this.toolStripSeparator4.Size = new System.Drawing.Size(230, 6); // // quitToolStripMenuItem // this.quitToolStripMenuItem.Image = global::ODEditor.Properties.Resources._305_Close_16x16_72; this.quitToolStripMenuItem.Name = "quitToolStripMenuItem"; - this.quitToolStripMenuItem.Size = new System.Drawing.Size(210, 22); + this.quitToolStripMenuItem.Size = new System.Drawing.Size(233, 22); this.quitToolStripMenuItem.Text = "Quit"; this.quitToolStripMenuItem.Click += new System.EventHandler(this.quitToolStripMenuItem_Click); // @@ -263,6 +267,20 @@ private void InitializeComponent() this.tabControl1.ControlAdded += new System.Windows.Forms.ControlEventHandler(this.tabControl1_ControlsChanged); this.tabControl1.ControlRemoved += new System.Windows.Forms.ControlEventHandler(this.tabControl1_Controlsremoved); // + // saveExportAllToolStripMenuItem + // + this.saveExportAllToolStripMenuItem.Enabled = false; + this.saveExportAllToolStripMenuItem.Image = global::ODEditor.Properties.Resources.Save_6530; + this.saveExportAllToolStripMenuItem.Name = "saveExportAllToolStripMenuItem"; + this.saveExportAllToolStripMenuItem.Size = new System.Drawing.Size(233, 22); + this.saveExportAllToolStripMenuItem.Text = "Save eds + xml+ Export device"; + this.saveExportAllToolStripMenuItem.Click += new System.EventHandler(this.saveExportAllToolStripMenuItem_Click); + // + // toolStripSeparator7 + // + this.toolStripSeparator7.Name = "toolStripSeparator7"; + this.toolStripSeparator7.Size = new System.Drawing.Size(230, 6); + // // ODEditor_MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -308,6 +326,8 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem reportsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem documentationToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem networkPDOToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem saveExportAllToolStripMenuItem; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator7; } } diff --git a/EDSTest/Form1.cs b/EDSTest/Form1.cs index d865534e..a916dd84 100644 --- a/EDSTest/Form1.cs +++ b/EDSTest/Form1.cs @@ -41,6 +41,8 @@ public partial class ODEditor_MainForm : Form private List _mru = new List(); private string appdatafolder; + private string networkfilename; + public static Dictionary TXCobMap = new Dictionary(); List network = new List(); @@ -165,7 +167,6 @@ private void exportCanOpenNodeToolStripMenuItem_Click(object sender, EventArgs e SaveFileDialog sfd = new SaveFileDialog(); sfd.CheckFileExists = false; - sfd.FileName = "CO_OD.c"; sfd.InitialDirectory = dv.eds.fi.exportFolder; sfd.RestoreDirectory = true; @@ -222,7 +223,7 @@ private void openXMLfile(string path) Bridge b = new Bridge(); eds = b.convert(coxml.dev); - eds.filename = path; + eds.xmlfilename = path; dev = coxml.dev; @@ -315,9 +316,9 @@ private void saveEDSToolStripMenuItem_Click(object sender, EventArgs e) sfd.Filter = "Electronic Data Sheets (*.eds)|*.eds"; - sfd.InitialDirectory = Path.GetDirectoryName(dv.eds.filename); + sfd.InitialDirectory = Path.GetDirectoryName(dv.eds.edsfilename); sfd.RestoreDirectory = true; - sfd.FileName = Path.GetFileNameWithoutExtension(dv.eds.filename); + sfd.FileName = Path.GetFileNameWithoutExtension(dv.eds.edsfilename); if (sfd.ShowDialog() == DialogResult.OK) { @@ -336,9 +337,9 @@ private void saveProjectXMLToolStripMenuItem_Click(object sender, EventArgs e) sfd.Filter = "Canopen Node XML (*.xml)|*.xml"; - sfd.InitialDirectory = Path.GetDirectoryName(dv.eds.filename); + sfd.InitialDirectory = Path.GetDirectoryName(dv.eds.xmlfilename); sfd.RestoreDirectory = true; - sfd.FileName = Path.GetFileNameWithoutExtension(dv.eds.filename); + sfd.FileName = Path.GetFileNameWithoutExtension(dv.eds.xmlfilename); if (sfd.ShowDialog() == DialogResult.OK) { @@ -394,6 +395,7 @@ private void enablesavemenus(bool enable) saveNetworkXmlToolStripMenuItem.Enabled = enable; documentationToolStripMenuItem.Enabled = enable; networkPDOToolStripMenuItem.Enabled = enable; + saveExportAllToolStripMenuItem.Enabled = enable; } @@ -492,6 +494,9 @@ private void saveNetworkXmlToolStripMenuItem_Click(object sender, EventArgs e) sfd.Filter = "CanOpen network XML (*.nxml)|*.nxml"; + sfd.InitialDirectory = Path.GetDirectoryName(networkfilename); + sfd.RestoreDirectory = true; + sfd.FileName = Path.GetFileNameWithoutExtension(networkfilename); if (sfd.ShowDialog() == DialogResult.OK) { @@ -543,6 +548,8 @@ private void openNetworkfile(string file) addtoMRU(file); } + + networkfilename = file; } private void networkPDOToolStripMenuItem_Click(object sender, EventArgs e) @@ -590,6 +597,65 @@ private void documentationToolStripMenuItem_Click(object sender, EventArgs e) { WarningsFrm frm = new WarningsFrm(); frm.ShowDialog(); + } + } + + private void saveExportAllToolStripMenuItem_Click(object sender, EventArgs e) + { + //Attempt to save EDS,XML and export the CanOpen dictionary + + if (tabControl1.SelectedTab != null) + { + DeviceView dv = (DeviceView)tabControl1.SelectedTab.Controls[0]; + SaveFileDialog sfd = new SaveFileDialog(); + + //save eds xml and export CO_OD.c and CO_OD.h + + if (dv.eds.edsfilename == null || dv.eds.edsfilename == "") + { + MessageBox.Show("Please manually save as EDS at least once"); + return; + } + + if (dv.eds.xmlfilename == null || dv.eds.xmlfilename == "") + { + MessageBox.Show("Please manually save as XML at least once"); + return; + } + + if (dv.eds.fi.exportFolder == null || dv.eds.fi.exportFolder == "") + { + MessageBox.Show("Please expot CO_OD.c/h at least once"); + return; + } + + //export XML + Bridge b = new Bridge(); + Device d = b.convert(dv.eds); + + CanOpenXML coxml = new CanOpenXML(); + coxml.dev = d; + + coxml.writeXML(dv.eds.xmlfilename); + + + //export EDS + dv.eds.savefile(dv.eds.edsfilename); + + //export CO_OD.c and CO_OD.h + CanOpenNodeExporter cone = new CanOpenNodeExporter(); + cone.export(dv.eds.fi.exportFolder, dv.eds); + + if (Warnings.warning_list.Count != 0) + { + WarningsFrm frm = new WarningsFrm(); + frm.ShowDialog(); + } + + + + + } } } diff --git a/libEDSsharp/eds.cs b/libEDSsharp/eds.cs index 3d9d2613..02f76376 100644 --- a/libEDSsharp/eds.cs +++ b/libEDSsharp/eds.cs @@ -489,8 +489,10 @@ public class FileInfo : InfoSection [EdsExport] public string ModifiedBy="";//=CANFestival //max244 + //Folder CO_OD.c and CO_OD.h will be exported into public string exportFolder = ""; + public FileInfo(Dictionary section) { infoheader = "CAN OPEN FileInfo"; @@ -956,7 +958,8 @@ public enum AccessType //This is the last file name used for this eds/xml file and is not //the same as filename within the FileInfo structure. - public string filename; + public string edsfilename = null; + public string xmlfilename = null; Dictionary> eds; public SortedDictionary ods; @@ -1159,7 +1162,7 @@ public void parseEDSentry(KeyValuePair> kvp) public void loadfile(string filename) { - this.filename = filename; + edsfilename = filename; //try { foreach (string linex in File.ReadLines(filename)) @@ -1190,7 +1193,7 @@ public void loadfile(string filename) public void savefile(string filename) { - this.filename = filename; + this.edsfilename = filename; updatePDOcount();