11using System ;
2+ using System . Collections . Generic ;
23using System . ComponentModel ;
34using System . IO ;
45using System . Linq ;
@@ -69,6 +70,8 @@ public NeuropixelsV2ProbeConfiguration ProbeConfiguration
6970 get => ChannelConfiguration . ProbeConfiguration ;
7071 }
7172
73+ readonly Dictionary < NeuropixelsV2ProbeType , NeuropixelsV2ProbeConfiguration > probeConfigurations ;
74+
7275 /// <inheritdoc cref="ConfigureNeuropixelsV2e.InvertPolarity"/>
7376 public bool InvertPolarity { get ; set ; }
7477
@@ -86,7 +89,15 @@ public NeuropixelsV2eProbeConfigurationDialog(NeuropixelsV2ProbeConfiguration co
8689
8790 textBoxProbeCalibrationFile . Text = calibrationFile ;
8891
89- ChannelConfiguration = new ( configuration )
92+ probeConfigurations = new ( )
93+ {
94+ [ NeuropixelsV2ProbeType . SingleShank ] = new ( configuration . Probe , NeuropixelsV2ProbeType . SingleShank , configuration . Reference ) ,
95+ [ NeuropixelsV2ProbeType . QuadShank ] = new ( configuration . Probe , NeuropixelsV2ProbeType . QuadShank , configuration . Reference )
96+ } ;
97+
98+ probeConfigurations [ configuration . ProbeType ] . SelectElectrodes ( configuration . ChannelMap ) ;
99+
100+ ChannelConfiguration = new ( probeConfigurations [ configuration . ProbeType ] )
90101 {
91102 TopLevel = false ,
92103 FormBorderStyle = FormBorderStyle . None ,
@@ -110,21 +121,17 @@ public NeuropixelsV2eProbeConfigurationDialog(NeuropixelsV2ProbeConfiguration co
110121 else
111122 comboBoxProbeType . SelectedIndexChanged += SelectedProbeTypeChanged ;
112123
113- comboBoxReference . DataSource = NeuropixelsV2ProbeConfiguration . FilterNeuropixelsV2ShankReference ( ProbeConfiguration . ProbeType ) ;
114- comboBoxReference . SelectedItem = ProbeConfiguration . Reference ;
115- comboBoxReference . SelectedIndexChanged += SelectedReferenceChanged ;
116-
117124 comboBoxChannelPresets . DataSource = GetComboBoxChannelPresets ( ProbeConfiguration . ProbeType ) ;
118125 comboBoxChannelPresets . SelectedIndexChanged += SelectedChannelPresetChanged ;
119126
120127 checkBoxInvertPolarity . Checked = InvertPolarity ;
121128 checkBoxInvertPolarity . CheckedChanged += InvertPolarityIndexChanged ;
122129
123- CheckForExistingChannelPreset ( ) ;
124-
125130 CheckStatus ( ) ;
126131
127132 Text += ": " + ProbeConfiguration . Probe . ToString ( ) ;
133+
134+ UpdateProbeConfiguration ( ) ;
128135 }
129136
130137 static Array GetComboBoxChannelPresets ( NeuropixelsV2ProbeType probeType )
@@ -173,27 +180,30 @@ private void FormShown(object sender, EventArgs e)
173180
174181 void UpdateProbeConfiguration ( )
175182 {
183+ var probeType = ( NeuropixelsV2ProbeType ) comboBoxProbeType . SelectedItem ;
184+
185+ ChannelConfiguration . ProbeConfiguration = probeConfigurations [ probeType ] ;
186+ ChannelConfiguration . ProbeGroup = ProbeConfiguration . ProbeGroup ;
187+
176188 ChannelConfiguration . DrawProbeGroup ( ) ;
177189 ChannelConfiguration . ResetZoom ( ) ;
178190 ChannelConfiguration . RefreshZedGraph ( ) ;
179191
180- comboBoxReference . DataSource = NeuropixelsV2ProbeConfiguration . FilterNeuropixelsV2ShankReference ( ProbeConfiguration . ProbeType ) ;
181-
182192 comboBoxChannelPresets . SelectedIndexChanged -= SelectedChannelPresetChanged ; // NB: Temporarily detach handler so the loaded electrode configuration is respected
183193 comboBoxChannelPresets . DataSource = GetComboBoxChannelPresets ( ProbeConfiguration . ProbeType ) ;
184194 comboBoxChannelPresets . SelectedIndexChanged += SelectedChannelPresetChanged ;
195+
196+ comboBoxReference . SelectedIndexChanged -= SelectedReferenceChanged ;
197+ comboBoxReference . DataSource = NeuropixelsV2ProbeConfiguration . FilterNeuropixelsV2ShankReference ( ProbeConfiguration . ProbeType ) ;
198+ comboBoxReference . SelectedItem = ProbeConfiguration . Reference ;
199+ comboBoxReference . SelectedIndexChanged += SelectedReferenceChanged ;
200+
201+ CheckForExistingChannelPreset ( ) ;
185202 }
186203
187204 void SelectedProbeTypeChanged ( object sender , EventArgs e )
188205 {
189- var probeType = ( NeuropixelsV2ProbeType ) ( ( ComboBox ) sender ) . SelectedItem ;
190-
191- if ( probeType != ProbeConfiguration . ProbeType )
192- {
193- ProbeConfiguration . ProbeType = probeType ;
194- ChannelConfiguration . LoadDefaultChannelLayout ( ) ;
195- UpdateProbeConfiguration ( ) ;
196- }
206+ UpdateProbeConfiguration ( ) ;
197207 }
198208
199209 private void SelectedReferenceChanged ( object sender , EventArgs e )
@@ -647,10 +657,25 @@ void CheckQuadShankForChannelPreset(NeuropixelsV2Electrode[] channelMap)
647657
648658 private void OnFileLoadEvent ( object sender , EventArgs e )
649659 {
650- ProbeConfiguration . ProbeType = NeuropixelsV2eProbeGroup . GetProbeTypeFromProbeName ( ChannelConfiguration . ProbeGroup . Probes . First ( ) . Annotations . Name ) ;
651- comboBoxProbeType . SelectedItem = ProbeConfiguration . ProbeType ;
660+ NeuropixelsV2ProbeType probeType ;
661+
662+ try
663+ {
664+ probeType = NeuropixelsV2eProbeGroup . GetProbeTypeFromProbeName ( ChannelConfiguration . ProbeGroup . Probes . First ( ) . Annotations . Name ) ;
665+ }
666+ catch ( ArgumentException ex )
667+ {
668+ MessageBox . Show ( ex . Message ) ;
669+ return ;
670+ }
671+
672+ probeConfigurations [ probeType ] = new ( ( NeuropixelsV2eProbeGroup ) ChannelConfiguration . ProbeGroup ,
673+ probeConfigurations [ probeType ] . Probe ,
674+ probeConfigurations [ probeType ] . ProbeType ,
675+ probeConfigurations [ probeType ] . Reference ) ;
676+
677+ comboBoxProbeType . SelectedItem = probeType ;
652678 UpdateProbeConfiguration ( ) ;
653- CheckForExistingChannelPreset ( ) ;
654679 }
655680
656681 private void FileTextChanged ( object sender , EventArgs e )
0 commit comments