Skip to content

Commit 64a0dc0

Browse files
authored
Merge pull request #142 from trojanobelix/prDefault
Set defaut value to all subs with empty default values
2 parents 07966bd + 597b2cb commit 64a0dc0

File tree

3 files changed

+88
-9
lines changed

3 files changed

+88
-9
lines changed

EDSEditorGUI/DeviceODView.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,50 @@ private void ObjectSave()
532532
od.prop.CO_accessSRDO = AccessSRDO.no;
533533
}
534534

535-
od.defaultvalue = textBox_defaultValue.Text;
535+
// Default value
536+
if (listView_subObjects.SelectedItems.Count > 1) {
537+
for (ushort i = 0; i < listView_subObjects.SelectedItems.Count; i++)
538+
{
539+
od.parent.subobjects[(ushort) Convert.ToInt32(listView_subObjects.SelectedItems[i].Text,16)].defaultvalue = textBox_defaultValue.Text;
540+
}
541+
}
542+
543+
544+
bool setDefaultValueToAll = false;
545+
bool identicalDefaultValues = true;
546+
string lastdefaultvalue;
547+
if (od.parent != null && od.parent.Nosubindexes > 2)
548+
{
549+
lastdefaultvalue = od.parent.subobjects[1].defaultvalue;
550+
foreach (ODentry subod in od.parent.subobjects.Values)
551+
{
552+
if (subod.Subindex > 0)
553+
{
554+
identicalDefaultValues &= (subod.defaultvalue == lastdefaultvalue)&& (subod.defaultvalue != textBox_defaultValue.Text);
555+
lastdefaultvalue = subod.defaultvalue;
556+
}
557+
}
558+
559+
if (identicalDefaultValues) {
560+
DialogResult confirm = MessageBox.Show("Do you want to set all identical default values in subobjects to this default value?", "Set to all?", MessageBoxButtons.YesNo);
561+
if (confirm == DialogResult.Yes)
562+
{
563+
setDefaultValueToAll = true;
564+
}
565+
}
566+
}
567+
if (setDefaultValueToAll)
568+
{
569+
for (ushort i = 1; i < od.parent.Nosubindexes; i++)
570+
{
571+
od.parent.subobjects[i].defaultvalue = textBox_defaultValue.Text;
572+
}
573+
}
574+
else
575+
{
576+
od.defaultvalue = textBox_defaultValue.Text;
577+
}
578+
536579
od.actualvalue = textBox_actualValue.Text;
537580
od.HighLimit = textBox_highLimit.Text;
538581
od.LowLimit = textBox_lowLimit.Text;

EDSEditorGUI/DevicePDOView2.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,12 @@ public void UpdatePDOinfo(bool updatechoices = true)
460460
int ordinal = 0;
461461
foreach (ODentry entry in slot.Mapping)
462462
{
463+
if ((bitoff + entry.Sizeofdatatype()) > 64)
463464
{
465+
string toDisplay = string.Join(Environment.NewLine, slot.Mapping);
466+
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));
467+
break;
468+
}
464469
string target = slot.getTargetName(entry);
465470
grid1[row + 2, bitoff + 3] = new SourceGrid.Cells.Cell(target, comboStandard);
466471
grid1[row + 2, bitoff + 3].ColumnSpan = entry.Sizeofdatatype();
@@ -480,14 +485,9 @@ public void UpdatePDOinfo(bool updatechoices = true)
480485

481486
grid1[row + 2, bitoff + 3].AddController(vcc);
482487
bitoff += entry.Sizeofdatatype();
483-
}
484488

485-
ordinal++;
486489

487-
if (bitoff > 64) {
488-
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));
489-
break;
490-
}
490+
ordinal++;
491491

492492
}
493493

EDSEditorGUI/Form1.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ private void openEDSfile(string path,InfoSection.Filetype ft)
218218

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

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

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

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

767+
addtoMRU(filepath);
768+
765769
}
766770

767771
private void ODEditor_MainForm_FormClosed(object sender, FormClosedEventArgs e)
@@ -816,8 +820,8 @@ private void addtoMRU(string path)
816820

817821
_mru.Insert(0, path);
818822

819-
if (_mru.Count > 10)
820-
_mru.RemoveAt(10);
823+
if (_mru.Count > 20)
824+
_mru.RemoveAt(20);
821825

822826
populateMRU();
823827

@@ -1322,5 +1326,37 @@ private void preferencesToolStripMenuItem_Click(object sender, EventArgs e)
13221326
Preferences p = new Preferences();
13231327
p.ShowDialog();
13241328
}
1329+
1330+
private void tabControl1_MouseClick(object sender, MouseEventArgs e)
1331+
{
1332+
TabPage tp;
1333+
if (e.Button == MouseButtons.Right)
1334+
{
1335+
for (int i = 0; i <= tabControl1.TabCount - 1; i++)
1336+
{
1337+
if (tabControl1.GetTabRect(i).Contains(e.Location))
1338+
{
1339+
tp = tabControl1.TabPages[i];
1340+
1341+
DialogResult dialogResult = MessageBox.Show(tabControl1.TabPages[i].Text, "Close file?", MessageBoxButtons.YesNo);
1342+
if (dialogResult == DialogResult.Yes)
1343+
{
1344+
1345+
DeviceView device = (DeviceView)tabControl1.TabPages[i].Controls[0];
1346+
1347+
if (device.eds.Dirty == true)
1348+
{
1349+
if (MessageBox.Show("All unsaved changes will be lost\n continue?", "Unsaved changes", MessageBoxButtons.YesNo) == DialogResult.No)
1350+
return;
1351+
}
1352+
1353+
network.Remove(device.eds);
1354+
1355+
tabControl1.TabPages.Remove(tabControl1.TabPages[i]);
1356+
}
1357+
}
1358+
}
1359+
}
1360+
}
13251361
}
13261362
}

0 commit comments

Comments
 (0)