Exemple #1
0
        private void btnSave_Notes_Click(object sender, EventArgs e)
        {
            string       file_name_sz = ((DMP_Main_MDIParent)this.MdiParent).HomeFolder + Environment.MachineName + "\\sznotes.csv";
            StreamWriter sw;

            if (File.Exists(file_name_sz))
            {
                sw = new StreamWriter(file_name_sz, true);
            }
            else
            {
                sw = new StreamWriter(file_name_sz, true);
                sw.WriteLine("start_time, end_time, channel, Event");
            }

            Int64  unixTimestamp = (Int64)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;
            string txt1          = unixTimestamp.ToString() + "," + "," + "," + "physician's note: " + textBox1.Text;

            sw.WriteLine(txt1); //write the text.
            sw.Close();
            CustomMsgBox.Show("Note Saved!\nClick OK to continue.", "", "OK");
            textBox1.Clear();

            ((DMP_Main_MDIParent)this.MdiParent).ToggleOSK(false);
        }
Exemple #2
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            btnStart.Text = "Impedance Test Running...";
            SetbtnStartEnable(false);

            DialogResult dialogResult = CustomMsgBox.Show("Sensing and stimulation will be temporarily stopped while the impedance test is performed.\n" +
                                                          "Do you want to continue?", "Start Impedance Test", "Yes", "No");

            if (dialogResult == DialogResult.Yes)
            {
                SetbtnStopEnable(true);
                ImpedanceRun_Thread = new Thread(() => { ((DMP_Main_MDIParent)this.MdiParent).StartTestingImpedance(this); });
                ImpedanceRun_Thread.Start();
            }
            else if (dialogResult == DialogResult.Cancel)
            {
                Console.WriteLine("The Impedance test is rejected by user.");
                //To avoid cross-threading issue.
                this.Invoke((MethodInvoker) delegate()
                {
                    SetbtnStartEnable(true);
                    btnStart.Text = "Start Impedance Test";
                    SetbtnStopEnable(false);
                });
            }
        }
Exemple #3
0
        public StimulationParamForm(DMP_Main_MDIParent parent)
        {
            InitializeComponent();

            this.pnl = panel1;

            this.MdiParent = parent;
            ((DMP_Main_MDIParent)this.MdiParent).stimParamForm = this;

            // read setting and identify current state
            ((DMP_Main_MDIParent)this.MdiParent).ReadStimulationSettingsFile();
            ((DMP_Main_MDIParent)this.MdiParent).UpdateStimSettingsFile(this);
            // When reading setting for the first time - make sure they are correct
            if (!(((DMP_Main_MDIParent)this.MdiParent).StimSettingsCheck(this)))
            {
                Console.WriteLine("Stimulation setting are NOT valid!\nStimulation is turned OFF!");
                CustomMsgBox.Show("Stimulation setting are NOT valid!\nStimulation is turned OFF!", "Error", "OK");

                ((DMP_Main_MDIParent)this.MdiParent).SetStimMode = 0;
            }

            ((DMP_Main_MDIParent)this.MdiParent).PropertyChanged -= ConnectionChanges;
            ((DMP_Main_MDIParent)this.MdiParent).PropertyChanged += ConnectionChanges;
            ConnectionChanges(this, null);
        }
