11using System ;
22using System . Collections . Generic ;
3+ using System . ComponentModel ;
34using System . Windows . Forms ;
45
56namespace OpenEphys . Onix1 . Design
@@ -15,7 +16,11 @@ public partial class NeuropixelsV2eDialog : Form
1516 /// Public <see cref="IConfigureNeuropixelsV2"/> interface that is manipulated by
1617 /// <see cref="NeuropixelsV2eDialog"/>.
1718 /// </summary>
18- public IConfigureNeuropixelsV2 ConfigureNode { get ; set ; }
19+ public IConfigureNeuropixelsV2 ConfigureNode
20+ {
21+ get => ( IConfigureNeuropixelsV2 ) propertyGrid . SelectedObject ;
22+ set => propertyGrid . SelectedObject = value ;
23+ }
1924
2025 /// <summary>
2126 /// Initializes a new instance of <see cref="NeuropixelsV2eDialog"/>.
@@ -55,17 +60,6 @@ public NeuropixelsV2eDialog(IConfigureNeuropixelsV2 configureNode)
5560 Tag = NeuropixelsV2Probe . ProbeB
5661 }
5762 } ;
58-
59- foreach ( var channelConfiguration in ProbeConfigurations )
60- {
61- channelConfiguration . InvertPolarityChanged += InvertPolarityChanged ;
62-
63- string probeName = GetProbeName ( ( NeuropixelsV2Probe ) channelConfiguration . Tag ) ;
64-
65- tabControlProbe . TabPages . Add ( probeName , probeName ) ;
66- tabControlProbe . TabPages [ probeName ] . Controls . Add ( channelConfiguration ) ;
67- this . AddMenuItemsFromDialogToFileOption ( channelConfiguration , probeName ) ;
68- }
6963 }
7064
7165 private void InvertPolarityChanged ( object sender , EventArgs e )
@@ -78,6 +72,8 @@ private void InvertPolarityChanged(object sender, EventArgs e)
7872 channelConfiguration . SetInvertPolarity ( sendingDialog . InvertPolarity ) ;
7973 }
8074 }
75+
76+ ConfigureNode . InvertPolarity = sendingDialog . InvertPolarity ;
8177 }
8278
8379 private string GetProbeName ( NeuropixelsV2Probe probe )
@@ -105,10 +101,38 @@ private void FormShown(object sender, EventArgs e)
105101 menuStrip . Visible = false ;
106102 }
107103
104+ int index = 0 ;
105+
108106 foreach ( var channelConfiguration in ProbeConfigurations )
109107 {
108+ channelConfiguration . InvertPolarityChanged += InvertPolarityChanged ;
109+ channelConfiguration . ValueChanged += RefreshPropertyGrid ;
110+
111+ string probeName = GetProbeName ( ( NeuropixelsV2Probe ) channelConfiguration . Tag ) ;
112+
113+ tabControlProbe . TabPages . Insert ( index ++ , probeName , probeName ) ;
114+ tabControlProbe . TabPages [ probeName ] . Controls . Add ( channelConfiguration ) ;
115+ this . AddMenuItemsFromDialogToFileOption ( channelConfiguration , probeName ) ;
116+
110117 channelConfiguration . Show ( ) ;
111118 }
119+
120+ tabControlProbe . SelectedIndex = 0 ;
121+ }
122+
123+ void RefreshPropertyGrid ( object s , EventArgs e )
124+ {
125+ var dialog = ( NeuropixelsV2eProbeConfigurationDialog ) s ;
126+ if ( ( NeuropixelsV2Probe ) dialog . Tag == NeuropixelsV2Probe . ProbeA )
127+ {
128+ ConfigureNode . GainCalibrationFileA = dialog . textBoxProbeCalibrationFile . Text ;
129+ }
130+ else if ( ( NeuropixelsV2Probe ) dialog . Tag == NeuropixelsV2Probe . ProbeB )
131+ {
132+ ConfigureNode . GainCalibrationFileB = dialog . textBoxProbeCalibrationFile . Text ;
133+ }
134+
135+ propertyGrid . Refresh ( ) ;
112136 }
113137
114138 internal void Okay_Click ( object sender , EventArgs e )
@@ -128,5 +152,25 @@ internal void SaveVariables()
128152
129153 ConfigureNode . InvertPolarity = ProbeConfigurations [ GetProbeIndex ( NeuropixelsV2Probe . ProbeA ) ] . InvertPolarity ;
130154 }
155+
156+ void PropertyValueChanged ( object s , PropertyValueChangedEventArgs e )
157+ {
158+ var propertyGrid = ( PropertyGrid ) s ;
159+ var configureNode = ( IConfigureNeuropixelsV2 ) propertyGrid . SelectedObject ;
160+
161+ foreach ( var configuration in ProbeConfigurations )
162+ {
163+ if ( ( NeuropixelsV2Probe ) configuration . Tag == NeuropixelsV2Probe . ProbeA )
164+ {
165+ configuration . UpdateControls ( configureNode . ProbeConfigurationA , configureNode . GainCalibrationFileA , configureNode . InvertPolarity ) ;
166+ }
167+ else if ( ( NeuropixelsV2Probe ) configuration . Tag == NeuropixelsV2Probe . ProbeB )
168+ {
169+ configuration . UpdateControls ( configureNode . ProbeConfigurationB , configureNode . GainCalibrationFileB , configureNode . InvertPolarity ) ;
170+ }
171+ else
172+ throw new InvalidEnumArgumentException ( ) ;
173+ }
174+ }
131175 }
132176}
0 commit comments