Skip to content

Commit

Permalink
Merge pull request #142 from trojanobelix/prDefault
Browse files Browse the repository at this point in the history
Set defaut value to all subs with empty default values
  • Loading branch information
trojanobelix authored Nov 9, 2024
2 parents 07966bd + 597b2cb commit 64a0dc0
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 9 deletions.
45 changes: 44 additions & 1 deletion EDSEditorGUI/DeviceODView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,50 @@ private void ObjectSave()
od.prop.CO_accessSRDO = AccessSRDO.no;
}

od.defaultvalue = textBox_defaultValue.Text;
// Default value
if (listView_subObjects.SelectedItems.Count > 1) {
for (ushort i = 0; i < listView_subObjects.SelectedItems.Count; i++)
{
od.parent.subobjects[(ushort) Convert.ToInt32(listView_subObjects.SelectedItems[i].Text,16)].defaultvalue = textBox_defaultValue.Text;
}
}


bool setDefaultValueToAll = false;
bool identicalDefaultValues = true;
string lastdefaultvalue;
if (od.parent != null && od.parent.Nosubindexes > 2)
{
lastdefaultvalue = od.parent.subobjects[1].defaultvalue;
foreach (ODentry subod in od.parent.subobjects.Values)
{
if (subod.Subindex > 0)
{
identicalDefaultValues &= (subod.defaultvalue == lastdefaultvalue)&& (subod.defaultvalue != textBox_defaultValue.Text);
lastdefaultvalue = subod.defaultvalue;
}
}

if (identicalDefaultValues) {
DialogResult confirm = MessageBox.Show("Do you want to set all identical default values in subobjects to this default value?", "Set to all?", MessageBoxButtons.YesNo);
if (confirm == DialogResult.Yes)
{
setDefaultValueToAll = true;
}
}
}
if (setDefaultValueToAll)
{
for (ushort i = 1; i < od.parent.Nosubindexes; i++)
{
od.parent.subobjects[i].defaultvalue = textBox_defaultValue.Text;
}
}
else
{
od.defaultvalue = textBox_defaultValue.Text;
}

od.actualvalue = textBox_actualValue.Text;
od.HighLimit = textBox_highLimit.Text;
od.LowLimit = textBox_lowLimit.Text;
Expand Down
12 changes: 6 additions & 6 deletions EDSEditorGUI/DevicePDOView2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,12 @@ public void UpdatePDOinfo(bool updatechoices = true)
int ordinal = 0;
foreach (ODentry entry in slot.Mapping)
{
if ((bitoff + entry.Sizeofdatatype()) > 64)
{
string toDisplay = string.Join(Environment.NewLine, slot.Mapping);
MessageBox.Show(string.Format("Invalid TXPDO mapping parameters in 0x{0:X}!\r\nTrying to map more than the maximum lenght of a CAN message (8 bytes).\r\n\r\nMembers are:\r\n{1}", slot.ConfigurationIndex,toDisplay));
break;
}
string target = slot.getTargetName(entry);
grid1[row + 2, bitoff + 3] = new SourceGrid.Cells.Cell(target, comboStandard);
grid1[row + 2, bitoff + 3].ColumnSpan = entry.Sizeofdatatype();
Expand All @@ -480,14 +485,9 @@ public void UpdatePDOinfo(bool updatechoices = true)

grid1[row + 2, bitoff + 3].AddController(vcc);
bitoff += entry.Sizeofdatatype();
}

ordinal++;

if (bitoff > 64) {
MessageBox.Show(string.Format("Invalid TXPDO mapping parameters in 0x{0:X}. Trying to map more than 64 bit (8 Bytes). CAN message maximum lenght is 8 Byte", slot.ConfigurationIndex));
break;
}
ordinal++;

}

Expand Down
40 changes: 38 additions & 2 deletions EDSEditorGUI/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ private void openEDSfile(string path,InfoSection.Filetype ft)

private void exportCanOpenNode(DeviceView dv, string FileName, ExporterFactory.Exporter exporterType)
{
bool saveDirty = dv.eds.Dirty; // dispatch update will set it to dirty. Save and restore axtual dirty status
Warnings.warning_list.Clear();

IExporter exporter = ExporterFactory.getExporter(exporterType);
Expand All @@ -241,6 +242,7 @@ private void exportCanOpenNode(DeviceView dv, string FileName, ExporterFactory.E
}

dv.dispatch_updateOD();
dv.eds.Dirty = saveDirty; // dispatch update will set it to dirty. Restore saved dirty status
}

private void exportCanOpenNodeToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -762,6 +764,8 @@ void OpenRecentFile(object sender, EventArgs e)
if (ext == ".dcf")
openEDSfile(filepath, InfoSection.Filetype.File_DCF);

addtoMRU(filepath);

}

private void ODEditor_MainForm_FormClosed(object sender, FormClosedEventArgs e)
Expand Down Expand Up @@ -816,8 +820,8 @@ private void addtoMRU(string path)

_mru.Insert(0, path);

if (_mru.Count > 10)
_mru.RemoveAt(10);
if (_mru.Count > 20)
_mru.RemoveAt(20);

populateMRU();

Expand Down Expand Up @@ -1322,5 +1326,37 @@ private void preferencesToolStripMenuItem_Click(object sender, EventArgs e)
Preferences p = new Preferences();
p.ShowDialog();
}

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]);
}
}
}
}
}
}
}

0 comments on commit 64a0dc0

Please sign in to comment.