11using System ;
2+ using System . Collections . Generic ;
23using System . ComponentModel ;
34using System . Drawing ;
45using System . IO ;
@@ -70,6 +71,8 @@ public NeuropixelsV2ProbeConfiguration ProbeConfiguration
7071 get => ChannelConfiguration . ProbeConfiguration ;
7172 }
7273
74+ readonly Dictionary < NeuropixelsV2ProbeType , NeuropixelsV2ProbeConfiguration > probeConfigurations ;
75+
7376 /// <inheritdoc cref="ConfigureNeuropixelsV2e.InvertPolarity"/>
7477 public bool InvertPolarity { get ; set ; }
7578
@@ -87,7 +90,15 @@ public NeuropixelsV2eProbeConfigurationDialog(NeuropixelsV2ProbeConfiguration co
8790
8891 textBoxProbeCalibrationFile . Text = calibrationFile ;
8992
90- ChannelConfiguration = new ( configuration )
93+ probeConfigurations = new ( )
94+ {
95+ [ NeuropixelsV2ProbeType . SingleShank ] = new ( configuration . Probe , NeuropixelsV2ProbeType . SingleShank , configuration . Reference ) ,
96+ [ NeuropixelsV2ProbeType . QuadShank ] = new ( configuration . Probe , NeuropixelsV2ProbeType . QuadShank , configuration . Reference )
97+ } ;
98+
99+ probeConfigurations [ configuration . ProbeType ] . SelectElectrodes ( configuration . ChannelMap ) ;
100+
101+ ChannelConfiguration = new ( probeConfigurations [ configuration . ProbeType ] )
91102 {
92103 TopLevel = false ,
93104 FormBorderStyle = FormBorderStyle . None ,
@@ -111,21 +122,17 @@ public NeuropixelsV2eProbeConfigurationDialog(NeuropixelsV2ProbeConfiguration co
111122 else
112123 comboBoxProbeType . SelectedIndexChanged += SelectedProbeTypeChanged ;
113124
114- comboBoxReference . DataSource = NeuropixelsV2ProbeConfiguration . FilterNeuropixelsV2ShankReference ( ProbeConfiguration . ProbeType ) ;
115- comboBoxReference . SelectedItem = ProbeConfiguration . Reference ;
116- comboBoxReference . SelectedIndexChanged += SelectedReferenceChanged ;
117-
118125 comboBoxChannelPresets . DataSource = GetComboBoxChannelPresets ( ProbeConfiguration . ProbeType ) ;
119126 comboBoxChannelPresets . SelectedIndexChanged += SelectedChannelPresetChanged ;
120127
121128 checkBoxInvertPolarity . Checked = InvertPolarity ;
122129 checkBoxInvertPolarity . CheckedChanged += InvertPolarityIndexChanged ;
123130
124- CheckForExistingChannelPreset ( ) ;
125-
126131 CheckStatus ( ) ;
127132
128133 Text += ": " + ProbeConfiguration . Probe . ToString ( ) ;
134+
135+ UpdateProbeConfiguration ( ) ;
129136 }
130137
131138 static Array GetComboBoxChannelPresets ( NeuropixelsV2ProbeType probeType )
@@ -184,27 +191,30 @@ private void ResizeTrackBar(object sender, EventArgs e)
184191
185192 void UpdateProbeConfiguration ( )
186193 {
194+ var probeType = ( NeuropixelsV2ProbeType ) comboBoxProbeType . SelectedItem ;
195+
196+ ChannelConfiguration . ProbeConfiguration = probeConfigurations [ probeType ] ;
197+ ChannelConfiguration . ProbeGroup = ProbeConfiguration . ProbeGroup ;
198+
187199 ChannelConfiguration . DrawProbeGroup ( ) ;
188200 ChannelConfiguration . ResetZoom ( ) ;
189201 ChannelConfiguration . RefreshZedGraph ( ) ;
190202
191- comboBoxReference . DataSource = NeuropixelsV2ProbeConfiguration . FilterNeuropixelsV2ShankReference ( ProbeConfiguration . ProbeType ) ;
192-
193203 comboBoxChannelPresets . SelectedIndexChanged -= SelectedChannelPresetChanged ; // NB: Temporarily detach handler so the loaded electrode configuration is respected
194204 comboBoxChannelPresets . DataSource = GetComboBoxChannelPresets ( ProbeConfiguration . ProbeType ) ;
195205 comboBoxChannelPresets . SelectedIndexChanged += SelectedChannelPresetChanged ;
206+
207+ comboBoxReference . SelectedIndexChanged -= SelectedReferenceChanged ;
208+ comboBoxReference . DataSource = NeuropixelsV2ProbeConfiguration . FilterNeuropixelsV2ShankReference ( ProbeConfiguration . ProbeType ) ;
209+ comboBoxReference . SelectedItem = ProbeConfiguration . Reference ;
210+ comboBoxReference . SelectedIndexChanged += SelectedReferenceChanged ;
211+
212+ CheckForExistingChannelPreset ( ) ;
196213 }
197214
198215 void SelectedProbeTypeChanged ( object sender , EventArgs e )
199216 {
200- var probeType = ( NeuropixelsV2ProbeType ) ( ( ComboBox ) sender ) . SelectedItem ;
201-
202- if ( probeType != ProbeConfiguration . ProbeType )
203- {
204- ProbeConfiguration . ProbeType = probeType ;
205- ChannelConfiguration . LoadDefaultChannelLayout ( ) ;
206- UpdateProbeConfiguration ( ) ;
207- }
217+ UpdateProbeConfiguration ( ) ;
208218 }
209219
210220 private void SelectedReferenceChanged ( object sender , EventArgs e )
@@ -658,10 +668,25 @@ void CheckQuadShankForChannelPreset(NeuropixelsV2Electrode[] channelMap)
658668
659669 private void OnFileLoadEvent ( object sender , EventArgs e )
660670 {
661- ProbeConfiguration . ProbeType = NeuropixelsV2eProbeGroup . GetProbeTypeFromProbeName ( ChannelConfiguration . ProbeGroup . Probes . First ( ) . Annotations . Name ) ;
662- comboBoxProbeType . SelectedItem = ProbeConfiguration . ProbeType ;
671+ NeuropixelsV2ProbeType probeType ;
672+
673+ try
674+ {
675+ probeType = NeuropixelsV2eProbeGroup . GetProbeTypeFromProbeName ( ChannelConfiguration . ProbeGroup . Probes . First ( ) . Annotations . Name ) ;
676+ }
677+ catch ( ArgumentException ex )
678+ {
679+ MessageBox . Show ( ex . Message ) ;
680+ return ;
681+ }
682+
683+ probeConfigurations [ probeType ] = new ( ( NeuropixelsV2eProbeGroup ) ChannelConfiguration . ProbeGroup ,
684+ probeConfigurations [ probeType ] . Probe ,
685+ probeConfigurations [ probeType ] . ProbeType ,
686+ probeConfigurations [ probeType ] . Reference ) ;
687+
688+ comboBoxProbeType . SelectedItem = probeType ;
663689 UpdateProbeConfiguration ( ) ;
664- CheckForExistingChannelPreset ( ) ;
665690 }
666691
667692 private void FileTextChanged ( object sender , EventArgs e )
0 commit comments