Exemple #4
0
        private void BbtnApply_Click(object sender, EventArgs e)
        {
            if (!((DMP_Main_MDIParent)this.MdiParent).GetCTMconnection ||
                !((DMP_Main_MDIParent)this.MdiParent).GetINSconnection)
            {
                CustomMsgBox.Show("Hardware is not connected.\nApplying new settings is currently not possible.", "Error", "OK");
            }
            else
            {
                if (((DMP_Main_MDIParent)this.MdiParent).StimSettingsCheck(this))
                {
                    if (((DMP_Main_MDIParent)this.MdiParent).WriteStimulationSettingsFile())
                    {
                        this.Setlabel_settingsTimeText("Setting successfully saved: " + String.Format("{0:G}", DateTime.Now));
                    }

                    // ask if to start or test stim
                    DialogResult dialogResult = CustomMsgBox.Show("Settings are saved!\nWould you like to start stimulation with current settings or\ntest current stimulation settings?",
                                                                  "Apply Stimulation Settings",
                                                                  "Start Stimulation", "Test Stimulation", "Done");

                    if (dialogResult == DialogResult.No) // Test Stimulation
                    {
                        stimTest = new StimTest((DMP_Main_MDIParent)this.MdiParent);
                        stimTest.ShowDialog();
                    }
                    else if (dialogResult == DialogResult.Yes) // Start Stimulation
                    {
                        new Thread(() => ((DMP_Main_MDIParent)this.MdiParent).StartStim(this)).Start();
                    }
                }
            }
        }
        public Read(string file)
        {
            string[] pieces;

            fileName = Path.GetFileName(file);
            string[] lines = File.ReadAllLines(file); // read all lines
            if (lines == null || lines.Length < 2)
            {
                return;                     //no data in file
            }
            header   = lines[0].Split(','); //first line is header
            nLines   = lines.Length - 1;    //first line is header
            nColumns = header.Length;

            //read the numerical data and section name from the file
            data    = new float[nLines, nColumns - 1]; // *** 1 less than nColumns as last col is sectionName
            section = new string[nLines];              // ***
            for (int i = 0; i < nLines; i++)
            {
                pieces = lines[i + 1].Split(','); // first line is header
                if (pieces.Length != nColumns)
                {
                    CustomMsgBox.Show("Invalid data at line " + (i + 2) + " of file " + fileName, "Invalid data", "OK"); return;
                }
                for (int j = 0; j < nColumns - 1; j++)
                {
                    float.TryParse(pieces[j], out data[i, j]); //data[i, j] = float.Parse(pieces[j]);
                }
                section[i] = pieces[nColumns - 1];             //last item is section
            }
        }
Exemple #6
0
 //btn_Login Click event
 private void Button_Login_Click(object sender, EventArgs e)
 {
     if (textBox_Password.Text == "")
     {
         CustomMsgBox.Show("Please enter Password!", "Error", "OK");
         return;
     }
     else
     {
         if (User == "Patient" && VerifyPassword(textBox_Password.Text, patientPass, patientSalt))
         {
             ///Run Patient Screen
             Patient PatientScreen = null;
             foreach (Form childForm in this.MdiParent.MdiChildren)
             {
                 if (childForm.Name == "Patient")
                 {
                     PatientScreen = (Patient)childForm;
                 }
             }
             if (PatientScreen == null)
             {
                 PatientScreen = new Patient()
                 {
                     MdiParent = this.MdiParent
                 };
             }
             PatientScreen.Show();
             logingclick = true;
             this.Close();
         }
         else if (User == "Physician" && VerifyPassword(textBox_Password.Text, physicianPass, physicianSalt))
         {
             ///Run Physician Screen
             Physician PhysiciantScreen = null;
             foreach (Form childForm in this.MdiParent.MdiChildren)
             {
                 if (childForm.Name == "Physician")
                 {
                     PhysiciantScreen = (Physician)childForm;
                 }
             }
             if (PhysiciantScreen == null)
             {
                 PhysiciantScreen = new Physician()
                 {
                     MdiParent = this.MdiParent
                 };
             }
             PhysiciantScreen.Show();
             logingclick = true;
             this.Close();
         }
         else
         {
             CustomMsgBox.Show("Login Failed!", "Error", "OK");
         }
     }
 }
