diff --git a/EDSTest/Form1.Designer.cs b/EDSTest/Form1.Designer.cs index 0888c554..80db1dda 100644 --- a/EDSTest/Form1.Designer.cs +++ b/EDSTest/Form1.Designer.cs @@ -32,9 +32,10 @@ private void InitializeComponent() this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.newToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); this.openCanOpenNodeXMLToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveProjectXMLToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.exportDeviceFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator(); this.loadNetworkXmlToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveNetworkXmlToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -53,18 +54,21 @@ 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.saveAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); // // menuStrip1 // + this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.fileToolStripMenuItem, this.insertToolStripMenuItem, this.reportsToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(1199, 24); + this.menuStrip1.Padding = new System.Windows.Forms.Padding(8, 2, 0, 2); + this.menuStrip1.Size = new System.Drawing.Size(1599, 28); this.menuStrip1.TabIndex = 1; this.menuStrip1.Text = "menuStrip1"; // @@ -74,6 +78,8 @@ private void InitializeComponent() this.newToolStripMenuItem, this.openCanOpenNodeXMLToolStripMenuItem, this.saveProjectXMLToolStripMenuItem, + this.saveAsToolStripMenuItem, + this.exportDeviceFileToolStripMenuItem, this.toolStripSeparator3, this.toolStripSeparator5, this.loadNetworkXmlToolStripMenuItem, @@ -89,28 +95,23 @@ private void InitializeComponent() this.toolStripSeparator4, this.quitToolStripMenuItem}); this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; - this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20); + this.fileToolStripMenuItem.Size = new System.Drawing.Size(44, 24); this.fileToolStripMenuItem.Text = "File"; // // newToolStripMenuItem // this.newToolStripMenuItem.Image = global::ODEditor.Properties.Resources.NewFile_6276; this.newToolStripMenuItem.Name = "newToolStripMenuItem"; - this.newToolStripMenuItem.Size = new System.Drawing.Size(233, 22); - this.newToolStripMenuItem.Text = "New"; + this.newToolStripMenuItem.Size = new System.Drawing.Size(288, 26); + this.newToolStripMenuItem.Text = "&New"; this.newToolStripMenuItem.Click += new System.EventHandler(this.newToolStripMenuItem_Click); // - // toolStripSeparator3 - // - this.toolStripSeparator3.Name = "toolStripSeparator3"; - 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(233, 22); - this.openCanOpenNodeXMLToolStripMenuItem.Text = "Open Device File"; + this.openCanOpenNodeXMLToolStripMenuItem.Size = new System.Drawing.Size(288, 26); + this.openCanOpenNodeXMLToolStripMenuItem.Text = "&Open"; this.openCanOpenNodeXMLToolStripMenuItem.Click += new System.EventHandler(this.openCanOpenNodeXMLToolStripMenuItem_Click); // // saveProjectXMLToolStripMenuItem @@ -118,20 +119,33 @@ 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(233, 22); - this.saveProjectXMLToolStripMenuItem.Text = "Save Device File"; + this.saveProjectXMLToolStripMenuItem.Size = new System.Drawing.Size(288, 26); + this.saveProjectXMLToolStripMenuItem.Text = "&Save"; this.saveProjectXMLToolStripMenuItem.Click += new System.EventHandler(this.saveProjectXMLToolStripMenuItem_Click); // + // exportDeviceFileToolStripMenuItem + // + this.exportDeviceFileToolStripMenuItem.Enabled = false; + this.exportDeviceFileToolStripMenuItem.Name = "exportDeviceFileToolStripMenuItem"; + this.exportDeviceFileToolStripMenuItem.Size = new System.Drawing.Size(288, 26); + this.exportDeviceFileToolStripMenuItem.Text = "Export Device File"; + this.exportDeviceFileToolStripMenuItem.Click += new System.EventHandler(this.exportDeviceFileToolStripMenuItem_Click); + // + // toolStripSeparator3 + // + this.toolStripSeparator3.Name = "toolStripSeparator3"; + this.toolStripSeparator3.Size = new System.Drawing.Size(285, 6); + // // toolStripSeparator5 // this.toolStripSeparator5.Name = "toolStripSeparator5"; - this.toolStripSeparator5.Size = new System.Drawing.Size(230, 6); + this.toolStripSeparator5.Size = new System.Drawing.Size(285, 6); // // loadNetworkXmlToolStripMenuItem // this.loadNetworkXmlToolStripMenuItem.Image = global::ODEditor.Properties.Resources.Open_6529; this.loadNetworkXmlToolStripMenuItem.Name = "loadNetworkXmlToolStripMenuItem"; - this.loadNetworkXmlToolStripMenuItem.Size = new System.Drawing.Size(233, 22); + this.loadNetworkXmlToolStripMenuItem.Size = new System.Drawing.Size(288, 26); this.loadNetworkXmlToolStripMenuItem.Text = "Open Network XML"; this.loadNetworkXmlToolStripMenuItem.Click += new System.EventHandler(this.loadNetworkXmlToolStripMenuItem_Click); // @@ -140,32 +154,32 @@ 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(233, 22); + this.saveNetworkXmlToolStripMenuItem.Size = new System.Drawing.Size(288, 26); 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(230, 6); + this.toolStripSeparator6.Size = new System.Drawing.Size(285, 6); // // mnuRecentlyUsed // this.mnuRecentlyUsed.Name = "mnuRecentlyUsed"; - this.mnuRecentlyUsed.Size = new System.Drawing.Size(233, 22); + this.mnuRecentlyUsed.Size = new System.Drawing.Size(288, 26); this.mnuRecentlyUsed.Text = "Recent Files"; // // toolStripSeparator1 // this.toolStripSeparator1.Name = "toolStripSeparator1"; - this.toolStripSeparator1.Size = new System.Drawing.Size(230, 6); + this.toolStripSeparator1.Size = new System.Drawing.Size(285, 6); // // 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.Size = new System.Drawing.Size(288, 26); this.saveExportAllToolStripMenuItem.Text = "Save eds + xml+ Export device"; this.saveExportAllToolStripMenuItem.Click += new System.EventHandler(this.saveExportAllToolStripMenuItem_Click); // @@ -174,46 +188,46 @@ private void InitializeComponent() this.exportCanOpenNodeToolStripMenuItem.Enabled = false; this.exportCanOpenNodeToolStripMenuItem.Image = global::ODEditor.Properties.Resources.Compile_191; this.exportCanOpenNodeToolStripMenuItem.Name = "exportCanOpenNodeToolStripMenuItem"; - this.exportCanOpenNodeToolStripMenuItem.Size = new System.Drawing.Size(233, 22); + this.exportCanOpenNodeToolStripMenuItem.Size = new System.Drawing.Size(288, 26); 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(230, 6); + this.toolStripSeparator2.Size = new System.Drawing.Size(285, 6); // // toolStripSeparator7 // this.toolStripSeparator7.Name = "toolStripSeparator7"; - this.toolStripSeparator7.Size = new System.Drawing.Size(230, 6); + this.toolStripSeparator7.Size = new System.Drawing.Size(285, 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(233, 22); + this.closeFileToolStripMenuItem.Size = new System.Drawing.Size(288, 26); 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(230, 6); + this.toolStripSeparator4.Size = new System.Drawing.Size(285, 6); // // quitToolStripMenuItem // this.quitToolStripMenuItem.Image = global::ODEditor.Properties.Resources._305_Close_16x16_72; this.quitToolStripMenuItem.Name = "quitToolStripMenuItem"; - this.quitToolStripMenuItem.Size = new System.Drawing.Size(233, 22); + this.quitToolStripMenuItem.Size = new System.Drawing.Size(288, 26); this.quitToolStripMenuItem.Text = "Quit"; this.quitToolStripMenuItem.Click += new System.EventHandler(this.quitToolStripMenuItem_Click); // // insertToolStripMenuItem // this.insertToolStripMenuItem.Name = "insertToolStripMenuItem"; - this.insertToolStripMenuItem.Size = new System.Drawing.Size(85, 20); + this.insertToolStripMenuItem.Size = new System.Drawing.Size(104, 24); this.insertToolStripMenuItem.Text = "Insert Profile"; // // reportsToolStripMenuItem @@ -222,7 +236,7 @@ private void InitializeComponent() this.documentationToolStripMenuItem, this.networkPDOToolStripMenuItem}); this.reportsToolStripMenuItem.Name = "reportsToolStripMenuItem"; - this.reportsToolStripMenuItem.Size = new System.Drawing.Size(59, 20); + this.reportsToolStripMenuItem.Size = new System.Drawing.Size(72, 24); this.reportsToolStripMenuItem.Text = "Reports"; // // documentationToolStripMenuItem @@ -230,7 +244,7 @@ private void InitializeComponent() this.documentationToolStripMenuItem.Enabled = false; this.documentationToolStripMenuItem.Image = global::ODEditor.Properties.Resources.ExporttoScript_9881; this.documentationToolStripMenuItem.Name = "documentationToolStripMenuItem"; - this.documentationToolStripMenuItem.Size = new System.Drawing.Size(157, 22); + this.documentationToolStripMenuItem.Size = new System.Drawing.Size(187, 26); this.documentationToolStripMenuItem.Text = "Documentation"; this.documentationToolStripMenuItem.Click += new System.EventHandler(this.documentationToolStripMenuItem_Click); // @@ -239,7 +253,7 @@ private void InitializeComponent() this.networkPDOToolStripMenuItem.Enabled = false; this.networkPDOToolStripMenuItem.Image = global::ODEditor.Properties.Resources.ExporttoScript_9881; this.networkPDOToolStripMenuItem.Name = "networkPDOToolStripMenuItem"; - this.networkPDOToolStripMenuItem.Size = new System.Drawing.Size(157, 22); + this.networkPDOToolStripMenuItem.Size = new System.Drawing.Size(187, 26); this.networkPDOToolStripMenuItem.Text = "Network PDO"; this.networkPDOToolStripMenuItem.Click += new System.EventHandler(this.networkPDOToolStripMenuItem_Click); // @@ -249,25 +263,35 @@ private void InitializeComponent() this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill; this.tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed; this.tabControl1.ItemSize = new System.Drawing.Size(24, 120); - this.tabControl1.Location = new System.Drawing.Point(0, 24); + this.tabControl1.Location = new System.Drawing.Point(0, 28); + this.tabControl1.Margin = new System.Windows.Forms.Padding(4); this.tabControl1.Multiline = true; this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; - this.tabControl1.Size = new System.Drawing.Size(1199, 737); + this.tabControl1.Size = new System.Drawing.Size(1599, 909); this.tabControl1.SizeMode = System.Windows.Forms.TabSizeMode.Fixed; this.tabControl1.TabIndex = 2; this.tabControl1.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.tabControl1_DrawItem); this.tabControl1.ControlAdded += new System.Windows.Forms.ControlEventHandler(this.tabControl1_ControlsChanged); this.tabControl1.ControlRemoved += new System.Windows.Forms.ControlEventHandler(this.tabControl1_Controlsremoved); // + // saveAsToolStripMenuItem + // + this.saveAsToolStripMenuItem.Enabled = false; + this.saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem"; + this.saveAsToolStripMenuItem.Size = new System.Drawing.Size(288, 26); + this.saveAsToolStripMenuItem.Text = "Save As"; + this.saveAsToolStripMenuItem.Click += new System.EventHandler(this.saveAsToolStripMenuItem_Click); + // // ODEditor_MainForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1199, 761); + this.ClientSize = new System.Drawing.Size(1599, 937); this.Controls.Add(this.tabControl1); this.Controls.Add(this.menuStrip1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.Margin = new System.Windows.Forms.Padding(4); this.Name = "ODEditor_MainForm"; this.Text = "Object Dictionary Editor "; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ODEditor_MainForm_FormClosing); @@ -306,6 +330,8 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem networkPDOToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem saveExportAllToolStripMenuItem; private System.Windows.Forms.ToolStripSeparator toolStripSeparator7; + private System.Windows.Forms.ToolStripMenuItem exportDeviceFileToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem saveAsToolStripMenuItem; } } diff --git a/EDSTest/Form1.cs b/EDSTest/Form1.cs index f6bab4bb..573c1a6d 100644 --- a/EDSTest/Form1.cs +++ b/EDSTest/Form1.cs @@ -193,6 +193,8 @@ private void openEDSfile(string path,InfoSection.Filetype ft) } } + + private void exportCanOpenNodeToolStripMenuItem_Click(object sender, EventArgs e) { if (tabControl1.SelectedTab != null) @@ -281,7 +283,7 @@ private void openXDDfile(string path) if (eds == null) return; - eds.xmlfilename = path; + eds.xddfilename = path; tabControl1.TabPages.Add(eds.di.ProductName); @@ -475,14 +477,14 @@ private void saveEDSToolStripMenuItem_Click(object sender, EventArgs e) } } - private void saveProjectXMLToolStripMenuItem_Click(object sender, EventArgs e) + private void exportDeviceFileToolStripMenuItem_Click(object sender, EventArgs e) { if (tabControl1.SelectedTab != null) { DeviceView dv = (DeviceView)tabControl1.SelectedTab.Controls[0]; SaveFileDialog sfd = new SaveFileDialog(); - sfd.Filter = "Canopen Node XML (*.xml)|*.xml|Electronic Data Sheets (*.eds)|*.eds|Device Configuration Files (*.dcf)|*.dcf|Canopen XDD (*.xdd)|*.xdd"; + sfd.Filter = "Canopen Node XML (*.xml)|*.xml|Electronic Data Sheets (*.eds)|*.eds|Device Configuration Files (*.dcf)|*.dcf"; sfd.InitialDirectory = Path.GetDirectoryName(dv.eds.xmlfilename); sfd.RestoreDirectory = true; @@ -490,46 +492,86 @@ private void saveProjectXMLToolStripMenuItem_Click(object sender, EventArgs e) if (sfd.ShowDialog() == DialogResult.OK) { + dosave(dv, sfd.FileName); + } + } + } - switch(Path.GetExtension(sfd.FileName)) - { - case ".eds": - dv.eds.Savefile(sfd.FileName, InfoSection.Filetype.File_EDS); - dv.eds.edsfilename = sfd.FileName; - break; - case ".dcf": - dv.eds.Savefile(sfd.FileName, InfoSection.Filetype.File_DCF); - dv.eds.dcffilename = sfd.FileName; - break; + private void saveProjectXMLToolStripMenuItem_Click(object sender, EventArgs e) + { + if (tabControl1.SelectedTab != null) + { + DeviceView dv = (DeviceView)tabControl1.SelectedTab.Controls[0]; - case ".xml": - Bridge b = new Bridge(); - Device d = b.convert(dv.eds); + if (dv.eds.xddfilename!=null && dv.eds.xddfilename != "") + { + dosave(dv, dv.eds.xddfilename); + } + else + { + saveAsToolStripMenuItem_Click(sender, e); + } + } + } - CanOpenXML coxml = new CanOpenXML(); - coxml.dev = d; + private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) + { + if (tabControl1.SelectedTab != null) + { + DeviceView dv = (DeviceView)tabControl1.SelectedTab.Controls[0]; + SaveFileDialog sfd = new SaveFileDialog(); - coxml.writeXML(sfd.FileName); + sfd.Filter = "CanOpen XDD (*.xdd)|*.xdd"; - dv.eds.xmlfilename = sfd.FileName; - dv.eds.Dirty = false; - dv.dispatch_updateOD(); - break; + sfd.InitialDirectory = Path.GetDirectoryName(dv.eds.xmlfilename); + sfd.RestoreDirectory = true; + sfd.FileName = Path.GetFileNameWithoutExtension(dv.eds.xmlfilename); - case ".xdd": - CanOpenXDD coxdd = new CanOpenXDD(); - coxdd.writeXML(sfd.FileName, dv.eds); - dv.eds.xddfilename = sfd.FileName; - dv.eds.Dirty = false; + if (sfd.ShowDialog() == DialogResult.OK) + { + dosave(dv, sfd.FileName); + } + } - break; + } - } - dv.dispatch_updateOD(); - } + void dosave(DeviceView dv,string FileName) + { + + switch (Path.GetExtension(FileName)) + { + case ".eds": + dv.eds.Savefile(FileName, InfoSection.Filetype.File_EDS); + dv.eds.edsfilename = FileName; + break; + + case ".dcf": + dv.eds.Savefile(FileName, InfoSection.Filetype.File_DCF); + dv.eds.dcffilename = FileName; + break; + + case ".xml": + Bridge b = new Bridge(); + Device d = b.convert(dv.eds); + + CanOpenXML coxml = new CanOpenXML(); + coxml.dev = d; + coxml.writeXML(FileName); + dv.eds.xmlfilename = FileName; + break; + + case ".xdd": + CanOpenXDD coxdd = new CanOpenXDD(); + coxdd.writeXML(FileName, dv.eds); + dv.eds.xddfilename = FileName; + dv.eds.Dirty = false; + break; } + + dv.dispatch_updateOD(); + } private void newToolStripMenuItem_Click(object sender, EventArgs e) @@ -548,6 +590,8 @@ private void newToolStripMenuItem_Click(object sender, EventArgs e) device.Dock = DockStyle.Fill; device.dispatch_updateOD(); + + network.Add(eds); } private void tabControl1_ControlsChanged(object sender, ControlEventArgs e) @@ -571,6 +615,8 @@ private void enablesavemenus(bool enable) documentationToolStripMenuItem.Enabled = enable; networkPDOToolStripMenuItem.Enabled = enable; saveExportAllToolStripMenuItem.Enabled = enable; + exportDeviceFileToolStripMenuItem.Enabled = enable; + saveAsToolStripMenuItem.Enabled = true; } @@ -687,7 +733,7 @@ private void saveNetworkXmlToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); - sfd.Filter = "CanOpen network XML (*.nxml)|*.nxml"; + sfd.Filter = "CanOpen Network XDD (*.nxdd)|*.nxdd|CanOpen network XML (*.nxml)|*.nxml"; sfd.InitialDirectory = Path.GetDirectoryName(networkfilename); sfd.RestoreDirectory = true; @@ -695,11 +741,21 @@ private void saveNetworkXmlToolStripMenuItem_Click(object sender, EventArgs e) if (sfd.ShowDialog() == DialogResult.OK) { - //dv.eds.savefile(sfd.FileName); - NetworkXML net = new NetworkXML(); - net.writeXML(sfd.FileName, network); - addtoMRU(sfd.FileName); + switch (Path.GetExtension(sfd.FileName).ToLower()) + { + case ".nxml": + NetworkXML net = new NetworkXML(); + net.writeXML(sfd.FileName, network); + addtoMRU(sfd.FileName); + break; + + case ".nxdd": + CanOpenXDD xdd = new CanOpenXDD(); + xdd.writeMultiXML(sfd.FileName, network); + break; + + } } @@ -709,11 +765,56 @@ private void loadNetworkXmlToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog odf = new OpenFileDialog(); - odf.Filter = "CanOpen network XML (*.nxml)|*.nxml"; + odf.Filter = "CanOpen Network XDD (*.nxdd)|*.nxdd|CanOpen network XML (*.nxml)|*.nxml"; if (odf.ShowDialog() == DialogResult.OK) { - openNetworkfile(odf.FileName); + switch (Path.GetExtension(odf.FileName).ToLower()) + { + case ".nxml": + openNetworkfile(odf.FileName); + break; + + case ".nxdd": + + openXDDNetworkfile(odf.FileName); + + break; + + } + + + } + } + + private void openXDDNetworkfile(string file) + { + CanOpenXDD xdd = new CanOpenXDD(); + List edss = xdd.readMultiXML(file); + + if (edss == null) + return; + + foreach (EDSsharp eds in edss) + { + + tabControl1.TabPages.Add(eds.di.ProductName); + + DeviceView device = new DeviceView(); + + device.eds = eds; + tabControl1.TabPages[tabControl1.TabPages.Count - 1].Controls.Add(device); + device.Dock = DockStyle.Fill; + + network.Add(eds); + eds.OnDataDirty += Eds_onDataDirty; + + device.dispatch_updateOD(); + } + + addtoMRU(file); + networkfilename = file; + } private void openNetworkfile(string file) @@ -983,5 +1084,7 @@ private void ODEditor_MainForm_FormClosing(object sender, FormClosingEventArgs e } } + + } } diff --git a/libEDSsharp/CanOpenXDD.cs b/libEDSsharp/CanOpenXDD.cs index d8586738..93906110 100644 --- a/libEDSsharp/CanOpenXDD.cs +++ b/libEDSsharp/CanOpenXDD.cs @@ -29,11 +29,58 @@ public EDSsharp readXML(string file) } - public void writeXML(string file, EDSsharp eds) + public List readMultiXML(string file ) { + List edss = new List(); + + try + { + XmlSerializer serializer = new XmlSerializer(typeof(OpenEDSProject)); + StreamReader reader = new StreamReader(file); + OpenEDSProject oep = (OpenEDSProject)serializer.Deserialize(reader); + + foreach(ISO15745ProfileContainer cont in oep.ISO15745ProfileContainer) + { + edss.Add(convert(cont)); + } + + reader.Close(); + + return edss; + } + catch (Exception e) + { + Console.WriteLine(e.ToString()); + return null; + } + } + + public void writeMultiXML(string file, List edss) + { + + List devs = new List(); + + foreach (EDSsharp eds in edss) + { + ISO15745ProfileContainer dev = convert(eds); + devs.Add(dev); + } + + OpenEDSProject oep = new OpenEDSProject(); + oep.Version = "1.0"; + + oep.ISO15745ProfileContainer = devs; + + XmlSerializer serializer = new XmlSerializer(typeof(OpenEDSProject)); + StreamWriter writer = new StreamWriter(file); + serializer.Serialize(writer, oep); + writer.Close(); + } + + public void writeXML(string file, EDSsharp eds) + { dev = convert(eds); - XmlSerializer serializer = new XmlSerializer(typeof(ISO15745ProfileContainer)); StreamWriter writer = new StreamWriter(file); serializer.Serialize(writer, dev); @@ -838,6 +885,7 @@ public EDSsharp convert(ISO15745ProfileContainer container) } } + if (ApplicationLayers.CANopenObjectList.CANopenObject != null) foreach (XSDImport.CANopenObjectListCANopenObject obj3 in ApplicationLayers.CANopenObjectList.CANopenObject) { ODentry entry = new ODentry(); @@ -1177,6 +1225,15 @@ public EDSsharp convert(ISO15745ProfileContainer container) } +[XmlRoot(ElementName = "OpenEDSProject")] +public class OpenEDSProject +{ + [XmlElement(ElementName = "ISO15745ProfileContainer", Namespace = "http://www.canopen.org/xml/1.0")] + public List ISO15745ProfileContainer { get; set; } + [XmlAttribute(AttributeName = "version")] + public string Version { get; set; } + +} namespace XSDImport