Skip to content

Commit

Permalink
Attempt to fix #33
Browse files Browse the repository at this point in the history
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
  • Loading branch information
robincornelius committed Dec 4, 2016
1 parent 764267c commit ee64f26
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 26 deletions.
54 changes: 37 additions & 17 deletions EDSTest/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 72 additions & 6 deletions EDSTest/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public partial class ODEditor_MainForm : Form
private List<string> _mru = new List<string>();
private string appdatafolder;

private string networkfilename;

public static Dictionary<UInt16, EDSsharp> TXCobMap = new Dictionary<UInt16, EDSsharp>();
List<EDSsharp> network = new List<EDSsharp>();

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -394,6 +395,7 @@ private void enablesavemenus(bool enable)
saveNetworkXmlToolStripMenuItem.Enabled = enable;
documentationToolStripMenuItem.Enabled = enable;
networkPDOToolStripMenuItem.Enabled = enable;
saveExportAllToolStripMenuItem.Enabled = enable;

}

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -543,6 +548,8 @@ private void openNetworkfile(string file)

addtoMRU(file);
}

networkfilename = file;
}

private void networkPDOToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -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();
}





}
}
}
Expand Down
9 changes: 6 additions & 3 deletions libEDSsharp/eds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> section)
{
infoheader = "CAN OPEN FileInfo";
Expand Down Expand Up @@ -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<string, Dictionary<string, string>> eds;
public SortedDictionary<UInt16, ODentry> ods;
Expand Down Expand Up @@ -1159,7 +1162,7 @@ public void parseEDSentry(KeyValuePair<string, Dictionary<string, string>> kvp)
public void loadfile(string filename)
{

this.filename = filename;
edsfilename = filename;
//try
{
foreach (string linex in File.ReadLines(filename))
Expand Down Expand Up @@ -1190,7 +1193,7 @@ public void loadfile(string filename)

public void savefile(string filename)
{
this.filename = filename;
this.edsfilename = filename;

updatePDOcount();

Expand Down

0 comments on commit ee64f26

Please sign in to comment.