using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace VisualBCM { public partial class StimulusForm : Form { BCMToolbox.StimulatorBase __stim = null; public StimulusForm(BCMToolbox.StimulatorBase stim) { InitializeComponent(); __stim = stim; // prepare stimulus screen string[] props = __stim.GetParameters(); StringBuilder rtext = new StringBuilder(); foreach (string prop in props) { rtext.AppendFormat("{0} = {1}", prop, BCMToolbox.StimulatorBase.STIMULUS_NULL); rtext.AppendLine(""); } this.richTextBox1.Text = rtext.ToString(); } public BCMToolbox.StimulatorBase Stimulator { get { return __stim; } } public event EventHandler ApplyStimulus; void SetParameters() { Dictionary stimParameters = new Dictionary(); foreach (string line in this.richTextBox1.Lines) { if (!line.Contains('=')) continue; string[] linetokens = line.Split('='); string key = linetokens[0].Trim(); string value = linetokens[1].Trim(); object parsedValue = null; if (value.Contains(';')) // this is an array of int { string[] arrTokens = value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); List pValue = new List(); foreach (string tok in arrTokens) pValue.Add(Int32.Parse(tok)); parsedValue = pValue.ToArray(); } else if (value.Contains('.')) // this is a double parsedValue = Double.Parse(value); else { try { parsedValue = Int32.Parse(value); } catch { if (value != "null") parsedValue = value; } } stimParameters.Add(key, parsedValue); } __stim.SetParameters(stimParameters); } private void button1_Click(object sender, EventArgs e) { SetParameters(); if (this.ApplyStimulus != null) this.ApplyStimulus(this, EventArgs.Empty); this.Close(); } private void button2_Click(object sender, EventArgs e) { this.Close(); } private void saveToolStripMenuItem_Click(object sender, EventArgs e) { if (this.saveFileDialog1.ShowDialog() != DialogResult.OK) return; using (StreamWriter sw = new StreamWriter(this.saveFileDialog1.FileName, false, Encoding.UTF8)) { foreach (string line in richTextBox1.Lines) sw.WriteLine(line); sw.Close(); } System.Media.SystemSounds.Beep.Play(); } private void loadToolStripMenuItem_Click(object sender, EventArgs e) { if (this.openFileDialog1.ShowDialog() != DialogResult.OK) return; using (StreamReader sr = new StreamReader(this.openFileDialog1.FileName, Encoding.UTF8)) { this.richTextBox1.Text = sr.ReadToEnd(); sr.Close(); } System.Media.SystemSounds.Beep.Play(); } } }