Exemplo n.º 1
0
        /*
         * private bool valid_input;
         * private bool valid_vector_inputs()
         * {
         *  //Checks for valid vecotr inputs across entire panel.
         *
         *
         *  return false;
         * }
         *
         * private Regex generateRegexIntArray(int N)
         * {
         *  string s = @"^\[";
         *  for (int n = 0; n < N; n++)
         *      s += @"\d+" + ",";
         *  s = s.Remove(s.Length - 1);
         *  s += @"\]$";
         *  return new Regex(s);
         * }
         * public bool isIntVectorValid_TB(TextBox tb)
         * {
         *  Regex regex_intArray = generateRegexIntArray((int)(N_rows_nud.Value));
         *  return regex_intArray.IsMatch(tb.Text);
         * }
         * public bool isDoubleVectorValid_TB(TextBox tb)
         * {
         *  Regex regex_doubleArray = generateRegexDoubleArray((int)(N_rows_nud.Value));
         *  return regex_doubleArray.IsMatch(tb.Text);
         * }
         */

        //Vector valid inputs check.

        /*
         * bool vecdata_isvalid;
         * bool validate_textboxes()
         * {
         *  //This function automatically:
         *  //Cleans double and int inputs when vectors have been turned into them.
         *  //Checks vector inputs where appropriate and returns a bool to tell whether they are all well.
         *  //Yeah so this basically just cleans up the whole picture doesn't it.
         *      //if there's an int to be entered it cleans it.
         *      //if there's a double to be entered it cleans it.
         *      //this saves me from typing the if structure into every single event handler.
         *      //stead i just have one fn to call.
         *
         *  //DO THESE TEXTBOXES HOLD VALID DATA.
         *  //YES OR NO.
         *
         *  int[] t_i = new int[(int)(N_rows_nud.Value)];
         *  double[] t_d = new double[(int)(N_rows_nud.Value)];
         *
         *  ELM_GUI.cleanTextInput(newDeviceName_tb);
         *
         *  if ((int)N_rows_nud.Value == 1)
         *  {
         *      //If it says "N/A" in there, that's ok IF the box is also readonly. Becuase the user might set it to
         *      //N/A but he'll never set it to readonly. GOOD.
         *
         *      //LEFT FOUR are checked by being valid ints.
         *      ELM_GUI.cleanIntInput(Npads_tb);
         *      ELM_GUI.cleanDoubleInput(padX_tb);
         *      ELM_GUI.cleanDoubleInput(padY_tb);
         *      ELM_GUI.cleanDoubleInput(padSpace_tb);
         *
         *      //RIGHT TWO are checked by holding "N/A" and being READONLY.
         *          //If I want them to hold N/A and be READONLY, this would be the time to set it anyway.
         *      ELM_GUI.disableTB(offsetX_tb);
         *      ELM_GUI.disableTB(offsetY_tb);
         *  }
         *  else if ((int)N_rows_nud.Value == 2)
         *  {
         *
         *      //LEFT FOUR are checked by being vectors
         *      t_i = ELM_GUI.textBoxToIntArray(Npads_tb);
         *      if (t_i[0] == -1) return false;
         *      t_d = ELM_GUI.textBoxToDoubleArray(padX_tb);
         *      if (t_d[0] == -1) return false;
         *      t_d = ELM_GUI.textBoxToDoubleArray(padY_tb);
         *      if (t_d[0] == -1) return false;
         *      t_d = ELM_GUI.textBoxToDoubleArray(padSpace_tb);
         *      if (t_d[0] == -1) return false;
         *
         *      //RIGHT TWO are checked as doubles.
         *      ELM_GUI.cleanDoubleInput(offsetX_tb);
         *      ELM_GUI.cleanDoubleInput(offsetY_tb);
         *  }
         *  else
         *  {
         *      //Check left four as vectors.
         *      t_i = ELM_GUI.textBoxToIntArray(Npads_tb);
         *      if (t_i[0] == -1) return false;
         *      t_d = ELM_GUI.textBoxToDoubleArray(padX_tb);
         *      if (t_d[0] == -1) return false;
         *      t_d = ELM_GUI.textBoxToDoubleArray(padY_tb);
         *      if (t_d[0] == -1) return false;
         *      t_d = ELM_GUI.textBoxToDoubleArray(padSpace_tb);
         *      if (t_d[0] == -1) return false;
         *
         *      //Check right two as vectors.
         *      t_d = ELM_GUI.textBoxToDoubleArray(offsetX_tb);
         *      if (t_d[0] == -1) return false;
         *      t_d = ELM_GUI.textBoxToDoubleArray(offsetY_tb);
         *      if (t_d[0] == -1) return false;
         *  }
         *
         *  return true;
         * }
         */

        //Misc math helper fns.
        public int calc_RxR_numPads()
        {
            double[] dd           = ELM_GUI.textBoxToDoubleArray(Npads_tb);
            int      totalNumPads = 0;

            foreach (double d in dd)
            {
                totalNumPads += (int)d;
            }

            return(totalNumPads);
        }
