// REO 10/2008: added +fileControlOffsetY to position around file load box
        private void addXYParameterEditor(int i)
        {
            HorizontalParameterEditor hpex = new HorizontalParameterEditor();

            hpex.setParameterData(currentWaveform.XValues[i]);
            HorizontalParameterEditor hpey = new HorizontalParameterEditor();

            hpey.setParameterData(currentWaveform.YValues[i]);

            hpex.Location = new Point(0, this.XYParametersStart1.Location.Y
                                      + i * y_parameter_spacing + fileControlOffsetY);
            hpey.Location = new Point(hpex.Width + 3, this.XYParametersStart1.Location.Y
                                      + i * y_parameter_spacing + fileControlOffsetY);
            hpex.Visible = true;
            hpex.Enabled = !currentWaveform.DataFromFile;

            hpey.Enabled = !currentWaveform.DataFromFile;

            this.xyParameters.Add(hpex);
            this.xyParameters.Add(hpey);

            hpex.updateGUI += this.updateGUI;
            hpey.updateGUI += this.updateGUI;

            /*hpex.updateGUI += this.updateGUI;
             * hpey.updateGUI += this.updateGUI;
             *
             * hpex.Location = new Point(this.XYParametersStart1.Location.X,
             *  this.XYParametersStart1.Location.Y + 2 * i * y_parameter_spacing);
             * hpex.Visible = true;
             * hpex.Enabled = true;
             * hpex.Size = this.XYParametersStart1.Size;
             *
             * hpey.Location = new Point(this.XYParametersStart2.Location.X,
             *  this.XYParametersStart2.Location.Y + 2 * i * y_parameter_spacing);
             * hpey.Visible = true;
             * hpey.Enabled = true;
             * hpey.Size = this.XYParametersStart2.Size;
             *
             * this.xyParameters.Add(hpex);
             * this.xyParameters.Add(hpey);
             *
             * Label labx = new Label();
             * Label laby = new Label();
             *
             * labx.Text = "X" + (i + 1).ToString();
             * laby.Text = "Y" + (i + 1).ToString();
             * labx.Location = new Point(this.XYLabelStart1.Location.X,
             *  this.XYLabelStart1.Location.Y + 2 * i * y_parameter_spacing);
             * laby.Location = new Point(this.XYLabelStart2.Location.X,
             *  this.XYLabelStart2.Location.Y + 2 * i * y_parameter_spacing);
             * labx.Visible = true;
             * labx.Enabled = true;
             * laby.Visible = true;
             * laby.Enabled = true;
             *
             * this.xyParameterLabels.Add(labx);
             * this.xyParameterLabels.Add(laby);
             * */
        }
        public void layOutParameters()
        {
            this.SuspendLayout();

            equationStatusLabel.Enabled = false;
            equationStatusLabel.Visible = false;

            equationTextBox.Enabled = false;
            equationTextBox.Visible = false;
            if (currentWaveform != null)
            {
                equationTextBox.Text = currentWaveform.EquationString;
            }

            equationHelpText.Visible = false;

            upButton.Enabled = false;
            upButton.Visible = false;

            downButton.Visible = false;
            downButton.Enabled = false;

            sortButton.Visible = false;
            scaleButton.Visible = false;

            // REO 10/2008
            // first, remove the old stuff
            disableLoadFileControls();
            hideXYLabels();

            if (specializedParameters != null)
            {
                foreach (HorizontalParameterEditor ed in specializedParameters)
                {
                    this.specialParametersBox.Controls.Remove(ed);
                    ed.Dispose();
                }
                foreach (Label lab in specializedParameterLabels)
                {
                    this.specialParametersBox.Controls.Remove(lab);
                    lab.Dispose();
                }
            }
            specializedParameters = null;
            specializedParameterLabels = null;

            if (xyParameters != null)
            {
                foreach (HorizontalParameterEditor ed in xyParameters)
                {
                    this.Controls.Remove(ed);
                    ed.Dispose();
                }
                foreach (Label lab in xyParameterLabels)
                {
                    this.Controls.Remove(lab);
                    lab.Dispose();
                }
            }
            xyParameterLabels = null;
            xyParameters = null;

            if (combinationParameters != null)
            {
                foreach (ComboBox box in combinationParameters)
                {
                    this.Controls.Remove(box);
                    box.Dispose();
                }
            }

            combinationParameters = null;

            if (currentWaveform != null)
            {

                if (currentWaveform.interpolationType.xyParametersEnabled)
                {
                    if (currentWaveform.interpolationType.xyParametersFixed)
                    {
                        sortButton.Visible = false;
                        scaleButton.Visible = false;
                    }
                    else
                    {
                        sortButton.Visible = true;
                        scaleButton.Visible = true;
                    }
                }

                // lay out specialized param editors

                if (currentWaveform.interpolationType.extraParametersEnabled)
                {
                    specializedParameters = new List<HorizontalParameterEditor>();
                    specializedParameterLabels = new List<Label>();

                    for (int i = 0; i < currentWaveform.interpolationType.extraParametersCount; i++)
                    {
                        HorizontalParameterEditor hpe = new HorizontalParameterEditor(
                            currentWaveform.ExtraParameters[i]);

                        hpe.updateGUI += this.updateGUI;

                        hpe.Location = new Point(specialParametersStartPoint.Location.X,
                            specialParametersStartPoint.Location.Y + i * y_parameter_spacing);
                        hpe.Visible = true;
                        hpe.Enabled = true;
                        hpe.Size = specialParametersStartPoint.Size;

                        specializedParameters.Add(hpe);

                        Label lab = new Label();
                        lab.Text = currentWaveform.interpolationType.extraParametersNames[i];
                        lab.Location = new Point(specializedLabelStart.Location.X,
                            specializedLabelStart.Location.Y + i * y_parameter_spacing);
                        lab.Visible = true;
                        lab.Enabled = true;

                        specializedParameterLabels.Add(lab);

                    }

                    specialParametersBox.Controls.AddRange(specializedParameters.ToArray());
                    specialParametersBox.Controls.AddRange(specializedParameterLabels.ToArray());
                }

                // REO 10/2008
                // Now lay out load file box
                if (currentWaveform.interpolationType.canReadDataFromFile)
                {
                    enableLoadFileControls();
                }

                // Now lay out XY parameters.

                if (currentWaveform.interpolationType.xyParametersEnabled)
                {
                    xyParameters = new List<HorizontalParameterEditor>();
                    xyParameterLabels = new List<Label>();

                    if (currentWaveform.interpolationType.xyParametersFixed)
                    {
                        for (int i = 0; i < currentWaveform.interpolationType.xyParametersCount; i++)
                        {
                            addXYParameterEditor(i);
                        }

                    }
                    else
                    {
                        for (int i = 0; i < currentWaveform.XValues.Count; i++)
                        {
                            addXYParameterEditor(i);
                        }

                        enableAndPositionUpDownButtons();
                    }

                    if (xyParameters.Count != 0)
                    {
                        showXYLabels();
                    }

                    this.Controls.AddRange(xyParameters.ToArray());
                    this.Controls.AddRange(xyParameterLabels.ToArray());
                    //    foreach (HorizontalParameterEditor hpe in xyParameters)
                    //       this.Controls.Add(hpe);
                    //   foreach (Label lab in xyParameterLabels)
                    //       this.Controls.Add(lab);
                }

                // REO 10/2008: added +fileControlOffsetY to position around file load box
                // Now layout waveform combination parameters

                if (currentWaveform.interpolationType.referencesOtherWaveforms)
                {
                    combinationParameters = new List<ComboBox>();
                    combinationBoxIsAWaveform = new Dictionary<ComboBox, bool>();

                    for (int i = 0; i < currentWaveform.ReferencedWaveforms.Count; i++)
                    {
                        ComboBox box = new ComboBox();
                        combinationBoxIsAWaveform.Add(box, true);
                        box.Size = waveformCombosStart.Size;
                        box.Location = new Point(waveformCombosStart.Location.X,
                            waveformCombosStart.Location.Y
                            + 2 * i * y_parameter_spacing
                            + fileControlOffsetY);

                        foreach (Waveform wf in Storage.sequenceData.CommonWaveforms)
                        {
                            if (wf.ToString() == null)
                                wf.WaveformName = "Name Required";
                            box.Items.Add(wf);
                        }

                        box.DropDownStyle = ComboBoxStyle.DropDownList;
                        box.Name = i.ToString();
                        box.SelectedIndexChanged += combinerComboBoxValueChanged;

                        box.SelectedItem = currentWaveform.ReferencedWaveforms[i];

                        combinationParameters.Add(box);

                    }

                    for (int i = 0; i < currentWaveform.WaveformCombiners.Count; i++)
                    {
                        ComboBox box = new ComboBox();
                        combinationBoxIsAWaveform.Add(box, false);
                        box.Size = waveformCombosStart.Size;
                        box.Location = new Point(waveformCombosStart.Location.X,
                            waveformCombosStart.Location.Y
                            + (2 * i + 1) * y_parameter_spacing
                            + fileControlOffsetY);

                        box.BeginUpdate();
                        foreach (Waveform.InterpolationType.CombinationOperators oper in Waveform.InterpolationType.allCombinationOperators)
                        {
                            box.Items.Add(oper);
                        }
                        box.EndUpdate();

                        box.DropDownStyle = ComboBoxStyle.DropDownList;
                        box.Name = i.ToString();
                        box.SelectedIndexChanged += combinerComboBoxValueChanged;

                        box.SelectedItem = currentWaveform.WaveformCombiners[i];
                        combinationParameters.Add(box);

                    }

                    this.Controls.AddRange(combinationParameters.ToArray());

                    //  foreach (ComboBox box in combinationParameters)
                    //      this.Controls.Add(box);

                    enableAndPositionUpDownButtons();
                }
            }
            if (currentWaveform != null)
            {
                if (currentWaveform.interpolationType.equationParameterEnabled)
                {
                    equationTextBox.Visible = true;
                    equationTextBox.Enabled = true;
                    equationStatusLabel.Visible = true;
                    equationStatusLabel.Enabled = true;

                    equationHelpText.Visible = true;

                    updateEquationStatusLabel();
                }
            }

            this.ResumeLayout();
        }
        // REO 10/2008: added +fileControlOffsetY to position around file load box
        private void addXYParameterEditor(int i)
        {
            HorizontalParameterEditor hpex = new HorizontalParameterEditor();
            hpex.setParameterData(currentWaveform.XValues[i]);
            HorizontalParameterEditor hpey = new HorizontalParameterEditor();
            hpey.setParameterData(currentWaveform.YValues[i]);

            hpex.Location = new Point(0, this.XYParametersStart1.Location.Y
                + i * y_parameter_spacing + fileControlOffsetY);
            hpey.Location = new Point(hpex.Width + 3, this.XYParametersStart1.Location.Y
                + i * y_parameter_spacing + fileControlOffsetY);
            hpex.Visible = true;
            hpex.Enabled = !currentWaveform.DataFromFile;

            hpey.Enabled = !currentWaveform.DataFromFile;

            this.xyParameters.Add(hpex);
            this.xyParameters.Add(hpey);

            hpex.updateGUI += this.updateGUI;
            hpey.updateGUI += this.updateGUI;

            /*hpex.updateGUI += this.updateGUI;
            hpey.updateGUI += this.updateGUI;

            hpex.Location = new Point(this.XYParametersStart1.Location.X,
                this.XYParametersStart1.Location.Y + 2 * i * y_parameter_spacing);
            hpex.Visible = true;
            hpex.Enabled = true;
            hpex.Size = this.XYParametersStart1.Size;

            hpey.Location = new Point(this.XYParametersStart2.Location.X,
                this.XYParametersStart2.Location.Y + 2 * i * y_parameter_spacing);
            hpey.Visible = true;
            hpey.Enabled = true;
            hpey.Size = this.XYParametersStart2.Size;

            this.xyParameters.Add(hpex);
            this.xyParameters.Add(hpey);

            Label labx = new Label();
            Label laby = new Label();

            labx.Text = "X" + (i + 1).ToString();
            laby.Text = "Y" + (i + 1).ToString();
            labx.Location = new Point(this.XYLabelStart1.Location.X,
                this.XYLabelStart1.Location.Y + 2 * i * y_parameter_spacing);
            laby.Location = new Point(this.XYLabelStart2.Location.X,
                this.XYLabelStart2.Location.Y + 2 * i * y_parameter_spacing);
            labx.Visible = true;
            labx.Enabled = true;
            laby.Visible = true;
            laby.Enabled = true;

            this.xyParameterLabels.Add(labx);
            this.xyParameterLabels.Add(laby);
             * */
        }
        public void layOutParameters()
        {
            this.SuspendLayout();

            equationStatusLabel.Enabled = false;
            equationStatusLabel.Visible = false;

            equationTextBox.Enabled = false;
            equationTextBox.Visible = false;
            if (currentWaveform != null)
            {
                equationTextBox.Text = currentWaveform.EquationString;
            }

            equationHelpText.Visible = false;

            upButton.Enabled = false;
            upButton.Visible = false;

            downButton.Visible = false;
            downButton.Enabled = false;

            sortButton.Visible  = false;
            scaleButton.Visible = false;


            // REO 10/2008
            // first, remove the old stuff
            disableLoadFileControls();
            hideXYLabels();

            if (specializedParameters != null)
            {
                foreach (HorizontalParameterEditor ed in specializedParameters)
                {
                    this.specialParametersBox.Controls.Remove(ed);
                    ed.Dispose();
                }
                foreach (Label lab in specializedParameterLabels)
                {
                    this.specialParametersBox.Controls.Remove(lab);
                    lab.Dispose();
                }
            }
            specializedParameters      = null;
            specializedParameterLabels = null;


            if (xyParameters != null)
            {
                foreach (HorizontalParameterEditor ed in xyParameters)
                {
                    this.Controls.Remove(ed);
                    ed.Dispose();
                }
                foreach (Label lab in xyParameterLabels)
                {
                    this.Controls.Remove(lab);
                    lab.Dispose();
                }
            }
            xyParameterLabels = null;
            xyParameters      = null;


            if (combinationParameters != null)
            {
                foreach (ComboBox box in combinationParameters)
                {
                    this.Controls.Remove(box);
                    box.Dispose();
                }
            }

            combinationParameters = null;

            if (currentWaveform != null)
            {
                if (currentWaveform.interpolationType.xyParametersEnabled)
                {
                    if (currentWaveform.interpolationType.xyParametersFixed)
                    {
                        sortButton.Visible  = false;
                        scaleButton.Visible = false;
                    }
                    else
                    {
                        sortButton.Visible  = true;
                        scaleButton.Visible = true;
                    }
                }

                // lay out specialized param editors

                if (currentWaveform.interpolationType.extraParametersEnabled)
                {
                    specializedParameters      = new List <HorizontalParameterEditor>();
                    specializedParameterLabels = new List <Label>();

                    for (int i = 0; i < currentWaveform.interpolationType.extraParametersCount; i++)
                    {
                        HorizontalParameterEditor hpe = new HorizontalParameterEditor(
                            currentWaveform.ExtraParameters[i]);

                        hpe.updateGUI += this.updateGUI;

                        hpe.Location = new Point(specialParametersStartPoint.Location.X,
                                                 specialParametersStartPoint.Location.Y + i * y_parameter_spacing);
                        hpe.Visible = true;
                        hpe.Enabled = true;
                        hpe.Size    = specialParametersStartPoint.Size;

                        specializedParameters.Add(hpe);

                        Label lab = new Label();
                        lab.Text     = currentWaveform.interpolationType.extraParametersNames[i];
                        lab.Location = new Point(specializedLabelStart.Location.X,
                                                 specializedLabelStart.Location.Y + i * y_parameter_spacing);
                        lab.Visible = true;
                        lab.Enabled = true;

                        specializedParameterLabels.Add(lab);
                    }

                    specialParametersBox.Controls.AddRange(specializedParameters.ToArray());
                    specialParametersBox.Controls.AddRange(specializedParameterLabels.ToArray());
                }

                // REO 10/2008
                // Now lay out load file box
                if (currentWaveform.interpolationType.canReadDataFromFile)
                {
                    enableLoadFileControls();
                }

                // Now lay out XY parameters.


                if (currentWaveform.interpolationType.xyParametersEnabled)
                {
                    xyParameters      = new List <HorizontalParameterEditor>();
                    xyParameterLabels = new List <Label>();


                    if (currentWaveform.interpolationType.xyParametersFixed)
                    {
                        for (int i = 0; i < currentWaveform.interpolationType.xyParametersCount; i++)
                        {
                            addXYParameterEditor(i);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < currentWaveform.XValues.Count; i++)
                        {
                            addXYParameterEditor(i);
                        }

                        enableAndPositionUpDownButtons();
                    }


                    if (xyParameters.Count != 0)
                    {
                        showXYLabels();
                    }


                    this.Controls.AddRange(xyParameters.ToArray());
                    this.Controls.AddRange(xyParameterLabels.ToArray());
                    //    foreach (HorizontalParameterEditor hpe in xyParameters)
                    //       this.Controls.Add(hpe);
                    //   foreach (Label lab in xyParameterLabels)
                    //       this.Controls.Add(lab);
                }


                // REO 10/2008: added +fileControlOffsetY to position around file load box
                // Now layout waveform combination parameters


                if (currentWaveform.interpolationType.referencesOtherWaveforms)
                {
                    combinationParameters     = new List <ComboBox>();
                    combinationBoxIsAWaveform = new Dictionary <ComboBox, bool>();


                    for (int i = 0; i < currentWaveform.ReferencedWaveforms.Count; i++)
                    {
                        ComboBox box = new ComboBox();
                        combinationBoxIsAWaveform.Add(box, true);
                        box.Size     = waveformCombosStart.Size;
                        box.Location = new Point(waveformCombosStart.Location.X,
                                                 waveformCombosStart.Location.Y
                                                 + 2 * i * y_parameter_spacing
                                                 + fileControlOffsetY);

                        foreach (Waveform wf in Storage.sequenceData.CommonWaveforms)
                        {
                            if (wf.ToString() == null)
                            {
                                wf.WaveformName = "Name Required";
                            }
                            box.Items.Add(wf);
                        }

                        box.DropDownStyle         = ComboBoxStyle.DropDownList;
                        box.Name                  = i.ToString();
                        box.SelectedIndexChanged += combinerComboBoxValueChanged;

                        box.SelectedItem = currentWaveform.ReferencedWaveforms[i];

                        combinationParameters.Add(box);
                    }

                    for (int i = 0; i < currentWaveform.WaveformCombiners.Count; i++)
                    {
                        ComboBox box = new ComboBox();
                        combinationBoxIsAWaveform.Add(box, false);
                        box.Size     = waveformCombosStart.Size;
                        box.Location = new Point(waveformCombosStart.Location.X,
                                                 waveformCombosStart.Location.Y
                                                 + (2 * i + 1) * y_parameter_spacing
                                                 + fileControlOffsetY);

                        box.BeginUpdate();
                        foreach (Waveform.InterpolationType.CombinationOperators oper in Waveform.InterpolationType.allCombinationOperators)
                        {
                            box.Items.Add(oper);
                        }
                        box.EndUpdate();


                        box.DropDownStyle         = ComboBoxStyle.DropDownList;
                        box.Name                  = i.ToString();
                        box.SelectedIndexChanged += combinerComboBoxValueChanged;

                        box.SelectedItem = currentWaveform.WaveformCombiners[i];
                        combinationParameters.Add(box);
                    }

                    this.Controls.AddRange(combinationParameters.ToArray());

                    //  foreach (ComboBox box in combinationParameters)
                    //      this.Controls.Add(box);

                    enableAndPositionUpDownButtons();
                }
            }
            if (currentWaveform != null)
            {
                if (currentWaveform.interpolationType.equationParameterEnabled)
                {
                    equationTextBox.Visible     = true;
                    equationTextBox.Enabled     = true;
                    equationStatusLabel.Visible = true;
                    equationStatusLabel.Enabled = true;

                    equationHelpText.Visible = true;

                    updateEquationStatusLabel();
                }
            }


            this.ResumeLayout();
        }