Exemple #7
0
        private void btn_ConfigurationLDA_Click(object sender, EventArgs e)
        {
            btn_ConfigurationLDA.Text    = "Applying..";
            btn_ConfigurationLDA.Enabled = false;
            //First check if the channels selected are different. If same, then show the message and stop implementing the rest of the code.
            lbl_LD_ConfigStatus.Text = "";
            if (cmb_Input1_channels.SelectedIndex == cmb_Input2_channels.SelectedIndex)
            {
                lbl_LD_ConfigStatus.ForeColor = Color.Red;
                CustomMsgBox.Show("Input channels must be different.\n" +
                                  "Please select different channel for Input 2.", "Error", "OK");
                lbl_LD_ConfigStatus.Text     = "Apply Settings Failed";
                btn_ConfigurationLDA.Text    = "Apply Settings";
                btn_ConfigurationLDA.Enabled = true;
                return;
            }
            //To restrict the user from passing lower frequncies greater than higher frequencies.
            if ((numericUpDownInput1LowBand1.Value >= numericUpDownInput1HighBand1.Value) || (numericUpDownInput1LowBand2.Value >= numericUpDownInput1HighBand2.Value) ||
                (numericUpDownInput2LowBand1.Value >= numericUpDownInput2HighBand1.Value) || (numericUpDownInput2LowBand2.Value >= numericUpDownInput2HighBand2.Value))
            {
                lbl_LD_ConfigStatus.ForeColor = Color.Red;
                CustomMsgBox.Show("High limits for frequency bands must be greater than low limits.\n"
                                  + "Please check frequency settings and try again.", "Error", "OK");
                lbl_LD_ConfigStatus.Text     = "Apply Settings Failed";
                btn_ConfigurationLDA.Text    = "Apply Settings";
                btn_ConfigurationLDA.Enabled = true;
                return;
            }
            if (chkBox_SaveFftData.Checked)
            {
                ((DMP_Main_MDIParent)this.MdiParent).fft_check_status = true;
            }
            else
            {
                ((DMP_Main_MDIParent)this.MdiParent).fft_check_status = false;
            }
            var    time          = DateTime.Now;
            string formattedTime = time.ToString("yyyy/MM/dd hh:mm:ss tt");

            ((DMP_Main_MDIParent)this.MdiParent).SetDoing_LDA_config = true;  //Started LDA configuration..Change flag to true.
            ((DMP_Main_MDIParent)this.MdiParent).StartStreaming(0, 0, "Off"); // stop all
            ((DMP_Main_MDIParent)this.MdiParent).CopyLDAConfigurationFromUI(this);
            ((DMP_Main_MDIParent)this.MdiParent).WriteLDASettingsFile(this);
            System.Threading.Thread.Sleep(250);
            ((DMP_Main_MDIParent)this.MdiParent).ReadLDAConfigurationFile();
            ((DMP_Main_MDIParent)this.MdiParent).StartStreaming(((DMP_Main_MDIParent)this.MdiParent).GetStimMode, ((DMP_Main_MDIParent)this.MdiParent).GetStreamingMode, ((DMP_Main_MDIParent)this.MdiParent).CurrState);
            ((DMP_Main_MDIParent)this.MdiParent).SetDoing_LDA_config = false; //finished the LDA configuration. Change flag to false.
            ((DMP_Main_MDIParent)this.MdiParent).UpdateBands_LDA(this);
            // write settings file again, this time with updated bands
            ((DMP_Main_MDIParent)this.MdiParent).WriteLDASettingsFile(this);
            System.Threading.Thread.Sleep(250);
            lbl_LD_ConfigStatus.ForeColor = Color.Blue;
            lbl_LD_ConfigStatus.Text      = "Settings applied successfully at: " + formattedTime;
            btn_ConfigurationLDA.Text     = "Apply Settings";
            btn_ConfigurationLDA.Enabled  = true;
        }