Exemplo n.º 2
0
        private void generate_btn_Click(object sender, EventArgs e)
        {
            /*
             * AddDevice_RxR_GUI(
             * char* inputPath,
             *
             *  char* d_name,
             *  char* d_padNames,
             *  int d_N_rows,
             *  int* d_N_pads, double* d_padX, double* d_padY, double* d_padSpace, //length N_rows
             *  double* d_horizontalOffset, double* d_verticalOffset, //length N_rows - 1
             *
             *  char* outputPath
             * )
             */

            int initialNumDevices = ELM_GUI.CurrentSession.currentDeviceNameList.Length;

            int[]    Npads    = ELM_GUI.textBoxToIntArray(Npads_tb);
            double[] padX     = ELM_GUI.textBoxToDoubleArray(padX_tb);
            double[] padY     = ELM_GUI.textBoxToDoubleArray(padY_tb);
            double[] padSpace = ELM_GUI.textBoxToDoubleArray(padSpace_tb);
            int      N_rows   = (int)N_rows_nud.Value;

            double[] offsetX = ELM_GUI.textBoxToDoubleArray(offsetX_tb);
            double[] offsetY = ELM_GUI.textBoxToDoubleArray(offsetY_tb);

            //Check vector inputs.
            //First: Are we able to attain enough, meaningful, information from each textbox.
            //That means actual numbers must be entered in.
            //Yes. If legitimate values are put in, even for the edge cases, the program works.
            //What protects us from accessing junk information in the "undersized" double[] vectors
            //is d_N_rows. It defines a universal length vector for everything. Then on the C++ level
            //we intentionally block ourselves from that junk information by a simple counter.
            //Second: Does valid input data hurt if we only have 1 or two rows.
            //No.... see above.

            //Stop program operation in this line if any inputs are invalid.
            //If you have a textBoxToArray call that gives you the [-1......] vector, AND that data is actuallly going
            //to be something that C++ tries to read from, then you need to stop operation here.
            //is not readonly and saying "N/A", that's how you know that this textbox has some invalid data. Or, rather,
            //needs data input into it.
            if (stop_program(Npads, padX, padY, padSpace, offsetX, offsetY) != 0)
            {
                MessageBox.Show("One or more input boxes on this page are lacking sufficient information.");
            }
            else
            {
                IntPtr newDeviceList_IntPtr = ELM_GUI.AddDevice_RxR_GUI(
                    ELM_GUI.stringToCharArray(ELM_GUI.CurrentSession.inputPath),                                         //char[] inputPath

                    ELM_GUI.stringToCharArray(newDeviceName_tb.Text),                                                    //char[] d_name
                    ELM_GUI.stringArrayToCharArray(ELM_GUI.textBoxToPadNamesList(newDeviceName_tb, calc_RxR_numPads())), //char[] padNames
                    N_rows,                                                                                              //int d_N_rows
                    Npads, padX, padY, padSpace,                                                                         //d_N_pads, d_padX, d_padY, d_padSpace
                    offsetX, offsetY,                                                                                    //d_horizontalOffset, d_verticalOffset

                    ELM_GUI.stringToCharArray(ELM_GUI.CurrentSession.outputPath)                                         //char[] outputPath
                    );

                ELM_GUI.postDeviceAdd(newDeviceList_IntPtr, initialNumDevices);
                foreach (string x in ELM_GUI.CurrentSession.currentDeviceNameList)
                {
                    Debug.WriteLine(x);
                }
                Debug.WriteLine("New num devices: " + ELM_GUI.CurrentSession.currentDeviceNameList.Length +
                                "\nOld num devices: " + initialNumDevices);
            }
        }