Skip to content

Commit 8787216

Browse files
committed
Refactor Rhs2116 design files
- Utilize the main library classes directly instead of passing individual properties to the design library
1 parent faf6ea1 commit 8787216

File tree

6 files changed

+44
-44
lines changed

6 files changed

+44
-44
lines changed

OpenEphys.Onix1.Design/HeadstageRhs2116Dialog.Designer.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

OpenEphys.Onix1.Design/HeadstageRhs2116Dialog.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,16 @@ public partial class HeadstageRhs2116Dialog : Form
1515
internal readonly Rhs2116StimulusSequenceDialog StimulusSequenceDialog;
1616
internal readonly GenericDeviceDialog Rhs2116Dialog;
1717

18-
internal Rhs2116ProbeGroup ProbeGroup;
19-
2018
/// <summary>
2119
/// Initializes a new instance of a <see cref="HeadstageRhs2116Dialog"/>.
2220
/// </summary>
23-
/// <param name="probeGroup">Current channel configuration settings for a <see cref="Rhs2116ProbeGroup"/>.</param>
24-
/// <param name="sequence">Current stimulus sequence for a <see cref="Rhs2116StimulusSequencePair"/>.</param>
21+
/// <param name="rhs2116Trigger">Current configuration settings for <see cref="ConfigureRhs2116Trigger"/>.</param>
2522
/// <param name="rhs2116">Current configuration settings for a single <see cref="ConfigureRhs2116"/>.</param>
26-
public HeadstageRhs2116Dialog(Rhs2116ProbeGroup probeGroup, Rhs2116StimulusSequencePair sequence,
27-
ConfigureRhs2116Pair rhs2116)
23+
public HeadstageRhs2116Dialog(ConfigureRhs2116Trigger rhs2116Trigger, ConfigureRhs2116Pair rhs2116)
2824
{
2925
InitializeComponent();
3026

31-
ProbeGroup = new Rhs2116ProbeGroup(probeGroup);
32-
33-
StimulusSequenceDialog = new Rhs2116StimulusSequenceDialog(sequence, ProbeGroup);
27+
StimulusSequenceDialog = new Rhs2116StimulusSequenceDialog(rhs2116Trigger);
3428

3529
StimulusSequenceDialog.SetChildFormProperties(this).AddDialogToTab(tabPageStimulusSequence);
3630
this.AddMenuItemsFromDialogToFileOption(StimulusSequenceDialog);

OpenEphys.Onix1.Design/HeadstageRhs2116Editor.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ public override bool EditComponent(ITypeDescriptorContext context, object compon
1818
var editorState = (IWorkflowEditorState)provider.GetService(typeof(IWorkflowEditorState));
1919
if (editorState != null && !editorState.WorkflowRunning && component is ConfigureHeadstageRhs2116 configureNode)
2020
{
21-
using var editorDialog = new HeadstageRhs2116Dialog(configureNode.StimulusTrigger.ProbeGroup,
22-
configureNode.StimulusTrigger.StimulusSequence, configureNode.Rhs2116Pair);
21+
using var editorDialog = new HeadstageRhs2116Dialog(configureNode.StimulusTrigger, configureNode.Rhs2116Pair);
2322

2423
if (editorDialog.ShowDialog() == DialogResult.OK)
2524
{
26-
configureNode.StimulusTrigger.StimulusSequence = editorDialog.StimulusSequenceDialog.Sequence;
27-
configureNode.StimulusTrigger.ProbeGroup = (Rhs2116ProbeGroup)editorDialog.StimulusSequenceDialog.ChannelDialog.ProbeGroup;
25+
configureNode.StimulusTrigger = editorDialog.StimulusSequenceDialog.Trigger;
2826
DesignHelper.CopyProperties((ConfigureRhs2116Pair)editorDialog.Rhs2116Dialog.Device, configureNode.Rhs2116Pair, DesignHelper.PropertiesToIgnore);
2927

3028
return true;

OpenEphys.Onix1.Design/Rhs2116StimulusSequenceDialog.cs

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ public partial class Rhs2116StimulusSequenceDialog : GenericStimulusSequenceDial
1515
const double SamplePeriodMilliSeconds = 1e3 / Rhs2116.SampleFrequencyHz;
1616
const int NumberOfChannels = 32;
1717

18-
internal Rhs2116StimulusSequencePair Sequence { get; set; }
18+
internal Rhs2116StimulusSequencePair Sequence { get => Trigger.StimulusSequence; }
19+
20+
internal ConfigureRhs2116Trigger Trigger { get; set; }
1921

2022
readonly Rhs2116StimulusSequencePair SequenceCopy = new();
2123

@@ -35,19 +37,18 @@ public partial class Rhs2116StimulusSequenceDialog : GenericStimulusSequenceDial
3537
/// Opens a dialog allowing for easy changing of stimulus sequence parameters, with
3638
/// visual feedback on what the resulting stimulus sequence looks like.
3739
/// </summary>
38-
/// <param name="sequence">Stimulus sequence containing 32 channels of stimuli.</param>
39-
/// <param name="probeGroup">Probe group containing ProbeInterface specifications for 32 contacts.</param>
40-
public Rhs2116StimulusSequenceDialog(Rhs2116StimulusSequencePair sequence, Rhs2116ProbeGroup probeGroup)
40+
/// <param name="rhs2116Trigger">Existing <see cref="ConfigureRhs2116Trigger"/> object.</param>
41+
public Rhs2116StimulusSequenceDialog(ConfigureRhs2116Trigger rhs2116Trigger)
4142
: base(NumberOfChannels, true, true)
4243
{
43-
if (probeGroup.NumberOfContacts != NumberOfChannels)
44+
if (rhs2116Trigger.ProbeGroup.NumberOfContacts != NumberOfChannels)
4445
{
45-
throw new ArgumentException($"Probe group is not valid: {NumberOfChannels} channels were expected, there are {probeGroup.NumberOfContacts} instead.");
46+
throw new ArgumentException($"Probe group is not valid: {NumberOfChannels} channels were expected, there are {rhs2116Trigger.ProbeGroup.NumberOfContacts} instead.");
4647
}
4748

4849
InitializeComponent();
4950

50-
Sequence = new Rhs2116StimulusSequencePair(sequence);
51+
Trigger = new(rhs2116Trigger);
5152

5253
dataGridViewStimulusTable.DataBindingComplete += DataBindingComplete;
5354
SetTableDataSource();
@@ -63,7 +64,7 @@ public Rhs2116StimulusSequenceDialog(Rhs2116StimulusSequencePair sequence, Rhs21
6364

6465
StepSize = Sequence.CurrentStepSize;
6566

66-
ChannelDialog = new(probeGroup);
67+
ChannelDialog = new(rhs2116Trigger.ProbeGroup);
6768

6869
ChannelDialog.SetChildFormProperties(this).AddDialogToPanel(panelProbe);
6970
this.AddMenuItemsFromDialogToFileOption(ChannelDialog, "Channel Configuration");
@@ -278,11 +279,6 @@ internal override PointPairList[] CreateStimulusWaveforms()
278279

279280
internal override void SetStatusValidity()
280281
{
281-
if (Sequence == null)
282-
{
283-
return;
284-
}
285-
286282
if (Sequence.Valid && Sequence.FitsInHardware)
287283
{
288284
toolStripStatusIsValid.Image = Properties.Resources.StatusReadyImage;
@@ -919,16 +915,16 @@ internal override void SerializeStimulusSequence(string fileName)
919915

920916
internal override bool IsSequenceValid()
921917
{
922-
return Sequence.Valid;
918+
return Sequence.Valid && Sequence.FitsInHardware;
923919
}
924920

925921
internal override void DeserializeStimulusSequence(string fileName)
926922
{
927-
var sequence = DesignHelper.DeserializeString<Rhs2116StimulusSequencePair>(File.ReadAllText(fileName));
923+
var newSequence = DesignHelper.DeserializeString<Rhs2116StimulusSequencePair>(File.ReadAllText(fileName));
928924

929-
if (sequence != null && sequence.Stimuli.Length == 32)
925+
if (newSequence != null && newSequence.Stimuli.Length == 32)
930926
{
931-
if (sequence == new Rhs2116StimulusSequencePair())
927+
if (newSequence == new Rhs2116StimulusSequencePair())
932928
{
933929
var result = MessageBox.Show("The stimulus sequence loaded does not have any configuration settings applied. " +
934930
"This could be because the file did not have the correct format. If this sequence is loaded, it will clear out " +
@@ -940,15 +936,15 @@ internal override void DeserializeStimulusSequence(string fileName)
940936
}
941937
}
942938

943-
Sequence = sequence;
939+
Trigger.StimulusSequence = newSequence;
944940

945-
for (int i = 0; i < Sequence.Stimuli.Length; i++)
941+
for (int i = 0; i < newSequence.Stimuli.Length; i++)
946942
{
947-
RequestedAnodicAmplitudeuA[i] = Sequence.Stimuli[i].AnodicAmplitudeSteps * Sequence.CurrentStepSizeuA;
948-
RequestedCathodicAmplitudeuA[i] = Sequence.Stimuli[i].CathodicAmplitudeSteps * Sequence.CurrentStepSizeuA;
943+
RequestedAnodicAmplitudeuA[i] = newSequence.Stimuli[i].AnodicAmplitudeSteps * newSequence.CurrentStepSizeuA;
944+
RequestedCathodicAmplitudeuA[i] = newSequence.Stimuli[i].CathodicAmplitudeSteps * newSequence.CurrentStepSizeuA;
949945
}
950946

951-
if (!Sequence.Valid)
947+
if (!newSequence.Valid)
952948
{
953949
MessageBox.Show("Warning: Invalid stimuli found in the recently opened file. Check all values to ensure they are what is expected.",
954950
"Invalid Stimuli", MessageBoxButtons.OK, MessageBoxIcon.Error);
@@ -962,10 +958,7 @@ internal override void DeserializeStimulusSequence(string fileName)
962958

963959
internal override void SetTableDataSource()
964960
{
965-
if (Sequence == null)
966-
return;
967-
968-
dataGridViewStimulusTable.DataSource = Sequence.Stimuli;
961+
dataGridViewStimulusTable.DataSource = Trigger?.StimulusSequence.Stimuli;
969962
}
970963

971964
private void DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)

OpenEphys.Onix1.Design/Rhs2116StimulusSequenceEditor.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ public override bool EditComponent(ITypeDescriptorContext context, object compon
1818
var editorState = (IWorkflowEditorState)provider.GetService(typeof(IWorkflowEditorState));
1919
if (editorState != null && !editorState.WorkflowRunning && component is ConfigureRhs2116Trigger configureNode)
2020
{
21-
using var editorDialog = new Rhs2116StimulusSequenceDialog(configureNode.StimulusSequence, configureNode.ProbeGroup);
21+
using var editorDialog = new Rhs2116StimulusSequenceDialog(configureNode);
2222

2323
if (editorDialog.ShowDialog() == DialogResult.OK)
2424
{
25-
configureNode.StimulusSequence = editorDialog.Sequence;
26-
configureNode.ProbeGroup = (Rhs2116ProbeGroup)editorDialog.ChannelDialog.ProbeGroup;
25+
DesignHelper.CopyProperties(editorDialog.Trigger, configureNode);
2726

2827
return true;
2928
}

OpenEphys.Onix1/ConfigureRhs2116Trigger.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@ public ConfigureRhs2116Trigger()
3333
{
3434
}
3535

36+
/// <summary>
37+
/// Copy constructor for the <see cref="ConfigureRhs2116Trigger"/> class.
38+
/// </summary>
39+
/// <param name="rhs2116Trigger">Existing <see cref="ConfigureRhs2116Trigger"/> object.</param>
40+
public ConfigureRhs2116Trigger(ConfigureRhs2116Trigger rhs2116Trigger)
41+
: this()
42+
{
43+
Enable = rhs2116Trigger.Enable;
44+
DeviceAddress = rhs2116Trigger.DeviceAddress;
45+
DeviceName = rhs2116Trigger.DeviceName;
46+
TriggerSource = rhs2116Trigger.TriggerSource;
47+
ProbeGroup = rhs2116Trigger.ProbeGroup;
48+
Armed = rhs2116Trigger.Armed;
49+
StimulusSequence = new(rhs2116Trigger.StimulusSequence);
50+
}
51+
3652
/// <summary>
3753
/// Gets or sets the device enable state.
3854
/// </summary>

0 commit comments

Comments
 (0)