Exemple #8
0
        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (!stopTest)
            {
                SettextBox1Text("*- Completed Test For All Settings -*");

                if (mdiParent.GetStimMode == 1)
                {
                    SettextBox1Text("Setting back to Default settings..");
                    // set to default
                    new Thread(() => mdiParent.StartStreaming(1, mdiParent.GetStreamingMode, "Default")).Start();
                }
                else // stimMode == 0
                {
                    DialogResult dialogResult = CustomMsgBox.Show("All stimulation settings were tested and verified!\n" +
                                                                  "Please confirm starting Stimulation with curent Settings", "Stimulation Settings", "Start Stimulation", "Cancel");
                    if (dialogResult == DialogResult.Yes)
                    {
                        new Thread(() => mdiParent.StartStim(null)).Start();

                        SettimeLeftText("*- Applied Stimulation Settings. -*");
                        SettimeLeftText("*- Stimulation is ON -*");
                    }
                    else
                    {
                        SettextBox1Text("Turning off stimulation..");
                        // stim off
                        new Thread(() => mdiParent.StartStreaming(0, mdiParent.GetStreamingMode, "Off")).Start();
                    }
                }
            }
            else
            {
                SettextBox1Text("*- Stopped Test -*");

                if (mdiParent.GetStimMode == 1)
                {
                    SettextBox1Text("Setting back to Default settings..");
                    // set to default
                    new Thread(() => mdiParent.StartStreaming(1, mdiParent.GetStreamingMode, "Default")).Start();
                }
                else // stimMode == 0
                {
                    SettextBox1Text("Turning off stimulation..");
                    // stim off
                    new Thread(() => mdiParent.StartStreaming(0, mdiParent.GetStreamingMode, "Off")).Start();
                }
            }

            SettextBox1Text("*- Test Done -*");
            SettimeLeftText("*- Test Done -*");
            btnStop_testStim.Text = "Close Window";

            Console.WriteLine("Stimulation setting test ended");
        }
Exemple #9
0
        private void CloseApp_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = CustomMsgBox.Show("If the program is terminated EEG sensing and dynamic stimulation adjustments will be halted. \n" +
                                                          "Please confirm closing the Application", "Close Application", "Close Application", "Cancel");

            if (dialogResult == DialogResult.Yes)
            {
                ((DMP_Main_MDIParent)this.MdiParent).CloseEnv();
                System.Environment.Exit(1);
            }
        }
Exemple #10
0
        private void btnStart_App_Click(object sender, EventArgs e)
        {
            /// https://www.dotnetperls.com/messagebox-show
            DialogResult dialogResult = CustomMsgBox.Show("If the program is terminated EEG sensing and dynamic stimulation adjustments will be halted. \n" +
                                                          "Please confirm restarting the Application", "Restart Application", "Restart Application", "Cancel");

            if (dialogResult == DialogResult.Yes)
            {
                ((DMP_Main_MDIParent)this.MdiParent).CloseEnv();
                Application.Restart();
            }
        }
Exemple #11
0
        private void InputBox_Validating(object sender, CancelEventArgs e)
        {
            TextBox currentb = (TextBox)sender;

            if (currentb.Text == "")
            {
                CustomMsgBox.Show("Field can not be empty", "Error", "OK");
                e.Cancel = true;
            }
            else if (!(int.TryParse(currentb.Text, out int res)))
            {
                CustomMsgBox.Show("Field should be a number", "Error", "OK");
                e.Cancel = true;
            }
Exemple #12
0
        private void stopStim_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult;

            Stopstimtimer.Interval = timersInterval;
            Stopstimtimer.Tick    += Stopstimtimer_Tick;
            Stopstimtimer.Start();
            stopStim.Enabled = false;

            if (((DMP_Main_MDIParent)this.MdiParent).TheSummit == null ||
                (((DMP_Main_MDIParent)this.MdiParent).TheSummit.IsDisposed))
            {
                CustomMsgBox.Show("Hardware is not connected.\nStop Stimulation is currently not possible.", "Error", "OK");
            }
            else
            {
                // stop stimulation
                if (((DMP_Main_MDIParent)this.MdiParent).GetIsStiming == 1)
                {
                    if (((DMP_Main_MDIParent)this.MdiParent).GetStimMode == 1)
                    {
                        dialogResult = CustomMsgBox.Show("Stimulation will be stopped.\n\n" +
                                                         "Stimulation should be stopped for patient safety reasons only"
                                                         , "Stop Stimulation", "Stop Stimulation", "Cancel");
                        if (dialogResult == DialogResult.Yes)
                        {
                            new Thread(() => ((DMP_Main_MDIParent)this.MdiParent).StopStim(null)).Start();
                        }
                    }
                    else // STIMULATION IS ON BUT WE DONT WANT TO STIM
                    {
                        Console.WriteLine("We don't want to stim...\nStimulation is ON but stimMode is 0!\n");
                        new Thread(() => ((DMP_Main_MDIParent)this.MdiParent).StopStim(null)).Start();
                    }
                }
                else
                {   // stimulation is off but we want to stim
                    if (((DMP_Main_MDIParent)this.MdiParent).GetStimMode == 1)
                    {
                        Console.WriteLine("Stimulation is OFF but stimMode is 1!\n");
                        new Thread(() => ((DMP_Main_MDIParent)this.MdiParent).StartStim(null)).Start();
                    }
                    else
                    {
                        dialogResult = CustomMsgBox.Show("Stimulation is currently off.\n", "", "OK");
                    }
                }
            }
        }
