From 7b8ceba96707e783e80b559867af06827517f33c Mon Sep 17 00:00:00 2001 From: Ueli Niederer Date: Thu, 15 Dec 2022 09:19:47 +0100 Subject: [PATCH 1/7] Extend dirty-notification with an option to save instantly rather than just falling back --- EDSEditorGUI/DeviceODView.cs | 1299 +++++++++++++++++----------------- 1 file changed, 661 insertions(+), 638 deletions(-) diff --git a/EDSEditorGUI/DeviceODView.cs b/EDSEditorGUI/DeviceODView.cs index dc0453a5..005e34c0 100644 --- a/EDSEditorGUI/DeviceODView.cs +++ b/EDSEditorGUI/DeviceODView.cs @@ -1,47 +1,47 @@ -/* - 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.Drawing; -using System.Windows.Forms; -using System.Reflection; -using System.Text.RegularExpressions; +/* + 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.Drawing; +using System.Windows.Forms; +using System.Reflection; +using System.Text.RegularExpressions; using libEDSsharp; -namespace ODEditor -{ - - public partial class DeviceODView : MyTabUserControl - { - EDSsharp eds = null; - - ODentry selectedObject; - ODentry lastSelectedObject; - ListView selectedList; +namespace ODEditor +{ + + public partial class DeviceODView : MyTabUserControl + { + EDSsharp eds = null; + + ODentry selectedObject; + ODentry lastSelectedObject; + ListView selectedList; bool justUpdating = false; bool ExporterOld = false; bool ExporterV4 = false; - public DeviceODView() - { - + public DeviceODView() + { + InitializeComponent(); RebuildControls(); @@ -126,322 +126,345 @@ private bool ExporterTypeV4() { return (type == ExporterFactory.Exporter.CANOPENNODE_V4); } - private bool Checkdirty() - { - if (button_saveChanges.BackColor == Color.Red) - { - if (lastSelectedObject != null && MessageBox.Show(String.Format("Unsaved changes on Index 0x{0:X4}/{1:X2}.\nDo you wish to switch object and loose your changes?", lastSelectedObject.Index, lastSelectedObject.Subindex), "Unsaved changes", MessageBoxButtons.YesNo) == DialogResult.No) - { - return true; - } - button_saveChanges.BackColor = default; - } - - return false; - } - - private void ComboBoxSet(ComboBox comboBox, string item) - { - if (item == null) - item = ""; - - if (!comboBox.Items.Contains(item)) - comboBox.Items.Add(item); - - comboBox.SelectedItem = item; - } - - public void PopulateObjectLists(EDSsharp eds_target) - { - if (eds_target == null) - return; - - eds = eds_target; - eds.UpdatePDOcount(); - doUpdateDeviceInfo(); - doUpdatePDOs(); - - /* save scroll positions */ - int listview_communication_position = 0; - int listview_manufacturer_position = 0; - int listview_deviceProfile_position = 0; - - if (listView_communication_objects.TopItem != null) - listview_communication_position = listView_communication_objects.TopItem.Index; - if (listView_manufacturer_objects.TopItem != null) - listview_manufacturer_position = listView_manufacturer_objects.TopItem.Index; - if (listView_deviceProfile_objects.TopItem != null) - listview_deviceProfile_position = listView_deviceProfile_objects.TopItem.Index; - - /* prevent flickering */ - listView_communication_objects.BeginUpdate(); - listView_manufacturer_objects.BeginUpdate(); - listView_deviceProfile_objects.BeginUpdate(); - - listView_communication_objects.Items.Clear(); - listView_manufacturer_objects.Items.Clear(); - listView_deviceProfile_objects.Items.Clear(); - - foreach (ODentry od in eds.ods.Values) - { - UInt16 index = od.Index; - ListViewItem lvi = new ListViewItem(new string[] { - string.Format("0x{0:X4}", index), - od.parameter_name - }); - - lvi.Tag = od; - if (selectedObject != null && index == selectedObject.Index) - lvi.Selected = true; - if (od.prop.CO_disabled == true) - lvi.ForeColor = Color.LightGray; - - if (index <= 0x1000 || index < 0x2000) - listView_communication_objects.Items.Add(lvi); - else if (index >= 0x2000 && index < 0x6000) - listView_manufacturer_objects.Items.Add(lvi); - else - listView_deviceProfile_objects.Items.Add(lvi); - - string countLabel = od.prop.CO_countLabel; - if (!comboBox_countLabel.Items.Contains(countLabel)) - comboBox_countLabel.Items.Insert(comboBox_countLabel.Items.Count - 1, countLabel); - - string storageGroup = od.prop.CO_storageGroup; - if (!comboBox_storageGroup.Items.Contains(storageGroup)) - comboBox_storageGroup.Items.Insert(comboBox_storageGroup.Items.Count - 1, storageGroup); - } - - listView_communication_objects.EndUpdate(); - listView_manufacturer_objects.EndUpdate(); - listView_deviceProfile_objects.EndUpdate(); - - /* reset scroll position and selection */ - if (listview_communication_position != 0 && listView_communication_objects.Items.Count > 0) - listView_communication_objects.TopItem = listView_communication_objects.Items[listview_communication_position]; - if (listview_manufacturer_position != 0 && listView_manufacturer_objects.Items.Count > 0) - listView_manufacturer_objects.TopItem = listView_manufacturer_objects.Items[listview_manufacturer_position]; - if (listview_deviceProfile_position != 0 && listView_deviceProfile_objects.Items.Count > 0) - listView_deviceProfile_objects.TopItem = listView_deviceProfile_objects.Items[listview_deviceProfile_position]; - } - - public void PopulateSubList() - { - listView_subObjects.Items.Clear(); - - if (selectedObject == null) + private bool Checkdirty() + { + var result = false; + + if (button_saveChanges.BackColor == Color.Red) + { + var answer = MessageBox.Show(String.Format("Unsaved changes on Index 0x{0:X4}/{1:X2}.\nDo you wish to switch object and loose your changes?", lastSelectedObject.Index, lastSelectedObject.Subindex), "Unsaved changes", MessageBoxButtons.YesNoCancel); + switch (answer) + { + case DialogResult.Cancel: + default: + result = lastSelectedObject != null; + break; + + case DialogResult.Yes: + result = false; + break; + + case DialogResult.No: + if (lastSelectedObject != null) + { + ObjectSave(); + result = false; + } + break; + } + + button_saveChanges.BackColor = default; + } + + return result; + } + + private void ComboBoxSet(ComboBox comboBox, string item) + { + if (item == null) + item = ""; + + if (!comboBox.Items.Contains(item)) + comboBox.Items.Add(item); + + comboBox.SelectedItem = item; + } + + public void PopulateObjectLists(EDSsharp eds_target) + { + if (eds_target == null) + return; + + eds = eds_target; + eds.UpdatePDOcount(); + doUpdateDeviceInfo(); + doUpdatePDOs(); + + /* save scroll positions */ + int listview_communication_position = 0; + int listview_manufacturer_position = 0; + int listview_deviceProfile_position = 0; + + if (listView_communication_objects.TopItem != null) + listview_communication_position = listView_communication_objects.TopItem.Index; + if (listView_manufacturer_objects.TopItem != null) + listview_manufacturer_position = listView_manufacturer_objects.TopItem.Index; + if (listView_deviceProfile_objects.TopItem != null) + listview_deviceProfile_position = listView_deviceProfile_objects.TopItem.Index; + + /* prevent flickering */ + listView_communication_objects.BeginUpdate(); + listView_manufacturer_objects.BeginUpdate(); + listView_deviceProfile_objects.BeginUpdate(); + + listView_communication_objects.Items.Clear(); + listView_manufacturer_objects.Items.Clear(); + listView_deviceProfile_objects.Items.Clear(); + + foreach (ODentry od in eds.ods.Values) + { + UInt16 index = od.Index; + ListViewItem lvi = new ListViewItem(new string[] { + string.Format("0x{0:X4}", index), + od.parameter_name + }); + + lvi.Tag = od; + if (selectedObject != null && index == selectedObject.Index) + lvi.Selected = true; + if (od.prop.CO_disabled == true) + lvi.ForeColor = Color.LightGray; + + if (index <= 0x1000 || index < 0x2000) + listView_communication_objects.Items.Add(lvi); + else if (index >= 0x2000 && index < 0x6000) + listView_manufacturer_objects.Items.Add(lvi); + else + listView_deviceProfile_objects.Items.Add(lvi); + + string countLabel = od.prop.CO_countLabel; + if (!comboBox_countLabel.Items.Contains(countLabel)) + comboBox_countLabel.Items.Insert(comboBox_countLabel.Items.Count - 1, countLabel); + + string storageGroup = od.prop.CO_storageGroup; + if (!comboBox_storageGroup.Items.Contains(storageGroup)) + comboBox_storageGroup.Items.Insert(comboBox_storageGroup.Items.Count - 1, storageGroup); + } + + listView_communication_objects.EndUpdate(); + listView_manufacturer_objects.EndUpdate(); + listView_deviceProfile_objects.EndUpdate(); + + /* reset scroll position and selection */ + if (listview_communication_position != 0 && listView_communication_objects.Items.Count > 0) + listView_communication_objects.TopItem = listView_communication_objects.Items[listview_communication_position]; + if (listview_manufacturer_position != 0 && listView_manufacturer_objects.Items.Count > 0) + listView_manufacturer_objects.TopItem = listView_manufacturer_objects.Items[listview_manufacturer_position]; + if (listview_deviceProfile_position != 0 && listView_deviceProfile_objects.Items.Count > 0) + listView_deviceProfile_objects.TopItem = listView_deviceProfile_objects.Items[listview_deviceProfile_position]; + } + + public void PopulateSubList() + { + listView_subObjects.Items.Clear(); + + if (selectedObject == null) return; - ODentry od = selectedObject.parent ?? selectedObject; - - if (od.objecttype == ObjectType.VAR) - { - ListViewItem lvi = new ListViewItem(new string[] { - " ", // subindex - od.parameter_name, - od.ObjectTypeString(), - od.datatype.ToString(), - od.AccessSDO().ToString(), - od.AccessPDO().ToString(), - od.prop.CO_accessSRDO.ToString(), - od.defaultvalue - }); - lvi.Tag = od; - listView_subObjects.Items.Add(lvi); - } - else if (od.objecttype == ObjectType.ARRAY || od.objecttype == ObjectType.RECORD) - { - ListViewItem lvi = new ListViewItem(new string[]{ - " ", - od.parameter_name, - od.ObjectTypeString() - }); - lvi.Tag = od; - listView_subObjects.Items.Add(lvi); - - foreach (KeyValuePair kvp in od.subobjects) - { - ODentry subod = kvp.Value; - int subindex = kvp.Key; - - ListViewItem lvi2 = new ListViewItem(new string[] { - string.Format("0x{0:X2}", subindex), - subod.parameter_name, - subod.ObjectTypeString(), - (subod.datatype != DataType.UNKNOWN) ? subod.datatype.ToString() : od.datatype.ToString(), - subod.AccessSDO().ToString(), - subod.AccessPDO().ToString(), - subod.prop.CO_accessSRDO.ToString(), - subod.defaultvalue - }); - lvi2.Tag = subod; - listView_subObjects.Items.Add(lvi2); - } - } - } - - public void PopulateObject() - { - - ExporterV4 = ExporterTypeV4(); + ODentry od = selectedObject.parent ?? selectedObject; + + if (od.objecttype == ObjectType.VAR) + { + ListViewItem lvi = new ListViewItem(new string[] { + " ", // subindex + od.parameter_name, + od.ObjectTypeString(), + od.datatype.ToString(), + od.AccessSDO().ToString(), + od.AccessPDO().ToString(), + od.prop.CO_accessSRDO.ToString(), + od.defaultvalue + }); + lvi.Tag = od; + listView_subObjects.Items.Add(lvi); + } + else if (od.objecttype == ObjectType.ARRAY || od.objecttype == ObjectType.RECORD) + { + ListViewItem lvi = new ListViewItem(new string[]{ + " ", + od.parameter_name, + od.ObjectTypeString() + }); + lvi.Tag = od; + listView_subObjects.Items.Add(lvi); + + foreach (KeyValuePair kvp in od.subobjects) + { + ODentry subod = kvp.Value; + int subindex = kvp.Key; + + ListViewItem lvi2 = new ListViewItem(new string[] { + string.Format("0x{0:X2}", subindex), + subod.parameter_name, + subod.ObjectTypeString(), + (subod.datatype != DataType.UNKNOWN) ? subod.datatype.ToString() : od.datatype.ToString(), + subod.AccessSDO().ToString(), + subod.AccessPDO().ToString(), + subod.prop.CO_accessSRDO.ToString(), + subod.defaultvalue + }); + lvi2.Tag = subod; + listView_subObjects.Items.Add(lvi2); + } + } + } + + public void PopulateObject() + { + + ExporterV4 = ExporterTypeV4(); if (ExporterOld != ExporterV4) - { - RebuildControls(); + { + RebuildControls(); ExporterOld = ExporterV4; - } - - justUpdating = true; - lastSelectedObject = selectedObject; - - - if (selectedObject == null) - { - textBox_index.Text = ""; - textBox_subIndex.Text = ""; - textBox_name.Text = ""; - textBox_denotation.Text = ""; - textBox_description.Text = ""; - justUpdating = false; - return; - } - - ODentry od = selectedObject; - - textBox_index.Text = string.Format("0x{0:X4}", od.Index); - textBox_name.Text = od.parameter_name; - textBox_denotation.Text = od.denotation; - textBox_description.Text = (od.Description == null) ? "" : Regex.Replace(od.Description, "(? 0) - { - foreach (ODentry subod in od.parent.subobjects.Values) - { - if (subod.Subindex > 0) - { - subod.datatype = od.datatype; - subod.accesstype = od.accesstype; - subod.PDOtype = od.PDOtype; - subod.prop.CO_accessSRDO = od.prop.CO_accessSRDO; - } - } - od.parent.datatype = od.datatype; - od.parent.accesstype = od.accesstype; - od.parent.PDOtype = od.PDOtype; - od.parent.prop.CO_accessSRDO = od.prop.CO_accessSRDO; - } - } - - if (od.parent == null) - { - od.prop.CO_countLabel = comboBox_countLabel.SelectedItem.ToString(); - od.prop.CO_storageGroup = comboBox_storageGroup.SelectedItem.ToString(); - od.prop.CO_disabled = !checkBox_enabled.Checked; - od.prop.CO_flagsPDO = checkBox_pdoFlags.Checked; - } - - PopulateObjectLists(eds); - PopulateSubList(); - PopulateObject(); - } - - private void ListView_objects_MouseClick(object sender, MouseEventArgs e) - { - ListView listview = (ListView)sender; - ODentry od = listview.SelectedItems.Count > 0 ? (ODentry)listview.SelectedItems[0].Tag : null; - - if ((od != selectedObject || e.Button == MouseButtons.Right) && !Checkdirty()) - { - selectedList = listview; - selectedObject = od; - - if (e.Button == MouseButtons.Right) - { - contextMenu_object.Show(Cursor.Position); - } - - PopulateObject(); - PopulateSubList(); - } - listView_communication_objects.HideSelection = true; - listView_deviceProfile_objects.HideSelection = true; - listView_manufacturer_objects.HideSelection = true; - } - - private void ListView_objects_SelectedIndexChanged(object sender, EventArgs e) - { - ListView_objects_MouseClick(sender, new MouseEventArgs(MouseButtons.None, 0, 0, 0, 0)); - } - - private void ListView_objects_ColumnClick(object sender, ColumnClickEventArgs e) - { - ((ListView)sender).SelectedItems.Clear(); - ListView_objects_MouseClick(sender, new MouseEventArgs(MouseButtons.Right, 0, 0, 0, 0)); - } - - private void ListView_subObjects_MouseClick(object sender, MouseEventArgs e) - { - if (listView_subObjects.SelectedItems.Count == 0) - return; - - ODentry od = (ODentry)listView_subObjects.SelectedItems[0].Tag; - - if ((od != selectedObject || e.Button == MouseButtons.Right) && !Checkdirty()) - { - if (e.Button == MouseButtons.Right) - { - ODentry parent = od.parent ?? od; - - if (parent.objecttype == ObjectType.ARRAY || parent.objecttype == ObjectType.RECORD) - { - contextMenu_subObject_removeSubItemToolStripMenuItem.Enabled = od.Subindex > 0 && od.parent != null; - contextMenu_subObject_removeSubItemLeaveGapToolStripMenuItem.Enabled = parent.objecttype == ObjectType.RECORD && od.Subindex > 0 && od.parent != null; - - if (listView_subObjects.FocusedItem.Bounds.Contains(e.Location) == true) - { - contextMenu_subObject.Show(Cursor.Position); - } - } - } - selectedObject = od; - PopulateObject(); - } - } - - private void ListView_subObjects_SelectedIndexChanged(object sender, EventArgs e) - { - ListView_subObjects_MouseClick(sender, new MouseEventArgs(MouseButtons.None, 0, 0, 0, 0)); - } - - private void ComboBox_countLabel_Add(object sender, EventArgs e) - { - ComboBox comboBox = (ComboBox)sender; - - if (comboBox.SelectedItem != null && comboBox.SelectedItem.ToString() == "Add...") - { - NewItem dialog = new NewItem("Add Count Label"); - if (dialog.ShowDialog() == DialogResult.OK && comboBox.FindStringExact(dialog.name) == -1) - { - comboBox.Items.Insert(comboBox.Items.Count - 1, dialog.name); - comboBox.SelectedItem = dialog.name; - } - } - } - - private void ComboBox_storageGroup_Add(object sender, EventArgs e) - { - ComboBox comboBox = (ComboBox)sender; - - if (comboBox.SelectedItem!=null && comboBox.SelectedItem.ToString() == "Add...") - { - NewItem dialog = new NewItem("Add Storage Group"); - if (dialog.ShowDialog() == DialogResult.OK && comboBox.FindStringExact(dialog.name) == -1) - { - comboBox.Items.Insert(comboBox.Items.Count - 1, dialog.name); - comboBox.SelectedItem = dialog.name; - /* add new dialog location to eds back end */ - eds.CO_storageGroups.Add(dialog.name); - } - } - } - - private void ContextMenu_object_clone_ToolStripMenuItem_Click(object sender, EventArgs e) - { - var srcObjects = new SortedDictionary(); - foreach (ListViewItem item in selectedList.SelectedItems) - { - ODentry od = (ODentry)item.Tag; - srcObjects.Add(od.Index, od); - } - - if (srcObjects.Count > 0) - { - InsertObjects insObjForm = new InsertObjects(eds, srcObjects, "1"); - - if (insObjForm.ShowDialog() == DialogResult.OK) - { - selectedObject = null; - eds.Dirty = true; - PopulateObjectLists(eds); - PopulateSubList(); - PopulateObject(); - } - } - } - - private void ContextMenu_object_add_ToolStripMenuItem_Click(object sender, EventArgs e) - { - NewIndex ni = new NewIndex(eds, (UInt16)(selectedObject == null ? 0x2000 : selectedObject.Index + 1)); - - if (ni.ShowDialog() == DialogResult.OK) - { - selectedObject = ni.od; - eds.Dirty = true; - PopulateObjectLists(eds); - PopulateSubList(); - PopulateObject(); - } - } - - private void ContextMenu_object_delete_ToolStripMenuItem_Click(object sender, EventArgs e) - { - ListView.SelectedListViewItemCollection selectedItems = selectedList.SelectedItems; - if (selectedItems.Count > 0) - { - DialogResult confirmDelete = MessageBox.Show(string.Format("Do you really want to delete the selected {0} items?", selectedItems.Count), "Are you sure?", MessageBoxButtons.YesNo); - - if (confirmDelete == DialogResult.Yes) - { - foreach (ListViewItem item in selectedItems) - { - ODentry od = (ODentry)item.Tag; - eds.ods.Remove(od.Index); - } - - eds.Dirty = true; - selectedObject = null; - PopulateObjectLists(eds); - PopulateSubList(); - PopulateObject(); - } - } - } - - private void ContextMenu_object_toggle_ToolStripMenuItem_Click(object sender, EventArgs e) - { - ListView.SelectedListViewItemCollection selectedItems = selectedList.SelectedItems; - - justUpdating = true; - foreach (ListViewItem item in selectedItems) - { - ODentry od = (ODentry)item.Tag; - - od.prop.CO_disabled = !od.prop.CO_disabled; - } - justUpdating = false; - eds.Dirty = true; - PopulateObjectLists(eds); - PopulateObject(); - } - - private void ContextMenu_subObject_add_ToolStripMenuItem_Click(object sender, EventArgs e) - { - ListView.SelectedListViewItemCollection selectedItems = listView_subObjects.SelectedItems; - - ODentry newOd = null; - - foreach (ListViewItem item in selectedItems) - { - ODentry od = (ODentry)item.Tag; - newOd = od.AddSubEntry(); - } - - eds.Dirty = true; - selectedObject = newOd; - PopulateSubList(); - PopulateObject(); - } - - private void ContextMenu_subObject_remove_ToolStripMenuItem_Click(object sender, EventArgs e) - { - ListView.SelectedListViewItemCollection selectedItems = listView_subObjects.SelectedItems; - bool renumber = sender == contextMenu_subObject_removeSubItemToolStripMenuItem; - bool update = false; - - foreach (ListViewItem item in selectedItems) - { - ODentry od = (ODentry)item.Tag; - od.RemoveSubEntry(renumber); - update = true; - } - - if (update) - { - eds.Dirty = true; - selectedObject = selectedObject.parent; - PopulateSubList(); - PopulateObject(); - } - } - } - - public static class ControlExtensions - { - public static void DoubleBuffering(this Control control, bool enable) - { - var method = typeof(Control).GetMethod("SetStyle", BindingFlags.Instance | BindingFlags.NonPublic); - method.Invoke(control, new object[] { ControlStyles.OptimizedDoubleBuffer, enable }); - } - } -} + od.prop.CO_accessSRDO = (AccessSRDO)Enum.Parse(typeof(AccessSRDO), comboBox_accessSRDO.SelectedItem.ToString()); + } + catch (Exception) + { + od.prop.CO_accessSRDO = AccessSRDO.no; + } + + od.defaultvalue = textBox_defaultValue.Text; + od.actualvalue = textBox_actualValue.Text; + od.HighLimit = textBox_highLimit.Text; + od.LowLimit = textBox_lowLimit.Text; + + // CO_stringLengthMin + if (od.datatype == DataType.VISIBLE_STRING || od.datatype == DataType.UNICODE_STRING || od.datatype == DataType.OCTET_STRING) + { + try + { + od.prop.CO_stringLengthMin = (uint)new System.ComponentModel.UInt32Converter().ConvertFromString(textBox_stringLengthMin.Text); + } + catch (Exception) + { + od.prop.CO_stringLengthMin = 0; + } + } + else + { + od.prop.CO_stringLengthMin = 0; + } + + // some propeties in all array sub elements (and base element) must be equal + if (od.parent != null && od.parent.objecttype == ObjectType.ARRAY && od.Subindex > 0) + { + foreach (ODentry subod in od.parent.subobjects.Values) + { + if (subod.Subindex > 0) + { + subod.datatype = od.datatype; + subod.accesstype = od.accesstype; + subod.PDOtype = od.PDOtype; + subod.prop.CO_accessSRDO = od.prop.CO_accessSRDO; + } + } + od.parent.datatype = od.datatype; + od.parent.accesstype = od.accesstype; + od.parent.PDOtype = od.PDOtype; + od.parent.prop.CO_accessSRDO = od.prop.CO_accessSRDO; + } + } + + if (od.parent == null) + { + od.prop.CO_countLabel = comboBox_countLabel.SelectedItem.ToString(); + od.prop.CO_storageGroup = comboBox_storageGroup.SelectedItem.ToString(); + od.prop.CO_disabled = !checkBox_enabled.Checked; + od.prop.CO_flagsPDO = checkBox_pdoFlags.Checked; + } + + PopulateObjectLists(eds); + PopulateSubList(); + PopulateObject(); + } + + private void ListView_objects_MouseClick(object sender, MouseEventArgs e) + { + ListView listview = (ListView)sender; + ODentry od = listview.SelectedItems.Count > 0 ? (ODentry)listview.SelectedItems[0].Tag : null; + + if ((od != selectedObject || e.Button == MouseButtons.Right) && !Checkdirty()) + { + selectedList = listview; + selectedObject = od; + + if (e.Button == MouseButtons.Right) + { + contextMenu_object.Show(Cursor.Position); + } + + PopulateObject(); + PopulateSubList(); + } + listView_communication_objects.HideSelection = true; + listView_deviceProfile_objects.HideSelection = true; + listView_manufacturer_objects.HideSelection = true; + } + + private void ListView_objects_SelectedIndexChanged(object sender, EventArgs e) + { + ListView_objects_MouseClick(sender, new MouseEventArgs(MouseButtons.None, 0, 0, 0, 0)); + } + + private void ListView_objects_ColumnClick(object sender, ColumnClickEventArgs e) + { + ((ListView)sender).SelectedItems.Clear(); + ListView_objects_MouseClick(sender, new MouseEventArgs(MouseButtons.Right, 0, 0, 0, 0)); + } + + private void ListView_subObjects_MouseClick(object sender, MouseEventArgs e) + { + if (listView_subObjects.SelectedItems.Count == 0) + return; + + ODentry od = (ODentry)listView_subObjects.SelectedItems[0].Tag; + + if ((od != selectedObject || e.Button == MouseButtons.Right) && !Checkdirty()) + { + if (e.Button == MouseButtons.Right) + { + ODentry parent = od.parent ?? od; + + if (parent.objecttype == ObjectType.ARRAY || parent.objecttype == ObjectType.RECORD) + { + contextMenu_subObject_removeSubItemToolStripMenuItem.Enabled = od.Subindex > 0 && od.parent != null; + contextMenu_subObject_removeSubItemLeaveGapToolStripMenuItem.Enabled = parent.objecttype == ObjectType.RECORD && od.Subindex > 0 && od.parent != null; + + if (listView_subObjects.FocusedItem.Bounds.Contains(e.Location) == true) + { + contextMenu_subObject.Show(Cursor.Position); + } + } + } + selectedObject = od; + PopulateObject(); + } + } + + private void ListView_subObjects_SelectedIndexChanged(object sender, EventArgs e) + { + ListView_subObjects_MouseClick(sender, new MouseEventArgs(MouseButtons.None, 0, 0, 0, 0)); + } + + private void ComboBox_countLabel_Add(object sender, EventArgs e) + { + ComboBox comboBox = (ComboBox)sender; + + if (comboBox.SelectedItem != null && comboBox.SelectedItem.ToString() == "Add...") + { + NewItem dialog = new NewItem("Add Count Label"); + if (dialog.ShowDialog() == DialogResult.OK && comboBox.FindStringExact(dialog.name) == -1) + { + comboBox.Items.Insert(comboBox.Items.Count - 1, dialog.name); + comboBox.SelectedItem = dialog.name; + } + } + } + + private void ComboBox_storageGroup_Add(object sender, EventArgs e) + { + ComboBox comboBox = (ComboBox)sender; + + if (comboBox.SelectedItem!=null && comboBox.SelectedItem.ToString() == "Add...") + { + NewItem dialog = new NewItem("Add Storage Group"); + if (dialog.ShowDialog() == DialogResult.OK && comboBox.FindStringExact(dialog.name) == -1) + { + comboBox.Items.Insert(comboBox.Items.Count - 1, dialog.name); + comboBox.SelectedItem = dialog.name; + /* add new dialog location to eds back end */ + eds.CO_storageGroups.Add(dialog.name); + } + } + } + + private void ContextMenu_object_clone_ToolStripMenuItem_Click(object sender, EventArgs e) + { + var srcObjects = new SortedDictionary(); + foreach (ListViewItem item in selectedList.SelectedItems) + { + ODentry od = (ODentry)item.Tag; + srcObjects.Add(od.Index, od); + } + + if (srcObjects.Count > 0) + { + InsertObjects insObjForm = new InsertObjects(eds, srcObjects, "1"); + + if (insObjForm.ShowDialog() == DialogResult.OK) + { + selectedObject = null; + eds.Dirty = true; + PopulateObjectLists(eds); + PopulateSubList(); + PopulateObject(); + } + } + } + + private void ContextMenu_object_add_ToolStripMenuItem_Click(object sender, EventArgs e) + { + NewIndex ni = new NewIndex(eds, (UInt16)(selectedObject == null ? 0x2000 : selectedObject.Index + 1)); + + if (ni.ShowDialog() == DialogResult.OK) + { + selectedObject = ni.od; + eds.Dirty = true; + PopulateObjectLists(eds); + PopulateSubList(); + PopulateObject(); + } + } + + private void ContextMenu_object_delete_ToolStripMenuItem_Click(object sender, EventArgs e) + { + ListView.SelectedListViewItemCollection selectedItems = selectedList.SelectedItems; + if (selectedItems.Count > 0) + { + DialogResult confirmDelete = MessageBox.Show(string.Format("Do you really want to delete the selected {0} items?", selectedItems.Count), "Are you sure?", MessageBoxButtons.YesNo); + + if (confirmDelete == DialogResult.Yes) + { + foreach (ListViewItem item in selectedItems) + { + ODentry od = (ODentry)item.Tag; + eds.ods.Remove(od.Index); + } + + eds.Dirty = true; + selectedObject = null; + PopulateObjectLists(eds); + PopulateSubList(); + PopulateObject(); + } + } + } + + private void ContextMenu_object_toggle_ToolStripMenuItem_Click(object sender, EventArgs e) + { + ListView.SelectedListViewItemCollection selectedItems = selectedList.SelectedItems; + + justUpdating = true; + foreach (ListViewItem item in selectedItems) + { + ODentry od = (ODentry)item.Tag; + + od.prop.CO_disabled = !od.prop.CO_disabled; + } + justUpdating = false; + eds.Dirty = true; + PopulateObjectLists(eds); + PopulateObject(); + } + + private void ContextMenu_subObject_add_ToolStripMenuItem_Click(object sender, EventArgs e) + { + ListView.SelectedListViewItemCollection selectedItems = listView_subObjects.SelectedItems; + + ODentry newOd = null; + + foreach (ListViewItem item in selectedItems) + { + ODentry od = (ODentry)item.Tag; + newOd = od.AddSubEntry(); + } + + eds.Dirty = true; + selectedObject = newOd; + PopulateSubList(); + PopulateObject(); + } + + private void ContextMenu_subObject_remove_ToolStripMenuItem_Click(object sender, EventArgs e) + { + ListView.SelectedListViewItemCollection selectedItems = listView_subObjects.SelectedItems; + bool renumber = sender == contextMenu_subObject_removeSubItemToolStripMenuItem; + bool update = false; + + foreach (ListViewItem item in selectedItems) + { + ODentry od = (ODentry)item.Tag; + od.RemoveSubEntry(renumber); + update = true; + } + + if (update) + { + eds.Dirty = true; + selectedObject = selectedObject.parent; + PopulateSubList(); + PopulateObject(); + } + } + } + + public static class ControlExtensions + { + public static void DoubleBuffering(this Control control, bool enable) + { + var method = typeof(Control).GetMethod("SetStyle", BindingFlags.Instance | BindingFlags.NonPublic); + method.Invoke(control, new object[] { ControlStyles.OptimizedDoubleBuffer, enable }); + } + } +} From 5ef3e831b60bc166f0a36c0c0a453880fe85bf19 Mon Sep 17 00:00:00 2001 From: Ueli Niederer Date: Thu, 15 Dec 2022 09:24:11 +0100 Subject: [PATCH 2/7] Make message more explicit --- EDSEditorGUI/DeviceODView.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EDSEditorGUI/DeviceODView.cs b/EDSEditorGUI/DeviceODView.cs index 005e34c0..e8f1f7ed 100644 --- a/EDSEditorGUI/DeviceODView.cs +++ b/EDSEditorGUI/DeviceODView.cs @@ -132,7 +132,7 @@ private bool Checkdirty() if (button_saveChanges.BackColor == Color.Red) { - var answer = MessageBox.Show(String.Format("Unsaved changes on Index 0x{0:X4}/{1:X2}.\nDo you wish to switch object and loose your changes?", lastSelectedObject.Index, lastSelectedObject.Subindex), "Unsaved changes", MessageBoxButtons.YesNoCancel); + var answer = MessageBox.Show(String.Format("Unsaved changes on Index 0x{0:X4}/{1:X2}.\nDo you wish to switch object and loose your changes?\n\nYes = Lose changes\nNo = Save\nCancel = Go back and stay on the object", lastSelectedObject.Index, lastSelectedObject.Subindex), "Unsaved changes", MessageBoxButtons.YesNoCancel); switch (answer) { case DialogResult.Cancel: From 813788a66d77c5bdd909cd188fa000a16b35bfc1 Mon Sep 17 00:00:00 2001 From: Ueli Niederer Date: Thu, 15 Dec 2022 12:03:44 +0100 Subject: [PATCH 3/7] Add autosave option --- EDSEditorGUI/DeviceODView.Designer.cs | 18 +++++++++++++++--- EDSEditorGUI/DeviceODView.cs | 27 +++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/EDSEditorGUI/DeviceODView.Designer.cs b/EDSEditorGUI/DeviceODView.Designer.cs index 927dd188..40363c1f 100644 --- a/EDSEditorGUI/DeviceODView.Designer.cs +++ b/EDSEditorGUI/DeviceODView.Designer.cs @@ -61,6 +61,7 @@ private void InitializeComponent() this.label23 = new System.Windows.Forms.Label(); this.textBox_index = new System.Windows.Forms.TextBox(); this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.checkBox_autosave = new System.Windows.Forms.CheckBox(); this.textBox_stringLengthMin = new System.Windows.Forms.TextBox(); this.label22 = new System.Windows.Forms.Label(); this.label20 = new System.Windows.Forms.Label(); @@ -464,6 +465,7 @@ private void InitializeComponent() // // groupBox1 // + this.groupBox1.Controls.Add(this.checkBox_autosave); this.groupBox1.Controls.Add(this.textBox_stringLengthMin); this.groupBox1.Controls.Add(this.label22); this.groupBox1.Controls.Add(this.label20); @@ -495,14 +497,23 @@ private void InitializeComponent() this.groupBox1.Controls.Add(this.comboBox_accessPDO); this.groupBox1.Dock = System.Windows.Forms.DockStyle.Bottom; this.groupBox1.Location = new System.Drawing.Point(0, 328); - this.groupBox1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.groupBox1.Margin = new System.Windows.Forms.Padding(2); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.groupBox1.Padding = new System.Windows.Forms.Padding(2); this.groupBox1.Size = new System.Drawing.Size(853, 188); this.groupBox1.TabIndex = 33; this.groupBox1.TabStop = false; this.groupBox1.Text = "Object settings"; // + // checkBox_autosave + // + this.checkBox_autosave.Location = new System.Drawing.Point(702, 148); + this.checkBox_autosave.Name = "checkBox_autosave"; + this.checkBox_autosave.Size = new System.Drawing.Size(139, 17); + this.checkBox_autosave.TabIndex = 35; + this.checkBox_autosave.Text = "Save changes on leave"; + this.checkBox_autosave.UseVisualStyleBackColor = true; + // // textBox_stringLengthMin // this.textBox_stringLengthMin.Location = new System.Drawing.Point(340, 99); @@ -1036,6 +1047,7 @@ private void InitializeComponent() private System.Windows.Forms.TextBox textBox_stringLengthMin; private System.Windows.Forms.TextBox textBox_subIndex; private System.Windows.Forms.Label label23; - private System.Windows.Forms.ToolStripMenuItem addToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem addToolStripMenuItem; + private System.Windows.Forms.CheckBox checkBox_autosave; } } diff --git a/EDSEditorGUI/DeviceODView.cs b/EDSEditorGUI/DeviceODView.cs index e8f1f7ed..f0594101 100644 --- a/EDSEditorGUI/DeviceODView.cs +++ b/EDSEditorGUI/DeviceODView.cs @@ -25,6 +25,7 @@ You should have received a copy of the GNU General Public License using System.Reflection; using System.Text.RegularExpressions; using libEDSsharp; + namespace ODEditor { @@ -132,7 +133,10 @@ private bool Checkdirty() if (button_saveChanges.BackColor == Color.Red) { - var answer = MessageBox.Show(String.Format("Unsaved changes on Index 0x{0:X4}/{1:X2}.\nDo you wish to switch object and loose your changes?\n\nYes = Lose changes\nNo = Save\nCancel = Go back and stay on the object", lastSelectedObject.Index, lastSelectedObject.Subindex), "Unsaved changes", MessageBoxButtons.YesNoCancel); + var answer = checkBox_autosave.Checked + ? DialogResult.No + : MessageBox.Show(String.Format("Unsaved changes on Index 0x{0:X4}/{1:X2}.\nDo you wish to switch object and loose your changes?\n\nYes = Lose changes\nNo = Save\nCancel = Go back and stay on the object", lastSelectedObject.Index, lastSelectedObject.Subindex), "Unsaved changes", MessageBoxButtons.YesNoCancel); ; + switch (answer) { case DialogResult.Cancel: @@ -629,7 +633,8 @@ private void ListView_subObjects_MouseClick(object sender, MouseEventArgs e) contextMenu_subObject_removeSubItemToolStripMenuItem.Enabled = od.Subindex > 0 && od.parent != null; contextMenu_subObject_removeSubItemLeaveGapToolStripMenuItem.Enabled = parent.objecttype == ObjectType.RECORD && od.Subindex > 0 && od.parent != null; - if (listView_subObjects.FocusedItem.Bounds.Contains(e.Location) == true) + + if (isClickOnItem(e.Location)) { contextMenu_subObject.Show(Cursor.Position); } @@ -640,6 +645,24 @@ private void ListView_subObjects_MouseClick(object sender, MouseEventArgs e) } } + private bool isClickOnItem(Point location) + { + if (listView_subObjects.FocusedItem != null) + { + return listView_subObjects.FocusedItem.Bounds.Contains(location); + } + + foreach (ListViewItem item in listView_subObjects.Items) + { + if (item.Bounds.Contains(location)) + { + return true; + } + } + + return false; + } + private void ListView_subObjects_SelectedIndexChanged(object sender, EventArgs e) { ListView_subObjects_MouseClick(sender, new MouseEventArgs(MouseButtons.None, 0, 0, 0, 0)); From ba45e03ccac2f7289eff971290ca3766687dc40e Mon Sep 17 00:00:00 2001 From: trojanobelix Date: Sun, 1 Dec 2024 13:09:31 +0100 Subject: [PATCH 4/7] Add/extend some exception catches to provide more information what was wrong Show filename on MouseHover in TabControl --- EDSEditorGUI/Form1.Designer.cs | 5 ++- EDSEditorGUI/Form1.cs | 67 +++++++++++++++++++++++++--------- EDSEditorGUI/Form1.resx | 2 +- libEDSsharp/CanOpenEDS.cs | 9 ++++- libEDSsharp/CanOpenXDD_1_1.cs | 10 ++++- 5 files changed, 70 insertions(+), 23 deletions(-) diff --git a/EDSEditorGUI/Form1.Designer.cs b/EDSEditorGUI/Form1.Designer.cs index 6ef5774d..7f1e72f2 100644 --- a/EDSEditorGUI/Form1.Designer.cs +++ b/EDSEditorGUI/Form1.Designer.cs @@ -290,17 +290,20 @@ private void InitializeComponent() this.tabControl1.Multiline = true; this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; + this.tabControl1.ShowToolTips = true; 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); + this.tabControl1.ControlRemoved += new System.Windows.Forms.ControlEventHandler(this.tabControl1_ControlsChanged); this.tabControl1.DragDrop += new System.Windows.Forms.DragEventHandler(this.ODEditor_MainForm_DragDrop); this.tabControl1.DragEnter += new System.Windows.Forms.DragEventHandler(this.ODEditor_MainForm_DragEnter); this.tabControl1.DragOver += new System.Windows.Forms.DragEventHandler(this.ODEditor_MainForm_DragOver); this.tabControl1.DragLeave += new System.EventHandler(this.ODEditor_MainForm_DragLeave); this.tabControl1.QueryContinueDrag += new System.Windows.Forms.QueryContinueDragEventHandler(this.ODEditor_MainForm_QueryContinueDrag); + this.tabControl1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.tabControl1_MouseClick); + this.tabControl1.MouseHover += new System.EventHandler(this.tabControl1_MouseHover); // // ODEditor_MainForm // diff --git a/EDSEditorGUI/Form1.cs b/EDSEditorGUI/Form1.cs index 1e9d0ca9..c168eb7e 100644 --- a/EDSEditorGUI/Form1.cs +++ b/EDSEditorGUI/Form1.cs @@ -26,7 +26,9 @@ You should have received a copy of the GNU General Public License using System.Windows.Forms; using System.IO; using libEDSsharp; -using static System.Windows.Forms.VisualStyles.VisualStyleElement; +//using static System.Windows.Forms.VisualStyles.VisualStyleElement; +//using SourceGrid.Cells.Controllers; +//using ToolTip = System.Windows.Forms.ToolTip; namespace ODEditor { @@ -189,6 +191,12 @@ private void openEDSfile(string path,InfoSection.Filetype ft) { EDSsharp eds = new EDSsharp(); + if (!File.Exists(path)) + { + MessageBox.Show("File " +path + "\ndoes not exist."); + return; + } + eds.Loadfile(path); DeviceView device = new DeviceView(eds, network); @@ -327,6 +335,11 @@ private void openToolStripMenuItem_Click(object sender, EventArgs e) private void openXDDfile(string path) { + if (!File.Exists(path)) + { + MessageBox.Show("File " + path + "\ndoes not exist."); + return; + } try { EDSsharp eds; @@ -449,13 +462,13 @@ private void Eds_onDataDirty(bool dirty, EDSsharp sender) { foreach(Control c in page.Controls) { - if(c.GetType() == typeof(DeviceView)) + if (c.GetType() == typeof(DeviceView)) { DeviceView d = (DeviceView)c; if (d.eds.Dirty == true) { page.BackColor = Color.Tomato; - } + } else { page.BackColor = default(Color); @@ -1329,34 +1342,52 @@ private void preferencesToolStripMenuItem_Click(object sender, EventArgs e) private void tabControl1_MouseClick(object sender, MouseEventArgs e) { - TabPage tp; if (e.Button == MouseButtons.Right) { for (int i = 0; i <= tabControl1.TabCount - 1; i++) { if (tabControl1.GetTabRect(i).Contains(e.Location)) { - tp = tabControl1.TabPages[i]; - DialogResult dialogResult = MessageBox.Show(tabControl1.TabPages[i].Text, "Close file?", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { - - DeviceView device = (DeviceView)tabControl1.TabPages[i].Controls[0]; - - if (device.eds.Dirty == true) - { - if (MessageBox.Show("All unsaved changes will be lost\n continue?", "Unsaved changes", MessageBoxButtons.YesNo) == DialogResult.No) - return; - } - - network.Remove(device.eds); - - tabControl1.TabPages.Remove(tabControl1.TabPages[i]); + DeviceView device = (DeviceView)tabControl1.TabPages[i].Controls[0]; + if (device.eds.Dirty == true) + { + if (MessageBox.Show("All unsaved changes will be lost\n continue?", "Unsaved changes", MessageBoxButtons.YesNo) == DialogResult.No) + return; + } + network.Remove(device.eds); + tabControl1.TabPages.Remove(tabControl1.TabPages[i]); } } } } } + private void tabControl1_MouseHover(object sender, EventArgs e) + { + + TabControl tabControl = sender as TabControl; + Point mousePosition = tabControl.PointToClient(Cursor.Position); + for (int i = 0; i < tabControl.TabCount; i++) + { + Rectangle tabRect = tabControl.GetTabRect(i); + if (tabRect.Contains(mousePosition)) + { + ToolTip toolTip = new ToolTip(); + // Set up the delays for the ToolTip. + + toolTip.AutoPopDelay = 5000; + toolTip.InitialDelay = 1000; + toolTip.ReshowDelay = 500; + // Force the ToolTip text to be displayed whether or not the form is active. + toolTip.ShowAlways = true; + DeviceView device = (DeviceView)tabControl1.TabPages[i].Controls[0]; + toolTip.SetToolTip(tabControl, device.eds.projectFilename); + break; + } + } + } + } } diff --git a/EDSEditorGUI/Form1.resx b/EDSEditorGUI/Form1.resx index 29de9ad8..e9b79be8 100644 --- a/EDSEditorGUI/Form1.resx +++ b/EDSEditorGUI/Form1.resx @@ -130,7 +130,7 @@ gqUTTxJHNd2gfCHts8Z5i7NeLLN6n/yF4ayxvMR1qkHEsYBFyBChoowNFOEgRrtBio0knUst/AOeXyaX Sq4NMHLMowQdiucH/4Pfs7VzE+N+UlgC2l9c92MYCO0CtYrrfh+7bu0ECD4DV0bDX6oC05+kVxpa9Ajo 2QYurhuaugdc7gD9T6ZiKZ4UpBJyOeD9jL4pA/TeAp2r/tzq5zh9AFI0q8QNcHAIjOQpe63Fuzua5/bn - HW9+kH4AMgFyjcd8GS4AAAAJcEhZcwAACw4AAAsOAUC+4UEAAAAHdElNRQfkCwILIglO4xvLAAAAD3RF + HW9+kH4AMgFyjcd8GS4AAAAJcEhZcwAACwwAAAsMAT9AIsgAAAAHdElNRQfkCwILIglO4xvLAAAAD3RF WHRDb21tZW50AENBTm9wZW7cllV1AAAC8UlEQVRYR9WWz2sTQRTHkx6SQy5RxFv1JDGHogiVIkqFEqLE QigetKY3iSUpPYh/gD8uoQiJIEKJ0UNNRZKjTaQiHozePAk21eagCC20NdW1plTa8X3f7mw3cZNuzSr6 hQ+8zn6/M29nZts6/hWdIu4T4xZJE2cJ23QvGAyKRCJhCXgp80CN2qNxTAyVP5QZZVXhn6H5mRlGCl5k diff --git a/libEDSsharp/CanOpenEDS.cs b/libEDSsharp/CanOpenEDS.cs index d4be60f6..ffdaae09 100644 --- a/libEDSsharp/CanOpenEDS.cs +++ b/libEDSsharp/CanOpenEDS.cs @@ -825,8 +825,13 @@ public void Loadfile(string filename) int lineno = 1; foreach (string linex in System.IO.File.ReadLines(filename)) { - Parseline(linex, lineno); - lineno++; + try + { + Parseline(linex, lineno); + lineno++; + } + catch (Exception) { Warnings.warning_list.Add("Failed to open file \n" + filename);} + } di = new DeviceInfo(eds["DeviceInfo"]); diff --git a/libEDSsharp/CanOpenXDD_1_1.cs b/libEDSsharp/CanOpenXDD_1_1.cs index 5c682027..91a7d659 100644 --- a/libEDSsharp/CanOpenXDD_1_1.cs +++ b/libEDSsharp/CanOpenXDD_1_1.cs @@ -100,8 +100,16 @@ public EDSsharp ReadXML(string file) dev = (ISO15745ProfileContainer)serializer.Deserialize(reader); reader.Close(); } - catch (Exception) + catch (Exception e) { + if (e is System.InvalidOperationException) + { + Warnings.warning_list.Add(String.Format("{0} {1} Action aborted!", e.Message, e.InnerException.Message)); + } + else + { + Warnings.warning_list.Add(String.Format("{0} Action aborted!", e.ToString())); + } return null; } From 5cb1bda209b0940aad1baf6257201b7ef008a45a Mon Sep 17 00:00:00 2001 From: trojanobelix Date: Tue, 14 Jan 2025 17:43:29 +0100 Subject: [PATCH 5/7] Unified header for Exporter legacy/V4 --- EDSEditorGUI/EDSEditorGUI.csproj | 10 ++++--- libEDSsharp/CanOpenNodeExporter.cs | 38 ++++++++++++--------------- libEDSsharp/CanOpenNodeExporter_V4.cs | 27 ++++++++++++++++++- 3 files changed, 50 insertions(+), 25 deletions(-) diff --git a/EDSEditorGUI/EDSEditorGUI.csproj b/EDSEditorGUI/EDSEditorGUI.csproj index 9dde5d88..642834ef 100644 --- a/EDSEditorGUI/EDSEditorGUI.csproj +++ b/EDSEditorGUI/EDSEditorGUI.csproj @@ -98,11 +98,15 @@ - - - + + + + + 8.0.11 + + git describe --tags --long --dirty > "$(MSBuildProjectDirectory)\version.txt" || exit 0 diff --git a/libEDSsharp/CanOpenNodeExporter.cs b/libEDSsharp/CanOpenNodeExporter.cs index df728b8d..78ea78d3 100644 --- a/libEDSsharp/CanOpenNodeExporter.cs +++ b/libEDSsharp/CanOpenNodeExporter.cs @@ -461,7 +461,22 @@ This file was automatically generated by CANopenEditor {0} https://github.com/CANopenNode/CANopenEditor DON'T EDIT THIS FILE MANUALLY !!!! -*******************************************************************************/", this.gitVersion)); +*******************************************************************************", this.gitVersion)); + file.WriteLine(" FILE INFO:"); + file.WriteLine(string.Format(" FileName: {0}", Path.GetFileName(eds.projectFilename))); + file.WriteLine(string.Format(" FileVersion: {0}", eds.fi.FileVersion)); + file.WriteLine(string.Format(" CreationTime: {0}", eds.fi.CreationTime)); + file.WriteLine(string.Format(" CreationDate: {0}", eds.fi.CreationDate)); + file.WriteLine(string.Format(" CreatedBy: {0}", eds.fi.CreatedBy)); + + file.WriteLine(""); + file.WriteLine(" DEVICE INFO:"); + file.WriteLine(string.Format(" VendorName: {0}", eds.di.VendorName)); + file.WriteLine(string.Format(" VendorNumber: {0}", eds.di.VendorNumber)); + file.WriteLine(string.Format(" ProductName: {0}", eds.di.ProductName)); + file.WriteLine(string.Format(" ProductNumber: {0}", eds.di.ProductNumber)); + file.WriteLine("*******************************************************************************/"); + file.WriteLine(""); } private void export_h(string filename) @@ -503,28 +518,9 @@ CANopen DATA TYPES "); - file.WriteLine("/*******************************************************************************"); - file.WriteLine(" FILE INFO:"); - file.WriteLine(string.Format(" FileName: {0}", Path.GetFileName(eds.projectFilename))); - file.WriteLine(string.Format(" FileVersion: {0}", eds.fi.FileVersion)); - file.WriteLine(string.Format(" CreationTime: {0}", eds.fi.CreationTime)); - file.WriteLine(string.Format(" CreationDate: {0}", eds.fi.CreationDate)); - file.WriteLine(string.Format(" CreatedBy: {0}", eds.fi.CreatedBy)); - file.WriteLine("*******************************************************************************/"); - file.WriteLine(""); - file.WriteLine(""); - file.WriteLine("/*******************************************************************************"); - file.WriteLine(" DEVICE INFO:"); - file.WriteLine(string.Format(" VendorName: {0}", eds.di.VendorName)); - file.WriteLine(string.Format(" VendorNumber: {0}", eds.di.VendorNumber)); - file.WriteLine(string.Format(" ProductName: {0}", eds.di.ProductName)); - file.WriteLine(string.Format(" ProductNumber: {0}", eds.di.ProductNumber)); - file.WriteLine("*******************************************************************************/"); - file.WriteLine(""); - file.WriteLine(""); - file.WriteLine(@"/******************************************************************************* +file.WriteLine(@"/******************************************************************************* FEATURES *******************************************************************************/"); diff --git a/libEDSsharp/CanOpenNodeExporter_V4.cs b/libEDSsharp/CanOpenNodeExporter_V4.cs index 786bb9c1..4b52984f 100644 --- a/libEDSsharp/CanOpenNodeExporter_V4.cs +++ b/libEDSsharp/CanOpenNodeExporter_V4.cs @@ -602,8 +602,33 @@ This file was automatically generated by CANopenEditor {0} https://github.com/CANopenNode/CANopenEditor DON'T EDIT THIS FILE MANUALLY, UNLESS YOU KNOW WHAT YOU ARE DOING !!!! -*******************************************************************************/ +******************************************************************************* + + File info: + File Names: {1}.h; {1}.c + Project File: {2} + File Version: {3} + + Created: {4} + Created By: {5} + Modified: {6} + Modified By: {7} + + Device Info: + Vendor Name: {8} + Vendor ID: {9} + Product Name: {10} + Product ID: {11} + Description: {12} +*******************************************************************************/", + gitVersion, odname, + Path.GetFileName(eds.projectFilename), eds.fi.FileVersion, + eds.fi.CreationDateTime, eds.fi.CreatedBy, eds.fi.ModificationDateTime, eds.fi.ModifiedBy, + eds.di.VendorName, eds.di.VendorNumber, eds.di.ProductName, eds.di.ProductNumber, + eds.fi.Description)); + + file.WriteLine(string.Format(@" #define OD_DEFINITION #include ""301/CO_ODinterface.h"" #include ""{1}.h"" From b995b396894e3191d9b794d3c49d7cb0d5fbff84 Mon Sep 17 00:00:00 2001 From: trojanobelix Date: Mon, 10 Mar 2025 16:13:48 +0100 Subject: [PATCH 6/7] Update EDSEditorGUI/Form1.cs Co-authored-by: Lars Elgtvedt Susaas --- EDSEditorGUI/Form1.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EDSEditorGUI/Form1.cs b/EDSEditorGUI/Form1.cs index c168eb7e..8f017f84 100644 --- a/EDSEditorGUI/Form1.cs +++ b/EDSEditorGUI/Form1.cs @@ -468,7 +468,7 @@ private void Eds_onDataDirty(bool dirty, EDSsharp sender) if (d.eds.Dirty == true) { page.BackColor = Color.Tomato; - } + } else { page.BackColor = default(Color); From 760a177ac245737aa4f116437cafd25cedc90ec5 Mon Sep 17 00:00:00 2001 From: trojanobelix Date: Mon, 10 Mar 2025 16:14:02 +0100 Subject: [PATCH 7/7] Update EDSEditorGUI/Form1.cs Co-authored-by: Lars Elgtvedt Susaas --- EDSEditorGUI/Form1.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EDSEditorGUI/Form1.cs b/EDSEditorGUI/Form1.cs index 8f017f84..16f743b4 100644 --- a/EDSEditorGUI/Form1.cs +++ b/EDSEditorGUI/Form1.cs @@ -462,7 +462,7 @@ private void Eds_onDataDirty(bool dirty, EDSsharp sender) { foreach(Control c in page.Controls) { - if (c.GetType() == typeof(DeviceView)) + if(c.GetType() == typeof(DeviceView)) { DeviceView d = (DeviceView)c; if (d.eds.Dirty == true)