Пример #1
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (editorService != null)
            {
                IDisposable subscription = null;
                var         source       = GetDataSource(context, provider);
                var         chart        = new ChartPanel(source, provider);
                chart.ClientSize = new System.Drawing.Size(320, 180);
                var matVisualizer = new MatVisualizer();
                matVisualizer.OverlayChannels  = false;
                matVisualizer.SelectedChannels = (int[])value;
                matVisualizer.Load(chart);
                var visualizerObservable = matVisualizer.Visualize(source.Output, chart);
                chart.HandleCreated += delegate { subscription = visualizerObservable.Subscribe(); };
                chart.Leave         += delegate { editorService.CloseDropDown(); subscription.Dispose(); };
                try
                {
                    editorService.DropDownControl(chart);
                }
                finally
                {
                    chart.Dispose();
                    matVisualizer.Unload();
                }

                return(matVisualizer.SelectedChannels);
            }

            return(base.EditValue(context, provider, value));
        }
Пример #2
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (editorService != null)
            {
                var subscription       = default(IDisposable);
                var propertyDescriptor = context.PropertyDescriptor;
                var source             = GetDataSource(context, provider);
                var chart = new ChartPanel(source, provider);
                chart.Dock = DockStyle.Fill;

                var autoSetButton = new Button {
                    Text = AutoStart
                };
                autoSetButton.Dock = DockStyle.Fill;
                var autoSetButtonClicked = Observable.FromEventPattern <EventHandler, EventArgs>(
                    handler => autoSetButton.Click += handler,
                    handler => autoSetButton.Click -= handler);

                var autoSetDeviationLabel = new Label();
                autoSetDeviationLabel.Dock      = DockStyle.Fill;
                autoSetDeviationLabel.Text      = DeviationLabel;
                autoSetDeviationLabel.TextAlign = ContentAlignment.MiddleCenter;

                var autoSetDeviationUpDown = new NumericUpDown();
                var upDownMargin           = autoSetDeviationUpDown.Margin;
                autoSetDeviationUpDown.Margin = new Padding(upDownMargin.Left, upDownMargin.Top + 1, upDownMargin.Right, upDownMargin.Bottom);
                autoSetDeviationUpDown.Anchor = AnchorStyles.None;

                var autoSetPanel = new TableLayoutPanel();
                autoSetPanel.Dock      = DockStyle.Top;
                autoSetPanel.Height    = autoSetButton.Height + autoSetPanel.Margin.Top;
                autoSetPanel.GrowStyle = TableLayoutPanelGrowStyle.AddColumns;
                autoSetPanel.Controls.Add(autoSetDeviationLabel, 0, 0);
                autoSetPanel.Controls.Add(autoSetDeviationUpDown, 1, 0);
                autoSetPanel.Controls.Add(autoSetButton, 2, 0);
                autoSetPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, autoSetDeviationLabel.PreferredWidth + autoSetPanel.Margin.Left + autoSetPanel.Margin.Right));
                autoSetPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, autoSetDeviationUpDown.PreferredSize.Width));
                autoSetPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
                autoSetDeviationUpDown.Maximum = 99;
                autoSetDeviationUpDown.Minimum = -99;

                var editorPanel = new TableLayoutPanel();
                editorPanel.ClientSize  = new System.Drawing.Size(320, 320);
                editorPanel.RowCount    = 2;
                editorPanel.ColumnCount = 1;
                editorPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 99));
                editorPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
                editorPanel.Controls.Add(chart);
                editorPanel.Controls.Add(autoSetPanel);

                var activeVisualizer = provider.GetService(typeof(DialogTypeVisualizer)) as SpikeWaveformCollectionVisualizer;
                var spikeVisualizer  = new MatVisualizer <WaveformThresholdPicker>();
                if (activeVisualizer != null)
                {
                    spikeVisualizer.AutoScaleX           = activeVisualizer.AutoScaleX;
                    spikeVisualizer.AutoScaleY           = activeVisualizer.AutoScaleY;
                    spikeVisualizer.ChannelOffset        = activeVisualizer.ChannelOffset;
                    spikeVisualizer.ChannelsPerPage      = activeVisualizer.ChannelsPerPage;
                    spikeVisualizer.HistoryLength        = activeVisualizer.HistoryLength;
                    spikeVisualizer.OverlayChannels      = activeVisualizer.OverlayChannels;
                    spikeVisualizer.SelectedChannels     = activeVisualizer.SelectedChannels;
                    spikeVisualizer.SelectedPage         = activeVisualizer.SelectedPage;
                    spikeVisualizer.WaveformBufferLength = activeVisualizer.WaveformBufferLength;
                    spikeVisualizer.XMax = activeVisualizer.XMax;
                    spikeVisualizer.XMin = activeVisualizer.XMin;
                    spikeVisualizer.YMax = activeVisualizer.YMax;
                    spikeVisualizer.YMin = activeVisualizer.YMin;
                }
                else
                {
                    spikeVisualizer.OverlayChannels      = false;
                    spikeVisualizer.WaveformBufferLength = 10;
                }
                spikeVisualizer.Load(chart);
                var thresholdPicker = spikeVisualizer.Graph;
                thresholdPicker.Threshold         = (double[])value;
                thresholdPicker.ThresholdChanged += (sender, e) => propertyDescriptor.SetValue(context.Instance, value = thresholdPicker.Threshold);

                var visualizerObservable = spikeVisualizer.Visualize(source.Output, chart);
                var autoSetObservable    = AutoThreshold(source.Output, autoSetButtonClicked, () => (double)autoSetDeviationUpDown.Value)
                                           .Do(ts => propertyDescriptor.SetValue(context.Instance, value = thresholdPicker.Threshold = ts));
                chart.HandleCreated += delegate { subscription = new CompositeDisposable(visualizerObservable.Subscribe(), autoSetObservable.Subscribe()); };
                editorPanel.Leave   += delegate { editorService.CloseDropDown(); subscription.Dispose(); };
                autoSetButton.Click += delegate { autoSetButton.Text = autoSetButton.Text == AutoStart ? AutoStop : AutoStart; };
                try
                {
                    editorService.DropDownControl(editorPanel);
                }
                finally
                {
                    chart.Dispose();
                    autoSetButton.Dispose();
                    editorPanel.Dispose();
                    spikeVisualizer.Unload();
                }

                return(value);
            }

            return(base.EditValue(context, provider, value));
        }