Exemple #13
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            // check if channel specifications are valid
            for (int i = 0; i < 4; i++)
            {
                if (channelMinusBox[i].Text.Equals(channelPlusBox[i].Text))
                {
                    String message_to_show = "Channel number " + i + " electrode specification is invalid, please fix and try again.";
                    CustomMsgBox.Show(message_to_show, "Error", "OK");
                    return;
                }
            }

            // write new setting file
            ((DMP_Main_MDIParent)this.MdiParent).WriteSettingsFile(this);

            System.Threading.Thread.Sleep(250);
            // get current settings to update in GUI
            ((DMP_Main_MDIParent)this.MdiParent).ReadSettingsFile();
            ((DMP_Main_MDIParent)this.MdiParent).UpdateSensingSettingsFile(this);

            System.Threading.Thread.Sleep(250);

            if (!((DMP_Main_MDIParent)this.MdiParent).GetCTMconnection ||
                !((DMP_Main_MDIParent)this.MdiParent).GetINSconnection)
            {
                CustomMsgBox.Show("Hardware is not connected.\nNew settings is will be applied when harware will connect successfuly!", "Error", "OK");
                ((DMP_Main_MDIParent)this.MdiParent).EndCurrentRecording(true);  // closes existing MEF files
            }
            else
            {
                SetbtnApplyEnable(false);

                new Thread(() =>
                {
                    ((DMP_Main_MDIParent)this.MdiParent).SetDoing_sensing = true;
                    ((DMP_Main_MDIParent)this.MdiParent).StartStreaming(0, 0, ((DMP_Main_MDIParent)this.MdiParent).CurrState);
                    System.Threading.Thread.Sleep(250);                             // give streaming time to stop before closing MEF files
                    ((DMP_Main_MDIParent)this.MdiParent).EndCurrentRecording(true); // closes existing MEF files
                    ((DMP_Main_MDIParent)this.MdiParent).StartStreaming(((DMP_Main_MDIParent)this.MdiParent).GetStimMode, ((DMP_Main_MDIParent)this.MdiParent).GetStreamingMode, ((DMP_Main_MDIParent)this.MdiParent).CurrState);
                    ((DMP_Main_MDIParent)this.MdiParent).SetDoing_sensing = false;
                }).Start();

                // update LDA form and re-write LDA settings files
                ((Physician)(this.physician_parent_form)).updateLDAform(null, null);

                SetbtnApplyEnable(true);
            }
        }
Exemple #14
0
 private void BtnStart_Stimulation_Click(object sender, EventArgs e)
 {
     if (!((DMP_Main_MDIParent)this.MdiParent).GetCTMconnection ||
         !((DMP_Main_MDIParent)this.MdiParent).GetINSconnection)
     {
         CustomMsgBox.Show("Hardware is not connected.\nStart Stimulation is currently not possible.", "Error", "OK");
     }
     else
     {
         if (((DMP_Main_MDIParent)this.MdiParent).StimSettingsCheck(this))
         {
             SetbtnStart_StimulationEnable(false);
             new Thread(() => ((DMP_Main_MDIParent)this.MdiParent).StartStim(this)).Start();
         }
     }
 }
Exemple #15
0
 private void BtnTest_Click(object sender, EventArgs e)
 {
     if (!((DMP_Main_MDIParent)this.MdiParent).GetCTMconnection ||
         !((DMP_Main_MDIParent)this.MdiParent).GetINSconnection)
     {
         CustomMsgBox.Show("Hardware is not connected.\nTesting new settings is currently not possible.", "Error", "OK");
     }
     else
     {
         if (((DMP_Main_MDIParent)this.MdiParent).StimSettingsCheck(this))
         {
             stimTest = new StimTest((DMP_Main_MDIParent)this.MdiParent);
             stimTest.ShowDialog();
         }
     }
 }
Exemple #16
0
        public static DialogResult Show(string Text, string Caption, string btnOK)
        {
            MsgBox             = new CustomMsgBox();
            MsgBox.label1.Text = Text;
            System.Media.SystemSounds.Exclamation.Play();

            MsgBox.button1.Visible = false;
            MsgBox.button2.Visible = false;
            MsgBox.button3.Visible = true;

            MsgBox.button3.Text = btnOK;

            MsgBox.Text = Caption;
            result      = DialogResult.Cancel;
            MsgBox.ShowDialog();
            return(result);
        }
Exemple #17
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            try
            {
                // input check
                if (comboBox_Medication.Text.Equals("Medication") || comboBox_Medication.Text.Equals("") ||
                    comboBox_Dosage.Text.Equals("Dosage"))
                {
                    CustomMsgBox.Show("Please select Medication and Dosage!", "Error", "OK");
                    return;
                }

                // write to annotations file
                string       file_name_sz = ((DMP_Main_MDIParent)this.MdiParent).HomeFolder + Environment.MachineName + "\\sznotes.csv";
                StreamWriter sw;
                if (File.Exists(file_name_sz))
                {
                    sw = new StreamWriter(file_name_sz, true);
                }
                else
                {
                    sw = new StreamWriter(file_name_sz, true);
                    sw.WriteLine("start_time, end_time, channel, Event");
                }
                Int64  unixTimestamp = (Int64)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;
                String medType       = SupMed ? "sm" : "rm";
                string medType_name;
                if (medType == "sm")
                {
                    medType_name = "supplemental medication";
                }
                else
                {
                    medType_name = "regular medication";
                }
                string txt1 = unixTimestamp.ToString() + "," + "," + "," + medType_name + ": " + comboBox_Medication.Text + " " + comboBox_Dosage.Text;
                sw.WriteLine(txt1); //write the text.

                sw.Close();
                CustomMsgBox.Show("Logged succesfuly!", "", "OK");
            }
            catch (Exception ex)
            {
                CustomMsgBox.Show("Error while logging...\n" + ex.Message, "Error", "OK");
            }
        }
Exemple #18
0
        private void numericUpDown_Validating(object sender, CancelEventArgs e)
        {
            NumericUpDown currentnup = (NumericUpDown)sender;

            if (currentnup.Text == "")
            {
                CustomMsgBox.Show("Field can not be empty", "Error", "OK");
                e.Cancel = true;
            }
            else if (currentnup.Value < currentnup.Minimum || currentnup.Value > currentnup.Maximum)
            {
                CustomMsgBox.Show("Value is out of range", "Error", "OK");
                e.Cancel = true;
            }
            else
            {
                e.Cancel = false;
            }
        }
Exemple #19
0
        private void btnStart_Sensing_Click(object sender, EventArgs e)
        {
            if (!((DMP_Main_MDIParent)this.MdiParent).GetCTMconnection ||
                !((DMP_Main_MDIParent)this.MdiParent).GetINSconnection)
            {
                CustomMsgBox.Show("Hardware is not connected.\nStart Sensing is currently not possible.\n\nConnect to Hardware via Program Control tab.", "Error", "OK");
            }
            else
            {
                SetbtnStart_SensingEnable(false);

                new Thread(() =>
                {
                    ((DMP_Main_MDIParent)this.MdiParent).SetStreamingMode = 1;
                    ((DMP_Main_MDIParent)this.MdiParent).SetDoing_sensing = true;
                    ((DMP_Main_MDIParent)this.MdiParent).StartStreaming(((DMP_Main_MDIParent)this.MdiParent).GetStimMode, ((DMP_Main_MDIParent)this.MdiParent).GetStreamingMode, ((DMP_Main_MDIParent)this.MdiParent).CurrState);
                    ((DMP_Main_MDIParent)this.MdiParent).SetDoing_sensing = false;
                }).Start();
            }
        }
Exemple #20
0
        private void safeMode_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult;

            if (((DMP_Main_MDIParent)this.MdiParent).TheSummit == null ||
                (((DMP_Main_MDIParent)this.MdiParent).TheSummit.IsDisposed))
            {
                CustomMsgBox.Show("Hardware is not connected.\nSafe mode is currently not possible.", "Error", "OK");
            }
            else
            {
                // safe mode
                if (((DMP_Main_MDIParent)this.MdiParent).GetIsStiming == 1)
                {
                    if (((DMP_Main_MDIParent)this.MdiParent).GetStimMode == 1)
                    {
                        if (safeMode.Text.Equals("Safe Mode"))
                        {
                            dialogResult = CustomMsgBox.Show("Stimulation settings will be changed to default.\n\n" +
                                                             "Safe Mode sets Default stimulation parameters and disables stimulation changes.Use for patient safety reasons only."
                                                             , "Safe Mode", "Default settings", "Cancel");
                            if (dialogResult == DialogResult.Yes)
                            {
                                safeMode.Text = "Cancel Safe Mode";
                                ((DMP_Main_MDIParent)this.MdiParent).SetSafeMode = true;
                                ((DMP_Main_MDIParent)this.MdiParent).WriteStimulationSettingsFile();

                                Thread t = new Thread(() =>
                                {
                                    ((DMP_Main_MDIParent)this.MdiParent).SetDoing_stim = true;
                                    ((DMP_Main_MDIParent)this.MdiParent).StartStreaming(((DMP_Main_MDIParent)this.MdiParent).GetStimMode, ((DMP_Main_MDIParent)this.MdiParent).GetStreamingMode, "Default");
                                    ((DMP_Main_MDIParent)this.MdiParent).SetDoing_stim = false;
                                });
                                t.Start();
                            }
                        }
                        else
                        {
                            dialogResult = CustomMsgBox.Show("Confirm canceling Safe Mode.\n", "Safe Mode", "Confirm", "Cancel");
                            if (dialogResult == DialogResult.Yes)
                            {
                                safeMode.Text = "Safe Mode";
                                ((DMP_Main_MDIParent)this.MdiParent).SetSafeMode = false;
                                ((DMP_Main_MDIParent)this.MdiParent).WriteStimulationSettingsFile();

                                Thread t = new Thread(() =>
                                {
                                    ((DMP_Main_MDIParent)this.MdiParent).SetDoing_stim = true;
                                    ((DMP_Main_MDIParent)this.MdiParent).StartStreaming(((DMP_Main_MDIParent)this.MdiParent).GetStimMode, ((DMP_Main_MDIParent)this.MdiParent).GetStreamingMode, "Default");
                                    ((DMP_Main_MDIParent)this.MdiParent).SetDoing_stim = false;
                                });
                                t.Start();
                            }
                        }
                    }
                    else // STIMULATION IS ON BUT WE DONT WANT TO STIM
                    {
                        Console.WriteLine("We don't want to stim...\nStimulation is ON but stimMode is 0!\n");
                        new Thread(() => ((DMP_Main_MDIParent)this.MdiParent).StopStim(null)).Start();
                    }
                }
                else
                {   // stimulation is off but we want to stim
                    if (((DMP_Main_MDIParent)this.MdiParent).GetStimMode == 1)
                    {
                        Console.WriteLine("Stimulation is OFF but stimMode is 1!\n");
                        new Thread(() => ((DMP_Main_MDIParent)this.MdiParent).StartStim(null)).Start();
                    }
                    else
                    {
                        dialogResult = CustomMsgBox.Show("Stimulation is currently off.\n", "", "OK");
                    }
                }
            }
        }